/* Breathe. Two themes share one stylesheet through the tokens below:
   Aurora: dark glass over soft colour, thin numerals, a glowing chart.
   Paper:  light grey, heavy numerals, hairlines, almost no colour. */

:root {
  color-scheme: dark;
  --bg: #060914;
  --backdrop:
    radial-gradient(75% 40% at 4% 0%, rgba(16, 179, 160, 0.42), transparent 70%),
    radial-gradient(65% 36% at 100% 12%, rgba(56, 108, 255, 0.4), transparent 70%),
    radial-gradient(85% 42% at 50% 106%, rgba(139, 124, 246, 0.34), transparent 70%),
    #060914;
  --top-bg: rgba(6, 9, 20, 0.7);
  --ink: #f3f6ff;
  --ink-2: rgba(243, 246, 255, 0.64);
  --ink-3: rgba(243, 246, 255, 0.42);
  --line: rgba(255, 255, 255, 0.1);
  --line-soft: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.22);

  --card: linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.035));
  --card-hover: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  --card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 20px 40px -24px rgba(0, 0, 0, 0.7);
  --fill: rgba(255, 255, 255, 0.06);
  --fill-on: rgba(255, 255, 255, 0.14);
  --raise: rgba(255, 255, 255, 0.11);
  --field: rgba(255, 255, 255, 0.06);
  --sheet: #10162c;
  --scrim: rgba(3, 5, 12, 0.6);

  /* Chart series, validated against each theme's card surface. */
  --before: #8b7cf6;
  --after: #10b3a0;
  --after-glow: #35d6bf;
  --chart-surface: #0b1022;
  --grid: rgba(255, 255, 255, 0.07);
  --tick: rgba(243, 246, 255, 0.46);
  --glow: 0.55;
  --area: 0.32;

  --accent: #35d6bf;
  --accent-ink: #8ff0de;
  --accent-wash: rgba(16, 179, 160, 0.14);
  --accent-line: rgba(53, 214, 191, 0.4);
  --primary: linear-gradient(90deg, #35d6bf, #4d8dff);
  --on-primary: #04121a;
  --primary-shadow: 0 12px 34px -8px rgba(53, 214, 191, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  --fab: conic-gradient(from 210deg, #35d6bf, #4d8dff, #8b7cf6, #35d6bf);
  --fab-shadow: 0 12px 34px rgba(53, 214, 191, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  --good: #8ff0de;
  --danger: #ff9a9a;
  --toast-bg: #f3f6ff;
  --toast-ink: #0a0f22;
  --toast-link: #1f52c7;

  --num-weight: 200;
  --num-track: -0.045em;
  --num-glow: drop-shadow(0 0 22px rgba(53, 214, 191, 0.4));
  --shimmer-base: #f3f6ff;
  --shimmer-hi: #6fe8d6;
  --rings-base: radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.2), rgba(16, 22, 48, 0.92) 62%);
  --rings-track: rgba(255, 255, 255, 0.1);
  --rings-shadow: rgba(0, 0, 0, 0.6);
  --radius: 26px;
  --font: -apple-system, "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="paper"] {
  color-scheme: light;
  --bg: #ececea;
  --backdrop: #ececea;
  --top-bg: rgba(236, 236, 234, 0.82);
  --ink: #1b1b1d;
  --ink-2: #6c6c70;
  --ink-3: #a3a3a6;
  --line: rgba(0, 0, 0, 0.1);
  --line-soft: rgba(0, 0, 0, 0.07);
  --line-strong: rgba(0, 0, 0, 0.26);

  --card: #f6f6f4;
  --card-hover: #fbfbfa;
  --card-shadow: none;
  --fill: rgba(0, 0, 0, 0.05);
  --fill-on: #ffffff;
  --raise: rgba(0, 0, 0, 0.08);
  --field: #ffffff;
  --sheet: #f6f6f4;
  --scrim: rgba(27, 27, 29, 0.32);

  --before: #257de0;
  --after: #f47230;
  --after-glow: #f47230;
  --chart-surface: #f6f6f4;
  --grid: #e2e2df;
  --tick: #6c6c70;
  --glow: 0;
  --area: 0.1;

  --accent: #1b1b1d;
  --accent-ink: #1b1b1d;
  --accent-wash: rgba(0, 0, 0, 0.05);
  --accent-line: rgba(0, 0, 0, 0.16);
  --primary: #1b1b1d;
  --on-primary: #ffffff;
  --primary-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.5);
  --fab: #1b1b1d;
  --fab-shadow: 0 14px 30px -10px rgba(0, 0, 0, 0.55);
  --good: #0a6e2a;
  --danger: #c22f30;
  --toast-bg: #1b1b1d;
  --toast-ink: #ffffff;
  --toast-link: #9cc4ff;

  --num-weight: 700;
  --num-track: -0.03em;
  --num-glow: none;
  --shimmer-base: #1b1b1d;
  --shimmer-hi: #a9a9ad;
  --rings-base: radial-gradient(circle at 34% 28%, #ffffff, #e4e4e1 70%);
  --rings-track: rgba(0, 0, 0, 0.08);
  --rings-shadow: rgba(0, 0, 0, 0.22);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font: 16px/1.45 var(--font);
  font-variant-numeric: slashed-zero;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* Fixed behind everything so content scrolls over it. */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--backdrop); }

