/* ============================================================
   psych — IB Psychology revision
   One typeface (Onest), one accent (purple), flat surfaces.

   Interaction follows Apple's fluid-interface principles
   (see .claude/skills/apple-design): feedback on press, springs
   for anything you can touch, translucent floating chrome,
   size-specific type, and gentle fallbacks for reduced motion,
   reduced transparency and higher contrast.
   ============================================================ */

:root {
  /* colour — purple, black, white, restrained neutrals */
  --ink:        #17151c;
  --ink-2:      #453f50;
  --muted:      #6d6779;
  --faint:      #757086;
  --line:       #eae7ef;
  --line-2:     #f2f0f6;
  --line-3:     #ddd8e6;
  --canvas:     #fbfafc;
  --surface:    #ffffff;
  --violet:     #5b2e9d;
  --violet-2:   #47237b;
  --violet-soft:#f1eafa;

  /* materials — translucent layers that float over content.
     Thicker (more opaque, more blur, deeper shadow) as surfaces grow. */
  --mat-rgb:         251, 250, 252;   /* canvas */
  --mat-surface-rgb: 255, 255, 255;   /* surface */
  --mat-edge:        rgba(255, 255, 255, .7);   /* light catching the top edge */
  --shadow-rgb:      23, 21, 28;
  --scrim:           rgba(23, 21, 28, .32);

  /* Onest is the brand face, a deliberate override of the system font. */
  --sans: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* type: tracking is size-specific, never one value for all sizes */
  --track-display: -.028em;   /* large titles: tighten */
  --track-title:   -.014em;   /* card titles, section heads */
  --track-body:    0;         /* body copy: leave alone */
  --track-small:   .012em;    /* captions and meta: open up slightly */
  --track-caps:    .09em;     /* small uppercase labels */

  --r-sm: .5rem;
  --r-md: .625rem;
  --r-lg: .75rem;
  --r-xl: 1rem;
  --maxw: 70rem;
  --gutter: clamp(1.25rem, 5vw, 2.5rem);

  /* easing — the closing curve mirrors the opening one, so a reversible
     transition leaves along the same path it arrived on */
  --ease:     cubic-bezier(.22, .61, .36, 1);   /* out: open / arrive */
  --ease-in:  cubic-bezier(.64, 0, .78, .39);   /* its mirror: close / leave */
  --press:    100ms;
  --fast:     130ms;
  --base:     200ms;
}

html { color-scheme: light; }

/* The theme is expressed entirely through the shared colour tokens, so every
   page and component inherits it without needing page-specific overrides. */
html[data-theme="dark"] {
  color-scheme: dark;
  --ink:         #f3eff8;
  --ink-2:       #d4cddd;
  --muted:       #afa6bb;
  --faint:       #9a91a6;
  --line:        #37303f;
  --line-2:      #28222f;
  --line-3:      #4b4154;
  --canvas:      #16121a;
  --surface:     #201b25;
  --violet:      #c9a8ff;
  --violet-2:    #b58af7;
  --violet-soft: #35264b;

  --mat-rgb:         22, 18, 26;
  --mat-surface-rgb: 32, 27, 37;
  --mat-edge:        rgba(255, 255, 255, .08);
  --shadow-rgb:      0, 0, 0;
  --scrim:           rgba(0, 0, 0, .5);
}

/* Switching theme eases the brightness change rather than flashing.
   The class is only present for the length of the switch. */
html.theme-changing,
html.theme-changing *,
html.theme-changing *::before,
html.theme-changing *::after {
  transition: background-color 320ms var(--ease), border-color 320ms var(--ease),
              color 320ms var(--ease), fill 320ms var(--ease) !important;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: 100%; }  /* respect the reader's text size */
body {
  margin: 0;
  min-height: 100vh; display: flex; flex-direction: column;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  letter-spacing: var(--track-body);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;  /* we draw our own, instant, press state */
}
img { max-width: 100%; display: block; }
button, input { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: inherit; }

/* No 300ms double-tap wait on anything you can press: nothing here uses double-tap. */
a, button, input, label, summary, [role="button"] { touch-action: manipulation; }

:focus-visible { outline: 2px solid var(--violet); outline-offset: 3px; border-radius: 5px; }
.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;
}
.skip-link {
  position: absolute; left: 50%; transform: translateX(-50%) translateY(-200%);
  top: 10px; z-index: 100; background: var(--ink); color: var(--canvas);
  padding: .56rem 1rem; border-radius: 999px; text-decoration: none; font-size: .875rem;
}
.skip-link:focus { transform: translateX(-50%) translateY(0); }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.wrap-narrow { max-width: 47.5rem; }

/* ---------- navigation: a translucent layer content scrolls under ---------- */
.nav {
  position: sticky; top: 0; z-index: 40;
  background: rgba(var(--mat-rgb), .82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transform: translateZ(0);          /* its own layer: scrolling content never repaints it */
}
/* Scroll-edge effect instead of a hard divider: a soft fade appears only once
   content actually passes underneath the bar. */
.nav::after {
  content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 14px;
  background: linear-gradient(to bottom, rgba(var(--mat-rgb), .75), rgba(var(--mat-rgb), 0));
  pointer-events: none; opacity: 0;
  transition: opacity var(--base) var(--ease);
}
.nav.is-scrolled::after { opacity: 1; }

.nav-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 3.875rem;
}
.brand {
  font-size: 1.22rem; font-weight: 700; letter-spacing: -.02em;
  color: var(--violet); text-decoration: none;
}
.nav-toggle { display: none; }
.nav-links { display: flex; align-items: center; gap: 2px; }
/* Text over a translucent material: higher contrast, a touch more tracking. */
.nav-links a {
  text-decoration: none; font-size: .9rem; font-weight: 500; color: var(--ink-2);
  letter-spacing: .005em;
  padding: .44rem .7rem; border-radius: 999px;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease),
              transform var(--fast) var(--ease);
}
.nav-links a:hover { color: var(--ink); background: rgba(var(--shadow-rgb), .05); }
html[data-theme="dark"] .nav-links a:hover { background: rgba(255, 255, 255, .07); }
.nav-links a:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.nav-links a[aria-current="page"] { color: var(--violet); background: var(--violet-soft); }
/* Desktop: the current-page pill is one element that slides between links. */
@media (min-width: 681px) {
  .nav-links.has-ind { position: relative; }
  .nav-links.has-ind a { position: relative; z-index: 1; }
  .nav-links.has-ind a[aria-current="page"] { background: transparent; }
  .nav-links.has-ind a[aria-current="page"]:hover { background: transparent; }
}
.nav-ind {
  position: absolute; left: 0; top: 0; width: 0; border-radius: 999px;
  background: var(--violet-soft); pointer-events: none; z-index: 0;
  opacity: 0; will-change: transform, width;
}
.nav-ind.is-ready { opacity: 1; }
.nav-short { display: none; }
.violet-text { color: var(--violet); }

