/* ===== Weights — Popsicle design system (§15) ===== */
/* All color is driven by CSS custom properties so the L/D/A toggle + auto
   schedule work for free. Never hardcode hex in component rules. */

:root, :root[data-theme="light"] {
  /* Popsicle (light) */
  --bg: #f6f5fa;            /* cool lilac-white page ground */
  --surface: #ffffff;      /* card surface */
  --surface-2: #efedf8;    /* secondary surface */
  --border: #e2def0;       /* hairline */
  --ink: #241f33;
  --muted: #6f6885;
  --faint: #9a93ad;

  --accent: #e2570e;       /* mango orange */
  --accent-2: #c74a0b;     /* darker mango (gradients) */
  --accent-ink: #ffffff;   /* text on accent fills */

  --teal: #0a9d90;
  --grape: #6b4de6;
  --good: #0a9d90;         /* success / money / good = teal */
  --danger: #d64545;
  --gold: #e0a400;
  --chip-ink: #14100c;

  --glass: rgba(255, 255, 255, 0.82);
  --shadow: 0 6px 20px rgba(36, 31, 51, 0.08);
  --shadow-lg: 0 14px 40px rgba(36, 31, 51, 0.16);

  /* chart palette (resolved by chart.js at render time) */
  --chart-grid: #e9e5f5;
  --chart-axis: #a89fc0;
  --chart-trend: #e2570e;
  --chart-dot: #0a9d90;
  --chart-dot-soft: #8fd7d0;
  --chart-stem: #bfe0dc;
  --chart-area: #e2570e;
  --chart-goal: #6b4de6;
  --chart-band-loss: rgba(10, 157, 144, 0.34);
  --chart-band-gain: rgba(214, 69, 69, 0.30);
  --chart-marker-ring: #ffffff;
  --tip-bg: #241f33;
  --tip-ink: #ffffff;
  --tip-sub: #0a9d90;
  --tip-date: #c9c2da;

  --radius: 15px;
  --radius-sm: 12px;

  --grad-hero: linear-gradient(135deg, var(--accent) 0%, var(--gold) 100%);
  --grad-streak: linear-gradient(135deg, var(--grape) 0%, var(--accent) 100%);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --nav-h: 64px;

  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", "Nunito", system-ui, -apple-system, Roboto, sans-serif;
}

:root[data-theme="dark"] {
  /* Popsicle Dark */
  --bg: #191625;
  --surface: #241f33;
  --surface-2: #2e2840;
  --border: #3b3352;
  --ink: #f2eef9;
  --muted: #a69dba;
  --faint: #7e7594;

  --accent: #ff8a3d;       /* warm coral-orange */
  --accent-2: #ff7a24;
  --accent-ink: #2a1206;   /* near-black text on accent fills */

  --teal: #2fd4c4;
  --grape: #ab8dff;
  --good: #2fd4c4;
  --danger: #ff6b78;
  --gold: #e0b24d;
  --chip-ink: #ffffff;

  --glass: rgba(25, 22, 37, 0.82);
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.5);

  --chart-grid: #332c47;
  --chart-axis: #6b6383;
  --chart-trend: #ff8a3d;
  --chart-dot: #2fd4c4;
  --chart-dot-soft: #2a7a73;
  --chart-stem: #356b66;
  --chart-area: #ff8a3d;
  --chart-goal: #ab8dff;
  --chart-band-loss: rgba(47, 212, 196, 0.30);
  --chart-band-gain: rgba(255, 107, 120, 0.30);
  --chart-marker-ring: #241f33;
  --tip-bg: #0f0d18;
  --tip-ink: #f2eef9;
  --tip-sub: #2fd4c4;
  --tip-date: #a69dba;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  min-height: 100vh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  font-family: inherit;
}
/* tabular figures for all the number-heavy readouts */
.hero-weight, .hero-stat .v, .stat-pill .value, .tile .v, .gauge-value,
.progress-row .v, .pred-w, .pred-d, .bmi-num, .streak-big, .streak-row .v,
.log-date, .log-rec, .log-avg, .rate-chip, .status-line b { font-variant-numeric: tabular-nums; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }

.hidden { display: none !important; }

/* ===== App layout ===== */
/* Fill the full window width (§3) — no stranded fixed-width column. Side padding
   grows to clear the notch/rounded corners in landscape (safe-area insets). */
#app {
  width: 100%;
  margin: 0 auto;
  padding:
    calc(var(--safe-top) + 8px)
    max(16px, var(--safe-right))
    calc(var(--nav-h) + var(--safe-bottom) + 24px)
    max(16px, var(--safe-left));
}

