/* Lisensøving – "tuning dial" design.
   Grey-green equipment panel, ink text, one teal action colour. The only bold
   element is the dial (glass scale, ticks, red needle); everything else is quiet.
   The needle colour is never used for "wrong" answers. */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --panel: #dde3dc;          /* page: grey-green of old equipment */
  --surface: #eef1ec;        /* answer rows, figures, popovers */
  --ink: #18211e;
  --muted: #4a5852;
  --line: #6b7a72;           /* structure: borders, scale */
  --line-soft: #b8c2bb;
  --action: #1f5e63;         /* buttons, links */
  --action-ink: #ffffff;
  --focus: #b3470b;
  --ok: #2f6b3f;
  --ok-bg: #dcebdf;
  --bad: #a3271c;
  --bad-bg: #f3dcd8;
  --exam: #6b4e00;
  --dial-glass: #f1ead2;
  --dial-scale: #3b4741;
  --dial-faint: #a8ae9f;
  --dial-needle: #d2481f;
  --fig-bg: var(--surface);
  --fig-fg: var(--ink);
  --term-line: var(--action);
  --text: var(--ink);        /* used by figure and popover code */
  --border: var(--line-soft);
  --accent: var(--action);
  --note-bg: #e6ebe4;
  --radius: 4px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --panel: #1f2a26; --surface: #26332e; --ink: #e3e9e4; --muted: #a9b6af; --line: #8a9a91;
    --line-soft: #3d4c46; --action: #7fc4c8; --action-ink: #10302f; --focus: #ffb27a;
    --ok: #7fd39c; --ok-bg: #1d3a28; --bad: #ff9b90; --bad-bg: #3d211d; --exam: #efc56a;
    --dial-glass: #2b2617; --dial-scale: #efc56a; --dial-faint: #6f6446; --dial-needle: #f06a3f;
    --note-bg: #243029; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --panel: #1f2a26; --surface: #26332e; --ink: #e3e9e4; --muted: #a9b6af; --line: #8a9a91;
  --line-soft: #3d4c46; --action: #7fc4c8; --action-ink: #10302f; --focus: #ffb27a;
  --ok: #7fd39c; --ok-bg: #1d3a28; --bad: #ff9b90; --bad-bg: #3d211d; --exam: #efc56a;
  --dial-glass: #2b2617; --dial-scale: #efc56a; --dial-faint: #6f6446; --dial-needle: #f06a3f;
  --note-bg: #243029; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--panel);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
}

.wrap { max-width: 42rem; margin: 0 auto; padding: 0 16px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 2px; }

a { color: var(--action); text-underline-offset: 3px; }

