/* Math Challenge - Premium Mobile Arcade Stylesheet */

:root {
  --font-display: 'Prompt', 'Kanit', sans-serif;
  --font-math: 'Prompt', sans-serif;

  /* Theme Core Colors - Dark Mode Default */
  --bg-color: #0b0f19;
  --panel-bg: rgba(17, 24, 39, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-shadow: rgba(0, 0, 0, 0.4);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --glass-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

  /* Operation Accents */
  --color-addition: #06b6d4;      /* Cyan */
  --color-subtraction: #f87171;   /* Coral */
  --color-multiplication: #c084fc;/* Purple */
  --color-division: #34d399;      /* Emerald */
  --color-mixed: #fbbf24;         /* Gold */
  
  --accent-color: var(--color-addition);
  --accent-gradient: linear-gradient(135deg, var(--color-addition) 0%, #0891b2 100%);
  --accent-glow: rgba(6, 182, 212, 0.3);
}

/* Light Mode Overrides */
[data-theme="light"] {
  --bg-color: #f3f4f6;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(0, 0, 0, 0.08);
  --panel-shadow: rgba(31, 41, 55, 0.06);
  --text-main: #111827;
  --text-muted: #6b7280;
  --glass-glow: 0 8px 32px 0 rgba(31, 41, 55, 0.04);
}

/* Category-specific Ambient Body & Frame Theme Backgrounds */
body.bg-theme-addition {
  --accent-color: var(--color-addition);
  --accent-gradient: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
  --accent-glow: rgba(6, 182, 212, 0.3);
}
body.bg-theme-subtraction {
  --accent-color: var(--color-subtraction);
  --accent-gradient: linear-gradient(135deg, #f87171 0%, #dc2626 100%);
  --accent-glow: rgba(248, 113, 113, 0.3);
}
body.bg-theme-multiplication {
  --accent-color: var(--color-multiplication);
  --accent-gradient: linear-gradient(135deg, #c084fc 0%, #9333ea 100%);
  --accent-glow: rgba(192, 132, 252, 0.3);
}
body.bg-theme-division {
  --accent-color: var(--color-division);
  --accent-gradient: linear-gradient(135deg, #34d399 0%, #059669 100%);
  --accent-glow: rgba(52, 211, 153, 0.3);
}
body.bg-theme-mixed {
  --accent-color: var(--color-mixed);
  --accent-gradient: linear-gradient(135deg, #fbbf24, #ec4899, #3b82f6);
  --accent-glow: rgba(251, 191, 36, 0.3);
}

/* Global Styling Reset */
body.math-challenge-page {
  font-family: var(--font-display);
  background-color: var(--bg-color);
  color: var(--text-main);
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
  transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Subtle Animated Watermark Background */
.math-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04;
  overflow: hidden;
}

[data-theme="light"] .math-bg {
  opacity: 0.08;
}

.math-shape {
  position: absolute;
  font-family: var(--font-math);
  font-size: clamp(3rem, 12vw, 8rem);
  font-weight: 800;
  color: var(--accent-color);
  user-select: none;
  transition: color 0.4s ease;
}

.math-shape.s1 { top: 12%; left: 6%; animation: floatShape 14s infinite ease-in-out; }
.math-shape.s2 { top: 62%; left: 9%; animation: floatShape 18s infinite ease-in-out 2s; }
.math-shape.s3 { top: 18%; right: 11%; animation: floatShape 16s infinite ease-in-out 1s; }
.math-shape.s4 { top: 72%; right: 13%; animation: floatShape 20s infinite ease-in-out 3s; }
.math-shape.s5 { top: 42%; left: 82%; animation: floatShape 15s infinite ease-in-out; }
.math-shape.s6 { top: 48%; left: 22%; animation: floatShape 22s infinite ease-in-out 4s; }

@keyframes floatShape {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  50% { transform: translateY(-24px) rotate(20deg) scale(1.08); }
}

/* Spacing and Header Adjustment (Pull content up) */
.game-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(16px, 4vw, 32px) 16px;
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 660px; /* Slightly wider centered game arena */
  margin: 0 auto;
  box-sizing: border-box;
  margin-top: 12px; /* Pulls content up right under header */
}

/* Cards & Shell Surfaces */
.hero-card {
  background: var(--panel-bg);
  border: 1.5px solid var(--panel-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 32px;
  padding: clamp(24px, 6vw, 40px) clamp(16px, 5vw, 32px);
  box-shadow: var(--glass-glow), 0 20px 40px rgba(0, 0, 0, 0.25);
  position: relative;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  transition: border-color 0.4s ease;
}

/* Menu top actions: sound toggle + leaderboard */
.menu-top-actions {
  position: absolute;
  top: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
}

.menu-sound-btn {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  border: 1.5px solid color-mix(in srgb, var(--accent-color) 55%, rgba(255,255,255,.12));
  background: rgba(17, 24, 39, .72);
  color: var(--text-main);
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 0 14px var(--accent-glow);
  transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.menu-sound-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 12%, rgba(17,24,39,.78));
  box-shadow: 0 0 18px var(--accent-glow);
}

.menu-sound-btn:active {
  transform: scale(.96);
}

.menu-sound-btn.sound-off {
  opacity: .72;
  box-shadow: none;
}

/* Corner Leaderboard button styling */
.leaderboard-corner-btn {
  position: static;
  background: rgba(251, 191, 36, 0.15);
  border: 1.5px solid rgba(251, 191, 36, 0.35);
  color: #fbbf24;
  border-radius: 99px;
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 800;
  font-family: var(--font-display);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}

.leaderboard-corner-btn:hover {
  background: #fbbf24;
  color: #0b0f19;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.5);
  transform: translateY(-1px);
}

.game-logo-mini {
  font-size: 3.5rem;
  margin-bottom: 6px;
  display: inline-block;
  animation: pulseLogo 3s infinite ease-in-out;
}

@keyframes pulseLogo {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.15) rotate(5deg); }
}

h1 {
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  font-weight: 950;
  margin: 0;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

[data-theme="light"] h1 {
  background: linear-gradient(135deg, #1f2937 30%, #4f46e5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 8px 0 32px 0;
  letter-spacing: 0.02em;
}

/* ==================================================
   COMPACT GAME PROFILE BAR (Player Name & Avatar Selector)
   ================================================== */
.player-profile-bar-wrapper {
  margin-bottom: 16px;
}

.player-profile-bar {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1.5px solid var(--panel-border);
  padding: 8px 18px 8px 8px;
  border-radius: 99px;
  gap: 12px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  max-width: 100%;
  box-sizing: border-box;
}

[data-theme="light"] .player-profile-bar {
  background: rgba(0, 0, 0, 0.02);
}

.profile-avatar-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--accent-color);
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
  flex-shrink: 0;
}

.profile-avatar-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 16px var(--accent-color);
}

.profile-avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Avatar camera edit badge */
.avatar-edit-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--accent-gradient);
  border: 1.5px solid var(--bg-color);
  font-size: 0.65rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.player-name-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.player-name-display {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

#playerNameText {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-name-btn {
  background: transparent;
  border: none;
  color: var(--accent-color);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 2px;
  transition: transform 0.15s ease;
}

.edit-name-btn:hover {
  transform: scale(1.2);
}

.player-name-input {
  background: rgba(0, 0, 0, 0.25);
  border: 1.5px solid var(--accent-color);
  color: #fff;
  border-radius: 99px;
  padding: 4px 12px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  outline: none;
  width: 140px;
  box-sizing: border-box;
}

[data-theme="light"] .player-name-input {
  background: #fff;
  color: #111827;
}

.toa-game-member-notice {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ==================================================
   GAME CATEGORY MODES (Visual Accents)
   ================================================== */
.setup-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.field > span {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.mode-card {
  aspect-ratio: 0.9;
  border-radius: 20px;
  border: 1.5px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-display);
  position: relative;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
  padding: 8px 4px;
}

.mode-icon {
  font-size: 2.75rem;
  font-weight: 950;
  line-height: 0.95;
  color: var(--accent);
  transition: transform 0.25s ease;
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}

.mode-card strong {
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
  margin-top: 4px;
}

/* Ambient color identity tint when idle */
.mode-card[data-mode="addition"] { border-color: rgba(6, 182, 212, 0.15); }
.mode-card[data-mode="subtraction"] { border-color: rgba(248, 113, 113, 0.15); }
.mode-card[data-mode="multiplication"] { border-color: rgba(192, 132, 252, 0.15); }
.mode-card[data-mode="division"] { border-color: rgba(52, 211, 153, 0.15); }
.mode-card[data-mode="mixed"] { border-color: rgba(251, 191, 36, 0.15); }

.mode-card:hover {
  transform: translateY(-4px);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.mode-card.active {
  background: var(--accent);
  color: #0b0f19 !important;
  border-color: transparent !important;
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 10px 24px var(--accent), 0 0 16px rgba(255, 255, 255, 0.1);
}

.mode-card.active .mode-icon {
  color: #0b0f19 !important;
  transform: scale(1.15);
}

/* ==================================================
   DIFFICULTY SEGMENTED CONTROLS (Pills)
   ================================================== */
.difficulty-segmented {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--panel-border);
  padding: 4px;
  border-radius: 14px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .difficulty-segmented {
  background: rgba(0, 0, 0, 0.03);
}

.diff-pill {
  flex: 1;
  font-family: var(--font-display);
  background: transparent;
  border: none;
  color: var(--text-main);
  opacity: 0.65;
  padding: 10px;
  font-size: 0.9rem;
  font-weight: 800;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-pill:hover {
  opacity: 0.9;
}

.diff-pill.active {
  background: var(--accent-gradient);
  color: #fff !important;
  opacity: 1;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.difficulty-desc {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
  min-height: 22px;
}

/* Setup Start Game Action Buttons */
.start-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

.primary-btn {
  flex: 1.5;
  font-family: var(--font-display);
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 15px 30px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.35);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

/* Subtle shine overlay */
.primary-btn::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  transform: skewX(-25deg);
  transition: 0.75s;
}

.primary-btn:hover::after {
  left: 150%;
}

.primary-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px var(--accent-color);
}

.primary-btn:active {
  transform: scale(0.97);
}

/* ==================================================
   GAME PLAY ARENA & ILLUMINATION BORDER
   ================================================== */
.game-screen {
  width: 100%;
  position: relative;
}

/* Glow Frame around the Game Board (Game Arena Highlight) */
.game-board {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  position: relative;
  background: var(--panel-bg);
  border: 2px solid var(--accent-color);
  border-radius: 28px;
  padding: clamp(20px, 5vw, 32px);
  box-shadow: var(--glass-glow), 0 0 20px var(--accent-glow);
  box-sizing: border-box;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

/* Ambient lighting behind gameboard */
.game-screen::before {
  content: '';
  position: absolute;
  inset: -10px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  z-index: -1;
  opacity: 0.6;
  pointer-events: none;
  filter: blur(20px);
  transition: background 0.4s ease;
}

/* ==================================================
   HUD — TIME / SCORE / QUESTION / MODE
   ================================================== */
.game-hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  margin-bottom: 18px;
}

.hud-stats {
  display: grid;
  grid-template-columns: minmax(88px, .8fr) minmax(88px, .8fr) minmax(88px, .8fr) minmax(150px, 1.35fr);
  gap: 9px;
  min-width: 0;
}

.hud-capsule {
  background:
    linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.018)),
    rgba(5, 10, 24, .78);
  border: 1.5px solid color-mix(in srgb, var(--accent-color) 72%, rgba(255,255,255,.12));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 17px;
  padding: 8px 12px 9px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  min-width: 0;
  box-shadow:
    0 6px 18px rgba(0,0,0,.18),
    inset 0 1px 0 rgba(255,255,255,.055),
    0 0 12px color-mix(in srgb, var(--accent-color) 12%, transparent);
  position: relative;
  overflow: hidden;
  transition: border-color .25s ease, box-shadow .25s ease, transform .2s ease;
  box-sizing: border-box;
}

[data-theme="light"] .hud-capsule {
  background: rgba(255,255,255,.86);
  box-shadow: 0 5px 16px rgba(15,23,42,.08), inset 0 1px 0 rgba(255,255,255,.8);
}

.hud-label {
  font-size: .68rem;
  line-height: 1;
  font-weight: 900;
  letter-spacing: .09em;
  color: var(--text-muted);
  opacity: .82;
}

.hud-main,
.hud-mode-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 950;
  color: var(--text-main);
  line-height: 1.1;
}

