/* ── CORE & RESET ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
:root {
  --primary: #00d4ff;
  --secondary: #ff006e;
  --accent: #ffb703;
  --success: #00f5a0;
  --error: #ff4757;
  --dark: #0f172a;
  --darker: #020617;
  --glass: rgba(255, 255, 255, 0.05);
  --neon-glow: 0 0 20px rgba(0, 212, 255, 0.5);
  --enter-color: #00c9a7;
  --clear-color: #ff006e;
  --gold: #ffd700;
  --gold-glow: rgba(255, 215, 0, 0.35);
  --silver: #c0c8d4;
  --silver-glow: rgba(192, 200, 212, 0.3);
  --bronze: #cd7f32;
  --bronze-glow: rgba(205, 127, 50, 0.3);
}

body {
  font-family:
    "Kanit",
    system-ui,
    -apple-system,
    sans-serif;
  background: linear-gradient(
    135deg,
    var(--darker) 0%,
    var(--dark) 50%,
    #1e293b 100%
  );
  min-height: 100vh;
  min-height: 100dvh;
  color: white;
  overflow-x: hidden;
  position: relative;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ── BACKGROUND ANIMATION ── */
.bg-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.bg-animation::before {
  content: "";
  position: absolute;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(
      circle at 20% 50%,
      rgba(0, 212, 255, 0.15) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(255, 0, 110, 0.15) 0%,
      transparent 50%
    );
  animation: bgMove 20s ease-in-out infinite;
}
@keyframes bgMove {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-5%, -5%);
  }
}
.grid-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
  background-size: 50px 50px;
}

/* ── PAGE ROUTING ── */
.page {
  display: none;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  z-index: 10;
  flex-direction: column;
}
.page.active {
  display: flex;
}

.app-container {
  width: 100%;
}
.game-container {
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}
.ranking-container {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 40px;
  width: 100%;
}

/* ── STATUS BANNER ── */
.status-banner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  transform: translateY(-100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.status-banner.show {
  transform: translateY(0);
}
.status-banner.warning {
  background: rgba(255, 183, 3, 0.15);
  border-bottom: 1px solid rgba(255, 183, 3, 0.3);
  color: #ffb703;
}
.status-banner.error {
  background: rgba(255, 71, 87, 0.15);
  border-bottom: 1px solid rgba(255, 71, 87, 0.3);
  color: #ff6b81;
}
.status-banner.success {
  background: rgba(0, 245, 160, 0.15);
  border-bottom: 1px solid rgba(0, 245, 160, 0.3);
  color: var(--success);
}
.status-banner .banner-icon {
  font-size: 1rem;
  flex-shrink: 0;
}
.status-banner .banner-text {
  flex: 1;
  text-align: center;
}
.status-banner .banner-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.status-banner .banner-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── SHARED COMPONENTS ── */
.back-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.back-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--primary);
  transform: scale(1.05);
}
.back-btn:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN MENU PAGE — Soft Cartoon Redesign
   Pastel palette, chunky shadows, bouncy animations
   ═══════════════════════════════════════════════════════════════ */

