/* Exercise-book look: blue squared paper, navy pencil, teacher's red/green marks. */
:root {
  --paper: #eef4fb;
  --grid: #d3e1f2;
  --sheet: #ffffff;
  --ink: #1d2b4f;
  --ink-soft: #56637f;
  --tick: #12805a;
  --cross: #c8372d;
  --highlight: #ffd84d;
  --bar: #3d64b5;
  --cell: 28px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.45;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}

.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 48px; }

header.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

header.top h1 { font-size: 28px; margin: 0; letter-spacing: -0.01em; }

a { color: var(--ink); text-underline-offset: 3px; }
.links { display: flex; gap: 18px; flex-wrap: wrap; justify-content: flex-end; }

a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 3px solid var(--highlight);
  outline-offset: 2px;
}

/* progress row: one box per question in the current set */
.progress { display: flex; align-items: center; gap: 8px; margin: 0 0 18px; }
.progress .label { color: var(--ink-soft); font-size: 15px; margin-right: 6px; }
.box {
  width: 34px; height: 34px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--sheet);
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px;
}
.box.current { background: var(--highlight); }
.box.ok { color: var(--tick); border-color: var(--tick); }
.box.bad { color: var(--cross); border-color: var(--cross); }

.sheet {
  background: var(--sheet);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 26px 24px 28px;
  box-shadow: 6px 6px 0 var(--grid);
}

.qnum { color: var(--ink-soft); font-size: 16px; margin: 0 0 10px; }

/* the sum itself is the hero */
/* whole sum on one line; app.js shrinks the font until it fits the sheet */
.sum {
  display: flex;
  flex-wrap: nowrap;
  white-space: nowrap;
  align-items: center;
  gap: 0.3em;
  font-size: 44px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  margin: 0 0 22px;
}

.answer-line { display: inline-flex; align-items: center; gap: 0.3em; }
#mark { display: inline-block; width: 0.95em; flex: none; }

input.answer {
  width: 3.8em;
  flex: none;
  font: inherit;
  color: var(--ink);
  padding: 2px 10px;
  border: none;
  border-bottom: 4px solid var(--ink);
  background: transparent;
  font-variant-numeric: tabular-nums;
}
input.answer:disabled { color: var(--ink); opacity: 1; }

