/* Model shell: everything inside .viz-container that every model shares.
   A model's own model.css sets LAYOUT ONLY. Colours are defined once, here,
   and reach model scripts through ModelShell.palette() / ctx.palette(), so
   every model matches and high contrast works without per-model code. */

.viz-container {
  --model-bg: #ffffff;
  --model-fg: #16232f;
  --model-grid: #c9d3dc;
  --model-muted: #5b6b79;
  --model-accent: #123c69;          /* the site's main colour: selected tabs, buttons, needles */
  --model-panel: #f3f6f8;
  --model-good: #1b7a57;
  --model-good-tint: #e6f3ee;
  --model-bad: #b3261e;
  --model-bad-tint: #fbeceb;
  --model-legend-bg: rgba(255, 255, 255, 0.9);
  --model-title-size: 16;
  --model-axis-size: 14;
  --model-series-1: #1b5fa8;        /* Prussian blue */
  --model-series-2: #d9580d;        /* dichromate */
  --model-series-3: #1b7a57;        /* malachite */
  --model-series-4: #424b54;        /* graphite */
  --model-series-5: #b3261e;        /* cinnabar: hot, warning, over the limit */

  color: var(--model-fg);
}

.viz-container.high-contrast {
  --model-bg: #000000;
  --model-fg: #ffffff;
  --model-grid: #ffffff;
  --model-muted: #ffffff;
  --model-accent: #ffeb3b;
  --model-panel: #000000;
  --model-good: #ffffff;
  --model-good-tint: #000000;
  --model-bad: #ffffff;
  --model-bad-tint: #000000;
  --model-legend-bg: rgba(0, 0, 0, 0.9);
  /* Every series is white in high contrast; scripts tell them apart by dash. */
  --model-series-1: #ffffff;
  --model-series-2: #ffffff;
  --model-series-3: #ffffff;
  --model-series-4: #ffffff;
  --model-series-5: #ffffff;

  background: #000;
  padding: 1rem;
  border-radius: 12px;
}
.viz-container.high-contrast a,
.viz-container.high-contrast .link-btn { color: #ffeb3b; }
.viz-container.high-contrast .tag { color: #fff; }
.viz-container.high-contrast :focus-visible { outline-color: #ffeb3b; }

/* "Dyslexia-friendly formatting". Follows the British Dyslexia Association style guide:
   plain sans-serif, larger, wider letter / word / line spacing, off-white
   background. */
.viz-container.dyslexic-font,
.viz-container.dyslexic-font * {
  font-family: Verdana, Tahoma, Arial, sans-serif !important;
  letter-spacing: 0.06em;
  word-spacing: 0.21em;
}
.viz-container.dyslexic-font { font-size: 1.08em; line-height: 1.6; }
.viz-container.dyslexic-font p,
.viz-container.dyslexic-font li,
.viz-container.dyslexic-font label { line-height: 1.6; }
.viz-container.dyslexic-font:not(.high-contrast) {
  --model-bg: #fdf9ec;
  --model-panel: #f6f0dc;
  background: #fdf9ec;
  padding: 1rem;
  border-radius: 12px;
}

.viz-container.focus-mode .hide-in-focus { display: none !important; }

/* ---------------------------------------------------------- display options */
.accessibility-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 1.2rem;
  margin-bottom: 1.2rem;
  padding: 0.55rem 0.9rem;
  font-size: 0.95rem;
  background: var(--model-panel);
  border: 1px solid var(--model-grid);
  border-radius: 10px;
}
.accessibility-panel h2 { margin: 0; font-family: inherit; font-size: inherit; letter-spacing: 0; }
.accessibility-options { display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; }
.accessibility-option { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.accessibility-option input { width: 1.05rem; height: 1.05rem; accent-color: var(--model-fg); }

/* ------------------------------------------------------------------ heading */
.model-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.3rem 1rem; margin-bottom: 0.6rem; }
.model-title { margin: 0; }
.model-meta { display: flex; gap: 0.4rem; margin: 0; }
.model-intro { max-width: 46rem; margin-bottom: 1.2rem; }
.model-intro p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ model layout */
/* Results on the left, controls on the right, so a slider sits beside the
   thing it changes. On narrow screens the controls drop directly underneath. */
.model-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.model-layout > * { min-width: 0; }
/* A model may have several results cards. They stack in the left column while
   the controls card spans the right. In one-column layouts the cards simply
   follow markup order, so put the controls card straight after the picture. */
.model-layout > .model-card--results { grid-column: 1; }
.model-layout > .model-card--controls { grid-column: 2; grid-row: 1 / span 4; }
.model-layout [hidden] { display: none !important; }

.model-card {
  padding: 1rem;
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 14px;
}
.model-card--controls { border-width: 1px; border-color: var(--model-grid); }
/* On wide screens the controls follow you down the page, so the sliders stay
   beside whatever they change (a graph under the picture, for example). */
@media (min-width: 821px) {
  .viz-container:not(.compact-mode) .model-card--controls { position: sticky; top: 1rem; }
}
.high-contrast .model-card--controls { border-color: #fff; }

.model-slider {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "label value" "input input";
  gap: 0.15rem 0.6rem;
  margin-bottom: 1rem;
}
.model-slider label { grid-area: label; font-weight: 700; }
.model-slider input { grid-area: input; width: 100%; accent-color: var(--model-series-1); }
.model-slider-value { grid-area: value; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.model-readout { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0.8rem 0 0.4rem; }
.model-readout-label { font-weight: 700; }
.model-readout-value {
  font-family: var(--display, inherit);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--model-accent);
}

.model-reset-btn {
  padding: 0.4rem 1rem;
  font: inherit;
  font-weight: 700;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 999px;
  cursor: pointer;
}
.model-reset-btn:hover { background: var(--model-fg); color: var(--model-bg); }
.model-reset-btn:disabled { opacity: 0.5; cursor: default; }

.model-note {
  max-width: 46rem;
  margin-top: 1.5rem;
  padding: 0.9rem 1.1rem;
  background: var(--model-panel);
  border: 1px solid var(--model-grid);
  border-radius: 10px;
}
.model-note h2 { font-size: 1.1rem; margin-bottom: 0.4rem; }
.model-note ul { margin: 0; padding-left: 1.2rem; }
.model-note li { margin: 0.25rem 0; }

/* -------------------------------------------------------------- compact mode */
.model-secondary > summary { font-weight: 700; cursor: pointer; margin-bottom: 0.8rem; }
.viz-container:not(.compact-mode) .model-secondary > summary { display: none; }

.compact-mode .model-layout { grid-template-columns: minmax(0, 1fr); }
.compact-mode .model-layout > .model-card { grid-column: auto; grid-row: auto; }

.model-notice {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  background: var(--model-panel);
  border: 2px solid var(--model-fg);
  border-radius: 10px;
}
.model-notice p { margin: 0 0 0.6rem; }
.model-notice-btn {
  margin-right: 0.5rem;
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-weight: 700;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 999px;
  cursor: pointer;
}

/* ----------------------------------------------------------------- practice */
/* Practice sets, topic tests and the short checks under models. The markup is
   written by assets/js/practice.js. Every colour is a --model-* property, so
   high contrast and the dyslexia-friendly background need nothing extra.
   Right and wrong never rely on colour: right is a solid thick border and a
   tick, wrong is a dashed border, a cross and a line through the text. */
.practice { margin-top: 0.5rem; }
.practice--check { margin-top: 2rem; }
.practice [hidden] { display: none !important; }
.practice-title { font-size: 1.35rem; }
.practice-empty { max-width: 46rem; padding: 0.9rem 1.1rem; background: var(--model-panel); border: 1px solid var(--model-grid); border-radius: 10px; }
.practice-test-link { margin: 2rem 0 0; }
.practice sup, .practice sub, .model-note sup, .model-note sub, .model-intro sup, .model-intro sub { line-height: 0; }

.pr-sheet {
  margin-bottom: 0.9rem;
  padding: 0.45rem 0.9rem;
  background: var(--model-bg);
  border: 2px solid var(--model-grid);
  border-radius: 10px;
}
.pr-sheet summary { font-weight: 700; cursor: pointer; }
.pr-sheet ul { margin: 0.5rem 0 0.3rem; padding-left: 1.2rem; columns: 2; column-gap: 2rem; }
.pr-sheet li { margin: 0.2rem 0; break-inside: avoid; }

.pr-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.9rem; }
.pr-body > * { min-width: 0; }
.pr-panel { border-width: 1px; border-color: var(--model-grid); }
.high-contrast .pr-panel { border-color: #fff; }

.pr-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.4rem 1rem; margin-bottom: 0.7rem; }
.pr-score { margin: 0; font-weight: 700; }
.pr-bar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.8rem; }
.pr-warn { font-weight: 700; }

/* the grid of problem tiles */
.pr-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
.pr-tile {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  font: inherit;
  text-align: left;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-grid);
  border-radius: 12px;
  cursor: pointer;
}
.pr-tile:hover { border-color: var(--model-fg); }
.pr-tile.is-done { border-color: var(--model-good); background: var(--model-good-tint); }
.pr-tile.is-part { border-style: dashed; border-color: var(--model-fg); }
.pr-tile[aria-current="true"] { border-style: solid; border-color: var(--model-accent); box-shadow: inset 0 0 0 2px var(--model-accent); }
.pr-ic {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  color: var(--model-accent);
  background: var(--model-panel);
  border: 1px solid var(--model-grid);
  border-radius: 10px;
}
.pr-tile-title { display: block; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.pr-tile-tags { display: block; margin-top: 0.25rem; }
.pr-tick { align-self: start; font-weight: 700; white-space: nowrap; color: var(--model-good); }
.pr-tile.is-part .pr-tick { color: var(--model-fg); }

/* Tags: the format is filled, the context is outlined. */
.pr-chip {
  display: inline-block;
  margin: 0 0.25rem 0.15rem 0;
  padding: 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.55;
  color: var(--model-fg);
  border: 1.5px solid var(--model-fg);
  border-radius: 999px;
}
.pr-chip--fmt { color: var(--model-bg); background: var(--model-fg); }

/* one problem */
.pr-tags { margin: 0 0 0.2rem; }
.pr-q h3 { margin: 0.2rem 0 0.4rem; font-size: 1.3rem; }
.pr-intro { max-width: 46rem; margin: 0 0 0.7rem; }
.pr-equation { margin: 0 0 0.5rem; font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.pr-fig { margin: 0.4rem 0 0.9rem; padding: 0.5rem; background: var(--model-panel); border: 1px solid var(--model-grid); border-radius: 10px; }
.pr-fig svg { display: block; width: 100%; max-width: 620px; height: auto; margin: 0 auto; background: var(--model-bg); border-radius: 6px; }
.pr-scroll { overflow-x: auto; }
.pr-data { width: 100%; max-width: 36rem; border-collapse: collapse; font-size: 0.95rem; background: var(--model-bg); }
.pr-data caption { padding-bottom: 0.25rem; text-align: left; font-weight: 700; }
.pr-data th, .pr-data td { padding: 0.3rem 0.6rem; text-align: right; border-bottom: 1px solid var(--model-grid); }
.pr-data th:first-child, .pr-data td:first-child { text-align: left; }
.pr-data tbody th { font-weight: 400; }

/* steps unlock in order */
.pr-step { margin: 0.55rem 0; padding: 0.55rem 0.75rem; border: 2px solid var(--model-grid); border-radius: 10px; }
.pr-step.is-active { border-color: var(--model-accent); }
.pr-step.is-done { border-color: var(--model-good); background: var(--model-good-tint); }
.pr-step.is-missed { border-style: dashed; border-color: var(--model-bad); background: var(--model-bad-tint); }
.pr-step.is-locked { border-style: dashed; color: var(--model-muted); }
.pr-label { margin: 0 0 0.45rem; font-weight: 700; }
.pr-lock { display: inline-block; margin-left: 0.3rem; font-size: 0.85rem; font-weight: 400; }
.pr-claim {
  margin: 0.2rem 0 0.55rem;
  padding: 0.45rem 0.7rem;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px dashed var(--model-fg);
  border-radius: 10px;
  overflow-wrap: anywhere;
}

.pr-num { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.6rem; }
.pr-num input {
  width: 9rem;
  max-width: 100%;
  padding: 0.35rem 0.55rem;
  font: inherit;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 8px;
}
.pr-num input:disabled { border-color: var(--model-grid); }
.pr-unit { font-weight: 700; }
.model-reset-btn.pr-strong { color: var(--model-bg); background: var(--model-fg); }
.model-reset-btn.pr-strong:hover:not(:disabled) { color: var(--model-fg); background: var(--model-bg); }

.pr-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.45rem; }
.pr-opt {
  padding: 0.5rem 0.7rem;
  font: inherit;
  text-align: left;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 8px;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.pr-opt:hover:not(:disabled) { background: var(--model-panel); box-shadow: inset 0 0 0 1px var(--model-fg); }
.pr-opt:disabled { cursor: default; color: var(--model-muted); border-color: var(--model-grid); }
.pr-opt.is-right { color: var(--model-fg); font-weight: 700; border-width: 3px; border-color: var(--model-good); background: var(--model-good-tint); }
.pr-opt.is-wrong { color: var(--model-fg); border-style: dashed; border-color: var(--model-bad); background: var(--model-bad-tint); text-decoration: line-through; }
.pr-opt.is-right::before, .pr-token.is-right::before { content: "✓"; margin-right: 0.35em; }
.pr-opt.is-wrong::before, .pr-token.is-wrong::before { content: "✗"; display: inline-block; margin-right: 0.35em; text-decoration: none; }

.pr-feedback, .pr-mark { margin: 0.5rem 0 0; }
.pr-feedback:empty { display: none; }
.pr-mark--right strong { color: var(--model-good); }
.pr-mark--wrong strong { color: var(--model-bad); }
.pr-working {
  margin: 0.8rem 0 0;
  padding: 0.6rem 0.9rem 0.6rem 2rem;
  background: var(--model-panel);
  border: 1px solid var(--model-grid);
  border-radius: 10px;
  overflow-wrap: anywhere;
}
.pr-working { list-style-type: lower-alpha; }   /* matches the step letters */
.pr-working li { margin: 0.35rem 0; }
.pr-from { margin: 0.8rem 0 0; font-size: 0.95rem; }

/* true or false, and sort */
.pr-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.pr-card { padding: 0.55rem 0.75rem; border: 2px solid var(--model-grid); border-radius: 10px; }
.pr-card.is-done { border-color: var(--model-good); background: var(--model-good-tint); }
.pr-card.is-missed { border-style: dashed; border-color: var(--model-bad); background: var(--model-bad-tint); }
.pr-card p { margin: 0 0 0.45rem; }
.pr-card p:last-child { margin-bottom: 0; }
.pr-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-bottom: 0.45rem; }
.pr-why { font-size: 0.95rem; }

/* match: select an item, then the box it belongs in */
.pr-pool { display: flex; flex-wrap: wrap; gap: 0.4rem; min-height: 2.4rem; }
.pr-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 0.45rem; margin-top: 0.7rem; }
.pr-cell { display: flex; flex-direction: column; gap: 0.3rem; min-height: 5.5rem; padding: 0.45rem; border: 2px dashed var(--model-grid); border-radius: 10px; }
.pr-cell.is-target { border-color: var(--model-accent); cursor: pointer; }
.pr-cap { font-size: 0.9rem; font-weight: 700; }
.pr-token {
  padding: 0.35rem 0.55rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: left;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 8px;
  cursor: pointer;
}
.pr-token:disabled { cursor: default; }
.pr-token[aria-pressed="true"] { border-color: var(--model-accent); box-shadow: 0 0 0 2px var(--model-accent); }
.pr-token.is-right { border-color: var(--model-good); background: var(--model-good-tint); }
.pr-token.is-wrong { border-style: dashed; border-color: var(--model-bad); background: var(--model-bad-tint); }
.pr-belongs { display: block; font-size: 0.88rem; font-weight: 400; }
.pr-place {
  margin-top: auto;
  padding: 0.25rem 0.5rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--model-bg);
  background: var(--model-accent);
  border: 2px solid var(--model-accent);
  border-radius: 8px;
  cursor: pointer;
}

