/* Pulse design system
   - One font family, 4 sizes (12/15/20/44), 2 weights (500/700), tabular figures for metrics
   - 60/30/10: dark neutral base / light text / brand orange accent
   - 8-point spacing grid; tap targets >= 44px; motion respects prefers-reduced-motion */

:root {
  --bg: #07090d;
  --surface: rgb(var(--ink) / 0.045);
  --surface-2: rgb(var(--ink) / 0.075);
  --line: rgb(var(--ink) / 0.08);
  --text: #f2f4f7;
  --text-2: rgba(242, 244, 247, 0.8);
  --text-3: rgba(242, 244, 247, 0.6);
  --brand: #e85d33;
  --brand-hi: #ff7a4d;
  --brand-5: rgba(232, 93, 51, 0.08);
  --green: #2be36a;
  --yellow: #ffd23f;
  --red: #ff4d5e;
  --strain: #3aa0ff;
  --sleep: #9b8cff;
  --deep: #5b4fe0;
  --rem: #a98bff;
  --light: #6fb1e8;
  --awake: var(--text);
  --accent: var(--brand); /* recolored by recovery zone */
  --fs-sm: 12px;
  --fs-md: 15px;
  --fs-lg: 20px;
  --fs-xl: 44px;
  --r-card: 24px;
  --r-pill: 999px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  /* theme tokens (dark default) */
  --ink: 255 255 255;          /* overlays, tracks and hairlines are this colour at low opacity */
  --bg-rgb: 7 9 13;
  --bg-2: #151a22;
  --pop: #1b212b;              /* toasts, tooltips */
  --card: rgba(255, 255, 255, 0.05);
  --sheet-bg: #10141b;
  --ai-bg: #12161e;
  --banner-text: #ffe39a;
  --error-text: #ff9aa5;
  --warn-text: #ffd2a6;
  --high-text: #ffb3bb;
  --tabbar-bg: rgba(18, 22, 29, 0.78);
  --shadow-k: 1;
  color-scheme: dark;
}

/* Light theme follows the phone's system setting. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7;
    --bg-rgb: 243 244 247;
    --ink: 15 23 42;
    --surface: rgba(15, 23, 42, 0.035);
    --surface-2: rgba(15, 23, 42, 0.06);
    --line: rgba(15, 23, 42, 0.1);
    --text: #111827;
    --text-2: rgba(17, 24, 39, 0.8);
    --text-3: rgba(17, 24, 39, 0.6);
    --brand-hi: #e4572e;
    --brand-5: rgba(232, 93, 51, 0.1);
    --green: #12a150;
    --yellow: #d49a00;
    --red: #e5384a;
    --strain: #1f7fe0;
    --sleep: #6d5bf0;
    --deep: #4a3fd0;
    --rem: #8e6cf5;
    --light: #3f8fd2;
    --bg-2: #ffffff;
    --pop: #ffffff;
    --card: #ffffff;
    --sheet-bg: #ffffff;
    --ai-bg: #ffffff;
    --banner-text: #7a5600;
    --error-text: #b4232f;
    --warn-text: #8a4b00;
    --high-text: #b4232f;
    --tabbar-bg: rgba(255, 255, 255, 0.82);
    --shadow-k: 0.22;
    color-scheme: light;
  }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 500 var(--fs-md)/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--text-3); }
.small { font-size: var(--fs-sm); }
.label { font-size: var(--fs-sm); color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }

/* ---------- Ambient background that follows recovery ---------- */
.aurora { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.aurora span {
  position: absolute; width: 90vmax; height: 90vmax; border-radius: 50%;
  opacity: 0.22; background: radial-gradient(closest-side, var(--accent), transparent 70%);
  animation: drift 24s ease-in-out infinite alternate;
  transition: background 1.2s var(--ease);
}
.aurora span:nth-child(1) { top: -35vmax; left: -20vmax; }
.aurora span:nth-child(2) { top: -25vmax; right: -35vmax; background: radial-gradient(closest-side, var(--brand), transparent 70%); opacity: 0.14; animation-duration: 30s; }
.aurora span:nth-child(3) { bottom: -45vmax; left: 10vmax; background: radial-gradient(closest-side, var(--strain), transparent 70%); opacity: 0.08; animation-duration: 36s; }
@keyframes drift { to { transform: translate3d(6vmax, 4vmax, 0) scale(1.08); } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: linear-gradient(to bottom, rgb(var(--bg-rgb) / 0.92), rgb(var(--bg-rgb) / 0.6));
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.24em; font-size: var(--fs-md); color: var(--text); text-decoration: none; }
.brand img, .brand svg { height: 28px; width: auto; }
.brand .word { color: var(--brand); }
.datenav { display: flex; align-items: center; gap: 4px; }
.date-chip { min-height: 44px; padding: 0 16px; border-radius: var(--r-pill); font-weight: 700; transition: background 0.2s; }
.date-chip:active { background: var(--surface-2); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  transition: background 0.2s, transform 0.2s var(--spring);
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: scale(0.9); background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.25; pointer-events: none; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#refresh.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pull to refresh ---------- */
.ptr {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 64px); z-index: 30;
  width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  display: grid; place-items: center; background: var(--bg-2); border: 1px solid var(--line);
  transform: translateY(-80px) scale(0.6); opacity: 0; pointer-events: none;
  box-shadow: 0 8px 24px rgb(0 0 0 / calc(0.4 * var(--shadow-k)));
}
.ptr svg { width: 20px; height: 20px; fill: none; stroke: var(--brand-hi); stroke-width: 2.4; stroke-linecap: round; }
.ptr.ready svg { stroke: var(--green); }
.ptr.loading svg { animation: spin 0.9s linear infinite; }

/* ---------- Tab bar: bottom on phones, top pill on desktop ---------- */
.tabbar {
  position: fixed; z-index: 25; left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 12px);
  height: var(--tabbar-h);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px; border-radius: 22px;
  background: var(--tabbar-bg);
  border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  box-shadow: 0 16px 40px rgb(0 0 0 / calc(0.45 * var(--shadow-k)));
}
.tabbar button {
  position: relative; z-index: 1; display: grid; place-items: center; align-content: center; gap: 2px;
  color: var(--text-3); font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  transition: color 0.25s, transform 0.2s var(--spring);
}
.tabbar button:active { transform: scale(0.92); }
.tabbar button[aria-selected="true"] { color: var(--text); }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-selected="true"] svg { stroke: var(--brand-hi); }
.tab-indicator {
  position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc((100% - 12px) / 4);
  border-radius: 16px; background: var(--brand-5);
  border: 1px solid rgba(232, 93, 51, 0.22);
  transition: transform 0.45s var(--spring);
}

