* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif; background: #d8e8f0; }
canvas { display: block; }

/* ── Welcome Screen ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes subtleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(247,147,30,0.1); }
  50% { box-shadow: 0 0 35px rgba(247,147,30,0.2); }
}

#welcome-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #080510;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(233,78,27,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(247,147,30,0.04) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 100%, rgba(196,35,123,0.03) 0%, transparent 50%);
  color: white;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: 'Trebuchet MS', sans-serif;
  -webkit-overflow-scrolling: touch;
}

.welcome-inner {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  height: 100vh; height: 100dvh;
  padding: 28px 40px 16px;
  box-sizing: border-box;
  width: 100%;
  overflow: hidden;
  animation: fadeInUp 0.8s ease-out;
}

.welcome-title {
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 52px; font-weight: 900; color: #fff;
  text-shadow: 0 0 60px rgba(233,78,27,0.3), 0 0 120px rgba(247,147,30,0.1);
  letter-spacing: 12px; margin-bottom: 4px; line-height: 1;
  animation: subtleFloat 4s ease-in-out infinite;
}

.welcome-subtitle {
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 15px; color: transparent; font-weight: 700;
  background: linear-gradient(90deg, rgba(247,147,30,0.4), rgba(247,147,30,0.9), rgba(233,78,27,0.7), rgba(247,147,30,0.4));
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text;
  animation: shimmer 4s linear infinite;
  text-transform: uppercase; letter-spacing: 10px;
  margin-bottom: 24px;
}

.welcome-section-label {
  text-align: center; font-family: 'Trebuchet MS', sans-serif;
  font-size: 14px; color: rgba(247,147,30,0.6); font-weight: 700;
  text-transform: uppercase; letter-spacing: 6px; margin-bottom: 14px;
}

.welcome-footer-text {
  margin-top: 16px;
  font-size: 9px; color: rgba(255,255,255,0.1);
  font-family: 'Trebuchet MS', sans-serif;
  letter-spacing: 3px; text-transform: uppercase;
}

/* ── Pseudo Input ── */
.pseudo-row {
  width: 100%;
  margin: 0 0 18px;
}

.pseudo-label {
  font-size: 11px; color: rgba(255,255,255,0.35);
  text-transform: uppercase; letter-spacing: 4px;
  margin-bottom: 8px;
  font-family: 'Trebuchet MS', sans-serif; font-weight: 700;
}

.pseudo-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: 0.25;
}

#pseudo-input {
  width: 100%; padding: 13px 16px 13px 40px;
  font-size: 14px; font-family: 'Trebuchet MS', sans-serif;
  border: 1px solid rgba(255,255,255,0.06); border-radius: 12px;
  background: rgba(255,255,255,0.03); color: #fff;
  outline: none; box-sizing: border-box; transition: all 0.3s;
  backdrop-filter: blur(10px);
}
#pseudo-input:focus {
  border-color: rgba(247,147,30,0.4);
  background: rgba(255,255,255,0.05);
  box-shadow: 0 0 20px rgba(247,147,30,0.08);
}
#pseudo-input::placeholder { color: rgba(255,255,255,0.2); font-weight: 500; }

#auth-msg {
  margin-top: 6px; text-align: center;
  font-size: 12px; font-family: 'Trebuchet MS', sans-serif;
  min-height: 16px; transition: all 0.3s;
}

/* ── Character Select Panel ── */
#charselect-panel {
  width: 100%; max-width: 800px;
  box-sizing: border-box;
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 0;
}

.charselect-flex {
  display: flex; gap: 28px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

/* ── 3D Preview ── */
.char-preview-wrap {
  flex: 1; min-width: 0;
  background: linear-gradient(180deg, rgba(15,10,8,0.95) 0%, rgba(8,5,3,0.98) 100%);
  border: 1px solid rgba(247,147,30,0.08);
  border-radius: 20px; overflow: hidden;
  position: relative;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.03);
  animation: pulseGlow 4s ease-in-out infinite;
}

.char-preview-wrap canvas {
  width: 100%; height: 100%; display: block;
}