.app-container {
  --menu-peach: #FFB5A0;
  --menu-pink: #FF8FB5;
  --menu-pink-soft: #FFBBD2;
  --menu-lavender: #B8A5FF;
  --menu-lavender-soft: #DBCCFF;
  --menu-sky: #7ED7FF;
  --menu-sky-soft: #B8E8FF;
  --menu-mint: #7FDCC0;
  --menu-sun: #FFD93D;
  --menu-sun-soft: #FFE89C;
  --menu-ink: #3A3555;
  --menu-ink-soft: #6B6488;
  --menu-ink-faint: #9D97B8;

  --bounce: cubic-bezier(0.68, -0.3, 0.27, 1.55);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  /* Opaque pastel background covers the dark bg-animation behind */
  background:
    radial-gradient(circle at 15% 10%, #FFD4E5 0%, transparent 45%),
    radial-gradient(circle at 85% 20%, #C8DFFF 0%, transparent 45%),
    radial-gradient(circle at 70% 85%, #D4F4E4 0%, transparent 50%),
    radial-gradient(circle at 20% 80%, #FFE5CC 0%, transparent 45%),
    linear-gradient(160deg, #FFE9F1, #E4EEFF);
  color: var(--menu-ink);
  font-family: "Mali", "Kanit", system-ui, sans-serif;
  font-weight: 500;
  overflow-x: hidden;
}
/* Center direct children of the menu page within a 500px column */
.app-container > .game-header,
.app-container > .login-status,
.app-container > .main-menu {
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

/* Floating decorations — populated by JS */
.menu-deco {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.menu-deco-item {
  position: absolute;
  animation: menuFloat 8s ease-in-out infinite;
  filter: drop-shadow(0 4px 12px rgba(255, 143, 181, 0.18));
}
@keyframes menuFloat {
  0%, 100% { transform: translateY(0) rotate(var(--r, 0deg)); }
  50% { transform: translateY(-18px) rotate(calc(var(--r, 0deg) + 8deg)); }
}
.menu-deco .cloud {
  background: white;
  width: 80px;
  height: 32px;
  border-radius: 100px;
  position: relative;
  opacity: 0.6;
}
.menu-deco .cloud::before,
.menu-deco .cloud::after {
  content: "";
  position: absolute;
  background: white;
  border-radius: 50%;
}
.menu-deco .cloud::before { width: 32px; height: 32px; top: -14px; left: 14px; }
.menu-deco .cloud::after { width: 44px; height: 44px; top: -22px; right: 12px; }

/* ═══ LANG TOGGLE (pill style) ═══ */
.lang-toggle {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: 100px;
  background: white;
  border: none;
  overflow: visible;
  font-size: 0.75rem;
  z-index: 10;
  align-self: flex-end;
  box-shadow:
    0 3px 0 rgba(184, 165, 255, 0.15),
    0 6px 16px rgba(184, 165, 255, 0.18);
}
.lang-btn {
  position: relative;
  padding: 7px 14px;
  background: transparent;
  color: var(--menu-ink-faint);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  border-radius: 100px;
  transition: color 0.3s ease, transform 0.2s var(--bounce);
  z-index: 2;
  line-height: 1;
}
.lang-btn.active {
  color: white;
  background: linear-gradient(135deg, var(--menu-pink), var(--menu-lavender));
  box-shadow: 0 3px 8px rgba(255, 143, 181, 0.35);
}
.lang-btn:active { transform: scale(0.92); }

/* ═══ GAME HEADER / LOGO ═══ */
.game-header {
  text-align: center;
  padding: max(10px, env(safe-area-inset-top)) 10px 16px;
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.game-header .lang-toggle {
  align-self: flex-end;
  margin-bottom: 20px;
  animation: dropIn 0.6s var(--spring) both;
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo-wrap {
  position: relative;
  display: inline-block;
  align-self: center;
  animation: headerPop 0.8s var(--spring) both;
}
@keyframes headerPop {
  from { opacity: 0; transform: scale(0.85) translateY(14px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.logo {
  display: inline-block;
  font-family: "Fredoka", "Mali", sans-serif;
  font-size: clamp(2.6rem, 10vw, 3.8rem);
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 0.95;
  background: linear-gradient(
    100deg,
    #FF8FB5 0%,
    #B8A5FF 35%,
    #7ED7FF 65%,
    #7FDCC0 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter:
    drop-shadow(0 5px 0 rgba(184, 165, 255, 0.25))
    drop-shadow(0 10px 25px rgba(255, 143, 181, 0.3));
  animation: logoWobble 4s ease-in-out infinite;
  text-transform: none;
}
@keyframes logoWobble {
  0%, 100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg); }
}

/* Sparkles around logo */
.logo-sparkle {
  position: absolute;
  animation: sparkleBlink 2.4s ease-in-out infinite;
  pointer-events: none;
}
.logo-sparkle svg { width: 100%; height: 100%; display: block; }
.logo-sparkle.s1 {
  width: 18px; height: 18px;
  top: -8px; right: -6px;
  color: var(--menu-sun);
  animation-delay: 0s;
}
.logo-sparkle.s2 {
  width: 14px; height: 14px;
  top: 45%; left: -18px;
  color: var(--menu-pink);
  animation-delay: 0.8s;
}
.logo-sparkle.s3 {
  width: 12px; height: 12px;
  bottom: -5px; right: 20%;
  color: var(--menu-lavender);
  animation-delay: 1.6s;
}
@keyframes sparkleBlink {
  0%, 100% { transform: scale(0.6) rotate(0); opacity: 0.3; }
  50% { transform: scale(1.15) rotate(180deg); opacity: 1; }
}

.subtitle {
  font-family: "Mali", sans-serif;
  color: var(--menu-ink-soft);
  font-size: 0.9rem;
  margin-top: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: none;
  animation: dropIn 0.7s var(--spring) 0.2s both;
}

/* ═══ LOGIN STATUS ═══ */
.login-status {
  text-align: center;
  padding: 4px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  margin-top: 8px;
  position: relative;
  z-index: 2;
  animation: dropIn 0.7s var(--spring) 0.3s both;
}
.login-status span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 100px;
  background: white;
  color: var(--menu-ink);
  box-shadow:
    0 3px 0 rgba(126, 215, 255, 0.3),
    0 6px 18px rgba(126, 215, 255, 0.2);
  transition: transform 0.25s var(--bounce);
}
.login-status:active span { transform: scale(0.94); }
.login-status.logged-in span {
  background: white;
  color: var(--menu-ink);
}
.login-status.logged-in span::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--menu-mint);
  box-shadow: 0 0 0 3px rgba(127, 220, 192, 0.3);
  animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 3px rgba(127, 220, 192, 0.3); }
  50% { transform: scale(1.2); box-shadow: 0 0 0 5px rgba(127, 220, 192, 0.15); }
}
.menu-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  flex-shrink: 0;
  overflow: hidden;
  color: white;
  border: 1.5px solid rgba(255,255,255,0.4);
  cursor: pointer;
}
.menu-avatar:empty { display: none; }
.menu-avatar.has-image { background: none; }
.menu-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
/* hide the green dot when avatar is shown */
.login-status.logged-in span:has(.menu-avatar:not(:empty))::before { display: none; }

/* ═══ MAIN MENU ═══ */
.main-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 0 16px;
  gap: 14px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  z-index: 2;
}

/* ═══ MENU BUTTONS ═══ */
.menu-button {
  --c1: var(--menu-sky);
  --c2: var(--menu-sky-soft);
  --shadow-color: rgba(126, 215, 255, 0.35);

  position: relative;
  width: 100%;
  padding: 18px 20px;
  border-radius: 24px;
  background: white;
  border: 3px solid rgba(255, 255, 255, 0.9);
  color: var(--menu-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: inherit;
  text-align: left;
  overflow: visible;
  box-shadow:
    0 5px 0 var(--shadow-color),
    0 12px 25px var(--shadow-color);
  transition:
    transform 0.25s var(--bounce),
    box-shadow 0.25s var(--bounce),
    border-color 0.2s ease;
  opacity: 0;
  transform: translateY(24px) scale(0.9);
  animation: menuPopIn 0.7s var(--spring) forwards;
}
.menu-button:nth-of-type(1) { animation-delay: 0.2s; }
.menu-button:nth-of-type(2) { animation-delay: 0.3s; }
.menu-button:nth-of-type(3) { animation-delay: 0.4s; }
.menu-button:nth-of-type(4) { animation-delay: 0.5s; }

@keyframes menuPopIn {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.menu-button:active {
  transform: translateY(3px) scale(0.98);
  box-shadow:
    0 2px 0 var(--shadow-color),
    0 5px 12px var(--shadow-color);
  transition-duration: 0.1s;
}

.menu-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  box-shadow:
    0 4px 0 color-mix(in srgb, var(--c1) 45%, transparent),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  color: white;
  position: relative;
  transition: transform 0.3s var(--bounce);
}
.menu-icon svg {
  width: 28px; height: 28px;
  stroke: white;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.12));
}
.menu-button:active .menu-icon {
  transform: rotate(-8deg) scale(0.92);
}

.menu-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}
.menu-label {
  font-family: "Fredoka", "Mali", sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--menu-ink);
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
}
.menu-desc {
  font-family: "Mali", sans-serif;
  font-size: 0.82rem;
  color: var(--menu-ink-soft);
  font-weight: 400;
}

.menu-arrow {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c1) 20%, white);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c1);
  flex-shrink: 0;
  transition: all 0.3s var(--bounce);
}
.menu-arrow svg {
  width: 14px; height: 14px;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Per-button accent colors */
.btn-player   { --c1: #7ED7FF; --c2: #B8E8FF; --shadow-color: rgba(126, 215, 255, 0.35); }
.btn-settings { --c1: #FF8FB5; --c2: #FFBBD2; --shadow-color: rgba(255, 143, 181, 0.35); }
.btn-stats    { --c1: #FFD93D; --c2: #FFE89C; --shadow-color: rgba(255, 217, 61, 0.35); }
.btn-ranking  { --c1: #B8A5FF; --c2: #DBCCFF; --shadow-color: rgba(184, 165, 255, 0.4); }

/* ═══ START GAME BUTTON ═══ */
.start-game-btn {
  position: relative;
  width: 100%;
  padding: 22px;
  margin-top: 18px;
  border: none;
  border-radius: 28px;
  background: linear-gradient(
    100deg,
    #FF8FB5 0%,
    #B8A5FF 50%,
    #7ED7FF 100%
  );
  background-size: 200% 100%;
  color: white;
  font-family: "Fredoka", "Mali", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition:
    transform 0.25s var(--bounce),
    box-shadow 0.25s var(--bounce);
  animation:
    menuPopIn 0.7s var(--spring) 0.65s both,
    candyShift 4s ease-in-out infinite;
  box-shadow:
    0 6px 0 rgba(184, 108, 164, 0.45),
    0 14px 30px rgba(184, 108, 164, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
  text-shadow: 0 2px 3px rgba(160, 80, 140, 0.25);
}
.start-game-btn > span:first-child {
  position: relative;
  z-index: 2;
}
.start-game-btn .play-icon {
  position: relative;
  z-index: 2;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: playBounce 1.4s ease-in-out infinite;
}
.start-game-btn .play-icon svg {
  width: 14px;
  height: 14px;
  fill: white;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
  margin-left: 2px;
}
@keyframes playBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15) rotate(-8deg); }
}
@keyframes candyShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.start-game-btn::before {
  content: "";
  position: absolute;
  top: 8%;
  left: 5%;
  right: 5%;
  height: 30%;
  border-radius: 100px;
  background: linear-gradient(180deg, rgba(255,255,255,0.45), transparent);
  pointer-events: none;
  opacity: 1;
  transition: none;
}
.start-game-btn:active {
  transform: translateY(4px) scale(0.97);
  box-shadow:
    0 2px 0 rgba(184, 108, 164, 0.45),
    0 6px 12px rgba(184, 108, 164, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.3);
  transition-duration: 0.1s;
}
.btn-outline-secondary {
  background: rgba(255, 0, 110, 0.12) !important;
  border: 1.5px solid rgba(255, 0, 110, 0.4) !important;
  box-shadow: none !important;
  color: #ff6b9d !important;
}

.btn-delete-account {
  background: transparent !important;
  border: 1px solid rgba(255, 50, 50, 0.25) !important;
  box-shadow: none !important;
  color: rgba(255, 100, 100, 0.5) !important;
  font-size: 0.85rem !important;
  margin-top: 8px;
}
.btn-delete-account:hover {
  background: rgba(255, 50, 50, 0.1) !important;
  color: #ff4444 !important;
}

/* ── SCREENS / MODALS ── */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active {
  transform: translateX(0);
}
.screen-header {
  padding: max(20px, env(safe-area-inset-top)) 20px 20px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 15px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.screen-title {
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.screen-content {
  flex: 1;
  padding: 25px 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.level-section {
  margin-bottom: 30px;
}
.section-title {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.current-level {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.2rem;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.level-btn {
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.level-btn:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}
.level-btn::after {
  content: "";
  position: absolute;
  bottom: 8px;
  width: 20px;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
}
.level-btn[data-level="0"] {
  color: #86efac;
}
.level-btn[data-level="1"] {
  color: #4ade80;
}
.level-btn[data-level="2"] {
  color: #34d399;
}
.level-btn[data-level="3"] {
  color: #2dd4bf;
}
.level-btn[data-level="4"] {
  color: #38bdf8;
}
.level-btn[data-level="5"] {
  color: #818cf8;
}
.level-btn[data-level="6"] {
  color: #a78bfa;
}
.level-btn[data-level="7"] {
  color: #f472b6;
}
.level-btn[data-level="8"] {
  color: #fb7185;
}
.level-btn.active {
  transform: scale(1.05);
  box-shadow: 0 0 20px currentColor;
  border-color: currentColor;
  background: rgba(255, 255, 255, 0.1);
}
.level-btn.active::after {
  opacity: 1;
  box-shadow: 0 0 10px currentColor;
}
.level-label {
  font-size: 0.6rem;
  opacity: 0.7;
  text-transform: uppercase;
}

.difficulty-info {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 15px;
  margin-top: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.3s ease;
}
.difficulty-icon {
  font-size: 1.5rem;
}
.difficulty-text {
  flex: 1;
}
.difficulty-name {
  font-weight: 700;
  margin-bottom: 2px;
}
.difficulty-desc {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
}

.setting-item {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.setting-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.setting-title {
  font-weight: 600;
  font-size: 1rem;
}
.setting-desc {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
}
.toggle {
  width: 55px;
  height: 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}
.toggle.active {
  background: var(--primary);
  border-color: var(--primary);
}
.toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.toggle.active .toggle-slider {
  transform: translateX(25px);
}

.player-card {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.player-avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 900;
  border: 3px solid rgba(255, 255, 255, 0.2);
}
/* ── Avatar Upload ── */
.avatar-upload-wrapper {
  position: relative;
  flex-shrink: 0;
}
.player-avatar.has-image {
  background-size: cover;
  background-position: center;
  background-color: transparent;
}
.avatar-upload-label {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 30px;
  height: 30px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}
/* ── First-login Photo Prompt ── */
.first-photo-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding-top: 40px;
}
.first-photo-desc {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.95rem;
  text-align: center;
  margin: 0;
}
.first-photo-avatar-wrap {
  position: relative;
  cursor: pointer;
  margin: 10px 0;
}
.first-photo-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  font-weight: 900;
  border: 4px solid rgba(255, 255, 255, 0.15);
  transition: opacity 0.2s;
}
.first-photo-avatar-wrap:active .first-photo-avatar {
  opacity: 0.8;
}
.first-photo-camera {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 34px;
  height: 34px;
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.first-photo-skip {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px;
  text-decoration: underline;
}
/* ── Edit Profile ── */
.edit-profile-form {
  display: none;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 15px;
}
.edit-profile-form.active {
  display: flex;
}
.edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.edit-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.5px;
}
.edit-field input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: white;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
.edit-field input:focus {
  border-color: var(--primary);
  background: rgba(0, 212, 255, 0.06);
}
.edit-btn-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.edit-btn-row button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.btn-save-profile {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
}
.btn-cancel-edit {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: rgba(255, 255, 255, 0.7);
}
.btn-edit-profile {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 10px;
}
.btn-edit-profile:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--primary);
}
.stat-card {
  background: linear-gradient(
    135deg,
    rgba(0, 212, 255, 0.1),
    rgba(255, 0, 110, 0.1)
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 15px;
  text-align: center;
  transition: transform 0.2s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.stat-number {
  font-size: 2.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.stats-grid .stat-card {
  margin-bottom: 0;
  padding: 16px 12px;
}
.stats-grid .stat-number {
  font-size: 1.6rem;
}
.stat-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.75rem;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.stat-icon {
  font-size: 1.4rem;
  margin-bottom: 6px;
}
.stat-section-title {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 20px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.level-stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  margin-bottom: 8px;
}
.level-stat-badge {
  min-width: 48px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  background: rgba(0, 212, 255, 0.15);
  color: var(--primary);
}
.level-stat-info {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.6);
}
.level-stat-info span {
  white-space: nowrap;
}
.level-stat-info strong {
  color: rgba(255, 255, 255, 0.9);
}
.stats-login-msg {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255, 255, 255, 0.5);
}
.stats-login-msg .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}
.stats-loading {
  text-align: center;
  padding: 40px;
  color: rgba(255, 255, 255, 0.4);
}

/* ── CUSTOM CONFIRM MODAL ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 20px;
}
.confirm-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.confirm-card {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 28px 24px 20px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  transform: scale(0.9) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.confirm-overlay.show .confirm-card {
  transform: scale(1) translateY(0);
}
.confirm-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}
.confirm-msg {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 24px;
  line-height: 1.5;
}
.confirm-buttons {
  display: flex;
  gap: 12px;
}
.confirm-btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.confirm-btn.cancel {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.confirm-btn.cancel:hover {
  background: rgba(255, 255, 255, 0.12);
}
.confirm-btn.ok {
  background: linear-gradient(135deg, var(--primary), #0088cc);
  color: white;
}
.confirm-btn.ok:hover {
  filter: brightness(1.1);
}
/* ── AUTH FORMS ── */
.auth-field {
  margin-bottom: 14px;
  flex: 1;
}
.auth-label {
  display: block;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.auth-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.auth-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
}
.auth-input:focus {
  border-color: var(--primary);
  background: rgba(0, 212, 255, 0.05);
  box-shadow:
    0 0 0 3px rgba(0, 212, 255, 0.1),
    0 0 20px rgba(0, 212, 255, 0.05);
}
.password-wrap {
  position: relative;
}
.password-wrap .auth-input {
  padding-right: 48px;
}
.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
}
.password-toggle:hover {
  color: rgba(255, 255, 255, 0.7);
}
.auth-row {
  display: flex;
  gap: 12px;
}
.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.5);
}
.auth-switch span {
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}
.auth-switch span:hover {
  text-decoration: underline;
}
.auth-loading {
  opacity: 0.6;
  pointer-events: none;
}

/* ── GAME PAGE ── */
.progress-wrap {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 0 3px 3px 0;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.5);
}

.game-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
  flex-shrink: 0;
}
.level-badge {
  font-family: "Orbitron", sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(0, 212, 255, 0.4);
  background: rgba(0, 212, 255, 0.1);
  color: var(--primary);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.3;
}
.level-badge .level-name {
  display: block;
  font-size: 0.55rem;
  opacity: 0.7;
  letter-spacing: 1px;
}
.timer-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.timer-label,
.score-label {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.timer-value {
  font-family: "Orbitron", sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 65px;
  text-align: center;
  transition: color 0.3s;
}
.timer-value.warning {
  color: var(--accent);
}
.timer-value.danger {
  color: var(--error);
  animation: timerPulse 0.5s ease-in-out infinite;
}
@keyframes timerPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}
.score-area {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.score-value {
  font-family: "Orbitron", sans-serif;
  font-size: 1.6rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), #ff6b35);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  min-width: 60px;
  text-align: right;
}

