/* Habits — R&Co. design language: quiet authority.
   Serif headlines over a clean sans body, hairlines, soft shadows, slow confident motion.
   Sections: fonts → tokens → base → layout → primitives → per-view → overlays → motion. */

/* ===== Fonts (self-hosted, latin subset, variable weight) ===== */
@font-face {
  font-family: 'Playfair Display'; font-style: normal; font-weight: 400 900; font-display: swap;
  src: url('/fonts/playfair-display-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Source Sans 3'; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url('/fonts/source-sans-3-latin.woff2') format('woff2');
}

/* ===== Theme tokens (colours overridden at runtime by themes.js) ===== */
:root {
  --bg: #fcfcfc; --bg2: #f7f7f8; --surface: #ffffff; --surface2: #f4f4f6;
  --text: #1a1d23; --muted: #676f7e; --border: #e3e5e8;
  --primary: #363d49; --primarySoft: #363d491a; --onPrimary: #ffffff;
  --accent: #89909f; --success: #40775e; --warn: #a3743e; --danger: #dc2828;

  --radius: 14px; --radius-sm: 10px; --radius-xs: 8px; --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);
  --shadow: var(--shadow-sm);

  --font-serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --tracking-tight: -0.025em; --tracking-wide: 0.05em;

  --ease: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --fast: 200ms; --base: 300ms; --slow: 500ms;

  --tab-h: 64px; --top-h: 60px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --tint: color-mix(in srgb, var(--primary) 10%, transparent);
  --tint-strong: color-mix(in srgb, var(--primary) 20%, transparent);
}
:root[data-mode="dark"] {
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .35), 0 2px 4px -2px rgb(0 0 0 / .3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .4), 0 4px 6px -4px rgb(0 0 0 / .35);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / .45), 0 8px 10px -6px rgb(0 0 0 / .4);
  --tint: color-mix(in srgb, var(--primary) 14%, transparent);
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  min-height: 100dvh; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color var(--base) var(--ease), color var(--base) var(--ease);
}
::selection { background: var(--tint-strong); }
a { color: inherit; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--text); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-family: var(--font-serif); font-weight: 600; letter-spacing: var(--tracking-tight); }
p { margin: 0; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-xs); }
.ic { flex: none; display: inline-block; vertical-align: -0.15em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.serif { font-family: var(--font-serif); letter-spacing: var(--tracking-tight); }
.num { font-variant-numeric: lining-nums tabular-nums; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; } .mt-s { margin-top: 8px; }
.stack > * + * { margin-top: 12px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--primary); }

