/* ═══════════════════════════════════════════════════════════
   BORDERLINE — design system
   ═══════════════════════════════════════════════════════════ */
:root {
  --bg-0: #04060f;
  --bg-1: #0b1026;
  --glass: rgba(13, 18, 38, 0.72);
  --glass-soft: rgba(13, 18, 38, 0.55);
  --line: rgba(255, 255, 255, 0.09);
  --ink: #eef2ff;
  --ink-dim: #9aa5c4;
  --cyan: #22d3ee;
  --violet: #818cf8;
  --purple: #c084fc;
  --green: #34d399;
  --amber: #fbbf24;
  --orange: #fb923c;
  --red: #f87171;
  --grad-aurora: linear-gradient(100deg, var(--cyan), var(--violet) 55%, var(--purple));
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.55);
  --radius: 20px;
  --font: "Avenir Next", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-1) 0%, var(--bg-0) 70%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.is-hidden { display: none !important; }

#stars {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

/* ═══ Loading screen ═══════════════════════════════════════ */
#loader {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(130% 100% at 50% 10%, #0d1330 0%, #04060f 75%);
  transition: opacity 0.7s ease, visibility 0.7s;
}
#loader.is-done { opacity: 0; visibility: hidden; }

.loader-aurora {
  position: absolute; inset: -20%;
  background:
    radial-gradient(40% 30% at 30% 25%, rgba(34, 211, 238, 0.14), transparent 70%),
    radial-gradient(35% 28% at 72% 20%, rgba(192, 132, 252, 0.13), transparent 70%),
    radial-gradient(45% 30% at 50% 80%, rgba(129, 140, 248, 0.10), transparent 70%);
  animation: aurora-drift 9s ease-in-out infinite alternate;
  filter: blur(10px);
}
@keyframes aurora-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.06); }
}

.loader-core { position: relative; text-align: center; padding: 24px; }

.loader-globe {
  position: relative; width: 150px; height: 150px; margin: 0 auto 34px;
  animation: float 4s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }

.lg-sphere {
  position: absolute; inset: 14px; border-radius: 50%;
  background:
    radial-gradient(circle at 33% 30%, rgba(255, 255, 255, 0.22), transparent 42%),
    radial-gradient(circle at 50% 50%, #1d3a6e 0%, #122348 55%, #0a142e 100%);
  box-shadow:
    0 0 50px rgba(34, 211, 238, 0.30),
    0 0 130px rgba(129, 140, 248, 0.18),
    inset -14px -12px 36px rgba(0, 0, 0, 0.55);
}
.lg-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid transparent;
}
.lg-ring-a {
  border-top-color: rgba(34, 211, 238, 0.85);
  border-right-color: rgba(34, 211, 238, 0.18);
  animation: spin 2.1s linear infinite;
}
.lg-ring-b {
  inset: -12px;
  border-bottom-color: rgba(192, 132, 252, 0.7);
  border-left-color: rgba(192, 132, 252, 0.14);
  animation: spin 3.4s linear infinite reverse;
}
.lg-ring-c {
  inset: 14px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, transparent 46%, rgba(34, 211, 238, 0.25) 50%, transparent 54%);
  animation: lat-sweep 2.6s ease-in-out infinite;
  opacity: 0.8;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes lat-sweep {
  0%, 100% { transform: scaleY(0.2) translateY(-26px); opacity: 0; }
  50% { transform: scaleY(1) translateY(0); opacity: 0.9; }
}
.lg-pin {
  position: absolute; left: 50%; top: 8%; width: 14px; height: 14px;
  margin-left: -7px; border-radius: 50% 50% 50% 0;
  background: var(--grad-aurora);
  transform: rotate(-45deg);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.9);
  animation: pin-drop 2.2s ease-in-out infinite;
}
@keyframes pin-drop {
  0%, 20% { transform: rotate(-45deg) translate(0, -26px); opacity: 0; }
  45%, 75% { transform: rotate(-45deg) translate(0, 0); opacity: 1; }
  100% { transform: rotate(-45deg) translate(0, 0); opacity: 0; }
}

