/* Layout: one phone-width column — weight card up top, sleep and meds below, save bar pinned to the bottom edge. */
:root {
  --bg: #EEF2F0;
  --surface: #FFFFFF;
  --ink: #14201D;
  --muted: #5B6A65;
  --line: #D3DCD8;
  --accent: #0E7A6A;
  --accent-ink: #FFFFFF;
  --accent-soft: #D4ECE6;
  --gold: #B97C05;
  --gold-soft: #FBF0D2;
  --spark: #E2674A;
  --good: #0E7A6A;
  --bad: #B4412F;
  --dot: #8FA8A1;

  --font-ui: "IBM Plex Sans", Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D1412; --surface: #152019; --ink: #E3ECE9; --muted: #93A39E; --line: #26342F;
    --accent: #3BBFA9; --accent-ink: #062621; --accent-soft: #163731;
    --gold: #F0B63E; --gold-soft: #3A2D0F; --spark: #F08A6E;
    --good: #3BBFA9; --bad: #F08A73; --dot: #5E7770;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D1412; --surface: #152019; --ink: #E3ECE9; --muted: #93A39E; --line: #26342F;
  --accent: #3BBFA9; --accent-ink: #062621; --accent-soft: #163731;
  --gold: #F0B63E; --gold-soft: #3A2D0F; --spark: #F08A6E;
  --good: #3BBFA9; --bad: #F08A73; --dot: #5E7770;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.num, input#weightInput { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px 112px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
main { display: flex; flex-direction: column; gap: 28px; }

/* ---- Header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.eyebrow {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
h2 { margin: 0; font-size: 18px; font-weight: 650; }
h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

.icon-btn {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 50%;
}
.icon-btn svg { width: 22px; height: 22px; }
.ico { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#soundBtn .mute { display: none; }
#soundBtn[aria-pressed="false"] .wave { display: none; }
#soundBtn[aria-pressed="false"] .mute { display: inline; }

/* ---- Banners */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  font-size: 14px;
}
.banner p { margin: 0; min-width: 0; }
.banner.error { background: var(--gold-soft); }

/* ---- Weight card (the one framed object on the page) */
.weigh {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 16px 14px;
  display: flex; flex-direction: column; gap: 14px;
  position: relative;
  overflow: hidden;
}
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chip {
  font-size: 13px; font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
}
.chip.done { background: var(--accent-soft); color: var(--ink); }

.weigh-input { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 8px; }
.step {
  height: 56px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 28px; line-height: 1; font-weight: 500;
  touch-action: manipulation;
}
.step:active { background: var(--accent-soft); }
.num-wrap { display: flex; align-items: baseline; justify-content: center; gap: 6px; min-width: 0; }
#weightInput {
  width: 100%;
  min-width: 0;
  max-width: 6.2ch;
  border: none;
  border-bottom: 2px solid var(--line);
  background: transparent;
  font-size: 48px; font-weight: 500;
  letter-spacing: -.02em;
  text-align: center;
  padding: 0 0 2px;
  border-radius: 0;
}
#weightInput:focus { outline: none; border-bottom-color: var(--accent); }
#weightInput::placeholder { color: var(--line); }
.unit { font-size: 18px; color: var(--muted); font-weight: 500; }
.field-error { margin: -4px 0 0; color: var(--bad); font-size: 14px; text-align: center; }

.stats {
  margin: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stats > div { padding: 10px 0 10px 12px; min-width: 0; }
.stats > div:first-child { padding-left: 0; }
.stats > div + div { border-left: 1px solid var(--line); }
.stats dt { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 0; }
.stats .num { font-size: 20px; font-weight: 500; margin-top: 2px; }
.stats .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub.good { color: var(--good); }
.sub.bad { color: var(--bad); }

.chart-head { margin-top: 2px; }
.chart { width: 100%; min-height: 180px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-empty { margin: 0; padding: 40px 12px; text-align: center; color: var(--muted); font-size: 14px; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-tick { fill: var(--muted); font-family: var(--font-num); font-size: 11px; }
.c-area { fill: var(--accent-soft); opacity: .7; }
.c-avg { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--dot); }
.c-today { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.c-low { fill: none; stroke: var(--gold); stroke-width: 2; }
.c-low-label { fill: var(--gold); font-family: var(--font-num); font-size: 11.5px; font-weight: 700; }

.legend { margin: -4px 0 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; flex: none; }
.key-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot); }
.key-line { width: 16px; height: 3px; border-radius: 2px; background: var(--accent); }
.key-low { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--gold); }