/* ── Mini avatars shared across game / ranking / stats headers ── */
.game-top-avatar,
.header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
  color: white;
}
.game-top-avatar:empty,
.header-avatar:empty { display: none; }
.screen-header .header-avatar { margin-left: auto; }
.game-top-avatar.has-image,
.header-avatar.has-image {
  background: none;
  border-color: rgba(255, 255, 255, 0.25);
}
.game-top-avatar img,
.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* ── Ranking top-right wrapper ── */
.ranking-top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* ── Row avatar image support ── */
.row-avatar.has-image {
  background: none;
  border-color: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}
.row-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* ── Stats profile header ── */
.stats-profile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  margin-bottom: 18px;
}
.stats-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 900;
  flex-shrink: 0;
  border: 3px solid rgba(255,255,255,0.15);
  overflow: hidden;
  color: white;
}
.stats-avatar.has-image {
  background: none;
  border-color: rgba(255,255,255,0.25);
}
.stats-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.stats-profile-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  letter-spacing: 0.3px;
}

.question-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  gap: 16px;
  position: relative;
}
.question-counter {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 1px;
}
.question-counter span {
  color: var(--primary);
  font-weight: 700;
}
.per-question-bar {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.per-question-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--success), var(--primary));
  border-radius: 2px;
  transition:
    width 0.2s linear,
    background 0.3s;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.3);
}
.per-question-fill.warning {
  background: linear-gradient(90deg, var(--accent), #ff6b35);
}
.per-question-fill.danger {
  background: linear-gradient(90deg, var(--error), var(--secondary));
}

.equation-wrap {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 22px 24px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  position: relative;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 90px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.equation-wrap.correct {
  border-color: var(--success);
  background: rgba(0, 245, 160, 0.08);
  box-shadow: 0 0 30px rgba(0, 245, 160, 0.2);
}
.equation-wrap.wrong {
  border-color: var(--error);
  background: rgba(255, 71, 87, 0.08);
  animation: shake 0.5s ease;
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-12px);
  }
  40% {
    transform: translateX(10px);
  }
  60% {
    transform: translateX(-8px);
  }
  80% {
    transform: translateX(6px);
  }
}

.eq-token {
  font-family: "Orbitron", sans-serif;
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1;
}
.eq-token.op {
  color: rgba(255, 255, 255, 0.4);
}
.eq-token.paren {
  color: rgba(255, 255, 255, 0.25);
}
.eq-token.eq-sign {
  color: rgba(255, 255, 255, 0.5);
}
.eq-token.result-num {
  color: var(--accent);
}

.input-slot {
  position: relative;
  min-width: 58px;
  height: 54px;
  border-radius: 14px;
  border: 2px solid var(--primary);
  background: rgba(0, 212, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: slotPulse 2s ease-in-out infinite;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.15);
  transition: all 0.3s;
  padding: 0 10px;
}
.input-slot.has-value {
  animation: none;
}
.input-slot.correct-slot {
  border-color: var(--success);
  background: rgba(0, 245, 160, 0.15);
  box-shadow: 0 0 20px rgba(0, 245, 160, 0.3);
}
.input-slot.wrong-slot {
  border-color: var(--error);
  background: rgba(255, 71, 87, 0.15);
  box-shadow: 0 0 20px rgba(255, 71, 87, 0.3);
}
@keyframes slotPulse {
  0%,
  100% {
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.15);
    border-color: var(--primary);
  }
  50% {
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.35);
    border-color: #66e3ff;
  }
}
.input-value {
  font-family: "Orbitron", sans-serif;
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 900;
  color: var(--primary);
  text-align: center;
}
.cursor-blink {
  width: 3px;
  height: 28px;
  background: var(--primary);
  border-radius: 2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.feedback {
  min-height: 30px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
}
.feedback.show {
  opacity: 1;
  transform: translateY(0);
}
.feedback.correct-fb {
  color: var(--success);
}
.feedback.wrong-fb {
  color: var(--error);
}
.floating-score {
  position: absolute;
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--accent);
  pointer-events: none;
  animation: floatUp 1.2s ease-out forwards;
  text-shadow: 0 0 20px rgba(255, 183, 3, 0.5);
  z-index: 50;
}
@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  60% {
    opacity: 1;
    transform: translateY(-50px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-90px) scale(0.8);
  }
}

.numpad-area {
  flex-shrink: 0;
  padding: 10px 16px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 360px;
  margin: 0 auto;
}
.num-btn {
  height: 62px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: white;
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.num-btn:active {
  transform: scale(0.93);
  background: rgba(255, 255, 255, 0.15);
}
.num-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0);
  animation: ripple 0.5s ease-out forwards;
  pointer-events: none;
}
@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}
.num-btn.clear-btn {
  background: rgba(255, 0, 110, 0.12);
  border-color: rgba(255, 0, 110, 0.25);
  color: var(--clear-color);
  font-size: 1.6rem;
}
.num-btn.clear-btn:active {
  background: rgba(255, 0, 110, 0.25);
}
.num-btn.enter-btn {
  background: linear-gradient(
    135deg,
    rgba(0, 201, 167, 0.2),
    rgba(0, 245, 160, 0.15)
  );
  border-color: rgba(0, 201, 167, 0.35);
  color: var(--enter-color);
  font-family: "Kanit", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 2px;
}
.num-btn.enter-btn:active {
  background: linear-gradient(
    135deg,
    rgba(0, 201, 167, 0.35),
    rgba(0, 245, 160, 0.3)
  );
}

.game-ready-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 20px;
}
.game-ready-overlay.show {
  opacity: 1;
  pointer-events: all;
}
.game-ready-card {
  text-align: center;
  padding: 40px 28px 36px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  max-width: 360px;
  width: 100%;
  transform: scale(0.85) translateY(20px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    0 25px 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.game-ready-overlay.show .game-ready-card {
  transform: scale(1) translateY(0);
}
.ready-level {
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  font-weight: 900;
  background: linear-gradient(135deg, #FF8FB5, #B8A5FF, #7ED7FF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 28px;
  letter-spacing: 0.05em;
}
.ready-cancel-btn {
  margin-top: 14px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 20px;
  border-radius: 20px;
  transition: color 0.2s, background 0.2s;
}
.ready-cancel-btn:hover {
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.07);
}
.game-over-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 20px;
}
.game-over-overlay.show {
  opacity: 1;
  pointer-events: all;
}
.game-over-card {
  text-align: center;
  padding: 40px 30px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  max-width: 380px;
  width: 100%;
  transform: scale(0.8) translateY(20px);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    0 25px 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.game-over-overlay.show .game-over-card {
  transform: scale(1) translateY(0);
}
.go-title {
  font-family: "Orbitron", sans-serif;
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 25px;
}
.go-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 30px;
}
.go-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}
.go-stat-label {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.5);
}
.go-stat-value {
  font-family: "Orbitron", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}