.loader-title {
  font-size: clamp(38px, 7vw, 62px);
  font-weight: 800; letter-spacing: 0.14em;
  background: var(--grad-aurora);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.loader-title span { -webkit-text-fill-color: var(--ink); color: var(--ink); }
.loader-tag {
  margin-top: 10px; color: var(--ink-dim);
  letter-spacing: 0.28em; text-transform: uppercase; font-size: 11px;
}
.loader-bar {
  width: 220px; height: 3px; margin: 30px auto 14px;
  background: rgba(255, 255, 255, 0.08); border-radius: 3px; overflow: hidden;
}
.loader-bar-fill {
  height: 100%; width: 40%;
  background: var(--grad-aurora); border-radius: 3px;
  animation: bar-slide 1.2s ease-in-out infinite;
}
@keyframes bar-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(560px); }
}
.loader-hint { color: var(--ink-dim); font-size: 13px; min-height: 18px; }

/* ═══ Layout ═══════════════════════════════════════════════ */
#app { position: fixed; inset: 0; z-index: 1; }
#app.is-faded-in { animation: app-in 0.8s ease both; }
@keyframes app-in { from { opacity: 0; } to { opacity: 1; } }

#globe-wrap { position: absolute; inset: 0; }
#globe { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#globe.is-dragging { cursor: grabbing; }

#globe-tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  padding: 5px 11px; border-radius: 999px;
  background: rgba(8, 12, 28, 0.85); border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 12.5px; letter-spacing: 0.04em; color: var(--ink);
  transform: translate(-50%, -160%);
  white-space: nowrap;
}

/* ═══ Top bar ══════════════════════════════════════════════ */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  background: linear-gradient(180deg, rgba(4, 6, 15, 0.85), transparent);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 800; letter-spacing: 0.13em; font-size: 16px;
}
.brand-accent {
  background: var(--grad-aurora);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--grad-aurora);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.8);
}
.topbar-context { flex: 1; text-align: center; color: var(--ink-dim); font-size: 13px; letter-spacing: 0.18em; text-transform: uppercase; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; font-size: 16px;
  background: var(--glass-soft); border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { transform: translateY(-2px); border-color: rgba(34, 211, 238, 0.45); }

/* ═══ Panels & buttons ═════════════════════════════════════ */
.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 26px; border-radius: 14px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.03em;
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--grad-aurora); color: #071018;
  box-shadow: 0 8px 28px rgba(99, 179, 237, 0.35);
}
.btn-primary:hover { filter: brightness(1.12); transform: translateY(-2px); }
.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line); color: var(--ink);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.10); }
.btn-small { padding: 8px 16px; font-size: 13px; border-radius: 11px; }

/* ═══ Menu ═════════════════════════════════════════════════ */
.screen {
  position: absolute; inset: 0; z-index: 8;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 90px 20px 40px;
  pointer-events: none;
}
.screen > * { pointer-events: auto; }