/* ---- Segmented controls */
.seg { display: flex; gap: 4px; padding: 3px; background: var(--bg); border-radius: var(--r-md); border: 1px solid var(--line); }
.seg > button, .seg.radios > label {
  flex: 1;
  min-height: 42px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-weight: 500;
  display: grid; place-items: center;
  padding: 0 10px;
  cursor: pointer;
  text-align: center;
}
.seg > button[aria-pressed="true"], .seg > button[aria-checked="true"], .seg.radios > input:checked + label {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
  font-weight: 600;
}
.seg.small { padding: 2px; }
.seg.small > button { min-height: 32px; font-size: 13px; padding: 0 10px; }
.seg.radios > input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg.radios > input:focus-visible + label { outline: 2.5px solid var(--accent); outline-offset: 1px; }

/* ---- Sleep */
.block { display: flex; flex-direction: column; gap: 12px; }
.watch {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 12px;
}
.watch p { margin: 0; }
.watch p + p { margin-top: 2px; }
.watch-kicker { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.watch-main { font-size: 22px; font-weight: 600; }
.watch-main .num { font-weight: 500; }
.watch-sub { font-size: 14px; color: var(--muted); }
.watch-none { font-size: 15px; color: var(--muted); }
.q { margin: 6px 0 0; font-weight: 600; }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale button {
  height: 52px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  font-family: var(--font-num);
  font-size: 20px; font-weight: 500;
  touch-action: manipulation;
}
.scale button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scale-ends { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: -6px; }

/* ---- Meds */
.meds { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.meds-sub { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 8px 0 0; }
.med {
  width: 100%;
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 12px;
  min-height: 56px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: left;
}
.med .box {
  width: 26px; height: 26px; border-radius: 8px;
  border: 2px solid var(--line);
  display: grid; place-items: center;
}
.med .box svg { width: 16px; height: 16px; opacity: 0; }
.med .box path { fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.med[aria-checked="true"] .box { background: var(--accent); border-color: var(--accent); }
.med[aria-checked="true"] .box svg { opacity: 1; }
.med-text { min-width: 0; }
.med-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.med-dose { display: block; font-size: 14px; color: var(--muted); }
.med-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.med[aria-checked="true"] .med-state { color: var(--good); font-weight: 600; }
.empty { margin: 0; color: var(--muted); font-size: 15px; }

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px; font-weight: 600;
  min-height: 36px;
}

/* ---- Save bar */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding-top: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.primary {
  display: block; width: 100%; max-width: 528px; margin: 0 auto;
  min-height: 52px;
  border: none;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px; font-weight: 650;
}
.primary:disabled { opacity: .6; cursor: progress; }
.primary:active { filter: brightness(.94); }

/* ---- Celebration */
.celebrate {
  margin: -18px -16px 0;
  padding: 16px 16px 14px;
  background: var(--gold-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  text-align: center;
}
.celebrate p { margin: 0; }
.celebrate p + p { margin-top: 4px; }
.celebrate-kicker { font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.celebrate-main { font-family: var(--font-num); font-size: 40px; font-weight: 700; line-height: 1.1; color: var(--ink); }
.celebrate-unit { font-size: 18px; color: var(--muted); font-weight: 500; }
.celebrate-sub { font-size: 14.5px; color: var(--ink); text-wrap: balance; }
.celebrate.big { padding-block: 22px 18px; }
.celebrate.big .celebrate-kicker { font-size: 15px; }
.celebrate.pop { animation: pop .55s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop {
  0% { transform: scale(.92); opacity: .4; }
  100% { transform: scale(1); opacity: 1; }
}

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* ---- Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(92vw, 440px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14.5px; font-weight: 500;
  z-index: 30;
  text-align: center;
}

/* ---- Manage sheet */
.sheet {
  width: min(560px, 100%);
  max-width: 100%;
  max-height: 88dvh;
  margin: auto auto 0;
  border: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
  color: var(--ink);
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet[open] { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; overscroll-behavior: contain; }
.sheet[open] > * { flex: none; }
.sheet::backdrop { background: rgba(5, 12, 10, .45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.manage-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.manage-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.manage-list .m-text { min-width: 0; }
.manage-list .m-name { font-weight: 600; overflow-wrap: anywhere; }
.manage-list .m-meta { font-size: 13.5px; color: var(--muted); }
.manage-list .m-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tiny-btn {
  border: 1px solid var(--line); background: var(--bg);
  border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 500; min-height: 32px;
}
.tiny-btn.warn { border-color: var(--bad); color: var(--bad); background: transparent; }

.add-med { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; border: none; padding: 0; min-width: 0; }
.field label, .field legend { font-size: 14px; font-weight: 600; padding: 0; }
.field input:not([type="radio"]) {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  background: var(--bg);
}
.field legend { margin-bottom: 6px; }
.opt { font-weight: 400; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.hint { margin: -4px 0 0; font-size: 13.5px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .celebrate.pop { animation: none; }
}
