:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #ece9e1;
  --ink: #1f2328;
  --ink-2: #4d535b;
  --ink-3: #737982;
  --line: #d9d5cb;
  --accent: #2f7d6d;
  --accent-soft: #d6ebe4;
  --accent-mid: #8cc2b4;
  --sos: #c4533a;
  --sos-ink: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --surface: #1a1f24;
    --surface-2: #232a31;
    --ink: #e9ecef;
    --ink-2: #b4bcc4;
    --ink-3: #8a939c;
    --line: #2e363e;
    --accent: #6cc3ad;
    --accent-soft: #1f3a34;
    --accent-mid: #3f7f70;
    --sos: #e0714f;
    --sos-ink: #1a0f0b;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111418;
  --surface: #1a1f24;
  --surface-2: #232a31;
  --ink: #e9ecef;
  --ink-2: #b4bcc4;
  --ink-3: #8a939c;
  --line: #2e363e;
  --accent: #6cc3ad;
  --accent-soft: #1f3a34;
  --accent-mid: #3f7f70;
  --sos: #e0714f;
  --sos-ink: #1a0f0b;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.topbar .sync { font-size: 12px; color: var(--ink-3); }
.icon-btn {
  border: 0; background: none; color: var(--ink-2); font-size: 20px;
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
}

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 180px; }

h2 { font-size: 22px; margin: 8px 0 4px; letter-spacing: -.01em; }
h3 { font-size: 16px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-3); font-size: 14px; }
.lead { color: var(--ink-2); margin-bottom: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; box-shadow: var(--shadow);
}
.card.accent { background: var(--accent-soft); border-color: transparent; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: 12px; line-height: 1.3; color: var(--ink-3); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .btn { flex: 1 1 140px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
}
.pill.ok { background: var(--accent-soft); color: var(--accent); }

.steps { list-style: none; padding: 0; margin: 8px 0 0; counter-reset: s; }
.steps li {
  counter-increment: s; position: relative; padding: 10px 0 10px 40px;
  border-top: 1px solid var(--line);
}
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 10px;
  width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2);
  display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--ink-2);
}
.steps small { display: block; color: var(--ink-3); }

audio { width: 100%; margin-top: 8px; }

.check {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line);
}
.check:first-of-type { border-top: 0; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.check.locked { opacity: .5; }
details summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-top: 4px; }
details p { font-size: 14px; color: var(--ink-2); margin-top: 6px; }

label.field { display: block; margin: 12px 0; font-size: 14px; color: var(--ink-2); }
label.field input, label.field textarea, label.field select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
}
.inline-fields { display: flex; gap: 8px; }
.inline-fields label.field { flex: 1; }

/* Bottom navigation */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px;
  font-size: 11px; color: var(--ink-3); text-decoration: none;
}
.tabs a .ico { font-size: 20px; line-height: 1; }
.tabs a.active { color: var(--accent); font-weight: 650; }

/* SOS */
.sos-fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 7;
  min-height: 56px; padding: 0 22px; border-radius: 28px; border: 0;
  background: var(--sos); color: var(--sos-ink); font: inherit; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25); cursor: pointer;
}

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 20px 16px 28px;
}
.sheet .close { float: right; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.choice-grid .btn { min-height: 64px; flex-direction: column; gap: 2px; text-align: center; }
.choice-grid .btn small { font-weight: 400; color: var(--ink-3); font-size: 12px; }

.timer { font-size: 44px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; margin: 8px 0; }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.chart .val { fill: var(--ink-2); font-weight: 600; }
.chart .bar { fill: var(--accent); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal div { aspect-ratio: 1; border-radius: 6px; background: var(--surface-2); }
.cal .full { background: var(--accent); }
.cal .min { background: var(--accent-mid); }
.cal .future { background: transparent; border: 1px dashed var(--line); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.science h3 { font-size: 17px; }
.science .src { font-size: 12px; color: var(--ink-3); margin-top: 8px; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.tag.myth { color: var(--sos); }