.menu-hero { text-align: center; animation: rise 0.7s ease both; }
.menu-title {
  font-size: clamp(30px, 5.4vw, 52px); font-weight: 800; line-height: 1.12;
  text-shadow: 0 6px 40px rgba(0, 0, 0, 0.7);
}
.menu-title em {
  font-style: normal;
  background: var(--grad-aurora);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.menu-cards { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.menu-card {
  position: relative; overflow: hidden;
  width: min(320px, 86vw); text-align: left;
  padding: 22px 24px 20px;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s ease, border-color 0.2s ease;
  animation: rise 0.7s ease 0.12s both;
}
.menu-card:nth-child(2) { animation-delay: 0.22s; }
.menu-card:hover { transform: translateY(-5px) scale(1.015); border-color: rgba(34, 211, 238, 0.4); }
.mc-glow {
  position: absolute; inset: -40%; pointer-events: none; opacity: 0;
  background: radial-gradient(45% 45% at 50% 50%, rgba(34, 211, 238, 0.12), transparent 70%);
  transition: opacity 0.25s ease;
}
.menu-card:hover .mc-glow { opacity: 1; }
.menu-card-practice .mc-glow { background: radial-gradient(45% 45% at 50% 50%, rgba(192, 132, 252, 0.12), transparent 70%); }
.menu-card-learn .mc-glow { background: radial-gradient(45% 45% at 50% 50%, rgba(52, 211, 153, 0.13), transparent 70%); }
.menu-card-learn:nth-child(2) { animation-delay: 0.18s; }
.menu-card:nth-child(3) { animation-delay: 0.26s; }
.mc-badge.is-due { background: rgba(251, 191, 36, 0.15); color: var(--amber); border-color: rgba(251, 191, 36, 0.4); }
.mc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.mc-emoji { font-size: 30px; filter: drop-shadow(0 4px 14px rgba(34, 211, 238, 0.35)); }
.mc-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(52, 211, 153, 0.16); color: var(--green);
  border: 1px solid rgba(52, 211, 153, 0.35);
}
.mc-badge.is-live { background: rgba(34, 211, 238, 0.14); color: var(--cyan); border-color: rgba(34, 211, 238, 0.4); animation: badge-pulse 2s ease-in-out infinite; }
@keyframes badge-pulse { 50% { box-shadow: 0 0 16px rgba(34, 211, 238, 0.45); } }
.menu-card h3 { font-size: 21px; margin-bottom: 6px; }
.menu-card p { color: var(--ink-dim); font-size: 14px; line-height: 1.45; }
.mc-meta { margin-top: 14px; font-size: 12.5px; color: var(--ink-dim); letter-spacing: 0.04em; display: flex; gap: 14px; }
.mc-meta b { color: var(--ink); }
.menu-foot { color: var(--ink-dim); font-size: 13.5px; letter-spacing: 0.05em; animation: rise 0.7s ease 0.32s both; }
.menu-foot b { color: var(--amber); }
.menu-links { animation: rise 0.7s ease 0.4s both; color: var(--ink-dim); font-size: 12px; }
.menu-links a, .menu-links .link-btn {
  color: var(--ink-dim); font-size: 12px; letter-spacing: 0.08em;
  text-decoration: none; opacity: 0.8;
}
.menu-links a:hover, .menu-links .link-btn:hover { color: var(--cyan); opacity: 1; }

/* ═══ Archive ═══ */
.archive-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px; max-height: 44vh; overflow-y: auto; padding: 2px;
}
.archive-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 6px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  font-size: 13px; transition: all 0.15s ease;
}
.archive-chip:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(34, 211, 238, 0.45); transform: translateY(-2px); }
.archive-chip small { color: var(--ink-dim); font-size: 10.5px; }
.archive-chip .ac-state { font-size: 11px; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.archive-chip .ac-unplayed { color: var(--cyan); }
.archive-chip.is-done { opacity: 0.75; }
.archive-tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; vertical-align: middle;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(129, 140, 248, 0.16); color: var(--violet);
  border: 1px solid rgba(129, 140, 248, 0.35);
}
.howto-toggle {
  display: flex; align-items: center; gap: 9px; margin-top: 16px;
  font-size: 13px; color: var(--ink-dim); cursor: pointer;
}
.howto-toggle input { accent-color: #22d3ee; width: 16px; height: 16px; }

/* ═══ Practice setup ═══════════════════════════════════════ */
.setup-panel { width: min(560px, 94vw); padding: 28px 30px; max-height: 84vh; overflow-y: auto; }
.panel-title { font-size: 24px; font-weight: 800; margin-bottom: 18px; }
.setup-label {
  margin: 18px 0 9px; font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-dim);
}
.seg { display: flex; gap: 8px; }
.seg-wrap { flex-wrap: wrap; }
.seg-btn {
  flex: 1; min-width: 76px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 8px; border-radius: 13px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  font-size: 14px; font-weight: 600; color: var(--ink-dim);
  transition: all 0.15s ease;
}
.seg-btn small { font-size: 10.5px; font-weight: 500; opacity: 0.75; }
.seg-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }
.seg-btn.is-active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.16), rgba(129, 140, 248, 0.16));
  border-color: rgba(34, 211, 238, 0.55); color: var(--ink);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.12) inset;
}
.setup-count { margin-top: 18px; color: var(--ink-dim); font-size: 13.5px; }
.setup-count b { color: var(--cyan); }
.setup-actions { display: flex; justify-content: space-between; margin-top: 20px; gap: 12px; flex-wrap: wrap; }
.setup-actions-right { display: flex; gap: 10px; flex-wrap: wrap; }
.setup-blurb { color: var(--ink-dim); font-size: 13.5px; line-height: 1.55; margin-bottom: 4px; }