.hud-main {
  font-size: 1.42rem;
}

.hud-mode-main {
  font-size: .96rem;
  width: 100%;
  white-space: nowrap;
}

#hudModeSymbol {
  color: var(--accent-color);
  font-size: 1.45rem;
  line-height: 1;
  text-shadow: 0 0 12px var(--accent-glow);
  flex: 0 0 auto;
}

#hudModeText {
  overflow: hidden;
  text-overflow: ellipsis;
}

.question-card .hud-emoji {
  color: var(--accent-color);
  font-weight: 950;
  font-size: 1.05rem;
}

.hud-emoji {
  font-size: 1rem;
}

/* Score popup bounce animation */
.hud-capsule.score-card {
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hud-capsule.score-card.score-pop {
  animation: scorePopEffect 0.3s ease-out;
  border-color: var(--accent-color);
}

@keyframes scorePopEffect {
  0% { transform: scale(1); }
  50% { transform: scale(1.09); color: #fff; }
  100% { transform: scale(1); }
}

/* Progress bar inside Timer Capsule */
.timer-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
}

#timerProgressFill {
  height: 100%;
  width: 100%;
  background: var(--accent-color);
  transition: width 1s linear, background-color 0.4s ease;
}

/* Pulse under 10 seconds */
.timer-card.pulse {
  animation: hudTimerPulse 1s infinite ease-in-out;
  border-color: rgba(239, 68, 68, 0.72) !important;
}