.skip-link { position: absolute; left: -999px; top: 0; }
.skip-link:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---- page frame ---- */
.site-header { border-bottom: 2px solid var(--line); }
.site-title { font-size: 1.25rem; font-weight: 700; margin: 0; padding: 16px 0 12px; letter-spacing: 0.01em; }
.site-sub { font-weight: 400; color: var(--muted); }
.site-footer { margin-top: 56px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 0.9rem; padding: 12px 0 40px; }
.site-footer p { max-width: 38rem; }
.preview-banner { background: var(--bad); color: #fff; text-align: center; padding: 8px 16px; font-weight: 700; }

main { padding-top: 24px; padding-bottom: 24px; }
main:focus { outline: none; }
h2 { font-size: 1.5rem; line-height: 1.25; margin: 0.4em 0 0.4em; font-weight: 700; }
h3 { font-size: 1.15rem; margin: 1.2em 0 0.4em; }
h4 { font-size: 1rem; margin: 0.9em 0 0.2em; }
h2:focus, h3:focus { outline: none; }
.lead { color: var(--muted); max-width: 36rem; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 6px; }
.loading { color: var(--muted); }

/* ---- the dial ---- */
.dial-wrap { margin: 16px 0 20px; }
.dial { display: block; width: 100%; height: auto; }
.dial-glass { fill: var(--dial-glass); stroke: var(--line); stroke-width: 1.5; }
.dial-base { stroke: var(--dial-scale); stroke-width: 1.5; }
.dial-tick { stroke: var(--dial-scale); stroke-width: 2; }
.dial-tick-minor { stroke-width: 1; }
.dial-tick-faint { stroke: var(--dial-faint); }
.dial-num { fill: var(--dial-scale); font-size: 15px; font-weight: 700; font-family: inherit; }
.dial-faint { fill: var(--dial-faint); font-weight: 400; }
.dial-note { fill: var(--dial-faint); font-size: 13px; font-family: inherit; }
.dial-station { fill: none; stroke: var(--dial-scale); stroke-width: 2; }
.dial-station.is-on { fill: var(--dial-needle); stroke: var(--dial-needle); }
.dial-needle line { stroke: var(--dial-needle); stroke-width: 2.5; }
.dial-needle polygon { fill: var(--dial-needle); }
.dial-mark-ok { fill: var(--ok); }
.dial-mark-bad { stroke: var(--bad); stroke-width: 2; fill: none; stroke-linecap: round; }

/* ---- buttons and inputs ---- */
.btn, .btn-small {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: var(--radius);
  border: 2px solid var(--action); background: transparent; color: var(--action);
  padding: 10px 20px; min-height: 44px;
}
.btn-small { padding: 4px 12px; min-height: 36px; font-size: 0.95rem; }
.btn-primary { background: var(--action); color: var(--action-ink); }
.btn-secondary { border-color: var(--line); color: var(--ink); }
.btn:hover:not(:disabled), .btn-small:hover:not(:disabled) { border-color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.btn:disabled, .btn-small:disabled { opacity: 0.45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.actions-compact { margin: 4px 0 10px; }

fieldset { border: 0; border-top: 2px solid var(--line); padding: 10px 0 0; margin: 0 0 20px; min-width: 0; }
legend { font-weight: 700; padding: 0 8px 0 0; font-size: 1.05rem; }
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.check-inline { display: flex; flex-wrap: wrap; gap: 4px 24px; }
.check-inline li { border-bottom: 0; }
.check-list input[type=checkbox] { width: 20px; height: 20px; margin: 0; align-self: center; flex: none; accent-color: var(--action); }
.check-list label { cursor: pointer; }
.ch-status { color: var(--muted); font-size: 0.92rem; }
.is-unavailable label, .ch-blank { color: var(--muted); cursor: not-allowed; }
.is-upcoming { padding-left: 30px !important; }
.dial text { font-variant-numeric: tabular-nums; }
.count-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0 4px; font-weight: 700; }
select {
  font: inherit; padding: 6px 10px; min-height: 44px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
}
.avail { color: var(--muted); }
.error { color: var(--bad); font-weight: 700; }

.notice { border-left: 4px solid var(--line); background: var(--note-bg); padding: 10px 16px; margin: 12px 0 20px; }
.notice p { margin: 0.3em 0; }
.notice-error { border-left-color: var(--bad); }

/* ---- question ---- */
.q-head { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; align-items: center; }
.q-head .dial-wrap { grid-column: 1 / -1; margin: 10px 0 6px; }
.q-progress { margin: 0; font-size: 1.1rem; }
.q-meta { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 0.95rem; display: flex; flex-wrap: wrap; gap: 2px 14px; align-items: baseline; }
.q-topic { color: var(--ink); }
.btn-quit { grid-row: 1; grid-column: 2; }
.badge { display: inline-block; border: 1.5px solid var(--exam); color: var(--exam); border-radius: var(--radius); padding: 0 8px; font-size: 0.85rem; font-weight: 700; }
.badge-preview { border-color: var(--bad); color: var(--bad); }
.q-context { border-left: 4px solid var(--line); padding: 2px 0 2px 14px; margin: 18px 0; }
.q-stem { font-size: 1.15rem; font-weight: 700; line-height: 1.45; margin-bottom: 10px; }
.q-stem p { margin: 0.3em 0; }
.answer-form fieldset { border-top: 0; padding: 0; }

.opts { display: grid; gap: 8px; }
.opt { position: relative; display: flex; align-items: stretch; border: 2px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.opt label { flex: 1; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 10px 14px; cursor: pointer; min-height: 52px; }
.opt-letter { flex: none; width: 1.9em; height: 1.9em; display: inline-grid; place-items: center; border: 2px solid var(--line); border-radius: 50%; font-weight: 700; }
.opt-text { flex: 1 1 12em; }
.opt:hover:not(.is-correct):not(.is-wrong):not(.is-other) { border-color: var(--line); }
.opt input:checked + label .opt-letter { background: var(--action); color: var(--action-ink); border-color: var(--action); }
.opt:has(input:checked):not(.is-correct):not(.is-wrong) { border-color: var(--action); }
.opt:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.opt input:disabled + label { cursor: default; }
.opt.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.is-wrong { border-color: var(--bad); border-style: dashed; background: var(--bad-bg); }
.opt.is-other { opacity: 0.8; }
.opt.is-correct .opt-letter { border-color: var(--ok); }
.opt.is-wrong .opt-letter { border-color: var(--bad); }
.opt.is-correct input:checked + label .opt-letter { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.opt.is-wrong input:checked + label .opt-letter { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.opt-mark { flex-basis: 100%; font-weight: 700; font-size: 0.95rem; }
.mark-correct { color: var(--ok); }
.mark-wrong { color: var(--bad); }

.feedback { border-top: 4px solid var(--line); padding: 4px 0 8px; margin-top: 22px; }
.feedback-correct { border-top-color: var(--ok); }
.feedback-wrong { border-top-color: var(--bad); }
.feedback h3 { margin-top: 0.6em; font-size: 1.3rem; }
.feedback-correct h3 { color: var(--ok); }
.feedback-wrong h3 { color: var(--bad); }
.fb-answer { font-size: 1.05rem; }
.fb-block p { margin: 0.4em 0; }
.fb-others ul { padding-left: 1.2em; }
.fb-others li { margin: 0.5em 0; }
details summary { cursor: pointer; padding: 6px 0; font-weight: 700; }
.ref { border-left: 4px solid var(--action); padding: 4px 0 4px 14px; margin: 16px 0 8px; }
.report { font-size: 0.92rem; color: var(--muted); margin: 6px 0 0; }
.steps { padding-left: 1.4em; }
.steps li { margin: 0.3em 0; }
.note { color: var(--muted); font-style: italic; }

/* ---- results ---- */
.score { font-size: 1.5rem; margin: 0.2em 0 0.6em; }
.by-chapter { border-collapse: collapse; margin: 12px 0; width: 100%; }
.by-chapter caption { text-align: left; font-weight: 700; padding-bottom: 4px; }
.by-chapter th, .by-chapter td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line-soft); }
.by-chapter td { font-variant-numeric: tabular-nums; }
.toggle { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.toggle input { width: 20px; height: 20px; accent-color: var(--action); }
.review { padding-left: 1.6em; }
.review > li { margin: 6px 0; }
.review-body { border-left: 2px solid var(--line-soft); padding-left: 14px; margin: 4px 0 14px; }

/* ---- glossary terms ---- */
.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: help;
  text-decoration: underline dotted var(--term-line); text-decoration-thickness: 2px; text-underline-offset: 3px;
  display: inline; text-align: inherit;
}
.term:hover, .term.is-pinned { text-decoration-style: solid; }
.term-pop {
  position: absolute; z-index: 20; display: block; background: var(--surface); color: var(--ink);
  border: 2px solid var(--line); border-radius: var(--radius);
  padding: 10px 36px 10px 12px; font-size: 0.95rem; font-weight: 400; line-height: 1.45; text-align: left; cursor: auto;
  white-space: normal; overflow-wrap: break-word; font-style: normal;
}
.term-pop > span { display: block; }
.term-pop-title { font-weight: 700; }
.term-pop-en { color: var(--muted); margin-bottom: 4px; }
.term-pop-en span { font-style: italic; color: var(--ink); }
.term-pop-rel { color: var(--muted); margin-top: 4px; font-size: 0.9rem; }
.term-pop-close {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border: 0; background: none;
  color: var(--ink); font-size: 1.3rem; cursor: pointer; border-radius: 50%;
}

/* ---- math ---- */
.math { white-space: normal; max-width: 100%; font-family: "STIX Two Math", "Cambria Math", Cambria, "Times New Roman", serif; font-size: 1.08em; font-variant-numeric: normal; }
.math-visual { display: inline-flex; flex-wrap: wrap; row-gap: 0.3em; align-items: center; gap: 0.12em; vertical-align: middle; }
.m-var { font-style: italic; }
.m-op { padding: 0 0.15em; }
.m-text, .m-unit { font-style: normal; }
.m-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: 0.92em; padding: 0 0.15em; }
.m-frac-num { border-bottom: 1px solid currentColor; padding: 0 0.2em; display: inline-flex; gap: 0.12em; align-items: center; }
.m-frac-den { padding: 0 0.2em; display: inline-flex; gap: 0.12em; align-items: center; }
.m-sqrt { display: inline-flex; align-items: center; }
.m-sqrt-body { border-top: 1px solid currentColor; padding: 0 0.15em; display: inline-flex; gap: 0.12em; }
.qty, .nowrap { white-space: nowrap; }
sub, sup { line-height: 0; }

/* ---- figures ---- */
.fig { margin: 18px 0; background: var(--fig-bg); color: var(--fig-fg); border: 2px solid var(--line-soft); border-radius: var(--radius); padding: 10px; }
.fig-canvas { overflow-x: auto; }
.fig-svg { display: block; width: 100%; height: auto; max-height: 360px; color: var(--fig-fg); }
.fig-svg text { fill: currentColor; font-family: inherit; }
.fig figcaption { font-size: 0.92rem; color: var(--muted); padding: 4px 4px 0; }
.fig figcaption span { display: block; }
.fig-desc { font-size: 0.92rem; padding: 0 4px; }
.fig-desc summary { font-weight: 400; }
.fig-anim-toggle { margin: 6px 4px; }
.fig-error { color: var(--muted); }
.flow-path { stroke: transparent; }
.fig.is-playing .flow-path { stroke: var(--action); animation: flow 1.4s linear infinite; }
.fig.is-playing .trace-1 { stroke-dasharray: 1 1; animation: draw 4s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -20; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .fig .flow-path, .fig .trace-1 { animation: none !important; }
  .fig.is-playing .trace-1 { stroke-dasharray: none; }
  .fig-anim-toggle { display: none; }
}

@media (max-width: 480px) {
  body { font-size: 1rem; }
  /* block diagrams keep a readable size and scroll inside their frame */
  .fig[data-template^="block-diagram"] .fig-svg { min-width: 600px; max-height: none; }
  .q-stem { font-size: 1.08rem; }
  .btn { width: 100%; }
}

@media print {
  .site-header, .site-footer, .actions, .btn-quit, .dial-wrap { display: none; }
}