/* ---------- Layout ---------- */
main { max-width: 1120px; margin: 0 auto; overflow-x: clip; padding: 8px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 40px); }
.view { animation: view-in 0.45s var(--ease) both; }
.view.slide-left { animation: slide-left 0.4s var(--ease) both; }
.view.slide-right { animation: slide-right 0.4s var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes slide-left { from { opacity: 0; transform: translateX(32px); } }
@keyframes slide-right { from { opacity: 0; transform: translateX(-32px); } }
.stack { display: grid; gap: 16px; }
.stack > *, .grid2 > *, .today-top > *, .side > *, .mini-rings > * { min-width: 0; }
.grid2 { display: grid; gap: 16px; }
.today-top, .today-top .side { display: grid; gap: 16px; align-content: start; }
.page-title { font-size: var(--fs-lg); font-weight: 700; margin: 8px 4px 16px; }
.greeting { margin: 8px 4px 16px; }
.greeting .label { margin-bottom: 4px; }
.greeting h1 { font-size: var(--fs-lg); font-weight: 700; }

/* ---------- Cards ---------- */
.card {
  position: relative; overflow: hidden; isolation: isolate; border-radius: var(--r-card); padding: 20px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgb(var(--ink) / 0.04) inset, 0 12px 32px rgb(0 0 0 / calc(0.25 * var(--shadow-k)));
}
.glass { background: var(--card); }
.card > *:not(.confetti) { position: relative; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.card-head h3 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-3); font-weight: 700; }
button.card { display: block; width: 100%; text-align: inherit; font: inherit; color: inherit; }
button.card.hero { display: grid; text-align: center; }
button.card.mini { display: flex; }
.tappable { cursor: pointer; transition: transform 0.25s var(--spring), background 0.25s, border-color 0.25s; }
.tappable:hover { border-color: rgb(var(--ink) / 0.14); }
.tappable:active { transform: scale(0.98); background: var(--surface-2); }
.rise { animation: rise 0.6s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
.chev { width: 18px; height: 18px; fill: none; stroke: var(--text-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.info-btn { width: 32px; height: 32px; margin: -6px; border-radius: 50%; display: grid; place-items: center; color: var(--text-3); }
.info-btn:active { background: var(--surface-2); }
.info-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line);
  font-weight: 700; text-decoration: none; color: var(--text);
  transition: transform 0.2s var(--spring), filter 0.2s, background 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn.primary {
  background: linear-gradient(180deg, var(--brand-hi), var(--brand)); border-color: transparent; color: #fff;
  box-shadow: inset 0 1px 0 rgb(var(--ink) / 0.35), 0 8px 24px rgba(232, 93, 51, 0.35);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { min-height: 52px; padding: 0 28px; font-size: var(--fs-md); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ---------- Banner / toast ---------- */
.banner {
  max-width: 1088px; margin: 8px auto 0; padding: 12px 16px; border-radius: 16px;
  background: rgba(255, 210, 63, 0.08); border: 1px solid rgba(255, 210, 63, 0.25); color: var(--banner-text);
  font-size: var(--fs-sm); animation: rise 0.4s var(--ease) both;
}
.banner.error { background: rgba(255, 77, 94, 0.08); border-color: rgba(255, 77, 94, 0.3); color: var(--error-text); }
.banner { width: calc(100% - 32px); margin-left: auto; margin-right: auto; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 28px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 12px 16px; border-radius: var(--r-pill); background: var(--pop); border: 1px solid var(--line);
  font-size: var(--fs-sm); font-weight: 700; box-shadow: 0 12px 32px rgb(0 0 0 / calc(0.45 * var(--shadow-k)));
  transition: opacity 0.3s, transform 0.4s var(--spring); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Hero (recovery) ---------- */
.hero { display: grid; justify-items: center; text-align: center; padding: 24px 20px; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; width: 240px; height: 240px; top: 24px; left: 50%; margin-left: -120px;
  border-radius: 50%; background: radial-gradient(closest-side, var(--accent), transparent 72%); opacity: 0.35; pointer-events: none; transition: background 1s var(--ease);
}
.ring { position: relative; display: grid; place-items: center; }
.ring svg { overflow: visible; }
.ring .track { stroke: rgb(var(--ink) / 0.07); }
.ring .bar { transition: stroke-dashoffset 1.4s var(--ease); filter: drop-shadow(0 0 8px var(--glow, transparent)); }
.ring .center { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; }
.ring .value { font-size: var(--fs-xl); font-weight: 700; line-height: 1; }
.ring .unit { font-size: var(--fs-sm); color: var(--text-3); font-weight: 700; letter-spacing: 0.1em; margin-top: 4px; }
.hero .ring { width: min(64vw, 240px); aspect-ratio: 1; }
.hero .ring svg { width: 100%; height: 100%; }
.hero-title { margin-top: 16px; display: flex; align-items: center; gap: 8px; font-size: var(--fs-lg); font-weight: 700; }
.zone-pill { padding: 4px 12px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 700; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.hero-sub { margin-top: 8px; color: var(--text-2); max-width: 36ch; }
.target-bar { width: min(100%, 320px); margin-top: 16px; }
.target-track { position: relative; height: 8px; border-radius: 8px; background: rgb(var(--ink) / 0.07); }
.target-range { position: absolute; top: 0; bottom: 0; border-radius: 8px; background: color-mix(in srgb, var(--strain) 45%, transparent); }
.target-now { position: absolute; top: -4px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--strain); border: 3px solid var(--bg); transition: left 1.2s var(--ease); }
.target-legend { display: flex; justify-content: space-between; margin-top: 8px; font-size: var(--fs-sm); color: var(--text-3); }

.mini-rings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mini { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 16px 12px; min-width: 0; }
.mini .ring { width: 80px; height: 80px; flex: none; }
.mini .ring svg { width: 80px; height: 80px; }
.mini .ring .value { font-size: var(--fs-md); }
.mini-text { min-width: 0; }
.mini-text .big { font-size: var(--fs-lg); font-weight: 700; }
.mini-text .muted { font-size: var(--fs-sm); }

/* ---------- Insights ---------- */
.insight { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.insight:first-of-type { border-top: 0; padding-top: 0; }
.insight .dot { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-5); color: var(--brand-hi); }
.insight .dot svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.insight p { color: var(--text-2); }

/* ---------- Vitals ---------- */
.vitals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.vital { padding: 16px; border-radius: 20px; text-align: left; }
.vital .top { display: flex; justify-content: space-between; align-items: center; }
.vital .value { font-size: var(--fs-lg); font-weight: 700; margin-top: 8px; }
.vital .value small { font-size: var(--fs-sm); color: var(--text-3); margin-left: 4px; font-weight: 500; }
.vital .delta { font-size: var(--fs-sm); color: var(--text-3); margin-top: 4px; min-height: 1.4em; }
.vital .spark { height: 28px; margin-top: 8px; }
.delta.good { color: var(--green); }
.delta.bad { color: var(--red); }

/* ---------- Sleep ---------- */
.hypno { position: relative; height: 128px; }
.hypno svg { width: 100%; height: 100%; }
.hypno text { fill: var(--text-3); font-size: 11px; font-weight: 500; }
.hypno rect { transform-origin: left center; animation: grow-x 0.8s var(--ease) both; animation-delay: calc(var(--d, 0) * 1ms); }
@keyframes grow-x { from { transform: scaleX(0); opacity: 0; } }
.stage-bar { display: flex; height: 12px; border-radius: 12px; overflow: hidden; margin: 16px 0 12px; gap: 2px; }
.stage-bar span { height: 100%; transform-origin: left; animation: grow-x 0.9s var(--ease) both; }
.stage-legend { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stage-legend div { font-size: var(--fs-sm); color: var(--text-3); }
.stage-legend b { display: block; color: var(--text); font-size: var(--fs-md); }
.stage-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin-top: 16px; }
.kv div { display: flex; justify-content: space-between; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.expander { display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; min-height: 44px; margin-top: 8px; color: var(--text-3); font-size: var(--fs-sm); font-weight: 700; }
.expander svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform 0.3s var(--ease); }
.expander[aria-expanded="true"] svg { transform: rotate(180deg); }
.collapse { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.4s var(--ease); }
.collapse > div { overflow: hidden; }
.collapse.open { grid-template-rows: 1fr; }

/* ---------- Activity ---------- */
.zone-row { display: grid; grid-template-columns: 80px 1fr 56px; align-items: center; gap: 12px; padding: 4px 0; font-size: var(--fs-sm); }
.zone-row .track { height: 10px; border-radius: 10px; background: rgb(var(--ink) / 0.06); overflow: hidden; }
.zone-row .track span { display: block; height: 100%; border-radius: 10px; transform-origin: left; animation: grow-x 0.9s var(--ease) both; }
.zone-row .mins { text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; }
.workout { border-top: 1px solid var(--line); }
.workout > button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 12px 0; text-align: left; }
.workout .w-icon { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--strain) 14%, transparent); color: var(--strain); }
.workout .w-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.workout .w-main { flex: 1; min-width: 0; }
.workout .w-meta { font-size: var(--fs-sm); color: var(--text-3); }
.workout .w-strain { font-size: var(--fs-lg); font-weight: 700; color: var(--strain); font-variant-numeric: tabular-nums; }
.workout .collapse .kv { margin: 0 0 12px; }

/* ---------- Charts ---------- */
.chart { position: relative; height: 180px; touch-action: pan-y; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart text { fill: var(--text-3); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); }
.chart .avg { stroke: var(--text-3); stroke-dasharray: 3 5; }
.chart .bar { transform-box: fill-box; transform-origin: bottom; animation: grow-y 0.7s var(--ease) both; animation-delay: calc(var(--d, 0) * 18ms); }
.chart .bar.dim { opacity: 0.35; transition: opacity 0.15s; }
.chart .line { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.4s var(--ease) forwards; }
.chart .area { opacity: 0; animation: fade 1s 0.4s var(--ease) forwards; }
.chart .cursor { stroke: var(--text-2); stroke-width: 1; }
.chart .cursor-dot { stroke: var(--bg); stroke-width: 3; }
@keyframes grow-y { from { transform: scaleY(0); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { to { opacity: 1; } }
.chart-tip {
  position: fixed; z-index: 70; pointer-events: none; transform: translate(-50%, calc(-100% - 12px));
  padding: 8px 12px; border-radius: 12px; background: var(--pop); border: 1px solid var(--line);
  font-size: var(--fs-sm); white-space: nowrap; box-shadow: 0 8px 24px rgb(0 0 0 / calc(0.45 * var(--shadow-k)));
}
.chart-tip b { display: block; font-size: var(--fs-md); }
.trend-card .card-head { margin-bottom: 8px; }
.trend-stats { display: flex; gap: 24px; margin-bottom: 8px; }
.trend-stats .big { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.trend-stats .muted { font-size: var(--fs-sm); }
.segmented { display: inline-flex; padding: 4px; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); }
.segmented button { min-height: 36px; padding: 0 16px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 700; color: var(--text-3); transition: background 0.25s, color 0.25s; }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

/* ---------- Sheet ---------- */
.sheet { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vvh, 100dvh); z-index: 80; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / calc(0.55 * var(--shadow-k))); opacity: 0; transition: opacity 0.3s; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(var(--vvh, 100dvh) * 0.88); overflow: auto; overscroll-behavior: contain;
  padding: 0 20px calc(var(--safe-bottom) + 24px); border-radius: 28px 28px 0 0;
  background: var(--sheet-bg); border-top: 1px solid var(--line);
  transform: translateY(100%); transition: transform 0.45s var(--ease);
  box-shadow: 0 -16px 48px rgb(0 0 0 / calc(0.5 * var(--shadow-k)));
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: translateY(0); }
.sheet-handle { display: grid; place-items: center; height: 24px; cursor: grab; touch-action: none; }
.sheet-handle span { width: 40px; height: 4px; border-radius: 4px; background: rgb(var(--ink) / 0.2); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { font-size: var(--fs-lg); font-weight: 700; }
.sheet-body > * + * { margin-top: 16px; }
.sheet-body p { color: var(--text-2); }
.comp { display: grid; gap: 12px; }
.comp-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.comp-row .track { grid-column: 1 / -1; height: 8px; border-radius: 8px; background: rgb(var(--ink) / 0.06); overflow: hidden; }
.comp-row .track span { display: block; height: 100%; border-radius: 8px; transform-origin: left; animation: grow-x 0.8s var(--ease) both; }
.big-stat { display: flex; align-items: baseline; gap: 8px; }
.big-stat .value { font-size: var(--fs-xl); font-weight: 700; line-height: 1; }

/* ---------- Skeleton ---------- */
.skel { border-radius: var(--r-card); background: linear-gradient(100deg, rgb(var(--ink) / 0.04) 30%, rgb(var(--ink) / 0.09) 50%, rgb(var(--ink) / 0.04) 70%); background-size: 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---------- Connect / empty ---------- */
.connect { max-width: 480px; margin: 48px auto 0; display: grid; justify-items: center; gap: 16px; text-align: center; padding: 32px 24px; }
.connect h1 { font-size: var(--fs-lg); font-weight: 700; }
.connect-icon img { border-radius: 18px; box-shadow: 0 12px 40px rgba(232, 93, 51, 0.35); animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.empty { text-align: center; padding: 32px 16px; color: var(--text-3); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 12px; fill: none; stroke: var(--text-3); stroke-width: 1.6; }

/* ---------- Pulse Age ---------- */
.age-hero { text-align: center; padding: 32px 20px 24px; overflow: hidden; }
.age-hero::before { content: ""; position: absolute; inset: auto 0 40% 0; height: 200px; background: radial-gradient(closest-side, var(--age-glow, var(--brand)), transparent); opacity: 0.25; }
.age-number { position: relative; font-size: 72px; font-weight: 700; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.age-compare { position: relative; margin-top: 8px; font-weight: 700; font-size: var(--fs-md); }
.age-compare.younger { color: var(--green); }
.age-compare.older { color: var(--red); }
.badges { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.badge { padding: 4px 12px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 700; color: var(--text-3); border: 1px solid var(--line); }
.age-scale { position: relative; margin: 24px 0 8px; height: 56px; }
.age-scale svg { width: 100%; height: 100%; overflow: visible; }
.age-scale text { fill: var(--text-3); font-size: 11px; font-weight: 700; }
.age-headline { position: relative; margin-top: 16px; color: var(--text-2); }
.factor { padding: 12px 0; border-top: 1px solid var(--line); }
.factor:first-child { border-top: 0; padding-top: 0; }
.factor-head { display: flex; justify-content: space-between; gap: 12px; }
.factor-head .impact { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.impact.younger { color: var(--green); }
.impact.older { color: var(--red); }
.factor-bar { position: relative; height: 8px; margin: 8px 0; border-radius: 8px; background: rgb(var(--ink) / 0.06); }
.factor-bar::after { content: ""; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; border-radius: 2px; background: rgb(var(--ink) / 0.25); }
.factor-bar span { position: absolute; top: 0; bottom: 0; border-radius: 8px; animation: grow-x 0.9s var(--ease) both; }
.factor-bar span.neg { transform-origin: right; }
.factor-detail { font-size: var(--fs-sm); color: var(--text-3); }
.rec { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.rec:first-child { border-top: 0; padding-top: 0; }
.rec .n { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-5); color: var(--brand-hi); font-weight: 700; }
.rec .why { font-size: var(--fs-sm); color: var(--text-3); margin-top: 4px; }
.rec .gain { font-size: var(--fs-sm); color: var(--green); font-weight: 700; margin-top: 4px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.metric-grid > div { padding: 12px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.metric-grid .v { font-weight: 700; font-size: var(--fs-md); margin-top: 4px; font-variant-numeric: tabular-nums; }
.field { display: grid; gap: 8px; }
.field label { font-size: var(--fs-sm); color: var(--text-3); font-weight: 700; }
.input { min-height: 48px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: rgb(var(--ink) / 0.04); color: var(--text); font: inherit; font-size: 16px; width: 100%; }
/* iOS Safari zooms the whole page when a focused field is under 16px, which pushed the chat bar off screen. */
input, textarea, select { font-size: max(16px, 1em); }
.input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 44px; padding: 0 16px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); font-weight: 700; color: var(--text-2); transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s var(--spring); }
.chip:active { transform: scale(0.95); }
.chip[aria-pressed="true"] { background: var(--brand-5); border-color: rgba(232, 93, 51, 0.5); color: var(--brand-hi); }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: 40%; left: 50%; width: 8px; height: 8px; border-radius: 2px; opacity: 0; animation: burst 1.4s var(--ease) forwards; animation-delay: calc(var(--k) * 12ms); }
@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); }
}

/* ---------- More ---------- */
.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 8px 0; border-top: 1px solid var(--line); text-align: left; width: 100%; text-decoration: none; }
.list-item:first-child { border-top: 0; }
.list-item .li-icon { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); }
.list-item .li-icon svg { width: 18px; height: 18px; fill: none; stroke: var(--text-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-sub { font-size: var(--fs-sm); color: var(--text-3); }
.list-item.danger, .list-item.danger .li-sub { color: var(--red); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--green); box-shadow: 0 0 0 0 rgba(43, 227, 106, 0.6); animation: ping 2s infinite; }
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgba(43, 227, 106, 0); } 100% { box-shadow: 0 0 0 0 rgba(43, 227, 106, 0); } }

/* ---------- Login / legal pages ---------- */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 32px 24px; border-radius: 28px; background: var(--surface); border: 1px solid var(--line); text-align: center; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); animation: rise 0.6s var(--ease) both; }
.login-card .logo { width: 220px; height: auto; margin: 0 auto 16px; }
.login-card form { display: grid; gap: 12px; margin-top: 24px; text-align: left; }
.login-card label { font-size: var(--fs-sm); color: var(--text-3); font-weight: 700; }
.error { color: var(--red); font-size: var(--fs-sm); margin-top: 12px; }
.legal-links { margin-top: 24px; font-size: var(--fs-sm); }
.legal-links a, .legal-doc a { color: var(--brand-hi); }
.legal { padding: 24px 16px 64px; }
.legal-doc { max-width: 720px; margin: 0 auto; }
.legal-doc .brand { margin-bottom: 24px; }
.legal-doc h1 { font-size: 28px; margin-bottom: 4px; }
.legal-doc h2 { font-size: var(--fs-lg); margin: 24px 0 8px; }
.legal-doc p, .legal-doc li { color: var(--text-2); margin-bottom: 8px; }

