:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --warn-text: #7a5300;
  --serious: #ec835a;
  --crit: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --good-text: #0ca30c;
    --warn-text: #fab219;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
input, textarea {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  min-height: 44px;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 88px; resize: vertical; }
input[type="date"] { min-width: 0; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  min-height: 58px;
}
.top .nav { height: 56px; font-size: 32px; line-height: 1; color: var(--accent); }
.top .nav:disabled { color: var(--line); cursor: default; }
.top .title { position: relative; text-align: center; padding: 7px 0 6px; min-width: 0; }
.top .title.center { grid-column: 2; }
.top .title b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title span, .top .title .link { display: block; font-size: 13px; color: var(--muted); width: 100%; }
.top .title .link { color: var(--accent); }
.datepick {
  position: absolute; left: 0; top: 0; width: 100%; height: 30px;
  opacity: 0; padding: 0; margin: 0; min-height: 0;
}
.prog { grid-column: 1 / -1; height: 3px; background: var(--line); }
.prog i { display: block; height: 100%; background: var(--accent); transition: width 0.2s; }

/* main */
.view {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(86px + env(safe-area-inset-bottom));
}
.card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.card p { margin: 0 0 8px; }
.setup { border-color: var(--accent); }
.setup input { margin-bottom: 8px; }
.setup .btn { margin-top: 6px; }

.ctl { margin: 12px 0 0; }
.lab { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; margin-bottom: 6px; }
.lab .val { color: var(--ink2); font-size: 14px; font-variant-numeric: tabular-nums; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.35; }

.scale { display: flex; gap: 3px; }
.scale button {
  flex: 1; min-width: 0; height: 44px;
  border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink2); font-size: 14px; font-variant-numeric: tabular-nums;
}
.scale button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; min-width: 0; height: 42px; color: var(--ink2); font-size: 15px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 52px; height: 44px; border: 1px solid var(--line); border-radius: 10px; font-size: 24px; color: var(--accent); flex: none; }
.stepper .v { flex: 1; text-align: center; font-size: 18px; font-variant-numeric: tabular-nums; }
.stepper .v small { color: var(--muted); font-size: 13px; margin-left: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 0 14px; height: 38px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink2); font-size: 15px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips button.on::before { content: "✓ "; }

.num { display: flex; align-items: center; gap: 8px; }
.num input { max-width: 150px; }
.num small { color: var(--muted); }

