/* nth — abstract-reasoning sprint
   :root tokens → base → components → responsive → dark mode
   Calm layout, Apple-style accents: an iOS blue→indigo gradient does the
   talking; figures stay clean monochrome so the puzzles read clearly. */

/* Space Grotesk — a geometric grotesk that suits the abstract, constructed
   feel of the puzzles. Self-hosted (variable, 300–700) so it works offline and
   needs no CDN. Latin covers en/fr/nl/de/es; latin-ext is loaded only if needed. */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("space-grotesk-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("space-grotesk-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #eef3f1;              /* cool off-white, faint teal */
  --surface: #ffffff;        /* solid fallback when glass unsupported */
  --glass: rgba(255, 255, 255, .62);
  --glass-border: rgba(255, 255, 255, .75);
  --glass-blur: 16px;
  --ink: #19231f;            /* deep teal-charcoal */
  --muted: #5f6f6a;
  --line: #dde7e3;
  --accent: #2f8e80;         /* Nordic aurora teal — the signature */
  --accent-2: #3fa68d;       /* one hue family, for gentle depth */
  --accent-grad: linear-gradient(135deg, #2f8e80 0%, #3fa68d 100%);
  --accent-soft: rgba(47, 142, 128, .12);
  --good: #3f9d6e;           /* muted green */
  --bad: #c75c54;            /* muted terracotta */

  --shadow: 0 1px 3px rgba(20, 45, 40, .06), 0 10px 30px rgba(20, 45, 40, .07);
  --shadow-accent: 0 6px 20px rgba(47, 142, 128, .3);
  --r-card: 18px;
  --r-tile: 13px;
  --font: "Space Grotesk", -apple-system, "Inter", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1815;             /* deep teal-black page */
    --surface: #1c2925;        /* solid fallback, clearly above bg */
    /* glass is kept fairly opaque in dark so cards read as raised panels
       instead of melting into the near-black background */
    --glass: rgba(38, 53, 48, .78);
    --glass-border: rgba(155, 205, 192, .16);
    --ink: #e8f0ec;
    --muted: #93aaa2;
    --line: #2c3b36;           /* brighter hairline so edges survive */
    --accent: #3ec5aa;
    --accent-2: #50d8b6;
    --accent-grad: linear-gradient(135deg, #34bf9f 0%, #50d8b6 100%);
    --accent-soft: rgba(62, 197, 170, .16);
    --good: #58c98f;
    --bad: #e1857d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 14px 36px rgba(0, 0, 0, .42);
    --shadow-accent: 0 6px 22px rgba(62, 197, 170, .32);
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  /* soft aurora washes give the glass something to refract */
  background-image:
    radial-gradient(1100px 540px at 82% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(820px 520px at -8% 8%, rgba(63, 166, 141, .12), transparent 55%),
    radial-gradient(900px 600px at 50% 116%, rgba(47, 142, 128, .1), transparent 58%);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

button { font-family: inherit; cursor: pointer; }

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- header ---------- */
.header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.title-block { display: flex; flex-direction: column; gap: 2px; }

/* header actions: info button + language selector */
.header-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.iconbtn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background-color: var(--surface);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
}
@media (hover: hover) { .iconbtn:hover { border-color: var(--accent); } }

/* language selector */
.lang { flex: 0 0 auto; }
.lang select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237f8c87' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 30px 9px 14px;
  min-height: 40px;
  cursor: pointer;
}
@media (hover: hover) { .lang select:hover { border-color: var(--accent); } }

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.wordmark {
  margin: 0;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1;
  width: max-content;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

/* ---------- liquid glass ----------
   Surfaces are solid by default. Where backdrop-filter is supported (and the
   user hasn't asked for reduced transparency) they become translucent frosted
   glass over the aurora background — Apple's current "Liquid Glass" direction. */
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  @media (prefers-reduced-transparency: no-preference) {
    .card, .results, .modal, .diff-card, .lang select, .reset, .ghost, .iconbtn {
      background-color: var(--glass);
      -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
      backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
      border-color: var(--glass-border);
    }
    .modal-overlay { background: rgba(15, 26, 23, .38); }
  }
}

/* ---------- screens ---------- */
.screen { display: flex; flex-direction: column; gap: 16px; }
.screen[hidden] { display: none; }

/* ---------- menu ---------- */
.lede { margin: 0; font-size: 16px; color: var(--muted); }
.lede em { color: var(--ink); font-style: italic; }

.diff { display: flex; flex-direction: column; gap: 10px; }

.diff-card {
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-tile);
  padding: 14px 16px;
  min-height: 70px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "glyph head best" "glyph desc best";
  align-items: center;
  gap: 2px 14px;
  color: var(--ink);
  transition: border-color .15s ease, background .15s ease;
}
.diff-glyph {
  grid-area: glyph;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  transition: background .15s ease, border-color .15s ease;
}
.diff-glyph .glyph { width: 84%; height: 84%; }
.diff-card[aria-checked="true"] .diff-glyph { background: var(--accent-soft); border-color: transparent; }
.diff-head { grid-area: head; display: flex; align-items: baseline; gap: 10px; }
.diff-n {
  font-size: 15px; font-weight: 700; color: #fff; background: var(--muted);
  width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center;
  transition: background .15s ease;
}
.diff-name { font-size: 17px; font-weight: 700; }
.diff-desc { grid-area: desc; font-size: 13px; color: var(--muted); }
.diff-best {
  grid-area: best; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); text-align: right;
}
.diff-best strong { display: block; font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }

