/* Night scheme. The palette is still the Worked Review's -- navy, maroon, green, cream --
   but re-tuned for a dark surface: the hues that were fills on white become accents on dark,
   and every "paper" colour is a token so a future change cannot miss a hardcoded #fff. */
:root {
  --bg: #0f141a;          /* page */
  --surface: #171e26;     /* cards, the passage pane, the bottom bar */
  --surface-2: #1e2732;   /* raised chips: letter circles, stat tiles, zebra rows */
  --band: #16222f;        /* the top bar */
  --ink: #e7edf4;
  --head: #cfe0f2;        /* headings -- the old title navy, inverted */
  --muted: #9aa8b6;
  --hair: #2a3542;
  --accent: #6aa9e0;      /* the old navy: borders, the selected choice, buttons */
  --accent-ink: #0d1218;  /* text on top of an accent fill */
  --maroon: #ef8ca3;      /* the student's wrong mark, lightened to carry on dark */
  --maroon-bg: #33161d;
  --green: #5fc79a;
  --green-bg: #13291f;
  --cream: #e8d9a8;       /* call-out text */
  --cream-bg: #241f10;
  --tan: #5c4f22;         /* call-out border */
  --warn: #c08a2e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
/* Tell the browser this is a dark page, so form controls and the scrollbar follow. */
:root { color-scheme: dark; }
#app.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- chrome */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem .9rem;
  background: var(--band); color: var(--ink);
  border-bottom: 1px solid var(--hair);
  padding-top: max(.55rem, env(safe-area-inset-top));
}
.topbar .who { font-weight: 700; letter-spacing: .01em; }
.topbar .sec { color: var(--muted); font-size: .9rem; }
.topbar .spacer { flex: 1; }
.clock {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem;
  padding: .15rem .55rem; border-radius: 6px; background: rgba(255,255,255,.09);
}
.clock.warn { background: var(--warn); color: var(--accent-ink); }
.clock.danger { background: var(--maroon); color: var(--accent-ink); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.savestate { font-size: .8rem; color: var(--muted); min-width: 5.5rem; text-align: right; }
.savestate.pending { color: var(--cream); }
.savestate.error { color: var(--maroon); font-weight: 700; }

/* ---------------------------------------------------------------- layout */
.wrap { max-width: 60rem; margin: 0 auto; padding: 1.25rem 1rem 6rem; }
.card {
  background: var(--surface); border: 1px solid var(--hair); border-radius: 10px;
  padding: 1.25rem 1.4rem; margin-bottom: 1rem;
}
h1 { font-size: 1.5rem; color: var(--head); margin: 0 0 .35rem; }
h2 { font-size: 1.15rem; color: var(--head); margin: 0 0 .6rem; }
p.sub { color: var(--muted); margin: .2rem 0 1rem; }

/* ---------------------------------------------------------------- section list */
.seclist { list-style: none; padding: 0; margin: 0; }
.seclist li {
  display: flex; align-items: baseline; gap: .6rem;
  padding: .55rem .2rem; border-bottom: 1px solid var(--hair);
}
.seclist li:last-child { border-bottom: 0; }
.seclist .nm { font-weight: 600; flex: 1; }
.seclist .meta { color: var(--muted); font-size: .9rem; }
.seclist .tag { font-size: .78rem; padding: .1rem .45rem; border-radius: 999px; }
.tag.done { background: var(--green-bg); color: var(--green); }
.tag.now { background: var(--cream-bg); color: var(--cream); border: 1px solid var(--tan); }
.tag.later { background: var(--surface-2); color: var(--muted); }

/* ---------------------------------------------------------------- reading */
.split { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 62rem) { .split.two { grid-template-columns: 1fr 1fr; align-items: start; } }
.passage {
  background: var(--surface); border: 1px solid var(--hair); border-radius: 10px;
  padding: 1.1rem 1.3rem; max-height: 70vh; overflow: auto;
}
@media (min-width: 62rem) { .passage { position: sticky; top: 4rem; } }
.passage h3 { margin: 0 0 .6rem; font-size: 1rem; color: var(--head); }
.passage p { margin: 0 0 .85rem; }
.passage mark { background: var(--cream-bg); color: var(--cream); border-bottom: 2px solid var(--tan); padding: 0 .1em; }

/* ---------------------------------------------------------------- question */
.stem { font-size: 1.08rem; margin: 0 0 1rem; }
.stem.headword { font-weight: 700; letter-spacing: .04em; font-size: 1.25rem; }
/* The SVG comes out of figs.py at its print size (~180pt wide), which is legible on paper
   and cramped on screen. It carries a viewBox, so widening it scales cleanly. The figures are
   drawn in dark ink for white paper, so they sit on their own light card rather than being
   recoloured -- a geometry diagram has to stay legible more than it has to match the theme. */
.fig { margin: 0 0 1.1rem; }
.fig svg { width: 100%; max-width: 22rem; height: auto; background: #f7f9fb; border-radius: 8px; padding: .4rem; }


/* ---------------------------------------------------------------- navigator */
.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--band); border-top: 1px solid var(--hair);
  padding: .6rem .9rem calc(.6rem + env(safe-area-inset-bottom));
  display: flex; gap: .6rem; align-items: center;
}
.navbar .spacer { flex: 1; }
button.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  border-radius: 8px; padding: .5rem 1rem;
}
button.btn:disabled { opacity: .35; cursor: default; }
button.btn.primary { background: var(--accent); color: var(--accent-ink); }
button.btn.warn { background: var(--maroon); border-color: var(--maroon); color: var(--accent-ink); }
button.btn.ghost { border-color: var(--hair); color: var(--muted); }