.pr-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; margin-top: 0.9rem; }
.pr-row--start { justify-content: flex-start; }

/* the score at the end of a test */
.pr-result { margin-top: 0.9rem; padding-top: 0.8rem; border-top: 2px solid var(--model-fg); }
.pr-result h3 { margin-bottom: 0.5rem; font-size: 1.4rem; }
.pr-result p { max-width: 46rem; margin: 0.7rem 0; }

@media (max-width: 900px) {
  .pr-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pr-sheet ul { columns: 1; }
}
@media (max-width: 560px) {
  .pr-tiles, .pr-cards, .pr-opts { grid-template-columns: minmax(0, 1fr); }
  .practice .model-card { padding: 0.75rem; }
  .pr-step, .pr-card { padding: 0.5rem 0.6rem; }
  .pr-working { padding-left: 1.7rem; }
  .pr-fig { padding: 0.25rem; }
}

@media (max-width: 820px) {
  .model-layout { grid-template-columns: minmax(0, 1fr); }
  .model-layout > .model-card { grid-column: auto; grid-row: auto; }
}

/* ------------------------------------------------- stage tabs and choice chips */
/* Shared by any model with stages or presets. Pressed state uses aria-pressed,
   so the script only has to set that attribute. */
.model-tabs { display: grid; gap: 0.35rem; margin-bottom: 1rem; }
.model-tab {
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-weight: 700;
  text-align: left;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 8px;
  cursor: pointer;
}
.model-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1rem; }
.model-chip {
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--model-fg);
  background: var(--model-bg);
  border: 2px solid var(--model-fg);
  border-radius: 999px;
  cursor: pointer;
}
.model-tab[aria-pressed="true"],
.model-chip[aria-pressed="true"] { background: var(--model-fg); color: var(--model-bg); }
.model-tab:hover:not([aria-pressed="true"]),
.model-chip:hover:not([aria-pressed="true"]) { background: var(--model-panel); }

.model-slider.is-fixed { opacity: 0.55; }
.model-slider.is-fixed label::after { content: " (fixed)"; font-weight: 400; }

/* ------------------------------------------------------------ cancelled units */
/* Wrap a unit that cancels in <span class="cancel">: it gets a diagonal stroke,
   as it would on paper. Works anywhere inside a model or a practice set. */
.cancel {
  padding: 0 0.1em;
  background: linear-gradient(to top left,
    transparent calc(50% - 1px), var(--model-bad) calc(50% - 1px),
    var(--model-bad) calc(50% + 1px), transparent calc(50% + 1px));
}
.high-contrast .cancel { --model-bad: #ffeb3b; }