.timer-card.pulse #timerProgressFill {
  background: #f87171 !important;
}

.timer-card.pulse .hud-main {
  color: #f87171 !important;
  text-shadow: 0 0 10px rgba(248, 113, 113, 0.45);
}

@keyframes hudTimerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); box-shadow: 0 0 14px rgba(239, 68, 68, 0.25); }
}

/* Sound and Exit circular actions buttons */
.hud-actions {
  display: flex;
  gap: 8px;
  align-self: center;
}

.hud-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--text-main);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.hud-btn:hover {
  border-color: var(--accent-color);
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.hud-btn:active { transform: scale(0.96); }

.hud-btn.danger:hover {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

/* ==================================================
   QUESTION CARD DISPLAY CENTERPIECE
   ================================================== */
.question-container {
  background: rgba(0, 0, 0, 0.2);
  border: 2px solid var(--accent-color);
  border-radius: 24px;
  padding: 36px 20px;
  text-align: center;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 14px rgba(255, 255, 255, 0.02);
  display: grid;
  place-items: center;
  min-height: 160px;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
  transition: border-color 0.4s ease;
}

[data-theme="light"] .question-container {
  background: rgba(255, 255, 255, 0.7);
}

/* Mathematical watermark */
.question-container::after {
  content: attr(data-sign);
  position: absolute;
  font-size: 10rem;
  font-weight: 900;
  color: var(--accent-color);
  opacity: 0.045;
  bottom: -20px;
  right: -10px;
  line-height: 1;
  pointer-events: none;
  font-family: var(--font-math);
}

.question-text {
  font-size: clamp(3.2rem, 10vw, 4.8rem);
  font-weight: 850;
  color: #fff;
  letter-spacing: -0.02em;
  text-shadow: 0 0 14px var(--accent-glow);
  z-index: 2;
  font-family: var(--font-math);
}

[data-theme="light"] .question-text {
  color: #111827;
  text-shadow: none;
}

/* ==================================================
   ANSWER BUTTONS (PREMIUM 1.5px ACCENT BORDER)
   ================================================== */
.choices-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
}

.choice-btn {
  font-family: var(--font-display);
  background: rgba(0, 0, 0, 0.15);
  border: 1.8px solid var(--accent-color);
  color: var(--text-main);
  border-radius: 20px;
  padding: 16px 8px;
  font-size: clamp(1.5rem, 5vw, 2.20rem);
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15), inset 0 2px 4px rgba(255, 255, 255, 0.02);
  min-height: 78px;
  box-sizing: border-box;
  outline: none;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease, border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

[data-theme="light"] .choice-btn {
  background: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
}

.choice-btn:hover {
  transform: translateY(-2px);
  border-color: #fff;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 8px 20px var(--accent-glow);
}

[data-theme="light"] .choice-btn:hover {
  background: rgba(0, 0, 0, 0.01);
  border-color: var(--text-main);
}

.choice-btn:active {
  transform: scale(0.96);
}

/* Input lock used during the short answer-feedback window. */
.choices-grid.answer-locked .choice-btn {
  pointer-events: none;
}

/* Answer feedback flasher (Quick transition) */
.choice-btn.correct-flash {
  background-color: rgba(16, 185, 129, 0.25) !important;
  border-color: #10b981 !important;
  color: #34d399 !important;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4) !important;
}

.choice-btn.wrong-flash {
  background-color: rgba(239, 68, 68, 0.25) !important;
  border-color: #ef4444 !important;
  color: #f87171 !important;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.4) !important;
}

/* ==================================================
   AVATAR MODAL GRID POPOVER (Bottom Sheet / Drawer style)
   ================================================== */
.avatar-modal-card {
  max-width: 480px;
}

.avatar-selection-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  max-height: 280px;
  overflow-y: auto;
  padding: 12px 6px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  margin-bottom: 20px;
}