/* At phone width the four bottom-bar controls wrap their labels onto two lines and the bar
   grows to eat the question. Tighten the padding and forbid the wrap instead. */
@media (max-width: 30rem) {
  .navbar { gap: .4rem; padding-left: .6rem; padding-right: .6rem; }
  .navbar .btn { padding: .5rem .7rem; }
  .navbar .btn, .navbar .sub { white-space: nowrap; }
}

/* ---------------------------------------------------------------- the exam shell
   Laid out after the official EMA "UL Mini SSAT Practice Test": a fixed sidebar carrying the
   paper name, the clock, the section and the question grid, and a content column with an
   instructions strip above the question. Night colours, but the same furniture. */
.shell { display: grid; grid-template-columns: 22rem 1fr; min-height: 100vh; min-height: 100dvh; }

.side {
  border-right: 1px solid var(--hair); background: var(--surface);
  display: flex; flex-direction: column;
  position: sticky; top: 0; align-self: start;
  height: 100vh; height: 100dvh; overflow: auto;
}
.brand {
  display: flex; align-items: baseline; gap: .6rem;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--hair);
}
.brand .mark { font-weight: 800; font-size: 1.15rem; letter-spacing: .06em; color: var(--accent); }
.brand .paper { color: var(--muted); font-size: .92rem; }

.timerbox {
  padding: .9rem 1.2rem; border-bottom: 1px solid var(--hair); background: var(--surface-2);
}
.timerbox .tl {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  font-size: .82rem; color: var(--muted); margin-bottom: .2rem;
}
.timerbox .tl b { font-variant-numeric: tabular-nums; font-size: .95rem; color: var(--ink); }
.timerbox .tl b.warn { color: var(--warn); }
.timerbox .tl b.danger { color: var(--maroon); }
button.btn.stop {
  margin-top: .7rem; width: 100%;
  background: var(--maroon); border-color: var(--maroon); color: var(--accent-ink);
  border-radius: 999px; font-size: .95rem;
}

.sidebody { padding: 1rem 1.2rem 1.6rem; }
.secbox {
  border: 1px solid var(--hair); border-radius: 6px; background: var(--bg);
  padding: .55rem .7rem; color: var(--ink); font-size: .92rem; margin-bottom: 1.1rem;
}
.jump { font-weight: 700; color: var(--head); margin-bottom: .6rem; }
.savenote { margin-top: 1rem; font-size: .78rem; color: var(--muted); }
.savenote.pending { color: var(--cream); }
.savenote.error { color: var(--maroon); font-weight: 700; }

/* The numbered grid: filled top-to-bottom, at most 12 to a column. `grid-auto-flow: column`
   with a fixed row count is what enforces the 12 -- the browser opens a new column itself once
   one is full, so 50 questions lay out 12/12/12/12/2 with no arithmetic here. */
