/* Memory & Storage — OCR J277 1.2
 *
 * Every font size is in em, never px, so the "Text size" control (which sets
 * --ui-scale on :root) actually scales the whole interface. A px size
 * anywhere is a control that silently stops working for the pupil who needs
 * it most.
 *
 * No inline styles and no external fonts: the Caddy CSP for this host is
 * style-src 'self' with no unsafe-inline.
 */

:root {
  --ui-scale: 1;

  --ink: #17202a;
  --ink-soft: #4a5866;
  --muted: #6b7885;
  --line: #d7dee6;
  --line-soft: #e8edf2;
  --paper: #ffffff;
  --ground: #f4f7fa;

  --brand: #1c5c9e;
  --brand-dark: #14456f;
  --good: #1c7a4a;
  --good-bg: #e8f6ee;
  --part: #8a6100;
  --part-bg: #fdf4e0;
  --bad: #a32929;
  --bad-bg: #fdeded;
  --prov: #5b4b8a;
  --prov-bg: #f1ecfa;

  font-size: calc(16px * var(--ui-scale));
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1em;
  line-height: 1.55;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--brand); color: #fff; padding: .6em 1em;
}
.skip:focus { left: .5em; top: .5em; z-index: 50; }

/* ── header ──────────────────────────────────────────────────────────── */
.top {
  display: flex; flex-wrap: wrap; gap: .75em;
  align-items: center; justify-content: space-between;
  padding: .7em 1.1em;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--brand); text-decoration: none; font-weight: 600; font-size: .92em; }
.brand:hover { text-decoration: underline; }
.top-right { display: flex; align-items: center; gap: 1em; flex-wrap: wrap; }
.scale-control { display: flex; align-items: center; gap: .5em; font-size: .82em; color: var(--muted); }
.scale-control input { width: 7em; }
.who { font-weight: 600; font-size: .9em; }

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn-primary, .btn-quiet, .btn-mark, .certificate-btn {
  font: inherit; cursor: pointer; border-radius: .4em;
  padding: .5em 1em; border: 1px solid transparent;
}
.btn-primary { background: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: var(--muted); cursor: default; }
.btn-quiet { background: var(--paper); color: var(--ink-soft); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--brand); color: var(--brand); }
.btn-mark {
  background: var(--paper); border-color: var(--line);
  min-width: 2.6em; font-weight: 600;
}
.btn-mark:hover { border-color: var(--brand); background: var(--brand); color: #fff; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ── sign in ─────────────────────────────────────────────────────────── */
.login-wrap { display: flex; justify-content: center; padding: 3em 1em; }
.login-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: .6em;
  padding: 2em; width: 100%; max-width: 24em;
}
.login-card h1 { margin: 0 0 .15em; font-size: 1.5em; }
.login-card .sub { margin: 0 0 1em; color: var(--brand); font-weight: 600; font-size: .9em; }
.login-card label { display: block; margin: .9em 0 .3em; font-weight: 600; font-size: .88em; }
.login-card input {
  width: 100%; font: inherit; padding: .55em .7em;
  border: 1px solid var(--line); border-radius: .35em; background: #fff; color: var(--ink);
}
.login-card button { width: 100%; margin-top: 1.3em; }

