:root {
  font: 16px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg-page: #f6f8fc;
  --bg-gradient: radial-gradient(ellipse at 50% 0%, #ffffff 0%, #edf2f9 85%);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #475569;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --card-shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --btn-bg: #ffffff;
  --btn-border: #cbd5e1;
  --btn-text: #1e293b;
  --btn-hover: #f1f5f9;
  --primary-bg: #0284c7;
  --primary-text: #ffffff;
  --primary-border: #0284c7;
  --primary-hover: #0369a1;
  --icon-bg: #ffffff;
  --icon-border: #cbd5e1;
  --icon-text: #334155;
  --mint: #0284c7;
  --mint-glow: rgba(2, 132, 199, 0.35);
  --panel: #ffffff;
  --line: #e2e8f0;
  --bg-dark: #0f172a;
  --board-bg: #e2e8f0;
  --board-border: #cbd5e1;
  --board-shadow: 0 14px 34px rgba(15, 23, 42, 0.10), inset 0 2px 4px rgba(255,255,255,0.7);
  --cell-empty: #f8fafc;
  --cell-border: #e2e8f0;
  --tray-bg: #ffffff;
  --tray-border: #e2e8f0;
  --header-pill-bg: rgba(2, 132, 199, 0.1);
  --header-pill-border: rgba(2, 132, 199, 0.35);
  --header-pill-text: #0284c7;
  --header-pill-shadow: 0 2px 8px rgba(2, 132, 199, 0.12);
  --hud-bg: rgba(15, 23, 42, 0.05);
  --hud-border: rgba(15, 23, 42, 0.1);
  --hud-text: #0f172a;
  --hud-title: #0f172a;
  --notice-color: #d97706;

  /* Complimentary, rich, saturated jewel tones for light mode */
  --tile-0: #0284c7; /* Vibrant Ocean Sapphire */
  --tile-1: #e11d48; /* Crimson Ruby Rose */
  --tile-2: #7c3aed; /* Royal Purple Amethyst */
  --tile-3: #d97706; /* Golden Honey Amber */
  --tile-4: #059669; /* Lush Jade Emerald */
  --tile-5: #ea580c; /* Warm Deep Tangerine */
}

[data-theme="dark"] {
  --bg-page: #090d16;
  --bg-gradient: radial-gradient(ellipse at 50% 0%, #172033 0%, #090d16 80%);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #cbd5e1;
  --card-bg: #111827;
  --card-border: #1e293b;
  --card-shadow: 0 10px 30px rgba(0,0,0,0.3);
  --btn-bg: #1e293b;
  --btn-border: #334155;
  --btn-text: #f8fafc;
  --btn-hover: #334155;
  --primary-bg: #06b6d4;
  --primary-text: #082f3b;
  --primary-border: #06b6d4;
  --primary-hover: #22d3ee;
  --icon-bg: rgba(255, 255, 255, 0.06);
  --icon-border: rgba(255, 255, 255, 0.14);
  --icon-text: #cbd5e1;
  --mint: #06b6d4;
  --mint-glow: rgba(6, 182, 212, 0.45);
  --panel: #111827;
  --line: #1e293b;
  --bg-dark: #070a10;
  --board-bg: #090d16;
  --board-border: #1e293b;
  --board-shadow: 0 16px 36px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(0,0,0,0.5);
  --cell-empty: #111827;
  --cell-border: #1e293b;
  --tray-bg: #111827;
  --tray-border: #1e293b;
  --header-pill-bg: rgba(6, 182, 212, 0.14);
  --header-pill-border: rgba(6, 182, 212, 0.55);
  --header-pill-text: #22d3ee;
  --header-pill-shadow: 0 0 14px rgba(6, 182, 212, 0.18);
  --hud-bg: rgba(255, 255, 255, 0.08);
  --hud-border: rgba(255, 255, 255, 0.12);
  --hud-text: #e2e8f0;
  --hud-title: #ffffff;
  --notice-color: #ffda77;

  /* Luminous neon jewels for dark mode */
  --tile-0: #00d4ff; /* Electric Cyan */
  --tile-1: #ff2a6d; /* Vivid Ruby */
  --tile-2: #a855f7; /* Royal Amethyst */
  --tile-3: #ffb300; /* Amber Gold */
  --tile-4: #00e676; /* Neon Emerald */
  --tile-5: #ff6d00; /* Tangerine */
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg-gradient);
  background-color: var(--bg-page);
  color: var(--text-main);
  overscroll-behavior: none;
}

body.in-game {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}

body.in-game #global-footer {
  display: none;
}

