/* Base, typography, layout primitives */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--sans); font-feature-settings: 'ss01', 'cv11'; -webkit-font-smoothing: antialiased; min-height: 100vh; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration-color: var(--rule-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--accent); color: var(--bg); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

/* Masthead */
.masthead { border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); }
.masthead .wrap { display: flex; align-items: center; justify-content: space-between; gap: 24px; height: 64px; }
.wordmark { font: 400 20px/1 var(--serif); letter-spacing: .01em; text-decoration: none; white-space: nowrap; }
.wordmark em { font-style: italic; color: var(--ink-2); }
.nav { display: flex; gap: clamp(14px, 2.4vw, 34px); overflow-x: auto; scrollbar-width: none; }
.nav a { font: 500 11px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; text-decoration: none; color: var(--ink-2); padding: 8px 0; border-bottom: 1px solid transparent; white-space: nowrap; transition: color var(--t-fast); }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.nav a.primary { color: var(--ink); }

#main { padding-top: clamp(28px, 5vw, 64px); padding-bottom: 96px; }
.view { animation: viewIn var(--t-med) var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } * { transition-duration: 0ms !important; } }

/* Type */
.label { font: 500 11px/1.3 var(--sans); letter-spacing: .18em; text-transform: uppercase; color: var(--mute); }
.label.ink { color: var(--ink-2); }
.label.accent { color: var(--accent-ink); }
.kicker { font: 500 11px/1 var(--sans); letter-spacing: .22em; text-transform: uppercase; color: var(--accent-ink); }
.display { font: 400 clamp(44px, 7vw, 96px)/.95 var(--serif); letter-spacing: -.02em; margin: 0; }
.h1 { font: 400 clamp(34px, 4.6vw, 60px)/1.02 var(--serif); letter-spacing: -.015em; margin: 0; }
.h2 { font: 400 clamp(26px, 3vw, 36px)/1.1 var(--serif); letter-spacing: -.01em; margin: 0; }
.h3 { font: 400 22px/1.2 var(--serif); margin: 0; }
.lede { font: 300 18px/1.55 var(--sans); color: var(--ink-2); max-width: 58ch; margin: 0; }
.body { color: var(--ink-2); max-width: 64ch; }
.serif { font-family: var(--serif); }
.italic { font-style: italic; }
.num { font-variant-numeric: tabular-nums lining-nums; }
.bignum { font: 400 clamp(48px, 6vw, 84px)/.9 var(--serif); letter-spacing: -.02em; font-variant-numeric: lining-nums; }
.bignum small, .midnum small { font: 400 .3em/1 var(--sans); letter-spacing: .06em; color: var(--ink-2); margin-left: 6px; }
.nil { color: var(--rule-2); font-size: .6em; }
.midnum { font: 400 40px/1 var(--serif); letter-spacing: -.01em; font-variant-numeric: lining-nums; }
.mono { font-family: var(--sans); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.muted { color: var(--mute); }
.ink2 { color: var(--ink-2); }
.err { color: var(--error); }
.accent { color: var(--accent-ink); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }

/* Rules and structure */
.rule { border: 0; border-top: 1px solid var(--rule); margin: 0; }
.rule.strong { border-top-color: var(--rule-2); }
.section { padding: clamp(28px, 4vw, 48px) 0; border-top: 1px solid var(--rule); }
.section:first-child { border-top: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.stack > * + * { margin-top: var(--s, 16px); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.top { align-items: flex-start; }
.grid { display: grid; gap: clamp(20px, 3vw, 40px); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); } }

/* Stat: number over label, thin rule above */
.stat { border-top: 1px solid var(--rule-2); padding-top: 14px; }
.stat .label { display: block; margin-top: 10px; }
.stat .note { color: var(--ink-2); font-size: 13px; margin-top: 6px; }

/* Buttons: typographic, not boxes */
.btn { text-decoration: none; appearance: none; background: none; border: 1px solid var(--rule-2); color: var(--ink); padding: 12px 20px; font: 500 11px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast); white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.quiet { border-color: transparent; padding-left: 0; padding-right: 0; color: var(--ink-2); }
.btn.quiet:hover { color: var(--ink); }
.btn.link { border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--rule-2); text-underline-offset: 4px; letter-spacing: .14em; }
.btn.link:hover { color: var(--ink); text-decoration-color: var(--accent); }
.btn.big { padding: 20px 34px; font-size: 12px; letter-spacing: .24em; }
.arrow-link { font: 500 11px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; text-decoration: none; color: var(--ink); display: inline-flex; gap: 10px; align-items: center; cursor: pointer; background: none; border: 0; padding: 6px 0; border-bottom: 1px solid var(--rule-2); }
.arrow-link::after { content: '→'; font-family: var(--sans); letter-spacing: 0; transition: transform var(--t-fast); }
.arrow-link:hover::after { transform: translateX(4px); }
.arrow-link:hover { border-bottom-color: var(--accent); }