#char-preview-name {
  position: absolute; bottom: 20px; left: 0; right: 0;
  text-align: center;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 12px; font-weight: 700;
  color: rgba(255,255,255,0.6);
  text-shadow: 0 2px 12px rgba(0,0,0,0.9);
  letter-spacing: 4px; text-transform: uppercase;
}

/* ── Left Panel ── */
.char-left-panel {
  display: flex; flex-direction: column; gap: 10px;
  width: 240px; min-width: 240px; max-width: 240px;
  justify-content: center;
}

.char-list {
  display: flex; flex-direction: column; gap: 4px;
}

.char-btn {
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  color: rgba(255,255,255,0.4); cursor: pointer;
  font-size: 13px; font-family: 'Trebuchet MS', sans-serif;
  font-weight: 600; transition: all 0.25s ease;
  display: flex; align-items: center; gap: 12px;
  letter-spacing: 0.5px;
  backdrop-filter: blur(4px);
}

.char-btn:hover {
  border-color: rgba(247,147,30,0.2);
  background: rgba(247,147,30,0.04);
  color: rgba(255,255,255,0.75);
  transform: translateX(4px);
}

.char-btn:active { transform: translateX(4px) scale(0.97); }

.char-btn.selected {
  border-color: rgba(247,147,30,0.5);
  background: linear-gradient(135deg, rgba(233,78,27,0.1), rgba(247,147,30,0.06));
  color: #fff;
  box-shadow: 0 0 20px rgba(233,78,27,0.1), inset 0 0 20px rgba(247,147,30,0.03);
}

.char-btn-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  border-radius: 6px;
  background: rgba(247,147,30,0.06);
  color: rgba(247,147,30,0.3);
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
  transition: all 0.25s;
}

.char-btn.selected .char-btn-num {
  background: linear-gradient(135deg, rgba(247,147,30,0.25), rgba(233,78,27,0.2));
  color: #f7931e;
  box-shadow: 0 0 8px rgba(247,147,30,0.15);
}

/* ── Enter Button ── */
#enter-btn {
  padding: 1rem 2.5rem; font-size: 0.85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.25em;
  border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(135deg, #f7931e 0%, #e94e1b 50%, #c4237b 100%);
  background-size: 200% auto;
  color: #fff;
  box-shadow: 0 8px 32px rgba(233,78,27,0.3), 0 2px 8px rgba(0,0,0,0.3);
  transition: all 0.4s ease;
  position: relative; overflow: hidden;
  width: 100%;
}
#enter-btn.disabled {
  opacity: 0.2 !important;
  pointer-events: none !important;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
#enter-btn.enabled {
  opacity: 1 !important;
  pointer-events: auto !important;
}
#enter-btn:hover {
  background-position: right center;
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(233,78,27,0.45), 0 4px 12px rgba(0,0,0,0.3);
}
#enter-btn::before {
  content: '';
  position: absolute; top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.7s ease;
}
#enter-btn:hover::before { left: 100%; }

/* ── Fade-in Overlay ── */
#fade-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: #000; z-index: 1000; opacity: 1;
  transition: opacity 1s ease; pointer-events: none;
}
#fade-overlay.fade-out { opacity: 0; }

/* ── HUD ── */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 10;
  transform: translateY(100px); opacity: 0;
  transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
#hud.slide-in { transform: translateY(0); opacity: 1; }

#crosshair { display: none; }

#interact-prompt {
  position: absolute; bottom: 25%; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.7); color: white;
  padding: 10px 24px; border-radius: 8px;
  font-size: 0.9rem; opacity: 0; transition: opacity 0.3s;
  cursor: pointer; pointer-events: auto;
}
#interact-prompt span { color: #f5e6c8; font-weight: bold; }

#stand-label {
  position: absolute; top: 15%; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.95); color: #333;
  padding: 12px 28px; border-radius: 25px;
  font-size: 1.1rem; font-weight: 600; opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  max-width: 350px; text-align: center;
  border: 2px solid rgba(0,0,0,0.1);
}
#stand-label strong { font-size: 1.2rem; color: #2c3e50; display: block; margin-bottom: 4px; }
#stand-label .stand-description { font-size: 0.9rem; color: #7f8c8d; font-weight: normal; line-height: 1.3; }

