:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --border: #e4e3de;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76756f;
  --accent: #11704f;
  --accent-ink: #ffffff;
  --danger: #c0352f;
  --warn-bg: #fff4dc;
  --warn-ink: #6b4a00;
  /* Sleep stages: one blue ramp, darker = deeper (validated as an ordinal ramp) */
  --st-awake: #86b6ef;
  --st-rem: #5598e7;
  --st-light: #256abf;
  --st-deep: #104281;
  --range: #2a78d6;
  --ref: #9a9993;
  --pos: #2a78d6;          /* above goal (diverging: blue) */
  --neg: #e34948;          /* below goal (diverging: red) */
  --neg-ink: #c0352f;
  --series-1: #2a78d6;     /* categorical slot 1 */
  --series-2: #eb6834;     /* categorical slot 2 */
  --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4;
  --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --shade: #f0efec;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2b;
    --grid: #262624;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #96958d;
    --accent: #1e9b6d;
    --danger: #e66767;
    --warn-bg: #3a2e10;
    --warn-ink: #f6d58a;
    --st-awake: #cde2fb;
    --st-rem: #86b6ef;
    --st-light: #3987e5;
    --st-deep: #1c5cab;
    --range: #3987e5;
    --ref: #6c6b65;
    --pos: #3987e5;
    --neg: #e66767;
    --neg-ink: #f08585;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70; --series-4: #c98500; --series-5: #d55181;
    --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --shade: #232321;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --border: #2e2e2b; --grid: #262624;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #96958d; --accent: #1e9b6d; --danger: #e66767;
  --warn-bg: #3a2e10; --warn-ink: #f6d58a;
  --st-awake: #cde2fb; --st-rem: #86b6ef; --st-light: #3987e5; --st-deep: #1c5cab;
  --range: #3987e5; --ref: #6c6b65; --shadow: none;
  --pos: #3987e5; --neg: #e66767; --neg-ink: #f08585; --series-1: #3987e5; --series-2: #d95926; --shade: #232321;
  --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.icon { width: 36px; padding: 0; font-size: 20px; line-height: 1; }

.logo { width: 22px; height: 22px; fill: var(--accent); }

/* Sign-in */
.signin { max-width: 420px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.signin .logo { width: 44px; height: 44px; }
.signin h1 { font-size: 28px; margin: 8px 0 6px; }
.signin p { color: var(--text-2); }
.signin .fine { font-size: 13px; color: var(--muted); }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
  overflow: hidden; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary img { width: 100%; height: 100%; object-fit: cover; }
.menu-panel {
  position: absolute; right: 0; top: 44px; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px;
}
.menu-who { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; cursor: pointer; }
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--danger); }