/* Choice list (segmented, typographic) */
.choices { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--rule-2); width: fit-content; }
.choices button { background: none; border: 0; border-right: 1px solid var(--rule-2); padding: 10px 16px; font: 500 11px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); cursor: pointer; }
.choices button:last-child { border-right: 0; }
.choices button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.choices button:hover:not([aria-pressed="true"]) { color: var(--ink); }

.options { display: grid; gap: 0; border-top: 1px solid var(--rule); }
.options button { text-align: left; background: none; border: 0; border-bottom: 1px solid var(--rule); padding: 16px 4px; font: 400 17px/1.3 var(--serif); color: var(--ink); cursor: pointer; display: flex; justify-content: space-between; align-items: baseline; gap: 16px; transition: padding var(--t-fast), color var(--t-fast); }
.options button:hover:not(:disabled) { padding-left: 12px; color: var(--accent-ink); }
.options button .key { font: 500 11px/1 var(--sans); color: var(--mute); letter-spacing: .1em; }
.options button.chosen { color: var(--ink); }
.options button.right::after { content: 'Model'; font: 500 10px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; color: var(--accent-ink); }
.options button.wrong { color: var(--mute); text-decoration: line-through; text-decoration-color: var(--error); }
.options button:disabled { cursor: default; }

input[type="text"], input[type="search"], textarea, select { background: transparent; border: 0; border-bottom: 1px solid var(--rule-2); padding: 10px 2px; outline: none; border-radius: 0; }
input[type="text"]:focus, textarea:focus, select:focus { border-bottom-color: var(--accent); }
select { padding-right: 18px; }
select option { background: var(--bg-2); }
textarea { width: 100%; border: 1px solid var(--rule-2); padding: 12px; min-height: 90px; }

/* Tables (restrained) */
.table { width: 100%; border-collapse: collapse; }
.table th { font: 500 10.5px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--mute); text-align: left; padding: 0 12px 12px 0; border-bottom: 1px solid var(--rule-2); }
.table td { padding: 14px 12px 14px 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
.table .r { text-align: right; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { color: var(--accent-ink); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px; font: 500 12px/1.3 var(--sans); letter-spacing: .06em; z-index: 100; max-width: 90vw; animation: viewIn var(--t-med) var(--ease); }

/* Progress (thin) */
.meter { height: 1px; background: var(--rule-2); position: relative; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--accent); transition: width var(--t-med) var(--ease); }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.chip { display: inline-block; font: 500 10.5px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); border: 1px solid var(--rule-2); padding: 6px 9px; }
.chip.accent { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.chip.err { color: var(--error); border-color: color-mix(in srgb, var(--error) 55%, transparent); }

.footnote { font-size: 12px; color: var(--mute); max-width: 72ch; line-height: 1.6; }
.sep { color: var(--rule-2); padding: 0 8px; }
.kbd { font: 500 10px/1 var(--sans); border: 1px solid var(--rule-2); padding: 3px 5px; color: var(--mute); letter-spacing: .05em; }
.empty { padding: 48px 0; color: var(--mute); font-family: var(--serif); font-size: 20px; font-style: italic; }
@media (max-width: 640px) {
  .masthead .wrap { flex-direction: column; align-items: flex-start; height: auto; padding-top: 14px; padding-bottom: 8px; gap: 8px; }
  .nav { flex-wrap: wrap; gap: 2px 16px; overflow: visible; }
  .nav a { letter-spacing: .12em; padding: 6px 0; }
}

/* ---- Installed app / phones: safe areas (notch, Dynamic Island, home indicator) ---- */
html { -webkit-tap-highlight-color: transparent; }
button, a, select, label, .options button, .choices button { touch-action: manipulation; }
.masthead { padding-top: env(safe-area-inset-top, 0px); }
.wrap { padding-left: max(var(--gutter), env(safe-area-inset-left, 0px)); padding-right: max(var(--gutter), env(safe-area-inset-right, 0px)); }
#main { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
/* The iOS status bar text is white in the installed app; in the Ivory edition keep a dark band behind it. */
:root[data-theme="ivory"] .masthead { box-shadow: inset 0 env(safe-area-inset-top, 0px) 0 0 #131311; }
@media (max-width: 640px) {
  :root { --gutter: 12px; }
  #main { padding-top: 18px; }
  .btn { padding: 14px 18px; }
  .btn.link, .arrow-link { padding-top: 10px; padding-bottom: 10px; }
}