.more { display: block; width: 100%; padding: 12px; margin: 2px 0 12px; color: var(--accent); font-size: 15px; text-align: center; }
.foot { display: flex; justify-content: space-between; align-items: center; padding: 4px 2px 0; gap: 10px; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok::before { background: var(--good); }
.status.pending::before { background: var(--warn); }
.status.error::before { background: var(--crit); }
.status-line { font-size: 14px; color: var(--ink2); margin: 0 0 10px; }
.status-line.error { color: var(--crit); }

.link { color: var(--accent); font-size: 14px; padding: 6px 0; }
.link.danger { color: var(--crit); }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; height: 44px; padding: 0 16px;
  border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { color: var(--crit); }
.btn:disabled { opacity: 0.5; }
.row { display: flex; gap: 10px; margin: 8px 0; }
.row > * { flex: 1; min-width: 0; }
.lab-form input { margin-bottom: 0; }
.lab-form .btn { margin-top: 4px; }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs .tab {
  flex: 1; height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; color: var(--muted);
}
.tabs .tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs .tab.on { color: var(--accent); }

/* lock */
.lock { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.lock[hidden] { display: none; }
.lock-card { width: 100%; max-width: 340px; text-align: center; }
.lock-logo { width: 72px; height: 72px; border-radius: 18px; }
.lock-card h1 { margin: 12px 0 4px; font-size: 24px; }
.lock-card p { color: var(--ink2); margin: 0 0 16px; }
.lock-card input { margin-bottom: 8px; text-align: center; }
.lock-card .link { margin-top: 14px; }
.err { color: var(--crit); min-height: 20px; font-size: 14px; margin: 0 0 8px !important; }

/* trends */
.hero { text-align: center; }
.hero-n { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.hero-sub { color: var(--ink2); font-size: 14px; margin-top: 4px; }
.verdict { margin: 14px 0 2px; font-size: 22px; font-weight: 700; }
.verdict.good { color: var(--good-text); }
.verdict.mid { color: var(--serious); }
.verdict.none { color: var(--ink2); }
.verdict.bad { color: var(--crit); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { font-weight: 500; color: var(--muted); font-size: 12px; text-align: right; padding: 4px; }
.tbl td { padding: 8px 4px; border-top: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; vertical-align: top; }
.tbl td.l, .tbl th.l { text-align: left; }
.tbl td.x { width: 1%; white-space: nowrap; }
.tbl .up { color: var(--good-text); }
.tbl .down { color: var(--crit); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink2); margin: 0 0 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.legend i.warn { background: var(--warn); }
.legend i.crit { background: var(--crit); }
.legend i.band { border-radius: 2px; width: 12px; }
.legend i.band-lion { background: var(--ink); opacity: 0.18; }
.legend i.band-reintro { background: var(--s2); opacity: 0.4; }
.legend i.band-off { background: var(--crit); opacity: 0.35; }
.chart { position: relative; margin: 0 -4px; }
.chart svg { display: block; max-width: 100%; }
.lc .grid { stroke: var(--line); stroke-width: 1; }
.lc .axis { stroke: var(--axis); stroke-width: 1; }
.lc .today { stroke: var(--axis); stroke-width: 1; }
.lc .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.lc .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lc .end { stroke: var(--surface); stroke-width: 2; }
.lc .band-lion { fill: var(--ink); opacity: 0.06; }
.lc .band-reintro { fill: var(--s2); opacity: 0.14; }
.lc .band-off { fill: var(--crit); opacity: 0.12; }
.lc .mark.slip { fill: var(--warn); }
.lc .mark.broke { fill: var(--crit); }
.lc .xh { stroke: var(--axis); stroke-width: 1; }
.lc .hp { stroke: var(--surface); stroke-width: 2; }
.lc .hit { touch-action: pan-y; cursor: crosshair; }
.lc .dl { fill: var(--ink2); font-size: 11px; }
.tip {
  position: fixed; z-index: 30;
  background: var(--surface); border: 1px solid var(--ring); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; min-width: 130px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}
.tip[hidden] { display: none; }
.tip .tip-h { color: var(--muted); margin-bottom: 4px; font-size: 12px; }
.tip div { display: flex; align-items: center; gap: 6px; }
.tip b { margin-left: auto; font-variant-numeric: tabular-nums; padding-left: 10px; }
.tip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.days { display: flex; flex-direction: column; }
.dayrow {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center;
  width: 100%; padding: 10px 0; border-top: 1px solid var(--line); text-align: left; font-size: 14px;
}
.dayrow:first-child { border-top: 0; }
.dayrow .d b { display: block; }
.dayrow .d .muted { font-size: 12px; }
.dayrow .nums { font-variant-numeric: tabular-nums; color: var(--ink2); text-align: right; }
.dayrow .bd { grid-column: 1 / -1; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink2); margin-right: 4px; }
.badge.ad-clean { color: var(--good-text); border-color: transparent; background: rgba(12, 163, 12, 0.12); }
.badge.ad-slip { color: var(--warn-text); border-color: transparent; background: rgba(250, 178, 25, 0.2); }
.badge.ad-broke { color: var(--crit); border-color: transparent; background: rgba(208, 59, 59, 0.12); }
.empty { color: var(--muted); text-align: center; padding: 12px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.lab-note { font-size: 12px; color: var(--muted); }
label.btn input { display: none; }
