:root {
  --bg: #0b1020;
  --card: #151b33;
  --card-2: #1d2546;
  --text: #e9ecf8;
  --muted: #9aa3c4;
  --accent: #8ea2ff;
  --warn: #ffcf70;
  --danger: #ff7a7a;
  --awake: #ffb86b;
  --rem: #c38bff;
  --light: #5fb4ff;
  --deep: #3a4fd8;
  --grid: #2a3358;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
body.night { padding-bottom: 0; background: #000; }
main { max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 30px; margin: 0; letter-spacing: -0.5px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.top { padding: 18px 0 12px; }
.sub, .muted { color: var(--muted); }
.sub { margin: 2px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.center { text-align: center; }
.back { display: inline-block; margin-bottom: 6px; }

.card { display: block; background: var(--card); border-radius: 18px; padding: 16px; margin: 0 0 14px; color: var(--text); }
.card.warn { background: #3a2f12; color: #ffe7b0; }
.card.link:active { background: var(--card-2); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); padding: 10px; border-radius: 10px; font: inherit; }
.seg button.on { background: var(--card-2); color: var(--text); font-weight: 600; }
.slider { display: block; margin-top: 14px; font-size: 14px; }
.slider span { float: right; color: var(--muted); }
.slider input { width: 100%; margin-top: 6px; accent-color: var(--accent); }

button { font: inherit; cursor: pointer; }
.big { width: 100%; border: 0; border-radius: 18px; padding: 18px; margin: 4px 0 14px; font-size: 19px; font-weight: 700;
  background: linear-gradient(135deg, #6b7cff, #9d6bff); color: #fff; }
.big:disabled { opacity: .6; }
.secondary { display: inline-block; border: 0; border-radius: 12px; padding: 10px 14px; background: var(--card-2); color: var(--text); margin: 4px 6px 0 0; }
.file input { display: none; }
.danger { width: 100%; border: 1px solid #5a2a3a; background: none; color: var(--danger); border-radius: 14px; padding: 14px; margin-top: 6px; }
.checklist { color: var(--muted); font-size: 14px; padding-left: 20px; margin: 0 0 18px; }
.checklist li { margin-bottom: 4px; }

.mini-score { font-size: 28px; font-weight: 700; min-width: 76px; }
.stagebar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 10px; background: var(--grid); }
.stagebar span { display: block; height: 100%; }

.st-awake { fill: var(--awake); background: var(--awake); }
.st-rem { fill: var(--rem); background: var(--rem); }
.st-light { fill: var(--light); background: var(--light); }
.st-deep { fill: var(--deep); background: var(--deep); }

.summary { display: flex; align-items: center; gap: 16px; }
.summary dl { margin: 0; display: grid; grid-template-columns: auto auto; gap: 4px 12px; font-size: 14px; flex: 1; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; text-align: right; font-weight: 600; }
.ring-bg { fill: none; stroke: var(--grid); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; }
.ring-num { fill: var(--text); font-size: 28px; font-weight: 700; }
.ring-lbl { fill: var(--muted); font-size: 12px; }

.chart { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .lvl { fill: #4a5a99; }

.stages { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.stage { display: flex; gap: 8px; background: var(--card-2); border-radius: 12px; padding: 10px; font-size: 13px; }
.big-num { font-size: 18px; font-weight: 700; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 4px 4px 0 0; flex: none; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 8px; }
.chip { flex: none; border: 1px solid var(--grid); background: none; color: var(--text); border-radius: 999px; padding: 6px 10px; font-size: 13px; }
.chip.on { background: var(--card-2); border-color: var(--accent); }
.events { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.events li { display: grid; grid-template-columns: 12px 70px 1fr auto 36px; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--grid); font-size: 14px; }
.events li[hidden] { display: none; }
.events li.flash { background: var(--card-2); }
.ev-time { font-variant-numeric: tabular-nums; }
.ev-dot { width: 10px; height: 10px; border-radius: 50%; }
.play { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--accent); color: #0b1020; font-size: 12px; }
.play.off { visibility: hidden; }

.ev-snore { fill: #c38bff; background: #c38bff; }
.ev-talk { fill: #6be3c3; background: #6be3c3; }
.ev-movement { fill: #ffb86b; background: #ffb86b; }
.ev-bang { fill: #ff7a7a; background: #ff7a7a; }
.ev-rustle { fill: #9ad86b; background: #9ad86b; }
.ev-noise { fill: #9aa3c4; background: #9aa3c4; }

.avgs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.avgs b { color: var(--text); font-size: 16px; }
.nights { list-style: none; padding: 0; margin: 0; }
.nights li a { display: block; background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 10px; color: var(--text); font-size: 14px; }

/* Night screen: as dark as possible so it can stay on all night. */
.nightscreen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #5b6488; gap: 10px; }
.clock { font-size: 72px; font-weight: 200; color: #7c86ad; letter-spacing: -2px; font-variant-numeric: tabular-nums; }
.since, .stats { font-size: 14px; }
.meter { width: 160px; height: 4px; background: #14182a; border-radius: 2px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 2%; background: #34406e; transition: width .25s; }
.meter span.hot { background: #6b4ea8; }
.warn-dim { color: #8a7440; font-size: 13px; max-width: 300px; }
.hold { position: relative; overflow: hidden; margin-top: 40px; width: 220px; padding: 16px; border-radius: 999px; border: 1px solid #262c48; background: #0a0c16; color: #7c86ad; user-select: none; -webkit-user-select: none; touch-action: none; }
.hold .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: #262c48; }
.hold .lbl { position: relative; }

nav#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; background: rgba(11, 16, 32, .94); border-top: 1px solid var(--grid); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
nav#tabs[hidden] { display: none; }
nav#tabs a { color: var(--muted); font-size: 11px; text-align: center; display: flex; flex-direction: column; align-items: center; min-width: 80px; }
nav#tabs a span { font-size: 20px; }
nav#tabs a.active { color: var(--text); }

@media (max-width: 360px) {
  .stages { grid-template-columns: 1fr; }
  .summary { flex-direction: column; }
}
