/* ============================================================
   sort·bench explorer — "A proof that terminates in a measurement"
   Deep-indigo oscilloscope ground · chalk ink · verification gold.
   IBM Plex Mono display (machine voice) · Spectral prose · Plex Sans UI.
   OKLCH throughout. Class/var names preserved for JS + chart compatibility.
   ============================================================ */

:root {
  /* Surfaces — deep indigo-slate "chalkboard / oscilloscope" */
  --paper: oklch(0.20 0.03 264);
  --surface: oklch(0.235 0.028 264);
  --surface-2: oklch(0.27 0.024 264);
  --surface-sunk: oklch(0.175 0.034 264);

  /* Ink — warm chalk through cool label grey */
  --ink: oklch(0.93 0.012 80);
  --ink-2: oklch(0.78 0.014 264);
  --ink-3: oklch(0.58 0.018 264);

  /* Hairlines — cool indigo */
  --line: oklch(0.30 0.032 264);
  --line-2: oklch(0.38 0.030 264);

  /* Signal accent — verification gold (used only for proof marks, links,
     active controls; never as background fill) */
  --accent: oklch(0.80 0.13 78);
  --accent-ink: oklch(0.84 0.13 78);
  --accent-wash: oklch(0.26 0.07 78);
  --accent-line: oklch(0.52 0.10 78);

  /* Series palette — luminous traces on dark ground. Matches palette.js.
     s8 doubles as error colour (boot failure). */
  --s0: oklch(0.72 0.17 252);
  --s1: oklch(0.74 0.15 33);
  --s2: oklch(0.74 0.12 192);
  --s3: oklch(0.79 0.14 82);
  --s4: oklch(0.68 0.18 322);
  --s5: oklch(0.73 0.15 148);
  --s6: oklch(0.70 0.19 295);
  --s7: oklch(0.75 0.15 52);
  --s8: oklch(0.70 0.15 25);
  --s9: oklch(0.76 0.14 358);

  /* Type */
  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r-sm: 2px;
  --r-md: 3px;
  --r-lg: 4px;

  --shadow-1: 0 1px 2px oklch(0.0 0.0 0 / 0.20);
  --shadow-2: 0 20px 56px -16px oklch(0.0 0.0 0 / 0.72),
    0 4px 14px -4px oklch(0.0 0.0 0 / 0.40);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-1: 0.16s;
  --dur-2: 0.36s;

  --z-sticky: 100;
  --z-overlay: 800;

  color-scheme: dark;
}

/* ---------- reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
* {
  margin: 0;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent-ink);
  text-decoration: none;
  text-underline-offset: 2px;
  text-decoration-color: var(--accent-line);
}
a:hover {
  text-decoration: underline;
}
code {
  font-family: var(--mono);
  font-size: 0.9em;
}
.tnum {
  font-variant-numeric: tabular-nums;
}

::selection {
  background: var(--accent-wash);
  color: var(--ink);
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
   Boot overlay
   ============================================================ */
.boot {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.5rem;
  background: var(--paper);
  transition: opacity var(--dur-2) var(--ease),
    visibility var(--dur-2) var(--ease);
}
.boot.done {
  opacity: 0;
  visibility: hidden;
}

.boot-proof {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.boot-turnstile {
  font-family: var(--mono);
  font-size: 2.2rem;
  color: var(--accent);
  line-height: 1;
  animation: turnstile-pulse 2s var(--ease) infinite;
}
@keyframes turnstile-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.boot-mark {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  width: 44px;
}
.boot-mark span {
  height: 6px;
  border-radius: 2px;
  background: var(--ink-3);
  transform-origin: left;
  animation: bootbar 1.2s var(--ease) infinite;
}
.boot-mark span:nth-child(1) { width: 40%; animation-delay: 0s; }
.boot-mark span:nth-child(2) { width: 60%; animation-delay: 0.12s; }
.boot-mark span:nth-child(3) { width: 80%; animation-delay: 0.24s; }
.boot-mark span:nth-child(4) { width: 100%; animation-delay: 0.36s; background: var(--accent); }

@keyframes bootbar {
  0%, 100% { transform: scaleX(0.35); }
  50% { transform: scaleX(1); }
}

.boot-title {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.boot-title i {
  font-style: normal;
  color: var(--accent);
}
.boot-status {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--ink-3);
}

/* ============================================================
   Masthead / Theorem Hero
   ============================================================ */
.masthead {
  max-width: 1280px;
  margin-inline: auto;
  padding: 2.8rem clamp(1rem, 4vw, 2.75rem) 0;
}

.masthead-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem 1.8rem;
  margin-bottom: 2rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  letter-spacing: -0.02em;
  line-height: 1;
}
.wordmark:hover {
  text-decoration: none;
}
.wordmark i {
  font-style: normal;
  color: var(--accent);
  margin-inline: -0.02em;
}
.wordmark-glyph {
  width: clamp(1rem, 2.2vw, 1.3rem);
  height: auto;
  fill: var(--accent);
  flex: none;
}

