/* base.css — @font-face, reset, layout, components, states.
   Design tokens (colors/type/spacing/radius) live in tokens.css, loaded first. */

/* ---------- self-hosted fonts (offline-first — cached by sw.js) ----------
   Fraunces (display/serif, opsz+wght variable axis in one file) and Space Grotesk
   (UI/sans, variable weight) are both SIL Open Font License, free for commercial use.
   font-display: swap avoids a blank-text flash; the metric-tuned FALLBACK faces right
   below make the swap itself nearly invisible (see the comment on each one). */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url("../assets/fonts/fraunces-latin.woff2") format("woff2");
}
/* Metrics extracted directly from the actual woff2 (via fontTools — unitsPerEm 2000,
   ascent 1956, descent -510) and matched against Times New Roman using the standard
   capsize/fontaine size-adjust formula, so the fallback line-box is (almost) the same
   height and average width as Fraunces — the swap causes minimal reflow. */
@font-face {
  font-family: "Fraunces Fallback";
  src: local("Georgia"), local("Times New Roman"), local("Times");
  size-adjust: 145.72%;
  ascent-override: 67.12%;
  descent-override: 17.5%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../assets/fonts/space-grotesk-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1EFF;
  src: url("../assets/fonts/space-grotesk-latin-ext.woff2") format("woff2");
}
/* Same technique: metrics from the real file (unitsPerEm 1000, ascent 984,
   descent -292) matched against Arial. */
@font-face {
  font-family: "Space Grotesk Fallback";
  src: local("Arial"), local("Helvetica"), local("Segoe UI"), local("Roboto");
  size-adjust: 126.64%;
  ascent-override: 77.7%;
  descent-override: 23.06%;
  line-gap-override: 0%;
}

/* ---------- reset ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  background: var(--bg);
  color: var(--ink);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--sp-6);
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: var(--lh-tight); margin: 0; }
p { margin: 0; }
button, input { font-family: inherit; }
img, svg { display: block; }

/* Always honour the OS-level reduced-motion preference, independent of the in-app
   toggle (that toggle is seeded FROM this same query at boot — see app.js — but this
   is a hard floor so motion never leaks through before JS runs). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
[data-reduce="1"] *, [data-reduce="1"] *::before, [data-reduce="1"] *::after { animation: none !important; transition: none !important; }

@media (prefers-contrast: more) {
  :root, [data-theme] { --line: var(--ink-soft); }
  .btn, .heat-cell, .field { border-width: 2px; }
}
@media (forced-colors: active) {
  .btn, .field, .heat-cell, .habit-row { forced-color-adjust: none; border: 1px solid CanvasText; }
}

/* faint paper grain, off for reduced-motion/contrast. A 64x64 baked noise tile
   (data URI, ~0.8KB, no extra request) — not a small repeating radial-gradient,
   which forces a gradient recompute per tiny tile and measurably slowed first
   paint (~150ms) in testing; a decoded bitmap tiles for free by comparison. */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1;
  opacity: var(--grain-opacity);
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAQKADAAQAAAABAAAAQAAAAABlmWCKAAABxUlEQVR4Ae2X7W3DMBBD/ZEpMoFn8XCeOEmbp5auWjRAgPtFgQKas04+II+kjWY+juPjuaZ5nieqlq6XZWmtx+PR7mGzbdu077tuta4LoPoTCWKwgOcaeJb6Eqc1zT+ava/ch03wSgI9CcG1+/rK9zdF7yzA7BGAa6rOhxLgFYycRxvA+wRICHf3+f6/EiCgXhTA2Y8ELc5TAOCAFCzur+vaoOmzp0qIkcS4CIYqIQSNIPSovQicj7LaIwCg3AdMoug9IPhRoHuORbG+3++nyxJBZ0oC/ZHch2eRy0DquacKlDT0CdD9DI+wWgIAkdsAkgaWnv+2eX70oqjnXs+XIOB6D1BZAmZ/u93Oc/Xd4fn+F37Y/AXCeb0IOUMA9dhfr9cR2BvD/AT7+Qk4DNb7IP/+J/j+uP+dEcDfwxpBElDTz386CfD3sEaQBNT0859OAvw9rBEkATX9/KeTAH8PawRJQE0//+kkwN/DGkESUNPPfzoJ8PewRpAE1PTzn04C/D2sESQBNf38p5MAfw9rBElATT//6STA38MaQRJQ089/Ognw97BGkATU9POfTgL8PawRJAE1/fynkwB/D2sESUBNP//pT8WgulJfdq5kAAAAAElFTkSuQmCC");
  background-size: 64px 64px;
}
@media (prefers-reduced-motion: reduce), (prefers-contrast: more) { body::before { display: none; } }