#instructions {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.85); color: #555;
  padding: 8px 20px; border-radius: 20px; font-size: 0.8rem;
}

#minimap {
  position: absolute; bottom: 50px; right: 15px;
  width: 180px; height: 180px;
  border-radius: 50%; overflow: hidden;
  border: none; background: transparent;
}
#minimap-canvas { width: 100%; height: 100%; border-radius: 50%; }

/* ── Footer ── */
#info-footer {
  position: absolute; bottom: 0; left: 0; right: 0; height: 35px;
  background: linear-gradient(135deg, rgba(0,0,0,0.8) 0%, rgba(52,73,94,0.9) 100%);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,0.2);
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center; z-index: 15;
}
.footer-content {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Segoe UI', system-ui, sans-serif; color: white; font-size: 0.9rem;
}
.footer-logo { font-weight: 900; color: #f5e6c8; text-shadow: 0 0 5px rgba(255,215,0,0.3); letter-spacing: 0.1em; }
.footer-text { font-weight: 500; color: #ecf0f1; }
.footer-separator { color: rgba(255,255,255,0.4); font-weight: 300; }

/* ── Mobile Interact Button ── */
#mobile-interact-btn {
  position: fixed; bottom: 90px; right: 20px;
  width: 64px; height: 64px;
  background: rgba(233,78,27,0.3);
  border: 3px solid rgba(233,78,27,0.6);
  border-radius: 50%;
  color: #f5e6c8; font-size: 22px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto; z-index: 200;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 4px 20px rgba(233,78,27,0.3);
}
#mobile-interact-btn:active {
  background: rgba(233,78,27,0.6);
  transform: scale(0.92);
}

/* ── Stand Modal ── */
#stand-modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75); z-index: 99999;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.25s ease; pointer-events: all;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#stand-modal-inner {
  background: #1a1a1a; border: 2px solid #e94e1b; border-radius: 12px;
  max-width: 620px; width: 90%; max-height: 80vh; overflow-y: auto;
  padding: 32px 28px 24px; position: relative;
  color: #eee; font-family: 'Segoe UI', Arial, sans-serif;
}
#stand-modal-close {
  position: absolute; top: 10px; right: 14px;
  background: rgba(0,0,0,0.3); border: none; color: #fff;
  font-size: 28px; width: 44px; height: 44px;
  border-radius: 50%; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
#stand-modal-title {
  color: #e94e1b; font-size: 1.6em;
  margin: 0 0 16px 0; border-bottom: 1px solid #333; padding-bottom: 10px;
}
#stand-modal-body { font-size: 0.95em; line-height: 1.65; color: #ccc; }
#stand-modal-body h3 { color: #e94e1b; font-size: 1.05em; margin: 18px 0 6px 0; }
#stand-modal-body ul { padding-left: 18px; margin: 6px 0; }
#stand-modal-body li { margin: 4px 0; }
#stand-modal-body .stat {
  display: inline-block; background: #e94e1b22; border: 1px solid #e94e1b55;
  border-radius: 6px; padding: 3px 10px; margin: 2px 4px; font-size: 0.9em; color: #e94e1b;
}

/* ═══════════════════════════════════════
   RESPONSIVE MOBILE
   ═══════════════════════════════════════ */