/* ===== Layout ===== */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: calc(var(--top-h) + var(--sat)); padding: var(--sat) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: transparent; border-bottom: 1px solid transparent;
  transition: background-color var(--base) var(--ease), border-color var(--base) var(--ease), box-shadow var(--base) var(--ease);
}
.topbar.scrolled {
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom-color: var(--border); box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-serif); font-weight: 600; font-size: 22px; letter-spacing: var(--tracking-tight); }
.brand-dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: var(--primary); }
#topbar-title { display: inline-block; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.sync-dot { width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--border); transition: background-color var(--base) var(--ease); }
.sync-dot.ok { background: var(--success); } .sync-dot.syncing { background: var(--muted); animation: pulse 1.5s ease-in-out infinite; }
.sync-dot.error { background: var(--danger); } .sync-dot.offline { background: var(--muted); }
@keyframes pulse { 50% { opacity: .3; } }
.icon-btn {
  background: transparent; border: 0; width: 42px; height: 42px; border-radius: var(--radius-sm); cursor: pointer;
  display: grid; place-items: center; color: var(--muted);
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.view { flex: 1; padding: 8px 16px calc(var(--tab-h) + var(--sab) + 32px); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; margin: 0 auto; max-width: 640px;
  height: calc(var(--tab-h) + var(--sab)); padding-bottom: var(--sab);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500; letter-spacing: .01em;
  transition: color var(--fast) var(--ease);
}
.tabbar a svg { width: 20px; height: 20px; transition: transform var(--base) var(--ease); }
.tabbar a:hover { color: var(--text); }
.tabbar a:active svg { transform: scale(.9); }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tab-ind {
  position: absolute; top: -1px; left: 0; width: 20%; height: 2px; pointer-events: none;
  transform: translateX(calc(var(--tab-i, 0) * 100%)); transition: transform var(--slow) var(--ease), opacity var(--fast);
}
.tab-ind::after { content: ''; position: absolute; left: 50%; width: 28px; margin-left: -14px; height: 2px; border-radius: 2px; background: var(--primary); }
.tabbar[data-none] .tab-ind { opacity: 0; }

/* ===== Cards & primitives ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); transition: box-shadow var(--base) var(--ease), border-color var(--base) var(--ease), background-color var(--base) var(--ease);
}
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title h2 { font-size: 20px; }
.card-title .meta { font-size: 13px; color: var(--muted); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; text-align: right; }
.sub { font-size: 13px; color: var(--muted); line-height: 1.5; }
.sub a, .card a:not(.btn):not(.item):not(.btn-text) { color: var(--primary); text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--primary) 40%, transparent); }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: 10px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; text-decoration: none; color: var(--text); box-shadow: var(--shadow-sm);
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; pointer-events: none; }
.btn.primary { background: var(--primary); color: var(--onPrimary); border-color: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); box-shadow: none; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: 13px; border-radius: var(--radius-xs); }
.btn.block { width: 100%; }
@media (hover: hover) {
  .btn:hover { transform: scale(1.02); box-shadow: var(--shadow-md); background: var(--surface2); }
  .btn.primary:hover { background: color-mix(in srgb, var(--primary) 90%, var(--bg)); }
  .btn.danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); box-shadow: none; }
  .btn.ghost:hover { background: var(--surface2); color: var(--text); box-shadow: none; }
  .btn:active { transform: scale(.98); }
}
.btn-text {
  background: none; border: 0; color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer; padding: 10px;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; transition: color var(--fast) var(--ease);
}
.btn-text:hover { color: var(--primary); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  position: relative; flex: 1 1 0; min-width: 0; min-height: 72px; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); padding: 10px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform var(--fast) var(--ease), background-color var(--base) var(--ease), border-color var(--base) var(--ease), box-shadow var(--fast) var(--ease);
}
@media (hover: hover) { .chip:hover { box-shadow: var(--shadow-md); } }
.chip:active { transform: scale(.96); }
.chip .name { font-weight: 600; font-size: 14px; text-align: center; line-height: 1.15; }
.chip .time { font-size: 12px; color: var(--muted); font-variant-numeric: lining-nums tabular-nums; white-space: nowrap; }
.chip .state { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 14px; }
.chip .state .ic { vertical-align: -2px; }
.chip.done { background: var(--tint); border-color: var(--primary); }
.chip.done .state { color: var(--primary); font-weight: 600; }
.chip.late { border-color: var(--warn); }
.chip.late .state { color: var(--warn); font-weight: 600; }
.chip.now { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.chip.now .state { color: var(--primary); font-weight: 600; text-transform: uppercase; letter-spacing: var(--tracking-wide); font-size: 10px; }
.chip.missed { opacity: .7; }
.chip.missed .state { color: var(--danger); }
.bar { height: 8px; border-radius: var(--radius-full); background: var(--surface2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; transition: width var(--slow) var(--ease); }
.bar.accent > i { background: var(--accent); }
.bar.thin { height: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 600; background: var(--surface2); border: 1px solid var(--border); white-space: nowrap;
}
.pill.primary { background: var(--tint); color: var(--primary); border-color: transparent; }
.pill.accent { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); border-color: transparent; }
label.pill { cursor: pointer; min-height: 34px; transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease); }
label.pill:has(input:checked) { background: var(--tint); border-color: var(--primary); color: var(--primary); }
label.pill input { accent-color: var(--primary); margin: 0; }
.kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi .k { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.kpi .k b { display: flex; align-items: center; gap: 6px; font-family: var(--font-serif); font-size: 28px; font-weight: 600; letter-spacing: var(--tracking-tight); line-height: 1.1; font-variant-numeric: lining-nums tabular-nums; }
.kpi .k b .muted { font-size: 18px; }
.kpi .k > span { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
.section-label { font-size: 12px; font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--primary); margin: 20px 0 10px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  transition: transform var(--base) var(--ease), box-shadow var(--base) var(--ease), border-color var(--base) var(--ease);
}
.item .t { font-weight: 600; }
.item .d { font-size: 13px; color: var(--muted); }
a.item, button.item { cursor: pointer; font: inherit; width: 100%; }
@media (hover: hover) { a.item:hover, button.item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); } }
a.item:active, button.item:active { transform: scale(.99); }
.chev { color: var(--muted); display: inline-flex; transition: transform var(--fast) var(--ease), color var(--fast) var(--ease); }
@media (hover: hover) { a.item:hover .chev, .step:hover .chev { transform: translateX(3px); color: var(--primary); } }
.checkbox {
  position: relative; width: 24px; height: 24px; border-radius: 7px; border: 1.5px solid color-mix(in srgb, var(--muted) 60%, var(--border));
  display: grid; place-items: center; flex: none; cursor: pointer; color: var(--onPrimary);
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.checkbox::before { content: ''; position: absolute; inset: -10px; }
.checkbox:active { transform: scale(.9); }
.checkbox.on { background: var(--primary); border-color: var(--primary); }
.checkbox.on::after {
  content: ''; width: 14px; height: 14px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.tabs { position: relative; display: flex; gap: 4px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 16px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px; min-height: 36px; border-radius: var(--radius-xs);
  font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer;
  transition: color var(--fast) var(--ease), background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, input.field {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; min-height: 42px; width: 100%;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, input.field:focus-visible {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--tint);
}
.field input[type="color"] { padding: 3px; height: 42px; cursor: pointer; }
.field textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.toggle {
  position: relative; width: 44px; height: 26px; border-radius: var(--radius-full); background: var(--border); border: 0; cursor: pointer; flex: none;
  transition: background-color var(--fast) var(--ease);
}
.toggle::before { content: ''; position: absolute; inset: -8px; }
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: var(--radius-full);
  background: var(--surface); box-shadow: var(--shadow-md); transition: transform var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
.toggle.on { background: var(--primary); } .toggle.on::after { transform: translateX(18px); background: var(--onPrimary); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .t { font-weight: 600; } .setting-row .d { font-size: 13px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.stepper button {
  border: 0; background: transparent; width: 42px; height: 42px; cursor: pointer; display: grid; place-items: center; color: var(--muted);
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.stepper button:hover { background: var(--surface2); color: var(--text); }
.stepper button:active { background: var(--tint); }
.stepper span { min-width: 40px; text-align: center; font-weight: 700; font-variant-numeric: lining-nums tabular-nums; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: 14px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 16px 8px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); transition: box-shadow var(--base) var(--ease); }
.badge .ic-tile { margin: 0 auto; }
.badge .n { font-size: 13px; font-weight: 600; margin-top: 10px; }
.badge .d { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.badge.locked { opacity: .45; }
.badge.locked .ic-tile { background: var(--surface2); color: var(--muted); }
.ic-tile { width: 48px; height: 48px; border-radius: var(--radius); display: grid; place-items: center; background: var(--tint); color: var(--primary); flex: none; transition: background-color var(--base) var(--ease); }
.ic-tile.sm { width: 40px; height: 40px; border-radius: var(--radius-sm); }

/* ===== Today: hero ===== */
.hero-card { padding: 24px 20px 20px; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.hero h1 { font-size: 28px; line-height: 1.15; margin-top: 6px; }
.hero h1 .w { display: inline-block; }
.hero .meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.ring { width: 120px; height: 120px; position: relative; flex: none; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .track { stroke: var(--surface2); }
.ring .fill { stroke: var(--primary); stroke-linecap: round; }
.ring .val { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; font-family: var(--font-serif); font-weight: 600; font-size: 34px; letter-spacing: var(--tracking-tight); line-height: 1; font-variant-numeric: lining-nums tabular-nums; }
.ring .val small { display: block; margin-top: 4px; font-family: var(--font); font-size: 10px; color: var(--muted); font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; }
.xp { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.xp .row { font-size: 13px; }
.streak { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.cats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 16px; }
.cat { text-align: center; font-size: 11px; color: var(--muted); font-weight: 500; }
.cat .bar { margin-bottom: 6px; }
.next-up { display: flex; align-items: center; gap: 8px; margin-top: 16px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); font-size: 13px; color: var(--muted); }
.next-up b { color: var(--text); font-weight: 600; }
.edit-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.water-glasses { display: flex; gap: 6px; flex-wrap: wrap; }
.glass {
  width: 34px; height: 44px; border-radius: 6px 6px 10px 10px; border: 1.5px solid var(--border); position: relative; overflow: hidden;
  cursor: pointer; background: var(--surface2); transition: border-color var(--base) var(--ease), transform var(--fast) var(--ease);
}
.glass:active { transform: scale(.92); }
.glass i { position: absolute; inset: 0; background: color-mix(in srgb, var(--primary) 70%, var(--surface)); transform: scaleY(0); transform-origin: bottom; }
.glass.on { border-color: color-mix(in srgb, var(--primary) 60%, var(--border)); }
.glass.on i { transform: scaleY(1); }
.glass.half i { transform: scaleY(.55); }
.focus-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.focus-mini .k { padding: 14px; border-radius: var(--radius-sm); background: var(--surface2); }
.focus-mini b { font-family: var(--font-serif); font-size: 22px; font-weight: 600; letter-spacing: var(--tracking-tight); font-variant-numeric: lining-nums tabular-nums; }
.moods { display: flex; gap: 2px; }
.moods .btn { width: 42px; padding: 0; color: var(--muted); }
.moods .btn.primary { color: var(--onPrimary); }

/* ===== Hourly timeline ===== */
.hours { position: relative; border-left: 1px solid var(--border); margin-left: 44px; }
.hour { position: relative; height: 44px; border-top: 1px dashed var(--border); }
.hour .lbl { position: absolute; left: -48px; top: -9px; width: 38px; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: lining-nums tabular-nums; }
.hour.now { background: linear-gradient(90deg, var(--tint), transparent); }
.hour.now .lbl { color: var(--primary); font-weight: 700; }
.ev {
  position: absolute; left: 8px; right: 8px; border-radius: var(--radius-xs); padding: 2px 8px; font-size: 12px; font-weight: 600;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-left: 3px solid var(--primary); background: var(--surface2); box-shadow: var(--shadow-sm);
}
.ev.work { border-left-color: var(--primary); } .ev.study { border-left-color: var(--accent); }
.ev.prayer { background: var(--tint); border-left-color: var(--primary); }
.ev.meal { border-left-color: var(--success); } .ev.exercise { border-left-color: var(--warn); }
.ev.planned { opacity: .55; border-left-style: dashed; box-shadow: none; }
.ev.dot { right: auto; padding: 1px 8px; }
.now-line { position: absolute; left: -5px; right: 0; height: 1.5px; background: var(--danger); z-index: 2; transition: top var(--slow) var(--ease); }
.now-line::before { content: ''; position: absolute; left: 0; top: -4px; width: 9px; height: 9px; border-radius: var(--radius-full); background: var(--danger); }

/* ===== Timeline analytics ===== */
.heatmap { display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; overflow-x: auto; padding-bottom: 6px; }
.heatmap i { border-radius: 3px; background: var(--surface2); }
.heatmap i.l1 { background: color-mix(in srgb, var(--primary) 22%, var(--surface2)); }
.heatmap i.l2 { background: color-mix(in srgb, var(--primary) 45%, var(--surface2)); }
.heatmap i.l3 { background: color-mix(in srgb, var(--primary) 70%, var(--surface2)); }
.heatmap i.l4 { background: var(--primary); }
.heatmap i.today { outline: 1.5px solid var(--text); outline-offset: 1px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .grid { stroke: var(--border); stroke-dasharray: 2 4; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: lining-nums tabular-nums; }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.accent { stroke: var(--primary); }
.chart .area { fill: var(--primary); opacity: .08; }
.chart .dot { fill: var(--surface); stroke: var(--primary); stroke-width: 1.5; }
.chart .bar-work { fill: var(--primary); } .chart .bar-study { fill: var(--accent); }
.chart .bar-water { fill: color-mix(in srgb, var(--primary) 55%, var(--surface)); }
.chart .target { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.day-row {
  display: grid; grid-template-columns: 72px 1fr 44px; gap: 12px; align-items: center; padding: 10px 8px; margin: 0 -8px;
  border-bottom: 1px solid var(--border); cursor: pointer; border-radius: var(--radius-xs); transition: background-color var(--fast) var(--ease);
}
.day-row:hover { background: color-mix(in srgb, var(--surface2) 60%, transparent); }
.day-row:last-child { border-bottom: 0; }
.day-row .score { font-family: var(--font-serif); font-size: 18px; font-weight: 600; text-align: right; font-variant-numeric: lining-nums tabular-nums; }
.mini-cats { display: flex; gap: 3px; }
.mini-cats i { flex: 1; height: 4px; border-radius: 2px; background: var(--surface2); }
.mini-cats i.on { background: var(--primary); } .mini-cats i.half { background: color-mix(in srgb, var(--primary) 45%, var(--surface2)); }

/* ===== Train ===== */
.fig { width: 100%; max-width: 320px; height: auto; display: block; margin: 0 auto; }
.fig.thumb { width: 56px; max-width: none; }
.fig line, .fig polyline, .fig path { fill: none; stroke: var(--text); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.fig .far { stroke: var(--muted); opacity: .5; stroke-width: 3.5; }
.fig .head { fill: var(--text); stroke: none; }
.fig .prop { stroke: var(--muted); stroke-width: 2.5; opacity: .55; fill: none; }
.fig .prop.floor { stroke-width: 1.5; }
.fig .prop.bar { stroke-width: 5; }
.fig .arrow { stroke: var(--muted); stroke-width: 2.5; }
.fig rect.prop { fill: var(--surface2); }
.fig-panel { padding: 12px 0 4px; border-radius: var(--radius-sm); background: var(--surface2); }
.step {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); cursor: pointer;
  transition: transform var(--base) var(--ease), box-shadow var(--base) var(--ease);
}
@media (hover: hover) { .step:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); } }
.step .fig.thumb { background: var(--surface2); border-radius: var(--radius-xs); }
.step.done { opacity: .6; }
.step .n { font-weight: 600; } .step .p { font-size: 13px; color: var(--muted); }
.step .n .num { font-family: var(--font-serif); color: color-mix(in srgb, var(--primary) 45%, transparent); margin-right: 8px; font-variant-numeric: lining-nums; }
.step.open .chev { transform: rotate(90deg); }
.step-detail { margin-top: -2px; }
.step-detail:not(.hidden) { animation: rise-sm var(--base) var(--ease) both; }
.workout-live { text-align: center; padding: 20px; }
.workout-live h2 { font-size: 26px; margin-top: 4px; }
.workout-live .timer {
  font-family: var(--font-serif); font-size: 72px; font-weight: 600; letter-spacing: -.03em;
  font-variant-numeric: lining-nums tabular-nums; line-height: 1; margin: 18px 0 12px;
}
.workout-live .timer small { font-family: var(--font); font-size: 16px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.workout-live .phase { font-size: 12px; font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--primary); }
.workout-live.rest .timer { color: var(--muted); }
.workout-live .bar { margin: 0 auto 4px; max-width: 280px; }
.sets { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.sets .set {
  min-width: 42px; padding: 6px 10px; border-radius: var(--radius-xs); background: var(--surface2); border: 1px solid var(--border);
  font-weight: 700; font-variant-numeric: lining-nums tabular-nums; transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.sets .set.done { background: var(--tint); border-color: var(--primary); color: var(--primary); }
.cues { padding-left: 18px; margin: 12px 0 0; font-size: 14px; line-height: 1.55; }
.cues li + li { margin-top: 6px; }
.cues li::marker { color: var(--muted); }

/* ===== Focus ===== */
.focus-timer { text-align: center; padding: 8px 0 4px; }
.focus-timer .big { font-family: var(--font-serif); font-size: 80px; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: lining-nums tabular-nums; line-height: 1; }
.focus-timer .lbl { font-size: 12px; font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--primary); margin-bottom: 10px; }
.focus-timer .track { height: 2px; max-width: 220px; margin: 18px auto 0; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.focus-timer .track i { display: block; height: 100%; width: 0; background: var(--primary); transition: width 1s linear; }
.focus-timer.running .big { color: var(--text); }
.seg { display: inline-flex; gap: 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; background: var(--surface2); }
.seg button {
  border: 0; background: transparent; padding: 6px 16px; min-height: 34px; border-radius: var(--radius-xs); font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted);
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg button:disabled { cursor: default; }
.block { display: grid; grid-template-columns: 3px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); transition: box-shadow var(--base) var(--ease); }
.block[data-action] { cursor: pointer; }
@media (hover: hover) { .block[data-action]:hover { box-shadow: var(--shadow-md); } }
.block > i { width: 3px; height: 100%; min-height: 34px; border-radius: 2px; background: var(--primary); }
.block.study > i { background: var(--accent); }
.block .t { font-weight: 600; font-size: 14px; } .block .d { font-size: 13px; color: var(--muted); font-variant-numeric: lining-nums tabular-nums; }

/* ===== Food ===== */
.macro { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.macro .m { text-align: center; background: var(--surface2); border-radius: var(--radius-sm); padding: 12px 4px; }
.macro .m b { display: block; font-family: var(--font-serif); font-size: 20px; font-weight: 600; letter-spacing: var(--tracking-tight); font-variant-numeric: lining-nums tabular-nums; }
.macro .m span { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; }
.meal-card {
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); padding: 20px; box-shadow: var(--shadow-sm);
  transition: border-color var(--base) var(--ease), background-color var(--base) var(--ease), box-shadow var(--base) var(--ease);
}
.meal-card .slot { font-size: 12px; font-weight: 600; letter-spacing: var(--tracking-wide); text-transform: uppercase; color: var(--primary); }
.meal-card h3 { font-size: 20px; margin: 4px 0 6px; }
.meal-card.done { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); background: color-mix(in srgb, var(--primary) 4%, var(--surface)); }
.ingr { margin: 14px 0 0; padding: 0; list-style: none; font-size: 14px; }
.ingr li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.ingr li:last-child { border-bottom: 0; }
.ingr li span:last-child { color: var(--muted); white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
details summary {
  cursor: pointer; font-weight: 600; font-size: 14px; color: var(--primary); margin-top: 12px; list-style: none;
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px;
}
details summary::-webkit-details-marker { display: none; }
details summary .ic { transition: transform var(--fast) var(--ease); }
details[open] summary .ic { transform: rotate(90deg); }
details[open] > :not(summary) { animation: rise-sm var(--base) var(--ease) both; }
ol.steps { padding-left: 20px; margin: 8px 0 0; font-size: 14px; line-height: 1.55; }
ol.steps li + li { margin-top: 4px; }
.week-day { padding: 12px 0; border-bottom: 1px solid var(--border); }
.week-day:first-child { padding-top: 0; }
.week-day.today b { color: var(--primary); }
.week-day .meal-line { display: grid; grid-template-columns: 84px 1fr; gap: 8px; }

/* ===== Theme editor ===== */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.theme-tile {
  border-radius: var(--radius-sm); border: 1px solid var(--border); padding: 10px; cursor: pointer; text-align: left; background: var(--surface);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
}
@media (hover: hover) { .theme-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); } }
.theme-tile.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.theme-tile .sw { display: flex; gap: 3px; margin-bottom: 8px; }
.theme-tile .sw i { flex: 1; height: 20px; border-radius: 4px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 10%, transparent); }
.theme-tile .n { font-size: 13px; font-weight: 600; }
/* The hue picker is the one place a full spectrum is the point. */
.hue { -webkit-appearance: none; appearance: none; width: 100%; height: 14px; border-radius: var(--radius-full); outline: 0;
  background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.hue::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border); box-shadow: var(--shadow-md); }

