:root {
  --bg: #ffffff;
  --fg: #1b1f24;
  --muted: #5b6470;
  --border: #dde1e6;
  --surface: #f5f7f9;
  --accent: #2166ac;
  --accent-fg: #ffffff;
  --todo: #b45309;
  --series-2: #c2410c;
  --max-width: 980px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111418;
    --fg: #e6e8eb;
    --muted: #9aa3ad;
    --border: #2b3138;
    --surface: #1a1f25;
    --accent: #6aa7e0;
    --accent-fg: #0b1220;
    --todo: #f59e0b;
    --series-2: #f59e0b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111418;
  --fg: #e6e8eb;
  --muted: #9aa3ad;
  --border: #2b3138;
  --surface: #1a1f25;
  --accent: #6aa7e0;
  --accent-fg: #0b1220;
  --todo: #f59e0b;
  --series-2: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

header, main, footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

.theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--muted); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
.theme-toggle .icon-sun circle { fill: currentColor; stroke: none; }
.theme-toggle[aria-pressed="false"] .icon-sun,
.theme-toggle[aria-pressed="true"] .icon-moon { display: none; }

.hero { text-align: center; padding-top: 56px; padding-bottom: 16px; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.2; margin: 0 0 16px; letter-spacing: -0.01em; }
.authors { font-size: 1.1rem; margin: 0; }
.affiliations { color: var(--muted); margin: 4px 0 20px; font-size: 0.95rem; }

.links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.button {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  text-decoration: none;
  font-weight: 500;
}
.button:hover { opacity: 0.85; }

section { padding: 24px 0; }
h2 { font-size: 1.5rem; margin: 0 0 12px; }
h3 { font-size: 1.15rem; margin: 32px 0 4px; }
p { margin: 0 0 12px; }
.todo { color: var(--todo); font-style: italic; }

figure { margin: 0; }
.cover img { width: 100%; height: auto; display: block; border-radius: 8px; background: #fff; }
figcaption { color: var(--muted); font-size: 0.92rem; margin-top: 8px; }

/* --- explorer --- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 20px 32px;
  align-items: flex-end;
  padding: 16px;
  margin: 20px 0 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.control { display: flex; flex-direction: column; gap: 6px; }
.control:first-child { flex: 1 1 260px; }
.control label, .control .label { font-weight: 600; font-size: 0.95rem; }
.k-value { font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 400; margin-left: 6px; color: var(--accent); }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
.ticks { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); padding: 0 4px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  font: inherit;
  font-size: 0.92rem;
  padding: 6px 14px;
  border: 0;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-fg); }

button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 640px) { .panels { grid-template-columns: 1fr; } }
.panel canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  display: block;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
  background: #e6e6e6;
}
.panel figcaption { text-align: center; }

.legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 12px; }
.ramp {
  width: 140px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(to right, #f7fbff, #deebf7, #c6dbef, #9ecae1, #6baed6, #4292c6, #2171b5, #08519c, #08306b);
}
.legend-note { margin-left: 8px; }
.status { font-size: 0.85rem; color: var(--muted); min-height: 1.4em; margin-top: 8px; }

.bars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; align-items: end; height: 180px; margin-top: 12px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; cursor: pointer; }
.bar .fill { width: 100%; max-width: 64px; background: var(--border); border-radius: 6px 6px 0 0; transition: background 0.15s; }
.bar.active .fill { background: var(--accent); }
.bar .value { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.85rem; }
.bar .name { font-size: 0.85rem; color: var(--muted); }

/* --- spectrum --- */
.check { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; cursor: pointer; padding-bottom: 6px; }
.check input { accent-color: var(--accent); margin: 0; }

.spectrum-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 640px) { .spectrum-layout { grid-template-columns: 1fr; } }
.spectrum-plot svg { width: 100%; display: block; cursor: crosshair; touch-action: pan-y; font-family: inherit; }
.spectrum-plot figcaption { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
.spectrum-plot .readout { flex-basis: 100%; color: var(--fg); }

#spec-plot .grid { stroke: var(--border); stroke-width: 1; }
#spec-plot .axis { stroke: var(--muted); stroke-width: 1; }
#spec-plot .tick { fill: var(--muted); font-size: 11px; }
#spec-plot .axis-label { fill: var(--muted); font-size: 12px; }
#spec-plot .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
#spec-plot .ref-label { fill: var(--muted); font-size: 11px; }
#spec-plot .points circle { fill: var(--accent); }
#spec-plot .ghost circle { fill: var(--muted); opacity: 0.3; }
#spec-plot .sv circle { fill: none; stroke: var(--series-2); stroke-width: 1.2; }
#spec-plot .curve { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: 0.6; }
#spec-plot .ghost-curve { fill: none; stroke: var(--muted); stroke-width: 1.5; opacity: 0.35; }
#spec-plot .marks circle { fill: none; stroke: var(--fg); stroke-width: 1; opacity: 0.5; }
#spec-plot .highlight { fill: none; stroke: var(--fg); stroke-width: 2; pointer-events: none; }

.key { display: inline-flex; align-items: center; gap: 6px; }
.key .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.key .dot.ghost { background: var(--muted); opacity: 0.4; }
.key .dot.sv { background: none; border: 1.5px solid var(--series-2); }

.eigvec-panel canvas { cursor: default; }

.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; margin-top: 20px; }
@media (max-width: 640px) { .thumbs { grid-template-columns: 1fr; } }
.thumb-title { font-weight: 600; font-size: 0.9rem; }
.thumb-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px;
  font: inherit;
  color: var(--fg);
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.thumb canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 4px; opacity: var(--weight, 1); transition: opacity 0.15s; }
.thumb.active { border-color: var(--accent); }
.thumb-name { font-size: 0.8rem; }
.thumb-mu { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.75rem; color: var(--muted); }