/* Flow the cards into as many space-filling columns as the viewport allows
   (masonry-like, no dead margin), collapsing to a single full-width column on
   phones. column-width self-adjusts: 1 col on iPhone, more as it gets wider. */
#view[data-tab="summary"],
#view[data-tab="logbook"],
#view[data-tab="awards"],
#view[data-tab="settings"],
#view[data-tab="reports"] #reportBody {
  column-width: 340px;
  column-gap: 16px;
}
/* Never let a card, month block, or settings group split across a column break. */
#view .card,
#view .month-group,
#view .settings-group { break-inside: avoid; }
/* The reports mode-toggle spans the full width above the report columns. */
#view[data-tab="reports"] > .card:first-child { column-span: all; }

/* ===== Header ===== */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 14px;
}
.app-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 26px; font-weight: 800; letter-spacing: -0.5px;
}
.app-title .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad-hero);
  display: grid; place-items: center; box-shadow: var(--shadow);
  font-size: 19px;
}
.header-actions { display: flex; gap: 5px; align-items: center; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 20px;
  transition: transform .12s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.primary { background: var(--accent); color: var(--accent-ink); }

/* ===== Theme toggle (L / D / A) ===== */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px;
}
.theme-toggle button {
  min-width: 32px; height: 40px; border-radius: 999px;
  font-size: 13px; font-weight: 800; color: var(--muted);
  display: grid; place-items: center; transition: background .15s, color .15s, transform .08s;
}
.theme-toggle button.active { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.theme-toggle button:active { transform: scale(0.9); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 18px;
  margin-bottom: 16px;
}
.card-title {
  text-align: center; font-size: 14px; font-weight: 800;
  letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--teal); margin: 2px 0 14px;
}
.card-title.left { text-align: left; }

/* ===== Insight card ===== */
.insight-card {
  position: relative;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--surface));
}
.insight-refresh {
  position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent);
  font-size: 15px; display: grid; place-items: center; transition: transform .3s ease;
}
.insight-refresh:active { transform: rotate(180deg) scale(0.9); }
.insight-body { text-align: center; padding: 2px 4px 4px; }
.insight-headline { font-size: 19px; font-weight: 800; color: var(--accent); letter-spacing: -0.3px; }
.insight-msg { font-size: 15px; line-height: 1.55; color: var(--ink); margin-top: 8px; }
.insight-loading { font-size: 15px; color: var(--faint); font-weight: 600; padding: 6px 0; }

