/* matikka.xyz — one stylesheet for every page. Colours are tokens; dark mode follows the
   system unless the reader picked a theme (html[data-theme]). */

:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #1f1e1b;
  --muted: #5f5e5a;
  --faint: #8a8880;
  --line: #e4e1d8;
  --edge: #b4b2a9;
  --edge-lit: #1f1e1b;
  --link: #3c3489;
  --backdrop: rgb(31 30 27 / 0.35);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.08);

  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #161614;
    --surface: #1f1f1c;
    --ink: #edebe4;
    --muted: #b4b2a9;
    --faint: #8a8880;
    --line: #34332f;
    --edge: #5f5e5a;
    --edge-lit: #edebe4;
    --link: #afa9ec;
    --backdrop: rgb(0 0 0 / 0.55);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #161614;
  --surface: #1f1f1c;
  --ink: #edebe4;
  --muted: #b4b2a9;
  --faint: #8a8880;
  --line: #34332f;
  --edge: #5f5e5a;
  --edge-lit: #edebe4;
  --link: #afa9ec;
  --backdrop: rgb(0 0 0 / 0.55);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

/* Colour ramps. Light: 50 fill / 600 stroke / 800 title / 600 subtitle.
   Dark: 800 fill / 200 stroke / 100 title / 200 subtitle. */
