/* styles.css — mobile-first, system fonts, one accent (the gold), day/night via CSS vars. */

:root {
  --maxw: 34rem;
  --radius: 14px;
  --radius-s: 10px;
  --pad: 1rem;
  --tap: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}

/* ---------- themes ---------- */
/* Day (default) — warm paper */
:root, :root[data-theme="day"] {
  color-scheme: light;
  --bg: #F5EFE2;
  --card: #FFFDF7;
  --line: #DDD3BE;
  --ink: #221D15;
  --muted: #6A614F;
  --accent: #8A5C00;          /* the gold, day voice */
  --accent-ink: #FFFDF7;
  --gold-chip-bg: #F3E3BC;
  --gold-chip-ink: #6E4A00;
  --ok: #2D6A33;
  --ok-bg: #E4EFE0;
  --bad: #9E372B;
  --bad-bg: #F6E3DE;
  --focus: #8A5C00;
}
:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #141310;
  --card: #1E1C17;
  --line: #37332A;
  --ink: #EDE6D4;
  --muted: #A79D88;
  --accent: #E3B84A;          /* the gold, night voice */
  --accent-ink: #201A0A;
  --gold-chip-bg: #2E2718;
  --gold-chip-ink: #E9C363;
  --ok: #8CC790;
  --ok-bg: #22301F;
  --bad: #E38A7B;
  --bad-bg: #37211C;
  --focus: #E3B84A;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #141310; --card: #1E1C17; --line: #37332A; --ink: #EDE6D4; --muted: #A79D88;
    --accent: #E3B84A; --accent-ink: #201A0A;
    --gold-chip-bg: #2E2718; --gold-chip-ink: #E9C363;
    --ok: #8CC790; --ok-bg: #22301F; --bad: #E38A7B; --bad-bg: #37211C; --focus: #E3B84A;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100svh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
main { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad) 3rem; }

/* A7: pinned Start bar — always-visible primary action on the setup view. Fixed to the viewport
   bottom; only present while #view-setup is shown (its [hidden] ancestor is display:none elsewhere).
   The setup view reserves bottom space so nothing hides behind it. */
#view-setup { padding-bottom: 4.75rem; }
.startbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: .5rem var(--pad) calc(.5rem + env(safe-area-inset-bottom, 0px));
}
.startbar .bigbtn { margin: 0 auto; max-width: var(--maxw); }

button { font: inherit; color: inherit; }
button, input, .chip, .choice { touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
header.app {
  max-width: var(--maxw); margin: 0 auto; padding: .6rem var(--pad) .3rem;
  display: flex; align-items: center; gap: .5rem;
}
.wordmark {
  font-weight: 700; letter-spacing: .14em; font-size: 1.05rem;
  margin-right: auto; text-decoration: none; color: var(--ink); background: none; border: 0; padding: .3rem .2rem; cursor: pointer;
}
.wordmark .star { color: var(--accent); }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap); white-space: nowrap;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--card); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font-size: .85rem; padding: 0 .6rem;
}
.goldchip {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--gold-chip-bg); color: var(--gold-chip-ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: .35rem .7rem; font-weight: 600; font-variant-numeric: tabular-nums;
  min-height: var(--tap);
}
.goldchip .coin { font-size: 1rem; }

/* ---------- cards & controls ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem; margin: .7rem 0; box-shadow: var(--shadow);
}
.card h1, .card h2 { font-size: .78rem; letter-spacing: .09em; color: var(--muted); margin: 0 0 .5rem; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  min-height: 44px; padding: .35rem .8rem; cursor: pointer; font-size: .92rem;
}
.chip[aria-pressed="true"] {
  background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600;
}

.rowflex { display: flex; align-items: center; gap: .9rem; }
input[type="range"] { flex: 1; accent-color: var(--accent); min-height: var(--tap); }
input[type="number"], input[type="text"] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: .55rem .6rem; width: 5.2rem; min-height: var(--tap); text-align: center;
}
input[type="text"] { width: 100%; text-align: left; }

.bigbtn {
  display: block; width: 100%; min-height: 52px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-size: 1.05rem; font-weight: 600;
  margin: .55rem 0; padding: .7rem 1rem;
}
.bigbtn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.bigbtn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.subnote { color: var(--muted); font-size: .82rem; text-align: center; margin: -0.2rem 0 .8rem; }

/* ---------- play ---------- */
.playbar {
  display: flex; align-items: center; gap: .6rem; margin: .25rem 0 .6rem;
  font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem;
}
.playbar .prog { font-weight: 700; color: var(--ink); }
.playbar .spacer { flex: 1; }
.progressline { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; position: relative; margin-bottom: .35rem; }
.progressline > .me { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .25s ease; }
.ghostline { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; position: relative; margin-bottom: .8rem; }
.ghostline > .them { height: 100%; width: 0; background: var(--muted); border-radius: 2px; transition: width .5s linear; }
.ghostlabel { font-size: .78rem; color: var(--muted); margin: -0.4rem 0 .8rem; }