[data-theme="light"] .avatar-selection-grid {
  background: rgba(0, 0, 0, 0.03);
}

.avatar-selection-option {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  padding: 2px;
  overflow: hidden;
  transition: all 0.15s ease;
  box-sizing: border-box;
  position: relative;
}

.avatar-selection-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-selection-option:hover {
  transform: scale(1.1);
}

.avatar-selection-option.active {
  border-color: var(--accent-color);
  background: rgba(99, 102, 241, 0.15);
  box-shadow: 0 0 12px var(--accent-color);
}

/* Small selected checkmark icon badge inside active avatar selection */
.avatar-selection-option.active::after {
  content: '✓';
  position: absolute;
  bottom: 0;
  right: 0;
  background: #10b981;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ==================================================
   COUNTDOWN POP EFFECTS
   ================================================== */
.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 25, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1000;
  display: grid;
  place-items: center;
  border-radius: 32px;
}

.countdown-number {
  font-size: clamp(6.5rem, 22vw, 11rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.25);
}

.countdown-number.count-pop {
  animation: countdownTextPulse 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) infinite;
}

@keyframes countdownTextPulse {
  0% { transform: scale(0.4); opacity: 0; }
  10% { opacity: 1; }
  85% { transform: scale(1.05); opacity: 0.95; }
  100% { transform: scale(1.1); opacity: 0; }
}