.ramp.diverging {
  background: linear-gradient(to right, #053061, #2166ac, #4393c3, #92c5de, #d1e5f0, #f7f7f7, #fddbc7, #f4a582, #d6604d, #b2182b, #67001f);
}

.bibtex {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px;
  margin: 0;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bibtex code { font: inherit; }
/* one field per line, wrapped lines indented under their field */
.bibtex .f { display: block; padding-left: 2.4em; text-indent: -1.2em; }

footer { color: var(--muted); font-size: 0.85rem; padding-top: 24px; padding-bottom: 40px; border-top: 1px solid var(--border); margin-top: 24px; }

/* --- TL;DR --- */
.tldr { padding-top: 8px; }
.tldr-text { font-size: 1.08rem; max-width: 760px; margin: 0 auto 16px; }
.tldr-strip { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 16px; align-items: center; max-width: 820px; margin: 0 auto; }
@media (max-width: 640px) { .tldr-strip { grid-template-columns: 1fr; } .tldr-arrow .arrow { transform: rotate(90deg); } }
.tldr-strip figcaption { font-size: 0.88rem; }
.tldr-bars { width: 100%; height: auto; display: block; font-family: inherit; }
.tldr-bars .kept { fill: var(--accent); }
.tldr-bars .cut { fill: var(--series-2); opacity: 0.75; }
.tldr-bars .rank { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 3 3; }
.tldr-bars .rank-label { fill: var(--fg); font-size: 9px; }
.tldr-bars .base { stroke: var(--muted); stroke-width: 1; }
.tldr-bars .axis { fill: var(--muted); font-size: 8.5px; }
.tldr-arrow { display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--muted); font-size: 0.85rem; max-width: 130px; margin: 0 auto; }
.tldr-arrow .arrow { font-size: 1.8rem; line-height: 1; color: var(--fg); }

details.abstract summary { cursor: pointer; list-style: none; }
details.abstract summary::-webkit-details-marker { display: none; }
details.abstract summary h2 { display: inline; }
details.abstract summary::after { content: " ▸"; color: var(--muted); font-size: 1.2rem; }
details.abstract[open] summary::after { content: " ▾"; }
details.abstract[open] summary { margin-bottom: 12px; }

/* --- reading hints --- */
.hint { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; font-size: 0.95rem; }
.hint b { color: var(--accent); }
.bridge { text-align: center; color: var(--muted); font-weight: 600; margin-top: 28px; }
.muted { color: var(--muted); }

#spec-plot .cut-region { fill: var(--series-2); opacity: 0.08; }
#spec-plot .rank-line { stroke: var(--series-2); stroke-width: 1.5; stroke-dasharray: 5 3; }
#spec-plot .rank-label { fill: var(--series-2); font-size: 11px; font-weight: 600; }
#spec-plot .rank-label.muted { font-weight: 400; }

/* --- page structure --- */
html { scroll-behavior: smooth; }
section[id] { scroll-margin-top: 64px; }
main > section { padding: 0; margin: 64px 0; }
main > section:not(.card) + section:not(.card) { border-top: 1px solid var(--border); padding-top: 48px; }

.toc {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 16px;
  margin-top: 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.toc a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.toc a:hover { color: var(--fg); background: var(--surface); }
.toc a.active { color: var(--accent-fg); background: var(--accent); }
.toc a.active .num { background: var(--accent-fg); color: var(--accent); }

.card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  background: var(--bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
}
@media (max-width: 640px) { .card { padding: 18px 14px; border-radius: 12px; } }
.tldr.card { background: var(--surface); }
.tldr .tldr-text { margin-bottom: 20px; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.num {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.75rem;
  letter-spacing: 0;
}
main h2 { font-size: 1.6rem; letter-spacing: -0.01em; margin-bottom: 14px; }
.card h3 { padding-top: 24px; border-top: 1px dashed var(--border); }

details.abstract { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
details.abstract summary h2 { font-size: 1.15rem; }

.bridge { margin: -28px 0; font-size: 1rem; }
@media (max-width: 640px) {
  .toc { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; padding: 8px 12px; }
  .toc::-webkit-scrollbar { display: none; }
  .toc a { flex: none; padding: 4px 10px; font-size: 0.85rem; }
  main h2 { font-size: 1.35rem; }
}

/* --- cover figure guide --- */
.lead { font-size: 1.05rem; max-width: 820px; margin-bottom: 20px; }
.cover-grid { display: grid; grid-template-columns: minmax(0, 1fr) 28px; gap: 10px; }
.cover-img { position: relative; }
/* outline around the learned-Q row (row 4, the three panels right of the divider) in cover.png */
.cover-focus {
  position: absolute;
  left: 41.6%;
  top: 74.6%;
  width: 58.6%;
  height: 25%;
  border: 2.5px dashed var(--series-2);
  border-radius: 10px;
  pointer-events: none;
}
.cover-groups { display: grid; grid-template-rows: 49fr 51fr; gap: 10px; }
.cover-groups .group {
  writing-mode: vertical-rl;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 2px solid var(--border);
  padding-left: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}
.cover-groups .group.learned { border-left-color: var(--series-2); color: var(--series-2); }
.cover + .hint { margin-top: 16px; }
.hint ul { margin: 4px 0 0; padding-left: 20px; }
.hint li { margin: 2px 0; }
@media (max-width: 640px) {
  .cover-grid { grid-template-columns: minmax(0, 1fr) 20px; gap: 6px; }
  .cover-groups .group { font-size: 0.68rem; padding-left: 3px; }
}

/* --- copy BibTeX --- */
.bibtex-wrap { position: relative; }
.bibtex-wrap .bibtex { padding-right: 56px; }
.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.copy-btn:hover { color: var(--fg); border-color: var(--muted); }
.copy-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.copy-btn .icon-check { display: none; }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied .icon-copy { display: none; }
.copy-btn.copied .icon-check { display: block; }
.copy-label:empty { display: none; }