/* ── tabs ────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; flex-wrap: wrap; gap: .3em;
  padding: .8em 1.1em 0; background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.tab {
  font: inherit; font-size: .92em; cursor: pointer;
  background: none; border: 1px solid transparent; border-bottom: none;
  padding: .55em 1em; border-radius: .4em .4em 0 0; color: var(--ink-soft);
  position: relative;
}
.tab:hover { color: var(--brand); }
.tab[aria-selected="true"] {
  background: var(--ground); border-color: var(--line);
  color: var(--brand); font-weight: 600;
  margin-bottom: -1px; border-bottom: 1px solid var(--ground);
}
.badge {
  display: inline-block; margin-left: .5em; min-width: 1.5em;
  padding: 0 .35em; border-radius: 1em;
  background: var(--bad); color: #fff; font-size: .75em; text-align: center;
}

/* ── panels ──────────────────────────────────────────────────────────── */
main { max-width: 60em; margin: 0 auto; padding: 1.5em 1.1em 4em; }
.panel-head h2 { margin: 0 0 .2em; font-size: 1.35em; }
.panel-head .muted { margin: 0 0 1.2em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error-text { color: var(--bad); font-weight: 600; }

/* ── filters ─────────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: .4em; margin-bottom: 1.3em; }
.chip {
  font: inherit; font-size: .82em; cursor: pointer;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 1.2em; padding: .3em .9em; color: var(--ink-soft);
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip-on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* ── question cards ──────────────────────────────────────────────────── */
.q-list { display: flex; flex-direction: column; gap: 1.1em; }
.q-card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: .55em; padding: 1.2em;
}
.q-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5em;
  margin-bottom: .8em; font-size: .78em;
}
.q-num { font-weight: 700; color: var(--brand); font-size: 1.15em; }
.q-marks, .q-spec, .q-level, .q-tag {
  padding: .15em .6em; border-radius: 1em; border: 1px solid var(--line-soft);
  background: var(--ground); color: var(--ink-soft);
}
.q-spec { font-variant-numeric: tabular-nums; }
.level-1 { background: #eaf4ea; color: #2c6b2c; border-color: #cfe4cf; }
.level-2 { background: #fdf4e0; color: var(--part); border-color: #f0e0bb; }
.level-3 { background: #fdeded; color: var(--bad); border-color: #f2d5d5; }
/* A genuine past-paper question and an adaptation of one must never look the
   same: a pupil who thinks they have seen the real thing when they have not
   is being misled about what the exam looks like. */
.tag-genuine { background: #e8f0f9; color: var(--brand-dark); border-color: #cadcef; font-weight: 600; }
.tag-adapted { background: #f3f0fa; color: var(--prov); border-color: #ded6f0; font-style: italic; }
.q-status { margin-left: auto; font-weight: 600; }
.q-status.solved { color: var(--good); }
.q-status.trying { color: var(--part); }

.q-stem { margin-bottom: 1em; white-space: normal; }

/* Binary and hex in a stem must line up in columns. */
.q-stem { font-variant-numeric: tabular-nums; }

/* ── answer inputs ───────────────────────────────────────────────────── */
.answer { margin-bottom: 1em; }
.opt {
  display: flex; align-items: flex-start; gap: .6em;
  padding: .45em .6em; border: 1px solid var(--line-soft);
  border-radius: .35em; margin-bottom: .35em; cursor: pointer;
}
.opt:hover { border-color: var(--brand); background: var(--ground); }
.opt input { margin-top: .25em; flex: none; }

.single-input, .cell-input, .prose-input {
  font: inherit; padding: .5em .65em;
  border: 1px solid var(--line); border-radius: .35em;
  background: #fff; color: var(--ink); width: 100%;
}
.single-input { max-width: 18em; font-variant-numeric: tabular-nums; }
.single-row { display: flex; align-items: center; gap: .6em; flex-wrap: wrap; }
.unit { color: var(--muted); font-size: .9em; }
.prose-input { resize: vertical; }
.field { margin-bottom: .7em; }
.field label { display: block; font-weight: 600; font-size: .85em; margin-bottom: .25em; }

.answer-grid { border-collapse: collapse; width: 100%; font-size: .9em; }
.answer-grid th, .answer-grid td {
  border: 1px solid var(--line); padding: .45em .6em; text-align: left;
}
.answer-grid thead th { background: var(--ground); font-size: .88em; }
.answer-grid .row-label { font-weight: 400; background: var(--ground); }
.answer-grid td.given { background: var(--ground); font-variant-numeric: tabular-nums; }
.cell-input { max-width: 12em; font-variant-numeric: tabular-nums; }

.gap-body { line-height: 2.4; }
.gap-select {
  font: inherit; font-size: .92em; padding: .25em .4em;
  border: 1px solid var(--brand); border-radius: .3em;
  background: #fff; color: var(--ink); margin: 0 .15em;
}

/* ── click-to-connect diagram ─────────────────────────────────────────── */
.net-stage {
  position: relative; width: 100%; max-width: 34em;
  aspect-ratio: 400 / 260; margin: .6em 0 1em;
  background: var(--ground); border: 1px solid var(--line); border-radius: .5em;
}
.net-links { position: absolute; inset: 0; width: 100%; height: 100%; }
.net-link { stroke: var(--brand); stroke-width: 2.5; }
.net-nodes { position: absolute; inset: 0; }
.net-node {
  position: absolute; transform: translate(-50%, -50%);
  font: inherit; font-size: .75em; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .1em;
  background: var(--paper); border: 2px solid var(--line);
  border-radius: .45em; padding: .35em .5em; min-width: 4.6em;
  color: var(--ink); line-height: 1.2;
}
.net-node:hover { border-color: var(--brand); }
.net-node-on { border-color: var(--brand); background: #e8f0f9; box-shadow: 0 0 0 3px #cadcef; }
.net-icon { font-size: 1.5em; line-height: 1; }
.net-label { white-space: nowrap; }

.net-palette { display: flex; flex-wrap: wrap; gap: .4em; margin-bottom: .6em; }
.net-chip {
  font: inherit; font-size: .8em; cursor: pointer;
  background: var(--paper); border: 1px dashed var(--line);
  border-radius: 1.2em; padding: .3em .85em; color: var(--ink-soft);
}
.net-chip:hover { border-color: var(--brand); color: var(--brand); }
.net-chip-on {
  border-style: solid; border-color: var(--brand);
  background: var(--brand); color: #fff; font-weight: 600;
}
.net-status { margin: 0 0 .5em; font-size: .82em; color: var(--muted); }

.cell-prose {
  font: inherit; padding: .45em .6em; width: 100%; min-width: 12em;
  border: 1px solid var(--line); border-radius: .35em;
  background: #fff; color: var(--ink); resize: vertical;
}

@media (max-width: 560px) {
  .net-node { font-size: .68em; min-width: 4em; padding: .25em .35em; }
  .net-icon { font-size: 1.25em; }
}

/* ── wireframe builder ────────────────────────────────────────────────── */
.wf-page {
  border: 1px solid var(--line); border-radius: .5em; background: var(--ground);
  padding: .4em; margin: .6em 0 1em; max-width: 26em;
}
.wf-row { display: flex; gap: .3em; min-height: 2.1em; margin-bottom: .25em; }
.wf-block, .wf-slot {
  flex: 1; font: inherit; font-size: .8em; cursor: pointer;
  border-radius: .3em; padding: .4em .6em; text-align: center;
}
.wf-block { background: #e8f0f9; border: 2px solid var(--brand); color: var(--brand-dark); font-weight: 600; }
.wf-block:hover { background: #d6e6f7; }
.wf-slot { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.wf-slot:disabled { cursor: default; color: #c3ccd6; }
.wf-slot:not(:disabled):hover { border-color: var(--brand); color: var(--brand); background: #f0f6fc; }
.wf-palette { display: flex; flex-wrap: wrap; gap: .4em; margin-bottom: .5em; }
.wf-chip {
  font: inherit; font-size: .8em; cursor: pointer;
  background: var(--paper); border: 1px dashed var(--line);
  border-radius: 1.2em; padding: .3em .85em; color: var(--ink-soft);
}
.wf-chip:hover { border-color: var(--brand); color: var(--brand); }
.wf-chip-on { border-style: solid; border-color: var(--brand); background: var(--brand); color: #fff; font-weight: 600; }
.wf-chip-used { opacity: .4; cursor: default; text-decoration: line-through; }

/* ── mock exam ────────────────────────────────────────────────────────── */
.exam-warning {
  background: #fffaf0; border: 1px solid #e6d089; border-radius: .5em;
  padding: 1em 1.2em; margin-bottom: 1.4em; font-size: .92em; line-height: 1.6;
}
.paper-list { display: flex; flex-direction: column; gap: .9em; margin-bottom: 2em; }
.paper-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: .55em;
  padding: 1.1em 1.2em; display: flex; flex-wrap: wrap; align-items: center; gap: .8em;
}
.paper-head { flex: 1; display: flex; flex-direction: column; gap: .2em; min-width: 14em; }

.exam-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 1em;
  background: var(--paper); border-bottom: 2px solid var(--line);
  padding: .8em 1.1em; margin: -1.5em -1.1em 1.4em;
}
.exam-bar-title { flex: 1; display: flex; flex-direction: column; min-width: 12em; }
.exam-bar-actions { display: flex; align-items: center; gap: .8em; }
.exam-timer {
  display: flex; flex-direction: column; align-items: center;
  padding: .3em 1em; border-radius: .45em; background: var(--ground);
  border: 2px solid var(--line);
}
.timer-label { font-size: .68em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.timer-value { font-size: 1.5em; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-warn { border-color: var(--part); background: var(--part-bg); }
.timer-warn .timer-value { color: var(--part); }
.timer-critical { border-color: var(--bad); background: var(--bad-bg); }
.timer-critical .timer-value { color: var(--bad); }

.exam-section {
  margin: 2em 0 .8em; font-size: .8em; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: .4em;
}
.exam-card { margin-bottom: 1em; }
/* A question the pupil tried to submit without answering. */
.exam-card.missing { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.exam-answered.solved { color: var(--good); }
.submit-warning {
  background: var(--bad-bg); border-left: 4px solid var(--bad);
  padding: .9em 1.1em; border-radius: .4em; font-weight: 600; margin-bottom: 1.2em;
}
.exam-foot { margin: 2em 0 4em; text-align: center; }

.result-summary { display: flex; flex-wrap: wrap; gap: 1em; margin-bottom: 1em; }
.score-block {
  flex: 1; min-width: 12em; background: var(--paper); border: 1px solid var(--line);
  border-radius: .5em; padding: 1em 1.2em; display: flex; flex-direction: column; gap: .2em;
}
.score-self { border-style: dashed; }
.score-label { font-size: .78em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.score-value { font-size: 1.8em; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-card { border-left-width: 4px; margin-bottom: 1em; }
.result-right { border-left-color: var(--good); }
.result-part  { border-left-color: var(--part); }
.result-wrong { border-left-color: var(--bad); }
.result-blank { border-left-color: var(--muted); }
.result-prov  { border-left-color: var(--prov); }
.your-answer { margin: .6em 0; }
.exam-feedback {
  background: var(--ground); border-radius: .4em; padding: .7em .9em;
  font-size: .9em; margin: .6em 0;
}

@media (max-width: 700px) {
  .exam-bar { position: static; margin: 0 0 1.2em; }
  .exam-timer { width: 100%; }
}

/* ── actions and feedback ────────────────────────────────────────────── */
.q-actions { display: flex; gap: .6em; flex-wrap: wrap; }
.hint {
  margin: .8em 0 0; padding: .7em .9em;
  background: #fdf9e8; border-left: 3px solid #d9b93c; border-radius: .3em;
  font-size: .9em;
}

.feedback {
  margin-top: 1em; padding: .9em 1.1em;
  border-radius: .4em; border-left: 4px solid var(--line);
}
.feedback.good { background: var(--good-bg); border-left-color: var(--good); }
.feedback.part { background: var(--part-bg); border-left-color: var(--part); }
.feedback.bad  { background: var(--bad-bg);  border-left-color: var(--bad); }
.feedback.provisional { background: var(--prov-bg); border-left-color: var(--prov); }
.score { margin: 0 0 .4em; font-weight: 700; font-size: 1.05em; }
.note { margin: .3em 0; font-size: .9em; }
.provisional-warning {
  margin: .5em 0; font-size: .88em; color: var(--prov); font-weight: 600;
}

.ms-block, .working-block { margin-top: .7em; }
.ms-block summary, .working-block summary {
  cursor: pointer; font-weight: 600; font-size: .9em; color: var(--brand);
}
.ms-text, .working-text, .prose-answer {
  white-space: pre-wrap; overflow-wrap: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .85em; background: var(--paper);
  border: 1px solid var(--line-soft); border-radius: .35em;
  padding: .7em .85em; margin: .5em 0 0;
}

.self-assess { margin-top: .9em; padding-top: .8em; border-top: 1px dashed var(--line); }
.self-assess p { margin: 0 0 .5em; font-size: .9em; }
.self-row { display: flex; gap: .4em; flex-wrap: wrap; }
.self-done { color: var(--good); font-weight: 600; }

.topic-heading {
  margin: 0 0 1.1em; font-size: 1.5em; color: var(--brand-dark);
  border-bottom: 2px solid var(--line); padding-bottom: .4em;
}
.topic-heading:empty { display: none; }

/* ── certificates ────────────────────────────────────────────────────── */
.certificate-banner {
  background: linear-gradient(180deg, #fffdf2, #fff8e0);
  border: 1px solid #e6d089; border-radius: .55em;
  padding: 1.1em 1.3em; margin-bottom: 1.5em;
}
.certificate-banner p { margin: 0 0 .7em; font-weight: 600; }
#certificate-links { display: flex; gap: .6em; flex-wrap: wrap; }
.certificate-btn {
  background: var(--brand); color: #fff; text-decoration: none;
  font-weight: 600; font-size: .9em; display: inline-block;
}
.certificate-btn:hover { background: var(--brand-dark); }

/* ── progress ────────────────────────────────────────────────────────── */
.prog-block {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: .55em; padding: 1.2em; margin-bottom: 1.2em;
}
.prog-block h3 { margin: 0 0 .6em; font-size: 1.05em; }
.bar { height: .7em; background: var(--line-soft); border-radius: 1em; overflow: hidden; }
.bar-fill { height: 100%; background: var(--good); border-radius: 1em; }
.topic-table { width: 100%; margin-top: .9em; border-collapse: collapse; font-size: .9em; }
.topic-table td { padding: .3em .2em; border-bottom: 1px solid var(--line-soft); }
.topic-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.topic-done td { color: var(--good); font-weight: 600; }

/* ── teacher ─────────────────────────────────────────────────────────── */
.admin-block {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: .55em; padding: 1.2em; margin-bottom: 1.3em;
}
.admin-block h3 { margin: 0 0 .5em; font-size: 1.05em; }
.cert-count { font-size: .8em; font-weight: 400; margin-left: .5em; }
.cert-count-new { color: var(--bad); font-weight: 700; }

.data-table { width: 100%; border-collapse: collapse; font-size: .88em; margin-top: .7em; }
.data-table th, .data-table td {
  text-align: left; padding: .45em .6em; border-bottom: 1px solid var(--line-soft);
}
.data-table th { background: var(--ground); font-size: .9em; }
.row-new td { background: #fff8e0; font-weight: 600; }

.prose-item { border-bottom: 1px solid var(--line-soft); padding: .5em 0; }
.prose-item summary { cursor: pointer; display: flex; gap: .8em; flex-wrap: wrap; font-size: .9em; }
.prose-who { font-weight: 600; }
.prose-q { color: var(--muted); font-family: ui-monospace, monospace; font-size: .9em; }
.prose-score { margin-left: auto; color: var(--prov); font-size: .88em; }
.prose-stem { font-size: .9em; color: var(--ink-soft); margin: .5em 0; }

/* The class grid is 50 columns wide — it has to scroll inside its own box
   rather than pushing the page sideways. */
.grid-wrap { overflow-x: auto; }
.prog-grid { border-collapse: collapse; font-size: .8em; }
.prog-grid th, .prog-grid td { border: 1px solid var(--line-soft); padding: .2em .35em; }
.prog-grid .sticky {
  position: sticky; left: 0; background: var(--paper);
  text-align: left; white-space: nowrap; font-weight: 600; z-index: 1;
}
.prog-grid .tiny { font-size: .85em; color: var(--muted); font-weight: 400; min-width: 1.5em; }
.prog-grid .num { text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.cell { width: 1.2em; height: 1.2em; padding: 0; }
.cell-yes { background: var(--good); }
.cell-no { background: var(--line-soft); }

/* ── footer ──────────────────────────────────────────────────────────── */
.foot {
  max-width: 60em; margin: 0 auto; padding: 2em 1.1em 3em;
  border-top: 1px solid var(--line); text-align: center; font-size: .88em;
}
.foot a { color: var(--brand); }

.bug-report-btn {
  position: fixed; right: 1em; bottom: 1em;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 1.5em; padding: .45em .9em;
  font-size: .82em; text-decoration: none; color: var(--ink-soft);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.bug-report-btn:hover { border-color: var(--brand); color: var(--brand); }

/* ── narrow screens ──────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .q-head { font-size: .74em; }
  .q-status { margin-left: 0; width: 100%; }
  .answer-grid { font-size: .82em; }
  .answer-grid th, .answer-grid td { padding: .35em .4em; }
  .cell-input { max-width: 100%; }
  .prose-score { margin-left: 0; width: 100%; }
  .bug-report-btn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