.countdown-number.start-pop {
  background: linear-gradient(135deg, #fbbf24, #ec4899, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: countdownTextPulse 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) infinite;
  text-shadow: none;
}

/* ==================================================
   RESULT GAME OVER MODAL (POLISHED)
   ================================================== */
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.report-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1.5px solid var(--panel-border);
  border-radius: 20px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .report-box {
  background: rgba(0, 0, 0, 0.015);
  border-color: rgba(0, 0, 0, 0.06);
}

/* Colored custom borders for result stats boxes */
.report-box.success-box { border-color: rgba(52, 211, 153, 0.25); background: rgba(52, 211, 153, 0.02); }
.report-box.total-box { border-color: rgba(99, 102, 241, 0.25); background: rgba(99, 102, 241, 0.02); }
.report-box.accuracy-box { border-color: rgba(6, 182, 212, 0.25); background: rgba(6, 182, 212, 0.02); }
.report-box.streak-box { border-color: rgba(251, 191, 36, 0.25); background: rgba(251, 191, 36, 0.02); }

.report-grid span {
  font-size: 0.98rem;
  font-weight: 900;
  opacity: 0.9;
  margin-bottom: 10px;
  color: var(--text-muted);
}

.report-grid strong {
  font-size: 2.05rem;
  font-weight: 950;
  color: #fff;
}

[data-theme="light"] .report-grid strong {
  color: #111827;
}

/* Confetti layout support */
.modal-card h2 {
  font-size: clamp(2.6rem, 7vw, 3.5rem);
  font-weight: 950;
  margin: 0 0 20px 0;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}


#gameOverModal .modal-card {
  max-width: 560px;
}

#gameOverModal .eyebrow.success {
  font-size: 1.15rem;
  font-weight: 850;
  letter-spacing: .02em;
  margin-bottom: 10px;
}

#gameOverModal .report-box {
  min-height: 112px;
  padding: 18px 12px;
  justify-content: center;
}

/* ==================================================
   RESULT CUSTOM ACTION BUTTONS (NO DEFAULT GRAY)
   ================================================== */
.result-actions-layout {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.result-actions-layout button {
  font-family: var(--font-display);
  border-radius: 16px;
  font-size: 1.02rem;
  font-weight: 900;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
}

/* 1. Play Again - Primary Gradient */
.primary-btn-restart {
  flex: 1.3;
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  box-shadow: 0 6px 16px var(--accent-glow);
}

.primary-btn-restart:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-color);
}

/* 2. View Leaderboard - Secondary Gold Accent */
.secondary-btn-leaderboard {
  flex: 1;
  background: rgba(251, 191, 36, 0.08);
  border: 1.8px solid #fbbf24 !important;
  color: #fbbf24 !important;
}

.secondary-btn-leaderboard:hover {
  background: #fbbf24;
  color: #0b0f19 !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(251, 191, 36, 0.3);
}

/* 3. Change Mode - Secondary Blue Accent */
.secondary-btn-mode {
  flex: 1;
  background: rgba(99, 102, 241, 0.08);
  border: 1.8px solid #818cf8 !important;
  color: #a5b4fc !important;
}

.secondary-btn-mode:hover {
  background: #6366f1;
  color: #fff !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3);
}

/* Unified press state for actions buttons */
.result-actions-layout button:active {
  transform: scale(0.96);
}

/* ==================================================
   LEADERBOARD MODAL POLISH
   ================================================== */
.leaderboard-modal-card {
  max-width: 480px;
}

