/* ============================================================================
   styles.css -- mobile first, one-handed, readable in direct sunlight.
   Light is the default on purpose: black-on-white wins outdoors. Dark follows
   the system setting for anyone who prefers it.
   ========================================================================== */

:root {
  --bg: #ffffff;
  --fg: #111318;
  --muted: #5a6070;
  --line: #d8dbe3;
  --card: #f5f6f9;
  --accent: #7c1d1d;      /* clown red, dark enough for white text */
  --accent-fg: #ffffff;
  --good: #14622f;
  --bad: #a51616;
  --groom: #1f4b8f;
  --group: #6b2d86;
  --warn-bg: #fff5d6;
  --warn-fg: #5a4300;
  --radius: 14px;
  --tap: 56px;            /* minimum tap target */
  color-scheme: light dark;
}

/* Dark tokens, applied in two situations:
   1. the viewer's OS is dark and they have not explicitly asked for light
   2. the viewer explicitly asked for dark
   The values are duplicated because CSS has no way to reuse a token block. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131a;
    --fg: #f2f4f8;
    --muted: #9aa2b5;
    --line: #2b303d;
    --card: #1a1e28;
    --accent: #d8353a;
    --accent-fg: #14161c;
    --good: #4ad07a;
    --bad: #ff6b6b;
    --groom: #7aaaff;
    --group: #cf9bef;
    --warn-bg: #3a3210;
    --warn-fg: #ffe9a3;
  }
}

:root[data-theme="dark"] {
  --bg: #11131a;
  --fg: #f2f4f8;
  --muted: #9aa2b5;
  --line: #2b303d;
  --card: #1a1e28;
  --accent: #d8353a;
  --accent-fg: #14161c;
  --good: #4ad07a;
  --bad: #ff6b6b;
  --groom: #7aaaff;
  --group: #cf9bef;
  --warn-bg: #3a3210;
  --warn-fg: #ffe9a3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

#app { max-width: 720px; margin: 0 auto; padding: 12px 14px 48px; }

/* ------------------------------------------------------------------ typo -- */

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; }
.title { font-size: 30px; letter-spacing: -0.02em; }
.sub { margin: 0 0 4px; color: var(--muted); }
.meta { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.fineprint { color: var(--muted); font-size: 13px; margin-top: 24px; }
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; }

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

button, .link {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  min-height: 44px;
  padding: 10px 16px;
  -webkit-tap-highlight-color: transparent;
}

