:root {
  --page: #eaf8fb; --surface: #ffffff; --soft: #cceff4; --ink: #102f3b; --muted: #4d6973; --line: #7fa4ad;
  --accent: #006d83; --accent-ink: #ffffff; --danger: #9d3044; --warn: #7a5600; --selected: #fff0c7;
  /* Validated diverging poles (dataviz reference: blue↔red, gray midpoint) and chart chrome. */
  --pos: #2a78d6; --neg: #e34948; --neutral: #f0efec; --series: #2a78d6; --fit: #52514e;
  --grid: #e1e0d9; --axis: #c3c2b7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #10251f; --surface: #182f27; --soft: #244239; --ink: #edf6ea; --muted: #aec6bb; --line: #587c6e;
    --accent: #7bd4b8; --accent-ink: #0b1c17; --danger: #ff9bab; --warn: #f2d27a; --selected: #4c492d;
    --pos: #3987e5; --neg: #e66767; --neutral: #383835; --series: #3987e5; --fit: #c3c2b7;
    --grid: #2c3f37; --axis: #4a5f56;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 14px; border-bottom: 1px solid var(--line); background: var(--soft); color: var(--ink); }
.top strong { font-size: 15px; }
.gate { max-width: 420px; margin: 48px auto; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
#app { max-width: 1400px; margin: 0 auto; padding: 10px 12px 24px; }
.app-root { display: grid; gap: 10px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.controls label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
select, input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
.filter input { width: 170px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { padding: 5px 10px; border: 0; border-right: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 13px/1.2 inherit; cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
button { font-family: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, tr:focus-visible, .hit:focus-visible, .overlay:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.error > button { margin-left: 6px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }
.muted { color: var(--muted); font-weight: 400; }
.note, .error { margin: 0; }
.note { color: var(--muted); }
.error { color: var(--danger); }
.workspace { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr); gap: 12px; align-items: start; }
@media (max-width: 900px) { .workspace { grid-template-columns: 1fr; } }
.panel { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.stale { opacity: 0.6; transition: opacity 0.15s; }
.table-wrap { max-height: calc(100vh - 150px); overflow: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
caption { padding: 8px 10px; caption-side: top; text-align: left; color: var(--muted); font-size: 12px; }
caption strong { color: var(--ink); }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
tbody th { max-width: 260px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover th, tbody tr:hover td.n { background: color-mix(in srgb, var(--soft) 55%, transparent); }
tbody tr.selected th, tbody tr.selected td.n { background: var(--selected); }
td.r { min-width: 64px; border-left: 2px solid var(--surface); border-right: 2px solid var(--surface); }
td.thin { color: var(--muted); }
td.n { color: var(--muted); font-size: 12px; }
.num { text-align: right; }
.tag { margin-left: 6px; padding: 0 5px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 11px; font-weight: 600; }
.empty { padding: 14px 10px; color: var(--muted); }
.detail { padding: 10px 12px 12px; }
.detail-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
h2 { margin: 0; font-size: 15px; }
h3 { margin: 12px 0 2px; font-size: 13px; }
.stat { margin: 6px 0; }
.warn { color: var(--warn); font-weight: 600; }
.chart { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.grid line { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.axis-labels text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.fit { stroke: var(--fit); stroke-width: 2; stroke-linecap: round; }
.dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.hit { fill: transparent; cursor: default; }
.line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.crosshair { stroke: var(--muted); stroke-width: 1; }
.overlay { fill: transparent; }
.tooltip { position: absolute; z-index: 5; min-width: 150px; max-width: 220px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); pointer-events: none; font-size: 12px; }
.tip-title { color: var(--muted); margin-bottom: 2px; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--muted); }
.nav { display: flex; align-items: center; gap: 14px; }
.nav a { color: var(--muted); font-weight: 600; text-decoration: none; }
.nav a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
:root { --info-tooltip-bg: var(--surface); --info-tooltip-text: var(--ink); --info-tooltip-border: var(--line); }
#app.log { max-width: 900px; display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: 600 13px/1.2 inherit; cursor: pointer; }
.chip .count { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip[aria-pressed="true"] .count { color: var(--accent-ink); }
.strip-panel { padding: 6px 8px; }
.strip { display: block; width: 100%; height: auto; }
.strip .track { stroke: var(--grid); stroke-width: 1; }
.strip .tag-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.strip .axis { fill: var(--muted); font-size: 11px; }
.strip .mark { fill: var(--series); stroke: var(--surface); stroke-width: 2; cursor: default; }
.strip .mark:focus-visible { outline: none; stroke: var(--accent); stroke-width: 3; }
.strip .dim { opacity: 0.3; }
#app.sleep { max-width: 900px; display: grid; gap: 10px; }
.period { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.actogram { display: block; width: 100%; height: auto; }
.actogram .grid { stroke: var(--grid); stroke-width: 1; }
.actogram .midnight { stroke: var(--axis); }
.actogram .axis { fill: var(--muted); font-size: 11px; }
.actogram .sleep-bar { fill: var(--series); opacity: 0.55; cursor: default; }
.actogram .sleep-bar:focus-visible { outline: none; opacity: 1; stroke: var(--accent); stroke-width: 2; }
.actogram .message { stroke: var(--ink); stroke-width: 1; opacity: 0.6; }
.day h2 { margin: 6px 0; font-size: 14px; }
.note-card { margin-bottom: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.note-card p { margin: 4px 0 0; white-space: pre-wrap; }
.note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }
button.tag { margin-left: 0; background: var(--surface); cursor: pointer; font-family: inherit; }
button.tag:hover { color: var(--ink); }
.source { margin-left: auto; color: var(--accent); }
#app.mind { max-width: 900px; display: grid; gap: 10px; }
.check { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 14px; min-height: 60px; }
.check > * { flex: 0 0 auto; }
.check .stage-head { flex: 1 0 100%; display: flex; align-items: center; justify-content: space-between; }
.check .instruction { flex: 1 0 100%; margin: 0; }
.action { padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 600 14px/1.2 inherit; cursor: pointer; }
.action.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.link { padding: 0; border: 0; background: none; color: var(--muted); font: 600 13px inherit; cursor: pointer; text-decoration: underline; }
.saved { color: var(--accent); font-weight: 600; }
.scale { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; flex: 1 0 100%; }
.scale-step { padding: 10px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 600 15px inherit; cursor: pointer; }
.scale-step:hover { background: var(--soft); }
.scale-ends { display: flex; justify-content: space-between; flex: 1 0 100%; font-size: 12px; }
.rt-box { flex: 1 0 100%; display: grid; place-items: center; height: 220px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); color: var(--ink); font: 600 22px inherit; font-variant-numeric: tabular-nums; user-select: none; touch-action: manipulation; cursor: pointer; }
.rt-box.go { background: #f08a24; border-color: #f08a24; color: #1d1203; }
.rt-box.early { color: var(--danger); }
.countdown { flex: 1 0 100%; font-variant-numeric: tabular-nums; }
.big-digit { flex: 1 0 100%; display: grid; place-items: center; height: 140px; font: 700 72px/1 inherit; font-variant-numeric: tabular-nums; }
.big-digit.right { color: var(--accent); }
.big-digit.wrong { color: var(--danger); }
.span-form { display: flex; gap: 8px; }
.span-form input { width: 180px; font-size: 22px; letter-spacing: 0.15em; font-variant-numeric: tabular-nums; }
.code-key { flex: 1 0 100%; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.code-cell { display: grid; justify-items: center; padding: 4px 0; border-right: 1px solid var(--grid); }
.code-cell:last-child { border-right: 0; }
.code-symbol { font-size: 22px; line-height: 1.2; }
.code-digit { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.code-target { flex: 1 0 100%; text-align: center; font-size: 72px; line-height: 1.3; user-select: none; }
.code-target.miss { animation: miss 0.25s; }
@keyframes miss { 0%, 100% { color: var(--ink); } 50% { color: var(--danger); } }
.code-pad { flex: 1 0 100%; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.pad-key { padding: 14px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 700 18px inherit; touch-action: manipulation; user-select: none; cursor: pointer; }
.pad-key:active { background: var(--soft); }
.history { display: grid; gap: 8px; }
.metric { padding: 8px 9px 4px; }
.metric-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 13px; }
.metric-name { color: var(--ink); font-weight: 700; font-size: 14px; text-decoration: none; }
.metric-name:hover { text-decoration: underline; }
.metric-head .latest { margin-left: auto; font-variant-numeric: tabular-nums; }
.verdict.worse { color: var(--danger); font-weight: 600; }
.verdict.better { color: var(--accent); font-weight: 600; }
.metric-chart { display: block; width: 100%; height: auto; overflow: visible; }
.metric-chart .band { fill: var(--soft); }
.metric-chart .band-mid { stroke: var(--line); stroke-dasharray: 3 3; }
.metric-chart .axis { fill: var(--muted); font-size: 11px; }
.metric-chart .latest-dot { fill: #f08a24; }
.metric-chart .dot:focus-visible { outline: none; stroke: var(--accent); stroke-width: 3; }
.group-head { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.verdict.unusual { color: var(--warn); font-weight: 600; }