.leaderboard-tabs {
  background: rgba(0, 0, 0, 0.2);
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  display: inline-flex;
}

[data-theme="light"] .leaderboard-tabs {
  background: rgba(0, 0, 0, 0.03);
}

.leaderboard-tabs button {
  background: transparent;
  border: none;
  color: var(--text-main);
  opacity: 0.65;
  padding: 6px 14px;
  border-radius: 9px;
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-display);
}

.leaderboard-tabs button.active {
  background: var(--accent-gradient);
  color: #fff;
  opacity: 1;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 20px;
}

.leaderboard-entry {
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.leaderboard-entry.me {
  background: rgba(99, 102, 241, 0.08) !important;
  border-color: rgba(99, 102, 241, 0.3) !important;
}

.lb-rank {
  font-size: 1.15rem;
  font-weight: 900;
  width: 24px;
  text-align: center;
}

.lb-rank.gold { color: #fbbf24; }
.lb-rank.silver { color: #cbd5e1; }
.lb-rank.bronze { color: #b45309; }

.lb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--panel-border);
  flex-shrink: 0;
}

.lb-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lb-name {
  flex: 1;
  font-weight: 750;
  font-size: 0.9rem;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-stats {
  text-align: right;
}

.lb-score {
  font-size: 1.1rem;
  font-weight: 900;
  color: #fff;
}

[data-theme="light"] .lb-score {
  color: #111827;
}

.lb-meta {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* ==================================================
   MOBILE DEVICES OPTIMIZATION (375px/390px/430px)
   ================================================== */
@media (max-width: 520px) {
  .game-shell {
    padding: 16px 12px;
    margin-top: 4px;
  }

  .hero-card, .modal-card {
    padding: 20px 14px;
    border-radius: 24px;
  }

  .menu-top-actions {
    position: static;
    width: 100%;
    justify-content: flex-end;
    margin-bottom: 10px;
  }

  .menu-sound-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
  }

  .leaderboard-corner-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    margin: 0;
  }

  .mode-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .mode-card {
    border-radius: 12px;
    padding: 6px 2px;
    aspect-ratio: 0.85;
  }

  .mode-icon {
    font-size: 1.35rem;
  }

  .mode-card strong {
    font-size: 0.6rem;
  }

  .difficulty-segmented {
    border-radius: 10px;
  }

  .diff-pill {
    padding: 8px;
    font-size: 0.8rem;
    border-radius: 7px;
  }

  .start-actions {
    flex-direction: column;
    gap: 12px;
  }

  .start-actions button, .start-actions a {
    width: 100%;
    box-sizing: border-box;
  }

  #gameOverModal .modal-card {
    max-width: 100%;
  }

  #gameOverModal .report-box {
    min-height: 96px;
    padding: 14px 8px;
  }

  .report-grid span {
    font-size: 0.82rem;
  }

  .report-grid strong {
    font-size: 1.75rem;
  }

  /* Result screen button row wrapper columns switch for mobile screen size */
  .result-actions-layout {
    flex-direction: column;
    gap: 10px;
  }
  .result-actions-layout button {
    width: 100%;
  }

  /* Gameplay elements */
  .choices-grid {
    gap: 12px;
  }

  .choice-btn {
    border-radius: 16px;
    padding: 14px 4px;
    min-height: 74px;
    font-size: 1.6rem;
  }

  .question-container {
    padding: 24px 12px;
    border-radius: 20px;
    min-height: 130px;
  }

  .question-text {
    font-size: 3.2rem;
  }

  /* Popover avatar selector adjustments */
  .avatar-selection-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-height: 220px;
  }
}

/* Modals Layout & Overrides */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 16px;
  box-sizing: border-box;
}

.modal-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  padding: clamp(20px, 5vw, 36px);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--glass-glow), 0 25px 50px rgba(0, 0, 0, 0.35);
  text-align: center;
  box-sizing: border-box;
  animation: modalOpenEffect 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  transition: border-color 0.4s ease;
}