.qtopic { color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.qtext { font-size: 1.18rem; font-weight: 600; margin: 0 0 .75rem; overflow-wrap: break-word; }

.choice {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); cursor: pointer;
  min-height: 50px; padding: .62rem .85rem; margin: .45rem 0;
  font-size: .98rem; overflow-wrap: break-word;
  /* the :active press stays tactile at .06s; the right/wrong colour and the dimming of the
     other choices settle over ~180ms instead of snapping in one frame (Phase-3 micro-motion).
     End states are unchanged, so AA stays 26/26; the reduced-motion blanket removes it. */
  transition: transform .06s ease, background-color .18s ease, border-color .18s ease, opacity .18s ease;
}
.choice:active { transform: scale(.995); }
.bigbtn:active, .iconbtn:active, .chip:active, .wordmark:active { transform: scale(.99); }
.choice.correct { background: var(--ok-bg); border-color: var(--ok); color: var(--ink); font-weight: 600; }
.choice.wrong { background: var(--bad-bg); border-color: var(--bad); }
.choice:disabled { cursor: default; opacity: 1; }
.choice.dim { opacity: .55; }
.choice .mark { float: right; font-weight: 700; }
.choice.correct .mark { color: var(--ok); }
.choice.wrong .mark { color: var(--bad); }

.verdict { font-weight: 700; margin: .6rem 0 .15rem; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.fact {
  background: var(--bg); border: 1px solid var(--line); border-left: 2px solid var(--accent); border-radius: var(--radius-s);
  padding: .6rem .7rem .6rem .8rem; font-size: .9rem; margin: .5rem 0 .65rem; line-height: 1.45;
}
.fact b { color: var(--accent); }
.goldpop { color: var(--accent); font-weight: 700; }
.streakchip { color: var(--accent); font-weight: 700; font-size: .9rem; }

/* ---------- result ---------- */
.scorebig { font-size: 3rem; font-weight: 800; text-align: center; margin: .6rem 0 0; font-variant-numeric: tabular-nums; }
.scoresub { text-align: center; color: var(--muted); margin-bottom: 1rem; }
.statrow { display: flex; justify-content: space-between; gap: .6rem; border-top: 1px solid var(--line); padding: .55rem 0; font-size: .98rem; }
.statrow:first-of-type { border-top: 0; }
.statrow b { font-variant-numeric: tabular-nums; }
.statrow > span:first-child { color: var(--muted); }
.coinaccent { color: var(--accent); }
.vsgrid { display: grid; grid-template-columns: 1fr auto 1fr; gap: .4rem .8rem; align-items: center; text-align: center; margin: .6rem 0; }
.vsgrid .who { font-weight: 700; }
.vsgrid .num { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.vsverdict { text-align: center; font-weight: 700; margin: .6rem 0; }
.minimap { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; margin: .6rem 0; }
.minimap span {
  width: 1.5rem; height: 1.5rem; border-radius: 6px; border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-size: .78rem; font-weight: 700;
}
.minimap .y { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.minimap .x { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

/* ---------- about / colophon ---------- */
.prose { font-size: .98rem; }
.prose h1 { font-size: 1.3rem; margin: 1rem 0 .4rem; }
.prose h2 { font-size: 1.02rem; margin: 1.1rem 0 .3rem; letter-spacing: 0; text-transform: none; color: var(--ink); }
.prose p { margin: .5rem 0; }
.prose a { color: var(--accent); }
.prose .quiet { color: var(--muted); font-size: .88rem; }

/* ---------- utility ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 999px;
  padding: .55rem 1rem; font-size: .9rem; box-shadow: var(--shadow); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .2s ease; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
:where(button, a, input, [tabindex]):focus-visible {
  /* no border-radius here: the browser rounds the outline to each element's own radius, so pills
     (chips, the gold chip at 999px) keep their shape on keyboard focus instead of squaring off. */
  outline: 2px solid var(--focus); outline-offset: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (min-width: 700px) {
  .qtext { font-size: 1.35rem; }
}

.noscript-note { text-align: center; padding: 2rem 1rem; }
.taglineline { color: var(--muted); font-size: .88rem; margin: .1rem 0 .7rem; text-align: center; }
.footlinks { text-align: center; margin: 1.6rem 0 0; color: var(--muted); font-size: .9rem; display: flex; gap: 1rem; justify-content: center; }
.footlinks button { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: .9rem; padding: .4rem; min-height: var(--tap); }
.dots { letter-spacing: .12em; color: var(--accent); font-size: .8rem; }
.sharerow { display: flex; gap: .5rem; margin: .6rem 0; }
.sharerow .bigbtn { margin: 0; flex: 1; min-height: 50px; font-size: .95rem; }
.namewrap { margin: .6rem 0; }
.namewrap label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.titlechip { display: inline-block; border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: .15rem .6rem; font-size: .82rem; font-weight: 700; margin-left: .5rem; }
.ghostmark { color: var(--muted); font-size: .9rem; margin: .5rem 0 0; font-style: italic; }
/* a milestone (a new craft title) should arrive, not blink in — one small, kind beat. The
   reduced-motion blanket above removes it entirely. */
@keyframes revealrise { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.milestoneline { text-align: center; color: var(--accent); font-weight: 700; margin: .6rem 0; animation: revealrise .24s ease both; }
.capnote { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.presets { display: flex; gap: .5rem; margin-bottom: .6rem; }
.presets .chip { flex: 1; text-align: center; justify-content: center; display: inline-flex; align-items: center; }

.fact .src { display: block; color: var(--muted); font-size: .8rem; margin-top: .35rem; }