.hero-eyebrow {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--ink-3);
  line-height: 1.4;
}

/* ------ Theorem block ------ */
.theorem {
  display: flex;
  gap: 1.4rem;
  align-items: flex-start;
  padding: 1.8rem clamp(1.2rem, 3vw, 2.2rem);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background-image: linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% 1.75rem;
  background-position: 0 0.5rem;
  position: relative;
  overflow: hidden;
  margin-bottom: 1.4rem;
}
.theorem::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 100% 120% at 50% 50%,
    transparent 40%,
    var(--surface) 100%
  );
  pointer-events: none;
}

.thm-spine {
  font-family: var(--mono);
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  font-weight: 400;
  color: var(--accent);
  line-height: 1;
  flex: none;
  padding-top: 0.15rem;
  user-select: none;
  position: relative;
  z-index: 1;
}

.thm-body {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  position: relative;
  z-index: 1;
  min-width: 0;
}

.thm-sig {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-3);
  letter-spacing: 0.01em;
  margin-bottom: 0.5rem;
}
.thm-kw { color: var(--accent); font-weight: 500; }
.thm-name { color: var(--ink); font-weight: 600; }
.thm-punct { color: var(--ink-3); }

.thm-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
}

.thm-q {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--ink-3);
  white-space: nowrap;
}

.thm-prop {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  color: var(--ink);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.thm-and {
  font-family: var(--mono);
  font-size: clamp(1.0rem, 2vw, 1.35rem);
  color: var(--accent);
  font-weight: 500;
  align-self: center;
}

.thm-qed {
  font-family: var(--mono);
  font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  color: var(--accent);
  font-weight: 600;
  margin-left: 0.4rem;
}

.thm-tag {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  vertical-align: middle;
}
.thm-tag--proof {
  background: var(--accent-wash);
  color: var(--accent-ink);
  border: 1px solid var(--accent-line);
}
.thm-tag--meas {
  background: var(--surface-2);
  color: var(--ink-3);
  border: 1px solid var(--line-2);
}

.hero-gloss {
  max-width: 72ch;
  font-family: var(--serif);
  font-size: 1.0rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 1.8rem;
  text-wrap: pretty;
}
.hero-gloss em {
  font-style: normal;
  color: var(--accent-ink);
}

.corpus {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 0 2rem;
  padding: 1.2rem 0 1.4rem;
  border-top: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line);
}
.corpus div {
  display: flex;
  flex-direction: column;
}
.corpus dt {
  order: 2;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-family: var(--sans);
  font-weight: 500;
  margin-top: 0.15rem;
}
.corpus dd {
  order: 1;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.05;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--ink);
}

