/* ─── TOKENS ──────────────────────────────────────────────── */
:root {
  --bg:       #111111;
  --surface:  #ffffff;
  --surface2: #f6f6f4;
  --ink:      #0d0d0d;
  --muted:    #888888;
  --border:   #e0e0e0;
  --yellow:   #F5E800;
  --red:      #f03030;
  --red-bg:   #ffd4d4;
  --green:    #1a9e5c;
  --green-bg: #e6f7ef;
  --topbar-h: 56px;
  --sidebar-w: 220px;
}

/* ─── RESET ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, a { font: inherit; cursor: pointer; text-decoration: none; }
button { border: none; background: none; color: inherit; }

/* ─── SCREENS ─────────────────────────────────────────────── */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; animation: fadeIn .22s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── TOPBAR ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}

/* ─── BRAND ───────────────────────────────────────────────── */
.brand {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -.01em;
  color: #ffffff;
  text-decoration: none;
  line-height: 1;
}
.brand-dot { color: var(--yellow); }

/* ─── ICON BUTTONS ────────────────────────────────────────── */
.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #aaa;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: #fff; background: #222; }

/* ─── LEVEL NAV ───────────────────────────────────────────── */
.level-nav {
  display: flex;
  align-items: center;
  gap: 0;
  background: #222;
  border-radius: 999px;
  padding: 4px 6px;
}
.nav-arrow {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #ccc;
  font-size: 18px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.nav-arrow:hover { color: #fff; background: #333; }
.level-label {
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  padding: 0 10px;
  white-space: nowrap;
  letter-spacing: .02em;
}

/* ─── TOPBAR RIGHT ────────────────────────────────────────── */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.hint-topbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: #222;
  color: #ccc;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  transition: color .15s, background .15s;
}
.hint-topbar-btn:hover { background: #2e2e2e; color: #fff; }

/* ─── HOME ────────────────────────────────────────────────── */
.home-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px 32px;
}
.home-hero {
  max-width: 680px;
  width: 100%;
}
.eyebrow {
  font-family: "Space Grotesk", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--muted);
  margin-bottom: 20px;
}
h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(58px, 11vw, 110px);
  font-weight: 700;
  line-height: .92;
  letter-spacing: -.04em;
  color: #ffffff;
  margin-bottom: 28px;
}
.hero-copy {
  font-size: clamp(17px, 2.5vw, 20px);
  line-height: 1.5;
  color: #aaa;
  margin-bottom: 40px;
  max-width: 520px;
}
.primary-btn {
  display: inline-flex;
  align-items: center;
  padding: 16px 32px;
  background: var(--yellow);
  color: var(--ink);
  border-radius: 999px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .06em;
  transition: transform .12s ease, box-shadow .12s ease;
  box-shadow: 0 0 0 0 transparent;
}
.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(245,232,0,.25);
}

/* ─── HOME LEGEND ─────────────────────────────────────────── */
.home-legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  background: var(--bg);
  border-top: 1px solid #222;
  padding: 32px 24px;
}
.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  flex: 1 1 160px;
  max-width: 200px;
  padding: 16px 12px;
  color: #aaa;
}
.legend-icon {
  width: 32px;
  height: 32px;
  color: var(--yellow);
  flex-shrink: 0;
}
.legend-item strong {
  font-family: "Space Grotesk", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #fff;
}
.legend-item span {
  font-size: 12px;
  line-height: 1.4;
  color: #777;
}

/* ─── FOOTER ──────────────────────────────────────────────── */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid #222;
  background: var(--bg);
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 8px;
}
.footer-brand {
  font-size: 16px;
}
.footer-tagline {
  font-size: 12px;
  color: #555;
  text-align: center;
}
.footer-credit {
  font-size: 11px;
  color: #444;
  letter-spacing: .04em;
  font-weight: 500;
}

/* ─── GAME LAYOUT ─────────────────────────────────────────── */
.game-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ─── SIDEBAR ─────────────────────────────────────────────── */
.game-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 28px 20px 24px;
  border-right: 1px solid #1e1e1e;
  background: #161616;
  overflow-y: auto;
}
.stat-block {
  padding-bottom: 22px;
  margin-bottom: 20px;
  border-bottom: 1px solid #252525;
}
.stat-block:last-of-type { border-bottom: none; }
.stat-label {
  font-family: "Space Grotesk", sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .15em;
  color: #555;
  margin-bottom: 6px;
}
.stat-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  margin-bottom: 4px;
}
.stat-value.error-val { color: var(--red); }
.stat-sub {
  font-size: 12px;
  color: #555;
  margin-bottom: 12px;
}
.progress-track {
  width: 100%;
  height: 5px;
  background: #2a2a2a;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--yellow);
  border-radius: 999px;
  transition: width .3s ease;
}

/* ─── HINT BUTTON ─────────────────────────────────────────── */
.hint-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 12px 16px;
  background: var(--yellow);
  color: var(--ink);
  border-radius: 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
  margin-top: 8px;
  transition: opacity .15s, transform .12s;
}
.hint-btn:hover { opacity: .9; transform: translateY(-1px); }
.hint-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.hint-avail {
  text-align: center;
  font-size: 11px;
  color: #444;
  margin-top: 8px;
}

/* ─── GAME MAIN ───────────────────────────────────────────── */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 32px 36px 80px; /* bottom clears thin fixed footer */
  overflow-y: auto;
  background: var(--surface);
  min-width: 0;
}
h2 {
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: 1.05;
  color: var(--ink);
  margin-bottom: 22px;
}