/* ---------- Larger screens ---------- */
@media (max-width: 560px) {
  .kv { grid-template-columns: 1fr; }
}
@media (min-width: 720px) {
  .vitals { grid-template-columns: repeat(3, 1fr); }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 960px) {
  :root { --tabbar-h: 56px; }
  .topbar { padding: 16px 24px; }
  .tabbar {
    position: sticky; top: 76px; left: auto; right: auto; bottom: auto;
    width: 440px; margin: 0 auto; height: 52px; border-radius: var(--r-pill); padding: 4px;
  }
  .tabbar button { grid-auto-flow: column; justify-content: center; gap: 8px; font-size: var(--fs-sm); }
  .tabbar svg { width: 18px; height: 18px; }
  .tab-indicator { top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 4); border-radius: var(--r-pill); }
  main { padding: 24px 24px 64px; }
  .grid2 { grid-template-columns: 1fr 1fr; align-items: start; }
  .today-top { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: stretch; }
  .today-top .side { display: grid; gap: 16px; align-content: start; }
  .mini-rings { grid-template-columns: 1fr 1fr; }
  .mini { flex-direction: row; text-align: left; gap: 16px; padding: 16px; }
  .toast { bottom: 32px; }
  .sheet-panel { left: 50%; right: auto; width: 520px; margin-left: -260px; bottom: 50%; border-radius: 28px; transform: translateY(calc(50% + 40px)); opacity: 0; transition: transform 0.4s var(--ease), opacity 0.3s; border: 1px solid var(--line); max-height: 80dvh; }
  .sheet.open .sheet-panel { transform: translateY(50%); opacity: 1; }
  .sheet-handle { visibility: hidden; height: 16px; }
}