.banner {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: 10px;
  background: var(--warn-bg); color: var(--warn-ink);
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.banner .btn { border-color: transparent; }

/* Layout */
.content { max-width: 960px; margin: 0 auto; padding: 16px 16px 48px; display: grid; gap: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; color: var(--text-2); font: inherit; padding: 6px 14px; cursor: pointer; min-width: 44px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .value small { font-size: 15px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.hint { margin: 6px 0 0; }
.empty { text-align: center; color: var(--text-2); }
.empty h2 { margin-bottom: 6px; color: var(--text); }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--grid); }
.chart .ref { stroke: var(--ref); stroke-dasharray: 4 4; }
.chart .ref-label { fill: var(--text-2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .bar-group.dim { opacity: .35; }
.chart .sel-outline { fill: none; stroke: var(--text); stroke-width: 1.5; }
.chart .range-bar { fill: var(--range); }

.night-nav { display: flex; gap: 6px; }
.night-stats { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 10px; font-size: 13px; color: var(--text-2); }
.night-stats strong { color: var(--text); font-size: 15px; }

details > summary { cursor: pointer; }
details > summary h2 { display: inline; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-2); font-weight: 600; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.16);
  padding: 8px 10px; font-size: 13px; min-width: 150px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
.tooltip .tt-row b { color: var(--text); font-weight: 600; }
.tooltip .tt-row i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

@media (max-width: 560px) {
  #sync-status { display: none; }
  h1 { font-size: 19px; }
  .tile .value { font-size: 22px; }
}

/* ── Insights ── */
.duo { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.headline { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 2px 0 4px; }
.headline .neg { color: var(--neg-ink); }
.headline .pos { color: var(--pos); }
.explain { margin: 0 0 12px; color: var(--text-2); font-size: 14px; }
.chart .zero { stroke: var(--ref); }
.chart .week-shade { fill: var(--shade); }
.chart .shade-label { fill: var(--muted); font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
.chart .missing { fill: var(--ref); }
.chart .row-label { fill: var(--text-2); font-size: 12px; }
.chart .mid-dot { fill: var(--surface); stroke: var(--text); stroke-width: 1.5; }
.legend i.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ref); }
#debt-legend { margin-top: 8px; }

/* ── Streaks & badges ── */
.streaks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.streak { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 10px; background: var(--bg); }
.streak-icon { font-size: 28px; line-height: 1; }
.streak-label { font-size: 13px; color: var(--text-2); }
.streak-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.streak-value small { font-size: 14px; font-weight: 500; color: var(--text-2); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; background: var(--surface); }
.badge-icon { font-size: 30px; line-height: 1.1; filter: grayscale(1); opacity: .45; }
.badge-name { font-weight: 600; font-size: 14px; margin-top: 6px; }
.badge-desc { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 2.6em; }
.badge-meta { font-size: 12px; color: var(--text-2); margin-top: 6px; }
.badge.earned { border-color: var(--accent); }
.badge.earned .badge-icon { filter: none; opacity: 1; }
.badge.earned .badge-meta { color: var(--accent); font-weight: 600; }

/* ── Wrapped promo ── */
.wrapped-promo {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 18px; border-radius: 12px; color: #fff;
  background: linear-gradient(120deg, #1b1446 0%, #3b2a8f 45%, #b0417a 100%);
}
.promo-kicker { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.promo-title { font-size: 18px; font-weight: 600; margin-top: 2px; }
.promo-actions { display: flex; gap: 8px; }
.promo-actions select {
  min-height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12); color: #fff; font: inherit; padding: 0 8px;
}
.promo-actions select option { color: #000; }
.promo-btn { background: #fff; color: #1b1446; border-color: #fff; }

/* ── Wrapped story ── */
.wrapped {
  position: fixed; inset: 0; z-index: 50; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 56px 24px 40px; overflow: hidden;
  transition: background .5s ease;
}
.wrapped.theme-1 { background: radial-gradient(circle at 30% 20%, #3a2f8f, #0e0b26 70%); }
.wrapped.theme-2 { background: radial-gradient(circle at 70% 30%, #1f6fb8, #071a33 70%); }
.wrapped.theme-3 { background: radial-gradient(circle at 30% 70%, #6a3fb5, #150c2e 70%); }
.wrapped.theme-4 { background: radial-gradient(circle at 70% 70%, #b8571f, #2a0f07 70%); }
.wrapped.theme-5 { background: radial-gradient(circle at 50% 30%, #c79a16, #2b1b02 72%); }
.wrapped.theme-6 { background: radial-gradient(circle at 30% 30%, #138a6a, #04211a 70%); }
.wrapped.theme-7 { background: radial-gradient(circle at 60% 40%, #b03c86, #26071b 70%); }
.wrapped.theme-8 { background: linear-gradient(140deg, #1b1446, #3b2a8f 45%, #b0417a); }
.wr-progress { position: absolute; top: 14px; left: 16px; right: 60px; display: flex; gap: 4px; }
.wr-progress span { flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,.28); }
.wr-progress span.done { background: #fff; }
.wr-close {
  position: absolute; top: 4px; right: 10px; z-index: 3; width: 44px; height: 44px;
  border: 0; background: none; color: #fff; font-size: 30px; cursor: pointer;
}
.wr-nav { position: absolute; top: 0; bottom: 0; z-index: 1; border: 0; background: none; cursor: pointer; }
.wr-prev { left: 0; width: 30%; }
.wr-next { right: 0; width: 70%; }
.wr-nav:focus-visible { outline: 2px solid rgba(255,255,255,.6); outline-offset: -6px; }
.wr-slide { position: relative; z-index: 0; max-width: 520px; width: 100%; text-align: center; pointer-events: none; }
.wr-slide.enter > * { animation: wr-rise .55s cubic-bezier(.2,.8,.2,1) both; }
.wr-slide.enter > :nth-child(2) { animation-delay: .06s; }
.wr-slide.enter > :nth-child(3) { animation-delay: .14s; }
.wr-slide.enter > :nth-child(4) { animation-delay: .26s; }
.wr-slide.enter > :nth-child(5) { animation-delay: .36s; }
.wr-slide.enter > :nth-child(6) { animation-delay: .5s; }
@keyframes wr-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.wr-emoji { font-size: 56px; margin-bottom: 12px; }
.wr-kicker { font-size: 15px; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.wr-big { font-size: clamp(40px, 11vw, 72px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; margin: 10px 0 14px; }
.wr-sub { font-size: 18px; line-height: 1.45; opacity: .92; }
.wr-list { list-style: none; padding: 0; margin: 22px auto 0; max-width: 320px; text-align: left; }
.wr-list li { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid rgba(255,255,255,.18); font-size: 16px; }
.wr-list b { font-weight: 700; }
.wr-hint { margin-top: 36px; font-size: 13px; opacity: .55; }
@media (prefers-reduced-motion: reduce) {
  .wr-slide.enter > * { animation: none; }
  .wrapped { transition: none; }
}

/* ── Tabs ── */
.top { flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tabs a { padding: 6px 14px; border-radius: 7px; color: var(--text-2); text-decoration: none; font-weight: 500; font-size: 14px; }
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 560px) {
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; text-align: center; }
}

/* ── Friends ── */
.toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
select, .inline-form input {
  min-height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit; padding: 0 10px;
}
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.btn.danger { color: var(--danger); }
.small-btn { min-height: 30px; padding: 0 10px; font-size: 13px; }
.invite-note { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chips button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; min-height: 32px;
}
.chips button[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }

.leaderboard { list-style: none; margin: 0; padding: 0; }
.lb-row {
  display: grid; grid-template-columns: 30px 32px minmax(60px, 140px) 1fr auto; align-items: center; gap: 10px;
  padding: 8px 8px; border-radius: 8px;
}
.lb-row + .lb-row { border-top: 1px solid var(--grid); }
.lb-row.you { background: var(--bg); }
.lb-rank { text-align: center; font-weight: 600; color: var(--text-2); font-size: 15px; }
.lb-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-bar { height: 10px; border-radius: 0 4px 4px 0; background: var(--grid); overflow: hidden; }
.lb-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.lb-bar.empty { background: none; }
.lb-value { font-weight: 600; text-align: right; white-space: nowrap; }
.muted-row .lb-name { color: var(--muted); }
.lb-cta { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; }
@media (max-width: 560px) {
  .lb-row { grid-template-columns: 26px 28px 1fr auto; }
  .lb-bar { grid-column: 3 / 5; grid-row: 2; }
  .lb-bar.empty { display: none; }
}

.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; outline: 2px solid transparent; outline-offset: 1px; flex: none; }
.avatar.initials { display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 13px; }

.chart .crosshair { stroke: var(--text-2); stroke-width: 1; }
.chart .hover-dot, .chart .end-dot { stroke: var(--surface); stroke-width: 2; }
.chart .series-label { fill: var(--text-2); font-size: 12px; font-weight: 500; }

.h2h-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }
.h2h-person { display: flex; align-items: center; gap: 8px; }
.h2h-person.right { justify-content: flex-end; }
.h2h-score { font-weight: 700; font-size: 15px; padding: 4px 12px; border-radius: 999px; background: var(--bg); text-align: center; }
.h2h-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--grid); align-items: center; }
.h2h-label { color: var(--muted); font-size: 13px; text-align: center; min-width: 110px; }
.h2h-val { font-size: 16px; color: var(--text-2); }
.h2h-val.right { text-align: right; }
.h2h-val.win { color: var(--text); font-weight: 700; }

.members { list-style: none; margin: 0 0 14px; padding: 0; }
.members li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.member-main { flex: 1; min-width: 0; }
.member-name { font-weight: 500; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2);
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; }
.share-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.share-chip { font-size: 11px; color: var(--muted); border: 1px dashed var(--border); border-radius: 999px; padding: 1px 7px; }
.share-chip.on { color: var(--text-2); border-style: solid; }
.invite-box { margin-bottom: 12px; }
.invite-box label { display: block; margin-bottom: 4px; }
.group-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.toggles { display: grid; gap: 8px; }
.toggle { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .switch { flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--ref); position: relative; transition: background .15s; margin-top: 1px; }
.toggle .switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-text { display: flex; flex-direction: column; }

/* ── Modal ── */
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); color: var(--text);
  border-radius: 14px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { font-size: 20px; margin: 4px 0 8px; }
.modal-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.join-error { color: var(--danger); font-size: 14px; }

/* ── Steps ── */
#group-view, #steps-body { display: grid; gap: 16px; }
.chart .steps-bar { fill: var(--series-1); }
.chart .steps-bar.today { fill: var(--series-1); opacity: .45; }
.weekdays { display: grid; gap: 8px; }
.wd-row { display: grid; grid-template-columns: 38px 1fr 64px; align-items: center; gap: 10px; font-size: 14px; }
.wd-name { color: var(--text-2); }
.wd-bar, .vs-bar { height: 12px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.wd-bar i, .vs-bar i { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.wd-val, .vs-val { text-align: right; font-weight: 600; }
.vs-rows { display: grid; gap: 12px; margin: 8px 0 10px; }
.vs-row { display: grid; grid-template-columns: minmax(120px, 160px) 1fr 70px; gap: 10px; align-items: center; }
.vs-label { display: flex; flex-direction: column; }

/* ── Group fun ── */
.night-nav { align-items: center; }
.group-streak { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--bg); margin-bottom: 12px; font-size: 14px; }
.gs-flame { font-size: 22px; line-height: 1; }
.awards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.award { display: flex; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.award.mine { border-color: var(--accent); background: var(--bg); }
.award-emoji { font-size: 28px; line-height: 1.1; }
.award-body { min-width: 0; }
.award-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 600; }
.award-winner { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px; flex-wrap: wrap; }
.award-winner .avatar { width: 22px; height: 22px; font-size: 11px; }
.trophy-cabinet { margin-top: 14px; }
.trophy-cabinet summary { font-weight: 600; font-size: 14px; }
.trophies { list-style: none; padding: 0; margin: 10px 0 0; }
.trophy-row { display: grid; grid-template-columns: 28px minmax(70px, 140px) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--grid); }
.trophy-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trophy-items { display: flex; flex-wrap: wrap; gap: 4px; }
.trophy-chip { font-size: 13px; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); }
.trophy-total { font-weight: 700; }

.ch-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.ch-emoji { font-size: 34px; line-height: 1; }
.ch-name { font-weight: 700; font-size: 17px; }
.ch-meta { color: var(--text-2); margin-top: 2px; }
.ch-list { list-style: none; padding: 0; margin: 0 0 12px; }
.ch-list li { display: grid; grid-template-columns: 22px 28px minmax(70px, 140px) 1fr auto; gap: 10px; align-items: center; padding: 7px 0; border-top: 1px solid var(--grid); }
.ch-list li.you { font-weight: 600; }
ul.ch-list li { grid-template-columns: 28px 1fr auto; }
.ch-rank { text-align: center; color: var(--text-2); font-weight: 600; }
.ch-bar { height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.ch-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.ch-bar.empty { background: none; }
.ch-val { font-weight: 600; text-align: right; white-space: nowrap; }
.team-bar { height: 16px; border-radius: 999px; background: var(--grid); overflow: hidden; }
.team-bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.team-label { margin: 6px 0 10px; font-size: 14px; color: var(--text-2); }
.ch-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin-bottom: 12px; }
.ch-opt { display: flex; gap: 10px; text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.ch-opt[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--bg); }
.ch-opt-emoji { font-size: 24px; line-height: 1.1; }
.ch-opt-text { display: flex; flex-direction: column; gap: 1px; }
.ch-opt-kind { color: var(--accent); font-weight: 600; margin-top: 2px; }
.past-challenges { margin-top: 14px; font-size: 14px; }
.past-challenges summary { font-weight: 600; }
.past-challenges ul { padding-left: 18px; margin: 8px 0 0; }
.past-challenges li { margin: 4px 0; }
@media (max-width: 560px) {
  .ch-list li { grid-template-columns: 18px 26px 1fr auto; }
  .ch-list li .ch-bar { grid-column: 3 / 5; grid-row: 2; }
  .ch-list li .ch-bar.empty { display: none; }
  .trophy-row { grid-template-columns: 28px 1fr auto; }
  .trophy-items { grid-column: 2 / 4; grid-row: 2; }
}

/* ── Last night ── */
.ln-highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.ln-hl { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.ln-hl > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.ln-hl-emoji { font-size: 24px; line-height: 1; }
.ln-list { list-style: none; margin: 0; padding: 0; }
.ln-row { display: flex; gap: 10px; align-items: center; padding: 9px 6px; border-top: 1px solid var(--grid); }
.ln-row.you { background: var(--bg); border-radius: 8px; }
.ln-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ln-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ln-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ln-asleep { font-weight: 700; white-space: nowrap; }
.ln-goal { color: var(--accent); }
.ln-bar { position: relative; height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; }
.ln-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.ln-goal-tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-2); border-radius: 1px; }
.ln-empty { margin-left: auto; }

/* ── Group sleep debt & social jet lag ── */
.small-headline { font-size: 17px; margin-bottom: 10px; }
.gbars { list-style: none; margin: 0; padding: 0; }
.gbar-row { display: grid; grid-template-columns: 28px minmax(60px, 110px) 1fr minmax(96px, auto); gap: 10px; align-items: center; padding: 8px 6px; border-top: 1px solid var(--grid); }
.gbar-row.you { background: var(--bg); border-radius: 8px; }
.gbar-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; flex-direction: column; }
.gbar-sub { font-weight: 400; white-space: normal; }
.gbar-track { position: relative; height: 10px; background: var(--grid); border-radius: 4px; }
.gbar-track.empty { background: none; }
.gbar-track i { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.gbar-track i.neg { background: var(--neg); border-radius: 4px 0 0 4px; }
.gbar-track i.pos { background: var(--pos); border-radius: 0 4px 4px 0; }
.gbar-zero { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text-2); }
.gbar-val { text-align: right; font-weight: 600; white-space: nowrap; font-size: 14px; }
.gbar-val.neg-ink { color: var(--neg-ink); }
#gdebt-legend { margin-top: 10px; }
@media (max-width: 560px) {
  .gbar-row { grid-template-columns: 28px 1fr auto; }
  .gbar-track { grid-column: 2 / 4; grid-row: 2; }
  .gbar-track.empty { display: none; }
}

/* ════════════ Phones ════════════ */
.tab-icon, .sync-icon, .section-tabs { display: none; }
/* Charts are drawn at their container's width; never stretch one up (that blows up its text) */
.chart svg { width: auto; max-width: 100%; }
/* Card titles with ‹ › arrows keep the arrows on the same line */
.card-head:has(> .night-nav) { flex-wrap: nowrap; align-items: flex-start; }
.card-head:has(> .night-nav) > h2 { flex: 1; min-width: 0; padding-top: 7px; }
.night-nav { flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  /* Slim top bar that scrolls away; Sleep / Friends move to a bottom tab bar */
  .top { position: static; padding: 8px 12px; flex-wrap: nowrap; border-bottom: 0; }
  .brand { font-size: 16px; }
  #sync-btn { width: 38px; height: 38px; min-height: 38px; padding: 0; border-radius: 50%; }
  #sync-btn .sync-label { display: none; }
  .sync-icon { display: block; width: 18px; height: 18px; fill: currentColor; }
  #sync-btn.syncing .sync-icon { animation: spin 1s linear infinite; }

  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; order: 0; width: auto; gap: 0;
    border: 0; border-top: 1px solid var(--border); border-radius: 0;
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    background: var(--surface); box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  }
  .tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 0 3px; font-size: 12px; border-radius: 12px; }
  .tabs a[aria-current="page"] { background: none; color: var(--accent); font-weight: 600; }
  .tab-icon { display: block; width: 24px; height: 24px; fill: currentColor; }
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }

  /* Compact banner: the one-line message plus the button */
  .banner { margin: 4px 12px 0; padding: 8px 10px 8px 12px; font-size: 13px; gap: 8px; flex-wrap: nowrap; }
  .banner .btn { min-height: 32px; padding: 0 12px; font-size: 13px; flex: none; }
  .banner-more { display: none; }

  /* Tighter spacing everywhere */
  .content { padding: 8px 12px 20px; gap: 12px; }
  #group-view { gap: 12px; }
  .duo { gap: 12px; }
  .card { padding: 14px; border-radius: 14px; }
  .card-head { margin-bottom: 8px; }
  .toolbar h1 { font-size: 20px; }
  .headline { font-size: 21px; }
  .explain { font-size: 13.5px; }

  /* Sub-tabs: one group of sections at a time */
  .section-tabs {
    display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
    position: sticky; top: 0; z-index: 4; background: var(--bg);
    margin: -2px -12px 0; padding: 6px 12px 8px;
  }
  .section-tabs::-webkit-scrollbar { display: none; }
  .section-tabs button {
    flex: 1 0 auto; min-height: 38px; padding: 0 14px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
    font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  }
  .section-tabs button[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
  #view-me[data-show="overview"] [data-section]:not([data-section="overview"]),
  #view-me[data-show="patterns"] [data-section]:not([data-section="patterns"]),
  #view-me[data-show="fun"] [data-section]:not([data-section="fun"]),
  #view-friends[data-show="today"] [data-section]:not([data-section="today"]),
  #view-friends[data-show="compete"] [data-section]:not([data-section="compete"]),
  #view-friends[data-show="trends"] [data-section]:not([data-section="trends"]),
  #view-friends[data-show="group"] [data-section]:not([data-section="group"]) { display: none !important; }
  /* The 7 / 30 / 90 picker only where it matters */
  #view-me[data-show="fun"] .toolbar .seg,
  #view-friends[data-show="today"] #friends-range,
  #view-friends[data-show="group"] #friends-range { display: none; }

  /* Tiles */
  .tiles { gap: 8px; }
  .tile { padding: 10px 12px; border-radius: 12px; }
  .tile .value { font-size: 21px; }
  .tile .label { font-size: 12.5px; }

  /* Swipeable single row of metric chips */
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px 10px; padding: 0 14px; }
  .chips::-webkit-scrollbar { display: none; }
  .chips button { flex: none; }

  /* Two-up grids instead of one tall column */
  .streaks { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .streak { flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 12px; }
  .streak-icon { font-size: 22px; }
  .streak-value { font-size: 20px; }
  .badges { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .badge { padding: 10px 8px; }
  .badge-icon { font-size: 24px; }
  .badge-desc { font-size: 11.5px; min-height: 0; }
  .awards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .award { flex-direction: column; gap: 2px; padding: 10px; }
  .award-emoji { font-size: 22px; }
  .ln-highlights { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 8px; }
  .ln-hl { flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; }
  .ln-hl strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .ln-hl-emoji { font-size: 20px; }

  /* Rows */
  .ln-row, .gbar-row { padding: 8px 4px; }
  .h2h-label { min-width: 0; font-size: 12px; }
  .h2h-val { font-size: 15px; }
  .members li { gap: 8px; }

  /* Wrapped banner: picker and Play share a full-width row */
  .wrapped-promo { padding: 14px; gap: 10px; }
  .promo-title { font-size: 16px; }
  .promo-actions { width: 100%; }
  .promo-actions select { flex: 1; min-width: 0; }

  .night-stats { gap: 4px 14px; }
  .modal { padding: 16px; }
}

/* Challenge picker folded behind a button; "Last night" date under the title */
.ch-start > summary { list-style: none; display: inline-flex; }
.ch-start > summary::-webkit-details-marker { display: none; }
.ch-start[open] > summary { display: none; }
.ch-start-note { margin-top: 0; }
.ln-date { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 1px; }
@media (max-width: 640px) {
  .ch-opt { padding: 9px 10px; }
  .ch-opts { gap: 6px; }
}

/* ── Steps ── */
:root {
  --bar: #7cc9a6;           /* a day under the goal */
  --bar-goal: #11704f;      /* a day at 10k+ */
  --avg-line: #eb6834;
  --alt: #8a7fd6;           /* "more on weekdays" in the diverging weekend chart */
  --ring-track: #e3efe9;
  --ring-extra: #0a4a34;
  --pos-ink: #11704f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bar: #2f6b55; --bar-goal: #2fbf8a; --avg-line: #f08a5d; --alt: #9085e9;
    --ring-track: #22302a; --ring-extra: #8fe3c0; --pos-ink: #4fd3a0; --pos: #2fbf8a;
  }
}
:root[data-theme="dark"] {
  --bar: #2f6b55; --bar-goal: #2fbf8a; --avg-line: #f08a5d; --alt: #9085e9;
  --ring-track: #22302a; --ring-extra: #8fe3c0; --pos-ink: #4fd3a0; --pos: #2fbf8a;
}
:root:not([data-theme="dark"]) { --pos: #1a8a62; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --pos: #2fbf8a; } }

#group-view { display: grid; gap: 16px; }
.chart .steps-bar { fill: var(--bar); }
.chart .steps-bar.goal { fill: var(--bar-goal); }
.chart .steps-bar.today { opacity: .5; }
.chart .avg-line { fill: none; stroke: var(--avg-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.legend i.line { height: 3px; width: 14px; border-radius: 2px; }
.pos-ink { color: var(--pos-ink); font-weight: 600; }

.today-card { display: flex; align-items: center; gap: 22px; }
.today-ring { flex: none; }
.ring { display: block; }
.ring-track { fill: none; stroke: var(--ring-track); }
.ring-fill { fill: none; stroke: var(--bar-goal); stroke-linecap: round; }
.ring-extra { fill: none; stroke: var(--ring-extra); stroke-linecap: round; }
.ring-label { font-size: 22px; font-weight: 700; fill: var(--text); }
.today-kicker { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.today-big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.today-sub { font-size: 15px; }
.today-compare { margin-top: 6px; }

.weekdays { display: grid; gap: 8px; }
.wd-row { display: grid; grid-template-columns: 38px 1fr 64px; align-items: center; gap: 10px; font-size: 14px; }
.wd-name { color: var(--text-2); }
.wd-row.best .wd-name, .wd-row.best .wd-val { color: var(--text); font-weight: 700; }
.wd-bar, .vs-bar { height: 12px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.wd-bar i, .vs-bar i { display: block; height: 100%; background: var(--bar-goal); border-radius: 0 4px 4px 0; }
.wd-val, .vs-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.wd-note { margin: 4px 0 0; }
.vs-rows { display: grid; gap: 12px; margin: 8px 0 10px; }
.vs-row { display: grid; grid-template-columns: minmax(110px, 150px) 1fr 70px; gap: 10px; align-items: center; }
.vs-label { display: flex; flex-direction: column; }

.jr-list { list-style: none; margin: 4px 0 8px; padding: 0; display: grid; gap: 6px; }
.jr-row { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.jr-row:last-child { border-bottom: 0; }
.jr-dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--ring-track); color: var(--pos-ink); font-weight: 700; }
.jr-row.next .jr-dot { background: var(--accent); color: var(--accent-ink); }
.jr-row.done .jr-name { color: var(--text-2); }
.jr-name { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.jr-row.next .jr-name > span:first-child { font-weight: 600; }
.jr-track { height: 8px; border-radius: 999px; background: var(--grid); overflow: hidden; }
.jr-track i { display: block; height: 100%; background: var(--bar-goal); border-radius: 999px; }
.jr-val { white-space: nowrap; font-variant-numeric: tabular-nums; }

.stack-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; gap: 2px; background: var(--grid); margin: 10px 0 8px; }
.stack-bar i { display: block; min-width: 3px; }
.gbar-track i.alt { background: var(--alt); border-radius: 4px 0 0 4px; }

@media (max-width: 640px) {
  .today-card { gap: 14px; }
  .today-ring .ring { width: 104px; height: 104px; }
  .today-big { font-size: 32px; }
  .today-sub { font-size: 14px; }
  .vs-row { grid-template-columns: minmax(90px, 120px) 1fr 60px; }
}
@media (max-width: 640px) {
  /* An odd last tile spans the row instead of sitting alone */
  .tiles > .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