h1, h2, h3, p { margin: 0; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.read-only [data-write] { display: none !important; }

.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.cap { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-2); }
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* A band of light that sweeps across the big numbers. */
.shimmer {
  background: linear-gradient(105deg, var(--shimmer-base) 38%, var(--shimmer-hi) 50%, var(--shimmer-base) 62%) 0 0 / 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: shimmer 3.6s linear infinite;
}
@keyframes shimmer { from { background-position: 130% 0; } to { background-position: -130% 0; } }

.glass { background: var(--card); border: 1px solid var(--line); box-shadow: var(--card-shadow); border-radius: var(--radius); }
.card { padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head .sub { font-size: 13px; color: var(--ink-2); }
.empty { padding: 22px 8px; text-align: center; color: var(--ink-2); font-size: 14px; }

.swatch { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.swatch.before { background: var(--before); }
.swatch.after { background: var(--after); }

/* ---------- Top bar ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(54px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
}
/* The blur sits on a pseudo-element so it cannot trap fixed children. */
.top::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--top-bg);
  backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
}

.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.brand-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--primary); }
.brand-mark svg { width: 18px; height: 18px; fill: none; stroke: var(--on-primary); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.nav { display: none; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.top-only { display: none !important; }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.sync::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); }
.sync[data-state="synced"]::before { background: var(--accent); }
.sync[data-state="denied"]::before { background: var(--danger); }
.sync:empty { display: none; }