/* ===== Lock screen ===== */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.lock-card { width: min(320px, 100%); text-align: center; animation: rise var(--slow) var(--ease) both; }
.lock-card h1 { font-size: 30px; margin: 16px 0 4px; }
.lock-card > p { font-size: 14px; }
.lock-logo img { border-radius: var(--radius); box-shadow: var(--shadow-md); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 24px 0; }
.pin-dots span { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--muted); transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease); }
.pin-dots span.on { background: var(--primary); border-color: var(--primary); }
.pin-dots span.on:not(:has(+ span.on)) { animation: dot-in var(--fast) var(--ease) both; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-pad button {
  height: 64px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm);
  font-family: var(--font-serif); font-size: 26px; font-weight: 500; cursor: pointer; display: grid; place-items: center;
  font-variant-numeric: lining-nums; transition: transform var(--fast) var(--ease), background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.pin-pad button:active { transform: scale(.95); background: var(--surface2); box-shadow: none; }
.pin-pad button:disabled { opacity: .35; cursor: default; }
.pin-pad button[data-k="bio"]:disabled { opacity: 0; }
.pin-pad button[data-k="bio"], .pin-pad button[data-k="del"] { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }

/* ===== Modal (bottom sheet) & toast ===== */
.modal-bg {
  position: fixed; inset: 0; background: rgb(0 0 0 / .6); z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in var(--fast) var(--ease) both;
}
.modal-bg.see-through { background: rgb(0 0 0 / .15); }
.modal-bg.closing { animation: fade-out var(--base) var(--ease-in-out) both; }
.modal {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
  width: min(640px, 100%); max-height: 88dvh; overflow: auto; padding: 28px 20px calc(20px + var(--sab)); box-shadow: var(--shadow-xl);
  animation: sheet-in var(--slow) var(--ease) both; overscroll-behavior: contain;
}
.modal::before { content: ''; position: absolute; top: 10px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: var(--radius-full); background: var(--border); }
.modal-bg.closing .modal { animation: sheet-out var(--base) var(--ease-in-out) both; }
.modal h2 { font-size: 24px; margin-bottom: 16px; }
.modal .actions { display: flex; gap: 8px; margin-top: 20px; }
.modal .actions .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sab) + 16px); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  z-index: 60; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; box-shadow: var(--shadow-lg);
  transition: opacity var(--base) var(--ease), transform var(--base) var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Moment (replaces confetti: a quiet, serif acknowledgement) ===== */
