/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --paper: #fbfaf6;
  --paper-2: #f3f1ea;
  --ink: #1f1d19;
  --ink-2: #534e46;
  --ink-3: #7d776c;
  --rule: #d9d4c7;
  --link: #9a3a1c;
  --accent: #a8401f;
  --bar: #2b2924;
  --bar-mid: #8d877b;
  --bar-light: #e2ddd1;
  --hl: rgba(168, 64, 31, 0.16);
  --code-bg: #efece3;
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #171613;
    --paper-2: #1f1e1a;
    --ink: #e8e4d8;
    --ink-2: #b9b3a5;
    --ink-3: #8a8477;
    --rule: #36332c;
    --link: #e8916f;
    --accent: #e07a55;
    --bar: #ddd8cb;
    --bar-mid: #8a8477;
    --bar-light: #34312a;
    --hl: rgba(224, 122, 85, 0.22);
    --code-bg: #24231e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171613;
  --paper-2: #1f1e1a;
  --ink: #e8e4d8;
  --ink-2: #b9b3a5;
  --ink-3: #8a8477;
  --rule: #36332c;
  --link: #e8916f;
  --accent: #e07a55;
  --bar: #ddd8cb;
  --bar-mid: #8a8477;
  --bar-light: #34312a;
  --hl: rgba(224, 122, 85, 0.22);
  --code-bg: #24231e;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.6 var(--serif);
  font-variant-numeric: tabular-nums lining-nums;
  border-top: 4px solid var(--ink);
}
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
code, pre, .mono { font-family: var(--mono); }
code { font-size: 0.84em; background: var(--code-bg); padding: 0.08em 0.3em; overflow-wrap: anywhere; }
pre { margin: 0 0 1em; }
h1, h2, h3 { font-weight: 600; line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.75rem, 4.6vw, 2.4rem); letter-spacing: -0.005em; }
h2 { font-size: 1.45rem; margin-top: 3.25rem; padding-top: 0.6rem; border-top: 2px solid var(--ink); }
h3 { font-size: 1.08rem; margin-top: 2em; }
p { margin: 0 0 1em; }
sup { font-size: 0.7em; line-height: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--ink-2); }
.measure, .prose > :not(h2) { max-width: 40em; }
.secnum { display: inline-block; min-width: 2.1em; color: var(--ink-3); font-weight: 400; }
h3 .secnum { min-width: 2.6em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--paper); padding: 8px 12px; z-index: 20; }
.skip:focus { left: 8px; top: 8px; }

.textbtn {
  font: inherit; color: var(--link); background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-decoration-style: dotted; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.textbtn:hover { text-decoration-style: solid; }

/* ---------- Masthead / colophon ---------- */
.masthead { border-bottom: 1px solid var(--rule); }
.masthead-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 20px; padding-top: 12px; padding-bottom: 10px; }
.site-title { font-weight: 600; color: var(--ink); text-decoration: none; }
nav { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px; margin-left: auto; font-size: 0.95rem; }
nav a { color: var(--ink-2); text-decoration: none; }
nav a:hover { color: var(--ink); text-decoration: underline; }
.theme-toggle { color: var(--ink-3); font-size: 0.9rem; }
.colophon { border-top: 1px solid var(--rule); margin-top: 4rem; padding: 1rem 0 2.5rem; color: var(--ink-3); font-size: 0.9rem; font-style: italic; }
.colophon p { margin: 0; }

/* ---------- Intro ---------- */
.intro { padding-top: 2.5rem; }
.byline { color: var(--ink-3); font-style: italic; font-size: 0.95rem; margin-top: -0.2em; }
.lede { font-size: 1.12rem; max-width: 36em; }