.ramp-coral  { --fill: #faece7; --stroke: #993c1d; --title: #712b13; --sub: #993c1d; }
.ramp-amber  { --fill: #faeeda; --stroke: #854f0b; --title: #633806; --sub: #854f0b; }
.ramp-green  { --fill: #eaf3de; --stroke: #3b6d11; --title: #27500a; --sub: #3b6d11; }
.ramp-teal   { --fill: #e1f5ee; --stroke: #0f6e56; --title: #085041; --sub: #0f6e56; }
.ramp-blue   { --fill: #e6f1fb; --stroke: #185fa5; --title: #0c447c; --sub: #185fa5; }
.ramp-purple { --fill: #eeedfe; --stroke: #534ab7; --title: #3c3489; --sub: #534ab7; }
.ramp-pink   { --fill: #fbeaf0; --stroke: #993556; --title: #72243e; --sub: #993556; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .ramp-coral  { --fill: #712b13; --stroke: #f0997b; --title: #f5c4b3; --sub: #f0997b; }
  :root:not([data-theme='light']) .ramp-amber  { --fill: #633806; --stroke: #ef9f27; --title: #fac775; --sub: #ef9f27; }
  :root:not([data-theme='light']) .ramp-green  { --fill: #27500a; --stroke: #97c459; --title: #c0dd97; --sub: #97c459; }
  :root:not([data-theme='light']) .ramp-teal   { --fill: #085041; --stroke: #5dcaa5; --title: #9fe1cb; --sub: #5dcaa5; }
  :root:not([data-theme='light']) .ramp-blue   { --fill: #0c447c; --stroke: #85b7eb; --title: #b5d4f4; --sub: #85b7eb; }
  :root:not([data-theme='light']) .ramp-purple { --fill: #3c3489; --stroke: #afa9ec; --title: #cecbf6; --sub: #afa9ec; }
  :root:not([data-theme='light']) .ramp-pink   { --fill: #72243e; --stroke: #ed93b1; --title: #f4c0d1; --sub: #ed93b1; }
}
:root[data-theme='dark'] .ramp-coral  { --fill: #712b13; --stroke: #f0997b; --title: #f5c4b3; --sub: #f0997b; }
:root[data-theme='dark'] .ramp-amber  { --fill: #633806; --stroke: #ef9f27; --title: #fac775; --sub: #ef9f27; }
:root[data-theme='dark'] .ramp-green  { --fill: #27500a; --stroke: #97c459; --title: #c0dd97; --sub: #97c459; }
:root[data-theme='dark'] .ramp-teal   { --fill: #085041; --stroke: #5dcaa5; --title: #9fe1cb; --sub: #5dcaa5; }
:root[data-theme='dark'] .ramp-blue   { --fill: #0c447c; --stroke: #85b7eb; --title: #b5d4f4; --sub: #85b7eb; }
:root[data-theme='dark'] .ramp-purple { --fill: #3c3489; --stroke: #afa9ec; --title: #cecbf6; --sub: #afa9ec; }
:root[data-theme='dark'] .ramp-pink   { --fill: #72243e; --stroke: #ed93b1; --title: #f4c0d1; --sub: #ed93b1; }

/* ------------------------------------------------------------------ base */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
}
a { color: var(--link); text-underline-offset: 0.15em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .wrap { padding: 0 32px; } }

.site-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
  padding-bottom: 20px;
  font-family: var(--sans);
  font-size: 15px;
}
.brand { font-family: var(--sans); font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand span { color: var(--faint); }
.site-nav { display: flex; align-items: center; gap: 18px; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a[aria-current='page'], .site-nav a:hover { color: var(--ink); }
.theme-toggle {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.theme-toggle svg { width: 16px; height: 16px; }
@media (max-width: 520px) { .site-nav .nav-subject { display: none; } }

h1, h2, h3 { font-family: var(--sans); font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.eyebrow { font: 500 13px/1.4 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin: 0 0 8px; }

.site-foot {
  margin-top: 64px;
  padding-top: 24px;
  padding-bottom: 40px;
  border-top: 1px solid var(--line);
  font: 14px/1.6 var(--sans);
  color: var(--muted);
}

/* --------------------------------------------------------------- landing */

.hero { padding: 48px 0 32px; max-width: 720px; }
.hero h1 { font-size: clamp(40px, 8vw, 64px); margin: 0 0 12px; letter-spacing: -0.03em; }
.hero h1 span { color: var(--faint); }
.hero p { font-size: 19px; color: var(--muted); margin: 0; }

.subjects { display: grid; gap: 20px; grid-template-columns: 1fr; margin-top: 16px; }
@media (min-width: 760px) { .subjects { grid-template-columns: 1fr 1fr; } }

.subject-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.subject-card:hover { border-color: var(--muted); box-shadow: var(--shadow); transform: translateY(-1px); }
.subject-card h2 { margin: 0; font-size: 26px; }
.subject-card p { margin: 0; color: var(--muted); }
.subject-card .basis { font: 14px/1.5 var(--sans); color: var(--faint); }
.subject-card .go { font: 500 15px var(--sans); color: var(--link); margin-top: auto; }

.mini { display: grid; gap: 5px; margin-bottom: 4px; }
.mini-row { display: flex; gap: 5px; }
.mini-row i { display: block; height: 12px; flex: 0 0 36px; border-radius: 3px; background: var(--fill); border: 1px solid var(--stroke); }

/* --------------------------------------------------------------- subject */

.subject-head { padding: 24px 0 8px; max-width: 760px; }
.subject-head h1 { font-size: clamp(32px, 6vw, 46px); margin: 0 0 12px; letter-spacing: -0.02em; }
.lede { font-size: 18px; color: var(--muted); margin: 0 0 16px; }
.story { margin: 0 0 8px; padding-inline-start: 1.2em; color: var(--muted); }
.story li { margin: 4px 0; }
.story strong { color: var(--ink); font-weight: 600; }
.hint { font: 14px/1.5 var(--sans); color: var(--faint); margin: 16px 0 0; }

.map-shell { margin-top: 24px; }
.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 12px;
  font: 14px/1.4 var(--sans);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 0; padding: 0; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--fill); border: 1px solid var(--stroke); }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); }
.seg { border: 0; background: transparent; padding: 4px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font: 500 13px var(--sans); }
.seg[aria-pressed='true'] { background: var(--bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.map-shell[data-view='map'] .map-list, .map-shell[data-view='list'] .map-canvas { display: none; }

.map-canvas {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
  padding: 8px;
}
.map-svg { display: block; width: 100%; max-width: 100%; height: auto; margin: 0 auto; font-family: var(--sans); }

.row-label { font: 600 12px var(--sans); fill: var(--faint); letter-spacing: 0.04em; }

.edge { fill: none; stroke: var(--edge); stroke-width: 1.25; marker-end: var(--arrow); transition: opacity 0.15s, stroke 0.15s; }
.map-svg marker path { fill: var(--edge); }
.map-svg marker:last-of-type path { fill: var(--edge-lit); }

.node { cursor: pointer; transition: opacity 0.15s; }
.node rect { fill: var(--fill); stroke: var(--stroke); stroke-width: 0.75; transition: stroke-width 0.15s; }
.node .t { font-size: 14px; font-weight: 600; fill: var(--title); }
.node .s { font-size: 12px; fill: var(--sub); }
.node:hover rect, .node:focus-visible rect { stroke-width: 2; }
.node:focus { outline: none; }
.node:focus-visible rect { stroke-width: 2.5; }

.spotlit .node:not(.lit) { opacity: 0.35; }
.spotlit .edge:not(.lit) { opacity: 0.2; }
.spotlit .edge.lit { stroke: var(--edge-lit); stroke-width: 1.75; marker-end: var(--arrow-lit); }

/* list view */
.map-list { display: grid; gap: 24px; }
.list-group h3 { font-size: 18px; margin: 0 0 10px; color: var(--ink); }
.list-group { display: grid; gap: 8px; }
.card {
  display: grid;
  gap: 2px;
  text-align: start;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--fill);
  cursor: pointer;
  font-family: var(--sans);
}
.card-t { font-weight: 600; font-size: 16px; color: var(--title); }
.card-s { font-size: 14px; color: var(--sub); }
.card-next { font-size: 13px; color: var(--sub); opacity: 0.85; margin-top: 4px; }

.map-error { padding: 16px; border: 1px solid var(--line); border-radius: 10px; font-family: var(--sans); }

/* sources */
.sources-block h2 { font-size: 22px; margin: 48px 0 8px; }
.sources-block > p { color: var(--muted); max-width: 760px; }
.sources { padding-inline-start: 1.2em; max-width: 860px; }
.sources li { margin: 10px 0; }
.source-note { color: var(--muted); }

/* ------------------------------------------------------------- sheet */

.sheet {
  border: 0;
  padding: 0;
  margin-block: 0;
  margin-inline: auto 0; /* hugs the end edge: right in LTR, left in RTL */
  height: 100dvh;
  max-height: 100dvh;
  /* --sheet-w is set by map.js from the stored width; the clamp there keeps it sane. */
  width: min(var(--sheet-w, 480px), calc(100% - 48px));
  max-width: 100%; /* % of the viewport minus scrollbar; 100vw would overflow by its width */
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: var(--backdrop); }

/* Drag handle on the sheet's inner edge (left in LTR, right in RTL; desktop only). */
.sheet-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  inset-inline-start: 0;
  width: 14px;
  cursor: ew-resize;
  touch-action: none;
  z-index: 2;
  /* the sheet's coloured edge stripe lives here, so all of it is grabbable */
  background: linear-gradient(to right, var(--stroke) 0 4px, transparent 4px);
}
[dir='rtl'] .sheet-resize { background: linear-gradient(to left, var(--stroke) 0 4px, transparent 4px);
}
.sheet-resize::after {
  content: '';
  position: absolute;
  inset-inline-start: 7px;
  top: 50%;
  width: 4px;
  height: 48px;
  margin-top: -24px;
  border-radius: 2px;
  background: var(--stroke);
  opacity: 0;
  transition: opacity 0.15s;
}
.sheet-resize:hover::after, .sheet-resize:focus-visible::after, .resizing-sheet .sheet-resize::after { opacity: 0.9; }
.sheet-resize:focus-visible { outline: none; }
.resizing-sheet, .resizing-sheet * { cursor: ew-resize !important; user-select: none !important; }
.sheet[open] { animation: slide-in 0.18s ease-out; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
[dir='rtl'] .sheet[open] { animation-name: slide-in-rtl; }
@keyframes slide-in-rtl { from { transform: translateX(-24px); opacity: 0; } }

@media (max-width: 640px) {
  .sheet {
    margin: auto 0 0;
    width: 100%;
    height: 88dvh;
    max-height: 88dvh;
    border-left: 0;
    border-top: 4px solid var(--stroke);
    border-radius: 16px 16px 0 0;
  }
  .sheet-resize { display: none; }
  @keyframes slide-in { from { transform: translateY(24px); opacity: 0; } }
  [dir='rtl'] .sheet[open] { animation-name: slide-in; }
}
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } * { transition: none !important; } }

.sheet[open] { display: flex; flex-direction: column; }
.sheet-inner { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 20px 24px 32px; overscroll-behavior: contain; }

/* Pinned footer: parents and children, always one tap away. */
.sheet-nav {
  flex: none;
  display: grid;
  gap: 8px;
  max-height: 40%;
  overflow-y: auto;
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -8px 16px -14px rgb(0 0 0 / 0.5);
}
.nav-row { display: flex; align-items: baseline; gap: 10px; }
.nav-label { flex: none; min-width: 92px; max-width: 11em; font: 600 12px/1.4 var(--sans); letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); }
.nav-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.nav-empty { font: italic 14px/1.4 var(--sans); color: var(--faint); }
.sheet-nav .rel-btn { font-size: 13px; padding: 2px 10px; }
.rel-dir { color: var(--faint); font: 600 14px var(--sans); width: 1em; flex: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chip {
  font: 500 12px/1 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--title);
  border: 1px solid var(--stroke);
}
.close { border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.close:hover { color: var(--ink); background: var(--bg); }
.sheet h2 { font-size: 28px; margin: 16px 0 4px; }
.sheet-sub { margin: 0 0 16px; color: var(--muted); font: 15px/1.5 var(--sans); }
.sheet h3 { font: 600 13px/1.4 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin: 24px 0 8px; }
.prose p { margin: 0 0 12px; }
.ideas { padding-inline-start: 1.2em; margin: 0; }
.ideas li { margin: 6px 0; }
.check { margin-top: 24px; padding: 4px 16px 12px; border-radius: 10px; background: var(--fill); color: var(--title); }
.check h3 { color: var(--sub); margin-top: 12px; }
.check p { margin: 0; }
.rel { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.rel li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.rel-btn {
  border: 1px solid var(--stroke);
  background: var(--fill);
  color: var(--title);
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
  font: 500 14px var(--sans);
}
.rel-note { font: 14px/1.4 var(--sans); color: var(--muted); }
.refs { padding-inline-start: 1.2em; margin: 0; font: 15px/1.5 var(--sans); }
.refs li { margin: 4px 0; }
.page { color: var(--faint); }

var { font-style: italic; }

/* Figures inside the detail sheet. Inline SVG styled by class so they follow the
   theme and the node's colour ramp. */
.fig { margin: 20px 0; padding: 12px 12px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.fig-art svg { display: block; width: 100%; height: auto; overflow: visible; }
.fig figcaption { margin-top: 8px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.fig text { fill: var(--ink); font: 14px var(--sans); }
.fig .t-vec { fill: var(--title); }
.fig .t-muted { fill: var(--muted); font-size: 12px; }
.fig .axis { stroke: var(--ink); stroke-width: 1.25; fill: none; }
.fig .fibre { stroke: var(--stroke); stroke-width: 1.25; opacity: 0.7; }
.fig .fibre-faint { stroke: var(--edge); stroke-width: 1; stroke-dasharray: 3 4; opacity: 0.6; }
.fig .vec { stroke: var(--stroke); stroke-width: 3; stroke-linecap: round; }
.fig marker path { fill: var(--stroke); }
.fig .pt { fill: var(--ink); }
.fig .t-big { font-size: 20px; font-weight: 600; }
.fig .t-huge { font-size: 30px; font-weight: 700; }
.fig .t-set { font-size: 22px; font-weight: 700; fill: var(--title); }
/* Shapes take the chapter's ramp; blank cells the page surface. */
.fig .set { fill: var(--fill); fill-opacity: 0.45; stroke: var(--stroke); stroke-width: 1.5; }
.fig .shape { fill: var(--fill); stroke: var(--stroke); stroke-width: 1.5; }
.fig .shape-2 { fill: var(--stroke); fill-opacity: 0.55; stroke: var(--stroke); stroke-width: 1.5; }
.fig .blank { fill: var(--surface); stroke: var(--edge); stroke-width: 1.25; }
.fig .merc { fill: var(--stroke); }
.fig .line { stroke: var(--ink); stroke-width: 1.5; fill: none; stroke-linecap: round; }
.fig .accent { stroke: var(--stroke); stroke-width: 2.5; fill: none; stroke-linecap: round; }
.fig .dash { stroke: var(--muted); stroke-width: 1.25; stroke-dasharray: 4 4; fill: none; }
.fig .grid { stroke: var(--line); stroke-width: 1; fill: none; }

/* KaTeX. Slightly smaller than its 1.21em default so it sits with the sans text.
   Wide display maths scrolls inside its own line instead of widening the page. */
.katex { font-size: 1.1em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; margin: 0.8em 0; }
.katex-display > .katex { white-space: nowrap; }

/* ------------------------------------------------------------- practice */

.ptoc { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 8px; }
.ptoc .rel-btn, .ppart-concepts .rel-btn { text-decoration: none; display: inline-block; }
.ppart { margin-top: 40px; scroll-margin-top: 16px; }
.ppart-head { padding-bottom: 8px; border-bottom: 3px solid var(--stroke); }
.ppart-head h2 { font-size: 28px; margin: 0 0 6px; }
.ppart-intro { margin: 0 0 12px; color: var(--muted); }
.ppart-concepts { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 10px; margin: 0 0 8px; }

.pblock { margin-top: 28px; }
.pblock-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.pblock-head h3 { font-size: 20px; margin: 0; }
.pblock-sub { margin: 2px 0 0; font-size: 14px; color: var(--faint); }
.reveal-all {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 12px;
  font: 500 13px var(--sans);
  cursor: pointer;
}
.reveal-all:hover { color: var(--ink); border-color: var(--muted); }

.pq-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.pq { background: var(--surface); border: 1px solid var(--line); border-inline-start: 4px solid var(--stroke); border-radius: 10px; padding: 14px 16px; }
.pq-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.pq-num { font: 700 13px var(--sans); color: var(--sub); letter-spacing: 0.04em; }
.pq-head .rel-btn { font-size: 12px; padding: 1px 9px; text-decoration: none; }
.pq-text { max-width: 760px; }
.pq-text p, .answer p { margin: 0 0 10px; }
.pq-text p:last-child, .answer p:last-child { margin-bottom: 0; }

.reveal { margin-top: 10px; }
.reveal > summary {
  display: inline-flex;
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--fill);
  color: var(--title);
  font: 500 13px var(--sans);
}
.reveal > summary::-webkit-details-marker { display: none; }
.reveal .when-open, .reveal[open] .when-closed { display: none; }
.reveal[open] .when-open { display: inline; }
.answer {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px dashed var(--line);
  max-width: 760px;
}

/* Practice link inside a concept's detail panel */
.practice-link { display: inline-block; margin-top: 20px; font: 500 14px var(--sans); }
.practice-cta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin: 16px 0 0; font: 14px/1.5 var(--sans); color: var(--muted); }
.practice-cta .rel-btn { text-decoration: none; font-size: 14px; padding: 4px 14px; }
/* Grid items default to min-width:auto and would grow to fit a wide equation,
   stretching the whole card; pin them so wide maths scrolls in its own line. */
.pq-list { grid-template-columns: minmax(0, 1fr); }
.pq, .answer, .pq-text { min-width: 0; }
@media (max-width: 520px) {
  .pq { padding: 12px 12px; }
  .answer { padding: 10px 10px; }
}

/* Step-by-step explanation: the potato beside an answer opens it underneath. */
.answer-row { display: flex; align-items: flex-start; gap: 10px; }
.answer-text { flex: 1; min-width: 0; }
.potato {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--stroke, var(--line));
  background: var(--fill, var(--bg));
  color: var(--title, var(--text));
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s, transform 0.15s;
}
.potato svg { width: 24px; height: 24px; }
.potato:hover, .potato:focus-visible { opacity: 1; }
.potato:hover svg { transform: rotate(-8deg); }
.potato[aria-expanded="true"] { opacity: 1; box-shadow: inset 0 0 0 1px var(--stroke, var(--line)); }
.explain {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--stroke, var(--line));
  background: var(--bg);
  min-width: 0;
}
.explain[hidden] { display: none; }
.explain h4 { margin: 16px 0 6px; font: 600 14px/1.4 var(--sans); }
.explain h4:first-of-type { margin-top: 12px; }
.explain p { margin: 0 0 10px; }
.explain p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------- key terms (ᛗ) */

.term-defined { font-style: italic; font-weight: 600; }
.rune {
  /* Sits ON the text baseline: an inline-block with overflow other than visible
     takes its bottom edge as its baseline, so vertical-align: baseline puts the
     icon's bottom exactly level with the text's. The glyph is centred inside. */
  display: inline-block;
  position: relative;
  overflow: hidden;
  vertical-align: baseline;
  line-height: 0;
  /* Lowercase-sized: 1ex is the font's x-height, so the icon matches the
     lowercase letters of whatever font/size it sits in (a touch taller so the
     glyph stays legible). */
  width: 1.15ex;
  height: 1.15ex;
  margin-inline-start: 0.22em;
  padding: 0;
  border-radius: 3px;
  /* Border as an inset shadow: Chrome puts a button's baseline at its CONTENT
     bottom, so a real 1px border would make the icon hang 1px below the text. */
  border: 0;
  box-shadow: inset 0 0 0 1px var(--stroke, var(--line));
  background: var(--fill, var(--bg));
  color: var(--sub, var(--muted));
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s;
}
.rune svg { position: absolute; inset: 0; margin: auto; width: 82%; height: 82%; }
.rune:hover, .rune:focus-visible { opacity: 1; }

.term-pop {
  position: fixed;
  inset: auto;
  margin: 0;
  width: max-content;
  max-width: min(320px, calc(100vw - 16px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font: 14px/1.5 var(--sans);
}
.tp-head { display: flex; align-items: center; gap: 8px; }
.tp-rune { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.tp-rune svg { width: 15px; height: 15px; }
.tp-term { font-size: 17px; }
.tp-def { margin: 8px 0 6px; color: var(--muted); }
.tp-link { border: 0; background: none; padding: 0; font: inherit; color: var(--link); cursor: pointer; text-decoration: underline; text-underline-offset: 0.15em; }
.tp-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.tp-langs { list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: grid; gap: 3px; }
.tp-langs li { display: grid; grid-template-columns: minmax(2.5em, 40%) 1fr; gap: 10px; align-items: baseline; }
.tp-lang { color: var(--faint); font: 600 11px/1.5 var(--mono); letter-spacing: 0.02em; }
.tp-lang abbr { text-decoration: none; cursor: help; }
.tp-name { overflow-wrap: anywhere; }
.tp-reading { display: block; font-size: 12px; color: var(--faint); }
.tp-current .tp-name { font-weight: 600; }

/* ------------------------------------------------------------- languages */

/* Formulas read left to right in every language, including Arabic, Hebrew, Persian. */
.katex, .katex-display { direction: ltr; unicode-bidi: isolate; }
/* Box labels in the (unmirrored) SVG map: each string picks its own direction. */
.map-svg text { unicode-bidi: plaintext; }

.lang-switch { position: relative; font: 500 13px var(--sans); }
.lang-switch > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 999px;
  height: 32px;
  min-width: 40px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
}
.lang-switch > summary::-webkit-details-marker { display: none; }
.lang-switch > summary:hover { color: var(--ink); border-color: var(--muted); }
.lang-switch ul {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  z-index: 20;
  list-style: none;
  margin: 0;
  padding: 6px;
  min-width: 170px;
  max-height: min(70vh, 460px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.lang-switch li a { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.lang-switch li a:hover { background: var(--bg); }
.lang-switch li a[aria-current='true'] { font-weight: 600; background: var(--bg); }

/* Flags beside language names. Drawn at 3:2 whatever the flag's own proportions;
   `cover` crops rather than stretches, so the Sámi and Greenland circles stay round. */
.flag { flex: none; width: 18px; height: 12px; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px var(--line); }

/* Scripts that the Latin system stack may not cover well. */
:lang(ar), :lang(fa) { --sans: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Arabic', Tahoma, sans-serif; }
:lang(he) { --sans: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Hebrew', Arial, sans-serif; }
:lang(zh-Hans) { --sans: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif; }
:lang(ja) { --sans: system-ui, -apple-system, 'Hiragino Sans', 'Yu Gothic UI', 'Noto Sans JP', sans-serif; }

/* Answer footer: back to the concept page and the original texts. */
.backlinks { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); display: grid; gap: 6px; font: 14px/1.5 var(--sans); }
.bl-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; }
.bl-row .refs { margin: 0; padding-inline-start: 1.1em; font-size: 14px; }
.backlinks .rel-btn { font-size: 12px; padding: 1px 9px; text-decoration: none; }

/* Objects inside formulas that link to the glossary (ℝⁿ, Sⁿ, GL(n,ℝ), TM, …). */
.katex-html [data-term] { cursor: pointer; border-bottom: 1px dotted var(--stroke, var(--muted)); border-radius: 1px; }
.katex-html [data-term]:hover { background: var(--fill, var(--bg)); }
.katex-html [data-term]:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.tp-type { margin-inline-start: auto; font: 500 11px/1 var(--sans); letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; white-space: nowrap; }
.site-foot .credits { margin-top: 6px; font-size: 12px; color: var(--faint); }
.site-foot .credits a { color: inherit; }

/* ------------------------------------------------------------- glossary term pages */

.term-page { max-width: 760px; padding-top: 24px; }
.term-page h1 { display: flex; align-items: center; gap: 12px; font-size: clamp(28px, 5vw, 40px); margin: 0 0 8px; }
.term-page h1 .tp-rune { width: 32px; height: 32px; border-radius: 8px; }
.term-page h1 .tp-rune svg { width: 20px; height: 20px; }
.term-meta { margin: 0 0 20px; }
.term-meta .tp-type { margin: 0; }
.term-definition ul { padding-inline-start: 1.2em; }
.term-definition li { margin: 8px 0; }
.term-back { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin: 24px 0; font: 15px var(--sans); color: var(--muted); }
.term-back .rel-btn { text-decoration: none; font-size: 15px; padding: 4px 14px; }
.term-refs h2, .term-langs h2 { font: 600 13px/1.4 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin: 28px 0 8px; }
.term-langs .tp-langs { border-top: 0; padding-top: 0; max-width: 460px; }
.tp-full { margin: 4px 0 8px; }

/* Visually hidden, still read by screen readers. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Multiple choice (practice): options are checked on the spot. */
:root { --right: #1d7a3a; --right-bg: #e6f4ea; --wrong: #b3261e; --wrong-bg: #fbe9e7; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { --right: #7fd49a; --right-bg: #173a24; --wrong: #f2a49c; --wrong-bg: #4a1c18; }
}
:root[data-theme='dark'] { --right: #7fd49a; --right-bg: #173a24; --wrong: #f2a49c; --wrong-bg: #4a1c18; }

.mc { border: 0; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; max-width: 760px; }
.mc-opt {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); cursor: pointer;
}
.mc-opt:hover { border-color: var(--muted); }
.mc-opt:has(input:focus-visible) { outline: 2px solid var(--link); outline-offset: 2px; }
.mc-opt input { position: absolute; opacity: 0; pointer-events: none; }
.mc-letter { font: 700 13px var(--sans); color: var(--sub, var(--muted)); min-width: 1.2em; }
.mc-text { min-width: 0; }
.mc-opt[data-state='right'], .mc-opt[data-state='answer'] { border-color: var(--right); background: var(--right-bg); }
.mc-opt[data-state='wrong'] { border-color: var(--wrong); background: var(--wrong-bg); }
.mc-opt[data-state='right'] .mc-letter, .mc-opt[data-state='answer'] .mc-letter { color: var(--right); }
.mc-opt[data-state='wrong'] .mc-letter { color: var(--wrong); }
.mc-opt[data-state]::after { margin-inline-start: auto; font-weight: 700; }
.mc-opt[data-state='right']::after, .mc-opt[data-state='answer']::after { content: '✓'; color: var(--right); }
.mc-opt[data-state='wrong']::after { content: '✗'; color: var(--wrong); }
.mc input:disabled + .mc-letter { cursor: default; }
.mc:has(input:disabled) .mc-opt { cursor: default; }
.mc-verdict { margin: 8px 0 0; font: 600 14px var(--sans); min-height: 1em; }
.mc-verdict:empty { display: none; }
.mc-verdict[data-state='right'] { color: var(--right); }
.mc-verdict[data-state='wrong'] { color: var(--wrong); }

/* Curriculum note: which country's "year 7" this is. */
.curriculum-note { max-width: 760px; margin: 16px 0; padding: 10px 14px; border-inline-start: 3px solid var(--link); background: var(--surface); border-radius: 6px; color: var(--muted); font-size: 14px; }

/* Glossary index */
.glossary-tools { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; }
.glossary-filter { font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); min-width: min(320px, 100%); }
.glossary-count { color: var(--faint); font-size: 13px; }
.gl-type h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); }
.gl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.gl-item a { text-decoration: none; }