@keyframes modalOpenEffect {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.hidden {
  display: none !important;
}


/* ==================================================
   FINAL UX FIXES — MODE ICONS / AVATAR PICKER / HUD
   ================================================== */
.profile-avatar-btn::after {
  content: 'เปลี่ยน';
  position: absolute;
  left: 50%;
  bottom: -22px;
  transform: translateX(-50%);
  font-size: .56rem;
  font-weight: 800;
  color: var(--accent-color);
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
  pointer-events: none;
  white-space: nowrap;
}

.profile-avatar-btn:hover::after,
.profile-avatar-btn:focus-visible::after {
  opacity: .95;
  transform: translate(-50%, -2px);
}

.avatar-modal-card {
  border-color: color-mix(in srgb, var(--accent-color) 55%, var(--panel-border));
  box-shadow: var(--glass-glow), 0 25px 60px rgba(0,0,0,.42), 0 0 28px var(--accent-glow);
}

.avatar-selection-option {
  background: rgba(255,255,255,.035);
  border-color: rgba(255,255,255,.08);
}

.avatar-selection-option:hover {
  border-color: var(--accent-color);
  box-shadow: 0 0 14px var(--accent-glow);
}


@media (max-width: 700px) {
  .game-hud {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px;
  }

  .hud-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .hud-capsule {
    min-height: 50px;
    padding: 7px 10px 8px;
    border-radius: 14px;
  }

  .hud-main { font-size: 1.08rem; }
  .hud-mode-main { font-size: .76rem; }
  #hudModeSymbol { font-size: 1.25rem; }

  .hud-actions {
    flex-direction: column;
    gap: 6px;
  }

  .hud-btn {
    width: 38px;
    height: 38px;
  }
}

@media (max-width: 520px) {
  .mode-icon {
    font-size: 2rem;
  }

  .mode-card strong {
    font-size: .68rem;
  }
}


/* ==================================================
   MOBILE RESULT FIT + SAFE VIEWPORT POLISH
   Keep the result card centered and prevent horizontal drift/tilt on phones.
   ================================================== */
@media (max-width: 520px) {
  #gameOverModal.modal {
    position: fixed;
    inset: 0;
    width: auto;
    min-width: 0;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  #gameOverModal .modal-card {
    width: 100%;
    max-width: 430px;
    min-width: 0;
    margin: auto;
    align-self: center;
    justify-self: center;
    box-sizing: border-box;
    padding: 18px 14px 16px;
    border-radius: 22px;
    transform-origin: center center;
  }

  #gameOverModal .eyebrow.success {
    margin: 0 0 5px;
    font-size: .98rem;
  }

  #gameOverModal .modal-card h2 {
    margin: 0 0 14px;
    font-size: clamp(2rem, 10vw, 2.65rem);
    line-height: 1;
  }

  #gameOverModal .report-grid {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
  }

  #gameOverModal .report-box {
    width: 100%;
    min-width: 0;
    min-height: 78px;
    padding: 9px 6px;
    border-radius: 16px;
    box-sizing: border-box;
  }

  #gameOverModal .report-grid span {
    margin-bottom: 5px;
    font-size: .84rem;
    line-height: 1.15;
  }

  #gameOverModal .report-grid strong {
    font-size: 1.62rem;
    line-height: 1;
  }

  #gameOverModal .personal-best-banner {
    width: 100%;
    margin: 2px 0 10px;
    font-size: .8rem;
    box-sizing: border-box;
  }

  /* Two compact secondary buttons, one strong full-width replay CTA. */
  #gameOverModal .result-actions-layout {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    box-sizing: border-box;
  }

  #gameOverModal .result-actions-layout button {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 11px 7px;
    border-radius: 14px;
    font-size: .92rem;
    line-height: 1.15;
    box-sizing: border-box;
  }

  #gameOverModal #restartBtn {
    grid-column: 1 / -1;
    grid-row: 2;
    min-height: 50px;
    font-size: 1rem;
  }
}

@media (max-width: 370px) {
  #gameOverModal .modal-card {
    padding: 15px 11px 13px;
  }

  #gameOverModal .report-grid {
    gap: 6px;
  }

  #gameOverModal .report-box {
    min-height: 72px;
  }

  #gameOverModal .result-actions-layout button {
    font-size: .8rem;
    padding-inline: 5px;
  }
}


/* ============================================================
   FINAL MOBILE HEADER + RESULT CENTERING FIX
   ============================================================ */