/* ============================================================
   App layout
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: minmax(248px, 286px) minmax(0, 1fr);
  gap: clamp(1.25rem, 3vw, 2.6rem);
  align-items: start;
  max-width: 1280px;
  margin-inline: auto;
  padding: 0.6rem clamp(1rem, 4vw, 2.75rem) 1rem;
}
.app[hidden] {
  display: none;
}

/* ---------- controls / instrument panel ---------- */
.controls {
  position: sticky;
  top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  padding-right: clamp(1rem, 2vw, 1.75rem);
  border-right: 1px solid var(--line);
  max-height: calc(100vh - 2.5rem);
  overflow: auto;
  animation: rise var(--dur-2) var(--ease) both;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.field.grow {
  flex: 1;
  min-height: 0;
}
.field-label,
.field-label-row .field-label {
  font-family: var(--sans);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.field-hint {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-3);
  font-family: var(--serif);
}

/* colab badge link */
.colab-link {
  display: inline-flex;
  border-radius: var(--r-sm);
  opacity: 0.85;
  transition: opacity var(--dur-1) var(--ease);
}
.colab-link:hover {
  opacity: 1;
  text-decoration: none;
}
.colab-link img {
  display: block;
  height: 20px;
  width: auto;
}

/* native select */
.select-wrap {
  position: relative;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 0.85rem;
  top: 50%;
  width: 0.42rem;
  height: 0.42rem;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}
#study {
  appearance: none;
  width: 100%;
  padding: 0.55rem 2rem 0.55rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease);
}
#study:hover {
  border-color: var(--accent-line);
}
#study:focus-visible {
  border-color: var(--accent);
}

/* experiment radio list */
.exp-list {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.exp-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.48rem 0.6rem;
  text-align: left;
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.exp-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.exp-item .exp-tick {
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--line-2);
  transition: border-color var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease);
}
.exp-item[aria-checked="true"] {
  background: var(--accent-wash);
  color: var(--accent-ink);
  border-color: var(--accent-line);
  font-weight: 500;
}
.exp-item[aria-checked="true"] .exp-tick {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px var(--accent);
}
.exp-item .exp-name { flex: 1; }
.exp-item .exp-axis {
  flex: none;
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1rem 0.34rem;
  border-radius: 999px;
  background: var(--surface-sunk);
  color: var(--ink-3);
}
.exp-item[aria-checked="true"] .exp-axis {
  background: var(--accent-line);
  color: oklch(0.96 0.04 78);
}

/* per-array reduction toggle */
.reduce-toggle {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.48rem 0.7rem;
  font-family: var(--mono);
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.reduce-toggle:hover {
  border-color: var(--accent-line);
  color: var(--ink);
}
.reduce-active {
  font-size: 0.82rem;
  font-weight: 600;
}
.reduce-alt {
  font-size: 0.68rem;
  color: var(--ink-3);
}
.reduce-toggle[aria-pressed="true"] {
  color: oklch(0.18 0.02 78);
  background: var(--accent);
  border-color: var(--accent);
}
.reduce-toggle[aria-pressed="true"] .reduce-alt {
  color: oklch(0.22 0.04 78);
}

/* view toggles */
.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.toggle {
  flex: 1;
  padding: 0.42rem 0.3rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.toggle:hover {
  border-color: var(--accent-line);
  color: var(--ink);
}
.toggle[aria-pressed="true"] {
  color: oklch(0.18 0.02 78);
  background: var(--accent);
  border-color: var(--accent);
}
.toggle:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* series list */
.series-bulk {
  display: flex;
  gap: 0.35rem;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-3);
}
.series-bulk button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-ink);
  cursor: pointer;
  font: inherit;
}
.series-bulk button:hover {
  text-decoration: underline;
}
.series-list {
  display: flex;
  flex-direction: column;
  gap: 0.04rem;
  overflow: auto;
  max-height: 42vh;
  margin: -0.2rem;
  padding: 0.2rem;
}
.series-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.36rem 0.44rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  transition: background var(--dur-1) var(--ease);
}
.series-item:hover {
  background: var(--surface-2);
}
.series-swatch {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 0 1px oklch(1 0 0 / 0.1);
  transition: opacity var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease);
}
.series-meta {
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}
.series-lang {
  display: block;
  font-family: var(--mono);
  font-size: 0.60rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.series-alg {
  display: block;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.series-item[aria-pressed="false"] {
  opacity: 0.45;
}
.series-item[aria-pressed="false"] .series-swatch {
  background: var(--ink-3);
  opacity: 0.35;
  transform: scale(0.78);
}
.series-item[aria-pressed="false"] .series-alg {
  color: var(--ink-3);
  text-decoration: line-through;
  text-decoration-color: var(--line-2);
}

/* methodology */
.method {
  border-top: 1px solid var(--line);
  padding-top: 0.9rem;
}
.method summary {
  font-family: var(--sans);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.method summary::-webkit-details-marker { display: none; }
.method summary::before {
  content: "+";
  font-family: var(--mono);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 400;
}
.method[open] summary::before { content: "–"; }
.method p {
  margin-top: 0.65rem;
  font-family: var(--serif);
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--ink-2);
  max-width: 60ch;
  text-wrap: pretty;
}
.method b {
  color: var(--ink);
  font-weight: 600;
}

/* ============================================================
   Stage
   ============================================================ */
.stage {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  min-width: 0;
  animation: rise var(--dur-2) var(--ease) 0.06s both;
}
.stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line-2);
}
.stage-title {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(1.2rem, 2.6vw, 1.75rem);
  letter-spacing: -0.015em;
  line-height: 1.15;
  text-wrap: balance;
  color: var(--ink);
}
.stage-sub {
  margin-top: 0.5rem;
  max-width: 68ch;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 0.94rem;
  line-height: 1.5;
  text-wrap: pretty;
}
.stage-axis {
  flex: none;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-3);
  text-align: right;
  line-height: 1.8;
  padding-top: 0.35rem;
}
.stage-axis b {
  color: var(--ink);
  font-weight: 500;
}