/* ---------- Lookup ---------- */
.lookup { margin: 2rem 0 0; padding: 14px 0 12px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.lookup-label { display: block; font-style: italic; color: var(--ink-2); font-size: 0.95rem; margin-bottom: 8px; }
.lookup-row { display: flex; align-items: baseline; gap: 16px; }
.lookup-row input {
  flex: 1; min-width: 0; font: 1.02rem var(--mono); color: var(--ink); background: var(--paper);
  border: 1px solid var(--ink-3); border-radius: 0; padding: 7px 10px;
}
.lookup-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.lookup-out {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px;
  margin: 16px 0 4px; min-height: 2.2rem; font-family: var(--mono);
}
.lk-from { color: var(--ink-2); font-size: 1.05rem; overflow-wrap: anywhere; }
.lk-arrow { color: var(--ink-3); font-size: 1.2rem; display: inline-block; }
.lk-to { font-size: clamp(1.25rem, 3.4vw, 1.6rem); font-weight: 600; color: var(--ink); overflow-wrap: anywhere; padding: 0 3px; margin: 0 -3px; }
.lk-to .scr { color: var(--accent); font-weight: 400; }
.lk-to.miss { font-family: var(--serif); font-style: italic; font-weight: 400; color: var(--ink-3); }
.lk-to.flash { animation: lk-flash 1.1s ease-out; }
@keyframes lk-flash { from { background: var(--hl); } to { background: transparent; } }
.lookup-out.busy .lk-arrow { color: var(--accent); animation: lk-nudge 0.7s ease-in-out infinite; }
@keyframes lk-nudge { 0%, 100% { transform: translateX(-2px); } 50% { transform: translateX(3px); } }
.lk-copy { font-size: 0.85rem; font-family: var(--serif); align-self: center; }
.lookup-meta {
  margin: 0; min-height: 1.6em; font-size: 0.95rem; color: var(--ink-2);
  opacity: 0; transition: opacity 0.35s ease;
}
.lookup-meta.show { opacity: 1; }
.lookup-try { margin: 10px 0 0; font-size: 0.88rem; color: var(--ink-3); }
.lookup-try .textbtn { font-family: var(--mono); font-size: 0.82rem; }
@media (prefers-reduced-motion: reduce) {
  .lookup-out.busy .lk-arrow, .lk-to.flash { animation: none; }
  .lookup-meta { transition: none; }
}

/* ---------- Progress ---------- */
.load-error { border-left: 3px solid #c0392b; padding: 4px 14px; margin-bottom: 16px; }
.load-error p { margin: 0; }
.headline { display: flex; align-items: center; gap: 8px 24px; flex-wrap: wrap; margin: 0.5rem 0 0.75rem; }
.headline-pct { font-size: clamp(2.8rem, 8vw, 3.6rem); font-weight: 600; line-height: 1; margin: 0; letter-spacing: -0.02em; }
.headline-text { margin: 0; flex: 1 1 20em; }
.meter-block { margin: 0 0 2.25rem; }
.meter-ceil-label { position: relative; height: 26px; }
.meter-ceil-label span {
  position: absolute; left: 60%; width: 10%; bottom: 0; height: 7px;
  border: 1px solid var(--ink-3); border-bottom: 0;
}
.meter-ceil-label span { font-size: 0; }
.meter-ceil-label::after {
  content: "estimated ceiling"; position: absolute; left: 65%; bottom: 9px; transform: translateX(-50%);
  white-space: nowrap; font-size: 0.8rem; font-style: italic; color: var(--ink-3);
}
.meter { position: relative; height: 10px; background: var(--bar-light); }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--bar); }
.meter-ceiling { position: absolute; top: 0; bottom: 0; left: 60%; width: 10%; border-left: 1px solid var(--ink-3); border-right: 1px solid var(--ink-3); }
.meter-scale { position: relative; display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--ink-3); margin-top: 3px; }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 40px; }
.fig { margin: 0 0 2rem; }
.fig figcaption { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--rule); font-size: 0.88rem; color: var(--ink-2); line-height: 1.5; }
.fignum { font-weight: 600; color: var(--ink); }