/* ═══ Learn summary & progress map ═════════════════════════ */
.mastery-bar {
  display: flex; height: 12px; border-radius: 7px; overflow: hidden;
  margin: 16px 0 10px; background: rgba(255, 255, 255, 0.06);
}
.mastery-bar div { height: 100%; transition: width 0.5s cubic-bezier(0.2, 0.9, 0.3, 1); }
.mastery-chips { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--ink-dim); }
.mastery-chips span {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
}
.mastery-chips i { width: 9px; height: 9px; border-radius: 50%; font-style: normal; }
.mastery-chips b { color: var(--ink); }
.mastery-pct { margin-top: 12px; font-size: 13.5px; color: var(--ink-dim); }
.mastery-pct b {
  font-size: 17px;
  background: var(--grad-aurora);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.learn-due-line { margin-top: 6px; font-size: 13px; color: var(--amber); }

.progress-panel {
  position: absolute; left: 22px; top: 86px;
  width: min(310px, calc(100vw - 44px));
  max-height: calc(100vh - 130px); overflow-y: auto;
  padding: 20px 22px;
  pointer-events: auto;
  animation: rise 0.5s ease both;
}
.progress-title { font-size: 20px; font-weight: 800; margin-bottom: 10px; }
.heat-legend { display: flex; flex-direction: column; gap: 5px; margin: 14px 0; }
.heat-legend .hl-row { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--ink-dim); }
.heat-legend .hl-swatch { width: 26px; height: 11px; border-radius: 4px; flex-shrink: 0; }
.weak-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 9px; border-radius: 10px; margin-bottom: 5px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  font-size: 13px;
}
.weak-row .wr-flag { font-size: 16px; }
.weak-row .wr-name { flex: 1; font-weight: 600; }
.weak-row .wr-lvl { font-size: 11.5px; color: var(--ink-dim); }
.progress-hint { font-size: 12px; color: var(--ink-dim); margin: 10px 0 12px; line-height: 1.5; }