.skip-link { position: absolute; left: -999px; top: 0; z-index: 100; }
.skip-link:focus { left: var(--sp-3); top: var(--sp-3); background: var(--ink); color: var(--bg); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-xs); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.ic { width: 18px; height: 18px; flex: 0 0 auto; }

/* ---------- masthead ---------- */
.masthead { max-width: var(--maxw); margin: 0 auto; padding: calc(env(safe-area-inset-top) + var(--sp-4)) var(--sp-3) var(--sp-2); position: relative; z-index: 2; }
.masthead-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.wordmark { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-display); font-weight: 600; font-size: var(--fs-h1); color: var(--ink); }
.wordmark-ic { width: 24px; height: 24px; color: var(--primary); }
.masthead-actions { display: flex; gap: var(--sp-2); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; transition: transform .1s ease, background .15s ease; }
.icon-btn:active { transform: scale(.92); }
.icon-btn:hover { border-color: var(--primary); }
/* min-height must match the REAL line-box (font-size x body's 1.55 line-height),
   not just the glyph box — a smaller reservation here caused a measured CLS the
   instant renderDateline() filled in the (initially empty) text on boot. */
.dateline { font-family: var(--font-display); font-size: var(--fs-display); font-weight: 500; font-style: italic; margin-top: var(--sp-3); color: var(--ink); min-height: calc(1em * var(--lh-body)); }
.tagline { color: var(--ink-soft); font-size: var(--fs-sm); margin-top: var(--sp-1); max-width: 46ch; }

/* ---------- main layout ---------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--sp-3); position: relative; z-index: 2; }
.spine { margin-top: var(--sp-5); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.section-head h1 { font-size: var(--fs-h1); }
.section-head h2 { font-size: var(--fs-h2); }
.sub { color: var(--ink-soft); font-size: var(--fs-sm); }
.cite { color: var(--ink-soft); font-size: var(--fs-xs); font-style: italic; margin-top: var(--sp-2); line-height: 1.5; }
.hint { color: var(--ink-soft); font-size: var(--fs-xs); line-height: 1.5; margin-top: var(--sp-2); }
.muted { color: var(--ink-soft); font-weight: 400; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: var(--sp-3); }
.mt-18 { margin-top: 18px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 18px; transition: transform .08s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.96); }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.btn.big { width: 100%; padding: 15px; font-size: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.link-btn { background: none; border: none; padding: 0; color: var(--primary); text-decoration: underline; font: inherit; cursor: pointer; }
.mini { display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font: inherit; font-size: 12.5px; min-height: 40px; padding: 8px 12px; border-radius: var(--radius-xs);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer;
  transition: transform .08s ease, background .15s ease; }
.mini:active { transform: scale(.94); }
.mini .ic { width: 14px; height: 14px; }

/* ---------- "never miss twice" nudge ---------- */
.nudge { display: flex; gap: var(--sp-2); align-items: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: var(--sp-3); margin-bottom: var(--sp-3); font-size: var(--fs-sm); color: var(--ink); }
.nudge .ic { color: var(--accent); margin-top: 2px; }

/* ---------- habit list ---------- */
/* min-height matches the empty-state's real height (~250px) — belt-and-braces
   alongside the static empty-state markup in index.html (see app.js renderHabitList)
   for the rare re-render path (e.g. after deleting the last habit). */