/* Result/other modals are now body-level. Keep result exactly on the viewport center. */
@media (max-width: 700px) {
  html,
  body.math-challenge-page {
    overflow-x: clip;
  }

  body.math-challenge-page > #gameOverModal.modal {
    position: fixed !important;
    inset: 0 !important;
    inline-size: 100vw !important;
    block-size: 100dvh !important;
    min-inline-size: 0 !important;
    max-inline-size: none !important;
    margin: 0 !important;
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left)) !important;
    box-sizing: border-box !important;
    display: grid !important;
    place-items: center !important;
    overflow-x: clip !important;
    overflow-y: auto !important;
    transform: none !important;
    left: 0 !important;
    right: 0 !important;
  }

  body.math-challenge-page > #gameOverModal.modal.hidden {
    display: none !important;
  }

  body.math-challenge-page > #gameOverModal .modal-card {
    position: relative !important;
    inset: auto !important;
    inline-size: min(430px, calc(100vw - 24px)) !important;
    max-inline-size: calc(100vw - 24px) !important;
    min-inline-size: 0 !important;
    margin: auto !important;
    translate: none !important;
    transform: none;
    box-sizing: border-box !important;
  }

  /* Preserve the opening animation without translating the card sideways. */
  body.math-challenge-page > #gameOverModal:not(.hidden) .modal-card {
    animation: mathResultOpenCentered .26s cubic-bezier(.22, 1, .36, 1);
  }

  @keyframes mathResultOpenCentered {
    from { opacity: 0; scale: .96; }
    to   { opacity: 1; scale: 1; }
  }

  /* Standard compact mobile header order:
     Theme -> Member -> Hamburger, with hamburger always far-right. */
  .site-header .header-actions {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    flex: 0 0 auto !important;
    gap: 7px !important;
    min-width: 0 !important;
  }

  .site-header .theme-toggle {
    order: 1 !important;
    flex: 0 0 42px !important;
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    padding: 0 !important;
    border-radius: 14px !important;
  }

  .site-header .member-nav {
    order: 2 !important;
    flex: 0 0 auto !important;
    min-width: 0 !important;
    margin: 0 !important;
  }

  /* When signed out, Login is icon-only on mobile. */
  .site-header .member-nav.is-logged-out {
    flex-basis: 42px !important;
    width: 42px !important;
  }

  .site-header .member-nav .toa-mobile-login-circle {
    position: relative !important;
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50% !important;
    display: grid !important;
    place-items: center !important;
    overflow: hidden !important;
    font-size: 0 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
  }

  .site-header .member-nav .toa-mobile-login-circle > * {
    display: none !important;
  }

  .site-header .member-nav .toa-mobile-login-circle::before {
    content: "👤";
    display: block;
    font-size: 17px;
    line-height: 1;
  }

  /* Logged-in profile also stays compact if shared auth CSS renders a long pill. */
  .site-header .member-nav:not(.is-logged-out) > a,
  .site-header .member-nav:not(.is-logged-out) > button {
    max-width: 46px;
  }

  .site-header .menu-toggle {
    order: 3 !important;
    display: grid !important;
    place-items: center !important;
    flex: 0 0 42px !important;
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 14px !important;
    font-size: 1.35rem !important;
    line-height: 1 !important;
  }

  /* Let the brand yield space instead of pushing the hamburger off-screen. */
  .site-header .nav-wrap {
    gap: 8px !important;
  }

  .site-header .brand {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .site-header .brand > div {
    min-width: 0 !important;
  }

  .site-header .brand-title,
  .site-header .brand-subtitle {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 390px) {
  .site-header .brand-subtitle {
    display: none !important;
  }

  .site-header .brand-title {
    font-size: .95rem !important;
  }

  .site-header .brand-logo {
    width: 42px !important;
    height: 42px !important;
  }

  .site-header .header-actions {
    gap: 5px !important;
  }
}


/* ============================================================
   MOBILE MENU: move "หน้ารวมเกม" to top-left,
   aligned with Sound + Leaderboard controls.
   ============================================================ */
@media (max-width: 520px) {
  .hero-card {
    position: relative;
  }

  /* Keep the existing right-side menu controls on the same top row. */
  .menu-top-actions {
    min-height: 40px;
    align-items: center;
  }

  /* Remove Home from the bottom action flow and pin it to top-left. */
  .start-actions .game-hub-link {
    position: absolute !important;
    top: 20px;
    left: 14px;
    z-index: 11;
    width: auto !important;
    min-width: 0 !important;
    min-height: 40px;
    margin: 0 !important;
    padding: 8px 11px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 13px;
    white-space: nowrap;
    font-size: 0.76rem;
    line-height: 1;
  }

  /* The bottom row now contains only the primary Start button. */
  .start-actions {
    display: block;
    margin-top: 12px;
  }

  .start-actions #startBtn {
    width: 100%;
  }
}

/* Give very narrow phones a little more breathing room without hiding controls. */
@media (max-width: 380px) {
  .start-actions .game-hub-link {
    left: 10px;
    padding-inline: 9px !important;
    font-size: 0.72rem;
  }

  .menu-top-actions {
    gap: 6px;
  }

  .leaderboard-corner-btn {
    padding-inline: 10px;
    font-size: 0.72rem;
  }
}
