:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --band: rgba(82, 81, 78, 0.13);
  --series-1: #2a78d6;
  --series-soft: #86b6ef;
  --stage-deep: #2a78d6;
  --stage-rem: #eb6834;
  --stage-light: #1baf7a;
  --stage-awake: #eda100;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --band: rgba(195, 194, 183, 0.14);
    --series-1: #3987e5;
    --series-soft: #1c5cab;
    --stage-deep: #3987e5;
    --stage-rem: #d95926;
    --stage-light: #199e70;
    --stage-awake: #c98500;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.page { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 24px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--ink-2); font-size: 13px; }
main > section, .filters { margin-top: 28px; }
main > section > h2 { margin-bottom: 8px; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }

button, select, .button-primary {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover, select:hover { background: var(--wash); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.button-primary { display: inline-block; margin-top: 16px; background: var(--ink); color: var(--surface); text-decoration: none; font-weight: 600; }

.banner { margin-top: 16px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--wash); font-weight: 600; }
.banner-error { border-color: var(--critical); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
#connect { margin-top: 24px; max-width: 640px; }
#connect p { margin-top: 8px; color: var(--ink-2); white-space: pre-line; overflow-wrap: anywhere; }
.login { display: grid; gap: 10px; max-width: 360px; margin: 12vh auto 0; }
.login input { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 8px 10px; }
.login .button-primary { margin-top: 6px; }

.headline { font-size: 22px; font-weight: 600; line-height: 1.3; }
.deviations { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.deviations li { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.deviations strong { color: var(--ink); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-top: 16px; }
.tile {
  display: grid; gap: 6px; text-align: left; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
button.tile[aria-pressed="true"] { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile-value { font-size: 28px; font-weight: 600; line-height: 1.1; }
.tile-value small { font-size: 14px; font-weight: 400; color: var(--ink-2); }
.tile-meta { color: var(--ink-2); font-size: 12px; }
.scores { display: flex; gap: 18px; }
.scores span { display: grid; }

.chip { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.badge {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700; line-height: 1; color: #ffffff;
  background: var(--muted);
}
.badge.tone-good { background: var(--good); }
.badge.tone-bad { background: var(--warning); color: #0b0b0b; }
.badge.tone-bad.strong { background: var(--critical); color: #ffffff; }

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters + .card, .card + .card { margin-top: 12px; }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.select { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.swatch-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--series-soft); }
.swatch-line { height: 2px; width: 16px; border-radius: 1px; background: var(--series-1); }
.swatch-band { background: var(--band); border: 1px solid var(--border); }

.chart { position: relative; min-height: 120px; }
.chart svg { display: block; border-radius: 6px; }
.chart.loading { opacity: 0.45; }
.empty { color: var(--ink-2); padding: 36px 0; text-align: center; }

.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.band { fill: var(--band); }
.dot-day { fill: var(--series-soft); }
.dot-day.hover { fill: var(--series-1); }
.line-main { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot-main { fill: var(--series-1); }
.ring { stroke: var(--surface); stroke-width: 2; }
.end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.hover-wash { fill: var(--wash); }
.spark { flex: none; }
.spark-line { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }

.stage-deep, .swatch.stage-deep { fill: var(--stage-deep); background: var(--stage-deep); }
.stage-rem, .swatch.stage-rem { fill: var(--stage-rem); background: var(--stage-rem); }
.stage-light, .swatch.stage-light { fill: var(--stage-light); background: var(--stage-light); }
.stage-awake, .swatch.stage-awake { fill: var(--stage-awake); background: var(--stage-awake); }

.tooltip {
  position: absolute; top: 8px; z-index: 2; pointer-events: none; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.tooltip-title { color: var(--ink-2); margin-bottom: 4px; }
.tooltip-row { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip-row strong { color: var(--ink); font-weight: 600; }
.key { flex: none; width: 12px; height: 2px; border-radius: 1px; }
.key-none { background: transparent; }
.key-day { background: var(--series-soft); }
.key-main { background: var(--series-1); }
.key-band { background: var(--muted); }
.key-deep { background: var(--stage-deep); }
.key-rem { background: var(--stage-rem); }
.key-light { background: var(--stage-light); }
.key-awake { background: var(--stage-awake); }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.table-wrap { overflow-x: auto; }
details .table-wrap { max-height: 320px; overflow-y: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; white-space: nowrap; }
th { color: var(--ink-2); font-weight: 500; }
th:first-child, td:first-child { text-align: left; }
td .chip { justify-content: flex-end; }

footer { margin-top: 28px; display: grid; gap: 8px; max-width: 820px; }
[hidden] { display: none !important; }