.habit-list { display: flex; flex-direction: column; gap: var(--sp-2); min-height: 248px; }
.habit-row {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-3);
  transition: box-shadow .15s ease, transform .1s ease;
}
.habit-row.is-pinned { box-shadow: 0 6px 22px -14px var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.habit-open {
  display: flex; align-items: center; gap: var(--sp-3); flex: 1 1 auto; min-width: 0;
  background: none; border: none; text-align: left; cursor: pointer; padding: var(--sp-2) 0;
  border-radius: var(--radius-sm);
}
.habit-icon-badge {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center;
  background: color-mix(in srgb, var(--habit-color, var(--primary)) 16%, var(--surface));
  color: var(--habit-color, var(--primary));
}
.habit-icon-badge.lg { width: 56px; height: 56px; }
.habit-icon-badge .ic { width: 22px; height: 22px; }
.habit-meta { min-width: 0; }
.habit-name { display: block; font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.habit-sub { display: flex; align-items: center; gap: 5px; color: var(--ink-soft); font-size: var(--fs-xs); margin-top: 2px; flex-wrap: wrap; }
.habit-sub .ic { width: 13px; height: 13px; color: var(--accent); }
.habit-row-nudge { display: flex; align-items: center; gap: 5px; color: var(--ink); font-size: 11.5px; margin-top: 4px; background: var(--surface-2); border-radius: 999px; padding: 3px 9px; width: fit-content; }
.habit-row-nudge .ic { width: 12px; height: 12px; color: var(--accent); }
.habit-actions { display: flex; align-items: center; gap: var(--sp-1); flex: 0 0 auto; }
.pin-btn, .more-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid transparent; background: none;
  color: var(--ink-soft); cursor: pointer; display: grid; place-items: center; transition: transform .08s ease, color .15s ease;
}
.pin-btn:hover, .more-btn:hover { color: var(--primary); background: var(--surface-2); }
.pin-btn:active, .more-btn:active { transform: scale(.9); }
.pin-btn[aria-pressed="true"] { color: var(--accent); }
.check-btn {
  width: 48px; height: 48px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--primary); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; color: transparent; transition: transform .12s ease, background .15s ease, color .15s ease;
}
.check-btn .ic { width: 22px; height: 22px; }
.check-btn:active { transform: scale(.88); }
.check-btn:hover { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 14%, transparent); }
.check-btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
/* signature ink-in micro-interaction on the check control itself */
.check-btn.just-checked { animation: inkPop .42s cubic-bezier(.2,.8,.2,1); }
@keyframes inkPop { 0% { transform: scale(.7); } 55% { transform: scale(1.18); } 100% { transform: scale(1); } }

.empty-state { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: var(--sp-5) var(--sp-4); text-align: center; }
.empty-state h2 { font-size: var(--fs-h1); margin-bottom: var(--sp-2); }
.empty-state p { color: var(--ink-soft); max-width: 42ch; margin: 0 auto var(--sp-4); }
.starter-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.starter-chip { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 14px; min-height: 44px;
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer;
  transition: transform .08s ease, border-color .15s ease; }
.starter-chip:hover { border-color: var(--primary); }
.starter-chip:active { transform: scale(.95); }
.starter-chip .ic { color: var(--primary); }

.add-cta { width: 100%; margin-top: var(--sp-3); }

/* ---------- heatmap band ---------- */
.heat-band { margin-top: var(--sp-6); background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: var(--sp-4) var(--sp-3); margin-left: calc(-1 * var(--sp-3)); margin-right: calc(-1 * var(--sp-3)); }
@media (min-width: 760px) { .heat-band { border-radius: var(--radius); margin-left: 0; margin-right: 0; } }
/* min-height 119px = the real rendered grid height (7 rows), reserved so the
   insights/footer below don't jump when JS fills the heatmap in. */