/* ---------- headings: tight leading and negative tracking as type grows ---------- */
h1.page-title {
  font-size: clamp(1.75rem, 4.2vw, 2.3rem);
  font-weight: 600; line-height: 1.1; letter-spacing: var(--track-display);
  margin: 0;
}
.page-head { padding-block: clamp(2.5rem, 7vh, 4.25rem) clamp(1.25rem, 3vh, 1.75rem); }
.page-note {
  margin: .7rem 0 0; color: var(--muted); font-size: .95rem; line-height: 1.6; max-width: 60ch;
}

/* ---------- about ---------- */
.about { padding-block: clamp(4rem, 11vh, 7.5rem) clamp(3.5rem, 9vh, 6.5rem); }
.about p {
  font-size: clamp(1.02rem, 1.7vw, 1.14rem); line-height: 1.65;
  color: var(--ink-2); max-width: 56ch; margin: 1.35rem 0 0;
}
.about .page-title + p { margin-top: 1.8rem; }
.about-actions { display: flex; flex-wrap: wrap; gap: .625rem; margin-top: 2.6rem; }
.credit {
  margin: clamp(3.25rem, 8vh, 5.25rem) 0 0; padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: .855rem; color: var(--muted); letter-spacing: var(--track-small);
}
.credit a { color: var(--violet); text-decoration: none; }
.credit a:hover { text-decoration: underline; }

/* ---------- buttons: feedback lives on the press, and it's instant ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .69rem 1.19rem; border-radius: var(--r-md);
  font-weight: 500; font-size: .94rem; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line-3); background: var(--surface); color: var(--ink);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:hover { background: var(--line-2); }
.btn:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.btn-primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn-primary:hover { background: var(--violet-2); border-color: var(--violet-2); }
html[data-theme="dark"] .btn-primary { color: #17151c; }

.text-btn {
  border: 0; background: none; color: var(--violet); font-size: .855rem; font-weight: 500;
  cursor: pointer; padding: .32rem .44rem; border-radius: 6px;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.text-btn:hover { background: var(--violet-soft); }
.text-btn:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.text-btn[hidden] { display: none; }

/* ---------- controls: search + one filter ---------- */
.controls {
  padding-bottom: .875rem;
}
.controls::after {
  content: ""; display: block; height: 1px; background: var(--line);
  margin-top: .875rem;
}
.search-field { position: relative; }
.search-field > svg {
  position: absolute; left: .875rem; top: 50%; transform: translateY(-50%);
  color: var(--faint); pointer-events: none;
}
.search-field input {
  width: 100%; padding: .75rem 2.625rem;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); font-size: .96rem;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.search-field input::placeholder { color: var(--faint); }
