/* Piquill — main stylesheet
   Questions are shown the way they sit on a printed paper: a white sheet,
   part labels hanging in the margin, marks in square brackets on the right.
   Everything around the sheet stays quiet.  One accent (ink blue) for actions,
   one highlighter yellow for "this question is in my test". */

/* ---------- Fonts (self-hosted, SIL Open Font Licence, see assets/fonts) ---------- */
@font-face {
  font-family: "Atkinson Hyperlegible Next"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next"; font-style: italic; font-weight: 200 800; font-display: swap;
  src: url("fonts/atkinson-hyperlegible-next-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2212;
}
@font-face {
  font-family: "Source Serif 4"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("fonts/source-serif-4-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url("fonts/source-serif-4-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2212;
}

/* ---------- Tokens ---------- */
:root {
  --desk: #e7eaee;          /* the table the paper lies on */
  --paper: #ffffff;
  --ink: #1b2027;           /* body text */
  --ink-2: #4c5560;         /* secondary text */
  --ink-3: #66707c;         /* meta text, still 4.8:1 on white */
  --rule: #d4d9df;
  --rule-soft: #e6e9ed;
  --accent: #2a4f86;        /* ink blue: actions, selected */
  --accent-hover: #22426f;
  --accent-soft: #e9eef6;
  --hl: #fbeea0;            /* highlighter: in my test */
  --hl-edge: #d9bd3c;
  --danger: #9b3229;
  --ok: #316a48;

  --ui: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --code: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* type scale, ratio ~1.2 */
  --fs-xs: 12.5px; --fs-sm: 13.5px; --fs-md: 15px; --fs-lg: 17px; --fs-xl: 20px;

  --header-h: 56px;
  --r-ctl: 5px;   /* buttons, inputs */
  --r-tag: 3px;   /* small labels */
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; }
body.app {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--ui);
  font-size: var(--fs-md);
  line-height: 1.5 !important;
  font-feature-settings: "kern";
}
.app button, .app input, .app select, .app textarea { font-family: inherit; }
.app :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app .font-mono { font-variant-numeric: tabular-nums; letter-spacing: 0; }
.app code, .app kbd, .app .font-code { font-family: var(--code); }
.app .uppercase { text-transform: none !important; letter-spacing: 0 !important; }
.app .tracking-wide, .app .tracking-wider, .app .tracking-widest { letter-spacing: 0 !important; }
/* The old icon font is gone. Any leftover icon tags in older dialogs stay invisible. */
.app i[class*="fa-"] { display: none !important; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 15px; height: 15px; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: var(--r-ctl);
  background: var(--paper); color: var(--ink);
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.2; text-decoration: none;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9c0c8; background: #f7f8f9; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-plain { border-color: transparent; background: transparent; color: var(--accent); padding: 0 8px; }
.btn-plain:hover { background: var(--accent-soft); border-color: transparent; }
.btn-danger-plain { border-color: transparent; background: transparent; color: var(--danger); padding: 0 8px; }
.btn-danger-plain:hover { background: #f8ecea; border-color: transparent; }
.btn-block { width: 100%; }
.btn-icon { min-height: 32px; width: 32px; padding: 0; border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-icon:hover { background: var(--rule-soft); border-color: transparent; }

.field-label { display: block; margin: 0 0 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--ink); }
.hint { margin: 6px 0 0; font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.4; }
.input, .select {
  width: 100%; box-sizing: border-box; min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--rule); border-radius: var(--r-ctl);
  background: var(--paper); color: var(--ink); font-size: var(--fs-sm);
}
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* segmented choice, e.g. Paper: All 1 2 3 */
.seg { display: flex; border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--paper); overflow: hidden; }
.seg > button {
  flex: 1 1 0; min-height: 34px; padding: 0 6px; border: 0; border-left: 1px solid var(--rule);
  background: transparent; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}
.seg > button:first-child { border-left: 0; }
.seg > button:hover { background: #f4f6f8; color: var(--ink); }
.seg > button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.check { display: flex; align-items: flex-start; gap: 9px; padding: 4px 0; font-size: var(--fs-sm); color: var(--ink); cursor: pointer; line-height: 1.35; }
.check input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.check .count { margin-left: auto; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h); box-sizing: border-box;
  display: flex; align-items: center; gap: 20px; padding: 0 20px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; flex: none; }
.brand img { width: 34px; height: 34px; object-fit: contain; filter: contrast(1.15); }
.brand span { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.search { position: relative; flex: 1 1 auto; max-width: 560px; }
.search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; box-sizing: border-box; height: 38px; padding: 0 12px 0 38px;
  border: 1px solid var(--rule); border-radius: var(--r-ctl); background: #f6f7f9;
  font-size: var(--fs-md); color: var(--ink);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { background: var(--paper); outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.topbar-actions .btn-plain { color: var(--ink-2); font-weight: 600; min-height: 36px; }
.topbar-actions .btn-plain:hover { color: var(--ink); background: var(--rule-soft); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #aab1ba; flex: none; }
.status-dot.on { background: var(--ok); }
.count-pill {
  min-width: 20px; height: 20px; padding: 0 6px; box-sizing: border-box; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: var(--accent); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.btn-test { display: none; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 320px;
  gap: 24px; align-items: start;
  max-width: 1500px; margin: 0 auto; padding: 20px 20px 48px;
}
.filters, .tray {
  position: sticky; top: calc(var(--header-h) + 20px);
  max-height: calc(100vh - var(--header-h) - 40px);
  overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: #c4c9d0 transparent;
}

/* ---------- Filters ---------- */
.filters { padding: 2px 4px 16px 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 14px; }
.panel-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.fgroup { padding: 14px 0; border-top: 1px solid var(--rule); }
.fgroup:first-of-type { border-top: 0; padding-top: 0; }
.topic-list { display: grid; gap: 1px; }
.topic-list label {
  display: flex; align-items: center; gap: 9px; min-height: 32px; padding: 0 8px; margin: 0 -8px;
  border-radius: var(--r-ctl); font-size: var(--fs-sm); cursor: pointer;
}
.topic-list label:hover { background: #dfe3e8; }
.topic-list input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.topic-list .num { color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 1ch; }
.topic-list label:has(input:checked) { font-weight: 700; }

.lo-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 36px; padding: 6px 10px; box-sizing: border-box; text-align: left;
  border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--paper);
  font-size: var(--fs-sm); color: var(--ink); cursor: pointer;
}
.lo-toggle:hover { border-color: #b9c0c8; }
#loPickerPanel { margin-top: 6px; border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--paper); overflow: hidden; }
#loPickerList label { font-size: var(--fs-sm); }

details.more { border-top: 1px solid var(--rule); }
details.more > summary {
  list-style: none; cursor: pointer; padding: 14px 0; display: flex; align-items: center; justify-content: space-between;
  font-size: var(--fs-sm); font-weight: 700;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary .ic { transition: transform .15s; color: var(--ink-3); }
details.more[open] > summary .ic { transform: rotate(180deg); }
details.more .fgroup:first-of-type { border-top: 1px solid var(--rule); padding-top: 14px; }

.diff-pick { display: flex; gap: 6px; }
.diff-pick button {
  flex: 1; min-height: 34px; border: 1px solid var(--rule); border-radius: var(--r-ctl);
  background: var(--paper); font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); cursor: pointer; font-variant-numeric: tabular-nums;
}
.diff-pick button:hover { border-color: #b9c0c8; color: var(--ink); }
.diff-pick button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.diff-ends { display: flex; justify-content: space-between; margin-top: 5px; font-size: var(--fs-xs); color: var(--ink-3); }
.marks-range { display: flex; align-items: center; gap: 8px; }
.marks-range input { flex: 1; accent-color: var(--accent); }

/* ---------- Feed ---------- */
.feed { min-width: 0; }
.feed-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; min-height: 36px; }
.feed-head .result-count { font-size: var(--fs-md); color: var(--ink-2); }
.feed-head .result-count strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.feed-head .sort { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ink-2); }
.feed-head .sort .select { width: auto; min-width: 170px; }
.btn-filters { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 14px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 6px 0 10px;
  border: 1px solid #c3cfe2; border-radius: 14px; background: var(--accent-soft); color: var(--accent);
  font-size: var(--fs-xs); font-weight: 600; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip .ic { width: 14px; height: 14px; }
.chip-clear { border-color: transparent; background: transparent; color: var(--ink-2); padding: 0 8px; }
.chip-clear:hover { color: var(--ink); border-color: transparent; text-decoration: underline; }

#questionsContainer { display: grid; gap: 14px; }

/* the sheet */
.q {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 18px 24px 16px 24px;
  box-shadow: 0 1px 0 rgba(20, 28, 38, .04);
}
.q.in-test { border-left: 5px solid var(--hl-edge); padding-left: 20px; }
.q-head { display: flex; align-items: flex-start; gap: 14px; }
.q-topic { flex: 1; min-width: 0; font-size: var(--fs-sm); line-height: 1.4; color: var(--ink-2); }
.q-code {
  display: inline; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-weight: 700; color: var(--accent); text-decoration: underline; text-decoration-color: #b8c6dc; text-underline-offset: 3px;
}
.q-code:hover { text-decoration-color: var(--accent); }
.q-total { flex: none; font-size: var(--fs-sm); font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0 0; }
.tag {
  display: inline-flex; align-items: center; height: 22px; padding: 0 7px; border-radius: var(--r-tag);
  border: 1px solid var(--rule); color: var(--ink-2); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.tag-hl { background: var(--hl); border-color: var(--hl-edge); color: #4a3c06; }
.pips { display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 2px 0 4px; }
.pips i { display: block !important; width: 7px; height: 7px; border-radius: 1px; background: var(--rule); }
.pips i.on { background: var(--ink-2); }
.pips span { margin-left: 5px; font-size: 12px; color: var(--ink-3); }

.q-text {
  margin: 16px 0 0;
  font-family: var(--text); font-size: var(--fs-lg); line-height: 1.6; color: var(--ink);
  max-width: 72ch;
  text-wrap: pretty;
}
.inline-math-group {
  white-space: nowrap;
  display: inline;
}
.q-text > div { line-height: 1.6 !important; }
.q-text .katex { font-size: 1.04em; }
.q-text .katex-display,
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 4px 0;
}
.q-parts { margin-top: 6px; }

/* IB-style part labels and marks (rendered by formatQuestionContent) */
.ib-part { position: relative; padding-left: 2.4em; margin: 12px 0 0; line-height: 1.6; }
.ib-part > .ib-tag { position: absolute; left: 0; top: 0; font-family: var(--text); font-weight: 400; color: var(--ink); }
.ib-part.roman { padding-left: 5em; margin-top: 8px; }
.ib-part.roman > .ib-tag { left: 2.4em; }
.ib-part-head { padding-left: 0; margin: 14px 0 0; font-family: var(--text); }
.ib-marks {
  float: right; margin-left: 16px; font-family: var(--text); font-weight: 400; color: var(--ink);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
/* In question text the marks sit in a right-hand column on the last line, as on a printed paper */
.q-text .ib-part, .q-text .ib-line { position: relative; padding-right: 3.2em; }
.q-text .ib-part > .ib-marks, .q-text .ib-line > .ib-marks { float: none; position: absolute; right: 0; bottom: 0; margin: 0; }
.ib-part::after, .ib-line::after { content: ""; display: table; clear: both; }
.ib-mark-badge.ms-token {
  display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 2px;
  font-family: var(--ui); font-size: 12.5px; font-weight: 700; color: var(--ink);
  background: #eef0f3; border: 1px solid var(--rule); vertical-align: baseline;
}
.ib-mark-badge.ms-ag { background: var(--hl); border-color: var(--hl-edge); }

.q-figure {
  margin: 16px auto 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
}
.q-figure img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  max-height: 380px;
  height: auto;
  cursor: zoom-in;
}
.q-figure-tools {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 6px;
  width: 100%;
}
.markscheme-snippet, .exam-visual-snippet {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.q-notes { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--rule-soft); font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.5; }
.q-notes p { margin: 0; line-height: 1.5 !important; }
.q-notes p + p { margin-top: 3px; }
.q-notes b { color: var(--ink-2); font-weight: 700; }
.q-notes .q-code { font-weight: 700; }

.q-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.q-foot .spacer { flex: 1; }
.q-foot .btn-plain[aria-expanded="true"] { background: var(--accent-soft); }
.btn-add { min-width: 128px; }
.btn-added { background: var(--hl); border-color: var(--hl-edge); color: #3d3205; }
.btn-added:hover { background: #f7e27a; border-color: #c9ab2b; }

.q-drawer { margin-top: 12px; padding: 16px 18px; border: 1px solid var(--rule); border-radius: 3px; background: #fafbfc; font-size: var(--fs-sm); }
.q-drawer .q-drawer-tabs { display: flex; gap: 4px; margin: -4px 0 12px; border-bottom: 1px solid var(--rule); }
.q-drawer .q-drawer-tabs button {
  padding: 6px 10px 8px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none;
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.q-drawer .q-drawer-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.q-drawer .q-drawer-tabs .total { margin-left: auto; align-self: center; font-size: var(--fs-xs); color: var(--ink-3); }

.empty { padding: 48px 24px; text-align: center; background: var(--paper); border: 1px dashed #bcc3cb; border-radius: 2px; }
.empty h3 { margin: 0 0 6px; font-size: var(--fs-lg); }
.empty p { margin: 0 0 16px; color: var(--ink-2); font-size: var(--fs-sm); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.pager span { font-size: var(--fs-sm); color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- My test (tray) ---------- */
.tray { background: var(--paper); border: 1px solid var(--rule); border-radius: 3px; }
.tray-inner { padding: 16px 16px 18px; }
.tray .panel-head { margin-bottom: 4px; }
.tray-close { display: none; }
.tray-sum { margin: 0 0 14px; font-size: var(--fs-sm); color: var(--ink-2); }
.tray-sum strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.tray-sec { padding: 12px 0; border-top: 1px solid var(--rule-soft); }
.tray-sec > summary, .tray-sec-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; list-style: none;
  font-size: var(--fs-sm); font-weight: 700; margin: 0;
}
.tray-sec > summary::-webkit-details-marker { display: none; }
.tray-sec > summary .ic { color: var(--ink-3); transition: transform .15s; }
.tray-sec[open] > summary .ic { transform: rotate(180deg); }
.tray-sec > summary .aside { margin-left: auto; font-weight: 400; color: var(--ink-3); font-size: var(--fs-xs); }
.tray-sec .stack { display: grid; gap: 8px; margin-top: 10px; }

#cartItemsList { list-style: none; margin: 10px 0 0; padding: 0; counter-reset: q; }
.cart-row {
  display: grid; grid-template-columns: 22px minmax(0,1fr) auto; align-items: center; gap: 4px 6px;
  padding: 7px 0; border-top: 1px solid var(--rule-soft); font-size: var(--fs-sm);
}
.cart-row:first-child { border-top: 0; }
.cart-row .n { font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cart-row .what { min-width: 0; }
.cart-row .what b { display: block; font-weight: 700; font-size: var(--fs-xs); color: var(--ink-2); }
.cart-row .what span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.cart-row .tools { display: flex; align-items: center; }
.cart-row .tools .btn-icon { width: 28px; min-height: 28px; }
.cart-row .m { font-weight: 700; font-variant-numeric: tabular-nums; font-size: var(--fs-xs); margin: 0 4px 0 2px; white-space: nowrap; }
.cart-empty { margin: 10px 0 2px; padding: 14px 12px; border: 1px dashed #c4cad1; border-radius: 3px; font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.45; }

.mix { display: flex; height: 8px; border-radius: 2px; overflow: hidden; background: var(--rule-soft); margin-top: 8px; }
.mix > div { height: 100%; transition: width .2s; }
.mix .t1 { background: #c8d4e6; } .mix .t2 { background: #93abcf; } .mix .t3 { background: #5f80b3; }
.mix .t4 { background: #34588f; } .mix .t5 { background: #1a2f52; }
.mix-ends { display: flex; justify-content: space-between; margin-top: 4px; font-size: var(--fs-xs); color: var(--ink-3); }

.ao-row { font-size: var(--fs-xs); }
.ao-row .lab { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 3px; color: var(--ink-2); }
.ao-row .lab span:last-child { font-variant-numeric: tabular-nums; }
.ao-row .bar { height: 5px; border-radius: 2px; background: var(--rule-soft); overflow: hidden; }
.ao-row .bar > div { height: 100%; background: var(--accent); transition: width .2s; }
.ao-row .near { color: var(--ok) !important; font-weight: 700; }
.ao-row .under { color: #8a6617 !important; }

.code-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.code-list span { font-size: 12px; font-weight: 600; padding: 1px 6px; border: 1px solid var(--rule); border-radius: var(--r-tag); color: var(--ink-2); }

.tray-actions { display: grid; gap: 8px; padding-top: 14px; border-top: 1px solid var(--rule); margin-top: 4px; }
.tray-actions .row { display: flex; gap: 8px; }
.tray-actions .row .btn { flex: 1; }

/* phone bar */
.phone-bar { display: none; }
.scrim { display: none; }

/* ---------- Toasts ---------- */
#toastContainer > div { font-family: var(--ui) !important; border-radius: 4px !important; }

/* ---------- Dialogs (older markup, unified look) ---------- */
.app .fixed.inset-0[class*="bg-slate-9"], .app .fixed.inset-0[class*="bg-black"] { background: rgba(23, 29, 37, .55) !important; backdrop-filter: none !important; }
.app [id$="Modal"] > div, .app [id$="Modal"] .rounded-2xl, .app [id$="Modal"] .rounded-3xl { border-radius: 6px; }
.app [id$="Modal"] h2, .app [id$="Modal"] h3 { letter-spacing: -0.005em; }
.app [class*="bg-gradient-to"] { background-image: none !important; }
.app [class*="bg-gradient-to"].text-white { background-color: var(--accent) !important; }
.app .backdrop-blur, .app .backdrop-blur-sm, .app .backdrop-blur-md { backdrop-filter: none !important; }
.app .animate-pulse { animation: none !important; }

/* keystroke chips in calculator steps */
.gdc-key {
  display: inline-block; padding: 0 6px; margin: 0 2px; font-family: var(--code); font-size: 12px; font-weight: 600; line-height: 1.5;
  color: var(--ink); background: #fff; border: 1px solid #b9c0c8; border-bottom-width: 2px; border-radius: 3px; white-space: nowrap;
}

/* ---------- Narrower screens ---------- */
@media (max-width: 1240px) {
  .layout { grid-template-columns: 252px minmax(0, 1fr); }
  .btn-test { display: inline-flex; }
  .tray {
    position: fixed; z-index: 60; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); max-height: none;
    border-radius: 0; border-width: 0 0 0 1px; transform: translateX(100%); transition: transform .2s ease;
    visibility: hidden;
  }
  body.test-open .tray { transform: none; visibility: visible; box-shadow: -8px 0 32px rgba(20,28,38,.18); }
  .tray-close { display: inline-flex; }
  body.test-open .scrim, body.filters-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(23,29,37,.45); }
}
@media (max-width: 880px) {
  :root { --header-h: 56px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand img { width: 38px; height: 38px; filter: contrast(1.25) brightness(0.95); }
  .brand span { display: none; }
  .topbar-actions .hide-sm { display: none; }
  .search input { font-size: 16px; } /* stops iOS zooming in */
  .layout { display: block; padding: 14px 12px 96px; }
  .filters {
    position: fixed; z-index: 60; top: 0; left: 0; bottom: 0; width: min(340px, 90vw); max-height: none;
    padding: 16px; box-sizing: border-box; background: var(--desk); border-right: 1px solid var(--rule);
    transform: translateX(-100%); transition: transform .2s ease; visibility: hidden;
  }
  body.filters-open .filters { transform: none; visibility: visible; box-shadow: 8px 0 32px rgba(20,28,38,.18); }
  .btn-filters { display: inline-flex; }
  .filters .panel-close { display: inline-flex; }
  .feed-head .sort .lab { display: none; }
  .feed-head { flex-wrap: nowrap; gap: 8px; }
  .feed-head .result-count { white-space: nowrap; }
  .feed-head .sort .select { min-width: 0; width: 150px; }
  .q { padding: 14px 14px 12px; }
  .q.in-test { padding-left: 10px; }
  .q-text { font-size: 16.5px; }
  .ib-part { padding-left: 2.1em; }
  .ib-part.roman { padding-left: 4.2em; } .ib-part.roman > .ib-tag { left: 2.1em; }
  .q-foot .btn-add { flex: 1 0 100%; order: 9; }
  .phone-bar {
    display: flex; align-items: center; gap: 12px;
    position: fixed; z-index: 45; left: 0; right: 0; bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); box-sizing: border-box;
    background: var(--paper); border-top: 1px solid var(--rule);
  }
  .phone-bar .sum { flex: 1; font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.3; }
  .phone-bar .sum strong { color: var(--ink); }
  .btn-test { display: none; }
}
.panel-close { display: none; }

@media (prefers-reduced-motion: reduce) {
  .tray, .filters, .mix > div, .ao-row .bar > div { transition: none !important; }
}

/* ---------- Calculator steps ---------- */
.q-drawer.gdc dl.gdc-setup { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 0 0 10px; }
.q-drawer.gdc dl.gdc-setup div { display: flex; gap: 8px; }
.q-drawer.gdc dt { color: var(--ink-3); }
.q-drawer.gdc dd { margin: 0; font-weight: 600; }
.gdc-syntax { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.gdc-syntax code { padding: 4px 8px; background: #fff; border: 1px solid var(--rule); border-radius: 3px; font-size: 13px; overflow-x: auto; white-space: nowrap; max-width: 100%; }
.gdc-steps { margin: 0; padding-left: 1.4em; display: grid; gap: 10px; }
.gdc-steps li { padding-left: 4px; line-height: 1.5; }
.gdc-steps li b { display: block; margin-bottom: 2px; }
.gdc-steps code { padding: 0 4px; background: #fff; border: 1px solid var(--rule); border-radius: 2px; font-size: 12.5px; }
.gdc-tip { margin: 12px 0 0; padding: 10px 12px; border-left: 3px solid var(--hl-edge); background: #fdf8e1; line-height: 1.5; }
.gdc-tip b { margin-right: 4px; }
.saved-n { color: var(--ink-3); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Worked solution ---------- */
.steps { font-size: var(--fs-sm); line-height: 1.55; }
.steps-title { margin: 0 0 10px; font-weight: 700; }
.step-part { margin: 18px 0 8px; font-size: var(--fs-sm); font-weight: 700; color: var(--ink); border-bottom: 1px solid var(--rule); padding-bottom: 4px; }
.steps > .step-part:first-child, .steps-title + .step-part { margin-top: 4px; }
.step { margin: 0 0 14px; }
.step-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.step-n { flex: none; min-width: 1.4em; font-weight: 700; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.step-title { flex: 1; font-weight: 700; }
.step-marks { flex: none; display: flex; gap: 2px; }
.step-body { padding-left: calc(1.4em + 8px); }
.step-line { margin: 4px 0; }
.step-line.has-mark { display: flex; align-items: center; gap: 12px; }
.step-line.has-mark > div { flex: 1; min-width: 0; overflow-x: auto; }
.step-line.has-mark > .ms-token { flex: none; }
.step-math { text-align: center; overflow-x: auto; }
.step-bullet::before { content: "–"; margin-right: .5em; color: var(--ink-3); }
.step-note { margin: 8px 0 0 calc(1.4em + 8px); padding: 8px 10px; border-left: 3px solid #b8c6dc; background: var(--accent-soft); color: var(--ink); }
.step-note b, .step-answer b { margin-right: 4px; }
.step-answer { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--rule); background: #fff; }
.step-none { margin: 0; color: var(--ink-2); }
.locked-solution-card {
    padding: 16px 18px;
    background: #f8fafc;
    border: 1px dashed var(--rule);
    border-radius: var(--r-ctl);
    margin: 8px 0;
}
.locked-solution-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: var(--fs-sm);
    color: var(--ink);
    margin-bottom: 6px;
}
.locked-solution-badge {
    color: var(--accent);
}
.locked-solution-text {
    margin: 0 0 12px;
    font-size: var(--fs-sm);
    color: var(--ink-2);
    line-height: 1.5;
}
.locked-solution-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.steps.print .step-note, .steps.print .locked-solution-card { display: none; }

/* ---------- Dialogs ---------- */
.dlg { position: fixed; inset: 0; z-index: 90; padding: 24px 16px; box-sizing: border-box; background: rgba(23, 29, 37, .5); overflow-y: auto; }
.dlg:not(.hidden) { display: flex; align-items: flex-start; justify-content: center; }
.dlg-box {
  width: 100%; margin: auto 0; background: var(--paper); border-radius: 6px; box-shadow: 0 16px 48px rgba(20,28,38,.24);
  display: flex; flex-direction: column; max-height: calc(100vh - 48px); overflow: hidden;
}
.dlg-tall { height: calc(100vh - 48px); max-height: 900px; }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 20px 12px; }
.dlg-head h2 { margin: 0; font-size: var(--fs-xl); font-weight: 700; line-height: 1.25; }
.dlg-sub { margin: 4px 0 0; font-size: var(--fs-sm); color: var(--ink-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dlg-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 4px 20px 12px; border-bottom: 1px solid var(--rule); }
.dlg-body { padding: 16px 20px 20px; font-size: var(--fs-md); }
.dlg-scroll { flex: 1; overflow-y: auto; }
.dlg-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--rule); background: #fafbfc; }
.dlg-row { display: flex; gap: 8px; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); }
.dlg-tools .tabs { border-bottom: 0; margin-right: auto; }
.tabs button {
  padding: 8px 10px 9px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none;
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.dlg-tools .tabs button[aria-selected="true"] { border-bottom-color: var(--accent); }

.choice-list { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--rule); border-radius: var(--r-ctl); cursor: pointer; }
.choice:hover { border-color: #b9c0c8; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin: 3px 0 0; accent-color: var(--accent); }
.choice b { display: block; font-size: var(--fs-sm); }
.choice span span { display: block; font-size: var(--fs-xs); color: var(--ink-2); line-height: 1.4; margin-top: 2px; }

.account-card { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--rule); border-radius: var(--r-ctl); }
.account-card img, .account-card .avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover; }
.account-card .avatar { background: var(--accent-soft); }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--ink-3); font-size: var(--fs-xs); }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
.stack-form { display: grid; gap: 12px; }

/* syllabus */
.syl-course { margin: 8px 0 4px; font-size: var(--fs-lg); }
.syl-topic h4 { margin: 18px 0 2px; padding-bottom: 6px; font-size: var(--fs-sm); color: var(--ink-2); border-bottom: 1px solid var(--rule); }
.syl-topic:first-child h4 { margin-top: 0; }
.syl-row { display: flex; align-items: flex-start; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--rule-soft); }
.syl-main { flex: 1; min-width: 0; }
.syl-title { font-size: var(--fs-md); line-height: 1.4; }
.syl-subs { margin: 6px 0 0; padding-left: 1.1em; font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.5; }
.syl-subs li.hit { background: var(--hl); }
.syl-none { font-size: var(--fs-xs); color: var(--ink-3); padding-top: 9px; white-space: nowrap; }

/* saved tests */
.saved-list { list-style: none; margin: 0; padding: 0; }
.saved-item { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--rule-soft); flex-wrap: wrap; }
.saved-item.is-open { background: linear-gradient(90deg, var(--hl) 0 4px, transparent 4px); padding-left: 14px; }
.saved-main { flex: 1; min-width: 220px; }
.saved-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.saved-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* lightbox */
.dlg-dark { background: rgba(14, 18, 24, .82); }
.dlg-dark:not(.hidden) { align-items: center; }
.lightbox { width: 100%; max-width: 1100px; display: flex; flex-direction: column; gap: 10px; }
.lightbox-bar { display: flex; align-items: center; gap: 6px; color: #fff; flex-wrap: wrap; }
.lightbox-bar .btn-icon { color: #fff; }
.lightbox-bar .btn-icon:hover { background: rgba(255,255,255,.12); }
.lightbox-canvas { background: #fff; border-radius: 4px; max-height: 82vh; overflow: auto; padding: 16px; display: flex; justify-content: center; }
.lightbox-canvas img { max-width: 100%; height: auto; transform-origin: top center; }

/* preview */
.preview { position: fixed; inset: 0; z-index: 95; background: var(--desk); }
.preview:not(.hidden) { display: flex; flex-direction: column; }
.preview-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: var(--paper); border-bottom: 1px solid var(--rule); }
.preview-title h2 { margin: 0; font-size: var(--fs-lg); line-height: 1.2; }
.preview-title p { margin: 0; font-size: var(--fs-xs); color: var(--ink-3); }
.preview-modes { flex: 0 1 auto; }
.preview-modes button { padding: 0 12px; flex: 0 0 auto; }
.preview-desk { flex: 1; overflow-y: auto; padding: 28px 16px 64px; }
.preview-paper { max-width: 210mm; margin: 0 auto; background: #fff; border: 1px solid var(--rule); box-shadow: 0 2px 10px rgba(20,28,38,.08); padding: 22mm 18mm; box-sizing: border-box; min-height: 297mm; }

/* the paper itself (preview) */
.paper-head { text-align: center; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 2px solid var(--ink); }
.paper-logo { height: 40px; width: auto; display: inline-block; margin-bottom: 6px; }
.paper-head h1 { margin: 0; font-family: var(--text); font-size: 26px; font-weight: 600; }
.paper-mode { margin: 4px 0 0; font-weight: 700; }
.paper-meta { margin: 4px 0 0; font-size: var(--fs-sm); color: var(--ink-2); }
.paper-appendix { margin-top: 40px; padding-top: 24px; border-top: 2px solid var(--ink); }
.paper-name { display: flex; align-items: flex-end; gap: 10px; margin: 0 0 22px; font-size: var(--fs-sm); font-weight: 700; }
.paper-name i { display: block !important; flex: 1; border-bottom: 1px solid var(--ink); height: 18px; }
.paper-q { padding: 0 0 22px; margin-bottom: 22px; border-bottom: 1px solid var(--rule-soft); }
.paper-q:last-child { border-bottom: 0; }
.paper-qhead { display: flex; justify-content: space-between; margin: 0 0 6px; font-family: var(--text); font-size: var(--fs-lg); font-weight: 700; }
.paper-qmax { font-weight: 400; font-size: var(--fs-md); }
.paper-text { margin-top: 4px; max-width: none; font-size: 16px; }
.paper-solution { margin-top: 14px; padding: 14px 16px; border: 1px solid var(--rule); background: #fafbfc; }
.paper-ms { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }
.answer-box { margin: 10px 0 14px; }
.answer-box .working-line { height: 28px; border-bottom: 1px dotted #9aa1ab; }
.q-text .answer-box { padding-right: 0; }

@media (max-width: 880px) {
  .dlg { padding: 0; }
  .dlg-box, .dlg-tall { max-height: none; height: 100%; min-height: 100vh; border-radius: 0; }
  .preview-bar { gap: 8px; }
  .preview-modes { order: 9; width: 100%; overflow-x: auto; }
  .preview-desk { padding: 0; }
  .preview-paper { padding: 18px 14px; min-height: 0; border: 0; box-shadow: none; }
  .syl-row { flex-direction: column; gap: 8px; }
}

/* ---------- Markscheme ---------- */
.ms { font-size: var(--fs-sm); line-height: 1.55; }
.ms-row { display: grid; grid-template-columns: 2.4em minmax(0, 1fr) auto; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--rule-soft); align-items: baseline; }
.ms-row > div { min-width: 0; overflow-x: auto; }
.ms-part { font-family: var(--text); font-size: var(--fs-md); }
.ms-mark { text-align: right; white-space: nowrap; }
.ms-note > div { color: var(--ink-2); font-style: italic; }
.ms-total { padding-top: 8px; text-align: right; font-weight: 700; }

.site-footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 20px 36px;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--ink-2);
  line-height: 1.5;
}
.site-footer p { margin: 0; }
@media (max-width: 880px) {
  .site-footer { padding: 16px 14px 104px; }
}

@media print {
  #toastContainer, .phone-bar, .scrim, .site-footer { display: none !important; }
  .print-running-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 9pt;
    color: #64748b;
    padding: 4px 0;
    background: #ffffff;
  }
}