/* chart */
.chart-frame {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.chart-plate {
  position: relative;
  padding: 1rem 1.1rem 0.7rem;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.chart {
  width: 100%;
  position: relative;
  z-index: 1;
}
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 1rem;
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  background: var(--surface-sunk);
  border-radius: var(--r-md);
  z-index: 2;
}
.chart-empty[hidden] { display: none; }
.fig-cap {
  font-family: var(--serif);
  font-size: 0.84rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--ink-3);
  max-width: 78ch;
  text-wrap: pretty;
  padding-left: 0.1rem;
}

/* ---------- uPlot theming ---------- */
.u-wrap { font-family: var(--mono); }
.uplot,
.uplot * { font-family: var(--mono); }
.u-axis { font-variant-numeric: tabular-nums; }
.u-legend {
  margin-top: 0.5rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
  font-size: 0.76rem;
  text-align: left;
}
.u-legend .u-series {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.12rem 0.55rem 0.12rem 0;
  cursor: pointer;
  vertical-align: middle;
}
.u-legend .u-series th {
  font-weight: 400;
  color: var(--ink-2);
  font-family: var(--mono);
}
.u-legend .u-series .u-value {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.u-legend .u-marker {
  width: 8px !important;
  height: 8px !important;
  border-radius: 2px;
  border: none !important;
}
.u-legend .u-series.u-off { opacity: 0.35; }
.u-legend .u-series.u-off .u-value { color: var(--ink-3); }
.u-legend .u-series:first-child { display: none; }
.u-cursor-pt { box-shadow: 0 0 0 2px var(--surface-sunk); }
.u-select { background: oklch(0.80 0.13 78 / 0.08); }

/* ============================================================
   Ranking — proof close "∎"
   ============================================================ */
.ranking {
  padding-top: 1.4rem;
  border-top: 1px solid var(--line-2);
}
.ranking-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}
.ranking-head h2 {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.0rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.ranking-head h2::before {
  content: "∎";
  color: var(--accent);
  font-size: 1.1em;
}
.ranking-head p {
  font-family: var(--mono);
  font-size: 0.70rem;
  color: var(--ink-3);
}
.ranking-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.rank-row {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1.3fr) minmax(64px, 1fr) auto;
  align-items: center;
  gap: 0.8rem;
  padding: 0.48rem 0;
  border-bottom: 1px solid var(--line);
}
.rank-row:first-child {
  border-top: 1px solid var(--line);
}
.rank-pos {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.rank-name {
  display: flex;
  align-items: center;
  gap: 0.52rem;
  min-width: 0;
}
.rank-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--c);
}
.rank-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--ink);
}
.rank-label .rank-lang {
  color: var(--ink-3);
  font-size: 0.76em;
}
.rank-bar-track {
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.rank-bar {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--c);
  transform-origin: left;
  transform: scaleX(var(--w));
  transition: transform var(--dur-2) var(--ease);
  box-shadow: 0 0 6px var(--c);
}
.rank-val {
  font-family: var(--mono);
  font-size: 0.80rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 8.5ch;
  color: var(--ink);
}
.rank-rel {
  display: block;
  font-family: var(--mono);
  font-size: 0.63rem;
  color: var(--ink-3);
}