.diff-card[aria-checked="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  box-shadow: var(--shadow-accent);
}
.diff-card[aria-checked="true"] .diff-n { background: var(--accent-grad); }
@media (hover: hover) {
  .diff-card:not([aria-checked="true"]):hover { border-color: var(--muted); }
}

.rules-strip {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  font-size: 13px; color: var(--muted);
}
.rules-strip b { color: var(--ink); font-weight: 700; }

/* primary call-to-action + ghost button */
.cta {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: var(--r-tile);
  background: var(--accent-grad);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  box-shadow: var(--shadow-accent);
  transition: filter .15s ease, transform .12s ease, box-shadow .15s ease;
}
@media (hover: hover) { .cta:hover { filter: brightness(1.06); } }
.cta:active { transform: scale(.99); }

.ghost {
  width: 100%;
  min-height: 46px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-tile);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}
@media (hover: hover) { .ghost:hover { color: var(--ink); border-color: var(--muted); } }

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 14px;
}
.timer { flex: 1; display: flex; align-items: center; gap: 10px; }
.timer-bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.timer-bar span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--accent-grad);
  transition: width .1s linear;
}
.timer-bar span.low { background: var(--bad); }
.timer-num {
  font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 3.2ch; text-align: right;
}
.timer-num.low { color: var(--bad); }

.hud-right { display: flex; align-items: center; gap: 12px; }
.hud-stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.hud-label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.hud-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-val.accent { color: var(--accent); }
.quit {
  width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  font-size: 15px; line-height: 1; display: grid; place-items: center;
}
@media (hover: hover) { .quit:hover { color: var(--bad); border-color: var(--bad); } }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tag-row { display: flex; flex-direction: column; gap: 6px; }

.tag {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}

.instruction { margin: 0; font-size: 15px; color: var(--muted); }

