/* Ledger, cool paper and ink, verdigris/oxide for direction.
   Sign is the semantic core: it gets the only saturated color and the one moment of motion;
   everything else stays quiet. Depth is a lighter fill + hairline, never a drop shadow. */

/* ---- fonts: local only (offline exam-week wifi). Falls back to system stacks. ---- */
@font-face { font-family: 'Spectral';     src: local('Spectral'),      url('fonts/Spectral-Medium.woff2')     format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Inter Tight';   src: local('Inter Tight'),   url('fonts/InterTight-Regular.woff2')  format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Inter Tight';   src: local('Inter Tight'),   url('fonts/InterTight-SemiBold.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: local('IBM Plex Mono'), url('fonts/IBMPlexMono-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: local('IBM Plex Mono'), url('fonts/IBMPlexMono-Medium.woff2')  format('woff2'); font-weight: 500; font-display: swap; }

:root {
  /* surfaces, one cool blue-grey hue, low chroma, so it all reads as one paper stock */
  --paper:      #E4E7EE;
  --panel:      #EEF1F6;
  --paper-deep: #D3D8E2;
  --rule:       #C7CCD6;
  --hair:       #D0D5DE;

  /* ink ramp */
  --ink:        #161A28;
  --ink-soft:   #454C60;
  --ink-faint:  #57607A;

  /* sign, the only saturated colors, only ever on signs/state */
  --up:         #1B6655;
  --up-ink:     #0E5142;
  --down:       #98311F;
  --down-ink:   #8A2C1B;
  --null:       #7A8194;
  --flag:       #A67C1E;
  --sel:        rgba(166, 124, 30, 0.16);
  --focus:      #A67C1E;

  --serif: 'Spectral', Georgia, 'Times New Roman', serif;
  --sans:  'Inter Tight', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* type scale (fixed rem, product UI, consistent DPI) */
  --t-display: 1.875rem;  /* 30 */
  --t-title:   1.375rem;  /* 22 */
  --t-lg:      1.0625rem; /* 17 */
  --t-md:      0.9375rem; /* 15 */
  --t-sm:      0.8125rem; /* 13 */
  --t-xs:      0.71875rem;/* 11.5 */

  /* space rhythm */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 18px; --s5: 28px; --s6: 44px;

  /* motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 120ms; --dur: 180ms; --dur-slow: 240ms;

  /* z-scale */
  --z-wiring: 1; --z-nodes: 2; --z-slot: 3; --z-suggest: 40;

  --maxw: 1180px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--t-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'tnum' 1;
}
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
button { font: inherit; color: inherit; }

/* ---- top bar ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s3) var(--s5); border-bottom: 2px solid var(--ink);
  position: sticky; top: 0; background: var(--paper); z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-weight: 500; font-size: var(--t-title);
  letter-spacing: -0.01em; margin-right: auto;
  background: transparent; border: 0; padding: 4px 8px 4px 0; margin-left: -2px;
  color: var(--ink); cursor: pointer; border-radius: 4px;
  transition: opacity var(--dur-fast) var(--ease);
}
.brand:hover { opacity: 0.62; }
.brand .mark {
  width: 14px; height: 18px; display: inline-block; border-radius: 1px;
  background: linear-gradient(90deg, var(--up) 0 50%, var(--down) 50% 100%);
  transition: transform var(--dur) var(--ease);
}
.brand:hover .mark { transform: rotate(-6deg); }
.tabs { display: flex; gap: var(--s1); }
.tab {
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 7px 14px; border: 1px solid transparent; background: transparent; color: var(--ink-soft);
  cursor: pointer; border-radius: 3px; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tab:hover { background: var(--paper-deep); color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--paper-deep); box-shadow: inset 0 -2px 0 var(--ink); }
.refbox {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft);
}
.refbox input { width: 15px; height: 15px; accent-color: var(--flag); cursor: pointer; }
.auth-ctl {
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 7px 12px; border: 1px solid var(--hair); background: transparent; color: var(--ink-soft);
  border-radius: 3px; cursor: pointer; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.auth-ctl:hover { border-color: var(--ink); color: var(--ink); }

main { display: block; }

/* ---- query / command field ---------------------------------------------- */
.query-wrap { max-width: var(--maxw); margin: 0 auto; padding: var(--s5) var(--s5) 0; position: relative; }
.query-field {
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1.5px solid var(--rule);
  transition: border-color var(--dur) var(--ease);
}
.query-field:focus-within { border-color: var(--ink); }
.query-icon { width: 18px; height: 18px; color: var(--ink-faint); flex: none; transition: color var(--dur) var(--ease); }
.query-field:focus-within .query-icon { color: var(--ink); }
.query {
  flex: 1; font-family: var(--mono); font-size: var(--t-lg); font-weight: 400;
  padding: 12px 2px; background: transparent; border: none; color: var(--ink);
  outline: none; letter-spacing: -0.01em;
}
.query::placeholder { color: var(--ink-faint); }

.suggest { position: relative; }
.suggest-list {
  position: absolute; left: 0; right: 0; top: 6px; z-index: var(--z-suggest);
  background: var(--panel); border: 1px solid var(--ink); border-radius: 4px; overflow: hidden;
  box-shadow: 0 8px 28px -18px rgba(22, 26, 40, 0.55);
}
.suggest-list button {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  width: 100%; text-align: left; padding: 10px 14px; border: none;
  background: transparent; font-family: var(--mono); font-size: var(--t-sm); color: var(--ink); cursor: pointer;
}
.suggest-list button + button { border-top: 1px solid var(--hair); }
.suggest-list button:hover, .suggest-list button.active { background: var(--paper-deep); }
.suggest-list .kindtag { color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--t-xs); }

