:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #15202e;
  --muted: #5b6777;
  --border: #dbe2ec;
  --accent: #2f7de1;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --warn: #b35a00;
  --warn-bg: #fff1e0;
  --due: #c62f2f;
  --due-bg: #fdeaea;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .06);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #18202b;
    --surface-2: #212b38;
    --text: #e9eef5;
    --muted: #9aa7b8;
    --border: #2c3747;
    --accent: #5b9cf0;
    --accent-text: #0b1420;
    --ok: #56c98a;
    --ok-bg: #16301f;
    --warn: #f0a35b;
    --warn-bg: #36260f;
    --due: #ff7a7a;
    --due-bg: #3a1919;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 18px 12px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
}
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.sync { font-size: 13px; color: var(--muted); }

main { padding: 4px 16px 24px; max-width: 640px; margin: 0 auto; outline: none; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); padding: 18px; margin: 12px 0;
}
.card h2 { margin: 0 0 6px; font-size: 20px; }
.card h3 { margin: 0 0 8px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }

.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600;
  border-radius: 14px; padding: 14px 18px; min-height: 52px;
  background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .06s ease, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--due-bg); color: var(--due); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 20px; border-radius: 18px; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 6px 0; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px;
  padding: 6px 10px; border-radius: 999px; background: var(--surface-2);
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c, var(--accent)); }
.dot-lg { width: 14px; height: 14px; }

/* Medication photos: ringed in the medication's color so it stays recognisable. */
.medpic { flex: none; object-fit: cover; border-radius: 50%; border: 2px solid var(--c, var(--accent)); background: var(--surface-2); }
.medpic-sm { width: 30px; height: 30px; }
.medpic-lg { width: 56px; height: 56px; border-width: 3px; }
.hero .med { gap: 12px; }
.photofield { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.photo-empty {
  width: 56px; height: 56px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface-2); border: 1px dashed var(--border); color: var(--muted);
}
.photo-empty svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.photofield label.btn { cursor: pointer; }

/* Wake card */
.wake .big-time { font-size: 44px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 12px; }
/* Form controls: reset iOS Safari's native styling so every box is the same height, left-aligned,
   and never wider than its column. */
input[type="time"], input[type="date"], input[type="text"], input[type="number"], input[type="url"], select {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; min-width: 0; max-width: 100%; height: 52px; margin: 0;
  font: inherit; font-size: 17px; line-height: 1.2; text-align: left;
  color: var(--text); background-color: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 0 14px;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* iOS Safari pins date/time text to the top of the box unless it is centered explicitly. */
input[type="date"], input[type="time"] { display: flex; align-items: center; line-height: 50px; }
input::-webkit-date-and-time-value { text-align: left; margin: 0; line-height: 50px; min-height: 50px; display: flex; align-items: center; }
input::-webkit-datetime-edit { padding: 0; }
select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%238793a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
input[type="color"] {
  -webkit-appearance: none; appearance: none; flex: none;
  width: 52px; height: 52px; padding: 0; margin: 0; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: none; overflow: hidden;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 11px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 11px; }
label.field { display: block; margin: 10px 0; min-width: 0; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); }
.choice input[type="radio"] {
  -webkit-appearance: none; appearance: none; flex: none; margin: 1px 0 0;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--muted); background: transparent; display: grid; place-content: center;
}
.choice input[type="radio"]:checked { border-color: var(--accent); }
.choice input[type="radio"]:checked::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
}
.choice input[type="radio"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Two-up fields: inputs line up along the bottom even when one label wraps. */
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; align-items: end; }
.medrow { display: flex; gap: 10px; align-items: center; }
.medrow input[type="text"] { flex: 1; }

/* Next-drop hero */
.hero { border: 2px solid var(--c, var(--accent)); }
.hero .when { font-size: 40px; font-weight: 700; letter-spacing: -.02em; }
.hero .med { font-size: 20px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.hero.due { background: var(--due-bg); }
.status { font-weight: 600; font-size: 15px; }
.status.due { color: var(--due); }
.status.ok { color: var(--ok); }
.status.wait { color: var(--warn); }

/* Countdown */
.countdown { background: var(--warn-bg); border-color: transparent; text-align: center; }
.countdown .clock { font-size: 56px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--warn); }
.ring { --p: 0; height: 8px; border-radius: 8px; background: color-mix(in srgb, var(--warn) 20%, transparent); overflow: hidden; margin-top: 8px; }
.ring > i { display: block; height: 100%; width: calc(var(--p) * 100%); background: var(--warn); transition: width 1s linear; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex; align-items: center; gap: 12px; padding: 12px 2px;
  border-bottom: 1px solid var(--border);
}
.timeline li:last-child { border-bottom: 0; }
.timeline .t { width: 84px; flex: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.timeline .gapnote { display: block; font-size: 13px; color: var(--warn); margin-top: 2px; }
.timeline .what { flex: 1; min-width: 0; }
.timeline .what b { display: flex; align-items: center; gap: 8px; }
.timeline li.taken .t, .timeline li.taken .what b { color: var(--muted); }
.timeline li.due { background: var(--due-bg); border-radius: 12px; padding-left: 8px; padding-right: 8px; }
.check {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ok); color: var(--ok);
  background: var(--ok-bg); display: grid; place-items: center; font-size: 20px; cursor: pointer;
}

.check.skip { border-color: var(--border); color: var(--muted); background: var(--surface-2); }
.timeline li.skipped .what b { text-decoration: line-through; text-decoration-color: var(--muted); }

/* History */
.hist li { display: block; }
.bar { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); }

/* Banners */
.banner { border-radius: 14px; padding: 12px 14px; margin: 12px 0; font-size: 15px; }
.banner.info { background: var(--surface-2); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.codebox { background: var(--surface-2); border-radius: 10px; padding: 10px; display: block; margin: 8px 0; user-select: all; -webkit-user-select: all; }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin: 6px 0; }
ol.steps.big-steps { font-size: 18px; padding-left: 24px; }
ol.steps.big-steps li { margin: 12px 0; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[data-tab="today"] svg { fill: currentColor; stroke: none; }
.tab.active { color: var(--accent); }

/* Toast */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 20; max-width: 560px; margin: 0 auto;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 14px 16px; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

/* Modal */
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(92vw, 420px);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(10, 15, 25, .45); }
dialog h2 { margin-top: 0; }

@media (max-width: 360px) {
  .timeline .t { width: 72px; }
  .hero .when { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