/* ---------- Reveal on scroll + calm re-render ---------- */
.rise:not(.seen) { animation-play-state: paused; }
.sheet .rise, .calm .rise { animation-play-state: running; }
.calm .rise, .calm .chart .bar, .calm .chart .area, .calm .stress-bars span, .calm .zone-row .track span, .calm .stage-bar span, .calm .hypno rect, .calm .tile, .calm .range .dot { animation: none !important; opacity: 1; }
.calm .chart .line { animation: none; stroke-dashoffset: 0; }

/* ---------- Press ripple ---------- */
.tappable, .btn, .chip, .list-item { position: relative; overflow: hidden; isolation: isolate; }
.rippling::after {
  content: ""; position: absolute; left: var(--rx); top: var(--ry); width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%; background: rgb(var(--ink) / 0.18); pointer-events: none; z-index: -1;
  animation: ripple 0.6s var(--ease) forwards;
}
@keyframes ripple { to { transform: scale(60); opacity: 0; } }

/* ---------- Hero sheen ---------- */
.hero .ring::after {
  content: ""; position: absolute; inset: 6%; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0 80%, rgb(var(--ink) / 0.16) 90%, transparent 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 14px), #000 calc(100% - 13px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 14px), #000 calc(100% - 13px));
  animation: sheen 6s linear infinite; opacity: 0.7;
}
@keyframes sheen { to { transform: rotate(360deg); } }
.hero .ring .value { text-shadow: 0 0 24px color-mix(in srgb, var(--accent) 40%, transparent); }