.go-buttons {
  display: flex;
  gap: 12px;
}
.go-btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-family: "Kanit", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
}
.go-btn:active {
  transform: scale(0.96);
  transition-duration: 0.1s;
}
.go-btn.retry {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 4px 20px rgba(0, 212, 255, 0.3);
}
.go-btn.retry:hover {
  box-shadow: 0 6px 30px rgba(0, 212, 255, 0.5);
  transform: translateY(-2px);
}
.go-btn.menu-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: white;
}
.go-btn.menu-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

/* ── NEW PERSONAL BEST BADGE ── */
.new-best-badge {
  background: linear-gradient(
    135deg,
    rgba(255, 215, 0, 0.15),
    rgba(255, 183, 3, 0.1)
  );
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 20px;
  text-align: center;
  animation:
    bestPulse 2s ease-in-out infinite,
    slideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes bestPulse {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.1);
  }
  50% {
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.25);
  }
}
.new-best-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 4px;
}
.new-best-desc {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.5);
}
.new-best-prev {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.35);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
/* ── RANKING PAGE ── */
.ranking-top-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 20px 16px;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title {
  font-family: "Orbitron", sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.player-count {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 1px;
  font-family: "Orbitron", sans-serif;
}
.filter-section {
  padding: 16px 20px 8px;
}
.level-filter {
  width: 100%;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: white;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2300d4ff' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
}
.level-filter:focus {
  outline: none;
  border-color: rgba(0, 212, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.12);
}
.level-filter option {
  background: #1e293b;
  color: white;
  padding: 8px;
}

.podium-section {
  padding: 28px 20px 10px;
}
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  height: 240px;
  position: relative;
}
.podium-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: podiumRise 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes podiumRise {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.podium-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  position: relative;
  z-index: 2;
}
.podium-player.rank-1 .podium-avatar {
  width: 80px;
  height: 80px;
  font-size: 1.8rem;
  background: linear-gradient(135deg, #ffd700, #f59e0b);
  border: 3px solid var(--gold);
  box-shadow:
    0 0 25px var(--gold-glow),
    0 0 60px rgba(255, 215, 0, 0.15);
}
.podium-player.rank-2 .podium-avatar {
  background: linear-gradient(135deg, #94a3b8, #c0c8d4);
  border: 3px solid var(--silver);
  box-shadow: 0 0 20px var(--silver-glow);
}
.podium-player.rank-3 .podium-avatar {
  background: linear-gradient(135deg, #b45309, #cd7f32);
  border: 3px solid var(--bronze);
  box-shadow: 0 0 20px var(--bronze-glow);
}
.podium-crown {
  position: absolute;
  top: -18px;
  font-size: 1.2rem;
  z-index: 3;
  filter: drop-shadow(0 2px 6px rgba(255, 215, 0, 0.5));
  animation: crownBob 3s ease-in-out infinite;
}
@keyframes crownBob {
  0%,
  100% {
    transform: translateY(0) rotate(-3deg);
  }
  50% {
    transform: translateY(-4px) rotate(3deg);
  }
}
.podium-name {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.podium-player.rank-1 .podium-name {
  color: var(--gold);
}
.podium-player.rank-2 .podium-name {
  color: var(--silver);
}
.podium-player.rank-3 .podium-name {
  color: var(--bronze);
}
.podium-score {
  font-family: "Orbitron", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
}
.podium-time {
  font-size: 0.65rem;
  color: var(--primary);
  opacity: 0.6;
  margin-top: 2px;
}
.podium-bar {
  width: 90px;
  border-radius: 12px 12px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 12px;
  position: relative;
  overflow: hidden;
}
.podium-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
}
.podium-player.rank-1 .podium-bar {
  height: 110px;
  width: 100px;
  background: linear-gradient(
    180deg,
    rgba(255, 215, 0, 0.1),
    rgba(255, 215, 0, 0.03)
  );
}
.podium-player.rank-2 .podium-bar {
  height: 80px;
  background: linear-gradient(
    180deg,
    rgba(192, 200, 212, 0.08),
    rgba(192, 200, 212, 0.02)
  );
}
.podium-player.rank-3 .podium-bar {
  height: 60px;
  background: linear-gradient(
    180deg,
    rgba(205, 127, 50, 0.08),
    rgba(205, 127, 50, 0.02)
  );
}
.podium-rank-num {
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  font-weight: 900;
  opacity: 0.25;
  position: relative;
  z-index: 2;
}

.table-section {
  padding: 8px 14px;
}
.table-header {
  display: none;
}
.rank-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 14px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  animation: rowSlideIn 0.4s ease-out both;
}
@keyframes rowSlideIn {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
.rank-row.is-me {
  background: rgba(0, 212, 255, 0.06);
  border-color: rgba(0, 212, 255, 0.2);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.08);
}
.rank-lv {
  font-family: "Orbitron", sans-serif;
  font-size: 0.58rem;
  font-weight: 700;
  flex-shrink: 0;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
}
.row-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(0, 212, 255, 0.3),
    rgba(255, 0, 110, 0.3)
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  font-weight: 800;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.1);
}
.rank-name {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.you-tag {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--primary);
}
.rank-score {
  font-family: "Orbitron", sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #ff6b35);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.rank-time {
  font-size: 0.68rem;
  flex-shrink: 0;
  color: var(--primary);
  opacity: 0.7;
  white-space: nowrap;
}
.rank-date {
  font-size: 0.62rem;
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.3);
  white-space: nowrap;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}
.empty-title {
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
}
.empty-desc {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.3);
}

/* ── RESPONSIVE: Short screens ── */
@media (max-height: 650px) {
  .equation-wrap {
    padding: 14px 18px;
    min-height: 70px;
  }
  .num-btn {
    height: 50px;
    font-size: 1.15rem;
    border-radius: 10px;
  }
  .numpad-area {
    padding: 6px 16px 10px;
  }
  .numpad {
    gap: 6px;
  }
  .game-top-bar {
    padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  }
  .question-area {
    padding: 6px 16px;
    gap: 10px;
  }
  .feedback {
    min-height: 24px;
    font-size: 0.85rem;
  }
}

/* ── RESPONSIVE: Very short screens (iPhone SE landscape, etc.) ── */
@media (max-height: 550px) {
  .num-btn {
    height: 42px;
    font-size: 1rem;
  }
  .numpad {
    gap: 5px;
  }
  .equation-wrap {
    padding: 10px 14px;
    min-height: 58px;
    border-radius: 14px;
  }
  .eq-token {
    font-size: 1.1rem !important;
  }
  .input-slot {
    min-width: 46px;
    height: 42px;
    border-radius: 10px;
  }
  .question-counter {
    font-size: 0.75rem;
  }
  .per-question-bar {
    margin-top: 4px;
  }
  .progress-wrap {
    height: 3px;
  }
}

/* ── RESPONSIVE: Small width ── */
@media (max-width: 380px) {
  .level-grid {
    gap: 6px;
  }
  .level-btn {
    font-size: 1rem;
    border-radius: 10px;
  }
  .menu-button {
    padding: 16px 16px;
    gap: 12px;
    border-radius: 20px;
  }
  .menu-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }
  .menu-icon svg { width: 24px; height: 24px; }
  .menu-label {
    font-size: 1rem;
  }
  .menu-desc {
    font-size: 0.76rem;
  }
  .game-header {
    padding: 8px 8px 12px;
  }
  .logo {
    font-size: 2.4rem;
  }
  .subtitle {
    font-size: 0.82rem;
    letter-spacing: 0.5px;
  }
  .numpad {
    gap: 8px;
  }
  .num-btn {
    height: 56px;
    font-size: 1.2rem;
  }
  .podium {
    gap: 8px;
  }
  .podium-bar {
    width: 75px;
  }
  .podium-player.rank-1 .podium-bar {
    width: 85px;
  }
  .rank-row {
    padding: 10px 10px;
    gap: 8px;
    font-size: 0.85rem;
  }
  .row-avatar {
    width: 34px;
    height: 34px;
    font-size: 0.75rem;
  }
}

/* ── RESPONSIVE: Standard mobile ── */
@media (min-width: 381px) and (max-width: 480px) {
  .level-grid {
    gap: 10px;
  }
  .level-btn {
    font-size: 1.15rem;
  }
}