.mark { width: 0.95em; height: 0.95em; flex: none; }
.mark path { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.mark.ok path { stroke: var(--tick); }
.mark.bad path { stroke: var(--cross); }
.mark path { stroke-dasharray: 160; stroke-dashoffset: 0; animation: draw 420ms ease-out; }
@keyframes draw { from { stroke-dashoffset: 160; } to { stroke-dashoffset: 0; } }

.feedback { min-height: 30px; margin: 0 0 18px; font-size: 20px; }
.feedback.ok { color: var(--tick); font-weight: 700; }
.feedback.bad { color: var(--cross); font-weight: 700; }
.feedback.hint { color: var(--ink-soft); }

button {
  font: inherit;
  font-weight: 700;
  font-size: 20px;
  padding: 12px 22px;
  color: var(--sheet);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: #2b3d6b; }
button:disabled { opacity: 0.5; cursor: default; }

.done h2 { font-size: 34px; margin: 0 0 6px; }
.done p { margin: 0 0 22px; color: var(--ink-soft); }

.today-line { margin-top: 18px; color: var(--ink-soft); font-size: 15px; }

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

[hidden] { display: none !important; }

/* ---------- stats page ---------- */
.actions { margin: 0 0 22px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 26px; }
.tile { background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px; padding: 12px 14px; }
.tile .v { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .k { color: var(--ink-soft); font-size: 15px; }

section.block { margin-bottom: 30px; }
section.block h2 { font-size: 22px; margin: 0 0 10px; }

table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--sheet);
  border: 2px solid var(--ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); }
table.data th { color: var(--ink-soft); font-weight: 400; }
table.data td.num, table.data th.num { text-align: right; }

.acc { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.acc .track { flex: 1; height: 10px; background: var(--paper); border-radius: 2px; overflow: hidden; }
.acc .fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }
.acc .pct { width: 3.4em; text-align: right; }

.status { font-weight: 700; white-space: nowrap; }
.status.done { color: var(--tick); }
.status.todo { color: var(--ink-soft); }
ul.wrong { list-style: none; margin: 0; padding: 0; background: var(--sheet); border: 2px solid var(--ink); }
ul.wrong li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; padding: 10px 12px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
ul.wrong li:last-child { border-bottom: none; }
ul.wrong .expr { font-weight: 700; font-size: 19px; }
ul.wrong s { color: var(--cross); text-decoration-thickness: 2px; }
ul.wrong .fix { color: var(--tick); font-weight: 700; margin-left: 8px; }
ul.wrong .when { color: var(--ink-soft); font-size: 15px; }

.empty { background: var(--sheet); border: 2px dashed var(--ink-soft); border-radius: 6px; padding: 18px; color: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) {
  .mark path { animation: none; }
}

/* narrow phones: tighter spacing so the one-line sum stays as large as possible */
@media (max-width: 520px) {
  .sheet { padding: 20px 14px 22px; }
  .sum, .answer-line { gap: 0.22em; }
  .sum { word-spacing: -0.12em; }
  input.answer { width: 3.3em; padding: 2px 4px; }
  #mark { width: 0.8em; }
  table.data th, table.data td { padding: 8px 5px; }
  table.data { font-size: 16px; }
  .status { white-space: normal; }
}

/* ---------- reading aloud ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px;
  padding: 12px 14px; text-decoration: none;
}
.card:hover { background: #f6f9fd; }
.card:focus-visible { outline: 3px solid var(--highlight); outline-offset: 2px; }
.ctitle { font-weight: 700; font-size: 19px; }
.csub { color: var(--ink-soft); font-size: 15px; }
.back { margin: 0 0 12px; }
.ptitle { font-size: 26px; margin: 0 0 8px; }
.situation { color: var(--ink-soft); font-style: italic; margin: 0 0 16px; }
/* the passage reads like a page of a reader: ruled lines, generous line height */
.passage {
  font-size: 22px; line-height: 2; margin: 0 0 22px;
  background-image: linear-gradient(transparent calc(2em - 1px), var(--grid) calc(2em - 1px));
  background-size: 100% 2em;
}
.passage.zh {
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif CJK SC", "Songti SC", serif;
  font-size: 26px; letter-spacing: 0.06em; line-height: 1.9;
  background-size: 100% 1.9em;
  background-image: linear-gradient(transparent calc(1.9em - 1px), var(--grid) calc(1.9em - 1px));
}
.passage .w.missed { color: var(--cross); text-decoration: line-through 2px; }
.passage .w.wrong { background: var(--highlight); border-radius: 3px; text-decoration: underline wavy var(--cross) 1px; text-underline-offset: 5px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 6px 0 0; }
.rec { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--cross); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
button.secondary, a.button.secondary {
  color: var(--ink); background: var(--sheet);
  font-weight: 700; font-size: 20px; padding: 12px 22px;
  border: 2px solid var(--ink); border-radius: 6px; text-decoration: none; display: inline-block;
}
button.secondary:hover, a.button.secondary:hover { background: #f6f9fd; }
.hint { color: var(--ink-soft); font-size: 15px; }
.headline { font-size: 28px; margin: 4px 0 14px; }
.findings { margin: 0 0 14px; padding-left: 20px; }
.findings li { margin: 4px 0; }
.findings li.missed b { color: var(--cross); }
details.heard { margin: 0 0 12px; }
details.heard summary { cursor: pointer; color: var(--ink-soft); }
@media (prefers-reduced-motion: reduce) { .rec .dot { animation: none; } }

/* ---------- top bar: subject switch on the left, History / Sign out on the right ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 18px; }
.subjects { display: inline-flex; background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; }
.subjects a { padding: 8px 18px; font-weight: 700; text-decoration: none; color: var(--ink); }
.subjects a + a { border-left: 2px solid var(--ink); }
.subjects a:hover { background: #f6f9fd; }
.subjects a[aria-current="page"] { background: var(--ink); color: var(--sheet); }
.bar .links { margin-left: auto; align-items: baseline; }
.who { color: var(--ink-soft); font-size: 15px; }
.links a[aria-current="page"] { font-weight: 700; text-decoration-thickness: 3px; }
h1.page-title { font-size: 28px; margin: 0 0 18px; letter-spacing: -0.01em; }

/* ---------- history ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.chip {
  font-size: 16px; padding: 6px 14px; border-radius: 999px;
  color: var(--ink); background: var(--sheet); border: 2px solid var(--ink);
}
.chip:hover { background: #f6f9fd; }
.chip[aria-pressed="true"] { color: var(--sheet); background: var(--ink); }
section.day { margin: 0 0 18px; }
section.day h3 { font-size: 17px; color: var(--ink-soft); margin: 0 0 8px; }
details.entry { background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px; margin: 0 0 8px; }
details.entry > summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  padding: 10px 12px; cursor: pointer; list-style: none;
}
details.entry > summary::-webkit-details-marker { display: none; }
details.entry > summary::before { content: "▸"; color: var(--ink-soft); }
details.entry[open] > summary::before { content: "▾"; }
details.entry[open] > summary { border-bottom: 1px solid var(--grid); }
details.entry .when { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 15px; }
.badge { font-size: 14px; font-weight: 700; padding: 1px 8px; border: 1.5px solid var(--ink-soft); border-radius: 4px; color: var(--ink-soft); }
details.entry .what { font-weight: 700; }
details.entry .score { color: var(--ink-soft); }
details.entry .detail { padding: 12px; }
details.entry .detail table.data { border: none; }
details.entry td.expr { font-weight: 700; font-variant-numeric: tabular-nums; }
details.entry td.num { white-space: nowrap; }
.ans.ok { color: var(--tick); font-weight: 700; }
.ans.bad { color: var(--cross); text-decoration-thickness: 2px; }
.muted { color: var(--ink-soft); }
details.entry audio { width: 100%; margin: 0 0 10px; }
details.entry .meta { color: var(--ink-soft); margin: 0 0 6px; }
details.entry .passage { font-size: 19px; margin-bottom: 12px; }
details.entry .passage.zh { font-size: 22px; }
.pick { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 14px; font-weight: 700; }
.pick select { font: inherit; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 6px; background: var(--sheet); color: var(--ink); }

/* Mistakes page */
ul.mistakes { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
li.mistake { background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px; padding: 12px 14px; }
li.mistake.fixed { border-color: var(--tick); }
li.mistake .q .expr { font-weight: 700; font-size: 24px; font-variant-numeric: tabular-nums; }
li.mistake .meta { margin: 2px 0 8px; color: var(--ink-soft); font-size: 15px; }
li.mistake .muted { margin: 0; }
form.retry { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
form.retry input.answer.small { width: 6em; font-size: 22px; }
form.retry button { font-size: 18px; padding: 8px 18px; }
form.retry .feedback { min-height: 0; margin: 0; font-size: 18px; }
li.mistake.reading .rhead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-bottom: 6px; }
li.mistake.reading .what { font-weight: 700; font-size: 20px; }
li.mistake.reading .when { color: var(--ink-soft); font-size: 15px; }
li.mistake.reading a.button { margin-left: auto; font-size: 16px; padding: 6px 14px; }
li.mistake.reading .findings { margin: 0; }
details.fixed-list { margin-top: 12px; }
details.fixed-list summary { cursor: pointer; color: var(--ink-soft); margin-bottom: 8px; }

/* P1 questions written out ("7 + ? = 10", "What number comes after 59?"): text, then the box */
.sum.prompt { flex-wrap: wrap; white-space: normal; font-size: 32px; row-gap: 12px; }
.sum.prompt #expr { flex-basis: 100%; }
