/* Noodl design tokens
   paper  #F1F3FB  cool graph-paper background
   ink    #1C1E4D  deep indigo text
   cobalt #3343D6  actions
   noodle #FFC531  the mascot, and a correct answer
   radish #E0457B  a miss
*/
:root {
  color-scheme: light;
  --paper: #f1f3fb;
  --paper-raised: #ffffff;
  --grid-line: #dfe2f3;
  --ink: #1c1e4d;
  --ink-soft: #565a8c;
  --cobalt: #3343d6;
  --cobalt-ink: #ffffff;
  --noodle: #ffc531;
  --noodle-deep: #e2a400;
  --radish: #e0457b;
  --line: #c9cdea;
  --focus: #3343d6;

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 26px;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #14163a;
    --paper-raised: #1e2150;
    --grid-line: #1d2049;
    --ink: #eceefc;
    --ink-soft: #a7abd8;
    --cobalt: #8f99ff;
    --cobalt-ink: #14163a;
    --noodle: #ffcd4a;
    --noodle-deep: #ffcd4a;
    --radish: #ff7aa6;
    --line: #353a78;
    --focus: #ffcd4a;
  }
}

*, *::before, *::after { box-sizing: inherit; }

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

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 18px;
}

button { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ---------- header and mascot ---------- */

.top {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 18px 0 6px;
}

.brand {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  text-decoration: none;
  color: var(--ink);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.1rem;
  letter-spacing: -0.04em;
  line-height: 1;
  padding-bottom: 4px;
}

.tagline {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.mascot { width: 46px; height: 58px; overflow: visible; }
.mascot .noodle { fill: none; stroke: var(--noodle); stroke-width: 20; stroke-linecap: round; }
.mascot .head { fill: var(--noodle); }
.mascot .eye { fill: #1c1e4d; }
.mascot .mouth { fill: none; stroke: #1c1e4d; stroke-width: 3.4; stroke-linecap: round; display: none; }
.mascot .mouth-wow { fill: #1c1e4d; stroke: none; }
.mascot .cheek { fill: var(--radish); opacity: 0.35; }
.mascot[data-mood="happy"] .mouth-happy,
.mascot[data-mood="wow"] .mouth-wow,
.mascot[data-mood="wilted"] .mouth-wilted { display: block; }

.mascot-body { transform-origin: 60px 142px; transition: transform 500ms cubic-bezier(.3,1.6,.5,1); }
.mascot[data-mood="wilted"] .mascot-body { transform: rotate(-24deg) translateY(6px); }
.mascot[data-mood="wow"] .mascot-body { animation: boing 900ms cubic-bezier(.3,1.6,.5,1) 2; }

.mascot-big { width: 112px; height: 140px; display: block; margin: 0 auto 4px; }

@keyframes boing {
  0%, 100% { transform: rotate(0) scaleY(1); }
  30% { transform: rotate(-6deg) scaleY(1.08); }
  60% { transform: rotate(5deg) scaleY(0.95); }
}

@media (prefers-reduced-motion: reduce) {
  .mascot-body { transition: none; animation: none !important; }
}

/* ---------- layout ---------- */

main {
  width: 100%;
  max-width: 480px;
  flex: 1;
  padding: 10px 0 28px;
}

.panel {
  background: var(--paper-raised);
  border: 2px solid var(--ink);
  border-radius: var(--radius-l);
  padding: 26px 22px 24px;
  box-shadow: 6px 6px 0 var(--ink);
}

.loading { color: var(--ink-soft); text-align: center; padding-top: 40px; }

.foot {
  width: 100%;
  max-width: 480px;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: center;
  padding: 8px 0 22px;
}
.foot p { margin: 0; }

/* ---------- type ---------- */

.number {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink-soft);
  font-size: 1rem;
}

h1 {
  margin: 2px 0 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.3rem, 9vw, 3.1rem);
  letter-spacing: -0.035em;
  line-height: 1;
}

.lede { margin: 0 0 22px; max-width: 34ch; }
.small { font-size: 0.9rem; color: var(--ink-soft); margin: 12px 0 0; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--cobalt);
  color: var(--cobalt-ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.secondary { background: var(--paper-raised); color: var(--ink); }
.btn + .btn { margin-top: 12px; }

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
}
.stat {
  border: 2px solid var(--line);
  border-radius: var(--radius-m);
  padding: 10px 8px;
  text-align: center;
  background: var(--paper-raised);
}
.stat strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1.1;
}
.stat span { font-size: 0.82rem; color: var(--ink-soft); }

/* ---------- play ---------- */

.play-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.play-head p { margin: 0; font-family: var(--font-display); font-weight: 500; }
.pips { display: flex; gap: 6px; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); }
.pip.done { background: var(--ink); }
.pip.now { background: var(--noodle); }

.prompt { margin: 0 0 14px; font-weight: 700; }

/* pattern grid */
.pgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 300px;
  margin: 0 auto 18px;
}
.pcell {
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--paper);
  display: grid;
  place-items: center;
}
.pcell svg { width: 88%; height: 88%; }
.pcell.missing {
  border: 2px dashed var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  color: var(--ink-soft);
}
.options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.option {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: var(--radius-m);
  background: var(--paper-raised);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 4px;
}
.option svg { width: 84%; height: 84%; }
.option:active, .option.picked { background: var(--noodle); }