/* ── RESPONSIVE: Tablet (768px+) ── */
@media (min-width: 768px) {
  .game-header {
    padding: 40px 30px 20px;
  }
  .logo {
    font-size: 4.2rem;
  }
  .subtitle {
    font-size: 1rem;
    letter-spacing: 1.5px;
    margin-top: 8px;
  }
  .main-menu {
    max-width: 480px;
    padding: 20px 30px 40px;
    gap: 16px;
  }
  .menu-button {
    padding: 22px 24px;
    border-radius: 26px;
    gap: 18px;
  }
  .menu-icon {
    width: 62px;
    height: 62px;
    border-radius: 20px;
  }
  .menu-icon svg {
    width: 32px;
    height: 32px;
  }
  .menu-label {
    font-size: 1.2rem;
  }
  .menu-desc {
    font-size: 0.85rem;
  }
  .start-game-btn {
    padding: 24px;
    font-size: 1.5rem;
    border-radius: 30px;
  }
  .login-status span {
    font-size: 0.95rem;
    padding: 10px 22px;
  }

  /* Game page tablet */
  .game-container {
    max-width: 560px;
  }
  .game-top-bar {
    padding: max(16px, env(safe-area-inset-top)) 24px 16px;
  }
  .level-badge {
    font-size: 0.8rem;
    padding: 8px 18px;
  }
  .timer-value {
    font-size: 1.3rem;
  }
  .score-value {
    font-size: 1.8rem;
  }
  .question-area {
    padding: 16px 28px;
    gap: 20px;
  }
  .equation-wrap {
    padding: 28px 32px;
    border-radius: 24px;
    min-height: 100px;
  }
  .eq-token {
    font-size: 2.2rem !important;
  }
  .input-slot {
    min-width: 68px;
    height: 62px;
    border-radius: 16px;
  }
  .numpad-area {
    padding: 14px 24px 28px;
  }
  .numpad {
    max-width: 420px;
    gap: 12px;
  }
  .num-btn {
    height: 72px;
    font-size: 1.6rem;
    border-radius: 16px;
  }

  /* Screens tablet */
  .screen-content {
    max-width: 540px;
    padding: 30px 28px;
  }
  .screen-header {
    padding: 22px 28px;
  }
  .screen-title {
    font-size: 1.5rem;
  }
  .level-grid {
    gap: 14px;
  }
  .level-btn {
    font-size: 1.4rem;
    border-radius: 14px;
  }
  .setting-item {
    padding: 22px 24px;
    border-radius: 18px;
  }
  .auth-input {
    padding: 16px 18px;
    font-size: 1.05rem;
    border-radius: 14px;
  }

  /* Ranking tablet */
  .ranking-container {
    max-width: 700px;
  }
  .podium {
    height: 280px;
    gap: 20px;
  }
  .podium-avatar {
    width: 70px;
    height: 70px;
  }
  .podium-player.rank-1 .podium-avatar {
    width: 88px;
    height: 88px;
    font-size: 2rem;
  }
  .podium-bar {
    width: 110px;
  }
  .podium-player.rank-1 .podium-bar {
    width: 130px;
    height: 130px;
  }
  .podium-player.rank-2 .podium-bar {
    height: 95px;
  }
  .podium-player.rank-3 .podium-bar {
    height: 70px;
  }
  .podium-name {
    font-size: 0.92rem;
    max-width: 120px;
  }
  .rank-row {
    padding: 14px 18px;
    border-radius: 16px;
    gap: 14px;
  }
  .row-avatar {
    width: 46px;
    height: 46px;
    font-size: 0.92rem;
  }
  .rank-name {
    font-size: 0.95rem;
  }
  .rank-score {
    font-size: 1rem;
  }

  /* Game over tablet */
  .game-over-card {
    max-width: 440px;
    padding: 48px 36px;
    border-radius: 28px;
  }
  .go-title {
    font-size: 2.2rem;
  }
  .go-stat {
    padding: 16px 22px;
  }
  .go-btn {
    padding: 18px;
    font-size: 1.1rem;
    border-radius: 16px;
  }

  /* Confirm modal tablet */
  .confirm-card {
    max-width: 380px;
    padding: 32px 28px 24px;
    border-radius: 24px;
  }
}

/* ── RESPONSIVE: Desktop (1024px+) ── */
@media (min-width: 1024px) {
  .game-header {
    padding: 50px 40px 24px;
  }
  .logo {
    font-size: 4.6rem;
    letter-spacing: -2px;
  }
  .subtitle {
    font-size: 1.05rem;
    letter-spacing: 1.5px;
  }
  .main-menu {
    max-width: 520px;
    gap: 18px;
  }
  .menu-button {
    transition:
      transform 0.3s var(--bounce),
      box-shadow 0.3s var(--bounce),
      border-color 0.2s ease;
  }
  .menu-button:hover {
    transform: translateY(-3px) rotate(-0.5deg);
    box-shadow:
      0 8px 0 var(--shadow-color),
      0 16px 30px var(--shadow-color);
    border-color: var(--c2);
  }
  .menu-button:hover .menu-icon {
    animation: iconWiggle 0.5s ease;
  }
  .menu-button:hover .menu-arrow {
    background: var(--c1);
    color: white;
    transform: translateX(4px);
  }
  @keyframes iconWiggle {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-8deg); }
    75% { transform: rotate(8deg); }
  }
  .start-game-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow:
      0 9px 0 rgba(184, 108, 164, 0.45),
      0 18px 36px rgba(184, 108, 164, 0.4),
      inset 0 2px 0 rgba(255, 255, 255, 0.5);
  }

  /* Level buttons hover */
  .level-btn {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .level-btn:hover:not(.active) {
    transform: scale(1.05);
    border-color: currentColor;
    background: rgba(255, 255, 255, 0.06);
  }

  /* Ranking desktop */
  .ranking-container {
    max-width: 780px;
  }
  .ranking-top-bar {
    padding: max(20px, env(safe-area-inset-top)) 28px 20px;
  }
  .page-title {
    font-size: 1.3rem;
  }
  .podium {
    height: 300px;
    gap: 28px;
  }
  .rank-row {
    transition: all 0.2s ease;
  }
  .rank-row:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(4px);
  }
  .rank-row.is-me:hover {
    background: rgba(0, 212, 255, 0.1);
  }

  /* Game page desktop */
  .game-container {
    max-width: 600px;
  }
  .num-btn {
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .num-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
  }
  .num-btn.enter-btn:hover {
    background: linear-gradient(
      135deg,
      rgba(0, 201, 167, 0.35),
      rgba(0, 245, 160, 0.3)
    );
    transform: translateY(-2px);
  }
  .num-btn.clear-btn:hover {
    background: rgba(255, 0, 110, 0.2);
    transform: translateY(-2px);
  }

  /* Stats desktop */
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ── RESPONSIVE: Wide Desktop (1440px+) ── */
@media (min-width: 1440px) {
  .ranking-container {
    max-width: 860px;
  }
  .game-container {
    max-width: 640px;
  }
}

/* ── TALL SCREENS (for game numpad optimization) ── */
@media (min-height: 800px) and (max-width: 767px) {
  .num-btn {
    height: 68px;
    font-size: 1.5rem;
  }
  .numpad {
    gap: 12px;
  }
  .equation-wrap {
    padding: 26px 28px;
    min-height: 95px;
  }
  .question-area {
    gap: 20px;
  }
}

/* ── LANDSCAPE MOBILE ── */
@media (max-height: 450px) and (orientation: landscape) {
  .game-top-bar {
    padding: max(6px, env(safe-area-inset-top)) 14px 6px;
  }
  .question-area {
    padding: 4px 20px;
    gap: 6px;
  }
  .equation-wrap {
    padding: 8px 14px;
    min-height: 50px;
    border-radius: 12px;
  }
  .eq-token {
    font-size: 1rem !important;
  }
  .input-slot {
    min-width: 40px;
    height: 38px;
    border-radius: 8px;
  }
  .numpad-area {
    padding: 4px 16px 8px;
  }
  .num-btn {
    height: 38px;
    font-size: 0.95rem;
    border-radius: 8px;
  }
  .numpad {
    gap: 4px;
    max-width: 300px;
  }
  .feedback {
    min-height: 20px;
    font-size: 0.8rem;
  }
  .question-counter {
    font-size: 0.7rem;
  }
  .per-question-bar {
    margin-top: 2px;
  }
  .progress-wrap {
    height: 2px;
  }
}

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


/* ═══════════════════════════════════════════════════════════════
   SOFT CARTOON OVERRIDES — All secondary screens & game pages
   Painted over the original neon styles. Last in the file = wins.
   Touches: screens (settings/player/stats/auth), game page,
   ranking page, game-over modal, status banner, custom confirm.
   ═══════════════════════════════════════════════════════════════ */