/* ---- home / empty state -------------------------------------------------- */
.home { max-width: var(--maxw); margin: 0 auto; padding: var(--s5) var(--s5) var(--s6); }
.home-hero { max-width: 62ch; margin-bottom: var(--s6); }
.home-hero h1 {
  font-family: var(--serif); font-weight: 500; font-size: var(--t-display); line-height: 1.12;
  letter-spacing: -0.015em; margin: 0 0 var(--s3); text-wrap: balance;
}
.home-hero p { color: var(--ink-soft); font-size: var(--t-lg); margin: 0; text-wrap: pretty; }
.home-hero .legend {
  display: flex; flex-wrap: wrap; gap: var(--s4); margin-top: var(--s4);
  font-family: var(--mono); font-size: var(--t-sm); color: var(--ink-soft);
}
.home-hero .legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend .k {
  width: 22px; height: 22px; border: 1.5px solid var(--ink); border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 500;
}
.legend .k.up { background: var(--up); color: #fff; border-color: var(--up); }
.legend .k.down { background: var(--down); color: #fff; border-color: var(--down); }
.legend .k.none { border-style: dashed; color: var(--null); }

.section-label {
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--ink-faint); font-weight: 500; margin: 0 0 var(--s3); padding-bottom: var(--s2);
  border-bottom: 1px solid var(--rule); display: flex; align-items: baseline; justify-content: space-between;
}
.section-label .count { color: var(--ink-faint); }

/* browse hub, a directory of every FSA subject on the home screen */
.browse { margin-bottom: var(--s6); }
.browse-group { margin-bottom: var(--s4); }
.browse-grouplabel { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin-bottom: var(--s2); }
.browse-chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.browse-chip {
  font-family: var(--sans); font-size: var(--t-sm); padding: 7px 12px;
  border: 1px solid var(--hair); background: transparent; color: var(--ink);
  border-radius: 3px; cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.browse-chip:hover { border-color: var(--ink); background: var(--paper-deep); transform: translateY(-1px); }

.misslist { display: flex; flex-direction: column; }
.miss {
  display: grid; grid-template-columns: 1fr auto auto; gap: var(--s4); align-items: center;
  padding: 13px 6px; border-bottom: 1px solid var(--hair); cursor: pointer; text-align: left;
  background: transparent; border-left: none; border-right: none; border-top: none; width: 100%;
  font-family: inherit; color: inherit; transition: background var(--dur-fast) var(--ease), padding-left var(--dur-fast) var(--ease);
}
.miss:hover { background: var(--paper-deep); padding-left: 12px; }
.miss .edge { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.miss .from { font-weight: 600; }
.miss .arrow { color: var(--ink-faint); font-family: var(--mono); }
.miss .to { color: var(--ink-soft); }
.miss .stat { font-family: var(--mono); font-size: var(--t-xs); color: var(--down-ink); white-space: nowrap; }
.miss .los { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); }
.empty-note { color: var(--ink-faint); font-family: var(--mono); font-size: var(--t-sm); padding: var(--s2) 6px; }
.modetag {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-soft); background: var(--paper-deep); border-radius: 3px; padding: 2px 6px; flex: none;
}
.home-footer { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--rule); flex-wrap: wrap; }
.footer-note { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); }
.grade { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); display: inline-flex; align-items: center; gap: 6px; }
.btn-quiet.good:hover { border-color: var(--up); color: var(--up-ink); }
.btn-quiet.miss:hover { border-color: var(--down); color: var(--down-ink); }
.cflip.graded { opacity: 0.7; }
.cflip.graded .grade { color: var(--up-ink); }

/* ---- graph subgraph ------------------------------------------------------ */
.graph { max-width: var(--maxw); margin: 0 auto; padding: var(--s3) var(--s5) var(--s6); }
.graph-head { display: flex; align-items: baseline; gap: var(--s4); margin: var(--s4) 0 var(--s2); flex-wrap: wrap; }
.graph-head .concept { font-family: var(--serif); font-size: var(--t-title); font-weight: 500; letter-spacing: -0.01em; }
.graph-head .def { color: var(--ink-soft); font-size: var(--t-sm); max-width: 60ch; }
.graph-head .los { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); margin-left: auto; white-space: nowrap; }

