:root {
  --bg: #0b0d10; --panel: #14171c; --panel2: #1b1f26; --line: #232832; --track: #232832;
  --text: #eef1f5; --muted: #8b93a1; --accent: #5ee0c1;
  --good: #5ee0c1; --mid: #f2c14e; --low: #ff7a6b;
  --deep: #4b6bff; --light: #8fb3ff; --rem: #b48cff; --awake: #f2c14e;
  --r: 18px; --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --panel: #fff; --panel2: #f0f2f5; --line: #e6e9ee; --track: #e8ebf0;
    --text: #12151a; --muted: #6b7380; --accent: #0fa585; --good: #0fa585; --mid: #c98a00; --low: #e0503f;
    --deep: #3654e0; --light: #6f97f2; --rem: #8b5cf6; --awake: #e0a400;
    color-scheme: light;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
small { color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); } .small { font-size: 13px; }

main { max-width: 620px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px); }

/* Navigation: bottom bar on phones, sidebar on wide screens */
.tabs { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px); background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-top: 1px solid var(--line); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 10px; border-radius: 12px; }
.tabs a.on { color: var(--text); }
.tabs a.on svg { stroke: var(--accent); }
.tabs svg, .ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand { display: none; }
#demo-badge { font-size: 11px; background: var(--panel2); color: var(--mid); padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }
@media (min-width: 900px) {
  .tabs { top: 0; right: auto; width: 220px; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 28px 14px; border-top: 0; border-right: 1px solid var(--line); }
  .tabs a { flex-direction: row; gap: 12px; font-size: 15px; padding: 10px 12px; }
  .tabs a.on { background: var(--panel); }
  .brand { display: block; font-weight: 700; font-size: 20px; padding: 0 12px 20px; }
  main { margin-left: max(240px, calc(50vw - 310px + 110px)); padding-top: 32px; padding-bottom: 48px; }
  #status { left: calc(50% + 110px); }
}

#status { position: fixed; z-index: 20; top: calc(env(safe-area-inset-top) + 10px); left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); padding: 7px 14px; border-radius: 99px; font-size: 13px; color: var(--muted); white-space: nowrap; }

/* Day navigation */
.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 26px; line-height: 1; color: var(--muted); }
.icon-btn:disabled { opacity: .25; cursor: default; }
.day-label { position: relative; font-weight: 600; font-size: 17px; padding: 6px 12px; border-radius: 12px; cursor: pointer; }
.day-label input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

/* Score rings */
.rings { display: flex; justify-content: space-around; padding: 6px 0 18px; }
.ring-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ring-num { fill: var(--text); font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.hero .ring-num { font-size: 34px; }

.panel, .plan, .vital, .tip { background: var(--panel); border-radius: var(--r); }
.panel { padding: 16px; margin-bottom: 12px; }
.panel h4 { font-size: 14px; color: var(--muted); font-weight: 500; margin-bottom: 10px; }
.sec { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 17px; margin: 26px 2px 10px; }
.sec small { font-size: 12px; margin-right: auto; }
.sec a { font-size: 13px; color: var(--accent); font-weight: 500; }
.page-title { font-size: 26px; margin: 8px 2px 16px; }

/* Plan card */
.plan { padding: 18px; position: relative; overflow: hidden; }
.plan::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--mid); }
.plan.good::before { background: var(--good); } .plan.low::before { background: var(--low); }
.plan-tag { display: inline-block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--mid); margin-bottom: 6px; }
.plan.good .plan-tag { color: var(--good); } .plan.low .plan-tag { color: var(--low); }
.plan h2 { font-size: 19px; margin-bottom: 4px; }
.plan p { margin: 0; color: var(--muted); }
.plan .plan-sub { margin-top: 10px; font-size: 13px; } .plan-sub b { color: var(--text); }

/* Vitals grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 560px) { .grid.vitals { grid-template-columns: repeat(3, 1fr); } .grid.vitals.four { grid-template-columns: repeat(4, 1fr); } }
.vital { text-align: left; padding: 13px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; transition: background .15s; }
button.vital:hover { background: var(--panel2); }
.vital-top { display: flex; justify-content: space-between; gap: 4px; font-size: 12.5px; color: var(--muted); }
.vital-top span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vital-val { font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.vital-val small { font-size: 12px; margin-left: 3px; }
.spark { width: 100%; height: 22px; margin-top: 4px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; opacity: .8; }
.delta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.delta.good, .good { color: var(--good); } .delta.low, .low { color: var(--low); }

/* Tips */
.tips { display: flex; flex-direction: column; gap: 10px; }
.tip { display: flex; gap: 12px; padding: 14px; }
.tip-ico { flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--panel2); color: var(--mid); }
.tip.good .tip-ico { color: var(--good); } .tip.low .tip-ico { color: var(--low); }
.tip-ico .ico { width: 20px; height: 20px; }
.tip h4 { font-size: 15px; margin: 1px 0 3px; color: var(--text); font-weight: 600; }
.tip p { margin: 0; color: var(--muted); font-size: 14px; }