body.in-game main {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top, 8px)) 12px max(8px, env(safe-area-inset-bottom, 8px));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
  box-sizing: border-box;
}

main {
  max-width: 680px;
  margin: auto;
  padding: 20px 16px;
  min-height: 85vh;
}

h1 {
  font-size: clamp(34px, 7vw, 56px);
  line-height: 1.08;
  letter-spacing: -1.5px;
  margin: 16px 0;
  color: var(--text-main);
}

h2 {
  font-size: 24px;
  line-height: 1.2;
  margin: 8px 0;
  color: var(--text-main);
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--mint);
  font-weight: 700;
}

p {
  color: var(--text-muted);
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 20px;
  border-radius: 20px;
  margin: 14px 0;
  box-shadow: var(--card-shadow);
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
  padding: 6px 0 8px;
  margin-bottom: 2px;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Wonderworld Brand Pill */
.ww-home-btn, .ww-home-pill {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  text-decoration: none !important;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  letter-spacing: -0.2px !important;
  padding: 5px 12px 5px 6px !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, 0.08) !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  color: #ffffff !important;
  transition: all 0.18s ease !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  line-height: 1 !important;
  pointer-events: auto !important;
  box-sizing: border-box !important;
  cursor: pointer !important;
}

.ww-home-btn:hover, .ww-home-pill:hover {
  background: rgba(255, 255, 255, 0.16) !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
  transform: translateY(-1px) !important;
  color: #ffffff !important;
}

.ww-home-pill .ww-logo-icon, .ww-home-btn .ww-logo-icon {
  width: 22px !important;
  height: 22px !important;
  border-radius: 6px !important;
  flex-shrink: 0 !important;
  display: block !important;
}

.ww-home-pill .ww-text-full, .ww-home-btn .ww-text-full {
  display: inline !important;
}

.ww-home-pill .ww-text-short, .ww-home-btn .ww-text-short {
  display: none !important;
}

@media (max-width: 600px) {
  .ww-home-btn, .ww-home-pill {
    padding: 5px 9px 5px 5px !important;
    gap: 6px !important;
    font-size: 12px !important;
  }
  .ww-home-pill .ww-text-full, .ww-home-btn .ww-text-full {
    display: none !important;
  }
  .ww-home-pill .ww-text-short, .ww-home-btn .ww-text-short {
    display: inline !important;
  }
}

button, .button {
  font: inherit;
  min-height: 40px;
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--btn-text);
  padding: 8px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}

button:active {
  transform: scale(0.97);
}

button:hover {
  background: var(--btn-hover);
}

button:disabled {
  opacity: .35;
  cursor: default;
  pointer-events: none;
}

.primary {
  background: var(--primary-bg);
  color: var(--primary-text);
  border-color: var(--primary-border);
  font-weight: 700;
}

.primary:hover {
  background: var(--primary-hover);
}

.icon-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--icon-bg);
  border: 1px solid var(--icon-border);
  color: var(--icon-text);
  transition: all 0.15s ease;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

.header-center-btns {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.header-pill {
  padding: 6px 14px;
  min-height: 36px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: var(--header-pill-bg);
  border: 1px solid var(--header-pill-border);
  color: var(--header-pill-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  box-shadow: var(--header-pill-shadow);
  transition: all 0.18s ease;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}

.header-pill:hover {
  background: rgba(6, 182, 212, 0.24);
  border-color: #06b6d4;
  transform: translateY(-1px);
}

.header-pill.active {
  background: rgba(6, 182, 212, 0.2);
  border-color: #06b6d4;
  color: #22d3ee;
}

.header-pill .caret {
  font-size: 10px;
  opacity: 0.85;
  margin-left: 2px;
}

.header-right-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Play Screen Layout - Fits mobile and laptop screens with zero vertical overflow */
.play-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  user-select: none;
  box-sizing: border-box;
}

.score-hud {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  padding: 4px 2px 6px;
  gap: 10px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.score-hud h2 {
  font-size: clamp(20px, 5.5vw, 24px);
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--hud-title);
  white-space: nowrap;
  flex-shrink: 0;
}

.score-hud h2 small {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.score-hud .hud-meta {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--hud-text);
  background: var(--hud-bg);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--hud-border);
  white-space: nowrap;
  flex-shrink: 0;
}