.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--raise); color: var(--ink); }
.menu-btn { color: var(--ink); }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 6px max(14px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.view { display: grid; gap: 12px; }

/* ---------- Corner plus button and menu drawer ---------- */

.fab {
  position: fixed;
  right: max(20px, calc(env(safe-area-inset-right) + 14px));
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  color: var(--on-primary);
  background: var(--fab);
  box-shadow: var(--fab-shadow);
  transition: transform 0.12s ease;
}
.fab:active { transform: scale(0.93); }
.fab .ico { width: 28px; height: 28px; stroke-width: 2.2; }
body[data-view="log"] .fab { display: none; }

.drawer {
  margin: 0;
  width: min(304px, 86vw);
  height: 100dvh;
  max-height: none;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 30px 0 60px -20px rgba(0, 0, 0, 0.5);
}
.drawer[open] { animation: drawer-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
.drawer::backdrop { background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
@keyframes drawer-in { from { transform: translateX(-100%); } }
.drawer-in { display: flex; flex-direction: column; height: 100%; padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 18px); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-left: 10px; }
.drawer-nav { display: grid; gap: 4px; margin-top: 20px; }
.drawer-nav a, .drawer-nav button { display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 14px; border: 0; border-radius: 16px; background: none; color: var(--ink-2); font-size: 16px; font-weight: 500; text-align: left; }
.drawer-nav a:hover, .drawer-nav button:hover { background: var(--fill); color: var(--ink); }
.drawer-nav [aria-current="page"] { background: var(--fill-on); color: var(--ink); }
.drawer-foot { margin-top: auto; display: grid; gap: 10px; padding: 0 4px; }

/* ---------- Buttons, chips, segmented control ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
}
.btn:hover { background: var(--raise); }
.btn .ico { width: 18px; height: 18px; stroke-width: 2.2; }
.btn.primary { border-color: transparent; color: var(--on-primary); background: var(--primary); box-shadow: var(--primary-shadow); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: 0.4; cursor: default; filter: none; box-shadow: none; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent-ink); padding: 0 8px; min-height: 36px; }

.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--fill); color: var(--ink-2); font-size: 12.5px; white-space: nowrap; }
button.chip:hover { background: var(--raise); color: var(--ink); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; border-radius: 999px; border: 1px solid var(--line); background: var(--fill); }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-3); font-weight: 600; font-size: 14px; }
.seg button[aria-checked="true"] { color: var(--ink); background: var(--fill-on); box-shadow: 0 0 0 1px var(--line); }
.seg button[data-kind="before"][aria-checked="true"] { box-shadow: inset 0 0 0 1.5px var(--before); }
.seg button[data-kind="after"][aria-checked="true"] { box-shadow: inset 0 0 0 1.5px var(--after-glow); }

.chips { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--fill); border: 1px solid var(--line-soft); }
.chips button { min-height: 26px; padding: 0 10px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-3); font-size: 11.5px; font-weight: 600; }
.chips button[aria-pressed="true"] { background: var(--fill-on); color: var(--ink); }

.delta { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; color: var(--ink-2); background: var(--fill); border: 1px solid var(--line); white-space: nowrap; }
.delta.up { color: var(--good); background: var(--accent-wash); border-color: var(--accent-line); }

/* ---------- Home ---------- */

.home-date { padding: 0 6px; font-size: 13px; color: var(--ink-2); }
.home-grid { display: grid; gap: 12px; margin-top: 30px; }
.home-side { display: grid; gap: 12px; align-content: start; }

.hero { position: relative; padding: 18px 16px 12px; }
.hero-top { padding-right: 128px; min-height: 104px; }
.hero-num { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; font-size: 78px; line-height: 1; font-weight: var(--num-weight); letter-spacing: var(--num-track); filter: var(--num-glow); }
.hero-num .unit { font-size: 14px; font-weight: 400; letter-spacing: 0; color: var(--ink-2); }
.hero-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 6px; font-size: 12.5px; color: var(--ink-2); }
.hero .chart-host { margin: 10px -6px 0; }
.legend { display: flex; gap: 6px 14px; align-items: center; margin-top: 6px; font-size: 12.5px; color: var(--ink-2); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend b { color: var(--ink); font-weight: 600; }
.legend .chips { margin-left: auto; }
.hero-empty { padding: 26px 16px 22px; text-align: center; }
.hero-empty .hero-num { justify-content: center; }
.hero-empty p { color: var(--ink-2); margin: 6px 0 18px; }

/* The hero figure: ring layers stacked in depth, tilted, floating above the card's corner. */
.hero-rings { position: absolute; top: -54px; right: -4px; z-index: 2; width: 140px; height: 140px; pointer-events: none; filter: drop-shadow(0 22px 20px var(--rings-shadow)); animation: floaty 6s ease-in-out infinite; }
@keyframes floaty { 50% { transform: translateY(-8px); } }
.hr-tilt { position: absolute; inset: 0; transform-style: preserve-3d; transform: perspective(520px) rotateX(calc(20deg + var(--tilt-y, 0deg))) rotateY(calc(-24deg + var(--tilt-x, 0deg))); transition: transform 0.25s ease-out; }
.hr-layer { position: absolute; inset: 0; }
.hr-layer svg { display: block; width: 100%; height: 100%; overflow: visible; }
.hr-base { border-radius: 50%; background: var(--rings-base); border: 1px solid var(--line); transform: translateZ(-26px) scale(0.97); }
.hr-echo { transform: translateZ(-6px); opacity: 0.4; filter: blur(2.5px); }
.hr-front { transform: translateZ(24px); }
.hr-center { display: grid; place-content: center; justify-items: center; transform: translateZ(50px); }
.hr-center b { font-size: 23px; line-height: 1.05; font-weight: 700; letter-spacing: -0.02em; }
.hr-center small { font-size: 9.500px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-2); }
.hr-track { fill: none; stroke: var(--rings-track); stroke-width: 9; }
.hr-arc { fill: none; stroke-width: 9; stroke-linecap: round; }
.hr-arc.after { stroke: var(--after-glow); }
.hr-arc.before { stroke: var(--before); }

.tiles2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { display: block; width: 100%; padding: 13px 14px; border-radius: 22px; text-align: left; color: var(--ink); }
button.tile, a.tile { cursor: pointer; }
button.tile:hover, a.tile:hover { background: var(--card-hover); }
.tile-h { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.tile-h .ico { width: 16px; height: 16px; }
.tile-v { margin-top: 6px; font-size: 22px; font-weight: calc(var(--num-weight) + 100); letter-spacing: -0.02em; white-space: nowrap; }
.tile-v em { font-style: normal; color: var(--ink-3); margin: 0 2px; font-weight: 300; }
.tile-v small { margin-left: 5px; font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--ink-2); }
.tile-v.off { color: var(--ink-3); font-weight: 400; }
.tile-s { margin-top: 1px; font-size: 12px; color: var(--ink-2); }
.tile-s.good { color: var(--good); }
.aq-dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; vertical-align: 0.12em; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); padding: 12px 6px; border-radius: 22px; }
.stats div { text-align: center; border-left: 1px solid var(--line-soft); padding: 0 4px; }
.stats div:first-child { border-left: 0; }
.stats b { display: block; font-size: 21px; font-weight: calc(var(--num-weight) + 100); letter-spacing: -0.02em; }
.stats small { font-size: 11px; color: var(--ink-2); }

