:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dde1e6;
  --text: #15181d;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #c62828;
  --good: #1f8a4c;
  --warn: #b26b00;
  --serious: #c2410c;
  --neutral: #6b7280;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --surface: #181c23;
    --border: #2a303a;
    --text: #eef1f5;
    --text-2: #b4bcc8;
    --muted: #8a93a1;
    --accent: #4c8dff;
    --accent-ink: #0b1220;
    --danger: #ef5350;
    --good: #3fbf74;
    --warn: #e0a030;
    --serious: #f0803c;
    --neutral: #8a93a1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  min-height: 100dvh;
}
.mono, .val { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .35rem; }
h2.section { margin: 1.75rem 0 .5rem; font-size: 1rem; color: var(--text-2); }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 2;
}
main { max-width: 760px; margin: 0 auto; padding: 16px; }

.pill, .state {
  display: inline-flex; align-items: center; gap: 8px; font-size: .85rem;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2);
}
.pill i, .state i { width: 9px; height: 9px; border-radius: 50%; background: var(--neutral); }
.pill[data-s="on"] i, .state[data-s="running"] i { background: var(--good); }
.pill[data-s="busy"] i, .state[data-s="key_on"] i { background: var(--warn); }
.state[data-s="cranking"] i { background: var(--serious); }
.state[data-s="no_data"] i { background: var(--danger); }
.state { font-size: 1rem; padding: 6px 14px; color: var(--text); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.step { display: flex; gap: 14px; }
.step-n {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.step[aria-disabled="true"] { opacity: .55; }
.step[aria-disabled="true"] .step-n { background: var(--neutral); }
.step-body { flex: 1; min-width: 0; }
.step-body p { margin: 0 0 12px; }

.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 10px 18px; cursor: pointer;
  min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn.link { background: none; border: none; color: var(--accent); font-weight: 500; padding: 8px 0; min-height: 0; display: block; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.armed { outline: 3px solid var(--danger); outline-offset: 2px; }
.check { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; color: var(--text-2); }
.check input { width: 18px; height: 18px; }

.notice {
  border: 1px solid var(--danger); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
}
.demo-line { text-align: center; margin: 4px 0 0; }
.demo-line a { color: var(--accent); }

.statusbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#elapsed { font-size: 1.3rem; font-weight: 600; }
.status { margin: 0 0 12px; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px dashed var(--border); color: var(--text-2); }

.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; min-width: 0;
}
.tile .lbl { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .val { font-size: 1.5rem; font-weight: 650; white-space: nowrap; }
.tile .val small { font-size: .8rem; font-weight: 500; color: var(--muted); margin-left: 4px; }
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.tile.big .val { font-size: clamp(2.6rem, 13vw, 4.5rem); line-height: 1.1; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.meta { text-align: center; color: var(--muted); font-size: .85rem; margin: 14px 0; }

.summary { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0 16px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 180px; }

.history { list-style: none; padding: 0; margin: 0; }
.history li {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.history .h-main { flex: 1 1 200px; min-width: 0; }
.history .h-title { font-weight: 600; }
.history .h-sub { font-size: .85rem; color: var(--muted); }
.history .btn { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.tag { font-size: .75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--warn); color: var(--warn); margin-left: 6px; font-weight: 500; }