/* Only our own clear button: hide the browser's built-in one (it doubled up on phones). */
.search-field input::-webkit-search-cancel-button,
.search-field input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search-field input:focus {
  outline: none; border-color: var(--violet);
  box-shadow: 0 0 0 3px var(--violet-soft);
}
.search-clear {
  position: absolute; right: .44rem; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: .44rem; border-radius: 999px; line-height: 0;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.search-clear:hover { background: var(--line-2); }
.search-clear:active { transform: translateY(-50%) scale(.9); transition: transform var(--press) ease-out; }
.search-clear[hidden] { display: none; }

.control-row {
  display: flex; align-items: center; gap: .625rem; flex-wrap: wrap;
  margin-top: .75rem; min-height: 2.25rem;
}
.filter-wrap { position: relative; flex-shrink: 0; }
.filter-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .5rem .81rem; border-radius: var(--r-md);
  border: 1px solid var(--line-3); background: var(--surface);
  font-size: .89rem; font-weight: 500; cursor: pointer; color: var(--ink);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease);
}
.filter-btn:hover { background: var(--line-2); }
.filter-btn:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.filter-btn[aria-expanded="true"] { border-color: var(--violet); }
.filter-btn .caret { transition: transform var(--base) var(--ease-in); color: var(--faint); }
.filter-btn[aria-expanded="true"] .caret { transform: rotate(180deg); transition-timing-function: var(--ease); }
.filter-count {
  min-width: 1.125rem; height: 1.125rem; padding: 0 .32rem; border-radius: 999px;
  background: var(--violet); color: #fff; font-size: .7rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums; letter-spacing: var(--track-small);
}
html[data-theme="dark"] .filter-count { color: #17151c; }
.filter-count[hidden] { display: none; }

.active-filters {
  margin: 0; font-size: .855rem; color: var(--muted); min-width: 0;
  letter-spacing: var(--track-small);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.active-filters[hidden] { display: none; }
.result-count {
  margin: 0 0 0 auto; color: var(--faint); font-size: .83rem;
  letter-spacing: var(--track-small);
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}

/* ---------- filter popover (desktop) ----------
   A light material that floats beside the content without a scrim, so the
   list stays readable while you filter. It grows out of the Filter button:
   transform-origin is set to the trigger from script. Motion is a spring
   driven from app.js, so it can be reversed at any instant. */
.filter-panel {
  position: fixed; top: 0; left: 0; z-index: 60;
  width: 18rem; max-width: calc(100vw - 2 * var(--gutter));
  max-height: min(72vh, 32.5rem); overflow-y: auto; overscroll-behavior: contain;
  background: rgba(var(--mat-surface-rgb), .93);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--line-3);
  border-radius: var(--r-xl); padding: .375rem;
  box-shadow: inset 0 1px 0 var(--mat-edge),
              0 18px 40px -22px rgba(var(--shadow-rgb), .5),
              0 2px 8px -4px rgba(var(--shadow-rgb), .12);
}
.filter-panel[hidden] { display: none; }

.sheet-grabber, .sheet-scrim { display: none; }

.fgroup { padding: .5rem .375rem .375rem; }
.fgroup + .fgroup { border-top: 1px solid var(--line-2); }
.fgroup-title {
  margin: 0 0 .25rem; padding-inline: .5rem;
  font-size: .715rem; font-weight: 600; letter-spacing: var(--track-caps); text-transform: uppercase;
  color: var(--muted);
}
.fopt {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  padding: .5rem .56rem; border: 0; border-radius: var(--r-sm);
  background: none; text-align: left; cursor: pointer;
  font-size: .9rem; color: var(--ink-2);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.fopt:hover:not(:disabled) { background: rgba(var(--shadow-rgb), .05); }
html[data-theme="dark"] .fopt:hover:not(:disabled) { background: rgba(255, 255, 255, .07); }
.fopt:active:not(:disabled) { background: var(--violet-soft); transition-duration: 0ms; }
.fopt[aria-pressed="true"] { color: var(--violet); font-weight: 500; }
.fopt:disabled { opacity: .38; cursor: default; }
.fopt .tick { width: 14px; flex-shrink: 0; color: var(--violet); opacity: 0; }
.fopt[aria-pressed="true"] .tick { opacity: 1; }
.fopt .label { flex: 1; min-width: 0; }
.fopt .count {
  color: var(--faint); font-size: .78rem; font-variant-numeric: tabular-nums;
  font-weight: 400; letter-spacing: var(--track-small);
}
.fpanel-foot {
  border-top: 1px solid var(--line-2); padding: .375rem .5rem .25rem; margin-top: 2px;
}

/* ---------- cards ---------- */
.list { display: flex; flex-direction: column; gap: .5rem; padding-top: 1.375rem; padding-bottom: 5rem; }
.list:empty { min-height: 85vh; }
.item[hidden] { display: none; }
.item { scroll-margin-top: 5rem; }
.list > .item { content-visibility: auto; contain-intrinsic-size: auto 5.5rem; }
html.is-scrolling main { pointer-events: none; }
.item { scroll-margin-top: 5rem; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  transition: background var(--base) var(--ease), border-color var(--base) var(--ease);
  contain: layout style;
}
.item:hover { background: var(--line-2); border-color: var(--line-3); }
/* pressed: the card answers on touch-down, not on release */
.item:has(> .item-head:active) { background: var(--line-2); border-color: var(--line-3); transition-duration: 0ms; }
.item.open { background: var(--surface); border-color: var(--line-3); }

.item-head {
  width: 100%; display: flex; align-items: flex-start; gap: 1.125rem; text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 1.25rem 1.375rem; border-radius: var(--r-lg); font-family: inherit;
}
.item-head:focus-visible { outline-offset: -3px; }
.item-main { flex: 1; min-width: 0; }

/* notes: the concept name dominates — weight, size and leading as a set */
.item-title {
  display: block; font-size: 1.04rem; font-weight: 600; line-height: 1.35;
  letter-spacing: var(--track-title); color: var(--ink); max-width: 62ch;
}
.item-sub {
  display: block; margin-top: 3px; font-size: .875rem; color: var(--muted);
  max-width: 62ch;
}

/* questions: the question dominates */
.item-q {
  display: block; margin: 0; font-size: 1rem; font-weight: 500; line-height: 1.52;
  letter-spacing: -.004em; color: var(--ink); max-width: 70ch;
}

/* one quiet line of supporting information — not a row of pills */
.item-meta {
  display: block; margin-top: .625rem; font-size: .79rem; color: var(--faint);
  line-height: 1.5; letter-spacing: var(--track-small);
}
.item-meta .sep { padding: 0 .42em; opacity: .6; }
.item-meta .marks { color: var(--ink-2); font-weight: 500; }

/* The chevron points where the card is going; closing mirrors the opening curve. */
.chevron {
  flex-shrink: 0; color: var(--faint); margin-top: 4px;
  transition: transform var(--base) var(--ease-in), color var(--fast) var(--ease);
}
.item.open .chevron { transform: rotate(180deg); color: var(--ink-2); transition-timing-function: var(--ease); }
.item-head:hover .chevron { color: var(--ink-2); }

/* expand / collapse — open eases out, close eases in along the mirrored curve.
   CSS transitions re-target from the current value, so a second tap
   mid-flight reverses straight away instead of waiting for the first to end. */
.item-body {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows var(--base) var(--ease-in);
}
.item.open .item-body { grid-template-rows: 1fr; transition-timing-function: var(--ease); }
.item-body > .inner {
  overflow: hidden; opacity: 0; transform: translateY(-4px);
  transition: opacity var(--fast) var(--ease-in), transform var(--base) var(--ease-in);
}
.item.open .item-body > .inner {
  opacity: 1; transform: none;
  transition: opacity var(--base) var(--ease) 40ms, transform var(--base) var(--ease);
}
.body-pad { margin: 0 1.375rem; padding: .25rem 0 1.5rem; border-top: 1px solid var(--line-2); }

.field { margin-top: 1.25rem; }
.field-label {
  font-size: .715rem; font-weight: 700; letter-spacing: var(--track-caps); text-transform: uppercase;
  color: var(--ink-2); margin-bottom: .4rem; line-height: 1.4;
}
.field p { margin: 0; color: var(--ink-2); line-height: 1.68; max-width: 68ch; }
.field ul { margin: 0; padding-left: 1.05rem; color: var(--ink-2); line-height: 1.66; max-width: 68ch; }
.field ul li { margin-bottom: .32rem; }
.field ul li::marker { color: var(--line-3); }

/* metadata a student only needs once the card is open */
.body-meta { margin: 1.25rem 0 0; }

/* ---------- concepts page ---------- */
/* Two views, chosen with quiet underline tabs rather than boxed pills. */
.view-switch { display: flex; gap: 1.75rem; border-bottom: 1px solid var(--line); }
.view-switch [role="tab"] {
  position: relative; border: 0; background: none; cursor: pointer;
  padding: .625rem 0 .75rem; font-size: .95rem; font-weight: 500; color: var(--muted);
  letter-spacing: var(--track-title);
  transition: color var(--fast) var(--ease);
}
.view-switch [role="tab"]:hover { color: var(--ink); }
.view-switch [role="tab"][aria-selected="true"] { color: var(--ink); }
.view-switch { position: relative; }
.tab-ind {
  position: absolute; left: 0; top: 0; width: 0; height: 2px !important; margin-top: -1px;
  border-radius: 2px; background: var(--violet); pointer-events: none;
  opacity: 0; will-change: transform, width;
}
.tab-ind.is-ready { opacity: 1; }
.view[hidden] { display: none; }

/* context switch: same treatment as the current page in the nav */
.ctx-switch { position: relative; display: flex; flex-wrap: wrap; gap: 2px; margin-top: 1.5rem; }
.ctx-switch .seg-btn { position: relative; z-index: 1; }
.ctx-switch .seg-btn[aria-pressed="true"] { background: transparent; }
.seg-ind {
  position: absolute; left: 0; top: 0; width: 0; border-radius: 999px;
  background: var(--violet-soft); pointer-events: none; z-index: 0;
  opacity: 0; will-change: transform, width;
}
.seg-ind.is-ready { opacity: 1; }
.seg-btn, .chip {
  border: 0; background: none; cursor: pointer;
  padding: .44rem .78rem; border-radius: 999px;
  font-size: .89rem; font-weight: 500; color: var(--ink-2); white-space: nowrap;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.seg-btn:hover, .chip:hover { color: var(--ink); background: rgba(var(--shadow-rgb), .05); }
html[data-theme="dark"] .seg-btn:hover, html[data-theme="dark"] .chip:hover { background: rgba(255, 255, 255, .07); }
.seg-btn:active, .chip:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.seg-btn[aria-pressed="true"], .chip[aria-pressed="true"] { color: var(--violet); background: var(--violet-soft); }
.chip-n {
  margin-left: .38rem; font-size: .74rem; font-weight: 400; color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] .chip-n { color: inherit; opacity: .7; }
.concept-chips { position: relative; }
.concept-chips .chip { position: relative; z-index: 1; }
.concept-chips .chip[aria-pressed="true"] { background: transparent; }
.chip-ind {
  position: absolute; left: 0; top: 0; width: 0; border-radius: 999px;
  background: var(--violet-soft); pointer-events: none; z-index: 0;
  opacity: 0; will-change: transform, width;
}
.chip-ind.is-ready { opacity: 1; }

/* context switch on the left, the key on the right */
.grid-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem 2rem;
  flex-wrap: wrap; margin-top: 1.5rem;
}
.grid-bar .ctx-switch { margin-top: 0; }
.gkey-wrap { position: relative; flex-shrink: 0; }
.gkey-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .44rem .78rem .44rem .62rem; border-radius: 999px;
  border: 1px solid var(--line-3); background: var(--surface);
  font: inherit; font-size: .89rem; font-weight: 500; color: var(--ink-2); cursor: pointer;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease),
              border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.gkey-btn:hover { color: var(--ink); background: var(--line-2); }
.gkey-btn:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.gkey-btn[aria-expanded="true"] { color: var(--violet); border-color: var(--violet); background: var(--violet-soft); }
.gkey-btn .caret { color: var(--faint); transition: transform var(--base) var(--ease-in); }
.gkey-btn[aria-expanded="true"] .caret { color: currentColor; transform: rotate(180deg); transition-timing-function: var(--ease); }
/* a tiny version of the two swatches, so the button says what it holds */
.gkey-icon { display: inline-flex; flex-direction: column; gap: 2px; }
.gkey-icon i { display: block; width: 12px; height: 5px; border-radius: 1.5px; background: var(--violet-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--violet) 35%, transparent); }
.gkey-icon i + i { background: transparent; box-shadow: inset 0 0 0 1px var(--line-3); }

