/* shared.css — theme, tour shell, and reusable viz primitives.
   Loaded by every station page. Zero dependencies; DOM/SVG only (no canvas). */
:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #2a3140;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #2ea043;
  --green-2: #7ee787;
  --blue: #1f6feb;
  --purple: #a371f7;
  --orange: #d29922;
  --danger: #f85149;
  --pink: #f778ba;
  --sky: #79c0ff;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* CJK fallbacks (Hiragino / Yu Gothic / Noto / Meiryo) so the 日本語 copy renders
     natively on macOS, Windows, and Linux rather than dropping to tofu boxes. */
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", "Noto Sans CJK JP", Meiryo, sans-serif;
}
/* the JA copy gets a touch more line-height — CJK glyphs read better with air */
:lang(ja) { line-height: 1.7; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1, h2, h3 { font-weight: 650; line-height: 1.25; }

/* keyboard focus: a visible, theme-matched ring (the UA default is faint on the dark bg) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* SVG buttons (clickable diagram numbers, chart rows): outline is unreliable on SVG, so
   also draw the ring with stroke. !important beats per-element stroke attrs on the rect. */
svg [role="button"]:focus-visible { stroke: var(--accent) !important; stroke-width: 2.5 !important; outline: none; }
/* skip link — first focusable element; revealed on focus, jumps past the sticky nav */
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  background: var(--accent); color: #07101f; font-weight: 700;
  padding: 8px 14px; border-radius: 0 0 8px 8px; transition: top .15s ease;
}
.skip-link:focus { top: 0; }
/* visually hidden but available to screen readers (used by the language live region) */
.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;
}
/* honour a reduced-motion preference: drop the build/heatmap/plot/skip transitions */
@media (prefers-reduced-motion: reduce) {
  .build, .heatmap .hrow, .plot .pt, .plot .ptlab, .skip-link { transition: none; }
}

/* ---- bilingual prose (EN / 日本語) ----
   Each translatable block is duplicated: an .t-en copy and an .t-ja copy (the JA
   copy also carries lang="ja" for screen-reader pronunciation). Only the active
   language shows. We HIDE the inactive language rather than force-show the active
   one, so the visible copy keeps its own natural/author display (flex .rev-hint,
   block <p>, list-item <li>, inline <span>). The hide rules are body-scoped so
   they out-specify same-specificity block rules like `.rev-hint { display: flex }`
   — otherwise a later equal-specificity rule would win and leak the hidden copy.
   Default — before the toggle JS, or on pages without it — has no body.lang-*
   class, so English shows and the JA copies stay hidden (no flash). */
body:not(.lang-ja) .t-ja { display: none; }
body.lang-ja .t-en { display: none; }
/* a dense description split into digestible points instead of one wall of text */
ul.points { margin: 0 0 14px; padding-left: 20px; max-width: 80ch; }
ul.points li { margin: 4px 0; }
.panel ul.points { color: var(--muted); font-size: 13px; }
/* stacked short paragraphs read as one description block, not separate notes */
.hint + .hint, .lede + .lede, .dims + .dims { margin-top: 8px; }