@media (max-width: 768px) {
  .welcome-inner { padding: 16px 16px 8px; }
  .welcome-title { font-size: 36px; letter-spacing: 6px; }
  .welcome-subtitle { letter-spacing: 5px; margin-bottom: 14px; font-size: 9px; }
  #plumbob { display: none; }

  #charselect-panel { max-width: 100%; }

  .charselect-flex {
    flex-direction: column; align-items: stretch; gap: 10px;
  }

  .char-left-panel {
    min-width: unset; max-width: unset; width: 100%;
    order: 1;
  }

  .char-list { flex-direction: row; flex-wrap: wrap; gap: 5px; }
  .char-btn { flex: 1; min-width: calc(50% - 3px); padding: 8px 10px; font-size: 12px; }
  .char-btn-num { width: 18px; height: 18px; font-size: 10px; }

  .char-preview-wrap {
    flex: 1; min-height: 160px;
    width: 100%; min-width: unset;
    order: 0;
  }

  .pseudo-row { margin-bottom: 10px; }

  #enter-btn {
    max-width: 280px; margin: 0 auto;
    display: block; padding: 0.7rem 2rem; font-size: 0.85rem;
  }

  #instructions { display: none; }

  /* Mobile: Hide D-pad (joystick only) */
  #dpad { display: none !important; }

  /* Mobile: Show joystick */
  #joy-container { display: block !important; }

  #minimap { 
    width: 90px; height: 90px; 
    bottom: 110px; right: 8px; 
    /* Ensure minimap doesn't overlap mobile E button */
    z-index: 199;
  }

  #mobile-interact-btn {
    /* Mobile E button: ensure proper positioning */
    bottom: 100px; right: 15px;
    z-index: 200;
  }

  #info-footer { height: 28px; }
  .footer-content { font-size: 0.7rem; gap: 4px; }

  #interact-prompt { padding: 14px 32px; font-size: 1.1rem; bottom: 30%; }

  /* Mobile modals: scrollable and proper sizing */
  #stand-modal-inner { 
    padding: 20px 16px 16px; 
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #stand-modal-title { font-size: 1.3em; }

  /* Mobile: Wheel of fortune sizing */
  #wheel-modal {
    padding: 10px;
  }
  #wheel-modal > div {
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
  }

  /* Mobile: Game modals */
  #snake-modal .snake-cabinet {
    max-width: 90vw;
    width: 90vw;
    padding: 15px;
  }
  
  #flappy-modal .flappy-cabinet {
    max-width: 90vw;
    width: 90vw;
    padding: 20px 16px;
  }

  /* Mobile controls for games always visible */
  #snake-mobile-controls { display: flex !important; }
  #flappy-tap-btn { display: block !important; }
}

@media (max-width: 400px) {
  .welcome-inner { padding: 8px; padding-top: 20px; }
  .char-preview-wrap { min-height: 200px; max-height: 240px; max-width: 240px; }
  .char-btn { padding: 8px 12px; font-size: 12px; }
  .char-btn-num { width: 20px; height: 20px; font-size: 10px; }
  #enter-btn { font-size: 0.9rem; padding: 0.8rem 2rem; }
  #mobile-interact-btn { bottom: 80px; right: 12px; width: 56px; height: 56px; font-size: 20px; }
  
  /* Ultra-small screens: further reduce modal padding */
  #stand-modal-inner { padding: 15px 12px 12px; }
}

/* Portrait orientation mobile adjustments */
@media (max-width: 768px) and (orientation: portrait) {
  #joy-container { 
    bottom: 80px; left: 15px; 
    /* Portrait: joystick at bottom left */
  }
  
  #minimap { 
    bottom: 80px; right: 8px;
    /* Portrait: minimap higher to avoid overlap */
  }
  
  #mobile-interact-btn {
    bottom: 80px; right: 110px;
    /* Portrait: E button between joystick and minimap */
  }
  
  /* Portrait: chat positioning */
  #chat-box {
    bottom: 30px; left: 10px;
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
  }
}

/* Landscape orientation mobile adjustments */
@media (max-width: 768px) and (orientation: landscape) {
  #joy-container { 
    bottom: 20px; left: 20px; 
    /* Landscape: more space, can be lower */
  }
  
  #minimap { 
    bottom: 25px; right: 10px;
  }
  
  #mobile-interact-btn {
    bottom: 25px; right: 110px;
  }
  
  /* Landscape: chat can be wider */
  #chat-box {
    bottom: 15px; left: 15px;
    width: calc(50% - 20px);
    max-width: 400px;
  }
}

/* Touch-friendly interactive elements */
@media (max-width: 768px) {
  /* Ensure all clickable elements are touch-friendly (44px min) */
  button, .char-btn, #mobile-interact-btn, .emoji-btn {
    min-height: 44px;
    touch-action: manipulation;
  }
  
  /* Prevent zoom on input focus */
  input, textarea, select {
    font-size: 16px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