/* ===== Status section ===== */
.status-block { padding: 4px 18px 10px; }
.status-line { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.status-line:last-child { border-bottom: none; }
.status-line span { color: var(--muted); }
.status-subhead { padding: 12px 18px 4px; font-size: 11px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; color: var(--faint); }
.status-api { display: flex; gap: 12px; align-items: flex-start; padding: 10px 18px; border-top: 1px solid var(--border); }
.s-api-ico { font-size: 20px; line-height: 1.2; flex: 0 0 auto; }
.s-api-name { font-weight: 700; font-size: 13.5px; }
.s-api-name a { color: var(--teal); text-decoration: none; font-weight: 700; }
.s-api-detail { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

/* ===== Backups list ===== */
.backup-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.backup-row:last-child { border-bottom: none; }
.backup-when { font-weight: 700; font-size: 14px; }
.backup-size { font-size: 11px; color: var(--faint); font-weight: 600; margin-top: 2px; }
.backup-actions { display: flex; gap: 8px; }
.mini-btn { padding: 8px 12px; border-radius: 10px; background: var(--surface-2); color: var(--ink); font-weight: 700; font-size: 13px; }
.mini-btn:active { transform: scale(0.95); }

/* ===== Hero (current weight) ===== */
.hero { text-align: center; background: var(--grad-hero); color: var(--accent-ink); border: none; }
.hero .card-title { color: var(--accent-ink); opacity: 0.9; }
.hero-weight { font-size: 64px; font-weight: 800; line-height: 1; letter-spacing: -2px; }
.hero-weight .unit { font-size: 22px; font-weight: 700; opacity: .85; margin-left: 6px; }
.hero-sub { margin-top: 8px; font-size: 15px; font-weight: 600; opacity: .95; }
.hero-row { display: flex; justify-content: center; gap: 22px; margin-top: 16px; }
.hero-stat { text-align: center; }
.hero-stat .v { font-size: 20px; font-weight: 800; }
.hero-stat .l { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; opacity: .85; }

/* ===== Stat pills (High/Trend/Low) ===== */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-pill { border-radius: var(--radius-sm); padding: 12px 10px; text-align: center; }
.stat-pill .label { font-size: 11px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; }
.stat-pill .value { font-size: 26px; font-weight: 800; margin: 3px 0; }
.stat-pill .ago { font-size: 11px; font-weight: 600; opacity: .8; }
.stat-pill.high { background: color-mix(in srgb, var(--grape) 16%, var(--surface)); color: var(--grape); }
.stat-pill.trend { background: color-mix(in srgb, var(--teal) 16%, var(--surface)); color: var(--teal); }
.stat-pill.low { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }

/* ===== Trend tiles ===== */
.trend-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { border-radius: var(--radius-sm); padding: 12px 6px; text-align: center; }
.tile .v { font-size: 22px; font-weight: 800; }
.tile .l { font-size: 10px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; margin-top: 4px; line-height: 1.3; }
.tile.gain { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); }
.tile.loss { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }
.tile.flat { background: var(--surface-2); color: var(--muted); }

/* ===== Personal Records ===== */
.record-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.record-tile { border-radius: var(--radius-sm); padding: 12px 5px; text-align: center; }
.record-ico { font-size: 17px; line-height: 1; }
.record-value { font-size: 19px; font-weight: 800; margin-top: 4px; }
.record-label { font-size: 9px; font-weight: 800; letter-spacing: .2px; text-transform: uppercase; margin-top: 3px; line-height: 1.25; opacity: .85; }
.record-sub { font-size: 9px; font-weight: 600; margin-top: 2px; opacity: .75; }
.record-tile.low { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }
.record-tile.high { background: color-mix(in srgb, var(--grape) 16%, var(--surface)); color: var(--grape); }
.record-tile.streak { background: color-mix(in srgb, var(--gold) 20%, var(--surface)); color: var(--gold); }
.record-tile.week { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }

/* ===== Progress gauge ===== */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; }
.gauge { position: relative; width: 240px; max-width: 80%; }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: 18%; }
.gauge-label { font-size: 13px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.gauge-value { font-size: 46px; font-weight: 800; letter-spacing: -1px; }
.progress-row { display: flex; justify-content: space-between; width: 100%; margin-top: 6px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--surface)); border-radius: var(--radius-sm); padding: 10px 6px; }
.progress-row .col { flex: 1; text-align: center; }
.progress-row .v { font-size: 17px; font-weight: 800; }
.progress-row .l { font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--faint); }
.milestone-track { display: flex; align-items: center; gap: 6px; margin: 14px 0 6px; width: 100%; }
.milestone-track .dot { flex: 1; height: 4px; border-radius: 4px; background: var(--border); position: relative; }
.milestone-track .dot::after { content: ""; position: absolute; right: -4px; top: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.milestone-track .dot.done { background: var(--accent); }
.milestone-track .dot.done::after { background: var(--accent); }
.milestone-caption { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; }

/* ===== BMI ===== */
.bmi-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.bmi-gauge { flex: 0 0 150px; text-align: center; }
.bmi-num { font-size: 30px; font-weight: 800; }
.bmi-cat { font-size: 13px; font-weight: 700; color: var(--muted); }
.bmi-table { flex: 1; min-width: 180px; }
.bmi-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.bmi-row:last-child { border-bottom: none; }
.bmi-row .cat { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.bmi-row .sw { width: 14px; height: 14px; border-radius: 4px; }
.bmi-row .range { color: var(--muted); font-weight: 600; }

/* ===== Last 30 Days calendar ===== */
.cal-dow-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.cal-dow { text-align: center; font-size: 10px; font-weight: 800; letter-spacing: .3px; text-transform: uppercase; color: var(--faint); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  aspect-ratio: 1 / 1; border-radius: 9px; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2px; overflow: hidden;
}
.cal-cell.empty { background: transparent; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day-num { font-size: 9.5px; font-weight: 700; color: var(--faint); line-height: 1; }
.cal-weight { font-size: 10.5px; font-weight: 800; line-height: 1.3; margin-top: 1px; white-space: nowrap; color: var(--ink); }
.cal-cell.loss { background: color-mix(in srgb, var(--good) 22%, var(--surface)); }
.cal-cell.loss .cal-weight { color: var(--good); }
.cal-cell.gain { background: color-mix(in srgb, var(--danger) 22%, var(--surface)); }
.cal-cell.gain .cal-weight { color: var(--danger); }
.cal-cell.flat .cal-weight { color: var(--muted); }
.cal-legend { display: flex; justify-content: center; gap: 16px; margin-top: 12px; font-size: 11px; font-weight: 700; color: var(--muted); }
.cal-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.cal-legend .dot.loss { background: var(--good); }
.cal-legend .dot.gain { background: var(--danger); }
.cal-legend .dot.flat { background: var(--border); }

/* ===== How You Compare (age profile) ===== */
.context-empty { text-align: center; font-size: 14px; color: var(--muted); line-height: 1.5; padding: 6px 4px; }
.compare-row { display: flex; align-items: stretch; gap: 10px; }
.compare-pill { flex: 1; border-radius: var(--radius-sm); padding: 14px 10px; text-align: center; }
.compare-pill.you { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.compare-pill.avg { background: var(--surface-2); }
.cp-label { font-size: 10.5px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); }
.cp-value { font-size: 23px; font-weight: 800; margin-top: 4px; }
.cp-value .cp-unit { font-size: 12.5px; font-weight: 700; margin-left: 3px; color: var(--muted); }
.cp-sub { font-size: 11.5px; font-weight: 700; color: var(--muted); margin-top: 3px; }
.compare-vs { align-self: center; font-size: 12px; font-weight: 800; color: var(--faint); }
.context-note { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin-top: 12px; text-align: center; }

/* ===== Predictions ===== */
.pred-toggle { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 14px; }
.pred-toggle button { flex: 1; padding: 9px 4px; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--muted); }
.pred-toggle button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.pred-toggle .rate { display: block; font-size: 16px; font-weight: 800; color: var(--ink); }
.pred-intro { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.pred-row { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--border); }
.pred-row:last-child { border-bottom: none; }
.pred-w { font-size: 17px; font-weight: 800; }
.pred-w small { display: block; font-size: 11px; color: var(--faint); font-weight: 600; }
.pred-d { text-align: right; font-weight: 700; }
.pred-d small { display: block; font-size: 11px; color: var(--faint); font-weight: 600; }

/* ===== Chart ===== */
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.chart-svg { width: 100%; display: block; touch-action: pan-y; }
.range-tabs { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.range-tabs button {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.range-tabs button.active { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }

/* ===== Seasonal Pattern (diverging bar chart) ===== */
.season-zero { stroke: var(--border); stroke-width: 1.5; }
.season-bar.pos { fill: var(--danger); }
.season-bar.neg { fill: var(--good); }
.season-bar.flat { fill: var(--border); }
.season-label { fill: var(--faint); }
.season-callout.pos { fill: var(--danger); }
.season-callout.neg { fill: var(--good); }
.seasonal-note { text-align: center; font-size: 13px; color: var(--muted); margin-top: 14px; line-height: 1.55; }

/* ===== Weigh-In Frequency (by day of week) ===== */
.wd-freq-chart { display: flex; align-items: flex-end; gap: 6px; }
.wd-freq-col { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.wd-freq-value { font-size: 11px; font-weight: 800; color: var(--ink); margin-bottom: 4px; }
.wd-freq-track { width: 100%; height: 90px; background: var(--surface-2); border-radius: 7px; display: flex; align-items: flex-end; overflow: hidden; }
.wd-freq-bar { width: 100%; background: var(--accent); border-radius: 7px 7px 0 0; min-height: 3px; }
.wd-freq-day { font-size: 10px; font-weight: 700; color: var(--faint); margin-top: 6px; text-transform: uppercase; letter-spacing: .3px; }

/* ===== Pace Over Time ===== */
.pace-area.pos { fill: color-mix(in srgb, var(--good) 22%, transparent); }
.pace-area.neg { fill: color-mix(in srgb, var(--danger) 22%, transparent); }
.pace-line.pos { stroke: var(--good); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.pace-line.neg { stroke: var(--danger); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.pace-dot { stroke: var(--surface); stroke-width: 2; }
.pace-dot.pos { fill: var(--good); }
.pace-dot.neg { fill: var(--danger); }
.pace-target { stroke: var(--grape); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: .8; }
.pace-target-label { fill: var(--grape); }

/* ===== Logbook ===== */
.month-group { margin-bottom: 16px; }
.month-head { text-align: center; font-size: 15px; font-weight: 800; letter-spacing: .5px; color: var(--teal); margin-bottom: 8px; }
.log-head, .log-row { display: grid; grid-template-columns: 56px 1fr 1fr 64px 28px; align-items: center; gap: 6px; }
.log-head { padding: 0 4px 6px; font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .3px; }
.log-head span:nth-child(n+2) { text-align: center; }
.log-row { padding: 10px 4px; border-bottom: 1px solid var(--border); }
.log-row:active { background: var(--surface-2); border-radius: 10px; }
.log-date { font-weight: 800; font-size: 16px; }
.log-date small { display: block; font-size: 11px; color: var(--faint); font-weight: 600; }
.log-rec, .log-avg { text-align: center; font-weight: 700; font-size: 15px; }
.log-avg { color: var(--muted); font-weight: 600; }
.rate-chip { justify-self: center; font-weight: 800; font-size: 13px; padding: 5px 8px; border-radius: 9px; min-width: 50px; text-align: center; }
.rate-chip.down { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }
.rate-chip.up { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); }
.rate-chip.none { background: transparent; }
.note-dot { justify-self: center; font-size: 15px; color: var(--teal); }
.milestone-banner {
  background: color-mix(in srgb, var(--teal) 18%, var(--surface)); color: var(--teal); text-align: center;
  font-weight: 700; font-size: 13px; padding: 8px; border-radius: var(--radius-sm); margin: 6px 0 10px;
}
.milestone-banner.start { background: color-mix(in srgb, var(--grape) 18%, var(--surface)); color: var(--grape); }

/* ===== Settings ===== */
.settings-group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; margin-bottom: 16px; }
.settings-row { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: none; }
.settings-row .s-icon { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; color: #fff; flex: 0 0 auto; }
.settings-row .s-label { flex: 1; font-weight: 600; }
.settings-row .s-value { color: var(--muted); font-weight: 600; }
.settings-row .s-chevron { color: var(--faint); }
.settings-row.tappable:active { background: var(--surface-2); }
.s-icon.c1 { background: var(--accent); } .s-icon.c2 { background: var(--teal); }
.s-icon.c3 { background: var(--danger); } .s-icon.c4 { background: var(--good); }
.s-icon.c5 { background: var(--grape); } .s-icon.c6 { background: var(--gold); }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + var(--safe-bottom));
  /* clear the home indicator (bottom) and, in landscape, the notch side (left/right) */
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; color: var(--faint); font-size: 10.5px; font-weight: 700; }
.nav-btn .ico { font-size: 21px; transition: transform .15s ease; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active .ico { transform: translateY(-2px) scale(1.1); }

/* ===== Streak card ===== */
.streak-card { text-align: center; background: var(--grad-streak); color: var(--accent-ink); border: none; }
.streak-flame { font-size: 40px; line-height: 1; }
.streak-big { font-size: 52px; font-weight: 800; letter-spacing: -2px; line-height: 1.05; margin-top: 4px; }
.streak-big .streak-unit { font-size: 22px; font-weight: 700; opacity: .9; letter-spacing: 0; }
.streak-sub { font-size: 14px; font-weight: 600; opacity: .95; margin-top: 4px; }
.streak-row { display: flex; justify-content: space-around; margin-top: 16px; background: rgba(255,255,255,0.18); border-radius: var(--radius-sm); padding: 12px 6px; }
.streak-row .col { flex: 1; }
.streak-row .v { font-size: 22px; font-weight: 800; }
.streak-row .l { font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; opacity: .9; margin-top: 2px; }

/* ===== Badge grid ===== */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { border-radius: var(--radius-sm); padding: 14px 8px; text-align: center; background: color-mix(in srgb, var(--accent) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--surface)); transition: transform .12s ease; }
.badge.earned:active { transform: scale(0.96); }
.badge.locked { background: var(--surface-2); border-color: var(--border); }
.badge.locked .badge-ico { filter: grayscale(1); opacity: .45; }
.badge.locked .badge-title, .badge.locked .badge-desc { opacity: .55; }
.badge-ico { font-size: 30px; line-height: 1; }
.badge-title { font-size: 13px; font-weight: 800; margin-top: 6px; color: var(--ink); }
.badge-desc { font-size: 10.5px; color: var(--muted); margin-top: 3px; line-height: 1.3; min-height: 26px; }
.badge-date { font-size: 10px; font-weight: 700; margin-top: 6px; color: var(--good); }
.badge.locked .badge-date { color: var(--faint); }
.badge.earned .badge-ico { animation: pop .4s ease; }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* ===== Achievement unlock overlay ===== */
.achv-overlay { position: fixed; inset: 0; z-index: 95; background: rgba(15,10,25,0.55); display: grid; place-items: center; padding: 24px; opacity: 0; transition: opacity .25s ease; }
.achv-overlay.open { opacity: 1; }
.achv-pop { background: var(--surface); border-radius: 22px; padding: 28px 24px; max-width: 340px; width: 100%; text-align: center; box-shadow: var(--shadow-lg); border: 1px solid var(--border); transform: scale(0.8); transition: transform .3s cubic-bezier(.2,1.4,.5,1); }
.achv-overlay.open .achv-pop { transform: scale(1); }
.achv-banner { font-size: 12px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; color: var(--accent); }
.achv-ico { font-size: 72px; line-height: 1; margin: 14px 0 6px; animation: pop .5s ease; }
.achv-title { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.achv-desc { font-size: 15px; color: var(--muted); margin: 8px 0 18px; line-height: 1.5; }

/* ===== Modal / sheet ===== */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,10,25,0.45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(22px + var(--safe-bottom));
  box-shadow: var(--shadow-lg); transform: translateY(20px); transition: transform .25s ease;
  max-height: 92vh; overflow-y: auto;
}
@supports (max-height: 92dvh) {
  /* dvh tracks the actual visible viewport on iPadOS/iOS Safari 15.4+, so the
     sheet (and its pinned action bar) correctly shrink above the on-screen
     keyboard instead of being sized against the full, keyboard-ignoring vh. */
  .sheet { max-height: 92dvh; }
}
.sheet-backdrop.open .sheet { transform: translateY(0); }

/* Opt-in layout for a sheet with a pinned action bar (e.g. the entry sheet's
   Save button). Deliberately NOT position:sticky + negative margins — that
   combination rendered fine in desktop testing but is a known WebKit bug
   pattern on real iPadOS Safari (the sticky element ends up mispositioned,
   overlapping earlier content instead of pinning below it). Plain flexbox
   is the robust, cross-engine way to do "scrollable middle + fixed footer
   inside a max-height container": .sheet becomes the column, .sheet-scroll
   is the only part that scrolls, .sheet-actions is a normal flex item that
   just always renders after it — no sticky math involved at all. */
.sheet.pinned-footer { display: flex; flex-direction: column; overflow: hidden; }
.sheet.pinned-footer .sheet-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--border); margin: 6px auto 10px; }
.sheet h2 { text-align: center; font-size: 20px; font-weight: 800; margin: 0 0 14px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-sm); border: 2px solid var(--border);
  font-size: 17px; background: var(--bg); color: var(--ink); outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .big-weight { font-size: 32px; font-weight: 800; text-align: center; letter-spacing: -1px; }
.field .hint { font-size: 12px; color: var(--faint); margin-top: 6px; }
.field.sunday input { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }

/* Always-visible action bar at the end of a .pinned-footer sheet — a normal
   flex item (see .sheet.pinned-footer above), not stickied, so it's simply
   never inside the part of the sheet that scrolls. */
.sheet-actions { flex: 0 0 auto; border-top: 1px solid var(--border); padding-top: 12px; margin-top: 10px; }
.sheet-actions .btn:first-child { margin-top: 0; }

/* snap-the-scale photo capture */
.snap-btn { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--accent); box-shadow: none; margin: 0 0 6px; }
.snap-btn:disabled { opacity: .7; }
.snap-msg { text-align: center; font-size: 13px; font-weight: 600; color: var(--muted); min-height: 18px; margin-bottom: 12px; line-height: 1.4; }
.snap-msg.ok { color: var(--good); }
.snap-msg.warn { color: var(--danger); }
.sheet.drag { outline: 2px dashed var(--accent); outline-offset: -10px; }
.sunday-flag { display: inline-flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent); font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 20px; margin-bottom: 12px; }
.btn {
  display: block; width: 100%; padding: 16px; border-radius: var(--radius); font-size: 17px; font-weight: 800;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); margin-top: 6px;
  transition: transform .1s ease;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--surface-2); color: var(--ink); box-shadow: none; }