progress {
  width: 100%;
  accent-color: var(--mint);
  height: 6px;
  border-radius: 4px;
  overflow: hidden;
  margin: 2px 0;
  flex-shrink: 0;
}

/* Game Board */
.board-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex-grow: 1;
  min-height: 0;
  padding: 2px 0;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 3px;
  background: var(--board-bg);
  border: 5px solid var(--board-border);
  box-shadow: var(--board-shadow);
  border-radius: 16px;
  padding: 4px;
  width: min(calc(100vw - 24px), calc(100dvh - 215px), 365px);
  height: min(calc(100vw - 24px), calc(100dvh - 215px), 365px);
  touch-action: none;
  position: relative;
  margin: 0 auto;
  box-sizing: border-box;
}

.cell {
  aspect-ratio: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border-radius: 5px;
  background: var(--cell-empty);
  border: 1px solid var(--cell-border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tile {
  background: var(--tile) !important;
  border-top: 2.5px solid rgba(255, 255, 255, 0.8) !important;
  border-left: 1px solid rgba(255, 255, 255, 0.35) !important;
  border-right: 1px solid rgba(0, 0, 0, 0.14) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2) !important;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.28), 0 3px 6px rgba(15, 23, 42, 0.14) !important;
  border-radius: 6px;
}

[data-theme="dark"] .tile {
  background: var(--tile) !important;
  border-top: 2.5px solid rgba(255, 255, 255, 0.65) !important;
  border-left: none !important;
  border-right: none !important;
  border-bottom: none !important;
  box-shadow: inset 0 -3.5px 0 rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  border-radius: 5px;
}

/* Tile color assignments mapped to theme variables */
.color0 { --tile: var(--tile-0); }
.color1 { --tile: var(--tile-1); }
.color2 { --tile: var(--tile-2); }
.color3 { --tile: var(--tile-3); }
.color4 { --tile: var(--tile-4); }
.color5 { --tile: var(--tile-5); } /* Tangerine */

.cell .gem, .mini .gem {
  color: white;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  font-size: 15px;
  line-height: 1;
}

.cell.preview {
  background: var(--mint-glow) !important;
  border-color: var(--mint) !important;
  box-shadow: 0 0 10px var(--mint);
  transform: scale(0.96);
  transition: background 0.08s, transform 0.08s;
}

/* Tray and Pieces */
.tray {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: clamp(75px, 14vh, 105px);
  width: min(calc(100vw - 24px), calc(100dvh - 215px), 365px);
  margin: 0 auto;
  flex-shrink: 0;
  box-sizing: border-box;
}

.piece {
  padding: 6px;
  flex: 1;
  max-width: 125px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tray-bg);
  border: 1.5px solid var(--tray-border);
  border-radius: 14px;
  touch-action: none;
  cursor: grab;
  transition: border-color 0.15s, transform 0.15s, opacity 0.15s;
}

.piece:active {
  cursor: grabbing;
}

.piece.selected {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(154, 244, 209, 0.25);
  transform: scale(1.02);
}

.piece.dragging-source {
  opacity: 0.25;
}

.mini {
  display: grid;
  gap: 2.5px;
}

.mini span {
  width: clamp(14px, 3.2vw, 22px);
  height: clamp(14px, 3.2vw, 22px);
  border-radius: 3px;
}

/* Floating Drag Avatar */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 9999;
  display: none;
  transform-origin: center center;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.6));
}

.drag-ghost.active {
  display: block;
}

.drag-ghost .mini {
  gap: 3px;
}

.drag-ghost .mini span {
  border-radius: 4px;
}

/* Notice / Helper */
#notice {
  text-align: center;
  font-size: 13px;
  color: #ffda77;
  margin: 0;
  padding: 4px;
  min-height: 24px;
  font-weight: 500;
  flex-shrink: 0;
}

/* Levels & Settings */
.levels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.levels button {
  padding: 12px 4px;
}

.settings label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

input[type=checkbox] {
  width: 22px;
  height: 22px;
  accent-color: var(--mint);
}

footer {
  text-align: center;
  color: #9cb2cf;
  font-size: 13px;
  padding: 16px;
}

footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