/* Pastel palette as global vars (so non-.app-container scopes can reach them) */
:root {
  --soft-peach: #FFB5A0;
  --soft-pink: #FF8FB5;
  --soft-pink-soft: #FFBBD2;
  --soft-lavender: #B8A5FF;
  --soft-lavender-soft: #DBCCFF;
  --soft-sky: #7ED7FF;
  --soft-sky-soft: #B8E8FF;
  --soft-mint: #7FDCC0;
  --soft-mint-soft: #B8ECD9;
  --soft-sun: #FFD93D;
  --soft-sun-soft: #FFE89C;
  --soft-coral: #FF6B8A;

  --soft-ink: #3A3555;
  --soft-ink-soft: #6B6488;
  --soft-ink-faint: #9D97B8;
  --soft-line: rgba(58, 53, 85, 0.08);

  --soft-bounce: cubic-bezier(0.68, -0.3, 0.27, 1.55);
  --soft-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Body background — replace dark gradient with pastel mesh ── */
body {
  font-family: "Mali", "Kanit", system-ui, sans-serif !important;
  color: var(--soft-ink) !important;
  background:
    radial-gradient(circle at 15% 10%, #FFD4E5 0%, transparent 45%),
    radial-gradient(circle at 85% 20%, #C8DFFF 0%, transparent 45%),
    radial-gradient(circle at 70% 85%, #D4F4E4 0%, transparent 50%),
    radial-gradient(circle at 20% 80%, #FFE5CC 0%, transparent 45%),
    linear-gradient(160deg, #FFE9F1, #E4EEFF) !important;
}

/* Hide the dark animated background entirely */
.bg-animation,
.bg-animation::before,
.grid-overlay {
  display: none !important;
}

/* ── Status Banner ── */
.status-banner {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 18px !important;
  color: var(--soft-ink) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.2),
    0 10px 25px rgba(184, 165, 255, 0.18) !important;
}
.status-banner.warning { border-color: var(--soft-sun) !important; }
.status-banner.error { border-color: var(--soft-coral) !important; }
.status-banner.success { border-color: var(--soft-mint) !important; }
.status-banner .banner-text { color: var(--soft-ink) !important; }
.status-banner .banner-close {
  color: var(--soft-ink-faint) !important;
  background: rgba(58, 53, 85, 0.06) !important;
}

/* ════════════════════════════════════════════════════════════
   SCREENS (Settings / Player / Stats / Auth modals)
   ════════════════════════════════════════════════════════════ */

.screen {
  background:
    radial-gradient(circle at 15% 10%, #FFD4E5 0%, transparent 45%),
    radial-gradient(circle at 85% 20%, #C8DFFF 0%, transparent 45%),
    radial-gradient(circle at 70% 85%, #D4F4E4 0%, transparent 50%),
    linear-gradient(160deg, #FFE9F1, #E4EEFF) !important;
}

/* Header */
.screen-header {
  background: rgba(255, 255, 255, 0.7) !important;
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--soft-line) !important;
  box-shadow: 0 4px 20px rgba(184, 165, 255, 0.08);
}
.screen-title {
  font-family: "Fredoka", "Mali", sans-serif !important;
  color: var(--soft-ink) !important;
  font-weight: 600 !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
}

/* Back button — pill style */
.back-btn {
  background: white !important;
  color: var(--soft-ink) !important;
  border: none !important;
  border-radius: 50% !important;
  width: 40px !important;
  height: 40px !important;
  font-size: 1.4rem !important;
  font-weight: 700 !important;
  box-shadow:
    0 3px 0 rgba(184, 165, 255, 0.25),
    0 6px 14px rgba(184, 165, 255, 0.2) !important;
  transition: transform 0.2s var(--soft-bounce) !important;
}
.back-btn:hover { background: white !important; transform: translateY(-1px); }
.back-btn:active { transform: translateY(2px) scale(0.94) !important; }

/* Section title */
.section-title {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.section-title .current-level,
.current-level {
  color: var(--soft-pink) !important;
  background: rgba(255, 143, 181, 0.12);
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 700;
}

/* ── Level grid buttons (the 0-8 picker in Settings) ── */
.level-btn {
  background: white !important;
  border: 3px solid white !important;
  color: var(--soft-ink) !important;
  border-radius: 18px !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.18),
    0 8px 18px rgba(184, 165, 255, 0.1) !important;
  transition:
    transform 0.2s var(--soft-bounce),
    box-shadow 0.2s var(--soft-bounce),
    border-color 0.2s !important;
}
.level-btn::after { background: currentColor !important; opacity: 0.4 !important; }
.level-btn:active {
  transform: translateY(2px) scale(0.96) !important;
  box-shadow:
    0 2px 0 rgba(184, 165, 255, 0.18),
    0 4px 8px rgba(184, 165, 255, 0.1) !important;
}

/* Pastel tinting per level */
.level-btn[data-level="0"] { color: #4DBFA0 !important; }
.level-btn[data-level="1"] { color: #4DBFA0 !important; }
.level-btn[data-level="2"] { color: #5BB8E0 !important; }
.level-btn[data-level="3"] { color: #5BB8E0 !important; }
.level-btn[data-level="4"] { color: #B8A5FF !important; }
.level-btn[data-level="5"] { color: #B8A5FF !important; }
.level-btn[data-level="6"] { color: #FF8FB5 !important; }
.level-btn[data-level="7"] { color: #FF8FB5 !important; }
.level-btn[data-level="8"] { color: #FF6B8A !important; }

.level-btn.active {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, currentColor 22%, white),
    color-mix(in srgb, currentColor 8%, white)
  ) !important;
  border-color: currentColor !important;
  box-shadow:
    0 4px 0 color-mix(in srgb, currentColor 35%, transparent),
    0 8px 22px color-mix(in srgb, currentColor 25%, transparent) !important;
  transform: scale(1.05) !important;
}
.level-btn.active::after {
  opacity: 1 !important;
  box-shadow: none !important;
}
.level-label { opacity: 0.7 !important; }

/* Difficulty info card */
.difficulty-info {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 20px !important;
  box-shadow:
    0 4px 0 rgba(126, 215, 255, 0.18),
    0 10px 25px rgba(126, 215, 255, 0.12) !important;
}
.difficulty-name {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
}
.difficulty-desc { color: var(--soft-ink-soft) !important; }

/* ── Setting items (sfx / vibrate / etc) ── */
.setting-item {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 20px !important;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.15),
    0 8px 18px rgba(184, 165, 255, 0.1) !important;
}
.setting-title {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
}
.setting-desc { color: var(--soft-ink-soft) !important; }

/* Toggle switch — pastel candy */
.toggle {
  background: rgba(58, 53, 85, 0.12) !important;
  border: none !important;
}
.toggle-slider {
  background: white !important;
  box-shadow: 0 2px 6px rgba(58, 53, 85, 0.2) !important;
}
.toggle.active {
  background: linear-gradient(135deg, var(--soft-mint), var(--soft-sky)) !important;
}

/* ── Player card ── */
.player-card {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 24px !important;
  box-shadow:
    0 5px 0 rgba(255, 143, 181, 0.2),
    0 12px 28px rgba(255, 143, 181, 0.15) !important;
}
.player-avatar {
  background: linear-gradient(135deg, var(--soft-pink), var(--soft-lavender)) !important;
  color: white !important;
  font-family: "Fredoka", sans-serif !important;
  border: 3px solid white !important;
  box-shadow:
    0 4px 0 rgba(255, 143, 181, 0.3),
    0 0 0 6px rgba(255, 143, 181, 0.08) !important;
}
.player-card .menu-label,
.player-card .menu-text .menu-label {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
}
.player-card .menu-desc { color: var(--soft-ink-soft) !important; }

/* Edit profile fields */
.edit-field label {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.edit-field input {
  background: white !important;
  border: 2px solid var(--soft-line) !important;
  color: var(--soft-ink) !important;
  border-radius: 14px !important;
  font-family: "Mali", sans-serif !important;
  box-shadow: 0 2px 0 rgba(184, 165, 255, 0.1) !important;
  transition: all 0.2s ease !important;
}
.edit-field input:focus {
  border-color: var(--soft-lavender) !important;
  background: white !important;
  box-shadow:
    0 0 0 4px rgba(184, 165, 255, 0.15),
    0 2px 0 rgba(184, 165, 255, 0.2) !important;
  outline: none !important;
}

.btn-edit-profile {
  background: linear-gradient(135deg, var(--soft-sky), var(--soft-sky-soft)) !important;
  color: white !important;
  border: none !important;
  border-radius: 18px !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  box-shadow:
    0 4px 0 rgba(108, 175, 215, 0.45),
    0 10px 22px rgba(126, 215, 255, 0.3) !important;
  transition: transform 0.2s var(--soft-bounce), box-shadow 0.2s var(--soft-bounce) !important;
}
.btn-edit-profile:hover {
  background: linear-gradient(135deg, var(--soft-sky), var(--soft-sky-soft)) !important;
  transform: translateY(-1px);
}
.btn-edit-profile:active {
  transform: translateY(3px) scale(0.98);
  box-shadow:
    0 1px 0 rgba(108, 175, 215, 0.45),
    0 4px 10px rgba(126, 215, 255, 0.3) !important;
}

.btn-save-profile {
  background: linear-gradient(135deg, var(--soft-mint), #5BCFB0) !important;
  color: white !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  border-radius: 16px !important;
  border: none !important;
  box-shadow:
    0 4px 0 rgba(91, 175, 144, 0.5),
    0 8px 16px rgba(127, 220, 192, 0.3) !important;
}
.btn-cancel-edit {
  background: white !important;
  color: var(--soft-ink-soft) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  border-radius: 16px !important;
  border: 2px solid var(--soft-line) !important;
  box-shadow: 0 3px 0 rgba(184, 165, 255, 0.15) !important;
}

/* Logout / red action variants — keep for warning intent */
.btn-outline-secondary {
  background: white !important;
  color: var(--soft-coral) !important;
  border: 2px solid rgba(255, 107, 138, 0.35) !important;
  box-shadow:
    0 4px 0 rgba(255, 107, 138, 0.18),
    0 8px 18px rgba(255, 107, 138, 0.12) !important;
}
.btn-delete-account {
  background: white !important;
  color: var(--soft-ink-faint) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 500 !important;
  border: 2px dashed rgba(157, 151, 184, 0.35) !important;
  border-radius: 14px !important;
  box-shadow: none !important;
  text-decoration: none !important;
}
.btn-delete-account:hover {
  background: rgba(255, 107, 138, 0.08) !important;
  color: var(--soft-coral) !important;
  border-color: rgba(255, 107, 138, 0.4) !important;
}

/* ════════════════════════════════════════════════════════════
   AUTH FORMS (login / register / forgot password)
   ════════════════════════════════════════════════════════════ */

.auth-label {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 0.85rem !important;
}
.auth-input {
  background: white !important;
  border: 2px solid var(--soft-line) !important;
  color: var(--soft-ink) !important;
  border-radius: 14px !important;
  font-family: "Mali", sans-serif !important;
  box-shadow: 0 2px 0 rgba(184, 165, 255, 0.1) !important;
  transition: all 0.2s ease !important;
}
.auth-input::placeholder { color: var(--soft-ink-faint) !important; }
.auth-input:focus {
  border-color: var(--soft-lavender) !important;
  background: white !important;
  box-shadow:
    0 0 0 4px rgba(184, 165, 255, 0.15),
    0 2px 0 rgba(184, 165, 255, 0.2) !important;
}
.password-toggle {
  background: transparent !important;
  color: var(--soft-ink-faint) !important;
  border: none !important;
}
.password-toggle:hover { color: var(--soft-pink) !important; }
.auth-switch {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
}
.auth-switch span {
  color: var(--soft-pink) !important;
  font-weight: 600 !important;
}
.auth-switch span:hover { color: var(--soft-coral) !important; }

/* Auth error message */
#auth-error {
  background: rgba(255, 107, 138, 0.1) !important;
  border: 2px solid rgba(255, 107, 138, 0.3) !important;
  color: var(--soft-coral) !important;
  border-radius: 14px !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 500 !important;
}

/* ════════════════════════════════════════════════════════════
   STATS SCREEN
   ════════════════════════════════════════════════════════════ */

.stats-grid .stat-card {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 20px !important;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.15),
    0 8px 18px rgba(184, 165, 255, 0.1) !important;
}
.stats-grid .stat-icon,
.stat-icon {
  font-size: 1.6rem !important;
  margin-bottom: 4px;
}
.stats-grid .stat-number {
  font-family: "Fredoka", "Mali", sans-serif !important;
  background: linear-gradient(135deg, var(--soft-pink), var(--soft-lavender));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent !important;
  font-weight: 700 !important;
}
.stats-grid .stat-label,
.stat-label {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.stat-section-title {
  color: var(--soft-ink-soft) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.level-stat-row {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 18px !important;
  box-shadow:
    0 3px 0 rgba(184, 165, 255, 0.15),
    0 6px 14px rgba(184, 165, 255, 0.08) !important;
  color: var(--soft-ink) !important;
}
.level-stat-badge {
  background: linear-gradient(135deg, var(--soft-lavender), var(--soft-pink)) !important;
  color: white !important;
  border: none !important;
  border-radius: 12px !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  letter-spacing: 0 !important;
  box-shadow: 0 2px 0 rgba(140, 100, 180, 0.3) !important;
}
.level-stat-info {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
}
.level-stat-info strong {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
}
.stats-loading,
.stats-login-msg {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
}

/* ════════════════════════════════════════════════════════════
   GAME PAGE — gameplay screen
   ════════════════════════════════════════════════════════════ */

#page-game {
  background:
    radial-gradient(circle at 15% 10%, #FFD4E5 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, #C8DFFF 0%, transparent 45%),
    linear-gradient(160deg, #FFE9F1, #E4EEFF) !important;
  color: var(--soft-ink) !important;
}

.progress-wrap {
  background: rgba(255, 255, 255, 0.6) !important;
  border-radius: 100px !important;
  height: 6px !important;
  margin: 12px 16px 6px !important;
  overflow: hidden;
}
.progress-bar {
  background: linear-gradient(90deg, var(--soft-pink), var(--soft-lavender), var(--soft-sky)) !important;
  border-radius: 100px !important;
}

.game-top-bar {
  background: rgba(255, 255, 255, 0.65) !important;
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-radius: 22px !important;
  margin: max(8px, env(safe-area-inset-top)) 16px 12px !important;
  padding: 12px 16px !important;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.12),
    0 8px 22px rgba(184, 165, 255, 0.08) !important;
  border: 2px solid white !important;
}

#page-game .back-btn {
  width: 36px !important;
  height: 36px !important;
  font-size: 1.2rem !important;
}

.level-badge {
  background: linear-gradient(135deg, var(--soft-lavender), var(--soft-pink)) !important;
  color: white !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  border-radius: 14px !important;
  border: none !important;
  padding: 6px 12px !important;
  box-shadow:
    0 3px 0 rgba(140, 100, 180, 0.35),
    0 6px 14px rgba(184, 165, 255, 0.3) !important;
  text-shadow: 0 1px 2px rgba(140, 100, 180, 0.2);
}
.level-badge .level-name { color: rgba(255, 255, 255, 0.85) !important; }

.timer-label,
.score-label {
  color: var(--soft-ink-faint) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600 !important;
  letter-spacing: 1px !important;
  text-transform: none !important;
}
.timer-value,
.score-value {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  text-shadow: none !important;
}
.timer-value.warning { color: var(--soft-sun) !important; }
.timer-value.danger {
  color: var(--soft-coral) !important;
  animation: softPulse 0.8s ease-in-out infinite !important;
}
@keyframes softPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* Question area */
.question-area {
  flex: 1 !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px !important;
}
.question-counter {
  color: var(--soft-ink-soft) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  font-size: 0.95rem !important;
}
.question-counter span { color: var(--soft-pink) !important; font-weight: 700 !important; }

.per-question-bar {
  background: rgba(255, 255, 255, 0.7) !important;
  border-radius: 100px !important;
  height: 4px !important;
  width: 80% !important;
  max-width: 280px !important;
  margin: 8px auto 14px !important;
  overflow: hidden;
}
.per-question-fill {
  background: linear-gradient(90deg, var(--soft-mint), var(--soft-sky)) !important;
  border-radius: 100px !important;
}
.per-question-fill.warning {
  background: linear-gradient(90deg, var(--soft-sun), #FFB347) !important;
}
.per-question-fill.danger {
  background: linear-gradient(90deg, var(--soft-coral), #FF4D6D) !important;
}

/* Equation card */
.equation-wrap {
  background: white !important;
  border: 3px solid white !important;
  border-radius: 28px !important;
  padding: 28px 24px !important;
  box-shadow:
    0 6px 0 rgba(184, 165, 255, 0.18),
    0 14px 32px rgba(184, 165, 255, 0.12) !important;
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  font-size: 1.6rem !important;
}
.equation-wrap.correct {
  border-color: var(--soft-mint) !important;
  background: linear-gradient(135deg, #E8FBF3, white) !important;
  box-shadow:
    0 6px 0 rgba(91, 175, 144, 0.3),
    0 14px 32px rgba(127, 220, 192, 0.3) !important;
}
.equation-wrap.wrong {
  border-color: var(--soft-coral) !important;
  background: linear-gradient(135deg, #FFEBF0, white) !important;
  box-shadow:
    0 6px 0 rgba(220, 90, 120, 0.25),
    0 14px 32px rgba(255, 107, 138, 0.3) !important;
}

/* Equation tokens — dark, readable on the white card */
.eq-token {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  text-shadow: none !important;
}
.eq-token.op {
  color: var(--soft-pink) !important;
  font-weight: 700 !important;
}
.eq-token.paren {
  color: var(--soft-ink-faint) !important;
  font-weight: 600 !important;
}
.eq-token.eq-sign {
  color: var(--soft-ink-soft) !important;
  font-weight: 700 !important;
}
.eq-token.result-num {
  color: var(--soft-lavender) !important;
  font-weight: 800 !important;
}

/* Input slot — soft pastel to match the white card */
.input-slot {
  border: 2.5px solid var(--soft-lavender) !important;
  background: rgba(184, 165, 255, 0.08) !important;
  box-shadow: 0 0 16px rgba(184, 165, 255, 0.2) !important;
}
.input-slot.correct-slot {
  border-color: var(--soft-mint) !important;
  background: rgba(127, 220, 192, 0.15) !important;
  box-shadow: 0 0 18px rgba(127, 220, 192, 0.3) !important;
}
.input-slot.wrong-slot {
  border-color: var(--soft-coral) !important;
  background: rgba(255, 107, 138, 0.12) !important;
  box-shadow: 0 0 18px rgba(255, 107, 138, 0.3) !important;
}
.input-value {
  color: var(--soft-lavender) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 800 !important;
}
.cursor-blink {
  background: var(--soft-lavender) !important;
}

.feedback {
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
}
.feedback.correct-fb { color: var(--soft-mint) !important; }
.feedback.wrong-fb { color: var(--soft-coral) !important; }

/* ── Numpad — chunky white candy buttons ── */
.num-btn {
  background: white !important;
  border: 2px solid white !important;
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  border-radius: 18px !important;
  height: 64px !important;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.2),
    0 8px 16px rgba(184, 165, 255, 0.12) !important;
  transition:
    transform 0.12s var(--soft-bounce),
    box-shadow 0.12s var(--soft-bounce) !important;
}
.num-btn:active {
  background: white !important;
  transform: translateY(3px) scale(0.96) !important;
  box-shadow:
    0 1px 0 rgba(184, 165, 255, 0.2),
    0 2px 6px rgba(184, 165, 255, 0.12) !important;
}
.num-btn .ripple { background: rgba(184, 165, 255, 0.3) !important; }

.num-btn.clear-btn {
  background: linear-gradient(135deg, #FFE0E8, #FFD0DC) !important;
  border-color: #FFD0DC !important;
  color: var(--soft-coral) !important;
  box-shadow:
    0 4px 0 rgba(220, 90, 120, 0.25),
    0 8px 16px rgba(255, 107, 138, 0.18) !important;
}
.num-btn.clear-btn:active {
  background: linear-gradient(135deg, #FFD0DC, #FFC0CC) !important;
}

.num-btn.enter-btn {
  background: linear-gradient(135deg, var(--soft-mint), #5BCFB0) !important;
  border: none !important;
  color: white !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  letter-spacing: 1px !important;
  box-shadow:
    0 4px 0 rgba(91, 175, 144, 0.5),
    0 8px 18px rgba(127, 220, 192, 0.3) !important;
  text-shadow: 0 1px 2px rgba(70, 140, 110, 0.25);
}
.num-btn.enter-btn:active {
  background: linear-gradient(135deg, #6BD0B0, #4DBFA0) !important;
}

/* ════════════════════════════════════════════════════════════
   GAME OVER MODAL
   ════════════════════════════════════════════════════════════ */

.game-over-overlay {
  background: rgba(58, 53, 85, 0.45) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.game-over-card {
  background: white !important;
  border: 3px solid white !important;
  border-radius: 28px !important;
  box-shadow:
    0 8px 0 rgba(184, 165, 255, 0.25),
    0 20px 50px rgba(184, 165, 255, 0.3) !important;
  color: var(--soft-ink) !important;
}
.go-title {
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  background: linear-gradient(120deg, var(--soft-pink), var(--soft-lavender), var(--soft-sky)) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent !important;
  letter-spacing: 0 !important;
  text-shadow: none !important;
  text-transform: none !important;
}
.go-stats {
  background: rgba(184, 165, 255, 0.06) !important;
  border-radius: 18px !important;
  padding: 16px !important;
}
.go-stat-label {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600 !important;
}
.go-stat-value {
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
}
/* Override the inline styles via specificity */
.go-stat-value[id="goScore"] { color: var(--soft-sun) !important; }
.go-stat-value[id="goCorrect"] { color: var(--soft-mint) !important; }
.go-stat-value[id="goTime"] { color: var(--soft-sky) !important; }

.go-btn {
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  border-radius: 18px !important;
  border: none !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
  transition: transform 0.2s var(--soft-bounce), box-shadow 0.2s var(--soft-bounce) !important;
}
.go-btn:active { transform: translateY(3px) scale(0.97) !important; }

.go-btn.menu-btn {
  background: white !important;
  color: var(--soft-ink-soft) !important;
  border: 2px solid var(--soft-line) !important;
  box-shadow: 0 3px 0 rgba(184, 165, 255, 0.18) !important;
}
.go-btn.menu-btn:hover {
  background: white !important;
  color: var(--soft-ink) !important;
}
.go-btn.retry {
  background: linear-gradient(135deg, var(--soft-pink), var(--soft-lavender)) !important;
  color: white !important;
  box-shadow:
    0 5px 0 rgba(140, 100, 180, 0.45),
    0 12px 24px rgba(184, 165, 255, 0.3) !important;
  text-shadow: 0 1px 2px rgba(140, 100, 180, 0.2);
}
.go-btn.retry:hover {
  background: linear-gradient(135deg, var(--soft-pink), var(--soft-lavender)) !important;
}

/* "New Best!" badge */
#newBestBadge:not(:empty) {
  display: inline-block !important;
  background: linear-gradient(135deg, var(--soft-sun), #FFB347) !important;
  color: white !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  padding: 6px 14px !important;
  border-radius: 100px !important;
  margin-bottom: 8px !important;
  box-shadow:
    0 3px 0 rgba(200, 140, 50, 0.3),
    0 6px 14px rgba(255, 217, 61, 0.3) !important;
  text-shadow: 0 1px 2px rgba(180, 120, 40, 0.2);
  animation: badgeBounce 0.6s var(--soft-spring) !important;
}
@keyframes badgeBounce {
  0% { transform: scale(0) rotate(-15deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

/* ════════════════════════════════════════════════════════════
   RANKING PAGE
   ════════════════════════════════════════════════════════════ */

#page-ranking {
  background:
    radial-gradient(circle at 15% 10%, #FFD4E5 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, #C8DFFF 0%, transparent 45%),
    linear-gradient(160deg, #FFE9F1, #E4EEFF) !important;
  color: var(--soft-ink) !important;
}
.ranking-top-bar {
  background: rgba(255, 255, 255, 0.7) !important;
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--soft-line) !important;
}
.page-title {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
  background: none !important;
  -webkit-background-clip: initial !important;
  background-clip: initial !important;
  -webkit-text-fill-color: var(--soft-ink) !important;
}
.player-count {
  color: var(--soft-ink-soft) !important;
  background: white !important;
  padding: 4px 12px !important;
  border-radius: 100px !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 600 !important;
  font-size: 0.78rem !important;
  box-shadow: 0 2px 0 rgba(184, 165, 255, 0.15) !important;
}

.level-filter {
  background: white !important;
  border: 2px solid white !important;
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
  border-radius: 16px !important;
  padding: 12px 18px !important;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.18),
    0 8px 18px rgba(184, 165, 255, 0.1) !important;
  cursor: pointer;
  transition: transform 0.2s var(--soft-bounce) !important;
}
.level-filter:focus {
  outline: none !important;
  border-color: var(--soft-lavender) !important;
  box-shadow:
    0 0 0 4px rgba(184, 165, 255, 0.15),
    0 4px 0 rgba(184, 165, 255, 0.2) !important;
}
.level-filter option {
  background: white !important;
  color: var(--soft-ink) !important;
}

/* Ranking rows */
.rank-row {
  background: white !important;
  border: 2px solid white !important;
  border-radius: 18px !important;
  padding: 12px 16px !important;
  box-shadow:
    0 3px 0 rgba(184, 165, 255, 0.15),
    0 6px 14px rgba(184, 165, 255, 0.08) !important;
  margin-bottom: 8px !important;
}
.rank-row.is-me {
  background: linear-gradient(135deg, #FFE5F0, white) !important;
  border-color: var(--soft-pink) !important;
  box-shadow:
    0 3px 0 rgba(255, 143, 181, 0.3),
    0 6px 18px rgba(255, 143, 181, 0.18) !important;
}

/* Top 3 ranks: gold/silver/bronze pastel tints */
.rank-row:nth-of-type(1) {
  background: linear-gradient(135deg, #FFF4D0, white) !important;
  border-color: var(--soft-sun) !important;
  box-shadow:
    0 4px 0 rgba(220, 180, 50, 0.3),
    0 10px 22px rgba(255, 217, 61, 0.2) !important;
}
.rank-row:nth-of-type(2) {
  background: linear-gradient(135deg, #EDF1F8, white) !important;
  border-color: #C5CFD9 !important;
  box-shadow:
    0 4px 0 rgba(165, 175, 190, 0.3),
    0 10px 20px rgba(165, 175, 190, 0.18) !important;
}
.rank-row:nth-of-type(3) {
  background: linear-gradient(135deg, #FBE4D0, white) !important;
  border-color: #E8B894 !important;
  box-shadow:
    0 4px 0 rgba(195, 145, 100, 0.3),
    0 10px 20px rgba(232, 184, 148, 0.2) !important;
}
/* If is-me coincides with top 3, prefer the is-me styling */
.rank-row.is-me:nth-of-type(1),
.rank-row.is-me:nth-of-type(2),
.rank-row.is-me:nth-of-type(3) {
  background: linear-gradient(135deg, #FFE5F0, white) !important;
  border-color: var(--soft-pink) !important;
}

.rank-lv {
  background: rgba(184, 165, 255, 0.15) !important;
  border: none !important;
  color: var(--soft-lavender) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  border-radius: 8px !important;
  padding: 4px 8px !important;
  font-size: 0.65rem !important;
  font-weight: 700 !important;
}
.row-avatar {
  background: linear-gradient(135deg, var(--soft-pink), var(--soft-lavender)) !important;
  color: white !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  border: 2px solid white !important;
  box-shadow: 0 2px 0 rgba(184, 165, 255, 0.25) !important;
}
.rank-name {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
}
.rank-score {
  font-family: "Fredoka", "Mali", sans-serif !important;
  background: linear-gradient(135deg, var(--soft-pink), var(--soft-coral)) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent !important;
  font-weight: 700 !important;
}
.rank-time {
  color: var(--soft-sky) !important;
  font-family: "Mali", sans-serif !important;
  opacity: 1 !important;
  font-weight: 600 !important;
}
.rank-date {
  color: var(--soft-ink-faint) !important;
  font-family: "Mali", sans-serif !important;
}
.you-tag {
  color: var(--soft-pink) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 700 !important;
  background: rgba(255, 143, 181, 0.15);
  padding: 2px 6px;
  border-radius: 6px;
}
.empty-icon {
  opacity: 0.7 !important;
}
.empty-title {
  color: var(--soft-ink) !important;
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 600 !important;
}

.empty-state,
.empty-desc {
  color: var(--soft-ink-soft) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 500 !important;
}

/* Guest panel inside Player screen */
.guest-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--soft-pink-soft), var(--soft-lavender-soft));
  color: white;
  margin-bottom: 4px;
  box-shadow:
    0 4px 0 rgba(184, 165, 255, 0.25),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
}
.guest-icon svg {
  width: 32px;
  height: 32px;
}
.guest-title {
  font-family: "Fredoka", "Mali", sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--soft-ink);
}
.guest-desc {
  font-family: "Mali", sans-serif;
  font-size: 0.85rem;
  color: var(--soft-ink-soft);
  font-weight: 500;
}

/* ════════════════════════════════════════════════════════════
   CUSTOM CONFIRM MODAL
   ════════════════════════════════════════════════════════════ */

.confirm-overlay {
  background: rgba(58, 53, 85, 0.45) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.confirm-card {
  background: white !important;
  border: 3px solid white !important;
  border-radius: 24px !important;
  box-shadow:
    0 8px 0 rgba(184, 165, 255, 0.2),
    0 18px 40px rgba(184, 165, 255, 0.25) !important;
  color: var(--soft-ink) !important;
}
.confirm-msg {
  color: var(--soft-ink) !important;
  font-family: "Mali", sans-serif !important;
  font-weight: 500 !important;
}
.confirm-btn {
  font-family: "Fredoka", "Mali", sans-serif !important;
  font-weight: 700 !important;
  border-radius: 14px !important;
  border: none !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.confirm-btn.cancel {
  background: white !important;
  color: var(--soft-ink-soft) !important;
  border: 2px solid var(--soft-line) !important;
  box-shadow: 0 3px 0 rgba(184, 165, 255, 0.15) !important;
}
.confirm-btn.cancel:hover {
  background: white !important;
  color: var(--soft-ink) !important;
}
.confirm-btn.ok {
  background: linear-gradient(135deg, var(--soft-coral), #FF4D6D) !important;
  color: white !important;
  box-shadow:
    0 4px 0 rgba(220, 60, 90, 0.4),
    0 8px 18px rgba(255, 107, 138, 0.3) !important;
}
.confirm-btn.ok:hover {
  background: linear-gradient(135deg, var(--soft-coral), #FF4D6D) !important;
  filter: brightness(1.05) !important;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE TWEAKS
   ════════════════════════════════════════════════════════════ */

@media (max-width: 380px) {
  .equation-wrap {
    padding: 22px 18px !important;
    font-size: 1.4rem !important;
  }
  .num-btn {
    height: 56px !important;
    font-size: 1.3rem !important;
    border-radius: 16px !important;
  }
  .level-btn {
    border-radius: 14px !important;
  }
  .game-over-card {
    padding: 24px 18px !important;
  }
}
/* ── Avatar Preview Overlay ── */
.avatar-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.avatar-preview-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.avatar-preview-overlay img {
  width: min(80vw, 80vh);
  height: min(80vw, 80vh);
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  transform: scale(0.85);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.avatar-preview-overlay.open img {
  transform: scale(1);
}