.btn.danger { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); box-shadow: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }

/* ===== Login / PIN ===== */
.lock-screen {
  position: fixed; inset: 0; z-index: 80; background: var(--grad-hero);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding:
    max(24px, var(--safe-top))
    max(24px, var(--safe-right))
    max(24px, var(--safe-bottom))
    max(24px, var(--safe-left));
  color: var(--accent-ink); text-align: center;
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.lock-logo { width: clamp(56px, 9vh, 90px); height: clamp(56px, 9vh, 90px); border-radius: 22px; background: color-mix(in srgb, var(--accent-ink) 18%, transparent); display: grid; place-items: center; font-size: clamp(30px, 5vh, 50px); margin-bottom: clamp(8px, 2vh, 18px); box-shadow: var(--shadow-lg); }
.lock-title { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.lock-sub { font-size: 15px; opacity: .9; margin: 6px 0 clamp(10px, 2.5vh, 26px); max-width: 280px; }
/* Booting splash: hide the PIN keypad + prompts, show only a spinner, so the
   PIN never flashes while SSO resolves. Revealed by JS only when PIN is needed. */
.lock-spin {
  width: 34px; height: 34px; margin: 24px auto 0; border-radius: 50%;
  border: 3px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor; animation: lock-spin .8s linear infinite;
}
@keyframes lock-spin { to { transform: rotate(360deg); } }
.lock-screen:not(.booting) .lock-spin { display: none; }
.lock-screen.booting #lockSub,
.lock-screen.booting #pinDots,
.lock-screen.booting #keypad,
.lock-screen.booting #lockMsg { display: none; }
.pin-dots { display: flex; gap: 12px; margin-bottom: clamp(12px, 3vh, 30px); height: 18px; max-width: 100%; }
.pin-dots .pd { width: 16px; height: 16px; flex: 0 0 auto; border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 70%, transparent); transition: transform .1s; }
.pin-dots .pd.filled { background: currentColor; transform: scale(1.1); }
.pin-dots.error { animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-8px)} 40%,80%{transform:translateX(8px)} }
.pin-dots.busy .pd.filled { animation: pinpulse .9s ease-in-out infinite; }
@keyframes pinpulse { 50% { opacity: .35; } }
.keypad { display: grid; grid-template-columns: repeat(3, clamp(64px, min(22vw, 10vh), 84px)); gap: clamp(8px, 1.8vh, 16px); touch-action: manipulation; }
.key { aspect-ratio: 1; width: 100%; padding: 0; touch-action: manipulation; border-radius: 50%; background: color-mix(in srgb, var(--accent-ink) 16%, transparent); color: var(--accent-ink); font-size: clamp(26px, 4vh, 32px); font-weight: 600; display: grid; place-items: center; transition: transform .08s, background .1s; }
.key:active { transform: scale(0.92); background: color-mix(in srgb, var(--accent-ink) 30%, transparent); }
.key.blank { background: transparent; }
.key.action { font-size: 24px; font-weight: 700; background: transparent; }
.key:disabled { opacity: .5; }
.lock-msg { min-height: 22px; margin-top: clamp(8px, 2vh, 18px); font-weight: 700; font-size: 16px; max-width: 320px; }