.moment { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; pointer-events: none; padding: 24px; }
.moment .m-card {
  min-width: min(280px, 100%); text-align: center; padding: 28px 32px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-xl); animation: rise var(--slow) var(--ease) both;
}
.moment .m-card .ic-tile { margin: 0 auto 14px; }
.moment .m-card h2 { font-size: 28px; margin-top: 6px; }
.moment .m-card p { margin-top: 6px; color: var(--muted); font-size: 14px; }
.moment.out .m-card { animation: fade-up-out var(--base) var(--ease-in-out) both; }

/* ===== Motion ===== */
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
@keyframes rise-sm { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-up-out { to { opacity: 0; transform: translateY(-10px); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes dot-in { from { transform: scale(.5); opacity: 0; } }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
@keyframes settle { 40% { transform: scale(.97); } }
@keyframes fill-up { from { transform: scaleY(0); } }
@keyframes draw { from { stroke-dashoffset: 1; } }

/* Route enter: the panel rises once; its first cards follow on a short, capped stagger. */
.view-enter > * { animation: rise var(--slow) var(--ease) both; }
.view-enter > :nth-child(2) { animation-delay: 60ms; }
.view-enter > :nth-child(3) { animation-delay: 120ms; }
.view-enter > :nth-child(4) { animation-delay: 180ms; }
.view-enter > :nth-child(5) { animation-delay: 240ms; }
.view-enter > :nth-child(n+6) { animation-delay: 300ms; }
.view-enter .hero h1 .w { animation: rise var(--slow) var(--ease) both; animation-delay: calc(150ms + var(--wi, 0) * 80ms); }
.view-enter .chart .line { stroke-dasharray: 1; animation: draw 900ms var(--ease) 250ms both; }
#topbar-title.swap { animation: rise-sm var(--base) var(--ease) both; }

/* One-shot state feedback, applied by views only to the element that just changed. */
.pop { animation: settle var(--base) var(--ease); }
.pop .state .ic, .checkbox.on.pop::after { animation: pop var(--fast) var(--ease) both; }
.glass.fill-in i { animation: fill-up var(--slow) var(--ease) both; animation-delay: calc(var(--gi, 0) * 50ms); }
.set.pop { animation: pop var(--fast) var(--ease) both; }
.phase-in .phase, .phase-in h2, .phase-in .timer { animation: rise-sm var(--base) var(--ease) both; }
.phase-in h2 { animation-delay: 40ms; } .phase-in .timer { animation-delay: 80ms; }

@media (min-width: 640px) {
  .view { padding-top: 16px; }
  .card, .meal-card { padding: 24px; }
  .kpi { grid-template-columns: repeat(3, 1fr); }
  .cats { gap: 12px; }
  .hero h1 { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