.heat-scroll { overflow-x: auto; padding-bottom: var(--sp-1); -webkit-overflow-scrolling: touch; min-height: 119px; }
.heat-ticks { display: grid; grid-auto-flow: column; grid-auto-columns: 13px; gap: var(--sp-1); font-size: 9.5px; color: var(--ink-soft); margin-bottom: 3px; min-width: max-content; }
.heatgrid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: var(--sp-1); min-width: max-content; }
.heatgrid-ov { grid-template-rows: repeat(7, 13px); }

/* 13px cells: WCAG 2.2 SC 2.5.8 "Essential" exception (same one date-grids rely on —
   16 weeks at a glance needs a dense cell size, cf. GitHub's contribution graph).
   Every cell has a real accessible name + keyboard reach (roving tabindex, see
   heatmap.js); the one action most users need — marking TODAY — has a full 44px
   button on the habit row, so nothing is pointer-only at sub-44px size. */
.heat-cell {
  width: 13px; height: 13px; padding: 0; border-radius: 3px; cursor: pointer;
  background: transparent; border: 1px solid var(--line);
  display: grid; place-items: center; position: relative;
}
.heat-cell[aria-disabled="true"] { cursor: default; }
.heat-cell .heat-mark { width: 8px; height: 8px; color: var(--primary-ink); }
/* not-scheduled: dashed hairline, muted — "empty slot" */
.heat-cell[data-state="not-scheduled"] { border-style: dashed; opacity: .55; }
/* future: even quieter, solid faint */
.heat-cell[data-state="future"] { border-style: solid; opacity: .3; }
/* pending (today, not yet acted on): dashed PRIMARY ring so today is easy to find */
.heat-cell[data-state="pending"] { border: 2px dashed var(--primary); background: var(--surface-2); }
/* done: solid fill + a small check mark (never color alone) */
.heat-cell[data-state="done"] { background: var(--primary); border-color: var(--primary); }
/* frozen: distinct cool tint + diagonal stripe TEXTURE (not just a different hue) */
.heat-cell[data-state="frozen"] {
  background: repeating-linear-gradient(135deg, var(--frozen), var(--frozen) 2px, color-mix(in srgb, var(--frozen) 45%, var(--surface)) 2px, color-mix(in srgb, var(--frozen) 45%, var(--surface)) 4px);
  border-color: var(--frozen);
}
/* missed: hollow with a THICK solid outline + centered dot — distinct from the dashed
   not-scheduled cell by both weight and fill, never relies on hue alone */
.heat-cell[data-state="missed"] { border: 2px solid var(--ink-soft); background: var(--surface); }
.heat-cell[data-state="missed"]::after { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--ink-soft); }
.heat-cell.is-today { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--primary); }
.heat-cell:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; z-index: 2; }
/* overview ramp — 5 steps from empty to "everyone checked in", color-mix so it always
   derives from the theme's own --primary (no hardcoded hex to go stale per theme) */
.heat-cell-ov[data-state="ov-0"] { background: var(--surface-2); border-color: var(--line); }
.heat-cell-ov[data-state="ov-1"] { background: color-mix(in srgb, var(--primary) 30%, var(--surface-2)); border-color: transparent; }
.heat-cell-ov[data-state="ov-2"] { background: color-mix(in srgb, var(--primary) 55%, var(--surface-2)); border-color: transparent; }
.heat-cell-ov[data-state="ov-3"] { background: color-mix(in srgb, var(--primary) 78%, var(--surface-2)); border-color: transparent; }
.heat-cell-ov[data-state="ov-4"] { background: var(--primary); border-color: var(--primary); }

/* signature "ink in" animation on a freshly-completed heatmap cell */
@keyframes inkIn { 0% { transform: scale(.4); opacity: .3; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.heat-cell.just-inked { animation: inkIn .38s cubic-bezier(.2,.8,.2,1); }

/* ---------- insights (asymmetric footer, per SPEC §6 — not 3 equal cards) ---------- */
.insights { margin-top: var(--sp-5); }
.insight-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--sp-2); }
.insight-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.insight-big { grid-row: span 2; justify-content: center; }
.insight-n { font-family: var(--font-display); font-size: clamp(1.8rem, 1.5rem + 1vw, 2.4rem); font-weight: 600; font-variant-numeric: tabular-nums; }
.insight-big .insight-n { font-size: clamp(2.4rem, 2rem + 1.6vw, 3.2rem); }
.insight-l { color: var(--ink-soft); font-size: var(--fs-xs); }
.insight-summary { margin-top: var(--sp-3); font-family: var(--font-display); font-style: italic; font-size: 17px; color: var(--ink); line-height: 1.5; min-height: 1.5em; }