/* Lists */
.list { list-style: none; padding: 6px 16px; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border: 0; } .list span { color: var(--muted); font-size: 13px; text-align: right; }

/* Contributors & meters */
.contrib { display: grid; grid-template-columns: 1fr 34% 28px; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.contrib b { text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 6px; background: var(--track); border-radius: 9px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 9px; background: var(--mid); }
.meter i.good { background: var(--good); } .meter i.low { background: var(--low); }

/* Charts */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .axis { fill: var(--muted); font-size: 17px; }
.chart .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.faint { opacity: .28; stroke-width: 1.2; }
.chart .dot { stroke: var(--panel); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart .band { fill: var(--accent); opacity: .07; }
.chart .proj { stroke-dasharray: 5 5; stroke-width: 2; vector-effect: non-scaling-stroke; opacity: .9; }
.chart .proj-band { fill: var(--accent); opacity: .1; }
.chart .target { stroke: var(--muted); stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.chart .cursor { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-box { position: relative; touch-action: pan-y; }
.tt { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 4px 9px; font-size: 12px; white-space: nowrap; pointer-events: none; color: var(--muted); }
.tt b { color: var(--text); margin-right: 4px; }
.empty { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; }
.empty.big { padding: 80px 0; }

/* Sleep */
.hero { display: flex; align-items: center; gap: 22px; padding: 6px 4px 18px; }
.hero-stats { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.hero-stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.hero-stats small { font-size: 12px; }
.hyp-wrap { display: flex; gap: 8px; }
.hyp-labels { display: flex; flex-direction: column; justify-content: space-around; font-size: 11px; color: var(--muted); padding-bottom: 8%; }
.hyp-wrap .chart { flex: 1; }
.stagebar { display: flex; height: 8px; border-radius: 9px; overflow: hidden; gap: 2px; margin: 14px 0 12px; }
.stages { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; font-size: 12px; color: var(--muted); }
.stages b { display: block; color: var(--text); font-size: 15px; margin-top: 2px; }
.dotc { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

/* Trends */
.chips { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.chip-group { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.chip-group::-webkit-scrollbar { display: none; }
.chip-group small { flex: none; width: 58px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.chip { flex: none; padding: 6px 12px; border-radius: 99px; background: var(--panel); font-size: 13px; color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); }
.trend-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.big-num { font-size: 32px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.big-num small { font-size: 14px; margin-left: 4px; }
.seg { display: flex; background: var(--panel2); border-radius: 10px; padding: 2px; }
.seg button { padding: 5px 10px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px #0003; }
.trend-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; font-size: 12px; }
.trend-stats b { display: block; font-size: 14px; }
.proj-text { font-size: 14px; color: var(--muted); margin: 14px 0 0; }
.proj-text b { color: var(--text); }
.legend-proj { display: inline-block; width: 18px; border-top: 2px dashed var(--accent); vertical-align: middle; margin-right: 8px; }
.proj-list, .corr { list-style: none; margin: 0; padding: 0; }
.proj-list li { display: grid; grid-template-columns: 1fr 24px auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.proj-list li:last-child, .corr li:last-child { border: 0; }
.proj-list b { font-variant-numeric: tabular-nums; font-weight: 500; }
.arrow { text-align: center; color: var(--muted); }
.corr li { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.corr small { grid-column: 1 / -1; font-size: 12px; }

/* Coach */
.goals { display: flex; flex-direction: column; gap: 14px; }
.goal > div:first-child { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.disclaimer { font-size: 12px; color: var(--muted); margin: 28px 4px 0; }

/* Settings & buttons */
.rows { padding: 4px 16px; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row:last-child { border: 0; } .row span { color: var(--muted); } .row b { font-weight: 500; text-align: right; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.btns.col { flex-direction: column; }
.btn { display: inline-flex; justify-content: center; align-items: center; padding: 11px 18px; border-radius: 12px; background: var(--panel); font-weight: 500; font-size: 14px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #06231c; }
.btn.danger { color: var(--low); }
.btn.disabled { opacity: .4; pointer-events: none; }

.onboard { text-align: center; padding: 12vh 12px 0; max-width: 380px; margin: 0 auto; }
.onboard h1 { font-size: 32px; margin: 18px 0 8px; }
.onboard p { color: var(--muted); }
.onboard .btns { margin: 28px 0 20px; }
body.no-data .tabs a:not([data-r="settings"]) { opacity: .35; pointer-events: none; }
