/* Uplink. Tokens and rules are documented in DESIGN.md. */
@font-face { font-family: "Geist"; src: url("/fonts/geist.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Geist"; src: url("/fonts/geist-ext.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Geist Mono"; src: url("/fonts/geist-mono.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --ink: #171717;
  --body: #4d4d4d;
  --muted: #6b6b6b;
  --line: #e4e4e4;
  --line-strong: #c4c4c4;
  --accent: #e8480c;
  --mark: #8a8a8a;
  --mark-faint: #cfcfcf;
  --on-ink: #ffffff;
  --radius: 12px;
  --radius-in: 8px;
  --sans: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --tabs-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0d;
    --surface: #151516;
    --ink: #ededed;
    --body: #b8b8b8;
    --muted: #8f8f8f;
    --line: #262628;
    --line-strong: #3d3d40;
    --accent: #ff6b2c;
    --mark: #7d7d7d;
    --mark-faint: #3a3a3c;
    --on-ink: #0c0c0d;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
h1, h2, p, dl, dd, figure, fieldset, ol { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 16px; top: -48px; z-index: 30; padding: 8px 12px; background: var(--ink); color: var(--on-ink); border-radius: var(--radius-in); text-decoration: none; }
.skip:focus { top: calc(8px + env(safe-area-inset-top)); }

/* ---------- frame ---------- */

.top, main { width: 100%; max-width: 520px; margin-inline: auto; padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -0.02em; }
.brand svg { fill: var(--ink); }
.brand .hot { fill: var(--accent); }
.net { min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 32px); outline: none; }
.view { display: grid; gap: 20px; animation: enter 180ms ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg); border-top: 1px solid var(--line);
}
.tabs a {
  flex: 0 1 173px; height: var(--tabs-h);
  display: grid; place-items: center; position: relative;
  color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none;
}
.tabs a[aria-current] { color: var(--ink); }
.tabs a[aria-current]::before { content: ""; position: absolute; top: -1px; left: 28%; right: 28%; height: 2px; background: var(--ink); }

/* ---------- shared text ---------- */

.label, legend, dt, .field label { font-size: 13px; color: var(--muted); }
.hint, .help, .meta { font-size: 13px; line-height: 1.45; color: var(--muted); }
.hint.warn { color: var(--ink); font-weight: 500; }
h1 { font-size: 28px; line-height: 1.15; font-weight: 600; letter-spacing: -0.03em; text-wrap: balance; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.lede { color: var(--body); margin-top: -10px; text-wrap: pretty; }

/* ---------- controls ---------- */

.seg legend { margin-bottom: 8px; }
.seg-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; height: 40px; border-radius: var(--radius-in); font-weight: 500; font-size: 15px; color: var(--body); transition: background-color 120ms, color 120ms; }
.seg input:checked + span { background: var(--ink); color: var(--on-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.seg input:disabled { cursor: default; }
.seg input:disabled:not(:checked) + span { opacity: 0.45; }
.seg + .hint { margin-top: -12px; }

.btn-primary {
  display: grid; place-items: center; width: 100%; height: 52px;
  border: 1px solid var(--ink); border-radius: var(--radius);
  background: var(--ink); color: var(--on-ink);
  font-weight: 500; font-size: 16px; text-decoration: none; cursor: pointer;
  transition: transform 80ms;
}
.btn-primary:active { transform: scale(0.985); }
.btn-primary.busy { background: transparent; color: var(--ink); }

.btn-ghost {
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-in);
  background: transparent; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn-ghost:active { transform: scale(0.97); }
.btn-ghost:disabled { opacity: 0.4; cursor: default; }

.error { padding: 12px 14px; border: 1px solid var(--ink); border-radius: var(--radius); font-size: 14px; }

/* ---------- test view ---------- */

.hero { display: grid; gap: 2px; }
.figure { display: flex; align-items: baseline; gap: 8px; font-size: 76px; line-height: 1; font-weight: 600; letter-spacing: -0.045em; }
.figure.is-empty { color: var(--mark-faint); font-variant-ligatures: none; letter-spacing: 0; }
.figure .unit { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; color: var(--muted); }
.phase { margin-top: 8px; font-size: 14px; color: var(--body); min-height: 21px; }
.progress { height: 2px; margin-top: 10px; background: var(--line); overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform 200ms linear; }

.trace-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; margin-bottom: 4px; }
.trace figcaption, .bars-chart figcaption { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-seg { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-in); }
.mini-seg button { height: 26px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer; }
.mini-seg button[aria-pressed="true"] { background: var(--line); color: var(--ink); }

svg { display: block; width: 100%; }
#trace { height: 148px; touch-action: pan-y; cursor: crosshair; }
#live-spark { height: 36px; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .axis { stroke: var(--line-strong); stroke-width: 1; }
svg .cross { stroke: var(--line-strong); stroke-width: 1; }
svg .tick { font: 11px var(--mono); fill: var(--muted); }
svg .empty { font: 13px var(--sans); fill: var(--muted); }
svg .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .area { fill: var(--accent); fill-opacity: 0.1; }
svg .spark { fill: none; stroke: var(--mark); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); border-block: 1px solid var(--line); }
.stats > div { padding: 14px 0 14px 16px; border-left: 1px solid var(--line); }
.stats > div:first-child { padding-left: 0; border-left: 0; }
.stats dd { font-variant-ligatures: none; display: flex; align-items: baseline; gap: 5px; margin-top: 2px; font-size: 26px; line-height: 1.15; font-weight: 600; letter-spacing: -0.03em; }
.stats small { font-size: 13px; font-weight: 400; letter-spacing: 0; color: var(--muted); }

.rating { display: flex; align-items: flex-start; gap: 12px; font-size: 15px; color: var(--body); text-wrap: pretty; }
.rating strong { color: var(--ink); font-weight: 600; }
.bars { flex: none; display: flex; align-items: flex-end; gap: 3px; height: 20px; margin-top: 1px; }
.bars i { width: 5px; border-radius: 1.5px; background: var(--mark-faint); }
.bars i:nth-child(1) { height: 35%; }
.bars i:nth-child(2) { height: 57%; }
.bars i:nth-child(3) { height: 79%; }
.bars i:nth-child(4) { height: 100%; }
.bars[data-level="1"] i:nth-child(-n + 1),
.bars[data-level="2"] i:nth-child(-n + 2),
.bars[data-level="3"] i:nth-child(-n + 3),
.bars[data-level="4"] i { background: var(--ink); }

.live { display: grid; gap: 6px; padding-top: 4px; }
.live-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.live-head p { font-size: 14px; color: var(--body); font-variant-numeric: tabular-nums; }

details > summary { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font-size: 14px; font-weight: 500; cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; font: 400 18px var(--mono); color: var(--muted); }
details[open] > summary::after { content: "-"; }
.more { border-top: 1px solid var(--line); }
.more[open] { padding-bottom: 8px; }
.facts { margin-bottom: 24px; }
.facts > div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; font-size: 14px; }
.facts > div + div { border-top: 1px solid var(--line); }
.facts dt { flex: none; }
.facts dd { text-align: right; overflow-wrap: anywhere; }
.facts .help { margin-top: 8px; }

.field { display: grid; gap: 6px; margin-bottom: 24px; }
.field input, .field select {
  width: 100%; height: 46px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: 16px;
}
.field input::placeholder { color: var(--muted); }
.field input:disabled { opacity: 0.5; }

/* ---------- compare view ---------- */

#view-compare .label { margin-bottom: -14px; }
.bars-chart figcaption { margin-bottom: 4px; }
.row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 14px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row .tag { font-weight: 600; font-size: 17px; letter-spacing: -0.02em; }
.row-main { display: grid; gap: 6px; }
.bar-line { display: flex; align-items: center; gap: 8px; }
.bar { flex: 0 0 0.5%; height: 14px; min-width: 3px; border-radius: 0 4px 4px 0; background: var(--mark); }
.val { flex: none; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.flag { flex: none; font-size: 12px; font-weight: 500; color: var(--muted); }
.bar-line .val, .bar-line .flag { white-space: nowrap; }
.bar { max-width: calc(100% - 104px); }
.row.winner .bar { background: var(--accent); }
.row.stale .bar { background: var(--mark-faint); }
.row.stale .val { color: var(--muted); font-weight: 500; }
.none { font-size: 15px; color: var(--muted); }

.steps { display: grid; gap: 10px; padding-top: 20px; border-top: 1px solid var(--line); }
.steps ol { display: grid; gap: 8px; padding-left: 20px; font-size: 15px; color: var(--body); }
.steps ol li::marker { font: 500 13px var(--mono); color: var(--muted); }
.steps details p { font-size: 14px; color: var(--body); margin-bottom: 10px; }
.steps details strong { color: var(--ink); font-weight: 600; }

/* ---------- history view ---------- */

.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.actions { display: flex; gap: 8px; }
#history-body { display: grid; gap: 12px; }
#history-body h2 { margin-top: 12px; }
#history-body h2 + .help { margin-top: -8px; }
.typical-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.typical { display: grid; gap: 2px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.typical-head { display: flex; align-items: baseline; justify-content: space-between; }
.typical .tag { font-weight: 600; }
.typical-value { display: flex; align-items: baseline; gap: 6px; font-size: 30px; line-height: 1.2; font-weight: 600; letter-spacing: -0.035em; }
.typical-value small { font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--muted); }
.typical svg { height: 32px; margin-top: 8px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 0 10px 12px; text-align: right; font-weight: 400; }
th:first-child { padding-left: 0; text-align: left; }
thead th { font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line-strong); }
tbody tr + tr { border-top: 1px solid var(--line); }
tbody th span { display: block; color: var(--ink); }
tbody th small { font-size: 12px; color: var(--muted); }
td.net { font-weight: 600; }

.empty-state { display: grid; gap: 10px; justify-items: start; padding: 40px 0; color: var(--body); }
.empty-title { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
.empty-state .btn-primary { width: auto; padding: 0 22px; margin-top: 10px; }

@media (min-width: 700px) {
  .top { padding-top: 28px; }
  .figure { font-size: 88px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
