/* /fm — generated Further Maths questions. Same palette as the /rp tools
   (rp-theme.css), restated here because this page loads none of /rp. */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --ink: #1a1d21; --mid: #343a40; --muted: #6b7280; --line: #e3e3e0;
  --bg: #f7f7f6; --surface: #ffffff; --sunken: #fafafa;
  --blue: #2a66b9; --green: #2e9e60;
  --answer-bg: #eff7f2; --answer-ink: #1f6b45;
  --tint: #eef3fb; --tint-line: #cddcf3; --blue-ink: #1f4f91;
  --bar: #1a1d21; --bar-line: #3a4048; --bar-fg: #d7dade;
  --radius: 8px;
  --picker-w: 360px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e7e9ec; --mid: #c9ced4; --muted: #9aa3ad; --line: #2f353d;
    --bg: #14171a; --surface: #21262d; --sunken: #1b1f24;
    --blue: #6fa8ff; --green: #3aa96b;
    --answer-bg: #16241d; --answer-ink: #7fd3a3;
    --tint: #1b2531; --tint-line: #33415a; --blue-ink: #9cc4ff;
    --bar: #0f1215;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body.fm-page {
  font-family: var(--font-sans); color: var(--mid); background: var(--bg);
  min-height: 100vh; display: flex; flex-direction: column;
}
button { font: inherit; }

/* ── Top bar ─────────────────────────────────────────────── */