/* ─── TEXT CARD ───────────────────────────────────────────── */
.text-card {
  font-size: clamp(16px, 2vw, 18px);
  line-height: 2;
  color: var(--ink);
  user-select: none;
  flex: 1;
}
.token {
  display: inline;
  border-radius: 4px;
  padding: 1px 1px;
  transition: background .12s ease;
  cursor: pointer;
}
.plain-token:hover { background: rgba(245,232,0,.35); }
.error-token:hover { background: rgba(245,232,0,.4); }

.token.correct {
  background: var(--red-bg);
  color: var(--red);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}
.token.correct::after {
  content: attr(data-correction);
  display: inline;
  margin-left: 4px;
  padding: 1px 5px;
  background: #d4f3e5;
  color: var(--green);
  border-radius: 3px;
  text-decoration: none;
  font-size: .85em;
  font-weight: 700;
}
.token.wrong { animation: shake .26s ease; background: #ffe4e4; }
.token.hint {
  outline: 2.5px solid var(--yellow);
  outline-offset: 2px;
  background: rgba(245,232,0,.18);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%  { transform: translateX(-4px); }
  75%  { transform: translateX(4px); }
}

/* ─── FEEDBACK BOX ────────────────────────────────────────── */
.feedback-box {
  margin-top: 24px;
  padding: 14px 18px;
  background: var(--green-bg);
  border: 1.5px solid #b2e6cf;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: opacity .2s;
}
.feedback-box.hidden { display: none; }
.feedback-correct-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--green);
}
.feedback-msg {
  font-size: 13px;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 5px;
}
.feedback-msg::before { content: "✓"; font-weight: 700; }

/* bad feedback */
.feedback-box.bad {
  background: #fff2f2;
  border-color: #ffcccc;
}
.feedback-box.bad .feedback-correct-label,
.feedback-box.bad .feedback-msg { color: var(--red); }
.feedback-box.bad .feedback-msg::before { content: "✗"; }

/* ─── GAME FOOT ───────────────────────────────────────────── */
.game-foot {
  display: flex;
  justify-content: flex-end;
  padding-top: 20px;
  margin-top: 8px;
}
.next-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 26px;
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .06em;
  transition: opacity .15s, transform .12s;
}
.next-btn:hover { opacity: .85; transform: translateY(-1px); }
.next-btn.hidden { display: none; }

/* ─── GAME BOTTOM STACK (fixed) ───────────────────────────── */
.game-bottom-stack {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
}

/* ─── MOBILE BAR ──────────────────────────────────────────── */
.mobile-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 12px;
}
.mobile-stats {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.mobile-stat-val {
  font-family: "Space Grotesk", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.mobile-stat-val small { font-size: 12px; }
.mobile-stat-val.error-val { color: var(--red); }
.mobile-stat-lbl { font-size: 11px; color: var(--muted); }
.mobile-stat-sep { color: var(--border); }
.mobile-hint-btn {
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 12px;
  flex-shrink: 0;
}

/* ─── THIN FOOTER (game screen) ───────────────────────────── */
.game-thin-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  background: var(--bg);
  border-top: 1px solid #222;
}
.game-footer-brand {
  font-size: 13px;
}
.game-footer-credit {
  font-size: 11px;
  color: #444;
  letter-spacing: .04em;
}

/* ─── FINAL SCREEN ────────────────────────────────────────── */
.final-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}
.final-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 540px;
  width: 100%;
}
.final-card .eyebrow { color: #666; margin-bottom: 24px; }
.final-icon {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  background: var(--yellow);
  border-radius: 24px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 28px;
}
.final-card h2 {
  font-size: clamp(40px, 8vw, 72px);
  color: #ffffff;
  margin-bottom: 20px;
}
.final-stats {
  font-size: 18px;
  color: #888;
  margin-bottom: 40px;
  line-height: 1.5;
}

/* ─── MODAL ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 32px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { transform: scale(.92); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal-eyebrow {
  font-family: "Space Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--muted);
}
.modal-body {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink);
}
.modal-close-btn {
  margin-top: 8px;
  padding: 12px 32px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .06em;
  transition: opacity .15s;
}
.modal-close-btn:hover { opacity: .8; }

/* ─── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 700px) {
  .game-layout { flex-direction: column; overflow: visible; }

  .game-sidebar { display: none; }

  .game-main {
    padding: 20px 18px 160px; /* clears mobile-bar + thin footer */
    overflow: visible;
  }
  .game-foot { padding-top: 16px; }
  .next-btn { width: 100%; justify-content: center; }

  .mobile-bar { display: flex; }

  h2 { margin-bottom: 14px; }

  .home-legend { padding: 20px 8px; }
  .legend-item { padding: 12px 8px; flex-basis: 140px; }
}

/* Desktop: game-bottom-stack only shows thin footer */
@media (min-width: 701px) {
  .game-bottom-stack {
    /* stack only has thin footer on desktop; sidebar is visible */
  }
  .game-sidebar {
    padding-bottom: 60px; /* clears thin footer */
  }
}

@media (max-width: 480px) {
  .topbar { padding: 0 14px; }
  .brand { font-size: 19px; }
  .level-label { font-size: 12px; }
  h1 { letter-spacing: -.05em; }
  .home-main { padding: 32px 18px 24px; }
}