.gkey {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
  width: max-content; max-width: calc(100vw - 2 * var(--gutter));
  display: grid; gap: .5rem;
  padding: .75rem .9rem .7rem;
  background: rgba(var(--mat-surface-rgb), .96);
  border: 1px solid var(--line-3); border-radius: var(--r-xl);
  box-shadow: inset 0 1px 0 var(--mat-edge),
              0 18px 40px -22px rgba(var(--shadow-rgb), .5),
              0 2px 8px -4px rgba(var(--shadow-rgb), .12);
  font-size: .82rem; color: var(--ink-2); letter-spacing: var(--track-small);
  transform-origin: 100% 0;
}
.gkey[hidden] { display: none; }
.gkey-list { display: flex; flex-direction: column; gap: .45rem; margin: 0; padding: 0; list-style: none; }
.gkey-list li { display: inline-flex; align-items: center; gap: .45rem; white-space: nowrap; }
.gkey-swatch {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.5rem; height: 1rem; border-radius: 4px; flex-shrink: 0;
  font-size: .75rem; font-weight: 600; line-height: 1; color: var(--faint);
}
.gkey-swatch.is-written { background: var(--violet-soft); }
@supports (background: color-mix(in srgb, red 50%, blue)) {
  .gkey-swatch.is-written { background: color-mix(in srgb, var(--violet-soft) 72%, var(--surface)); }
}
.gkey-swatch.is-weak { background: transparent; }
.gkey-hint { margin: 0; padding-top: .5rem; border-top: 1px solid var(--line-2); font-size: .76rem; color: var(--faint); }
.on-touch { display: none; }
@media (hover: none) { .on-touch { display: inline; } .on-pointer { display: none; } }

