:root {
  --bg: #f5f6f8; --bg2: #ffffff; --fg: #16181d; --fg2: #5d6470;
  --line: #e2e5ea; --accent: #3b82f6; --good: #22a06b; --warn: #d97706;
  --bad: #dc2626; --chip: #eef1f5;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --bg2: #181b21; --fg: #e8eaee; --fg2: #9aa1ac;
    --line: #2a2e36; --accent: #5b9bf8; --good: #34c77b; --warn: #f0a13a;
    --bad: #ef5350; --chip: #232730;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
h1 { font-size: 1.3rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--bg); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem;
}
label { display: block; font-size: .82rem; color: var(--fg2); margin: .7rem 0 .25rem; }

.overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.panel { width: 100%; max-width: 380px; text-align: center; }
.panel .big-icon { font-size: 3.6rem; line-height: 1; margin-bottom: .6rem; }
.panel h1 { font-size: 1.9rem; }
.panel p { color: var(--fg2); font-size: 1.02rem; }
.panel input { margin: 1rem 0; text-align: center; padding: .9rem; font-size: 1.1rem; border-radius: 14px; }
.panel .btn { padding: .9rem; font-size: 1.1rem; border-radius: 14px; }
.err { color: var(--bad); }

.btn {
  display: inline-block; width: 100%; padding: .65rem 1rem; border-radius: 12px;
  font-weight: 600; border: 1px solid var(--line); background: var(--bg2);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-style: dashed; color: var(--fg2); margin-top: .8rem; }
.btn.small { width: auto; padding: .35rem .8rem; font-size: .85rem; border-radius: 9px; }

.picker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 1rem 0; }
.picker-card {
  padding: 1.2rem .5rem; border-radius: 16px; background: var(--bg2);
  border: 1px solid var(--line); font-weight: 700; font-size: 1.05rem;
}
.picker-card .avatar {
  width: 52px; height: 52px; border-radius: 50%; margin: 0 auto .5rem;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.3rem;
}

#app { max-width: 640px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(.9rem + env(safe-area-inset-top, 0px)) 1rem .5rem;
  position: sticky; top: 0; z-index: 30; background: var(--bg);
}
#topbar-title { font-size: 1.35rem; font-weight: 800; }
#profile-chip {
  width: 36px; height: 36px; border-radius: 50%; color: #fff;
  font-weight: 700; flex: none;
}
#view { flex: 1; padding: 0 1rem calc(5.2rem + var(--safe-b)); }
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: var(--bg2); border-top: 1px solid var(--line);
  padding: .4rem 0 calc(.4rem + var(--safe-b));
}
#tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .68rem; color: var(--fg2); padding: .2rem .9rem; border-radius: 10px;
}
#tabs button span { font-size: 1.25rem; }
#tabs button.active { color: var(--accent); }

.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: .8rem .9rem; margin: .6rem 0;
}
.muted { color: var(--fg2); font-size: .85rem; }
.chip {
  display: inline-block; font-size: .7rem; font-weight: 600; padding: .1rem .5rem;
  border-radius: 99px; background: var(--chip); color: var(--fg2);
}
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip.now { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

/* Today */
.day-nav { display: flex; align-items: center; justify-content: space-between; margin: .3rem 0 .5rem; }
.day-nav > div { font-size: 1.05rem; }
.day-nav button {
  font-size: 1.5rem; width: 48px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--fg); padding: 0 0 .15rem;
}
.day-nav button:disabled { opacity: .35; }
.ring-wrap { display: flex; justify-content: center; margin: .2rem 0 .6rem; }
.ring { position: relative; width: 96px; height: 96px; }
.ring svg { transform: rotate(-90deg); }
.ring .nums {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: 800; font-size: 1.15rem;
}
.ring .nums small { font-weight: 500; color: var(--fg2); font-size: .7rem; }
.dose-row { display: flex; align-items: center; gap: .8rem; }
.dose-row.now-slot { border-color: var(--accent); }
.dose-row .check {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line);
  flex: none; font-size: 1.05rem; color: #fff; transition: all .15s;
}
.dose-row .check.taken { background: var(--good); border-color: var(--good); }
.dose-row .check.skipped { background: var(--fg2); border-color: var(--fg2); }
.dose-row .body { flex: 1; min-width: 0; }
.dose-row .name { font-weight: 650; }
.dose-row.done .name { text-decoration: line-through; opacity: .55; }
.dose-row .sub { font-size: .8rem; color: var(--fg2); }
.dose-row .more { color: var(--fg2); font-size: 1.2rem; padding: .3rem .5rem; }

/* History */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: .6rem; }
.cal .dow { text-align: center; font-size: .68rem; color: var(--fg2); padding: .2rem 0; }
.cal .day {
  aspect-ratio: 1; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .8rem; gap: 3px;
}
.cal .day.out { visibility: hidden; }
.cal .day .dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.cal .day.full .dot { background: var(--good); }
.cal .day.partial .dot { background: var(--warn); }
.cal .day.none .dot { background: var(--bad); }
.cal .day.today { border-color: var(--accent); }

/* Modal & toast */
dialog {
  border: none; border-radius: 16px; background: var(--bg2); color: var(--fg);
  width: min(92vw, 420px); padding: 1.1rem; max-height: 86vh;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
#toast {
  position: fixed; bottom: calc(5.5rem + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: .5rem 1rem; border-radius: 99px;
  font-size: .85rem; z-index: 99; max-width: 90vw; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.row { display: flex; gap: .6rem; align-items: center; }
.row > * { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; }
.dose-grid { display: grid; grid-template-columns: 1fr 70px 110px; gap: .4rem; align-items: center; }
.dose-grid .slot-name { font-size: .85rem; }