/* ============================================================
   Distribution drawer (native <dialog>)
   ============================================================ */
.dist {
  width: min(620px, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  color: var(--ink);
}
.dist::backdrop {
  background: oklch(0.10 0.02 264 / 0.72);
  backdrop-filter: blur(3px);
}
.dist[open] {
  animation: distpop var(--dur-2) var(--ease);
}
@keyframes distpop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}
.dist-card { padding: 1.4rem 1.5rem 1.5rem; }
.dist-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.dist-id {
  display: flex;
  gap: 0.65rem;
  min-width: 0;
}
.dist-dotmark {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 0.55rem;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 6px var(--c);
}
.dist-lang {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.dist-title {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  line-height: 1.2;
  word-break: break-word;
  color: var(--ink);
}
.dist-close {
  flex: none;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 0.22rem 0.48rem;
  cursor: pointer;
  transition: color var(--dur-1) var(--ease),
    border-color var(--dur-1) var(--ease);
}
.dist-close:hover {
  color: var(--ink);
  border-color: var(--accent-line);
}
.dist-context {
  margin-top: 0.85rem;
  font-family: var(--serif);
  font-size: 0.92rem;
  color: var(--ink-2);
}
.dist-context b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.dist-svg {
  width: 100%;
  height: auto;
  margin: 0.5rem 0 0.2rem;
}
.dist-axis { stroke: var(--line-2); stroke-width: 1; }
.dist-tick { stroke: var(--line-2); stroke-width: 1; }
.dist-ticklabel {
  fill: var(--ink-3);
  font-family: var(--mono);
  font-size: 10px;
  text-anchor: middle;
}
.dist-whisker { stroke: var(--c); stroke-width: 1.5; opacity: 0.5; }
.dist-box {
  fill: var(--c);
  fill-opacity: 0.15;
  stroke: var(--c);
  stroke-width: 1.5;
  stroke-opacity: 0.9;
}
.dist-median { stroke: var(--c); stroke-width: 2.5; }
.dist-dot {
  fill: var(--c);
  fill-opacity: 0.65;
  stroke: var(--surface);
  stroke-width: 0.75;
}
.dist-stats {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
  margin: 0.9rem 0 0;
  padding: 0.8rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.dist-stats div {
  display: flex;
  flex-direction: column;
  gap: 0.14rem;
}
.dist-stats dt {
  font-family: var(--sans);
  font-size: 0.57rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.dist-stats dd {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.dist-foot {
  margin-top: 0.85rem;
  font-family: var(--serif);
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--ink-3);
  text-wrap: pretty;
}
.dist-foot b { color: var(--ink-2); font-weight: 600; }

@media (max-width: 520px) {
  .dist-stats {
    grid-template-columns: repeat(4, 1fr);
    row-gap: 0.7rem;
  }
}

/* ============================================================
   Colophon
   ============================================================ */
.colophon {
  max-width: 1280px;
  margin-inline: auto;
  padding: 1.5rem clamp(1rem, 4vw, 2.75rem) 3rem;
}
.colophon p {
  max-width: 72ch;
  font-family: var(--serif);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-3);
  border-top: 1px solid var(--line);
  padding-top: 1.2rem;
  text-wrap: pretty;
}

/* ============================================================
   Motion primitives
   ============================================================ */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .controls {
    position: static;
    max-height: none;
    padding-right: 0;
    padding-bottom: 1.4rem;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .series-list { max-height: none; }
  .theorem { flex-direction: column; gap: 0.8rem; }
  .thm-spine { font-size: 2rem; }
}
@media (max-width: 560px) {
  .corpus { grid-template-columns: repeat(2, auto); gap: 0.9rem 1.6rem; }
  .stage-axis { text-align: left; }
  .rank-row { grid-template-columns: 1.4rem auto 1fr; }
  .rank-bar-track { display: none; }
  .thm-prop { font-size: 0.95rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .boot.done { transition: opacity 0.001ms; }
}