/* ---------- footer ---------- */
.site-footer { max-width: var(--maxw); margin: var(--sp-6) auto 0; padding: var(--sp-4) var(--sp-3); border-top: 1px solid var(--line); text-align: center; color: var(--ink-soft); font-size: var(--fs-sm); position: relative; z-index: 2; }
.version { color: var(--ink-soft); font-size: 11.5px; text-align: center; margin-top: var(--sp-2); }

/* ---------- form fields ---------- */
.field-label { display: block; font-size: var(--fs-sm); font-weight: 600; margin: var(--sp-3) 0 var(--sp-2); color: var(--ink); }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.field {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--ink);
  min-height: 44px;
}
.field:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 1px; }
.field-err { color: var(--danger); font-size: var(--fs-xs); margin-top: 6px; }

.icon-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--sp-2); }
.icon-opt { aspect-ratio: 1; border-radius: var(--radius-sm); border: 1.5px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer; display: grid; place-items: center; min-height: 44px; }
.icon-opt[aria-checked="true"] { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, var(--surface)); }
.icon-opt:hover { border-color: var(--primary); }

.swatch-picker { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.swatch-opt { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; background: var(--sw, var(--primary)); position: relative; }
.swatch-opt[aria-checked="true"]::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--ink); }
.swatch-opt[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface); }

.seg-group { display: flex; gap: var(--sp-1); background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; }
.seg { flex: 1; font: inherit; font-size: 13px; font-weight: 500; min-height: 40px; border: none; border-radius: var(--radius-xs); background: transparent; color: var(--ink-soft); cursor: pointer; padding: 8px 6px; }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: 0 1px 4px -1px rgba(0,0,0,.18); }

.weekday-picker { display: flex; gap: 6px; margin-top: var(--sp-2); flex-wrap: wrap; }
.wd-btn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-size: 12.5px; font-weight: 600; }
.wd-btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.stepper { display: inline-flex; align-items: center; gap: var(--sp-3); }
.stepper-btn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface); font-size: 20px; color: var(--ink); cursor: pointer; }
.stepper-btn:active { transform: scale(.92); }
.stepper output { font-family: var(--font-display); font-size: 22px; font-weight: 600; min-width: 2ch; text-align: center; }

.coach-details { margin-top: var(--sp-4); border-top: 1px solid var(--line); padding-top: var(--sp-3); }
.coach-details summary { cursor: pointer; font-weight: 600; font-size: var(--fs-sm); padding: 6px 0; }
.coach-details summary:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; }

.stack-row { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); }
.stack-word { flex: 0 0 52px; font-size: var(--fs-sm); color: var(--ink-soft); font-weight: 600; }