/* the grid: a raised card so it reads as one object on the canvas.
   Written cells are tinted tiles; weaker links stay plain. */
.cgrid {
  --cg-cols: minmax(10rem, 13.5rem) repeat(6, minmax(0, 1fr));
  --tile: color-mix(in srgb, var(--violet-soft) 72%, var(--surface));
  margin: 1.25rem 0 5rem;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: 0 1rem .75rem;
  box-shadow: 0 1px 2px rgba(var(--shadow-rgb), .04), 0 14px 34px -26px rgba(var(--shadow-rgb), .35);
}
html[data-theme="dark"] .cgrid { --tile: color-mix(in srgb, var(--violet-soft) 70%, var(--surface)); }
.cg-head {
  display: grid; grid-template-columns: var(--cg-cols); gap: 0 .375rem;
  position: sticky; top: 3.875rem; z-index: 5;
  margin: 0 -1rem; padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
}
.cg-corner, .cg-col {
  padding: 1rem .55rem .8rem; font-size: .715rem; font-weight: 600;
  letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--muted);
}
.cg-corner { padding-left: 0; }
.cg-col.is-hl { color: var(--violet); }
.cg-group + .cg-group { margin-top: .5rem; }
.cg-group-title {
  margin: 1.25rem 0 .5rem; font-size: .715rem; font-weight: 700;
  letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--violet);
}
.cg-row {
  display: grid; grid-template-columns: var(--cg-cols); gap: .375rem;
  padding-block: .375rem; border-top: 1px solid var(--line-2);
}
.cg-group-title + .cg-row { border-top: 0; }
.cg-cells { display: contents; }
.cg-topic {
  margin: 0; padding: .7rem .75rem .7rem 0; align-self: center;
  font-size: .93rem; font-weight: 600; line-height: 1.35; letter-spacing: var(--track-title); color: var(--ink);
}
.cg-cell {
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  width: 100%; min-height: 3.5rem; text-align: left; cursor: pointer;
  border: 1px solid transparent; background: var(--tile); border-radius: var(--r-md);
  padding: .6rem .65rem; font-size: .82rem; font-weight: 500; line-height: 1.35; color: var(--ink);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease);
}
.cg-cell:hover { background: var(--violet-soft); border-color: color-mix(in srgb, var(--violet) 35%, transparent); }
.cg-cell:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.cg-cell:focus-visible { outline-offset: 2px; }
.cg-cell.is-empty { background: transparent; align-items: center; }
.cg-cell.is-empty:hover { background: var(--line-2); border-color: transparent; }
.cg-cell.is-hl { border-color: var(--violet); }
.cg-cname { display: none; }
.cg-hook .key-dot { display: none; }
.cg-none { color: var(--line-3); font-weight: 600; }
.cg-cell.is-empty:hover .cg-none { color: var(--faint); }

/* only paint what is on screen: keeps long lists smooth on phones */
.cg-group, .terms-group { content-visibility: auto; contain-intrinsic-size: auto 600px; }

/* angle detail: a modal card on desktop, a bottom sheet on phones */
/* The card: the dialog is only a full-screen stage; the scrim and the card
   inside it are what move, driven frame by frame by springs in app.js. */
.angle-dialog {
  position: fixed; inset: 0; width: 100%; height: 100%;
  max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: transparent; color: var(--ink); overflow: hidden;
}
.angle-dialog[open] { display: flex; align-items: center; justify-content: center; }
.angle-dialog::backdrop { background: transparent; }
.angle-scrim {
  position: absolute; inset: 0; background: rgba(23, 21, 28, .32); opacity: 0;
  will-change: opacity;
}
html[data-theme="dark"] .angle-scrim { background: rgba(0, 0, 0, .55); }
.angle-sheet {
  position: relative; z-index: 1;
  width: min(38rem, calc(100vw - 2 * var(--gutter)));
  max-height: min(86vh, 46rem); overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1.375rem 1.625rem 1.125rem;
  border: 1px solid var(--line-3); border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: 0 30px 70px -30px rgba(var(--shadow-rgb), .55), 0 2px 10px -4px rgba(var(--shadow-rgb), .12);
  opacity: 0; will-change: transform, opacity;
}
.angle-grabber { display: none; }
.angle-content { will-change: auto; }

/* While a card is open the page underneath is frozen, so scrolling can't
   chain into it, and the blurred bars behind the scrim stop re-blurring. */
html:has(.angle-dialog[open]) { overflow: hidden; }
html:has(.angle-dialog[open]) .nav,
html:has(.angle-dialog[open]) .cg-head,
html:has(.angle-dialog[open]) .theme-toggle {
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.angle-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.angle-eyebrow {
  margin: .3rem 0 0; font-size: .79rem; color: var(--muted); letter-spacing: var(--track-small); line-height: 1.45;
}
.angle-close {
  flex-shrink: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: .44rem; margin: -.2rem -.5rem 0 0; border-radius: 999px; line-height: 0;
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.angle-close:hover { background: var(--line-2); color: var(--ink); }
.angle-close:active { transform: scale(.9); transition: transform var(--press) ease-out; }
.angle-title:focus { outline: none; }
.angle-title {
  margin: .4rem 0 0; font-size: 1.32rem; font-weight: 600; line-height: 1.25;
  letter-spacing: var(--track-title); color: var(--ink);
}
.angle-q { color: var(--ink) !important; font-weight: 500; }
.angle-aside { margin: .45rem 0 0; font-size: .82rem; color: var(--faint); line-height: 1.55; max-width: 62ch; }
.angle-links { margin: 1.5rem 0 0; font-size: .875rem; line-height: 1.7; }
.angle-links a, .note-angles a { color: var(--violet); text-decoration: none; font-weight: 500; }
.angle-links a:hover, .note-angles a:hover { text-decoration: underline; }
.angle-links .sep, .note-angles .sep { padding: 0 .5em; color: var(--faint); opacity: .6; }
.angle-nav {
  display: flex; justify-content: space-between; gap: .625rem;
  margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line-2);
}
.angle-nav .text-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .56rem 1rem; border: 1px solid var(--line-3); border-radius: 999px;
  background: var(--surface); color: var(--violet); font-size: .875rem; font-weight: 600;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease);
}
.angle-nav .text-btn:hover { background: var(--violet-soft); border-color: var(--violet); }
.angle-nav .text-btn:active { transform: scale(.97); transition: transform var(--press) ease-out; }
.angle-nav .text-btn:only-child { margin-left: auto; }
#angle-next { margin-left: auto; }

