:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ecebe6;
  --text: #16171a;
  --muted: #676b72;
  --line: #dddbd5;
  --accent: #e2570a;
  --accent-text: #ffffff;
  --good: #1d8a4c;
  --warn: #b57a00;
  --bad: #cf3b3b;
  --start: #1d8a4c;
  --finish: #cf3b3b;
  --track: #b9b6ae;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d0f;
    --surface: #16181b;
    --surface-2: #1f2226;
    --text: #f1f1ee;
    --muted: #979ba3;
    --line: #2a2e33;
    --accent: #ff7a1f;
    --accent-text: #160a00;
    --good: #3fcf7f;
    --warn: #f0b429;
    --bad: #ff6464;
    --start: #3fcf7f;
    --finish: #ff6464;
    --track: #4a4e55;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0d0f; --surface: #16181b; --surface-2: #1f2226; --text: #f1f1ee; --muted: #979ba3; --line: #2a2e33;
  --accent: #ff7a1f; --accent-text: #160a00; --good: #3fcf7f; --warn: #f0b429; --bad: #ff6464; --start: #3fcf7f; --finish: #ff6464; --track: #4a4e55;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
main {
  max-width: 560px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 22px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; min-height: 40px; }
.topbar .title { flex: 1; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; padding: 8px 4px; cursor: pointer; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.warn { border-color: var(--warn); }
.card.tap { cursor: pointer; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 12px 16px; margin: 0 0 10px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(0.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.big { min-height: 64px; font-size: 19px; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; width: auto; margin: 0; }
.btn:disabled { opacity: 0.5; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin: 2px 4px 2px 0; }
.badge.good { color: var(--good); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.status-big { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; text-align: center; margin: 18px 0 4px; }
.status-sub { text-align: center; color: var(--muted); min-height: 22px; }
.timer { font-size: clamp(48px, 17vw, 76px); font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; margin: 8px 0 14px; }
.state-armed .status-big { color: var(--good); }
.state-running .status-big { color: var(--accent); }
.state-finished .status-big { color: var(--good); }

.track-item { display: flex; align-items: center; gap: 12px; }
.track-item .info { flex: 1; min-width: 0; }
.track-item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.list-item .t { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

canvas.map { width: 100%; height: 260px; display: block; background: var(--surface-2); border-radius: 10px; }
canvas.chart { width: 100%; height: 150px; display: block; }

input[type=text], input[type=number], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.lock {
  position: fixed; inset: 0; z-index: 100; background: #000; color: #7d7d7d;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-user-select: none; padding: 24px; text-align: center;
}
.lock .ls { font-size: 22px; font-weight: 700; color: #a8a8a8; }
.lock .lt { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; color: #8a8a8a; margin: 10px 0; }
.lock .hold { position: absolute; bottom: calc(40px + env(safe-area-inset-bottom)); font-size: 14px; color: #555; }
.lock .bar { width: 160px; height: 4px; background: #222; border-radius: 2px; margin: 10px auto 0; overflow: hidden; }
.lock .bar > i { display: block; height: 100%; width: 0; background: #ff7a1f; }

pre.out { white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 10px; overflow-x: auto; }
.help p, .help li { color: var(--text); }
.help li { margin-bottom: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 4px; border-radius: 2px; }
