:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16191d;
  --muted: #646b75;
  --border: #e2e5ea;
  --accent: #16a34a;
  --accent-ink: #ffffff;
  /* glucose, as on the device: green in range, yellow high, orange very high, red low, grey not current */
  --in: #16a34a;
  --high: #b98900;
  --vhigh: #d9670b;
  --low: #dc2626;
  --stale: #8a929c;
  --band: rgba(22, 163, 74, 0.10);
  --danger: #c0352b;
  --warn-bg: #fff7e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --surface: #171b20;
    --surface-2: #1f252c;
    --text: #e9ecef;
    --muted: #98a1ab;
    --border: #2a3139;
    --accent: #34d399;
    --accent-ink: #052014;
    --in: #34d399;
    --high: #facc15;
    --vhigh: #fb923c;
    --low: #f87171;
    --stale: #7b848e;
    --band: rgba(52, 211, 153, 0.10);
    --danger: #ff6b5e;
    --warn-bg: #2b2412;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; letter-spacing: -.01em; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand svg { width: 24px; height: 24px; fill: var(--accent); }
.brand svg .drop { fill: var(--surface); }
#nav { display: flex; align-items: center; gap: 12px; font-size: 14px; min-width: 0; }
#nav .who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 38vw; }
#nav a[aria-current="page"] { color: var(--text); font-weight: 650; }
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  #nav { width: 100%; gap: 10px; }
  #nav .who { margin-left: auto; max-width: 22vw; }
}
.device-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 16px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 16px 28px; max-width: 640px; margin: 0 auto; }

h1 { font-size: 22px; margin: 4px 0 4px; letter-spacing: -.015em; overflow-wrap: anywhere; }
h2 { font-size: 13px; margin: 0 0 12px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 32px 0; }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.two { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .two { grid-template-columns: 1fr 1fr; } }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 560; cursor: pointer;
  min-height: 42px; text-align: center;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 500; }
.btn.link.danger { color: var(--danger); }
.btn.big { width: 100%; font-size: 17px; min-height: 50px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 0; }
.actions { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; min-height: 42px; width: 100%;
}
input[type="checkbox"] { width: auto; min-height: 0; }
input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--accent); }
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field-block + .field-block { margin-top: 14px; }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Landing */
.hero { max-width: 540px; margin: 32px auto; text-align: center; }
.hero h1 { font-size: 30px; margin-bottom: 8px; }
.hero p { color: var(--muted); }
.signin { display: flex; justify-content: center; margin: 24px 0 8px; min-height: 44px; }
.disclaimer { font-size: 13px; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 24px; }

/* Link confirmation */
.confirm { max-width: 440px; margin: 24px auto; text-align: center; }
.confirm .devname { font-size: 26px; font-weight: 700; margin: 8px 0 2px; }
.confirm .stack { text-align: left; }

/* Device cards */
.devcard { display: block; color: inherit; }
.devcard:hover { text-decoration: none; border-color: var(--accent); }
.devcard .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.devcard .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--stale); margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--in); }

.bg { display: flex; align-items: baseline; gap: 10px; margin: 10px 0 2px; flex-wrap: wrap; }
.bg .val { font-size: 52px; font-weight: 750; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.bg .arrow { font-size: 34px; line-height: 1; }
.bg .unit { color: var(--muted); font-size: 13px; }
.bg.big .val { font-size: 96px; }
.bg.big .arrow { font-size: 60px; }
.bg .val.struck { text-decoration: line-through; text-decoration-thickness: 4px; }
.sub { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.c-in { color: var(--in); }
.c-high { color: var(--high); }
.c-vhigh { color: var(--vhigh); }
.c-low { color: var(--low); }
.c-stale { color: var(--stale); }

/* Chart */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; padding: 6px 12px; cursor: pointer; min-height: 36px; }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 650; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid line { stroke: var(--border); }
svg.chart text { fill: var(--muted); font-size: 11px; }
svg.chart .band { fill: var(--band); }

/* Key/value */
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
ul.plain li:last-child { border-bottom: 0; }
ul.plain li .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  ul.plain li.member-row .grow { flex: 1 0 100%; }
}

.notice { border-left: 3px solid var(--accent); background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-size: 14px; margin: 0 0 12px; }
.notice.warn { border-left-color: var(--high); background: var(--warn-bg); }
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100vw - 32px);
}
.codebox { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; letter-spacing: .18em; }
.scroll-x { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
table.tbl td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 140px; }
table.tbl th { color: var(--muted); font-weight: 600; }
.state { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.state.acked { color: var(--in); }
.state.failed { color: var(--danger); }
.state.expired { text-decoration: line-through; }
.back { display: inline-block; margin-bottom: 8px; font-size: 14px; }
.headline { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.shot { display: block; max-width: 100%; max-height: 70vh; border-radius: 8px; border: 1px solid var(--border); image-rendering: pixelated; margin: 0 auto; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; }
.thumbs a img { height: 64px; border-radius: 4px; border: 1px solid var(--border); display: block; }
.thumbs a.on img { outline: 2px solid var(--accent); }
pre.log { background: var(--surface-2); border-radius: 8px; padding: 10px; font-size: 12px; max-height: 60vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
details > summary { cursor: pointer; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

/* privacy / terms pages */
.doc { max-width: 680px; margin: 0 auto; padding: 24px 16px 48px; line-height: 1.55; }
.doc h1 { margin-bottom: 4px; }
.doc h2 { font-size: 1.05rem; margin-top: 24px; text-transform: none; letter-spacing: 0; color: var(--text); }
.doc a { color: inherit; text-decoration: underline; }