/* notes: links from a note card into its grid cells */
.note-angles { margin: 0 0 .35rem !important; font-size: .9rem; }
.note-angles-topic { color: var(--muted); margin-right: .6rem; }

/* key terms: concept intro on the left, a two-column glossary on the right */
.terms-search { padding-top: 1.5rem; padding-bottom: .25rem; }
.terms-search .control-row { align-items: flex-start; }
.concept-chips { display: flex; flex-wrap: wrap; gap: 2px; min-width: 0; }
.terms-search .result-count { padding-top: .5rem; }
.terms-group {
  display: grid; grid-template-columns: minmax(12rem, 16rem) 1fr; gap: 1rem 3rem;
  padding-top: 2.5rem;
}
.terms-group + .terms-group {
  margin-top: 2.5rem; padding-top: 2.75rem;
  border-top: 3px solid var(--ink);
}
.terms-group[hidden] { display: none; }
.terms-intro { position: sticky; top: 5.25rem; align-self: start; }
.terms-heading {
  margin: 0; font-size: 1.25rem; font-weight: 600; line-height: 1.25;
  letter-spacing: -.02em; color: var(--ink);
}
.terms-blurb { margin: .55rem 0 0; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.terms-togrid { margin: .7rem 0 0 -.44rem; text-align: left; }
.terms { margin: 0; display: grid; grid-template-columns: 1fr 1fr; column-gap: 2.25rem; align-content: start; }
.term { padding: .95rem 0 1rem; border-top: 1px solid var(--line); }
.term[hidden] { display: none; }
.term dt { font-size: .97rem; font-weight: 600; line-height: 1.35; letter-spacing: var(--track-title); color: var(--ink); }
.term dd { margin: .32rem 0 0; font-size: .9rem; line-height: 1.62; color: var(--ink-2); }
.term-also { display: block; margin-top: .4rem; font-size: .78rem; color: var(--faint); letter-spacing: var(--track-small); }
#terms-list { padding-bottom: 5rem; }

@media (max-width: 960px) {
  .cgrid { --cg-cols: minmax(8.5rem, 10.5rem) repeat(6, minmax(0, 1fr)); }
  .cg-cell { font-size: .78rem; padding-inline: .45rem; }
  .terms { grid-template-columns: 1fr; }
  .terms-group { grid-template-columns: minmax(10rem, 13rem) 1fr; gap: 1rem 2rem; }
}

.empty { text-align: center; padding: 4.75rem 1.25rem; color: var(--muted); }
.empty h2 { font-size: 1.15rem; font-weight: 600; letter-spacing: -.012em; margin: 0 0 .35rem; color: var(--ink); }
.empty p { margin: 0; font-size: .92rem; }

/* ---------- AI marking ---------- */
.prompt-card {
  background: var(--surface); border: 2px solid var(--ink); border-radius: var(--r-xl);
  overflow: hidden; margin-top: 4px;
}
.prompt-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .81rem 1rem; border-bottom: 1px solid var(--line-2); flex-wrap: wrap;
}
.prompt-bar .label { font-size: .8rem; color: var(--muted); letter-spacing: var(--track-small); }
/* completion feedback: the copy button confirms on the same frame it copies */
#copy-prompt.is-done { background: var(--ink); border-color: var(--ink); color: var(--canvas); }
.prompt-text {
  margin: 0; padding: 1.25rem clamp(1rem, 3vw, 1.375rem); white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: .8rem; line-height: 1.7; color: var(--ink-2); letter-spacing: 0;
  max-height: 32.5rem; overflow-y: auto; overscroll-behavior: contain;
}
.caveat {
  margin: 1.25rem 0 5rem; font-size: .855rem; font-weight: 700;
  color: var(--muted); max-width: 60ch;
}

@media (min-width: 681px) {
  .caveat { max-width: none; }
}

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--line); padding-block: 1.125rem 1.625rem;
  display: flex; justify-content: space-between; align-items: center;
  gap: .625rem 1.125rem; flex-wrap: wrap; font-size: .8rem; color: var(--faint);
  letter-spacing: var(--track-small);
}
.footer b { color: var(--violet); font-weight: 700; letter-spacing: -.01em; }
.footer a { color: var(--faint); text-decoration: none; }
.footer a:hover { color: var(--ink-2); }
.footer-links { display: flex; gap: .875rem; flex-wrap: wrap; }

/* ---------- theme switcher: a small, light glass chip ---------- */
.theme-toggle {
  position: fixed; right: 22px; bottom: 22px; z-index: 50;
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.75rem; height: 2.75rem; padding: 0; border-radius: 999px;
  border: 1px solid var(--line-3);
  background: rgba(var(--mat-surface-rgb), .8);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--mat-edge), 0 8px 24px -14px rgba(var(--shadow-rgb), .7);
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.theme-toggle:hover { border-color: var(--violet); color: var(--violet); }
.theme-toggle:active { transform: scale(.92); transition: transform var(--press) ease-out; }
.theme-toggle svg { width: 19px; height: 19px; }