/* ---------- Live heart rate ---------- */
.live-card { overflow: hidden; }
.live-card::before { content: ""; position: absolute; top: -120px; right: -100px; width: 320px; height: 320px; border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 77, 94, 0.22), transparent 72%); pointer-events: none; }
.live-top { display: flex; justify-content: space-between; align-items: center; }
.live-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; color: var(--red); }
.live-badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 0 rgba(255, 77, 94, 0.6); animation: ping-red 1.6s infinite; }
.live-card.stale .live-badge { color: var(--text-3); }
.live-card.stale .live-badge i { background: var(--text-3); animation: none; }
@keyframes ping-red { 70% { box-shadow: 0 0 0 8px rgba(255, 77, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 77, 94, 0); } }
.live-main { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.heart { width: 56px; height: 56px; flex: none; display: grid; place-items: center; border-radius: 18px; background: rgba(255, 77, 94, 0.1); }
.heart svg { width: 30px; height: 30px; fill: var(--red); filter: drop-shadow(0 0 8px rgba(255, 77, 94, 0.6)); animation: beat var(--beat, 1s) ease-in-out infinite; transform-origin: center; }
.live-card.no-data .heart svg, .live-card.stale .heart svg { animation: none; opacity: 0.5; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.22); } 30% { transform: scale(0.96); } 45% { transform: scale(1.12); } 60% { transform: scale(1); } }
.live-read { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 6px; }
.live-bpm { font-size: var(--fs-xl); font-weight: 700; line-height: 1; }
.live-unit { color: var(--text-3); font-weight: 700; }
.live-zone { grid-column: 1 / -1; font-size: var(--fs-sm); font-weight: 700; color: var(--text-3); margin-top: 4px; }
.live-zone.z1 { color: #6fb1e8; } .live-zone.z2 { color: #2ec4b6; } .live-zone.z3 { color: var(--yellow); } .live-zone.z4 { color: #ffa133; } .live-zone.z5 { color: var(--red); }
.live-steps { margin-left: auto; text-align: right; display: grid; }
.live-steps b { font-size: var(--fs-lg); }
.live-steps span { font-size: var(--fs-sm); color: var(--text-3); }
.live-chart { height: 120px; margin-top: 12px; }
.live-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: var(--fs-sm); color: var(--text-3); }
.live-foot .hint { color: var(--yellow); font-weight: 700; }
.batt { position: relative; display: inline-block; width: 26px; height: 12px; border: 1.5px solid var(--text-3); border-radius: 3px; padding: 1px; }
.batt::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 4px; border-radius: 1px; background: var(--text-3); }
.batt i { display: block; height: 100%; border-radius: 1px; background: var(--green); }
.batt.big { width: 40px; height: 18px; }