/* ---------- overlay sheets (dialogs) ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(20, 16, 12, .5);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-3); }
.sheet { position: relative; background: var(--bg); width: 100%; max-width: var(--maxw); border-radius: 22px;
  max-height: 90vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom)); animation: rise .28s cubic-bezier(.2,.8,.2,1); }
.sheet-wide { max-width: 620px; }
@keyframes rise { from { transform: translateY(32px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 21px; margin: var(--sp-1) 0 6px; padding-right: 40px; }
.sheet-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--primary); border: 1px solid var(--line); margin-bottom: var(--sp-2); }
.sheet-ic { width: 24px; height: 24px; }
.sheet-close { position: absolute; top: var(--sp-2); right: var(--sp-2); width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer;
  display: grid; place-items: center; }
.sheet-close:active { transform: scale(.9); }

.detail-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.detail-identity { font-style: italic; color: var(--ink-soft); font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.detail-stats { display: flex; gap: var(--sp-2); margin: var(--sp-3) 0; }
.detail-stat { flex: 1; background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--sp-2); text-align: center; }
.detail-stat .insight-n { font-size: 22px; }

.menu-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-3); }
.menu-item { display: flex; align-items: center; gap: var(--sp-3); width: 100%; text-align: left;
  font: inherit; font-size: 15px; cursor: pointer; padding: 13px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); min-height: 44px;
  transition: transform .08s ease, border-color .15s ease; }
.menu-item:hover { border-color: var(--primary); }
.menu-item:active { transform: scale(.98); }
.menu-item[disabled] { opacity: .5; cursor: not-allowed; }
.menu-ic { width: 20px; height: 20px; flex: 0 0 auto; color: var(--primary); }
.menu-label { display: flex; flex-direction: column; gap: 2px; }
.menu-sub { font-size: 12px; color: var(--ink-soft); font-weight: 400; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .menu-ic { color: var(--danger); }

.tip-list { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-2); }
.tip-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--sp-3); }
.tip-card h4 { font-family: var(--font-display); font-size: 16px; margin-bottom: 4px; }
.tip-card p { font-size: var(--fs-sm); color: var(--ink); margin-bottom: 6px; }
.tip-card .cite { margin-top: 0; }
.legend { list-style: none; padding: 0; margin: var(--sp-2) 0; }
.legend li { display: flex; gap: var(--sp-2); font-size: var(--fs-sm); line-height: 1.5; padding: 8px 0; border-bottom: 1px solid var(--line); }
.legend b { font-family: var(--font-display); }

.about-h { font-size: 15px; margin: var(--sp-4) 0 4px; }
.about-p { font-size: 14px; line-height: 1.6; color: var(--ink-soft); margin: 0; }
.about-p a { color: var(--primary); }

.setting-group { margin: var(--sp-4) 0; padding-bottom: var(--sp-3); border-bottom: 1px solid var(--line); }
.setting-group h3 { font-size: 16px; margin: 0 0 var(--sp-2); }
.toggle { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) 0; font-size: 15px; min-height: 44px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.theme-picker { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.theme-swatch { display: flex; flex-direction: column; align-items: center; gap: 5px; background: none; border: none; cursor: pointer; padding: 4px; }
.theme-swatch-dot { width: 46px; height: 46px; border-radius: 14px; border: 2px solid var(--line); position: relative; overflow: hidden; }
.theme-swatch[aria-pressed="true"] .theme-swatch-dot { outline: 3px solid var(--ink); outline-offset: 2px; }
.theme-swatch-label { font-size: 11px; color: var(--ink-soft); }
.steps-guide { margin: var(--sp-2) 0 4px; padding-left: 22px; }
.steps-guide li { font-size: 15px; line-height: 1.55; padding: 6px 0; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-size: 14px; z-index: 70; max-width: 90%; text-align: center; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); animation: rise .22s ease; }
.toast-btn { margin-left: 8px; background: var(--bg); color: var(--ink); border: none; border-radius: 999px;
  padding: 5px 13px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.toast-btn:active { transform: scale(.94); }

/* install banner: position:fixed at the BOTTOM, on purpose (CLS) —
   beforeinstallprompt can fire well after first paint; in normal flow it would push
   everything below it down (measured via PerformanceObserver). Out-of-flow means it
   only ever overlays — and bottom (not top) so it can never cover the masthead's
   Habit-lab / Settings buttons the way a top-fixed banner did in an earlier pass
   (caught by a scripted click-through test: #open-settings became unreachable
   whenever the banner was showing). Nothing else lives at the bottom of the page. */
.banner { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--primary); color: var(--primary-ink); font-size: 14px; text-align: center;
  box-shadow: 0 -6px 18px -8px rgba(0,0,0,.35); }
.banner button { margin-left: 8px; background: var(--primary-ink); color: var(--primary); border: none; border-radius: 8px; padding: 6px 10px; font: inherit; cursor: pointer; }
.banner .close { background: transparent; color: var(--primary-ink); float: right; padding: 4px; }