/* ===== Chart expand overlay ===== */
/* Full-screen, not a bottom sheet — a chart benefits from all available space.
   Always has a visible, reachable close control (top-right, fixed in the
   header) so this is never a view you can get stuck in. */
.chart-modal-backdrop {
  position: fixed; inset: 0; z-index: 65; background: var(--bg);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.chart-modal-backdrop.open { opacity: 1; pointer-events: auto; }
.chart-modal {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 14px) max(16px, var(--safe-right)) calc(16px + var(--safe-bottom)) max(16px, var(--safe-left));
}
.chart-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; margin-bottom: 18px; }
.chart-modal-title { font-size: 19px; font-weight: 800; letter-spacing: -.3px; }
.chart-modal-close {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  background: var(--surface-2); color: var(--ink); display: grid; place-items: center; font-size: 16px;
}
.chart-modal-close:active { transform: scale(0.92); }
.chart-modal-body { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; min-height: 0; }
.chart-modal-body .card { box-shadow: none; margin-bottom: 0; }
/* Bar charts (Weigh-In Frequency, Weight Ranges) use a fixed-height CSS track
   rather than an SVG viewBox, so they need an explicit larger height inside
   the modal — otherwise the same 90px-tall bars would just sit lost in the
   middle of a full-screen view instead of actually looking "expanded". */