dialog {
  max-width: 420px;
  border: 1px solid #3d5575;
  border-radius: 20px;
  background: #182945;
  color: white;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

dialog::backdrop {
  background: rgba(7, 16, 33, 0.75);
  backdrop-filter: blur(4px);
}

.badge {
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.muted {
  opacity: .4;
}

@media (max-width: 480px) {
  .board {
    border-width: 5px;
    padding: 3px;
    gap: 2px;
  }
  .score-hud h2 {
    font-size: 22px;
  }
}


/* Unified Wonderworld Games Brand Pill */
.ww-home-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  color: inherit;
  transition: all 0.18s ease;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.ww-home-pill:hover {
  background: color-mix(in srgb, currentColor 14%, transparent);
  border-color: color-mix(in srgb, currentColor 32%, transparent);
  transform: translateY(-1px);
  color: inherit;
}
.ww-home-pill .ww-logo-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}
.ww-home-pill .ww-text-short {
  display: none;
}
@media (max-width: 600px) {
  .ww-home-pill {
    padding: 5px 9px 5px 5px;
    gap: 5px;
    font-size: 12.5px;
  }
  .ww-home-pill .ww-text-full {
    display: none;
  }
  .ww-home-pill .ww-text-short {
    display: inline;
  }
}


/* ========================================================
   Enhanced Levels World Map & Adventure Hub Styles
   ======================================================== */
.levels-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: 40px;
}

.levels-hero-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 22px 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.levels-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}

.levels-hero-title h1 {
  font-size: clamp(24px, 5.5vw, 32px);
  margin: 0 0 4px;
  letter-spacing: -0.8px;
  color: var(--text-main);
  line-height: 1.15;
}

.levels-hero-title p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.levels-stats-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.levels-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: var(--hud-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
}

.levels-progress-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.levels-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.levels-progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  position: relative;
}

.levels-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0284c7 0%, #06b6d4 50%, #10b981 100%);
  transition: width 0.4s ease;
}

/* Mode Switcher Tabs */
.mode-segmented-tabs {
  display: flex;
  gap: 6px;
  background: var(--hud-bg);
  padding: 5px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
}

.mode-tab-btn {
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.18s ease;
}

.mode-tab-btn:hover {
  background: color-mix(in srgb, currentColor 8%, transparent);
  color: var(--text-main);
}

.mode-tab-btn.active {
  background: var(--card-bg);
  color: var(--text-main);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border: 1px solid var(--card-border);
}

/* Chapters & Grids */
.chapters-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chapter-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chapter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.chapter-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chapter-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--chapter-accent, var(--mint));
}

.chapter-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.chapter-count {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--hud-bg);
  border: 1px solid var(--card-border);
}

.chapter-level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (min-width: 520px) {
  .chapter-level-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 6px;
  min-height: 86px;
  border-radius: 14px;
  border: 1.5px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-main);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
  text-align: center;
}

.level-card:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.level-card:active:not(:disabled) {
  transform: scale(0.97);
}

.level-card-number {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: var(--text-main);
}

.level-card-goal {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.level-card-status {
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 2px;
}

/* Completed Level */
.level-card.is-done {
  border-color: #10b981;
  background: color-mix(in srgb, #10b981 8%, var(--card-bg));
}

.level-card.is-done .level-card-status {
  color: #10b981;
}

/* Current Active Playable Level */
.level-card.is-current {
  border-color: var(--mint);
  border-width: 2px;
  background: color-mix(in srgb, var(--mint) 12%, var(--card-bg));
  box-shadow: 0 0 16px var(--mint-glow);
  transform: scale(1.02);
}

.level-card.is-current .level-card-status {
  background: var(--mint);
  color: #ffffff;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 10px;
  letter-spacing: 0.5px;
}

/* Locked Level */
.level-card.is-locked {
  opacity: 0.45;
  background: var(--hud-bg);
  cursor: not-allowed;
  pointer-events: none;
}

.level-card.is-locked .level-card-status {
  color: var(--text-muted);
}

/* Classic Endless Banner on Levels Screen */
.classic-overview-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 24px 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  align-items: center;
}

.classic-overview-box h2 {
  font-size: 24px;
  margin: 0;
  color: var(--text-main);
}

.classic-score-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 24px;
  border-radius: 16px;
  background: var(--hud-bg);
  border: 1px solid var(--card-border);
}

.classic-score-badge span {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
}

.classic-score-badge strong {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-main);
}

/* Milestones & Badges */
.milestones-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--card-shadow);
}

.milestones-box h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.milestone-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}

.milestone-item:last-child {
  border-bottom: none;
}

.milestone-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-main);
}

.milestone-left.unearned {
  color: var(--text-muted);
}

.milestone-progress {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}