.predict-bar {
  font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-soft);
  display: flex; gap: var(--s4); align-items: center; padding: var(--s2) 0; border-bottom: 1px solid var(--rule); flex-wrap: wrap;
}
.predict-bar .hint { display: inline-flex; gap: 6px; align-items: center; }
.predict-bar kbd {
  font-family: var(--mono); background: var(--panel); border: 1px solid var(--hair); border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 6px; color: var(--ink); font-size: var(--t-xs);
}
.predict-bar .prog { margin-left: auto; color: var(--ink); }
.predict-bar .prog b { font-weight: 500; }
.predict-bar.reference { color: var(--flag); }

.colhead {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-faint); border-bottom: 2px solid var(--ink); margin-top: var(--s4);
}
.colhead span { padding: var(--s3) var(--s4); }
.colhead span + span { border-left: 1px solid var(--rule); }

.wiring { position: relative; overflow-x: auto; }
.wiring svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: var(--z-wiring); }
.wiring svg path { transition: stroke var(--dur) var(--ease), stroke-width var(--dur) var(--ease); }
.cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; position: relative; z-index: var(--z-nodes); min-width: 0; }
/* depth-layered, expandable graph */
.cols-depth { display: grid; position: relative; z-index: var(--z-nodes); min-width: 0; border-top: 2px solid var(--ink); }
.node.expandable { cursor: pointer; }
.node.expandable:hover { background: var(--paper-deep); }
.node .expand {
  display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; margin-left: 8px;
  border: 1.5px solid var(--flag); color: var(--flag); border-radius: 50%; font-family: var(--mono); font-size: 12px;
  line-height: 1; vertical-align: middle; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.node.expandable:hover .expand { background: var(--flag); color: #fff; }
.graph-actions { display: flex; gap: var(--s3); align-items: center; margin-top: var(--s4); flex-wrap: wrap; }
.col { display: flex; flex-direction: column; min-width: 0; }
.col + .col { border-left: 1px solid var(--rule); }

/* nodes are ruled rows, not floating cards */
.node {
  position: relative; padding: 18px var(--s4) 18px 22px; border-bottom: 1px solid var(--hair);
  min-height: 78px; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 5px;
  transition: background var(--dur) var(--ease);
}
.node.focus { background: var(--paper-deep); }
.node.dim { opacity: 0.55; }
.node .nlabel { font-weight: 600; font-size: var(--t-lg); line-height: 1.3; overflow-wrap: anywhere; }
.node .nmeta { font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.07em; }
.node .nformula { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); margin-top: 4px; line-height: 1.4; overflow-wrap: anywhere; }
/* the focus concept's plain-language definition, anchored where the eye lands first */
.node.focus .node-def { font-size: var(--t-md); color: var(--ink); line-height: 1.5; margin-top: 10px; max-width: 42ch; }
/* once answers are visible, concept labels become explore links */
.graph.explorable .node .nlabel { cursor: pointer; }
.graph.explorable .node:not(.focus) .nlabel:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* sign slots, stacked on the target node's left edge, one per incoming edge */
.slots { position: absolute; left: -13px; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: center; gap: 8px; z-index: var(--z-slot); }
.slot {
  position: relative; width: 26px; height: 26px; border: 1.5px solid var(--ink); background: var(--paper);
  border-radius: 4px; cursor: pointer; padding: 0; overflow: visible;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.slot:hover { border-color: var(--ink); background: var(--panel); }
.slot .glyph {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-family: var(--mono); font-size: var(--t-sm); font-weight: 500; line-height: 1;
}
/* the ink-bleed fill: a scaling inset layer, revealed via .bleed */
.slot::before {
  content: ''; position: absolute; inset: 1px; border-radius: 3px; z-index: 1;
  background: var(--fill, transparent); transform: scale(0); transform-origin: center;
  transition: transform var(--dur) var(--ease);
}
.slot.bleed::before { transform: scale(1); }

.slot.sel { border-color: var(--flag); box-shadow: 0 0 0 3px var(--sel); }
.slot.guess-plus  .glyph { color: var(--up-ink); }
.slot.guess-minus .glyph { color: var(--down-ink); }
.slot.guess-zero  .glyph { color: var(--null); }

/* revealed states */
.slot.reveal-up    { border-color: var(--up); --fill: var(--up); }
.slot.reveal-up    .glyph { color: #fff; }
.slot.reveal-down  { border-color: var(--down); --fill: var(--down); }
.slot.reveal-down  .glyph { color: #fff; }
.slot.reveal-none  { border-style: dashed; border-color: var(--null); --fill: transparent; }
.slot.reveal-none  .glyph { color: var(--null); }
.slot.reveal-ambiguous { border-color: var(--flag); --fill: var(--flag); }
.slot.reveal-ambiguous .glyph { color: #fff; }
.slot.wrong { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--down); }

/* right/wrong badge in the slot's corner, unambiguous once answers show */
.slot.correct::after, .slot.wrong::after {
  position: absolute; top: -7px; right: -7px; width: 15px; height: 15px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 9px; font-weight: 700; line-height: 1; z-index: 5;
  border: 1.5px solid var(--paper);
}
.slot.correct::after { content: '✓'; background: var(--up); color: #fff; }
.slot.wrong::after { content: '✗'; background: var(--down); color: #fff; }

/* per-step verdict on concept build drills */
.cverdict { font-family: var(--mono); font-size: var(--t-xs); margin: 4px 0 2px; letter-spacing: 0.02em; }
.cverdict.ok { color: var(--up-ink); }
.cverdict.no { color: var(--down-ink); font-weight: 500; }

/* the user's wrong guess, struck through, to the left of the corrected slot */
.slot .wrongguess {
  position: absolute; right: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: var(--t-sm); text-decoration: line-through; white-space: nowrap; opacity: 0.85;
}
.wrongguess.g-plus  { color: var(--up-ink); }
.wrongguess.g-minus { color: var(--down-ink); }
.wrongguess.g-zero  { color: var(--null); }

/* mobile-only source label per slot (wiring is hidden on small screens) */
.slot .srclabel { display: none; }

/* ---- reveal controls + details ------------------------------------------ */
.reveal-btn {
  font-family: var(--mono); font-size: var(--t-sm); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 11px 22px; border: 2px solid var(--ink); background: var(--ink); color: var(--paper);
  cursor: pointer; border-radius: 3px; margin-top: var(--s4);
  transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.reveal-btn:hover:not(:disabled) { transform: translateY(-1px); }
.reveal-btn:active:not(:disabled) { transform: translateY(0); }
.reveal-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.scoreline { font-family: var(--mono); font-size: var(--t-md); margin-top: var(--s4); }
.scoreline .good { color: var(--up-ink); font-weight: 500; }
.scoreline .bad { color: var(--down-ink); font-weight: 500; }
.scoreline .rest { color: var(--ink-soft); }
.post-actions { display: flex; align-items: center; gap: var(--s4); margin-top: var(--s3); flex-wrap: wrap; }
.post-actions .kbd-note {
  font-family: var(--mono); font-size: 10px; margin-left: 6px; padding: 1px 5px;
  border: 1px solid var(--hair); border-radius: 3px; color: var(--ink-faint);
}
.post-tip { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); }

.details { margin-top: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.detail {
  background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; padding: var(--s4);
  font-size: var(--t-sm); animation: rise var(--dur-slow) var(--ease) both;
}
.detail .claim { font-size: var(--t-lg); margin-bottom: var(--s3); line-height: 1.3; }
.detail .claim .verb-up { color: var(--up-ink); font-weight: 600; }
.detail .claim .verb-down { color: var(--down-ink); font-weight: 600; }
.detail .claim .verb-none { color: var(--null); font-weight: 600; }
.detail .claim .verb-ambiguous { color: var(--flag); font-weight: 600; }
.detail .drow { display: grid; grid-template-columns: 96px 1fr; gap: var(--s3); margin: var(--s2) 0; align-items: start; }
.detail .dkey { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); padding-top: 2px; }
.detail .dval { max-width: 68ch; }
.detail .trap { color: var(--down-ink); }
.detail .example { font-family: var(--mono); font-size: var(--t-sm); background: var(--paper-deep); padding: 10px 12px; border-radius: 3px; line-height: 1.5; overflow-wrap: anywhere; }
.detail .fw { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.detail .conf { font-family: var(--mono); font-size: var(--t-xs); }
.detail .conf.verified { color: var(--up-ink); }
.detail .conf.unverified { color: var(--flag); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- quant tab ----------------------------------------------------------- */
.quant { max-width: var(--maxw); margin: 0 auto; padding: var(--s5); }
.quant-head { max-width: 62ch; margin-bottom: var(--s5); }
.quant-head h1 { font-family: var(--serif); font-weight: 500; font-size: var(--t-display); margin: 0 0 var(--s2); letter-spacing: -0.015em; }
.quant-head .sub { color: var(--ink-soft); font-size: var(--t-lg); margin: 0; }

.qtree { border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; background: var(--panel); }
.qnode { padding: var(--s5); animation: rise var(--dur-slow) var(--ease) both; }
.qbreadcrumb { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); margin-bottom: var(--s3); text-transform: uppercase; letter-spacing: 0.08em; }
.qnode .qprompt { font-family: var(--serif); font-size: var(--t-title); font-weight: 500; margin-bottom: var(--s4); letter-spacing: -0.01em; }
.qopts { display: flex; flex-direction: column; gap: var(--s2); }
.qopt {
  display: flex; align-items: center; gap: var(--s3);
  text-align: left; padding: 13px 16px; border: 1px solid var(--hair); background: var(--paper);
  border-radius: 3px; cursor: pointer; font-size: var(--t-md); color: var(--ink);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.qopt:hover { background: var(--paper-deep); border-color: var(--ink); transform: translateX(3px); }
.qopt .chev { color: var(--ink-faint); font-family: var(--mono); margin-left: auto; transition: color var(--dur-fast) var(--ease); }
.qopt:hover .chev { color: var(--ink); }

.qresult .qanswer {
  font-family: var(--mono); font-weight: 500; color: var(--up-ink); font-size: var(--t-title);
  display: flex; align-items: baseline; gap: 10px;
}
.qresult .qanswer .tick { color: var(--up); }
.qresult .qwhy { margin-top: var(--s3); font-size: var(--t-md); max-width: 66ch; color: var(--ink-soft); }
.qresult .qformula { font-family: var(--mono); font-size: var(--t-md); background: var(--paper-deep); padding: 12px 14px; border-radius: 3px; margin-top: var(--s3); color: var(--ink); }

.quant-drill { margin-top: var(--s6); }
.drill-card {
  border: 1px solid var(--rule); border-radius: 4px; padding: var(--s5); background: var(--panel);
  display: flex; flex-direction: column; gap: var(--s2);
}
.drill-card .los { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.08em; order: -1; }
.drill-card .prompt { font-family: var(--serif); font-size: var(--t-lg); }
.drill-card .answer { font-family: var(--mono); font-size: var(--t-sm); background: var(--paper-deep); padding: 12px 14px; border-radius: 3px; margin-top: var(--s2); line-height: 1.5; }
.drill-card .answer.hidden-a { display: none; }
.drill-controls { display: flex; gap: var(--s2); margin-top: var(--s3); }
.drill-counter { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); margin-left: auto; align-self: center; }

.btn-quiet {
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 9px 15px; border: 1px solid var(--hair); background: transparent; color: var(--ink); cursor: pointer; border-radius: 3px;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn-quiet:hover { border-color: var(--ink); background: var(--paper-deep); }
.qback { margin-top: var(--s4); }

/* ---- concepts tab -------------------------------------------------------- */
.concepts { max-width: var(--maxw); margin: 0 auto; padding: var(--s5); }
.concept-tabs { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s5); }
.concept-chip {
  font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 13px; border: 1px solid var(--hair); background: transparent; color: var(--ink-soft);
  border-radius: 3px; cursor: pointer; transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.concept-chip:hover { border-color: var(--ink); color: var(--ink); }
.concept-chip.active { background: var(--paper-deep); color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }

.concept-head { max-width: 66ch; margin-bottom: var(--s4); }
.concept-head h1 { font-family: var(--serif); font-weight: 500; font-size: var(--t-title); margin: 0 0 var(--s2); letter-spacing: -0.01em; }
.concept-head .sub { color: var(--ink-soft); font-size: var(--t-md); margin: 0 0 var(--s2); }
.concept-head .los { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); }

/* build drill, a vertical ledger with a spine */
.cledger { position: relative; margin-top: var(--s4); border-top: 2px solid var(--ink); }
.cstart, .cresult { padding: 14px 14px 14px 52px; display: flex; align-items: baseline; gap: var(--s3); }
.cstart { border-bottom: 1px solid var(--rule); }
.cresult { border-top: 2px solid var(--ink); }
.cstart .clabel, .cresult .clabel { font-weight: 600; font-size: var(--t-lg); }
.cresult .clabel { font-family: var(--mono); color: var(--up-ink); }
.cstart .cnote { color: var(--ink-faint); font-size: var(--t-sm); }

.cstep {
  position: relative; display: grid; grid-template-columns: 52px 1fr; align-items: start;
  border-bottom: 1px solid var(--hair); min-height: 56px;
}
.cstep .slot { position: relative; align-self: center; justify-self: center; margin: 14px 0; }
.cbody { padding: 14px 14px 14px 0; min-width: 0; }
.cbody .citem { font-weight: 600; font-size: var(--t-md); line-height: 1.3; }
.cbody .cwhy { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; animation: rise var(--dur) var(--ease) both; }
.cbody .csrc { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
.cbody .cexpl { font-size: var(--t-sm); color: var(--ink-soft); max-width: 68ch; }

.crules {
  margin-top: var(--s5); background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; padding: var(--s4) var(--s4) var(--s4) var(--s4);
}
.crules-h { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); margin-bottom: var(--s3); }
.crules ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.crules li { font-size: var(--t-sm); color: var(--ink); max-width: 74ch; line-height: 1.5; }

/* recall, flip cards */
.crecall { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s4); border-top: 2px solid var(--ink); }
.cflip {
  position: relative; text-align: left; width: 100%; cursor: pointer;
  border: none; border-bottom: 1px solid var(--hair); background: transparent; color: inherit; font-family: inherit;
  padding: 16px 90px 16px 14px; transition: background var(--dur-fast) var(--ease);
}
.cflip:hover { background: var(--paper-deep); }
.cflip .cfront { font-weight: 600; font-size: var(--t-md); }
.cflip .cback { display: none; margin-top: 8px; }
.cflip.flipped .cback { display: block; animation: rise var(--dur) var(--ease) both; }
.cflip .cans { font-family: var(--mono); font-size: var(--t-md); color: var(--up-ink); display: block; }
.cflip .cnote2 { display: block; margin-top: 5px; font-size: var(--t-sm); color: var(--ink-soft); max-width: 70ch; }
.cflip .cflip-hint {
  position: absolute; right: 14px; top: 16px; font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint);
  border: 1px solid var(--hair); border-radius: 3px; padding: 2px 7px;
}
.cflip.flipped .cflip-hint { opacity: 0; }

/* comparison board, two frameworks side by side with a = / ≠ connector */
.cmp-controls { display: flex; align-items: center; gap: var(--s3); margin: var(--s3) 0 var(--s4); flex-wrap: wrap; }
.cmp { border-top: 2px solid var(--ink); }
.cmp-head, .cmp-row { display: grid; grid-template-columns: 1.5fr 1fr 40px 1fr; }
.cmp-head { border-bottom: 2px solid var(--ink); }
.cmp-head .cmp-area, .cmp-head .cmp-cell { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); padding: 10px 14px; font-weight: 500; }
.cmp-head .cmp-cell { border-left: 1px solid var(--rule); }
.cmp-row { border-bottom: 1px solid var(--hair); position: relative; }
.cmp-row[role="button"] { cursor: pointer; }
.cmp-row[role="button"]:hover { background: var(--paper-deep); }
.cmp-area { font-weight: 600; font-size: var(--t-md); padding: 14px; display: flex; align-items: center; }
.cmp-row .cmp-cell { padding: 14px; display: flex; align-items: center; font-family: var(--mono); font-size: var(--t-sm); color: var(--ink); border-left: 1px solid var(--hair); }
.cmp-rel { display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 18px; font-weight: 700; border-left: 1px solid var(--hair); color: var(--ink-faint); transition: color var(--dur) var(--ease); }
.cmp-row:not(.revealed) .cmp-val { filter: blur(6px); opacity: 0.45; user-select: none; }
.cmp-row:not(.revealed) .cmp-rel { color: transparent; }
.cmp-row.revealed.differ .cmp-rel { color: var(--down); }
.cmp-row.revealed.same .cmp-rel { color: var(--up); }
.cmp-note { grid-column: 1 / -1; padding: 0 14px 12px; font-size: var(--t-sm); color: var(--ink-soft); display: none; }
.cmp-row.revealed .cmp-note { display: block; animation: rise var(--dur) var(--ease) both; }
.cmp-tag { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; margin-right: 8px; padding: 2px 6px; border-radius: 3px; }
.cmp-tag.differ { color: var(--down-ink); background: rgba(152, 49, 31, 0.10); }
.cmp-tag.same { color: var(--up-ink); background: rgba(27, 102, 85, 0.10); }
.cmp-row .grade { grid-column: 1 / -1; padding: 0 14px 12px; }

/* connector recall, front stays visible, answer reveals across an arrow */
.crecall2 { border-top: 2px solid var(--ink); }
.crow { display: grid; grid-template-columns: 1fr 40px 1.4fr; align-items: stretch; border-bottom: 1px solid var(--hair); }
.crow[role="button"] { cursor: pointer; }
.crow[role="button"]:hover { background: var(--paper-deep); }
.crow-front { font-weight: 600; font-size: var(--t-md); padding: 14px; display: flex; align-items: center; }
.crow-arrow { display: flex; align-items: center; justify-content: center; font-family: var(--mono); color: var(--ink-faint); border-left: 1px solid var(--hair); border-right: 1px solid var(--hair); transition: color var(--dur) var(--ease); }
.crow-back { padding: 14px; display: flex; flex-direction: column; gap: 5px; justify-content: center; }
.crow-val { font-family: var(--mono); font-size: var(--t-sm); color: var(--up-ink); }
.crecall2.prose .crow-val { font-family: var(--sans); font-size: var(--t-md); color: var(--ink); line-height: 1.5; }
.crecall2.prose .crow-front { align-items: flex-start; padding-top: 16px; }
.crow:not(.revealed) .crow-val { filter: blur(6px); opacity: 0.45; user-select: none; }
.crow:not(.revealed) .crow-arrow { color: transparent; }
.crow-note { font-size: var(--t-sm); color: var(--ink-soft); display: none; }
.crow.revealed .crow-note { display: block; }
.crow.revealed .grade { margin-top: 8px; }

@media (max-width: 760px) {
  .cmp-head { display: none; }
  .cmp-row { grid-template-columns: 1fr; }
  .cmp-row .cmp-cell { display: block; border-left: none; padding-top: 4px; padding-bottom: 4px; }
  .cmp-cell.gaap::before { content: 'US GAAP'; }
  .cmp-cell.ifrs::before { content: 'IFRS'; }
  .cmp-cell.gaap::before, .cmp-cell.ifrs::before { display: block; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
  .cmp-rel { display: none; }
  .cmp-area { border-bottom: 1px dashed var(--hair); padding-bottom: 8px; }
  .crow { grid-template-columns: 1fr; }
  .crow-arrow { display: none; }
  .crow-front { border-bottom: 1px dashed var(--hair); }
}

@media (max-width: 760px) {
  .cstart, .cresult { padding-left: 44px; }
  .cstep { grid-template-columns: 44px 1fr; }
}

/* ---- statements tab: interactive three-statement model ------------------ */
.statements { max-width: var(--maxw); margin: 0 auto; padding: var(--s5); }
.stmt-head { max-width: 70ch; margin-bottom: var(--s4); }
.stmt-head h1 { font-family: var(--serif); font-weight: 500; font-size: var(--t-display); margin: 0 0 var(--s2); letter-spacing: -0.015em; }
.stmt-head .sub { color: var(--ink-soft); font-size: var(--t-md); margin: 0; text-wrap: pretty; }

.stmt-stepper { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.stmt-steplabel { font-family: var(--mono); font-size: var(--t-sm); color: var(--ink); font-weight: 500; }
.stmt-dots { display: flex; gap: 6px; margin-bottom: var(--s4); flex-wrap: wrap; }
.stmt-dot { width: 22px; height: 8px; border-radius: 4px; border: 1px solid var(--rule); background: transparent; cursor: pointer; padding: 0; transition: background var(--dur-fast) var(--ease); }
.stmt-dot.done { background: var(--paper-deep); }
.stmt-dot.on { background: var(--ink); border-color: var(--ink); }

.stmt-event { border: 1px solid var(--ink); border-radius: 4px; background: var(--panel); padding: var(--s4); margin-bottom: var(--s5); }
.stmt-event .ev-title { font-family: var(--serif); font-size: var(--t-lg); display: flex; align-items: center; gap: 10px; }
.stmt-event .ev-num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: var(--t-xs); flex: none; }
.stmt-event .ev-desc { color: var(--ink-soft); font-size: var(--t-sm); margin: 6px 0 10px; max-width: 74ch; }
.stmt-event .ev-entries { display: flex; flex-wrap: wrap; gap: var(--s2); }
.stmt-event .je { font-family: var(--mono); font-size: var(--t-xs); padding: 3px 8px; border-radius: 3px; background: var(--paper-deep); }
.stmt-event .je.up { color: var(--up-ink); } .stmt-event .je.down { color: var(--down-ink); }

.stmt-panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); align-items: start; }
.stmt-panel { border: 1px solid var(--rule); border-radius: 4px; background: var(--panel); overflow: hidden; }
.stmt-panel .sp-head { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink); font-weight: 500; padding: 12px var(--s4); border-bottom: 2px solid var(--ink); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sp-badge { font-family: var(--mono); font-size: 10px; text-transform: none; letter-spacing: 0; padding: 2px 7px; border-radius: 3px; }
.sp-badge.ok { color: var(--up-ink); background: rgba(27, 102, 85, 0.12); }
.sp-badge.no { color: var(--down-ink); background: rgba(152, 49, 31, 0.12); }
.sp-body { padding: 6px var(--s4) var(--s4); }
.sp-section { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin: 12px 0 4px; }
.sp-row { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--hair); }
.sp-row .sp-label { font-size: var(--t-sm); color: var(--ink-soft); }
.sp-row .sp-val { font-family: var(--mono); font-size: var(--t-sm); font-variant-numeric: tabular-nums; color: var(--ink); }
.sp-row .sp-delta { font-family: var(--mono); font-size: 10.5px; color: var(--flag); font-variant-numeric: tabular-nums; }
.sp-row.subtotal { border-top: 1px solid var(--rule); margin-top: 2px; }
.sp-row.subtotal .sp-label, .sp-row.subtotal .sp-val { font-weight: 600; color: var(--ink); }
.sp-row.total { border-top: 2px solid var(--ink); border-bottom: none; margin-top: 4px; padding-top: 8px; }
.sp-row.total .sp-label { font-weight: 600; color: var(--ink); }
.sp-row.total .sp-val { font-weight: 700; color: var(--ink); font-size: var(--t-md); }
.sp-row.changed { animation: rowflash 1.1s var(--ease) 1; }
.sp-row.changed .sp-val { color: var(--flag); }
@keyframes rowflash { 0% { background: rgba(166, 124, 30, 0.22); } 100% { background: transparent; } }

.cf-toggle { display: inline-flex; gap: 2px; }
.cf-tab { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 9px; border: 1px solid var(--hair); background: transparent; color: var(--ink-faint); cursor: pointer; border-radius: 3px; }
.cf-tab.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.cf-note { font-size: var(--t-sm); color: var(--ink-soft); padding: 12px var(--s4); border-top: 1px solid var(--rule); background: var(--paper); }
.cf-note b { font-family: var(--mono); color: var(--ink); }

@media (max-width: 900px) { .stmt-panels { grid-template-columns: 1fr; } }

.hidden { display: none !important; }
main > section { animation: fade var(--dur-slow) var(--ease) both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- equations (native MathML) ------------------------------------------ */
math {
  font-family: 'STIX Two Math', 'Cambria Math', 'Latin Modern Math', 'Times New Roman', serif;
  color: var(--ink);
  math-style: normal;
}
math[display="block"] { display: block; margin: 0; text-align: center; }
.nformula math { font-size: 13.5px; }
.math-fallback { font-family: var(--mono); }

/* Block-equation card: hugs a short equation and centers it (no more wide flat band);
   a long one caps at the column width and scrolls inside its own box, never the page. */
.equation { width: fit-content; max-width: 100%; margin: var(--s3) auto; padding: 10px 16px; background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; color: var(--ink); box-sizing: border-box; overflow: hidden; }
.equation__math { overflow-x: auto; overflow-y: hidden; }
.equation math { font-size: 1.3rem; line-height: 1.2; }

/* ---- quant: formula library --------------------------------------------- */
.qcat-chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s3) 0 var(--s4); }
.qcat-chip { font-family: var(--mono); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.05em; padding: 7px 12px; border: 1px solid var(--hair); background: transparent; color: var(--ink-soft); border-radius: 3px; cursor: pointer; transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.qcat-chip:hover { border-color: var(--ink); color: var(--ink); }
.qcat-chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.qcat-head { font-family: var(--serif); font-weight: 500; font-size: var(--t-lg); margin: var(--s5) 0 var(--s3); letter-spacing: -0.01em; }
.qf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s3); }
.qf-card { border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); padding: var(--s3) var(--s4) var(--s4); display: flex; flex-direction: column; position: relative; transition: border-color var(--dur-fast) var(--ease); }
.qf-card[role="button"] { cursor: pointer; }
.qf-card[role="button"]:hover { border-color: var(--ink); }
.qf-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.qf-name { font-weight: 600; font-size: var(--t-md); }
.qf-los { font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); flex: none; }
.qf-eq { margin: 10px auto 8px; background: var(--paper-deep); }
.qf-eq math { font-size: 1.15rem; }
.qf-note { font-size: var(--t-sm); color: var(--ink-soft); line-height: 1.5; }
.qf-card:not(.revealed) .qf-eq math { filter: blur(6px); opacity: 0.5; user-select: none; }
.qf-card .grade { margin-top: 12px; }

