:root {
  --bg: #f4f7f6; --card: #ffffff; --ink: #14201f; --muted: #5b6b69; --line: #dbe4e2;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #d9f0ec;
  --sys: #c2410c; --dia: #1d4ed8;
  --b-low: #1d4ed8; --b-optimal: #15803d; --b-normal: #3f7d20; --b-high: #b45309; --b-vhigh: #b91c1c; --b-severe: #7f1d1d;
  --shadow: 0 1px 2px rgba(20,32,31,.06), 0 4px 14px rgba(20,32,31,.05);
  --tab-h: 74px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514; --card: #172120; --ink: #e8f0ee; --muted: #9bb0ac; --line: #2a3a38;
    --accent: #2dd4bf; --accent-ink: #04201c; --accent-soft: #123a35;
    --sys: #fb923c; --dia: #7aa2ff;
    --b-low: #7aa2ff; --b-optimal: #4ade80; --b-normal: #a3e635; --b-high: #fbbf24; --b-vhigh: #f87171; --b-severe: #fca5a5;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top);
}
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); }
h1 { font-size: 1.6rem; margin: 4px 0 14px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.topbar { display: flex; align-items: center; justify-content: space-between; }
.iconbtn { background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 10px; font-size: 1.2rem; }

/* buttons & inputs */
.btn { font: inherit; font-weight: 600; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 13px 18px; min-height: 48px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--b-vhigh); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.block { width: 100%; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 46px; width: 100%; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .wheel:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
label input { margin-top: 4px; }

/* band pills */
.pill { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: #fff; vertical-align: middle; }
.pill.low { background: var(--b-low); } .pill.optimal { background: var(--b-optimal); } .pill.normal { background: var(--b-normal); }
.pill.high { background: var(--b-high); } .pill.vhigh { background: var(--b-vhigh); } .pill.severe { background: var(--b-severe); }
@media (prefers-color-scheme: dark) { .pill { color: #0b1110; } }

/* stats */
.big { font-size: 2.8rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.big small { font-size: 1rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.statcard .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.mini .big { font-size: 1.7rem; }

/* segmented */
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; font: inherit; font-size: .88rem; font-weight: 600; border: 0; background: none; color: var(--muted); padding: 8px 4px; border-radius: 9px; min-height: 36px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* chart */
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .thr { stroke-width: 1; stroke-dasharray: 4 4; opacity: .7; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.readout { min-height: 1.4em; font-size: .88rem; margin-top: 6px; }

/* add / edit */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.step { font: inherit; background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 8px 6px; text-align: center; color: var(--ink); min-height: 58px; }
.step b { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.step span { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.step.active { border-color: var(--accent); background: var(--accent-soft); }
.step.todo span { color: var(--muted); font-weight: 500; }
.step.done b::after { content: " ✓"; color: var(--accent); }
.wheels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wcol { text-align: center; }
.wcol .wl { font-size: .75rem; font-weight: 700; letter-spacing: .08em; color: var(--muted); }
.readbtn { font: inherit; font-size: 2.1rem; font-weight: 700; background: none; border: 0; color: var(--ink); width: 100%; padding: 2px 0 6px; font-variant-numeric: tabular-nums; min-height: 52px; }
.readbtn.sys { color: var(--sys); } .readbtn.dia { color: var(--dia); }
.readinput { font-size: 1.8rem; font-weight: 700; text-align: center; padding: 4px; }
.wwrap { position: relative; height: 220px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.wwrap::before { content: ""; position: absolute; left: 0; right: 0; top: 88px; height: 44px; background: var(--accent-soft); border-top: 1px solid var(--accent); border-bottom: 1px solid var(--accent); pointer-events: none; }
.wwrap::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(var(--card), transparent 38%, transparent 62%, var(--card)); opacity: .85; }
.wheel { position: relative; z-index: 1; height: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; padding: 88px 0; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.wheel::-webkit-scrollbar { display: none; }
.wheel .it { height: 44px; line-height: 44px; text-align: center; font-size: 1.25rem; scroll-snap-align: center; scroll-snap-stop: always; font-variant-numeric: tabular-nums; color: var(--muted); }
.wheel .it.sel { color: var(--ink); font-weight: 700; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.chip { font: inherit; font-size: .88rem; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 8px 14px; min-height: 40px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
details.more summary { cursor: pointer; font-weight: 600; padding: 12px 0; min-height: 44px; }
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 14px; }
.actions.one { grid-template-columns: 1fr; }

/* history */
.day { margin: 18px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.day b { font-size: .95rem; }
.sess { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.sess .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sess .avg { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sess .rd { font-size: .82rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.sess .nt { font-size: .82rem; margin-top: 4px; }

/* tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; background: color-mix(in srgb, var(--card) 92%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); height: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; padding: 4px; min-height: 48px; justify-content: center; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent); }
.tabbar a.add .plus { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 2rem; line-height: 44px; text-align: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(15,118,110,.35); }
.tabbar a.add.on { color: var(--accent); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; z-index: 20; max-width: 90%; }
.banner { position: sticky; top: 0; z-index: 15; background: var(--b-high); color: #fff; text-align: center; padding: 8px 12px; font-size: .88rem; font-weight: 600; }
.empty { text-align: center; padding: 28px 10px; color: var(--muted); }
.err { color: var(--b-vhigh); font-weight: 600; }
.disclaimer { font-size: .78rem; color: var(--muted); margin: 6px 4px 0; }

/* login */
body.login { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px; box-shadow: var(--shadow); text-align: center; }
.login-card form { text-align: left; display: grid; gap: 14px; margin-top: 10px; }
.login-icon { border-radius: 16px; }
.login-card h1 { margin-top: 10px; }
@media (prefers-reduced-motion: no-preference) { .toast { animation: pop .2s ease-out; } @keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } } }
