/* Layout: phone-first single column; sticky top bar; one screen at a time. Navy + red on a cool light ground, dark theme follows the phone. */
:root {
  --bg: #F3F5FA; --surface: #FFFFFF; --surface-2: #E9EDF6; --ink: #14204A; --ink-soft: #4B5675; --line: #D5DBEA;
  --navy: #1B2D6B; --navy-ink: #F4F6FC; --red: #C62F2F; --red-soft: #FBE7E5; --good: #1E7A4C; --good-soft: #E2F3EA;
  --focus: #3A62D8;
  --font-display: "Bricolage Grotesque", "Trebuchet MS", "Segoe UI", sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1430; --surface: #161E40; --surface-2: #1E2850; --ink: #E8ECF8; --ink-soft: #A6B0CE; --line: #2C3866;
    --navy: #8EA6F2; --navy-ink: #0E1430; --red: #FF7A6E; --red-soft: #3A1E2A; --good: #6FD3A0; --good-soft: #17352B;
    --focus: #8EA6F2; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.5; padding-bottom: env(safe-area-inset-bottom, 0px); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.gut { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.col { max-width: 760px; margin: 0 auto; }

.bar { position: sticky; top: 0; z-index: 9; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.bar .col { display: flex; align-items: center; gap: 10px; padding-block: 10px; }
.back { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; width: 40px; height: 40px; flex: none; font-size: 20px; line-height: 1; }
.brand { min-width: 0; flex: 1; }
.brand small { display: block; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--red); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand b { font-family: var(--font-display); font-weight: 800; font-size: 20px; line-height: 1.15; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { border: 1px solid var(--navy); background: var(--navy); color: var(--navy-ink); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; flex: none; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; background: var(--surface-2); border-radius: 999px; padding: 7px 12px; flex: none; }

main { padding-block: 16px 48px; display: flex; flex-direction: column; gap: 14px; }
h1 { font-family: var(--font-display); font-weight: 800; font-size: 26px; line-height: 1.1; margin: 0; text-wrap: balance; }
h2 { font-family: var(--font-display); font-weight: 700; font-size: 22px; line-height: 1.15; margin: 0; text-wrap: balance; }
h3 { font-size: 12.5px; letter-spacing: .1em; text-transform: uppercase; margin: 0; color: var(--navy); }
h3.bad { color: var(--red); }
.sub { color: var(--ink-soft); margin: 0; font-size: 14.5px; }
.label { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); font-weight: 600; margin: 0; }
.note { font-size: 13.5px; color: var(--ink-soft); margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.months { display: grid; grid-template-columns: 44px repeat(3, minmax(0, 1fr)); gap: 8px; align-items: center; }
.lvl { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--navy); }
.mbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 4px; display: flex; flex-direction: column; align-items: center; line-height: 1.2; font-weight: 600; }
.mbtn small { font-size: 11px; color: var(--ink-soft); font-weight: 400; }
.mbtn[aria-pressed="true"] { background: var(--navy); color: var(--navy-ink); border-color: var(--navy); }
.mbtn[aria-pressed="true"] small { color: var(--navy-ink); opacity: .8; }
.mbtn:disabled { cursor: not-allowed; opacity: .5; background: var(--surface-2); }

.topics { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.topic { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 12px 14px; display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.topic .n { font-family: var(--font-display); font-weight: 700; color: var(--red); font-size: 18px; font-variant-numeric: tabular-nums; }
.topic .t { font-weight: 600; display: block; }
.topic .u { display: block; font-size: 13px; color: var(--ink-soft); }
.score { font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 3px 9px; background: var(--surface-2); color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.score.ok { background: var(--good-soft); color: var(--good); }

.btn { border: 1px solid var(--navy); background: var(--navy); color: var(--navy-ink); border-radius: 12px; padding: 12px 16px; font-weight: 600; font-size: 15px; text-align: center; text-decoration: none; display: inline-block; }
.btn.ghost { background: var(--surface); color: var(--navy); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row > .btn { flex: 1 1 140px; }
.linkbtn { background: none; border: none; padding: 8px 0; color: var(--ink-soft); text-decoration: underline; font-size: 13.5px; align-self: center; }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tab { border: none; background: none; border-radius: 9px; padding: 10px 4px; font-weight: 600; font-size: 14.5px; color: var(--ink-soft); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--navy); box-shadow: 0 1px 2px rgba(20, 32, 74, .15); }

.rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: r; }
.rules li { counter-increment: r; display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 2px 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.rules li::before { content: counter(r); grid-row: span 3; font-family: var(--font-display); font-weight: 700; color: var(--red); font-variant-numeric: tabular-nums; }
.rules .uzr, .rules .ex, .rules .ru { min-width: 0; overflow-wrap: anywhere; }
.rules .ex { color: var(--navy); font-size: 15px; }
.rules .ru { color: var(--ink-soft); font-size: 13.5px; }
.rules .ru b { font-size: 10.5px; letter-spacing: .08em; margin-right: 4px; }
.bad-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); }
.switch input { width: 38px; height: 22px; appearance: none; -webkit-appearance: none; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; position: relative; margin: 0; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink-soft); transition: transform .15s; }
.switch input:checked { background: var(--navy); border-color: var(--navy); }
.switch input:checked::after { transform: translateX(16px); background: var(--navy-ink); }

.prog { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--navy); border-radius: 999px; transition: width .2s; }
.qhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; color: var(--ink-soft); }
.qtext { font-size: 19px; font-weight: 500; margin: 0; overflow-wrap: anywhere; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { text-align: left; border: 2px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 16px; overflow-wrap: anywhere; }
.opt.picked { border-color: var(--navy); background: var(--surface-2); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }
.opt:disabled { cursor: default; color: var(--ink); }
.parts { display: flex; flex-wrap: wrap; gap: 8px; }
.parts .opt { text-align: center; font-size: 17px; }
.gap { display: flex; gap: 8px; }
input.field, textarea.field, select.field, .gap input { width: 100%; min-width: 0; border: 2px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: 16px; }
.gap input { flex: 1; font-size: 17px; }
textarea.field { resize: vertical; }
.fb { border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.fb.right { background: var(--good-soft); }
.fb.wrong { background: var(--red-soft); }
.fb.info { background: var(--surface-2); }
.fb b { font-size: 16px; }
.big { font-family: var(--font-display); font-weight: 800; font-size: 54px; line-height: 1; color: var(--navy); font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--ink-soft); }
.review { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.review li { border-left: 4px solid var(--red); background: var(--surface); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; overflow-wrap: anywhere; }
.review .q { font-weight: 600; }
.review .yours { color: var(--red); }
.review .corr { color: var(--good); }
.review .why { color: var(--ink-soft); font-size: 14px; }
.promptbox { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; user-select: all; -webkit-user-select: all; }
.checks { display: flex; flex-direction: column; gap: 6px; }
.checks label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.checks input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.status { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.status li { display: flex; gap: 8px; }

/* Teacher page: results and content editor */
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; flex: none; }
.btn.danger { background: var(--surface); color: var(--red); border-color: var(--red); }
.btn.danger.armed { background: var(--red); color: #fff; }
.res { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.res > li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.res .head { width: 100%; text-align: left; background: none; border: none; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.res .head b { overflow-wrap: anywhere; }
.res .head .meta { font-size: 13px; color: var(--ink-soft); grid-column: 1; overflow-wrap: anywhere; }
.res .head .pct { grid-row: 1 / span 2; grid-column: 2; text-align: right; }
.res .body { border-top: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.pill { display: inline-block; font-weight: 700; font-size: 14px; border-radius: 999px; padding: 4px 10px; font-variant-numeric: tabular-nums; background: var(--surface-2); }
.pill.hi { background: var(--good-soft); color: var(--good); }
.pill.lo { background: var(--red-soft); color: var(--red); }
.pct small { display: block; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.qstat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.qstat li { display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.qstat .meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.qstat .meter i { display: block; height: 100%; background: var(--red); border-radius: 999px; }
.qstat .cap { font-size: 13px; color: var(--ink-soft); }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.items li { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.items .acts { display: flex; gap: 8px; justify-content: flex-end; }
.items .k { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); font-weight: 600; }
.lbl { display: flex; flex-direction: column; gap: 6px; }
.lbl > span { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
details.more { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--navy); }
details.more[open] { display: flex; flex-direction: column; gap: 10px; }
.tabs.five { grid-auto-columns: minmax(0, 1fr); }
.tabs .tab small { display: block; font-size: 11px; font-weight: 600; }
/* Stop the phone's pull-to-refresh from reloading a test by accident */
html, body { overscroll-behavior-y: none; }