/* ---------- page enter ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
main { flex: 1 0 auto; animation: rise 300ms var(--ease) backwards; }

/* ---------- mobile ---------- */
@media (max-width: 680px) {
  :root { --gutter: 18px; }

  .nav-inner { position: relative; min-height: 3.875rem; gap: 1rem; }
  .brand { font-size: 1.16rem; }
  .nav-toggle {
    display: inline-flex; width: 2.625rem; height: 2.625rem; padding: 0;
    flex-direction: column; align-items: center; justify-content: center; gap: 5px;
    border: 0; border-radius: var(--r-sm); background: transparent;
    color: var(--violet); cursor: pointer;
    transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
  }
  .nav-toggle:hover { background: var(--violet-soft); }
  .nav-toggle:active { transform: scale(.92); background: var(--violet-soft); transition: transform var(--press) ease-out; }
  .nav-toggle span {
    width: 20px; height: 2px; border-radius: 2px; background: currentColor;
    transition: transform var(--base) var(--ease-in), opacity var(--fast) var(--ease-in);
  }
  .nav.is-open .nav-toggle span { transition-timing-function: var(--ease); }
  .nav.is-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav.is-open .nav-toggle span:nth-child(2) { opacity: 0; }
  .nav.is-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* While the menu is open the bar turns solid, so we never stack one
     translucent surface on another. */
  .nav.is-open { background: var(--canvas); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .nav.is-open::after { opacity: 0; }

  /* The menu grows out of the toggle (top-right origin) and leaves the same
     way. Only transform and opacity move; a spring in app.js drives them. */
  .nav-links {
    position: absolute; top: calc(100% - 1px); left: var(--gutter); right: var(--gutter);
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    padding: .5rem;
    border: 1px solid var(--line); border-radius: var(--r-lg);
    background: var(--canvas);
    box-shadow: 0 18px 36px -24px rgba(var(--shadow-rgb), .45);
    transform-origin: calc(100% - 1.3rem) 0;
    opacity: 0; visibility: hidden; pointer-events: none;
  }
  .nav-links.is-shown { visibility: visible; }
  .nav.is-open .nav-links { visibility: visible; pointer-events: auto; }
  .nav-links a { padding: .625rem .75rem; border-radius: var(--r-sm); font-size: .9rem; }
  .nav-ind { display: none; }
  .nav-full { display: inline; }
  .nav-short { display: none; }

  .page-head { padding-block: 1.625rem 1.125rem; }
  .about { padding-top: 2.125rem; }
  .about .page-title + p, .about p { margin-top: 1.1rem; }
  .about-actions { gap: .5rem; }
  .about-actions .btn { flex: 1 1 auto; justify-content: center; }

  /* ---------- filter sheet (phone) ----------
     On a phone the filter becomes a bottom sheet: a modal task, so it pairs
     with a dimming scrim. Drag it by the grabber (or the list, once it is
     scrolled to the top); it tracks 1:1, rubber-bands past the top, and a
     flick projects where it's going before it snaps. */
  .filter-panel.is-sheet {
    /* extends 4rem below the screen so a rubber-banded pull never shows a gap */
    top: auto !important; left: 0 !important; right: 0; bottom: -4rem;
    width: 100% !important; max-width: none;
    max-height: calc(min(82vh, 40rem) + 4rem) !important;
    border-radius: 1.25rem 1.25rem 0 0; border-width: 1px 0 0;
    padding: 0 .5rem calc(4.75rem + env(safe-area-inset-bottom));
    background: rgba(var(--mat-surface-rgb), .97);
    -webkit-backdrop-filter: blur(36px) saturate(180%);
    backdrop-filter: blur(36px) saturate(180%);
    box-shadow: inset 0 1px 0 var(--mat-edge), 0 -18px 48px -20px rgba(var(--shadow-rgb), .45);
    overscroll-behavior: contain;
  }
  .filter-panel.is-sheet .sheet-grabber {
    display: flex; justify-content: center; align-items: center;
    position: sticky; top: 0; z-index: 1;
    height: 1.75rem; margin: 0 -.5rem; cursor: grab; touch-action: none;
    background: var(--surface);
    border-radius: 1.25rem 1.25rem 0 0;
  }
  .filter-panel.is-sheet .sheet-grabber span {
    width: 2.25rem; height: 5px; border-radius: 999px; background: var(--line-3);
  }
  .sheet-scrim {
    display: block; position: fixed; inset: 0; z-index: 59;
    background: var(--scrim); opacity: 0; visibility: hidden;
  }
  .sheet-scrim.is-visible { visibility: visible; }

  .filter-btn { padding: .69rem .94rem; }          /* ~45px tap target */
  .fopt { padding: .69rem .56rem; font-size: .92rem; }
  .fgroup-title { font-size: .75rem; }
  .field-label { font-size: .75rem; }
  .search-clear { padding: .56rem; }
  .result-count { margin-left: auto; }
  .active-filters { flex-basis: 100%; order: 3; margin-top: -2px; white-space: normal; }

  /* concepts page */
  .view-switch { gap: 1.5rem; }
  .ctx-switch, .concept-chips {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    width: calc(100% + 2 * var(--gutter)); max-width: none; align-self: auto;
    margin-inline: calc(-1 * var(--gutter)); padding-inline: var(--gutter);
    scroll-padding-inline: var(--gutter);
  }
  .seg-btn, .chip { flex-shrink: 0; }
  .grid-bar { display: flex; flex-direction: column; align-items: stretch; gap: .625rem; margin-top: 1.25rem; }
  .gkey-wrap { align-self: flex-end; }
  .gkey-btn { padding: .62rem .9rem .62rem .75rem; }   /* ~44px tap target */
  .gkey { padding: .8rem .95rem .75rem; font-size: .85rem; }
  .gkey-list { gap: .5rem; }
  .gkey-hint { font-size: .78rem; }
  .gkey-swatch.is-weak { border: 1px dashed var(--line-3); }
  .ctx-switch::-webkit-scrollbar, .concept-chips::-webkit-scrollbar { display: none; }
  .terms-search .control-row { flex-direction: column; align-items: stretch; gap: .5rem; }
  .terms-search .result-count { padding-top: 0; margin-left: 0; }
  .seg-btn, .chip { padding: .56rem .85rem; }

  .cgrid {
    background: none; border: 0; box-shadow: none; padding: 0; margin-top: 1rem;
  }
  .cg-head { display: none; }
  .cg-group-title { margin: 1.5rem 0 .625rem; }
  .cg-group:first-of-type .cg-group-title { margin-top: .5rem; }
  .cg-row {
    display: block; padding: .95rem .95rem 1rem; margin-bottom: .625rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
    box-shadow: 0 10px 26px -24px rgba(var(--shadow-rgb), .45);
  }
  .cg-group-title + .cg-row { border-top: 1px solid var(--line); }
  .cg-cells { display: grid; grid-template-columns: 1fr 1fr; gap: .375rem; }
  .cg-topic { padding: 0 0 .7rem; font-size: 1rem; }
  .cg-cell {
    min-height: 0; justify-content: flex-start;
    padding: .6rem .7rem .65rem; font-size: .84rem;
  }
  .cg-cell.is-empty { align-items: flex-start; border: 1px dashed var(--line-3); }
  .cg-cname {
    display: block; margin-bottom: .18rem; font-size: .72rem; font-weight: 700;
    letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--violet);
  }
  .cg-cell.is-empty .cg-cname { color: var(--faint); }
  .cg-group, .terms-group { contain-intrinsic-size: auto 900px; }

  .angle-dialog.is-sheet[open] { align-items: flex-end; }
  .angle-dialog.is-sheet .angle-sheet {
    width: 100%; max-height: 88vh;
    border-radius: 1.25rem 1.25rem 0 0; border-width: 1px 0 0;
    padding: 0 var(--gutter) calc(1rem + env(safe-area-inset-bottom));
  }
  .angle-dialog.is-sheet .angle-grabber {
    display: flex; justify-content: center; align-items: center;
    position: sticky; top: 0; z-index: 2; height: 1.75rem;
    margin: 0 calc(-1 * var(--gutter)) .25rem;
    background: var(--surface); cursor: grab; touch-action: none;
  }
  .angle-nav .text-btn { flex: 1 1 0; justify-content: center; padding-block: .7rem; }
  .angle-grabber span { width: 2.25rem; height: 5px; border-radius: 999px; background: var(--line-3); }
  .angle-title { font-size: 1.18rem; }

  .terms-group { display: block; padding-top: 1.75rem; }
  .terms-group + .terms-group { margin-top: 1.75rem; padding-top: 2.125rem; }
  .terms-intro { position: static; margin-bottom: 1rem; }
  .terms-heading { font-size: 1.15rem; }

  .item-head { padding: 1.06rem 1rem; gap: .75rem; }
  .body-pad { margin-inline: 1rem; padding-bottom: 1.25rem; }
  .item-title { font-size: 1rem; }
  .item-q { font-size: .97rem; }
  .field { margin-top: 1.06rem; }
  .list { padding-top: 1.125rem; }

  .prompt-text { font-size: .765rem; max-height: 62vh; }
  .footer { padding-block: .5rem calc(4.5rem + env(safe-area-inset-bottom)); }   /* clear of the theme button */
  .footer-links { gap: 0 .25rem; }
  .footer a { display: inline-block; padding: .7rem .4rem; }                         /* ~44px tap target */
  .footer > span:first-child { padding-block: .7rem; }
  .note-angles a { display: inline-block; padding-block: .45rem; }
  .cg-group-title { font-size: .75rem; }
  .theme-toggle { right: 16px; bottom: 16px; }
}

