:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15181d;
  --muted: #5d6573;
  --border: #dde1e7;
  --accent: #2563eb;
  --danger: #dc2626;
  --q-green: #16a34a;
  --q-yellow: #eab308;
  --q-orange: #ea580c;
  --q-red: #dc2626;
  --q-black: #111111;
  --q-none: #9ca3af;
  --spark-line: #2563eb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --card: #1b1f25;
    --text: #e8eaed;
    --muted: #9aa3b0;
    --border: #2c323b;
    --accent: #60a5fa;
    --danger: #f87171;
    --q-black: #000000;
    --q-none: #4b5563;
    --spark-line: #60a5fa;
    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.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
main {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
header { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 20px; margin: 0; }
.pill {
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.ok { color: var(--q-green); border-color: var(--q-green); }
.pill.warn { color: var(--q-orange); border-color: var(--q-orange); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

#setup { display: flex; gap: 12px; }
#setup label { flex: 1; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
#setup input {
  font: inherit; font-size: 18px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; width: 100%;
}

.light-card { display: flex; align-items: center; gap: 16px; }
.light { width: 72px; height: 72px; border-radius: 50%; flex: none; transition: background .3s; }
.light.green { background: var(--q-green); }
.light.yellow { background: var(--q-yellow); }
.light.orange { background: var(--q-orange); }
.light.red { background: var(--q-red); }
.light.black { background: var(--q-black); border: 2px solid var(--q-red); }
.light.none { background: var(--q-none); }
.big { font-size: 44px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.big small { font-size: 18px; color: var(--muted); font-weight: 400; }
.big .sub { font-size: 13px; color: var(--muted); font-weight: 400; margin-top: 4px; }

#spark { width: 100%; height: 120px; display: block; }
.legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.lossmark { color: var(--q-red); }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 6px; }
.grid div { display: flex; flex-direction: column; }
.grid b { font-size: 20px; font-variant-numeric: tabular-nums; }
.grid span { font-size: 11px; color: var(--muted); }

.info { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.info div { display: flex; justify-content: space-between; gap: 8px; }
.info span { color: var(--muted); flex: none; }
.info code { overflow-wrap: anywhere; text-align: right; }

.error { color: var(--danger); margin: 0; }

footer {
  position: sticky; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex; justify-content: center;
}
footer button {
  width: 100%; max-width: 488px;
  font: inherit; font-size: 20px; font-weight: 600;
  padding: 16px; border: 0; border-radius: 12px; color: #fff;
}
.primary { background: var(--accent); }
.danger { background: var(--danger); }
button:disabled { opacity: .5; }

@media (max-width: 360px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

#setup { flex-wrap: wrap; }
#setup label.wide { flex-basis: 100%; }
#setup label:not(.wide) { flex: 1 1 40%; }

.banner { border-color: var(--q-orange); display: flex; flex-direction: column; gap: 10px; }
.banner p { margin: 0; font-size: 14px; }
.banner .row { display: flex; gap: 8px; }
.banner button {
  font: inherit; font-weight: 600; padding: 12px 14px; border-radius: 8px; flex: 1;
  border: 1px solid var(--border); background: transparent; color: var(--text);
}
.banner button.primary { border-color: transparent; background: var(--accent); color: #fff; }

.result h2 { font-size: 17px; margin: 0 0 10px; }
.result .links { margin: 10px 0 0; font-size: 14px; }
a { color: var(--accent); }

.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* Hold-to-stop: a fill sweeps across while the button is held. */
.hold { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.hold::before {
  content: ""; position: absolute; inset: 0;
  background: rgb(0 0 0 / .28);
  transform: scaleX(var(--p, 0)); transform-origin: left;
}
.hold span { position: relative; }