/* ---- responsive: structural collapse, not fluid type -------------------- */
@media (max-width: 760px) {
  .topbar { padding: var(--s3) var(--s4); gap: var(--s3); }
  /* collapse the wordmark to just the logo mark so the bar fits narrow screens */
  .brand { font-size: 0; gap: 0; }
  .brand .mark { width: 16px; height: 20px; }
  .tab { padding: 6px 10px; }
  .refbox { letter-spacing: 0.04em; }
  .query-wrap, .home, .graph, .quant { padding-left: var(--s4); padding-right: var(--s4); }
  .cols3, .colhead, .cols-depth { grid-template-columns: 1fr !important; }
  .col + .col, .colhead span + span { border-left: none; }
  .col + .col { border-top: 1px solid var(--rule); }
  .colhead { display: none; }
  .wiring svg { display: none; }
  .predict-bar .hint { display: none; }
  .predict-bar .prog { margin-left: 0; }
  .graph-head .los { margin-left: 0; }
  /* slots become an inline row inside each target node, each labelled with its source */
  .slots { position: static; flex-direction: column; align-items: stretch; margin: 0 0 var(--s2); gap: var(--s2); }
  .slot { display: flex; align-items: center; width: 100%; height: auto; border: none; border-radius: 0; padding: 4px 0; background: transparent; }
  .slot::before { display: none; }
  .slot .glyph { width: 26px; height: 26px; border: 1.5px solid var(--ink); border-radius: 4px; flex: none; }
  .slot.reveal-up .glyph { background: var(--up); }
  .slot.reveal-down .glyph { background: var(--down); }
  .slot.reveal-none .glyph { border-style: dashed; border-color: var(--null); }
  .slot.reveal-ambiguous .glyph { background: var(--flag); }
  .slot.sel { box-shadow: none; }
  .slot.sel .glyph { box-shadow: 0 0 0 3px var(--sel); }
  .slot .srclabel { display: block; font-family: var(--mono); font-size: var(--t-xs); color: var(--ink-faint); margin-left: 10px; }
  .slot .wrongguess { position: static; transform: none; margin-left: auto; }
  .node { padding-left: var(--s3); }
  .detail .drow { grid-template-columns: 1fr; gap: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  .slot::before { transition: none !important; }
}