/* ---------- accessibility preferences ---------- */

/* Reduced motion is not "no feedback": slides, scales and springs become
   short cross-fades; colour and opacity changes that aid comprehension stay. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  @keyframes rise { from { opacity: 0; } }
  main { animation-duration: 200ms; }
  .btn:active, .text-btn:active, .filter-btn:active, .gkey-btn:active, .theme-toggle:active,
  .nav-links a:active, .nav-toggle:active { transform: none; }
  .search-clear:active { transform: translateY(-50%); }
  .item-body, .item.open .item-body { transition: none; }
  .item-body > .inner, .item.open .item-body > .inner {
    transform: none; transition: opacity 200ms ease;
  }
  .chevron, .item.open .chevron, .filter-btn .caret, .gkey-btn .caret, .nav-toggle span,
  .nav.is-open .nav-toggle span { transition: color var(--fast) ease; }
}

/* Reduced transparency: materials turn solid, blur goes away. */
@media (prefers-reduced-transparency: reduce) {
  .nav, .filter-panel, .filter-panel.is-sheet, .theme-toggle,
  .filter-panel.is-sheet .sheet-grabber, .cg-head {
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .cg-head { background: var(--canvas); }
  .nav { background: var(--canvas); }
  .filter-panel, .filter-panel.is-sheet, .theme-toggle,
  .filter-panel.is-sheet .sheet-grabber { background: var(--surface); }
}

/* Higher contrast: near-solid surfaces with defined borders. */
@media (prefers-contrast: more) {
  :root { --line: #c6bed4; --line-3: #9b91ad; --faint: #59536a; --muted: #4f4960; }
  html[data-theme="dark"] { --line: #70637b; --line-3: #93839f; --faint: #c2b7cb; --muted: #d2c7db; }
  .item, .btn, .filter-btn, .search-field input { border-width: 1.5px; }
  .nav { background: var(--canvas); border-bottom: 1.5px solid var(--line-3);
         -webkit-backdrop-filter: none; backdrop-filter: none; }
  .nav::after { display: none; }
  .filter-panel, .filter-panel.is-sheet, .theme-toggle {
    background: var(--surface); border: 1.5px solid var(--line-3);
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
}
@media print {
  .nav, .controls, .footer, .chevron, .theme-toggle { display: none; }
  .item-body { grid-template-rows: 1fr; }
  .item-body > .inner { opacity: 1; transform: none; }
}