/* 30-day heat map: one column per day; rows for the before reading, the after reading, and air quality. */
.heat { padding: 14px 14px 12px; border-radius: 22px; }
.heat-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.heat-head b { font-size: 13px; font-weight: 600; }
.heat-grid { display: grid; grid-template-columns: 40px repeat(var(--cols), minmax(0, 1fr)); gap: 3px 2.5px; align-items: center; }
.heat-grid span { font-size: 10.5px; color: var(--ink-2); }
.heat-grid i { height: 13px; border-radius: 3.5px; background: var(--fill); }
.heat-grid i.on.before { background: var(--before); }
.heat-grid i.on.after { background: var(--after-glow); }
.heat-grid i.today { box-shadow: 0 0 0 1.5px var(--ink); }
.heat-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 10px; margin-top: 9px; padding-left: 42.5px; font-size: 10.5px; color: var(--ink-2); }
.heat-key { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.heat-key span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.heat-key i { width: 9px; height: 9px; border-radius: 2.5px; }

.home-side [data-timer-slot]:empty { display: none; }
.timer { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; border-radius: 20px; border: 1px solid var(--accent-line); background: var(--accent-wash); font-size: 14px; }
.timer b { font-size: 22px; font-weight: calc(var(--num-weight) + 100); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.timer .grow { flex: 1; min-width: 0; }
.timer.due { background: var(--primary); border-color: transparent; color: var(--on-primary); font-weight: 600; }
.timer.due .btn.ghost { color: var(--on-primary); }

/* ---------- Log ---------- */

.log-grid { display: grid; gap: 14px; align-items: start; }
.entry { display: grid; gap: 12px; padding: 0 4px; }
.log-head { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; text-align: center; margin: 0 -6px; }
.log-head h1 { font-size: 16px; font-weight: 600; }

/* The arc wheel. Values ride the curve; the one at the top is the reading. */
.wheel-wrap { display: grid; align-items: center; min-height: 0; margin: 0 -18px; }
.wheel { position: relative; height: 236px; overflow: hidden; --kind: var(--before); -webkit-mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent); }
.wheel[data-kind="after"] { --kind: var(--after-glow); }
.wheel-stage { position: absolute; inset: 0; }
.wheel-arc { position: absolute; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.wheel-items > * { position: absolute; left: 0; top: 0; will-change: transform, opacity; }
.wheel-item { font-size: 80px; line-height: 1; font-weight: var(--num-weight); letter-spacing: var(--num-track); font-variant-numeric: tabular-nums slashed-zero; white-space: nowrap; color: var(--ink); }
.wheel-item.is-on {
  background: linear-gradient(105deg, var(--shimmer-base) 38%, var(--shimmer-hi) 50%, var(--shimmer-base) 62%) 0 0 / 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 3.6s linear infinite;
}
.wheel-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); }
.wheel-dot.major { width: 7px; height: 7px; background: var(--ink-2); }
.wheel-mark { width: 9px; height: 9px; border-radius: 50%; }
.wheel-mark.usual { border: 1.5px solid var(--ink-2); }
.wheel-mark.ref { background: var(--before); }
.wheel-pin { position: absolute; left: 50%; top: 112px; width: 13px; height: 13px; border-radius: 50%; background: var(--kind); transform: translate(-50%, -50%); box-shadow: 0 0 0 4px var(--bg), 0 0 calc(18px * var(--glow) * 2) var(--kind); }
.wheel-meta { position: absolute; left: 0; right: 0; top: 136px; display: grid; justify-items: center; gap: 8px; }
.wheel-unit { font-size: 11.500px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-2); }
.wheel-note { min-height: 28px; font-size: 12.500px; color: var(--ink-2); }
.wheel-scroll { position: absolute; inset: 0; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; cursor: grab; outline-offset: -4px; }
.wheel-scroll::-webkit-scrollbar { display: none; }
.wheel.is-dragging .wheel-scroll { scroll-snap-type: none; cursor: grabbing; }
.wheel-track { display: flex; width: max-content; height: 100%; padding-inline: calc(50% - 20px); }
.wheel-track i { flex: none; width: 40px; height: 100%; scroll-snap-align: center; }

