/* Dark is the default; light follows the system setting. No external fonts or images. */
:root {
  --bg: #101214; --surface: #1a1d21; --surface2: #23272d; --line: #2f343b;
  --fg: #e8eaed; --muted: #9aa0a6; --accent: #8ab4f8; --accent-fg: #0b1220;
  --good: #81c995; --warn: #fdd663; --bad: #f28b82;
  --c1: #8ab4f8; --c2: #f28b82; --c3: #fdd663; --c4: #81c995; --c5: #c58af9; --band: rgba(129, 201, 149, .18);
  --sleep-deep: #5b7fd6; --sleep-light: #9ab8f0; --sleep-rem: #b58af0; --sleep-awake: #f2a65a; --sleep-asleep: #7f8a99;
  --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9; --surface: #ffffff; --surface2: #eceff3; --line: #d8dce2;
    --fg: #1f2328; --muted: #5d6670; --accent: #1a5fd0; --accent-fg: #ffffff;
    --good: #1e7e34; --warn: #9a6700; --bad: #c5221f;
    --c1: #1a5fd0; --c2: #d93025; --c3: #b06000; --c4: #188038; --c5: #8e24aa; --band: rgba(30, 126, 52, .16);
    --sleep-deep: #2b4fb0; --sleep-light: #7da3e6; --sleep-rem: #8e4fd0; --sleep-awake: #d9822b; --sleep-asleep: #6b7684;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; max-width: 760px; margin: 0 auto;
  padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 20px 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
button { background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; min-height: 40px; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; }
input[type=search], input[type=password], input[type=text], select {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 40px; }
.top { padding: calc(10px + env(safe-area-inset-top)) 16px 4px; }
.pad { padding: 16px; }
#view { padding: 4px 16px 16px; }
.banner { margin-top: 6px; padding: 6px 10px; border-radius: 8px; font-size: 13px; background: var(--surface2); color: var(--muted); }
.banner.amber { background: color-mix(in srgb, var(--warn) 22%, var(--surface)); color: var(--fg); }
.banner.red { background: color-mix(in srgb, var(--bad) 26%, var(--surface)); color: var(--fg); }
.update { position: fixed; top: 0; left: 0; right: 0; z-index: 30; display: flex; gap: 10px; align-items: center; justify-content: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--accent); color: var(--accent-fg); }
.update button { min-height: 32px; padding: 4px 12px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; max-width: 760px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); padding: 8px 2px 6px; font-size: 11px; min-height: 56px; }
.tabs a svg { display: block; margin: 0 auto 2px; width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current=page] { color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 10px 0; }
.card.link { display: block; color: inherit; text-decoration: none; }
.grid { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 600px) { .grid { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.big { font-size: 26px; font-weight: 650; line-height: 1.1; }
.unit { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 3px; }
.up, .down { color: var(--accent); } /* a difference is not a verdict: one neutral colour */
.spark { display: block; width: 100%; height: 36px; margin-top: 6px; }
.spark path { fill: none; stroke: var(--c1); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.seg button { padding: 5px 11px; min-height: 34px; font-size: 13px; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chart { width: 100%; min-height: 260px; touch-action: pan-y; position: relative; }
.chart .u-legend { display: none; }
.readout { min-height: 22px; font-size: 13px; color: var(--muted); margin: 4px 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats b { display: block; font-size: 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.flag { display: inline-block; min-width: 18px; text-align: center; font-weight: 700; border-radius: 4px; padding: 0 4px; }
.flag.H, .flag.L, .flag.A { background: color-mix(in srgb, var(--bad) 28%, transparent); color: var(--bad); }
.review { color: var(--warn); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin: 4px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
details > summary { cursor: pointer; padding: 8px 0; color: var(--muted); }
.dialog { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; width: 100%; max-width: 420px; }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.error { color: var(--bad); }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; }
.stack > * + * { margin-top: 10px; }

.night { padding: 8px 0; border-bottom: 1px solid var(--line); }
.night .row b { font-weight: 600; }
.night .extra { font-size: 12px; color: var(--muted); margin-top: 2px; }
.metric-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.metric-row:last-child { border-bottom: 0; }
.metric-row .grow { flex: 1; min-width: 0; }
.metric-row .num { font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.metric-row .spark { width: 72px; height: 28px; margin: 0; flex: none; }
.metric-row .flagged { color: var(--bad); }
.spark-gap { width: 72px; flex: none; }
.row.night { display: flex; }
.compare { margin: 6px 0; }
.edit-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.edit-row:last-child { border-bottom: 0; }
.edit-row button { min-width: 40px; margin-left: 6px; }
.edit-row input { width: auto; min-height: 0; margin-right: 6px; }