/* ---- top tour nav (shared across every station) ---- */
.tour-nav {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--panel); position: sticky; top: 0; z-index: 50;
}
.tour-nav .brand { font-weight: 700; margin-right: 12px; white-space: nowrap; cursor: pointer; }
.tour-nav .brand .dot { color: var(--accent); }
.tour-nav a.station {
  color: var(--muted); padding: 5px 10px; border-radius: 6px; white-space: nowrap;
  border: 1px solid transparent; font-weight: 600; font-size: 13px;
}
.tour-nav a.station:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.tour-nav a.station.active { color: var(--text); background: var(--panel-2); border-color: var(--accent); }
.tour-nav .station.soon { color: #4d5663; padding: 5px 10px; font-size: 13px; font-weight: 600; cursor: not-allowed; }
.tour-nav .station.soon::after { content: " · soon"; font-size: 10px; color: #3a4250; }
.tour-nav .spacer { flex: 1; }
.tour-nav .pager { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tour-nav .pager kbd { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-family: inherit; }
/* EN / 日本語 language switch — a two-segment pill, like a minitoggle pair */
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-right: 12px; }
.lang-toggle button { background: transparent; border: 0; border-radius: 0; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 12px; cursor: pointer; line-height: 1.4; }
.lang-toggle button + button { border-left: 1px solid var(--border); }
.lang-toggle button:hover:not([aria-pressed="true"]) { color: var(--text); }
.lang-toggle button[aria-pressed="true"] { background: var(--panel-2); color: var(--accent); cursor: default; }

/* architecture build-up diagram (the spine) — rail on stations + overview on home */
.with-rail { display: flex; gap: 22px; align-items: flex-start; max-width: 1680px; margin: 0 auto; padding: 0 16px; }
.with-rail .station-main { margin: 0; max-width: none; flex: 1; min-width: 0; }
.arch-rail { position: sticky; top: 54px; flex: none; width: 196px; padding: 18px 0 24px; }
.arch-cap { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px 2px; }
.arch { display: flex; flex-direction: column; gap: 6px; }
.arch-io { text-align: center; color: var(--muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.arch-layer { position: relative; display: flex; flex-direction: column; gap: 6px; border: 1px dashed var(--border); border-radius: 11px; padding: 18px 8px 8px; }
.arch-xn { position: absolute; top: 4px; right: 9px; font-size: 10px; color: var(--muted); }
.arch-block { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px; color: var(--text); }
a.arch-block:hover { border-color: var(--accent); text-decoration: none; }
.arch-block.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--panel-2); }
.arch-block.soon { opacity: .5; }
.arch-block .ab-label { display: block; font-weight: 650; font-size: 13px; }
.arch-block .ab-tag { color: var(--accent); font-weight: 500; font-family: ui-monospace, monospace; font-size: 11px; }
.arch-block .ab-soon { color: #3a4250; font-size: 10px; font-weight: 500; }
.arch-block .ab-meaning { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
/* the per-token vectors crossing a seam of the stack: x = W_E + P into Attention (.flow-emb),
   and x + attn(x) into the FFN (.flow-attn, shown inside the layer between Attention and FFN) */
.arch-flow { text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.5; }
.arch-flow .af-lab { display: block; font-size: 10.5px; color: var(--muted); }
.arch-flow .af-vec { display: block; font-size: 11px; color: var(--green-2); }
.arch-flow .af-tok { color: var(--muted); }
.arch-overview .arch { gap: 10px; max-width: 440px; margin: 16px auto; }
.arch-overview .arch-block { padding: 13px 16px; }
.arch-overview .arch-block .ab-label { font-size: 16px; }
.arch-overview .arch-io { font-size: 14px; }
.arch-overview .arch-flow .af-lab { font-size: 12px; }
.arch-overview .arch-flow .af-vec { font-size: 13px; }
@media (max-width: 720px) { .arch-rail { display: none; } .with-rail { display: block; } }

/* ---- station page scaffold ---- */
.station-main { max-width: 1500px; margin: 0 auto; padding: 24px 20px 90px; }
.station-main > header.intro { margin-bottom: 8px; }
.station-main h1 { font-size: 24px; margin: 0 0 6px; }
.station-main .lede { color: var(--muted); font-size: 15px; margin: 0; max-width: 74ch; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin: 18px 0; }
.panel > h2 { font-size: 16px; margin: 0 0 4px; }
.panel > .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 80ch; }

.row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.col { flex: 1; min-width: 0; }

.takeaway { border-left: 3px solid var(--accent); background: #15202e; padding: 10px 14px; border-radius: 0 8px 8px 0; margin-top: 14px; font-size: 14px; }
.takeaway b { color: var(--accent); }

/* on-demand detail: a one-line lead stays visible, the deeper prose folds into this
   disclosure so the diagram stays the focus of the section. Collapsed by default. */
details.more { margin: 8px 0 0; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 13px; list-style: none; width: max-content; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸"; color: var(--accent); margin-right: 6px; }
details.more[open] > summary::before { content: "▾"; }
details.more[open] > summary { margin-bottom: 8px; }
details.more > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
details.more > .hint, details.more > .dims, details.more > p { color: var(--muted); font-size: 13px; margin: 6px 0 0; max-width: 80ch; }
details.more > .hint:first-of-type, details.more > .dims:first-of-type, details.more > p:first-of-type { margin-top: 0; }

/* ⓘ keyboard / interaction help — a compact icon by the step control that reveals the
   keys on hover AND keyboard focus, replacing the old full-paragraph instruction. */
.kbd-help { position: relative; display: inline-flex; }
.kbd-help > button { background: transparent; border: 0; color: var(--muted); cursor: help; font-size: 15px; line-height: 1; padding: 2px; border-radius: 50%; font-weight: 400; }
.kbd-help > button:hover:not(:disabled), .kbd-help > button:focus-visible { color: var(--accent); border-color: transparent; }
.kbd-help .kbd-pop { position: absolute; z-index: 30; right: 0; top: calc(100% + 6px); display: none; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; font-size: 12px; line-height: 1.7; color: var(--muted); white-space: nowrap; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }
.kbd-help:hover .kbd-pop, .kbd-help:focus-within .kbd-pop { display: block; }   /* reveal on hover or any focus (keyboard, SR, programmatic) */
.kbd-pop kbd { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; font: inherit; font-size: 11px; }

.controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }

/* form controls */
input[type=text], input[type=number], select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 7px 9px; font: inherit;
}
input[type=text].wide { min-width: 320px; }
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; font: inherit; cursor: pointer; font-weight: 600;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #07101f; border-color: var(--accent); }
label.fld { display: inline-flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
/* small, understated pill toggle for minor options */
button.minitoggle { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; }
button.minitoggle:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
button.minitoggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
input[type=range] { accent-color: var(--accent); }

/* token chips (named .chip to avoid clashing with the generation demo's .tok) */
.chip {
  display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  border-radius: 5px; padding: 4px 8px; margin: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--panel-2); border: 1px solid var(--border);
}
.chip .id { color: var(--muted); font-size: 10px; }
.chip.hot { border-color: var(--green-2); }

/* heatmap (one flex row per matrix row) */
.heatmap { display: inline-flex; flex-direction: column; gap: 3px; }
.heatmap .hrow { display: flex; gap: 2px; align-items: center; border: 2px solid transparent; border-radius: 7px; padding: 1px 3px; transition: opacity .15s; }
.heatmap .hrow.mark { border-color: var(--green-2); background: rgba(126, 231, 135, .14); }
/* when some rows are highlighted, fade the rest so the matches stand out */
.heatmap .hrow.dim { opacity: .28; }
.heatmap .cell { flex: none; width: var(--cs, 26px); height: var(--cs, 26px); border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-variant-numeric: tabular-nums; color: #0c1117; }
/* corner + row labels share the SAME font so the `ch`-based width resolves to
   identical pixels in the header and the data rows — otherwise the column
   headers shift sideways relative to the columns. */
.heatmap .rowlab, .heatmap .corner { flex: none; width: var(--lw, 6ch); font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.heatmap .rowlab { color: var(--muted); padding-right: 8px; text-align: right; white-space: nowrap; }
.heatmap .rowlab.rowlab-el { padding: 0 8px 0 0; display: flex; align-items: center; justify-content: flex-start; }
.heatmap .hrow.mark .rowlab { color: var(--green-2); font-weight: 700; }
.heatmap .collab { flex: none; width: var(--cs, 26px); color: var(--muted); font-size: 10px; text-align: center; }

/* per-row vector list: E("dog") → [0.89, 1.16, ...] */
.vec-list { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; overflow-x: auto; }
.vec-list[hidden] { display: none; }
.vec-list .vrow { white-space: nowrap; color: var(--text); }
.vec-list .vrow .lab { color: var(--accent); }
.vec-list .vrow .arr { color: var(--muted); margin: 0 8px; }
.vec-list .vrow.hot .lab { color: var(--green-2); font-weight: 700; }

/* labeled matrix axes (Input rows / Meaning columns) */
.mat-wrap { display: inline-grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 6px 8px; align-items: center; margin: 4px 0 2px; max-width: 100%; }
.mat-axis-x { grid-column: 2; grid-row: 1; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.mat-axis-y { grid-column: 1; grid-row: 2; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; writing-mode: vertical-rl; justify-self: center; }
.mat-body { grid-column: 2; grid-row: 2; overflow: auto; max-width: 100%; }

/* stepper */
.stepper { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.stepper input[type=range] { flex: 1; }
.stepper .lab { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* scatter / vector plots (SVG) */
.plot { width: 100%; height: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.plot .grid { stroke: var(--border); stroke-width: 1; }
.plot .pt { fill: var(--accent); transition: opacity .15s; }
.plot .pt.dim { opacity: .12; }
.plot .pt.hot { fill: var(--accent); }
.plot .ptlab { fill: var(--text); font-size: 11px; font-family: ui-monospace, monospace; transition: opacity .15s; }
.plot .ptlab.dim { opacity: .12; }
.plot .ptlab.hot { font-weight: 700; font-size: 13px; }
.plot .axis { stroke: var(--muted); stroke-width: 1.5; }
.plot .axislab { fill: var(--muted); font-size: 11px; }
.plot .vec { stroke: var(--orange); stroke-width: 2.5; fill: none; }
.plot .result { fill: var(--green-2); }

/* equations */
.eq { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--panel-2); padding: 8px 12px; border-radius: 6px; display: inline-block; font-size: 13px; }
.eq .hl { color: var(--accent); }
.dims { color: var(--muted); font-size: 12px; }
.legend { display: inline-flex; gap: 14px; color: var(--muted); font-size: 12px; align-items: center; flex-wrap: wrap; }
.legend[hidden] { display: none; }
.legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---- progressive reveal ("build") on single-page stations ---- */
/* every buildable section animates between lit and dimmed; dimmed sections stay
   laid out (no layout shift) but recede so the revealed content reads clearly. */
.build { transition: opacity .45s ease, filter .45s ease; }
.build.dim { opacity: .24; filter: saturate(.55); cursor: pointer; }
.build.dim:hover { opacity: .42; }     /* hint that a dimmed panel is clickable */
.rev-hint { color: var(--muted); font-size: 12px; margin: 2px 0 18px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rev-hint kbd { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; font-family: inherit; font-size: 11px; }