button.big, .big {
  display: block;
  width: 100%;
  min-height: var(--tap);
  font-size: 19px;
  font-weight: 650;
  margin-top: 10px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

button.groom { background: var(--groom); border-color: var(--groom); color: #fff; }
button.group { background: var(--group); border-color: var(--group); color: #fff; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost, .ghost { background: transparent; }

button:active { transform: translateY(1px); }

a.link { text-decoration: none; display: inline-block; text-align: center; }

/* ----------------------------------------------------------------- start -- */

.screen.start { padding-top: 18vh; text-align: center; }
.screen.start .title { font-size: 34px; }

/* ------------------------------------------------------------ stage head -- */

.stagehead { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 14px; }
.stagehead .row { display: flex; justify-content: space-between; align-items: center; }

.badge {
  background: var(--accent); color: var(--accent-fg);
  border-radius: 999px; padding: 4px 12px;
  font-weight: 700; font-size: 15px;
  user-select: none; -webkit-user-select: none;
}

.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }

.route { margin-top: 8px; font-size: 15px; }
.route .from { color: var(--muted); }
.route .arrow { margin: 0 6px; color: var(--muted); }
.route .to { font-weight: 700; }

.countdown {
  margin-top: 8px; padding: 8px 12px; border-radius: var(--radius);
  background: var(--card); font-variant-numeric: tabular-nums; font-weight: 650;
}
.countdown.hard { border: 2px solid var(--accent); }
.countdown.urgent { background: var(--accent); color: var(--accent-fg); }
.countdown.gone { background: var(--bad); color: #fff; }

.tallybar { display: flex; gap: 8px; margin-top: 10px; }
.chip {
  font-size: 14px; font-weight: 650; padding: 4px 10px;
  border-radius: 999px; border: 1px solid var(--line);
}
.chip.groom { color: var(--groom); }
.chip.group { color: var(--group); }

/* ------------------------------------------------------------------ card -- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
}
.ptitle { font-size: 21px; }

.prompt {
  margin: 0;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.note {
  margin-top: 12px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line);
  font-size: 15px;
}
.note.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }

/* ------------------------------------------------------- puzzle renderers -- */

.puzimg { display: block; width: 100%; height: auto; margin-top: 14px; border-radius: 10px; }
.puzaudio { display: block; width: 100%; margin-top: 14px; }
.svgwrap { margin-top: 14px; overflow-x: auto; }
.svgwrap svg { max-width: 100%; height: auto; }

.swatches { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.swatch { margin: 0; text-align: center; flex: 1 1 120px; }
.swatch .chipcolor {
  height: 92px; border-radius: 10px; border: 1px solid var(--line);
}
.swatch figcaption {
  margin-top: 6px; font-family: ui-monospace, Consolas, monospace; font-size: 15px;
}

.bongard { display: flex; gap: 12px; margin-top: 16px; }
.bongard .bcol { flex: 1; }
.bongard img { width: 100%; border-radius: 8px; margin-bottom: 8px; }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin-top: 16px;
  border: 2px solid var(--fg);
  border-radius: 6px;
  overflow: hidden;
  max-width: 420px;
}
.board .sq {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: min(8vw, 34px); line-height: 1;
}
.board .lite { background: #eeeadf; color: #111; }
.board .dark { background: #9a7b56; color: #111; }

.wason { margin-top: 16px; }
.wason .triple { display: flex; gap: 8px; }
.wason .triple input {
  flex: 1 1 0; min-width: 0; min-height: var(--tap);
  font-size: 18px; text-align: center;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg); color: var(--fg);
}
.wason .triple button { flex: 0 0 auto; margin: 0; }
.wason .guesses { list-style: none; margin: 12px 0 0; padding: 0; }
.wason .guesses li {
  display: flex; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; margin-bottom: 6px;
  font-variant-numeric: tabular-nums; background: var(--bg);
  border: 1px solid var(--line);
}
.wason .guesses li span { font-weight: 700; }
.wason .guesses li.yes span { color: var(--good); }
.wason .guesses li.no span { color: var(--bad); }

.acrostic {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0;
}
.acell {
  width: 34px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 22px; font-weight: 700; color: var(--muted);
}
.acell.got { border-color: var(--accent); color: var(--fg); background: var(--card); }

/* ------------------------------------------------------------- answer box -- */

form.answer, .answer.done { margin-top: 16px; }

#answerInput {
  width: 100%;
  min-height: var(--tap);
  font-size: 18px;               /* >=16px so iOS does not zoom on focus */
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
#answerInput:focus { outline: none; border-color: var(--accent); }

.feedback { min-height: 22px; margin: 8px 0 0; font-size: 15px; }
.feedback.bad { color: var(--bad); font-weight: 650; }
.feedback.good { color: var(--good); font-weight: 650; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
form.answer.shake { animation: shake 0.28s ease-in-out; }

.stagefoot { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.hint.shown {
  margin: 0; padding: 10px 12px; border-radius: 10px;
  background: var(--warn-bg); color: var(--warn-fg); font-size: 15px;
}

/* ----------------------------------------------------------------- modal -- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
}
.modalbox {
  background: var(--bg); color: var(--fg);
  border-radius: 20px; padding: 20px;
  width: 100%; max-width: 480px;
}
.modalbox h3 { font-size: 22px; text-align: center; margin-bottom: 14px; }

/* --------------------------------------------------------------- summary -- */

.summary .scoreboard { display: flex; gap: 12px; margin: 16px 0; }
.summary .side {
  flex: 1; text-align: center; padding: 18px 8px;
  border-radius: var(--radius); border: 2px solid var(--line);
}
.summary .side.groom { border-color: var(--groom); }
.summary .side.group { border-color: var(--group); }
.summary .side .n { display: block; font-size: 44px; font-weight: 800; line-height: 1; }
.summary .side .l { display: block; margin-top: 6px; color: var(--muted); font-size: 14px; }
.summary .verdict { text-align: center; font-size: 20px; font-weight: 700; margin: 0 0 18px; }

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.stats > div {
  flex: 1 1 90px; text-align: center; padding: 12px 6px;
  background: var(--card); border-radius: var(--radius);
}
.stats .n { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats .l { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

.stable { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0 20px; }
.stable th, .stable td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
.stable th { color: var(--muted); font-weight: 650; }
.stable td { font-variant-numeric: tabular-nums; }
.stable .tname { font-variant-numeric: normal; }
.stable tr.skipped { opacity: 0.5; }

/* -------------------------------------------------------------- gm mode --- */

.gm-banner {
  position: sticky; top: 0; z-index: 40;
  background: var(--bad); color: #fff;
  font-weight: 700; letter-spacing: 0.08em; font-size: 13px;
  padding: 8px 12px; border-radius: 10px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.gm-banner .gm-off {
  min-height: 32px; padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2); border-color: transparent; color: #fff;
}

.gmpanel {
  margin-top: 28px; padding: 14px;
  border: 2px dashed var(--bad); border-radius: var(--radius);
}
.gmpanel h3 { color: var(--bad); }
.gmrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.gmrow button { flex: 1 1 auto; min-height: 46px; }
.gmrow select, .gmrow input {
  flex: 1 1 120px; min-width: 0; min-height: 46px; font-size: 16px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); padding: 6px 10px;
}
.gmrow label { display: flex; align-items: center; gap: 8px; flex: 1 1 160px; font-size: 15px; }
.gmrow.score { font-size: 14px; }
.gmrow.score button { flex: 0 0 52px; }
.gmout { flex: 1 1 100%; font-family: ui-monospace, Consolas, monospace; font-size: 15px; }

/* ------------------------------------------------------------------ misc -- */

@media (min-width: 560px) {
  .title { font-size: 36px; }
  #app { padding: 20px 20px 60px; }
}

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

/* ============================================================================
   v2 additions: free navigation, narrative blocks, stage index
   ========================================================================== */

/* -------------------------------------------------------------- pager ----- */

.pager {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.pager .badge {
  flex: 1; text-align: center; min-height: 44px;
  border: 0; font-size: 16px;
}
.pager .pg {
  flex: 0 0 56px; min-height: 48px;
  font-size: 26px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}

.tag {
  margin: 8px 0 0; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---------------------------------------------------------- narrative ----- */

.narrative {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}
.narrative > summary {
  cursor: pointer; list-style: none;
  padding: 13px 16px; min-height: 48px;
  font-size: 14px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent);
  display: flex; align-items: center; justify-content: space-between;
}
.narrative > summary::-webkit-details-marker { display: none; }
.narrative > summary::after { content: '▾'; font-size: 15px; }
.narrative[open] > summary::after { content: '▴'; }
.narrative[open] > summary { border-bottom: 1px solid var(--line); }

.ntext {
  padding: 14px 16px 18px;
  white-space: pre-wrap;
  font-size: 17px; line-height: 1.6;
}
.prologue { text-align: left; margin-top: 22px; }

/* ------------------------------------------------------------ scorepick --- */

.scorepick {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; font-size: 14px; color: var(--muted);
}
.chipbtn { min-height: 40px; padding: 6px 14px; border-radius: 999px; font-size: 15px; }
.chipbtn.groom.on { background: var(--groom); border-color: var(--groom); color: #fff; }
.chipbtn.group.on { background: var(--group); border-color: var(--group); color: #fff; }

/* ------------------------------------------------------- stage index ------ */

.modalbox.toc { max-height: 82vh; overflow-y: auto; }
.toclist { list-style: none; margin: 0 0 14px; padding: 0; }
.toclist li { margin-bottom: 6px; }
.tocrow {
  width: 100%; display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px; align-items: baseline;
  text-align: left; min-height: 50px;
  font-size: 15px;
}
.tocrow .tocn { color: var(--muted); font-variant-numeric: tabular-nums; }
.tocrow .tocname { font-weight: 650; }
.tocrow .tocto {
  grid-column: 2 / 4; font-size: 13px; color: var(--muted);
}
.tocrow .tocok { grid-row: 1; grid-column: 3; color: var(--good); font-weight: 700; }
.tocrow.solved { border-color: var(--good); }

/* the index modal is a full-height sheet, not a bottom card */
#tocHost .modal { align-items: center; }

/* post-solve reveal: where the answer actually points */
.reveal {
  margin: 10px 0 0; padding: 12px 14px;
  border-radius: var(--radius);
  border: 2px solid var(--good);
  font-size: 18px; font-weight: 650;
}

/* Chess pieces: one solid glyph set, told apart by fill + outline. The outline
   glyph set (U+2654..U+2659) is unreadable at phone size on a light square. */
.board .pc { line-height: 1; }
.board .pc.w {
  color: #fff;
  text-shadow: 0 0 2px #000, 1px 0 0 #3a2a18, -1px 0 0 #3a2a18,
               0 1px 0 #3a2a18, 0 -1px 0 #3a2a18;
}
.board .pc.b {
  color: #1a1208;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.45);
}

/* progressive hints: numbered once there is more than one */
.hintn {
  display: inline-block; min-width: 18px; height: 18px;
  border-radius: 50%; background: var(--warn-fg); color: var(--warn-bg);
  font-size: 11px; font-weight: 700; text-align: center; line-height: 18px;
  margin-right: 4px;
}
.hintof { opacity: .6; font-weight: 400; }

/* ============================================================================
   Het slot: de scherven en de ban
   ========================================================================== */

.shardlist { list-style: none; margin: 0; padding: 14px 16px 18px; }
.shardrow {
  display: grid; grid-template-columns: 28px 1fr auto;
  gap: 8px; align-items: baseline;
  padding: 5px 0; font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.shardrow:last-child { border-bottom: 0; }
.shardrow .srn { color: var(--muted); font-variant-numeric: tabular-nums; }
.shardrow .srstat { font-size: 13px; color: var(--muted); }
.shardrow.solved .srstat { color: var(--good); font-weight: 650; }
.shardrow.skipped .srname { opacity: .6; }

.shardgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px; margin: 14px 0 18px;
}
.shard {
  position: relative; min-height: 62px; padding: 4px;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--card); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.shard .shardn {
  position: absolute; top: 3px; left: 6px;
  font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.shard .shardl {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 26px; font-weight: 700; line-height: 1;
}
.shard:not(.open) .shardl { color: var(--muted); }
.shard.open {
  border-color: var(--accent); background: var(--bg); cursor: default;
}
.shard.open .shardl { color: var(--accent); }

.acrostic.big { gap: 4px; }
.acrostic.big .acell { width: 28px; height: 38px; font-size: 19px; }

#banInput {
  width: 100%; min-height: var(--tap);
  font-size: 18px; padding: 12px 14px;
  border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--bg); color: var(--fg);
  text-transform: uppercase; letter-spacing: 0.04em;
}
#banInput:focus { outline: none; border-color: var(--accent); }

/* Bongard: één probleem per keer */
.bongard { margin-top: 16px; }
.bongard .bcount {
  margin: 0 0 8px; font-size: 13px; font-weight: 650;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent);
}
.bongard .puzimg { background: #fff; padding: 6px; }

/* wissen: tweede tik bevestigt */
.resetbtn { margin-top: 6px; font-size: 15px; color: var(--muted); }
.resetbtn.danger {
  background: var(--bad); border-color: var(--bad); color: #fff;
  font-weight: 650;
}