/* ═══ HUD ══════════════════════════════════════════════════ */
#hud { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.hud-prompt {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%);
  min-width: 280px; max-width: min(480px, 92vw);
  padding: 14px 24px 12px; text-align: center;
  pointer-events: auto;
  animation: prompt-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes prompt-in { from { opacity: 0; transform: translate(-50%, -16px) scale(0.94); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
.hud-prompt-kind { font-size: 10.5px; font-weight: 800; letter-spacing: 0.3em; color: var(--cyan); margin-bottom: 4px; }
.hud-prompt-main { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 40px; }
.hud-flag { font-size: 34px; line-height: 1; filter: drop-shadow(0 3px 8px rgba(0,0,0,0.5)); }
.hud-name { font-size: clamp(20px, 3.4vw, 28px); font-weight: 800; letter-spacing: 0.01em; }
.hud-shape { width: 200px; height: 132px; filter: drop-shadow(0 0 14px rgba(34, 211, 238, 0.35)); }
.hud-pips { display: flex; gap: 7px; justify-content: center; margin-top: 10px; }
.hud-timer {
  position: relative; height: 10px; margin-top: 10px;
  border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden;
}
.hud-timer-fill {
  height: 100%; width: 100%; border-radius: 6px;
  background: linear-gradient(90deg, #22d3ee, #818cf8);
  transition: width 0.1s linear;
}
.hud-timer.is-warn .hud-timer-fill { background: linear-gradient(90deg, #fbbf24, #fb923c); }
.hud-timer.is-danger .hud-timer-fill { background: linear-gradient(90deg, #fb923c, #f87171); }
.hud-timer-num {
  position: absolute; right: 8px; top: -22px;
  font-size: 13px; font-weight: 800; color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.hud-timer.is-danger .hud-timer-num { color: var(--red); }
.blitz-chip { color: var(--amber); font-weight: 700; }
.hud-pip { width: 26px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.14); transition: background 0.3s; }
.hud-pip.is-on { background: var(--grad-aurora); }
.hud-pip.is-lost { background: rgba(248, 113, 113, 0.65); }

.hud-side {
  position: absolute; right: 18px; top: 74px;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: auto;
}
.hud-score { padding: 10px 18px; text-align: right; }
.hud-score span { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; display: block; }
.hud-score small { color: var(--ink-dim); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }

#toast {
  position: absolute; bottom: 12vh; left: 50%; transform: translateX(-50%);
  z-index: 9; pointer-events: none;
  padding: 12px 22px; border-radius: 16px;
  background: rgba(8, 12, 28, 0.92); border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  font-size: 15.5px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
  max-width: 92vw;
}
#toast small { display: block; font-weight: 500; color: var(--ink-dim); font-size: 12.5px; margin-top: 2px; }
#toast.is-bad { border-color: rgba(248, 113, 113, 0.4); }
#toast.is-bad b { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px) scale(0.92); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }

/* ═══ Reveal card ══════════════════════════════════════════ */
#reveal {
  position: absolute; inset: 0; z-index: 12;
  display: grid; place-items: end center;
  padding-bottom: 5vh; pointer-events: none;
}
.reveal-card {
  width: min(420px, 92vw); text-align: center;
  padding: 24px 26px 22px; pointer-events: auto;
  animation: reveal-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.18) both;
}
@keyframes reveal-in { from { opacity: 0; transform: translateY(40px) scale(0.93); } to { opacity: 1; transform: none; } }
.reveal-grade { font-size: 12px; font-weight: 800; letter-spacing: 0.3em; margin-bottom: 8px; }
.reveal-grade.g-great { color: var(--green); }
.reveal-grade.g-good { color: var(--amber); }
.reveal-grade.g-ok { color: var(--orange); }
.reveal-grade.g-miss { color: var(--red); }
.reveal-flag { font-size: 52px; line-height: 1.1; filter: drop-shadow(0 6px 18px rgba(0,0,0,0.5)); }
.reveal-name { font-size: 26px; font-weight: 800; margin: 6px 0 4px; }
.reveal-facts { color: var(--ink-dim); font-size: 13.5px; line-height: 1.55; }
.reveal-points {
  margin: 14px 0 16px; font-size: 30px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--grad-aurora);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.reveal-points small { font-size: 14px; -webkit-text-fill-color: var(--ink-dim); color: var(--ink-dim); font-weight: 600; }

/* ═══ Modals ═══════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 20px;
  background: rgba(2, 4, 12, 0.66);
  backdrop-filter: blur(6px);
  animation: app-in 0.25s ease both;
}
.modal {
  width: min(480px, 94vw); max-height: 86vh; overflow-y: auto;
  padding: 26px 28px;
  animation: reveal-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.18) both;
}
.modal h2 { font-size: 23px; font-weight: 800; margin-bottom: 4px; }
.modal .modal-sub { color: var(--ink-dim); font-size: 13.5px; margin-bottom: 18px; }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  width: 32px; height: 32px; border-radius: 10px;
  background: rgba(255,255,255,0.06); font-size: 14px;
}
.modal-wrap { position: relative; }

.howto-step { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.howto-emoji { font-size: 24px; width: 34px; text-align: center; flex-shrink: 0; }
.howto-step > div > b { display: block; margin-bottom: 2px; }
.howto-step p { color: var(--ink-dim); font-size: 13.5px; line-height: 1.5; }
.howto-step p b { color: var(--ink); }
.howto-scale { display: flex; gap: 6px; justify-content: center; margin: 16px 0 4px; font-size: 13px; flex-wrap: wrap; }
.howto-scale span { padding: 5px 11px; border-radius: 999px; background: rgba(255,255,255,0.05); border: 1px solid var(--line); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0 20px; }
.stat-cell { text-align: center; padding: 12px 4px; border-radius: 14px; background: rgba(255,255,255,0.045); border: 1px solid var(--line); }
.stat-cell b { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-cell.is-hot b { color: var(--amber); }
.stat-cell span { font-size: 10.5px; color: var(--ink-dim); letter-spacing: 0.08em; text-transform: uppercase; }
.dist-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; font-size: 12.5px; }
.dist-row .dist-label { width: 70px; color: var(--ink-dim); text-align: right; }
.dist-bar-track { flex: 1; height: 18px; border-radius: 6px; background: rgba(255,255,255,0.05); overflow: hidden; }
.dist-bar {
  height: 100%; border-radius: 6px; min-width: 22px;
  background: linear-gradient(90deg, rgba(34,211,238,0.7), rgba(129,140,248,0.7));
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 7px; font-weight: 700; font-size: 11px;
  transition: width 0.6s cubic-bezier(0.2, 0.9, 0.3, 1);
}

/* Results */
.results-score {
  text-align: center; font-size: 52px; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums; margin: 8px 0 2px;
  background: var(--grad-aurora);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.results-sub { text-align: center; color: var(--ink-dim); font-size: 13px; margin-bottom: 18px; }
.results-rows { margin-bottom: 18px; }
.result-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 12px; margin-bottom: 6px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  font-size: 14px;
}
.result-row .rr-emoji { font-size: 17px; }
.result-row .rr-flag { font-size: 19px; }
.result-row .rr-name { flex: 1; font-weight: 600; }
.result-row .rr-pts { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink-dim); }
.results-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.results-countdown { text-align: center; color: var(--ink-dim); font-size: 13px; margin-top: 16px; }
.results-countdown b { color: var(--cyan); font-variant-numeric: tabular-nums; }
.results-streakline { text-align: center; margin-bottom: 14px; font-size: 14.5px; }
.results-streakline b { color: var(--amber); }
.results-standing { text-align: center; font-size: 14.5px; color: var(--ink-dim); margin: -8px 0 14px; min-height: 1em; }
.results-standing b { color: var(--cyan); }

#coach {
  position: absolute; bottom: 22vh; left: 50%; transform: translateX(-50%);
  z-index: 9; pointer-events: none;
  padding: 11px 22px; border-radius: 999px;
  background: rgba(8, 12, 28, 0.88); border: 1px solid rgba(34, 211, 238, 0.35);
  backdrop-filter: blur(10px);
  font-size: 14.5px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 0 26px rgba(34, 211, 238, 0.18);
  animation: coach-pulse 2.2s ease-in-out infinite;
  transition: opacity 0.5s ease;
}
#coach.is-fading { opacity: 0; }
@keyframes coach-pulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.04); }
}

#confetti { position: fixed; inset: 0; z-index: 60; pointer-events: none; width: 100%; height: 100%; }

/* ═══ Responsive ═══════════════════════════════════════════ */
/* small screens (or short landscape): menu & setup screens scroll
   instead of clipping; the globe behind them is decorative there */
@media (max-width: 640px), (max-height: 720px) {
  #menu, #practice-setup, #learn-setup {
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    padding: 76px 16px 34px;
  }
  #menu { gap: 18px; }
  .menu-card { animation: rise 0.5s ease both; }
}

@media (max-width: 640px) {
  .hud-prompt { top: 64px; padding: 10px 16px 10px; min-width: 240px; }
  .hud-flag { font-size: 26px; }
  .hud-side { top: auto; bottom: 18px; right: 14px; flex-direction: row; align-items: center; }
  .hud-score { padding: 8px 14px; } .hud-score span { font-size: 19px; }
  .topbar-context { display: none; }
  #toast { bottom: 18vh; }
  .menu-cards { flex-direction: column; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .progress-panel { left: 10px; right: 10px; width: auto; top: auto; bottom: 12px; max-height: 46vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
