:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #17201d;
  --muted: #66716d;
  --line: #e1e6e3;
  --accent: #0e8c7a;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ee;
  --warn: #b26a00;
  --warn-soft: #fff1d9;
  --danger: #c2372f;
  --med: #2f62c9;
  --med-soft: #e5ecfb;
  --supp: #a0620a;
  --supp-soft: #fbefd9;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 10px rgb(0 0 0 / 0.04);
  --radius: 16px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1312;
    --surface: #181e1c;
    --surface-2: #222a27;
    --text: #e8eeeb;
    --muted: #93a09b;
    --line: #2a3330;
    --accent: #3cc3a9;
    --accent-ink: #062a24;
    --accent-soft: #163d36;
    --warn: #f0b056;
    --warn-soft: #3a2b12;
    --danger: #f07a72;
    --med: #8fb0ff;
    --med-soft: #1e2a45;
    --supp: #f0bf6a;
    --supp-soft: #3a2c14;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
body.locked { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 18px 8px; }

.splash { min-height: 100dvh; display: grid; place-items: center; }
.splash img { border-radius: 18px; opacity: 0.9; }

/* ---------- signed out ---------- */
.center-page {
  min-height: 100dvh;
  max-width: 420px;
  margin: 0 auto;
  padding: calc(var(--top) + 32px) 24px calc(var(--bottom) + 32px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.hero-logo {
  width: 88px; height: 88px; border-radius: 24px; display: grid; place-items: center;
  background: linear-gradient(135deg, #14a38b, #0b6f61); color: #fff; margin-bottom: 20px;
  box-shadow: 0 10px 30px rgb(14 140 122 / 0.3);
}
.hero-logo svg { width: 52px; height: 52px; }
.center-page h1 { font-size: 30px; letter-spacing: -0.02em; margin-bottom: 28px; }
.lead { color: var(--muted); font-size: 17px; margin: 10px 0 28px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface-2); color: var(--text); min-height: 44px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 7px 14px; min-height: 36px; font-size: 15px; border-radius: 10px; }
.btn.block { width: 100%; margin-top: 12px; }
.btn.danger { color: var(--danger); }
.btn.google { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); width: 100%; max-width: 320px; padding: 14px 18px; }
.btn.google svg { width: 22px; height: 22px; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 0; font-weight: 500; }
.link.strong { font-weight: 700; }
.icon-btn { background: var(--surface-2); border: 0; width: 40px; height: 40px; border-radius: 10px; font-size: 22px; line-height: 1; color: var(--muted); }

/* ---------- shell ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  max-width: 640px; margin: 0 auto;
}
.top h1 { font-size: 28px; letter-spacing: -0.02em; }
.view { max-width: 640px; margin: 0 auto; padding: 4px 16px calc(var(--bottom) + 96px); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--bottom);
}
.tabs a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabs a svg { width: 25px; height: 25px; }
.tabs a.on { color: var(--accent); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.pad { padding: 16px; }
.card p { margin: 0 0 4px; }
h2.group { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
ul { list-style: none; margin: 0; padding: 0; }

.summary { display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin-top: 4px; }
.summary .date { font-weight: 700; font-size: 17px; }
.ring { width: 64px; height: 64px; flex: none; }
.ring circle { fill: none; stroke-width: 7; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset 0.5s ease; }
.ring text { font-size: 14px; font-weight: 700; fill: var(--text); }

.banner {
  display: block; margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--warn-soft); color: var(--text); text-decoration: none; font-size: 15px;
}
.empty { text-align: center; padding: 40px 16px; }
.empty .btn { margin-top: 12px; }

/* ---------- doses ---------- */
.doses { display: grid; gap: 8px; }
.dose { display: grid; grid-template-columns: 74px 1fr; grid-template-areas: "time main" "actions actions"; gap: 6px 12px; padding: 12px 14px; align-items: center; }
@media (min-width: 480px) { .dose { grid-template-columns: 78px 1fr auto; grid-template-areas: "time main actions"; } }
.dose-time { grid-area: time; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; font-size: 15px; }
.dose-main { grid-area: main; min-width: 0; }
.dose-name { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dose-sub { color: var(--muted); font-size: 14px; }
.dose-actions { grid-area: actions; display: flex; gap: 8px; justify-content: flex-end; }
.dose.taken, .dose.skipped { opacity: 0.72; }
.dose.taken .dose-name { text-decoration: line-through; text-decoration-color: var(--muted); }
.dose.late { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.dose.flash { animation: flash 1.6s ease 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 3px var(--accent); } }

.chip { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; letter-spacing: 0.02em; }
.chip.med { background: var(--med-soft); color: var(--med); }
.chip.supp { background: var(--supp-soft); color: var(--supp); }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.tag.due { background: var(--accent-soft); color: var(--accent); }
.tag.late { background: var(--warn-soft); color: var(--warn); }

.pill { border: 0; border-radius: 99px; padding: 7px 14px; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 5px; min-height: 36px; }
.pill svg { width: 16px; height: 16px; }
.pill.taken { background: var(--accent-soft); color: var(--accent); }
.pill.skipped { background: var(--surface-2); color: var(--muted); }

/* ---------- history ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 14px 4px 10px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.days { display: grid; gap: 8px; }
.day { padding: 12px 14px; }
.day-head { display: flex; justify-content: space-between; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.dot.taken { background: var(--accent); }
.dot.skipped { background: var(--muted); opacity: 0.5; }
.dot.missed { background: transparent; border: 2px solid var(--warn); }
.dot.upcoming { background: var(--surface-2); border: 1px dashed var(--muted); }
.missed { margin-top: 8px; font-size: 13px; color: var(--muted); }

/* ---------- meds list ---------- */
.list { display: grid; gap: 8px; }
.med-card { display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer; }
.med-card .med-main { flex: 1; min-width: 0; }
.med-card.paused { opacity: 0.55; }

.switch { flex: none; width: 51px; height: 31px; border-radius: 99px; border: 0; padding: 2px; background: var(--surface-2); position: relative; transition: background 0.2s; box-shadow: inset 0 0 0 1px var(--line); }
.switch span { display: block; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgb(0 0 0 / 0.2); transition: transform 0.2s; }
.switch[aria-checked="true"] { background: var(--accent); box-shadow: none; }
.switch[aria-checked="true"] span { transform: translateX(20px); }

/* ---------- settings ---------- */
.account { display: flex; align-items: center; gap: 12px; }
.account img { width: 44px; height: 44px; border-radius: 50%; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.card .row + .row { border-top: 1px solid var(--line); }
.row.tight { padding: 0 0 8px; }
.card + .card { margin-top: 10px; }
.ok { display: flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; }
.ok svg { width: 18px; height: 18px; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin: 4px 0; }
.view > .btn.block.danger { margin-top: 24px; }

/* ---------- sheet ---------- */
#sheet-root .backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); opacity: 0; transition: opacity 0.25s; z-index: 20; }
#sheet-root .sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: calc(100dvh - var(--top) - 24px);
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(.2, .8, .2, 1);
}
#sheet-root.open .backdrop { opacity: 1; }
#sheet-root.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(var(--bottom) + 24px); -webkit-overflow-scrolling: touch; }

.field { display: block; margin-top: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.field > span i { font-weight: 400; font-style: normal; }
.field input:not([type=checkbox]) {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; min-height: 46px; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 9px; font-weight: 600; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.times { display: grid; gap: 8px; }
.time-row { display: flex; gap: 8px; align-items: center; }
.time-row input { flex: 1; }
.day-picker { display: flex; justify-content: space-between; gap: 6px; }
.day-picker button { flex: 1; aspect-ratio: 1; max-width: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-weight: 700; color: var(--muted); }
.day-picker button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row.check { margin-top: 16px; padding: 12px 14px; background: var(--surface); border-radius: 12px; border: 1px solid var(--line); }
.row.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 84px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
  animation: toast-in 0.2s ease; transition: opacity 0.3s;
}
.toast.out { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- start / end date ---------- */
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.date-range label { min-width: 0; }
.date-range small { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; }
.date-range input { -webkit-appearance: none; appearance: none; display: block; text-align: left; }
.field-help { margin: 6px 2px 0; font-size: 13px; color: var(--muted); }
.tag.ended { background: var(--surface-2); color: var(--muted); }

/* ---------- backup ---------- */
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.paste { margin-top: 12px; }
.paste summary { color: var(--accent); font-weight: 500; cursor: pointer; padding: 6px 0; }
.paste textarea {
  width: 100%; margin-top: 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: 13px/1.4 ui-monospace, Menlo, monospace; resize: vertical;
}
.banner.migrate { background: var(--accent-soft); }
.banner .btn-row { margin-top: 10px; }
.banner.denied { margin: 0 0 18px; text-align: left; background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