.hint { min-height: 18px; text-align: center; font-size: 13.5px; line-height: 18px; color: var(--danger); }
.when { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; min-height: 36px; }
.when input { min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--field); font-size: 14px; }

.entry-actions { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.round-btn { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%; border: 1px solid var(--accent-line); background: var(--accent-wash); color: var(--accent-ink); }
.round-btn:active { transform: scale(0.94); }

/* Slide to save: the pill carries the value and is dragged to the far end. */
.slide { position: relative; height: 60px; border-radius: 999px; border: 1px solid var(--line); background: var(--fill); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; --slide: 0; }
.slide-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; padding-left: 116px; color: var(--ink-2); font-size: 15px; font-weight: 600; opacity: calc(1 - var(--slide) * 1.6); }
.slide-arrows { letter-spacing: 3px; color: var(--ink-3); animation: arrows 1.6s ease-in-out infinite; }
@keyframes arrows { 50% { transform: translateX(5px); opacity: 0.5; } }
.slide-knob { position: absolute; left: 4px; top: 4px; bottom: 4px; display: flex; align-items: baseline; justify-content: center; gap: 5px; min-width: 116px; padding: 13px 18px 0; border-radius: 999px; color: var(--on-primary); background: var(--primary); box-shadow: var(--primary-shadow); }
.slide-knob b { font-size: 23px; line-height: 1; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums slashed-zero; }
.slide-knob small { font-size: 11px; opacity: 0.75; }
.slide.is-dragging { cursor: grabbing; }
.slide.is-hinting .slide-knob { animation: slide-hint 0.6s ease; }
@keyframes slide-hint { 35% { transform: translateX(30px); } }
.log-today { display: none; }

/* Keypad sheet: plain digits with a small star where the gridlines would cross. */
.pad-display { display: grid; justify-items: center; gap: 2px; outline: none; }
.pad-display b { font-size: 68px; line-height: 1.05; font-weight: var(--num-weight); letter-spacing: var(--num-track); font-variant-numeric: tabular-nums slashed-zero; }
.pad-display b.is-empty { color: var(--ink-3); }
.pad-display small { font-size: 11.500px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-2); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 6px; padding: 6px; border-radius: 26px; background: var(--fill); }
.pad button { position: relative; display: grid; place-items: center; height: 60px; border: 0; border-radius: 18px; background: none; font-size: 26px; font-weight: 400; user-select: none; -webkit-user-select: none; }
.pad button:active { background: var(--raise); }
.pad-del { color: var(--ink-2); }
.pad > :nth-child(3n+1):not(:nth-last-child(-n+3))::after,
.pad > :nth-child(3n+2):not(:nth-last-child(-n+3))::after { content: "✦"; position: absolute; right: -5px; bottom: -8px; z-index: 1; font-size: 10px; line-height: 1; color: var(--ink-3); pointer-events: none; }
.err { font-size: 13px; color: var(--danger); min-height: 18px; }

/* ---------- Reading rows ---------- */