.rail {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(12, auto);
  gap: .34rem; justify-content: start;
}
.rail button {
  width: 2.3rem; height: 2.3rem; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--hair); background: var(--bg); color: var(--muted);
  font: 600 .82rem/1 inherit; font-variant-numeric: tabular-nums;
}
/* Fill carries "answered", the ring carries "flagged", so a question can show both at once. */
.rail button.answered { background: #1d3348; border-color: var(--accent); color: var(--accent); }
.rail button.flagged { border-color: var(--warn); color: var(--warn); border-width: 2px; }
.rail button.flagged:not(.answered) { background: #2a2110; }
.rail button.cur { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Where one reading passage ends and the next begins. */
.rail button.group { box-shadow: 0 -4px 0 -3px var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.instructions {
  padding: 1rem 1.6rem; border-bottom: 1px solid var(--hair);
  background: var(--surface); color: var(--ink); font-size: .95rem;
}
.instructions b { color: var(--head); }
.mainbody { padding: 1.4rem 1.6rem 2.5rem; max-width: 62rem; }

/* The question itself sits on the page rather than in a card -- the sidebar already supplies
   the frame, and a card inside a framed column reads as a box inside a box. */
.mainbody .card { background: transparent; border: 0; padding: 0; margin: 0 0 1.2rem; }
.qtop { display: flex; align-items: center; gap: .8rem; margin-bottom: .7rem; }
.qtop .n { flex: 1; color: var(--muted); font-size: .85rem; font-weight: 700;
           letter-spacing: .06em; text-transform: uppercase; }

/* Choice rows: the letter in its own gutter behind a rule, as on the official paper. */
.choices { border: 1px solid var(--hair); border-radius: 8px; overflow: hidden; }
.choice {
  display: flex; align-items: stretch; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--hair); border-radius: 0;
  background: var(--surface); padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
  transition: background .12s;
}
.choice:last-child { border-bottom: 0; }
.choice:nth-child(even) { background: var(--surface-2); }
.choice:hover:not(:disabled) { background: #232e3b; }
.choice:disabled { cursor: default; }
.choice .let {
  flex: 0 0 3.2rem; display: grid; place-items: center;
  border-right: 1px solid var(--hair); border-radius: 0;
  background: transparent; color: var(--muted);
  font-weight: 600; font-size: .95rem; height: auto;
}
.choice .txt { padding: .95rem 1.1rem; }
.choice.on { background: #1d3348; box-shadow: inset 4px 0 0 var(--accent); }
.choice.on .let { color: var(--accent); font-weight: 800; }
.choice.right { background: var(--green-bg); box-shadow: inset 4px 0 0 var(--green); }
.choice.right .let { color: var(--green); font-weight: 800; }
.choice.wrong { background: var(--maroon-bg); box-shadow: inset 4px 0 0 var(--maroon); }
.choice.wrong .let { color: var(--maroon); font-weight: 800; }

.pager { display: flex; align-items: center; gap: .7rem; margin-top: 1.3rem; }
.pager .spacer { flex: 1; }
.pager .blanks { color: var(--muted); font-size: .85rem; }

.flagbtn {
  font: 600 .75rem/1 inherit; letter-spacing: .04em; text-transform: uppercase;
  cursor: pointer; white-space: nowrap;
  border: 1px solid var(--hair); background: transparent; color: var(--muted);
  border-radius: 999px; padding: .38rem .7rem;
}
.flagbtn:hover { border-color: var(--warn); color: var(--warn); }
.flagbtn.on { border-color: var(--warn); color: var(--warn); background: #2a2110; }

/* Under ~56rem the sidebar cannot be a sidebar. `display: contents` dissolves it so its three
   blocks become direct children of the shell and can be reordered independently: the paper name
   and the clock stay on top (the clock sticky, so it never scrolls away), the question comes
   next, and the 50-button grid drops BELOW it. Stacked in source order the grid alone filled a
   phone screen and pushed every question under the fold. */
@media (max-width: 56rem) {
  .shell { display: flex; flex-direction: column; min-height: 0; }
  .side { display: contents; }
  .brand { order: 1; padding: .7rem 1rem; }
  .timerbox {
    order: 2; padding: .7rem 1rem;
    position: sticky; top: 0; z-index: 5;
    border-bottom: 1px solid var(--hair);
  }
  .main { order: 3; }
  .sidebody { order: 4; padding: 1rem; border-top: 1px solid var(--hair); }
  .secbox { display: none; }            /* the section name is already in the instructions strip */
  .instructions { padding: .8rem 1rem; font-size: .88rem; }
  .mainbody { padding: 1rem 1rem 1.6rem; }
  .rail { gap: .3rem; }
  .rail button { width: 2.1rem; height: 2.1rem; font-size: .76rem; }
  .choice .let { flex-basis: 2.4rem; }
  .choice .txt { padding: .8rem .9rem; }
  button.btn.stop { margin-top: .55rem; }
}

/* ---------------------------------------------------------------- review */
.scorebar { display: flex; flex-wrap: wrap; gap: .8rem; margin: .8rem 0 0; }
.tile { flex: 1 1 8rem; background: var(--surface-2); border: 1px solid var(--hair); border-radius: 8px; padding: .7rem .9rem; }
.tile .v { font-size: 1.7rem; font-weight: 700; color: var(--head); font-variant-numeric: tabular-nums; }
.tile .k { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
table.sec { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: .95rem; }
table.sec th, table.sec td { padding: .45rem .5rem; text-align: right; border-bottom: 1px solid var(--hair); }
table.sec th:first-child, table.sec td:first-child { text-align: left; }
table.sec thead th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }

/* The finish-line hamster: he gets it for handing in, not for scoring well. */
.finish { margin: 1.4rem 0 .2rem; text-align: center; }
.finish img {
  width: 100%; max-width: 26rem; height: auto;
  border-radius: 10px; border: 1px solid var(--hair);
}
.finish .cap { color: var(--muted); font-size: .85rem; margin-top: .5rem; }

.miss { border-left: 3px solid var(--maroon); padding: .1rem 0 .1rem .8rem; margin: 0 0 1.1rem; }
.miss.blank { border-left-color: var(--muted); }
.miss .q { font-weight: 700; color: var(--head); }
.miss .yours { color: var(--maroon); }
.miss .theirs { color: var(--green); font-weight: 600; }
.miss .expl { color: var(--muted); font-size: .93rem; margin-top: .25rem; }
.note { background: var(--cream-bg); border: 1px solid var(--tan); color: var(--cream); border-radius: 8px; padding: .8rem 1rem; margin: 1rem 0; }
.err { background: var(--maroon-bg); border: 1px solid var(--maroon); color: var(--maroon); border-radius: 8px; padding: .8rem 1rem; margin: 1rem 0; }
.kbd { font: 600 .8rem/1 ui-monospace, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--hair); border-radius: 4px; padding: .12rem .35rem; }