/* shape colours */
.c-noodle { --shape: var(--noodle-deep); }
.c-cobalt { --shape: var(--cobalt); }
.c-radish { --shape: var(--radish); }
.shape { stroke: var(--shape); stroke-width: 5; stroke-linejoin: round; }
.shape.f-solid { fill: var(--shape); }
.shape.f-outline, .shape.f-dot { fill: none; }
.dot { fill: var(--shape); }

/* number chains */
.chain {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 6px 0 22px;
}
.link {
  min-width: 56px;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  background: var(--paper);
}
.link.missing { border-style: dashed; color: var(--ink-soft); }
.options.numbers { grid-template-columns: repeat(2, 1fr); }
.options.numbers .option {
  aspect-ratio: auto;
  min-height: 64px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
}

/* flash memory */
.mgrid {
  display: grid;
  gap: 8px;
  max-width: 320px;
  margin: 0 auto;
}
.tile {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: var(--radius-m);
  background: var(--paper);
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}
.tile:disabled { cursor: default; }
.tile.lit { background: var(--noodle); transform: scale(0.94); }
.tile.tapped { background: var(--cobalt); }
.memory-status { text-align: center; margin: 0 0 14px; font-weight: 700; min-height: 1.5em; }

/* ---------- results ---------- */

.result { text-align: center; }
.result h1 { margin-top: 0; }
.share-grid {
  font-size: 2.3rem;
  letter-spacing: 0.08em;
  margin: 6px 0 14px;
  line-height: 1;
}
.points {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 3.4rem;
  line-height: 1;
  letter-spacing: -0.03em;
}
.points-label { margin: 2px 0 6px; color: var(--ink-soft); }
.breakdown { font-size: 0.9rem; color: var(--ink-soft); margin: 0 0 20px; }
.countdown { margin: 18px 0 0; }
.countdown strong { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.toast { min-height: 1.4em; margin: 10px 0 0; font-weight: 700; }

details.review { margin-top: 22px; text-align: left; border-top: 2px solid var(--line); padding-top: 14px; }
details.review summary { cursor: pointer; font-weight: 700; }
.review ol { padding-left: 1.3em; margin: 12px 0 0; }
.review li { margin-bottom: 12px; }
.review .mini { display: inline-grid; width: 54px; height: 54px; vertical-align: middle; margin-left: 6px; }
.tag-right { color: var(--ink); font-weight: 700; }
.tag-wrong { color: var(--radish); font-weight: 700; }

.error { color: var(--radish); font-weight: 700; }

/* ---------- tribes ---------- */

.tribe { margin-top: 18px; padding: 22px 20px 20px; }
.tribe h2 {
  margin: 2px 0 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.tribe-copy { margin: 0 0 16px; }
.tribe-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tribe-btn {
  min-height: 60px;
  border-radius: var(--radius-m);
  border: 2px solid var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.tribe-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tribe-btn:disabled { opacity: 0.6; cursor: default; }
.side-a { background: #3343d6; color: #ffffff; }
.side-b { background: #ffc531; color: #1c1e4d; }
.link-btn {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: 0;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.95rem;
  min-height: 44px;
}
.standings { display: flex; justify-content: space-between; gap: 12px; font-size: 0.95rem; margin-bottom: 8px; }
.tbar {
  display: flex;
  height: 20px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  overflow: hidden;
}
.tbar span { display: block; height: 100%; transition: width 600ms ease; }
.tribe .small { margin-top: 10px; }
.tribe-line { margin: -8px 0 18px; font-weight: 700; }

/* ---------- IQ estimate ---------- */

a.btn { text-decoration: none; }
.panel + .panel { margin-top: 18px; }
.note h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
}
.note p { margin: 0 0 12px; }
.note .btn { margin-top: 6px; }
.clock { font-family: var(--font-display); font-weight: 800; font-variant-numeric: tabular-nums; }
.clock .low, .clock span.low { color: var(--radish); }
.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin: -6px 0 16px;
}
.progress span { display: block; height: 100%; background: var(--noodle-deep); }
.iq-score { font-size: 5rem; }
.skills { margin-top: 22px; text-align: left; display: grid; gap: 14px; }
.skill-row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.skill-bar { height: 12px; border-radius: 999px; border: 2px solid var(--ink); overflow: hidden; }
.skill-bar span { display: block; height: 100%; background: var(--cobalt); }

.iq-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding: 18px 20px;
  color: var(--ink);
  text-decoration: none;
}
.iq-link strong { display: block; font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; }
.iq-link span { color: var(--ink-soft); font-size: 0.95rem; }
.iq-link .arrow { font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; color: var(--cobalt); }

/* ---------- account & privacy ---------- */

.account { margin-top: 18px; }
.account h2 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; }
.account p { margin: 0 0 14px; }
.account-links { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.account-links .link-btn { margin: 0; display: inline-flex; align-items: center; }
.result .btn + .btn, .result #save-streak { margin-top: 12px; }
.notice { margin: 0 0 18px; padding: 14px 18px; font-weight: 700; }
.foot a { color: var(--ink-soft); }
.foot p + p { margin-top: 6px; }

.policy { display: flex; flex-direction: column; }
.policy h2 { margin: 0 0 8px; font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; }
.policy p { margin: 0 0 12px; }
.policy a:not(.btn) { color: var(--cobalt); }