.rows { display: grid; }
.row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 6px 2px; border: 0; border-top: 1px solid var(--line-soft); background: transparent; text-align: left; }
.rows .row:first-child { border-top: 0; }
button.row:hover { background: var(--fill); }
.row-main { display: grid; min-width: 0; }
.row-kind { font-size: 15px; font-weight: 500; }
.row-time { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.row-val { font-size: 22px; font-weight: calc(var(--num-weight) + 100); font-variant-numeric: tabular-nums slashed-zero; letter-spacing: -0.02em; }
.row-val small { margin-left: 4px; font-size: 11.5px; font-weight: 400; color: var(--ink-2); letter-spacing: 0; }
.row .ico { width: 16px; height: 16px; color: var(--ink-3); stroke-width: 2; }

.day-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.day-head .sub { font-size: 12.5px; color: var(--ink-2); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar h1 { display: flex; align-items: center; gap: 2px; margin-left: -8px; font-size: 26px; font-weight: calc(var(--num-weight) + 100); letter-spacing: -0.02em; }
.toolbar .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar .btn { min-height: 38px; padding: 0 14px; font-size: 14px; }

/* ---------- Chart ---------- */

.chart-host { position: relative; }
.chart { display: block; height: auto; overflow: visible; touch-action: pan-y; }
.c-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.c-tick { fill: var(--tick); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.c-line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.c-line.before { stroke: var(--before); stroke-width: 2; }
.c-line.after { stroke: var(--after); }
.c-glow { fill: none; stroke: var(--after-glow); stroke-width: 5; opacity: var(--glow); }
.c-stop-top { stop-color: var(--after); stop-opacity: var(--area); }
.c-stop-bottom { stop-color: var(--after); stop-opacity: 0; }
.c-dot { stroke: var(--chart-surface); stroke-width: 2; }
.c-dot.before, .c-end.before { fill: var(--before); }
.c-dot.after { fill: var(--after); }
.c-end { stroke: var(--chart-surface); stroke-width: 2; }
.c-end.after { fill: var(--after-glow); }
.c-halo { fill: var(--after); opacity: 0.25; }
.c-link { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 3; }
.c-cross { stroke: var(--line-strong); stroke-width: 1; }
.c-hit { cursor: crosshair; }
.c-tip { position: absolute; z-index: 2; min-width: 150px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 14px; background: var(--sheet); box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.45); font-size: 13px; pointer-events: none; }
.tip-head { margin-bottom: 5px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.tip-row { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.tip-row b { margin-left: auto; padding-left: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tip-delta { margin-top: 4px; padding-top: 5px; border-top: 1px solid var(--line-soft); color: var(--ink-2); }
.tip-delta b { color: var(--ink); }

/* ---------- Report ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; text-align: right; border-top: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
th { font-size: 11.5px; font-weight: 500; color: var(--ink-2); border-top: 0; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
td.strong { font-weight: 500; font-size: 15px; }
td.none { color: var(--ink-3); }
.report-head h1 { font-size: 24px; font-weight: calc(var(--num-weight) + 100); letter-spacing: -0.02em; }
.report-head p { margin-top: 2px; font-size: 13.5px; color: var(--ink-2); }
.report-stats { display: grid; grid-template-columns: repeat(2, 1fr); margin: 14px 0; border: 1px solid var(--line-soft); border-radius: 18px; }
.report-stats div { padding: 12px 14px; border-top: 1px solid var(--line-soft); border-left: 1px solid var(--line-soft); }
.report-stats div:nth-child(-n+2) { border-top: 0; }
.report-stats div:nth-child(odd) { border-left: 0; }
.report-stats small { display: block; font-size: 11.5px; color: var(--ink-2); }
.report-stats b { font-size: 24px; font-weight: calc(var(--num-weight) + 100); letter-spacing: -0.02em; }
.report-stats b i { font-style: normal; font-size: 13px; font-weight: 400; color: var(--ink-2); margin-left: 4px; }
.table-scroll { overflow-x: auto; }

/* ---------- Sheets and toast ---------- */

.sheet { width: min(440px, 100vw); max-width: 100vw; margin: auto auto 0; padding: 0; border: 1px solid var(--line); border-radius: 28px 28px 0 0; background: var(--sheet); color: var(--ink); box-shadow: 0 -20px 60px -10px rgba(0, 0, 0, 0.55); }
.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sheet-in { padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.015em; }
.sheet p { margin-top: 4px; font-size: 14.5px; color: var(--ink-2); }
.sheet-body { display: grid; gap: 14px; margin-top: 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; min-height: 48px; }
.sheet-actions .btn.fit { flex: none; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-2); }
.field input, .field select { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--field); font-size: 16px; }
.field select option { background: var(--sheet); }
.field input.big { font-size: 30px; font-weight: calc(var(--num-weight) + 100); letter-spacing: -0.02em; min-height: 58px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-size: 14px; }

.voice-row { display: flex; gap: 8px; }
.voice-row input { flex: 1; min-width: 0; }
.voice-mic { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--accent-line); background: var(--accent-wash); color: var(--accent-ink); display: grid; place-items: center; }
.voice-mic.live { background: var(--primary); color: var(--on-primary); border-color: transparent; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px var(--accent-wash); } }
.parsed .row { grid-template-columns: auto 1fr auto; min-height: 46px; }

.toast {
  position: fixed;
  left: 50%;
  /* At the top so it never covers the controls at the bottom. */
  top: calc(env(safe-area-inset-top) + 60px);
  z-index: 30;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 28px);
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 14.5px;
  font-weight: 600;
  box-shadow: 0 14px 40px -10px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}