/* ---------- Metric tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.tile { display: grid; gap: 2px; padding: 12px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); animation: rise 0.5s var(--ease) both; }
.tile .t-emoji { font-size: 16px; }
.tile b { font-size: var(--fs-md); }
.tile b small { font-size: 11px; color: var(--text-3); margin-left: 2px; font-weight: 500; }
.tile span:last-child { font-size: 11px; color: var(--text-3); }
.am-bar { display: flex; gap: 2px; height: 8px; border-radius: 8px; overflow: hidden; margin-bottom: 4px; }
.am-bar span { transform-origin: left; animation: grow-x 0.9s var(--ease) both; }
.device { display: flex; align-items: center; gap: 16px; }
.device .d-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); font-size: 22px; }
.device .d-main { flex: 1; display: grid; }
.device .d-batt { display: flex; align-items: center; gap: 8px; }

/* ---------- Today's summary ---------- */
.summary { padding: 20px; margin-bottom: 16px; }
.summary::before { content: ""; position: absolute; top: -160px; right: -140px; width: 380px; height: 380px; border-radius: 50%; background: radial-gradient(closest-side, var(--accent), transparent 72%); opacity: 0.18; pointer-events: none; }
.sum-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sum-head h1 { font-size: var(--fs-lg); font-weight: 700; margin-top: 4px; }
.sum-head .ai-mini { margin: 0; flex: none; }
.sum-headline { margin-top: 12px; font-size: var(--fs-md); font-weight: 700; color: var(--text); line-height: 1.4; }
.sum-chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.sum-chips div { display: grid; gap: 2px; padding: 12px; border-radius: 16px; background: color-mix(in srgb, var(--c) 10%, transparent); border: 1px solid color-mix(in srgb, var(--c) 28%, transparent); animation: rise 0.5s var(--ease) both; min-width: 0; }
.sum-chips b { font-size: var(--fs-lg); color: var(--c); line-height: 1.1; }
.sum-chips span { font-size: 11px; color: var(--text-3); font-weight: 700; letter-spacing: 0.02em; overflow-wrap: anywhere; }
.sum-guide { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 4px; }
.sum-guide li { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: start; padding: 8px 0; border-top: 1px solid var(--line); }
.sum-guide li:first-child { border-top: 0; }
.sum-guide li span { font-size: 18px; line-height: 1.3; text-align: center; }
.sum-guide li p { color: var(--text-2); font-size: var(--fs-md); }
@media (min-width: 720px) { .sum-chips { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- Compact heart-rate & steps tiles ---------- */
.hr-heart { width: 22px; height: 22px; display: grid; place-items: center; }
.hr-heart svg { width: 18px; height: 18px; fill: var(--red); filter: drop-shadow(0 0 4px rgba(255, 77, 94, 0.6)); animation: beat var(--beat, 1s) ease-in-out infinite; }
.hr-tile.no-data .hr-heart svg, .hr-tile.stale .hr-heart svg { animation: none; opacity: 0.45; }
.hr-tile .delta { display: flex; flex-wrap: wrap; gap: 0 4px; }
.hr-tile .live-zone { font-size: inherit; margin: 0; display: inline; }
.steps-bar { height: 6px; margin-top: 18px; border-radius: 6px; background: rgb(var(--ink) / 0.07); overflow: hidden; }
.steps-bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #2ec4b6, var(--green)); transition: width 1.2s var(--ease); }

/* ---------- Air quality & weather ---------- */
.env-card::before { content: ""; position: absolute; bottom: -140px; left: -120px; width: 340px; height: 340px; border-radius: 50%; background: radial-gradient(closest-side, var(--air), transparent 72%); opacity: 0.2; pointer-events: none; }
.env-main { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: center; }
.env-aqi { position: relative; text-align: center; }
.gauge { width: 100%; max-width: 180px; display: block; margin: 0 auto -18px; overflow: visible; }
.gauge .g-fill { transition: stroke-dashoffset 1.4s var(--ease); filter: drop-shadow(0 0 6px var(--air)); }
.gauge .g-dot { animation: rise 0.8s 0.6s var(--spring) both; }
.env-aqi-num { display: grid; justify-items: center; }
.env-aqi-num b { font-size: 36px; line-height: 1; color: var(--air); }
.env-aqi-num span { font-weight: 700; font-size: var(--fs-sm); color: var(--air); margin-top: 2px; }
.env-aqi .muted { margin-top: 6px; }
.env-wx { display: grid; gap: 2px; }
.env-wx > b { font-size: 36px; line-height: 1; }
.env-wx > span { color: var(--text-2); font-size: var(--fs-sm); }
.env-wx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; margin-top: 8px; font-size: 12px; color: var(--text-3); }
.env-wx-grid b { color: var(--text); }
.env-fc { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; align-items: end; height: 48px; margin-top: 16px; }
.env-fc span { border-radius: 4px; transform-origin: bottom; animation: grow-y 0.6s var(--ease) both; }
.kv.stack { grid-template-columns: 1fr; }
.kv.stack div { display: grid; gap: 2px; }
.kv.stack dd { text-align: left; font-weight: 500; color: var(--text-2); }
.env-advice { margin-top: 12px; padding: 10px 14px; border-radius: 14px; font-size: var(--fs-sm); background: var(--surface-2); color: var(--text-2); border-left: 3px solid var(--text-3); }
.env-advice.ok { border-color: var(--green); }
.env-advice.info { border-color: var(--yellow); }
.env-advice.warn { border-color: #ffa133; color: var(--warn-text); }
.env-advice.high { border-color: var(--red); color: var(--high-text); }
.air-chip { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 6px 12px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); animation: rise 0.6s 0.8s var(--spring) both; }
@media (max-width: 380px) { .env-main { grid-template-columns: 1fr; } }

/* ---------- Whoop-style features ---------- */
.monitor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 4px 0; }
.monitor-head h2 { font-size: var(--fs-md); font-weight: 700; margin-top: 4px; color: var(--green); }
.monitor-head h2.warn { color: var(--yellow); }
.vital .top { gap: 8px; }
.vital .top .label { min-width: 0; }
.monitor-head .ai-mini { margin: 0; flex: none; }
.status-chip { flex: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); }
.status-chip i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-chip.ok { color: var(--green); background: rgba(43, 227, 106, 0.1); }
.status-chip.warn { color: var(--yellow); background: rgba(255, 210, 63, 0.12); }
.status-chip.muted { color: var(--text-3); background: var(--surface-2); }
.range { position: relative; height: 8px; margin-top: 12px; border-radius: 8px; background: rgb(var(--ink) / 0.06); }
.range .band { position: absolute; top: 0; bottom: 0; border-radius: 8px; background: rgba(43, 227, 106, 0.28); }
.range .dot { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--green); border: 2px solid var(--bg); animation: rise 0.6s var(--spring) both; }
.range .dot.high, .range .dot.low { background: var(--yellow); }
.range-legend { display: flex; justify-content: space-between; margin-top: 4px; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.beta { font-size: 10px; letter-spacing: 0.06em; padding: 1px 6px; border-radius: 6px; background: var(--brand-5); color: var(--brand-hi); vertical-align: 1px; margin-left: 4px; }
.stress-bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 64px; margin-top: 8px; }
.stress-bars span { border-radius: 3px; transform-origin: bottom; animation: grow-y 0.6s var(--ease) both; }
.plan-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 8px; }
.plan-options div { padding: 10px 8px; border-radius: 14px; background: var(--surface-2); text-align: center; border: 1px solid var(--line); }
.plan-options b { display: block; font-size: var(--fs-md); }
.plan-options span { display: block; font-size: 11px; color: var(--text-3); margin-top: 2px; }
.plan-options .peak { border-color: rgba(155, 140, 255, 0.5); background: rgba(155, 140, 255, 0.1); }
.plan-options.big { grid-template-columns: 1fr; }
.plan-options.big div { display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 12px 16px; }
.plan-options.big span { margin: 0; text-align: right; max-width: 60%; }
.journal-card { display: flex !important; align-items: center; gap: 16px; padding: 16px 20px; }
.journal-card .j-icon { flex: none; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; background: var(--brand-5); border: 1px solid rgba(232, 93, 51, 0.3); }
.journal-card.done .j-icon { background: rgba(43, 227, 106, 0.12); border-color: rgba(43, 227, 106, 0.35); color: var(--green); font-weight: 700; }
.journal-card .j-main { flex: 1; min-width: 0; display: grid; }
.journal-card .j-streak { font-weight: 700; }
.j-list { display: grid; }
.j-row { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.j-row:first-child { border-top: 0; }
.j-emoji { font-size: 20px; text-align: center; }
.j-q { font-size: var(--fs-md); color: var(--text-2); }
.segmented.small button { min-height: 36px; padding: 0 12px; }
.segmented.small button[data-v="yes"][aria-pressed="true"] { background: rgba(232, 93, 51, 0.2); color: var(--brand-hi); }
.impact { display: grid; grid-template-columns: 32px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.impact:first-of-type { border-top: 0; }
.impact-main { display: grid; gap: 2px; min-width: 0; }
.impact-bar { position: relative; height: 6px; margin-top: 4px; border-radius: 6px; background: rgb(var(--ink) / 0.06); }
.impact-bar::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: rgb(var(--ink) / 0.25); }
.impact-bar i { position: absolute; top: 0; bottom: 0; border-radius: 6px; animation: grow-x 0.8s var(--ease) both; }
.impact-bar i.pos { left: 50%; background: var(--green); }
.impact-bar i.neg { right: 50%; background: var(--red); transform-origin: right; }
.impact-pct { font-weight: 700; font-size: var(--fs-md); }
.impact-pct.pos { color: var(--green); }
.impact-pct.neg { color: var(--red); }
.impact.collecting { opacity: 0.7; grid-template-columns: 32px 1fr; }

/* ---------- AI assistant ---------- */
.top-actions { display: flex; align-items: center; }
.ai-btn svg { stroke: var(--brand-hi); }
.ai-btn { position: relative; }
.ai-btn::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: radial-gradient(closest-side, var(--brand), transparent 75%); opacity: 0.45; z-index: -1; animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.5; transform: scale(1.15); } }
.ai-mini { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 12px; margin: -6px -8px -6px 0; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 700; color: var(--brand-hi); background: var(--brand-5); border: 1px solid rgba(232, 93, 51, 0.25); transition: transform 0.2s var(--spring); }
.ai-mini:active { transform: scale(0.94); }
.ai-mini svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.ai-card { position: relative; margin-top: 24px; padding: 2px; border-radius: 22px; background: linear-gradient(135deg, rgba(232, 93, 51, 0.55), rgba(155, 140, 255, 0.45), rgba(58, 160, 255, 0.35)); }
.ai-card > * { position: relative; }
.ai-card::before { content: ""; position: absolute; inset: 2px; border-radius: 20px; background: var(--ai-bg); }
.ai-trigger { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 16px; text-align: left; border-radius: 20px; transition: transform 0.2s var(--spring); }
.ai-trigger:active { transform: scale(0.98); }
.ai-trigger svg, .ai-orb svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--brand-hi); stroke-width: 2; stroke-linejoin: round; }
.ai-trigger b { display: block; }
.ai-trigger small { display: block; color: var(--text-3); font-size: var(--fs-sm); }
.ai-out { padding: 0 16px; }
.ai-out:not(:empty) { padding: 16px; }
.ai-card:has(.ai-chips):not(:has(.ai-out:not(:empty))) .ai-out { padding: 0; }
.ai-thinking { display: flex; align-items: center; gap: 12px; color: var(--text-2); font-weight: 700; }
.ai-thinking i, .bubble.typing i { display: inline-block; width: 5px; height: 5px; margin-left: 3px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite ease-in-out; }
.ai-thinking i:nth-child(2), .bubble.typing i:nth-child(2) { animation-delay: 0.15s; }
.ai-thinking i:nth-child(3), .bubble.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.ai-orb { width: 40px; height: 40px; flex: none; border-radius: 14px; display: grid; place-items: center; background: var(--brand-5); border: 1px solid rgba(232, 93, 51, 0.3); animation: pulse-orb 2s ease-in-out infinite; }
.ai-orb.big { width: 56px; height: 56px; border-radius: 18px; }
.ai-orb.big svg { width: 28px; height: 28px; }
@keyframes pulse-orb { 50% { box-shadow: 0 0 0 8px rgba(232, 93, 51, 0.08); } }
.ai-headline { font-size: var(--fs-lg); font-weight: 700; line-height: 1.3; color: var(--text) !important; }
.ai-sec { margin-top: 16px; }
.ai-sec .label { margin-bottom: 4px; }
.ai-sec .rec:first-of-type { border-top: 0; padding-top: 4px; }
.ai-note { padding: 12px 16px; border-radius: 14px; background: rgba(255, 210, 63, 0.06); border: 1px solid rgba(255, 210, 63, 0.18); }
.ai-result > .small { margin-top: 16px; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.ai-chip { min-height: 40px; padding: 8px 14px; font-size: var(--fs-sm); text-align: left; line-height: 1.3; }
.ai-form { display: flex; gap: 8px; padding: 0 16px 16px; }
.ai-form .input { flex: 1; min-width: 0; border-radius: var(--r-pill); }
.ai-send { width: 48px; min-height: 48px; padding: 0; flex: none; }
.ai-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ai-thread { display: grid; gap: 8px; padding: 0 16px 12px; }
.exchange { display: grid; gap: 8px; }
/* Ask Pulse: message bar first, then suggestions, then answers (newest first). */
.ai-card.chat { display: flex; flex-direction: column; }
.ai-card.chat .ai-form { order: 1; padding-top: 16px; }
.ai-card.chat .ai-chips { order: 2; padding-top: 0 !important; }
.ai-card.chat .ai-out { order: 3; }
.ai-card.chat .ai-out .ai-thread { padding: 0 16px 16px; }
.ai-card.chat .exchange + .exchange { padding-top: 12px; border-top: 1px solid var(--line); }
.ai-out .ai-thread { padding: 16px 0 0; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 18px; animation: rise 0.35s var(--ease) both; }
.bubble p + p, .bubble ul { margin-top: 6px; }
.bubble ul { padding-left: 18px; margin-bottom: 0; }
.bubble.me { justify-self: end; background: linear-gradient(180deg, var(--brand-hi), var(--brand)); color: #fff; border-bottom-right-radius: 6px; }
.bubble.ai { justify-self: start; background: var(--surface-2); color: var(--text-2); border-bottom-left-radius: 6px; }
.bubble.typing { color: var(--text-3); }
.ai-intro { display: flex; gap: 16px; align-items: center; }
.ai-intro p { color: var(--text-2); }
.ai-intro + .ai-card { margin-top: 16px; }
.ai-intro + .ai-card .ai-chips { padding-top: 16px; }

@media (max-width: 420px) {
  .brand .word { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; animation-delay: 0ms !important; }
  .chart .line { stroke-dashoffset: 0; }
}

@media (max-width: 360px) {
  .topbar { padding-left: 12px; padding-right: 8px; gap: 0; }
  .brand .word { display: none; }
  .date-chip { padding: 0 8px; }
}

/* ---------- Body ---------- */
.body-card { width: 100%; text-align: left; margin-top: 16px; }
.body-main { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.body-main > div { min-width: 0; }
.body-main .value { font-size: 44px; font-weight: 700; line-height: 1.05; }
.body-main .value small { font-size: 15px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.body-main .delta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.body-stats { gap: 24px; margin: 0; }
.body-card .chart.spark { margin-top: 12px; }

/* Light theme: bright data colours (AQI yellow, etc.) are darkened when used as text so they stay readable on white. */
@media (prefers-color-scheme: light) {
  .sum-chips b, .sum-chips span { color: color-mix(in srgb, var(--c) 72%, #000) !important; }
  .env-aqi-num b, .env-aqi-num span { color: color-mix(in srgb, var(--air) 72%, #000); }
  .hero .ring .value { text-shadow: none; }
  .sheet-backdrop { background: rgba(15, 23, 42, 0.35); }
}