/* stimulus — sequence */
.stimulus.sequence {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.stimulus.sequence .cell {
  flex: 0 0 auto;
  width: clamp(58px, 22vw, 88px);
}

/* stimulus — matrix */
.stimulus.matrix {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.cell {
  aspect-ratio: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px;
  display: grid;
  place-items: center;
}

.cell.qcell {
  border-style: dashed;
  border-color: var(--accent);
  background: transparent;
}

.glyph { width: 100%; height: 100%; display: block; overflow: visible; }

.glyph .ln { stroke: var(--ink); stroke-width: 1.7; fill: none; }
.glyph .ln2 {
  stroke: var(--ink); stroke-width: 2; fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.glyph .spoke { stroke: var(--ink); stroke-width: 1; opacity: .45; }
.glyph .fill-ink { fill: var(--ink); }
.glyph .qmark { fill: var(--accent); font-size: 46px; font-weight: 700; font-family: var(--font); }

/* ---------- options ---------- */
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option {
  position: relative;
  min-height: 44px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--r-tile);
  padding: 12px;
  display: grid;
  place-items: center;
  transition: border-color .15s ease, transform .12s ease, background .15s ease;
}

.option .opt-letter {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.option .opt-glyph { width: 78%; }

@media (hover: hover) {
  .option:not(.locked):hover { border-color: var(--accent); }
}
.option:not(.locked):active { transform: scale(.98); }

.option.locked { cursor: default; }

.option .seal {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.option.correct {
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 9%, var(--surface));
  animation: seal .3s ease;
}
.option.correct .seal { color: var(--good); }

.option.wrong {
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 9%, var(--surface));
  animation: seal .3s ease;
}
.option.wrong .seal { color: var(--bad); }

.option.locked:not(.correct):not(.wrong) { opacity: .55; }

@keyframes seal {
  from { transform: scale(.94); }
  to   { transform: scale(1); }
}

/* ---------- results ---------- */
.results {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 28px 22px;
  text-align: center;
  align-items: center;
}
.results-kicker {
  margin: 0; font-size: 13px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
}
.newbest {
  margin: 0; font-size: 14px; font-weight: 700; color: var(--accent);
  animation: pop .4s ease;
}
.finalscore { display: flex; flex-direction: column; gap: 2px; margin: 4px 0; }
.finalscore-num {
  font-size: 64px; font-weight: 700; line-height: 1; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  width: max-content; margin: 0 auto;
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.finalscore-cap { font-size: 13px; color: var(--muted); }

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  margin: 8px 0 4px;
}
.results-grid div {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 6px;
}
.results-grid dt {
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.results-grid dd {
  margin: 3px 0 0; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums;
}

.results-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

/* ---------- leaderboard ---------- */
.board-head {
  width: 100%;
  margin: 14px 0 8px;
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: left;
}
.board-sub { margin: -4px 0 14px; font-size: 13px; color: var(--muted); }
.board { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 5px; }
.board-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.b-rank { font-weight: 700; color: var(--muted); text-align: center; }
.b-score { font-weight: 700; font-size: 16px; }
.b-acc { font-size: 13px; color: var(--muted); }
.b-date { font-size: 12px; color: var(--muted); min-width: 3.4rem; text-align: right; }
.board-row.me { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.b-me { grid-column: 1 / -1; margin-top: -2px; font-size: 11px; font-weight: 600; color: var(--accent); }
.board-empty {
  padding: 18px; text-align: center; color: var(--muted); font-size: 14px;
  background: var(--bg); border-radius: 10px;
}

@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- screen flash on answer ---------- */
.app { position: relative; }
.app::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}
.app.flash-ok::after  { animation: flash .4s ease; background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--good) 28%, transparent), transparent 70%); }
.app.flash-bad::after { animation: flash .4s ease; background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--bad) 28%, transparent), transparent 70%); }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(28, 33, 38, .5);
  animation: fade .15s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 22px;
  width: 100%;
  max-width: 360px;
  animation: pop .2s ease;
}
.modal-title { margin: 0 0 8px; font-size: 19px; font-weight: 700; }
.modal-text { margin: 0 0 18px; font-size: 14px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .ghost, .modal-actions .cta { width: auto; flex: 1; min-height: 48px; }
.cta.danger { background: var(--bad); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* how-to-play / about modal */
.info-modal { max-width: 420px; max-height: min(80vh, 640px); display: flex; flex-direction: column; }
.info-body { overflow-y: auto; margin: 4px -4px 16px; padding: 0 4px; }
.info-body section { margin-bottom: 16px; }
.info-body section:last-child { margin-bottom: 0; }
.info-body h3 {
  margin: 0 0 5px;
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}
.info-body p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink); }

/* ---------- footer ---------- */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px;
}
.copy { margin: 0; font-size: 13px; color: var(--muted); }
.copy a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
@media (hover: hover) { .copy a:hover { color: var(--accent); border-color: var(--accent); } }
.reset {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  min-height: 40px;
}
@media (hover: hover) { .reset:hover { color: var(--bad); border-color: var(--bad); } }

/* ---------- responsive ---------- */
@media (min-width: 600px) {
  .app { padding-top: 32px; }
  .card { padding: 24px 22px; }
}

@media (min-width: 820px) {
  .app { max-width: 720px; }
  .options { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- dark-mode depth ----------
   Token swaps alone leave the page flat: over near-black, the light-mode
   aurora stops are invisible. Repaint the background with stronger teal/aqua
   glows for depth, and deepen the modal scrim so dialogs detach cleanly.
   Placed after the base rules so it wins on source order (no @supports needed). */
@media (prefers-color-scheme: dark) {
  body {
    background-image:
      radial-gradient(1150px 620px at 86% -14%, rgba(62, 197, 170, .20), transparent 60%),
      radial-gradient(880px 600px at -12% 4%, rgba(46, 128, 156, .16), transparent 55%),
      radial-gradient(1050px 720px at 50% 122%, rgba(50, 150, 132, .15), transparent 60%);
  }
  .modal-overlay { background: rgba(3, 9, 7, .64); }
}

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