.hbars { display: grid; gap: 7px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 9em) minmax(0, 1fr); align-items: center; gap: 2px 12px; }
.hbar-label { font-size: 0.93rem; line-height: 1.3; overflow-wrap: anywhere; }
.hbar-body { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hbar-track { flex: 1; height: 9px; background: var(--bar-light); display: flex; gap: 1px; }
.hbar-track.bare { background: transparent; }
.seg { height: 100%; min-width: 2px; }
.hbar-value { font-size: 0.88rem; color: var(--ink-2); white-space: nowrap; min-width: 6.2em; text-align: right; }
.hbar-value strong { color: var(--ink); font-weight: 600; }
.hbar:hover .hbar-label { text-decoration: underline; text-decoration-color: var(--ink-3); }
.history .hbar { grid-template-columns: minmax(120px, 18em) minmax(0, 1fr); }
.history .hbar-value { min-width: 8.5em; }
.seg.kind, .seg.rel-reliable, .seg.hist-added { background: var(--bar); }
.seg.rel-measured { background: var(--bar-mid); }
.seg.rel-unmeasured { background: repeating-linear-gradient(135deg, var(--bar-mid) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px var(--bar-mid); }
.seg.hist-before { background: var(--bar-mid); opacity: 0.45; }

.tip {
  position: fixed; z-index: 30; pointer-events: none;
  background: var(--paper); color: var(--ink); border: 1px solid var(--ink);
  padding: 5px 9px; font-size: 0.85rem; line-height: 1.4; max-width: 280px;
}

/* ---------- Prose ---------- */
.prose h3 + p { margin-top: 0; }
pre.examples { background: var(--code-bg); padding: 10px 14px; overflow-x: auto; font-size: 0.88rem; line-height: 1.6; }
pre.examples code { background: none; padding: 0; font-size: inherit; }

/* ---------- Names table ---------- */
.filters { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin: 1.25rem 0 6px; }
.filters label { display: block; min-width: 0; }
.filters input, .filters select {
  width: 100%; font: inherit; font-size: 0.95rem; color: var(--ink); background: var(--paper);
  border: 1px solid var(--ink-3); border-radius: 0; padding: 6px 9px;
}
.filters input { font-family: var(--mono); font-size: 0.9rem; }
.filters input:focus, .filters select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.count { font-size: 0.88rem; color: var(--ink-3); font-style: italic; margin: 0 0 6px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.names { font-size: 0.92rem; border-bottom: 2px solid var(--ink); }
.names th, .names td { text-align: left; padding: 5px 14px 5px 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
.names thead th { border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); padding: 0; background: var(--paper); }
.names th button {
  font: inherit; font-weight: 600; color: var(--ink); background: none; border: 0;
  padding: 6px 14px 6px 0; width: 100%; text-align: left; cursor: pointer; white-space: nowrap;
}
.names th button[aria-sort="ascending"]::after { content: " ↑"; color: var(--ink-3); font-weight: 400; }
.names th button[aria-sort="descending"]::after { content: " ↓"; color: var(--ink-3); font-weight: 400; }
.names td.n { font-family: var(--mono); font-size: 0.88rem; overflow-wrap: anywhere; }
.names td.h { font-family: var(--mono); font-size: 0.85rem; color: var(--ink-2); white-space: nowrap; }
.names td.k, .names td.m { color: var(--ink-2); white-space: nowrap; }
.names mark { background: var(--hl); color: inherit; }
.meth sup { color: var(--accent); margin-left: 1px; }
.more { display: block; margin: 12px 0 0; font-size: 0.95rem; }
.notes { margin: 1.5rem 0 0; font-size: 0.9rem; max-width: 40em; }
.notes div { display: grid; grid-template-columns: 10.5em minmax(0, 1fr); gap: 12px; margin-bottom: 4px; }
.notes dt { font-style: italic; }
.notes dt sup { color: var(--accent); }
.notes dd { margin: 0; color: var(--ink-2); }
.notes.accuracy { margin: -0.25rem 0 1.25rem; font-size: 0.95rem; }
.notes.accuracy div { grid-template-columns: 12em minmax(0, 1fr); margin-bottom: 8px; }

/* ---------- Credits ---------- */
.credits { font-size: 0.9rem; margin: 0 0 1.5em; border-bottom: 2px solid var(--ink); }
.credits th, .credits td { text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.credits thead th { border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); font-weight: 600; }
.credits td a { overflow-wrap: anywhere; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  body { font-size: 16px; }
  nav { margin-left: 0; width: 100%; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .hbar, .history .hbar { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filters .f-search { grid-column: 1 / -1; }
  .notes div, .notes.accuracy div { grid-template-columns: minmax(0, 1fr); gap: 0; margin-bottom: 8px; }
  .lookup-out { gap: 2px 10px; }
  /* names table: one stacked block per row */
  .names thead tr { display: flex; flex-wrap: wrap; }
  .names thead th { flex: 1 1 auto; }
  .names tbody tr { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 0 12px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
  .names td { border: 0; padding: 0; }
  .names td.n { grid-column: 1 / -1; }
  .names td.m { justify-self: end; }
  /* credits table: stacked */
  .credits thead { display: none; }
  .credits tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
  .credits td { border: 0; padding: 0; }
  .credits td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; color: var(--ink-2); }
  .credits td:nth-child(3) { grid-row: 1; grid-column: 2; text-align: right; color: var(--ink-2); max-width: 9.5em; }
}