.toast button { border: 0; background: transparent; color: var(--toast-link); font-weight: 700; padding: 4px 2px; }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .fab { display: none; }
  .top { height: 68px; gap: 22px; padding-left: max(28px, calc((100vw - 1080px) / 2 + 14px)); padding-right: max(28px, calc((100vw - 1080px) / 2 + 14px)); }
  .nav { display: flex; gap: 4px; }
  .nav a { padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
  .nav a:hover { color: var(--ink); background: var(--fill); }
  .nav a[aria-current="page"] { color: var(--ink); background: var(--fill-on); }
  .top-only { display: inline-flex !important; }
  .top-actions .btn { min-height: 40px; }
  main { padding-top: 14px; padding-bottom: 56px; }
  .view { gap: 16px; }
  .home-grid { grid-template-columns: minmax(0, 1.65fr) minmax(320px, 1fr); gap: 16px; align-items: start; margin-top: 44px; }
  .home-side { gap: 16px; }
  .hero { padding: 26px 24px 18px; }
  .hero-top { padding-right: 200px; min-height: 128px; }
  .hero-num { font-size: 100px; }
  .hero-rings { width: 196px; height: 196px; top: -66px; right: 10px; }
  .hr-center b { font-size: 31px; }
  .tiles2 { gap: 16px; }
  .log-grid { grid-template-columns: 440px 1fr; gap: 20px; }
  .entry { padding: 22px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); box-shadow: var(--card-shadow); }
  .log-head .icon-btn { visibility: hidden; }
  .log-today { display: block; }
  .card { padding: 20px; }
  .sheet { margin: auto; border-radius: 28px; }
  .sheet-in { padding: 24px; }
  .toast { top: 84px; }
  .report-stats { grid-template-columns: repeat(4, 1fr); }
  .report-stats div { border-top: 0; border-left: 1px solid var(--line-soft); }
  .report-stats div:nth-child(odd) { border-left: 1px solid var(--line-soft); }
  .report-stats div:first-child { border-left: 0; }
}

@media (max-width: 899px) {
  body[data-view="log"] .top { display: none; }
  body[data-view="log"] main { padding-top: calc(env(safe-area-inset-top) + 8px); padding-bottom: calc(env(safe-area-inset-bottom) + 18px); min-height: 100dvh; display: grid; }
  body[data-view="log"] .log-grid, body[data-view="log"] .entry { height: 100%; }
  /* head, timer, type switch, wheel (takes the spare room), hint, chips, actions */
  body[data-view="log"] .entry { grid-template-rows: auto auto auto 1fr auto auto auto; }
}

@media (prefers-reduced-motion: reduce) {
  .shimmer, .wheel-item.is-on, .hero-rings, .slide-arrows { animation: none; }
  .shimmer, .wheel-item.is-on { background-position: 50% 0; }
}

/* ---------- Print (the doctor's copy is plain black on white, whatever the theme) ---------- */

@media print {
  :root, :root[data-theme="paper"] {
    color-scheme: light;
    --ink: #111; --ink-2: #555; --ink-3: #888; --line: #ccc; --line-soft: #ddd; --line-strong: #999;
    --before: #257de0; --after: #f47230; --after-glow: #f47230; --chart-surface: #fff; --grid: #e7e7e7; --tick: #666;
    --glow: 0; --area: 0; --num-weight: 400;
  }
  @page { margin: 14mm; }
  html, body { background: #fff; }
  body { font-size: 11pt; }
  body::before, .top, .fab, .drawer, .toast, .sheet, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  .view:not(#v-report) { display: none !important; }
  .glass { background: none; border: 0; box-shadow: none; padding: 0; border-radius: 0; }
  .c-glow, .c-area, .c-halo, .c-tip, .c-link { display: none; }
  .chart-host { break-inside: avoid; }
  tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