.fm-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 14px;
  margin: 8px 8px 0; padding: 6px 12px; border-radius: var(--radius);
  background: var(--bar); color: #fff;
}
.fm-header-left, .fm-header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.fm-header h1 { margin: 0; font-size: 15px; font-weight: 700; color: #fff; white-space: nowrap; }
.fm-header h1 small { font-weight: 500; color: #9aa3ad; margin-left: 6px; font-size: 12px; }

.fm-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--bar-fg); background: transparent; text-decoration: none;
  border: 1px solid var(--bar-line); border-radius: 5px; padding: 5px 10px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.fm-btn:hover, .fm-btn[aria-pressed="true"] { background: #fff; color: #1a1d21; border-color: #fff; }
.fm-group { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--bar-fg); }
.fm-group-label { color: #9aa3ad; margin-right: 2px; }
.fm-group select {
  font: inherit; font-size: 12px; color: var(--bar-fg); background: #23282e;
  border: 1px solid var(--bar-line); border-radius: 5px; padding: 3px 4px;
}
.fm-step-btn {
  width: 24px; height: 24px; line-height: 1; font-size: 15px; color: var(--bar-fg); background: transparent;
  border: 1px solid var(--bar-line); border-radius: 5px; cursor: pointer;
}
.fm-step-btn:hover { background: #fff; color: #1a1d21; }
.fm-readout { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) { .fm-group-label { display: none; } }

/* ── Picker + board ──────────────────────────────────────── */

.fm-main { flex: 1; display: flex; gap: 10px; padding: 10px 8px; min-height: 0; }

#fm-picker {
  flex: 0 0 var(--picker-w); width: var(--picker-w);
  position: sticky; top: 58px; align-self: flex-start;
  max-height: calc(100vh - 70px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
body.fm-picker-hidden #fm-picker { display: none; }
.fm-picker-help { margin: 0; padding: 10px 12px 6px; font-size: 12px; color: var(--muted); }
#fm-skill-list { overflow-y: auto; padding: 0 6px 6px; flex: 1; }

.fm-skill { border-top: 1px solid var(--line); }
.fm-skill:first-child { border-top: 0; }
.fm-skill-head {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 8px 6px; background: none; border: 0; cursor: pointer; color: var(--ink);
}
.fm-skill-head:hover { background: var(--sunken); }
.fm-skill-n {
  flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--surface); font-size: 12px; font-weight: 700;
}
.fm-skill-name { flex: 1; font-size: 13.5px; font-weight: 650; }
.fm-skill-meta { font-size: 11px; color: var(--muted); }
.fm-skill-head::after { content: "▸"; color: var(--muted); font-size: 11px; transition: transform .15s; }
.fm-skill.is-open .fm-skill-head::after { transform: rotate(90deg); }
.fm-subs { list-style: none; margin: 0 0 6px; padding: 0; display: none; }
.fm-skill.is-open .fm-subs { display: block; }

.fm-sub {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px;
  border-radius: 6px; font-size: 12.5px; cursor: pointer; color: var(--mid);
}
.fm-sub:hover { background: var(--tint); }
.fm-sub.is-picked { background: var(--tint); box-shadow: inset 3px 0 0 var(--blue); }
.fm-sub.is-soon { cursor: default; color: var(--muted); opacity: .7; }
.fm-sub.is-soon:hover { background: none; }
.fm-code { flex: 0 0 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.fm-sub.is-soon .fm-code { color: var(--muted); }
.fm-sub-name { flex: 1; line-height: 1.3; }
.fm-soon { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; }
.fm-step { display: inline-flex; align-items: center; gap: 2px; }
.fm-step button {
  width: 22px; height: 22px; line-height: 1; padding: 0; cursor: pointer; color: var(--mid);
  background: var(--surface); border: 1px solid var(--line); border-radius: 5px;
}
.fm-step button:hover { border-color: var(--blue); color: var(--blue); }
.fm-count { min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; }

.fm-picker-foot {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-top: 1px solid var(--line); background: var(--sunken); border-radius: 0 0 var(--radius) var(--radius);
}
.fm-check { font-size: 12.5px; display: inline-flex; gap: 5px; align-items: center; }
.fm-link-btn { background: none; border: 0; color: var(--blue); cursor: pointer; font-size: 12.5px; padding: 0; }
.fm-primary {
  margin-left: auto; padding: 7px 12px; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--ink); color: var(--surface); font-weight: 650; font-size: 13px;
}
.fm-primary:disabled { opacity: .45; cursor: default; }

.fm-board {
  flex: 1; min-width: 0; align-content: start;
  display: grid; grid-template-columns: repeat(var(--fm-cols, 2), minmax(0, 1fr)); gap: 10px;
  font-size: calc(17px * var(--fm-scale, 1));
}
.fm-empty {
  grid-column: 1 / -1; padding: 40px 24px; text-align: center; color: var(--muted);
  border: 2px dashed var(--line); border-radius: var(--radius); font-size: 15px;
}
.fm-empty strong { color: var(--ink); }

/* ── Cards ───────────────────────────────────────────────── */

.fm-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.fm-card-bar {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px;
  background: var(--bar); color: #fff; font-size: 12px;
}
.fm-qn { font-weight: 700; }
.fm-card-code {
  font-weight: 700; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #3a4048; color: #fff;
}
.fm-card-name { flex: 1; min-width: 0; color: #c9ced4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-card-actions { display: inline-flex; gap: 4px; flex-shrink: 0; }
.fm-card-actions button {
  font-size: 12px; font-weight: 600; color: var(--bar-fg); background: transparent; cursor: pointer;
  border: 1px solid var(--bar-line); border-radius: 5px; padding: 2px 8px; min-width: 26px;
}
.fm-card-actions button:hover { background: #fff; color: #1a1d21; border-color: #fff; }
.fm-card.is-answered .fm-ans-btn { background: var(--green); border-color: var(--green); color: #fff; }

.fm-q { padding: .7em .9em; color: var(--ink); line-height: 1.45; overflow-x: auto; }
.fm-q p, .fm-ans p { margin: .35em 0; }
.fm-part { display: flex; gap: .5em; margin: .45em 0; }
.fm-pl { flex: 0 0 auto; font-weight: 600; }
.fm-part > div { flex: 1; min-width: 0; }
.fm-part > div > p:first-child { margin-top: 0; }

.fm-ans {
  margin: 0 .7em .7em; padding: .5em .8em; border-left: 3px solid var(--green);
  background: var(--answer-bg); color: var(--answer-ink); border-radius: 0 6px 6px 0; overflow-x: auto;
}
.fm-ans-main { font-weight: 500; }
.fm-work { margin-top: .4em; font-size: .88em; color: var(--mid); }
.fm-work summary { cursor: pointer; color: var(--answer-ink); font-weight: 600; font-size: .9em; }
/* a full model solution (exam-style skills): full size, ink colour, a rule per part */
.fm-work.fm-model { font-size: .95em; color: var(--ink); }
.fm-model .fm-part + .fm-part { border-top: 1px dashed var(--line); padding-top: .3em; margin-top: .3em; }
.fm-error { color: #c0392b; }

mjx-container[display="true"] { margin: .45em 0 !important; }

/* ── Narrow screens ──────────────────────────────────────── */

@media screen and (max-width: 900px) {
  .fm-main { flex-direction: column; }
  #fm-picker { position: static; width: 100%; flex-basis: auto; max-height: none; }
  .fm-board { grid-template-columns: minmax(0, 1fr); }
}

/* ── Print ───────────────────────────────────────────────── */

@media print {
  :root { --ink: #000; --mid: #000; --surface: #fff; --line: #999; --bg: #fff; }
  body.fm-page { background: #fff; display: block; }
  .fm-header, #fm-picker, .fm-empty, .fm-card-actions, .fm-card-name, .fm-ans { display: none !important; }
  .fm-main { display: block; padding: 0; }
  .fm-board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6mm; font-size: 11.5pt; }
  .fm-card { break-inside: avoid; border: 1px solid #999; }
  .fm-card-bar { background: none; color: #000; border-bottom: 1px solid #999; padding: 3px 8px; }
  .fm-card-code { background: none; color: #000; border: 1px solid #999; }
  .fm-q { overflow: visible; }
  #fm-key { break-before: page; font-size: 11pt; color: #000; }
  #fm-key h2 { font-size: 14pt; margin: 0 0 4mm; }
  .fm-key-item { display: flex; gap: 4mm; padding: 2mm 0; border-bottom: 1px solid #ccc; break-inside: avoid; }
  .fm-key-q { flex: 0 0 18mm; font-weight: 700; }
  .fm-key-q span { font-weight: 400; color: #555; }
  .fm-key-a { flex: 1; min-width: 0; }
  .fm-key-a p { margin: 1mm 0; }
}
@media screen { #fm-key { display: none; } }

/* Matrices side by side (row() in the skill files): one line when there is
   room, wrapping when a card or a printed half-page column is too narrow. */
.fm-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .4em 1.6em; margin: .5em 0; }

/* 2a's size table and 7e's bullet list. */
.fm-table { border-collapse: collapse; margin: .5em auto; font-size: .92em; }
.fm-table th, .fm-table td { border: 1px solid var(--line); padding: .25em .7em; text-align: center; }
.fm-table th { font-weight: 600; background: var(--sunken); }
.fm-list { margin: .3em 0 .3em 1.3em; padding: 0; }
.fm-list li { margin: .15em 0; }

/* Working is supporting detail: a touch smaller, so a long 3x3 expansion
   fits a three-across card. The panel still scrolls sideways if not. */
.fm-work mjx-container { font-size: 92%; }

/* A main skill's row: the open/close header plus its "Mix" counter, which
   adds random questions from across the whole skill. */
.fm-skill-row { display: flex; align-items: center; gap: 6px; }
.fm-skill-row .fm-skill-head { flex: 1; min-width: 0; }
.fm-mix { padding: 2px 4px 2px 8px; border-radius: 6px; font-size: 12px; }
.fm-mix.is-picked { background: var(--tint); box-shadow: inset 3px 0 0 var(--blue); }
.fm-mix-label { color: var(--muted); font-weight: 600; margin-right: 2px; }

/* "Exam-style only" at the top of the list, and the tag on every exam-style row
   (2026-11-23): just the harder, past-paper-style questions of the chapter. */
.fm-exam {
  display: flex; align-items: center; gap: 8px; margin: 2px 0 6px; padding: 7px 6px 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-weight: 650;
}
.fm-exam.is-picked { background: var(--tint); box-shadow: inset 3px 0 0 var(--blue); border-color: var(--tint-line); }
.fm-exam-label { flex: 1; line-height: 1.3; }
.fm-exam-label small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 1px; }
.fm-exam-tag {
  display: inline-block; padding: 0 5px; border-radius: 4px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .02em; line-height: 16px; vertical-align: 1px;
  color: #8a4b00; background: #fdf0d8; border: 1px solid #f1d29b;
}
.fm-exam-label > .fm-exam-tag { font-size: 12px; line-height: 18px; }
@media (prefers-color-scheme: dark) { .fm-exam-tag { color: #ffc56b; background: #3a2a10; border-color: #6b4c1a; } }

/* Display maths in an answer panel a hair smaller: a full 3x3 expansion then
   fits a three-across card. */
.fm-ans-main mjx-container[display="true"] { font-size: 95%; }

/* Chapter switcher at the top of the skill list. */
.fm-chapter-pick { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.fm-chapter-pick select { flex: 1; min-width: 0; font: inherit; font-weight: 600; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; }

/* Argand diagrams (fm-argand.js): drawn in currentColor so they work in
   dark mode, with the shading in the tool blue. */
.fm-ag-wrap { display: flex; justify-content: center; margin: .5em 0; color: var(--ink); }
.fm-argand { max-width: 100%; height: auto; overflow: hidden; }
.fm-ag-grid line { stroke: var(--line); stroke-width: .6; }
.fm-ag-axes line { stroke: currentColor; stroke-width: 1.1; }
.fm-ag-t { font: 11px var(--font-sans); fill: currentColor; }
.fm-ag-tick { font: 9px var(--font-sans); fill: var(--muted); }
.fm-ag-curve { stroke: var(--blue); stroke-width: 1.8; fill: none; }
.fm-ag-vec { stroke: currentColor; stroke-width: 1.4; }
.fm-ag-pt { fill: currentColor; }
.fm-ag-open { fill: var(--surface); stroke: var(--blue); stroke-width: 1.6; }
.fm-ag-shade { fill: var(--blue); opacity: .22; }
@media print { .fm-ag-shade { opacity: .25; } .fm-ag-grid line { stroke: #ccc; } }

/* Sketch graphs (fm-plot.js): volumes of revolution and transformations.
   Equations and letters in the diagrams are italic serif, like the book's. */
.fm-pl-wrap { display: flex; justify-content: center; margin: .5em 0; color: var(--ink); }
.fm-plot { max-width: 100%; height: auto; overflow: hidden; }
.fm-pl-grid line { stroke: var(--line); stroke-width: .6; }
.fm-pl-axes line, .fm-pl-tick { stroke: currentColor; stroke-width: 1.1; }
.fm-pl-t { font: italic 14px "Times New Roman", Times, serif; fill: currentColor; }
.fm-pl-n { font: 11px var(--font-sans); fill: var(--mid); }
.fm-pl-curve { stroke: var(--blue); stroke-width: 1.8; fill: none; }
.fm-pl-thin { stroke: currentColor; stroke-width: .9; fill: none; }
.fm-pl-shape { stroke: currentColor; stroke-width: 1.5; fill: none; }
.fm-pl-pt { fill: currentColor; }
.fm-pl-shade { fill: var(--blue); opacity: .22; }
@media print { .fm-pl-shade { opacity: .25; } .fm-pl-grid line { stroke: #ccc; } }

/* The eye on a subskill row: an example question without adding it (as /fp). */
.fm-peek {
  flex: 0 0 auto; display: inline-grid; place-items: center; width: 24px; height: 22px; padding: 0;
  color: var(--muted); background: none; border: 1px solid transparent; border-radius: 5px; cursor: pointer;
}
.fm-peek:hover, .fm-peek:focus-visible { color: var(--blue); border-color: var(--line); background: var(--surface); }

/* The preview: one question in a dialog over the page. */
.fm-modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; background: rgba(15, 18, 21, .55); }
.fm-modal.is-open { display: flex; }
.fm-modal-box { width: min(760px, 100%); max-height: 88vh; overflow: auto; background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); outline: none; }
.fm-modal-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 7px 8px 7px 12px; background: var(--bar); color: #fff; font-size: 13px; }
.fm-modal-title { flex: 1; min-width: 0; font-weight: 600; color: #e7e9ec; }
.fm-modal-actions { display: inline-flex; gap: 4px; flex-shrink: 0; }
.fm-modal-actions button { font-size: 12.5px; font-weight: 600; color: var(--bar-fg); background: transparent; cursor: pointer; border: 1px solid var(--bar-line); border-radius: 5px; padding: 3px 9px; min-width: 28px; }
.fm-modal-actions button:hover { background: #fff; color: #1a1d21; border-color: #fff; }
.fm-modal-body { font-size: 17px; }
.fm-modal-body .fm-q { padding: .9em 1.1em .4em; }
.fm-modal-body .fm-ans { margin: 0 1em .8em; }
.fm-modal-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding: .4em 1.1em 1em; }
.fm-modal-foot .fm-primary { margin-left: 0; }
.fm-modal-keys { font-size: 12px; color: var(--muted); }
@media print { .fm-modal { display: none !important; } }

/* Labels off: each card shows only its number (the name would give the method away). */
body.fm-no-labels .fm-card .fm-card-code, body.fm-no-labels .fm-card .fm-card-name { visibility: hidden; }

/* Exam-style questions: the marks for a part, at the right as on a paper —
   <span class="fm-marks">(3 marks)</span> at the end of a part's text. */
.fm-marks { float: right; margin-left: .8em; font-weight: 600; font-size: .85em; color: var(--muted); white-space: nowrap; }
@media print { .fm-marks { color: #000; } }

/* A skill that belongs to this chapter (it is on past papers) but needs a topic
   the scheme of work teaches LATER: listed in red with the reason, never added. */
.fm-sub.is-later { cursor: default; color: #b42318; background: none; }
.fm-sub.is-later:hover { background: none; }
.fm-sub.is-later .fm-code { color: #b42318; }
.fm-sub.is-later small { display: block; font-size: 11px; line-height: 1.3; color: #b42318; opacity: .85; margin-top: 1px; }
@media (prefers-color-scheme: dark) { .fm-sub.is-later, .fm-sub.is-later .fm-code, .fm-sub.is-later small { color: #ff8a80; } }

/* ── Search (every chapter, from search.json) ─────────────── */
.fm-search { padding: 8px 12px 0; }
.fm-search input {
  width: 100%; font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; -webkit-appearance: none; appearance: none;
}
.fm-search input:focus { outline: 2px solid var(--tint-line); border-color: var(--blue); }
.fm-search-out {
  margin-top: 6px; max-height: min(55vh, 460px); overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.fm-search-ch {
  position: sticky; top: 0; z-index: 1; padding: 6px 9px 4px; font-size: 11.5px; font-weight: 700;
  color: var(--ink); background: var(--sunken); border-bottom: 1px solid var(--line);
}
.fm-search-ch span { font-weight: 600; color: var(--blue-ink); margin-left: 4px; }
.fm-search-hit {
  display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left; cursor: pointer;
  padding: 6px 9px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--mid); font: inherit; font-size: 12.5px;
}
.fm-search-hit:last-child { border-bottom: 0; }
.fm-search-hit:hover, .fm-search-hit.is-active { background: var(--tint); }
.fm-search-hit .fm-code { flex: 0 0 auto; min-width: 26px; }
.fm-search-name { flex: 1; line-height: 1.3; }
.fm-search-name small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.fm-search-hit mark { background: #fff1a8; color: inherit; border-radius: 2px; }
.fm-search-note { margin: 0; padding: 8px 9px; font-size: 12px; color: var(--muted); }
@media (prefers-color-scheme: dark) { .fm-search-hit mark { background: #5c4d00; } }
@keyframes fm-flash { from { background: #fff1a8; } to { background: var(--tint); } }
.fm-sub.is-flash { animation: fm-flash 1.6s ease-out; }
@media screen and (max-width: 900px) {
  .fm-search input { font-size: 16px; padding: 9px 10px; }   /* 16px: iOS does not zoom in on focus */
  .fm-search-hit { padding: 9px 10px; font-size: 14px; }
  .fm-search-out { max-height: 60vh; }
}
@media print { .fm-search { display: none !important; } }