.chart-modal-body .wd-freq-track { height: 46vh; max-height: 320px; }

/* A small, explicit expand button on every chart card — deliberately NOT a
   tap-anywhere-on-the-chart handler, since the main Weight Chart already uses
   taps for its scrubber and that would fight this on every scrub attempt. */
.chart-card { position: relative; }
.chart-expand-btn {
  position: absolute; top: 14px; right: 14px; z-index: 1;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); font-size: 13px;
  display: grid; place-items: center;
}
.chart-expand-btn:active { transform: scale(0.9); }

/* ===== misc ===== */
.empty { text-align: center; color: var(--faint); padding: 40px 20px; }
.empty .big { font-size: 44px; margin-bottom: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 30px; font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100;
  max-width: calc(100vw - 28px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

/* iPhone: compact density so the Weight Chart lands on the first screen (§3).
   Header top keeps 10px clear for the version badge (safe-top + 3px, 9px tall). */
@media (max-width: 599px) {
  :root, :root[data-theme] { --nav-h: 58px; }
  #app { padding-top: calc(var(--safe-top) + 12px); }
  .app-header { padding: 0 2px 8px; }
  .app-title { font-size: 23px; gap: 8px; }
  .app-title .logo { width: 30px; height: 30px; font-size: 17px; }
  .theme-toggle button { min-width: 30px; }

  .card { padding: 14px; margin-bottom: 12px; }
  #view[data-tab] { column-gap: 12px; }
  .card-title { font-size: 12.5px; letter-spacing: 1.2px; margin: 0 0 10px; }

  .hero .card-title { margin-bottom: 4px; }
  .hero { padding-top: 12px; padding-bottom: 12px; }
  .hero-weight { font-size: 52px; }
  .hero-weight .unit { font-size: 19px; }
  .hero-sub { margin-top: 3px; font-size: 14px; }
  .hero-row { margin-top: 8px; gap: 26px; }
  .hero-stat .v { font-size: 18px; }
  .hero-stat .l { font-size: 10px; }

  /* the tinted card + orange headline already say "insight"; drop the title row */
  .insight-card > .card-title { display: none; }
  .insight-refresh { top: 10px; right: 10px; width: 30px; height: 30px; font-size: 13px; }
  .insight-body { text-align: left; padding: 0 2px; }
  .insight-headline { font-size: 17px; padding-right: 34px; }
  .insight-msg { font-size: 14px; line-height: 1.45; margin-top: 4px; }
  /* 3 lines by default; tapping the card toggles the full text */
  .insight-card:not(.expanded) .insight-msg {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
  }
  .insight-card { cursor: pointer; }
  .insight-loading { font-size: 14px; }

  .chart-expand-btn { top: 10px; right: 10px; }
  .chart-card .stat-cards { gap: 8px; margin: 6px 0 8px !important; }
  .stat-pill { padding: 6px 6px 7px; }
  .stat-pill .label { font-size: 10px; }
  .stat-pill .value { font-size: 21px; margin: 1px 0; }
  .stat-pill .ago { font-size: 10px; }
  .range-tabs button { padding: 5px 13px; font-size: 12.5px; }
  /* main chart: range tabs take the title row's place (the chart explains itself;
     the expanded view still carries the "Weight Chart" title) */
  .chart-card:has(#mainChart) { display: flex; flex-direction: column; }
  .chart-card:has(#mainChart) > .chart-head { display: none; }
  .chart-card:has(#mainChart) > .range-tabs { order: -1; margin: 0 36px 0; min-height: 30px; align-items: center; }

  .nav-btn { padding: 5px 0; font-size: 10px; }
  .nav-btn .ico { font-size: 20px; }
}
@media (max-width: 389px) {
  .range-tabs { gap: 4px; }
  .range-tabs button { padding: 5px 9px; }
}

/* tablet / desktop niceties */
@media (min-width: 600px) {
  .hero-weight { font-size: 72px; }
}
@media (min-width: 760px) {
  /* more breathing room on big screens, but never less than the safe-area inset
     (iPhone landscape is ~850px wide, so this rule applies there too). */
  #app {
    padding-left: max(24px, var(--safe-left));
    padding-right: max(24px, var(--safe-right));
  }
}

/* ===== Version badge (index.html, filled from /version.js) =====
   Top-left, inside the notch (safe-top), in the 16px above the header row, so it clears the
   title and the L/D/A toggle + buttons on the right. Tiny on purpose. Measured, not eyeballed:
   --muted is 4.85:1 on the light page (#f6f5fa), 6.89:1 on the dark page (#191625).
   Failure red: --danger is only 4.04:1 on light, so light uses #ab3737 (5.81:1); dark --danger
   is 6.45:1. z-index 85 is above the lock/splash (80), full-screen chart view (65) and sheets
   (60); it stays under the brief confetti (90), award pop (95) and toast (100). */
.app-version {
  position: fixed; z-index: 85; pointer-events: none;
  top: calc(var(--safe-top) + 3px);
  left: max(20px, calc(var(--safe-left) + 4px));
  font: 500 9px/9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .2px; color: var(--muted); white-space: nowrap;
}
.app-version.fail { color: #ab3737; font-weight: 700; }
:root[data-theme="dark"] .app-version.fail { color: var(--danger); }
/* An open sheet dims the page (light: #8e8b94 behind the badge), where muted drops below 4.5,
   so the badge takes --ink there: 4.75:1 (dark: muted on the dimmed #12101b is 7.31:1). */
:root:not([data-theme="dark"]) body:has(#sheetBackdrop.open) .app-version:not(.fail) { color: var(--ink); }
/* The lock/boot splash paints the mango-to-gold gradient, where page ink would vanish.
   Near-black #2a1206 (the dark theme's accent-ink) is 4.72:1 on light #e2570e (rising toward
   the gold end) and 7.54:1 / 8.96:1 on the dark #ff8a3d / #e0b24d. The splash is also what stays
   up when app.js fails, so the failure text keeps this readable color there, bold, and the
   words "app.js failed" carry the meaning. */
body:has(#lock:not(.hidden)) .app-version { color: #2a1206; }
