/* GaitID capture — mobile-first, calm, large touch targets. */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #14181f;
  --muted: #5b6472;
  --line: #dde1e7;
  --accent: #2456c9;
  --accent-ink: #ffffff;
  --ok: #157f3b;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --bad: #c0262d;
  --bad-bg: #fde8e8;
  --rec: #d7263d;
  --paused: #b26b00;
  --stopped: #4a5361;
  --reconn: #6b3fc4;
  --radius: 14px;
  --tap: 52px;
  --tabs-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --card: #18202b;
    --text: #e8ecf2;
    --muted: #9aa5b4;
    --line: #2a3442;
    --accent: #5b8cff;
    --accent-ink: #0b1020;
    --ok: #46c172;
    --warn: #f0b34a;
    --warn-bg: #3a2c10;
    --bad: #ff6b6b;
    --bad-bg: #3d1a1d;
    --stopped: #7b8594;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
h2 { font-size: 1.12rem; margin: 0 0 .5rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
p { margin: .4rem 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.who { color: var(--muted); font-size: .9rem; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 12px;
}
.card.warn { background: var(--warn-bg); border-color: var(--warn); }

/* ---------- forms ---------- */
label { display: block; margin: 0 0 12px; font-weight: 600; font-size: .95rem; }
input, select {
  display: block; width: 100%; min-height: var(--tap); margin-top: 6px;
  padding: 10px 12px; font: inherit; font-weight: 400; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .tabs a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
label.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; }
label.check input { width: 26px; height: 26px; min-height: 0; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row input { margin: 0; flex: 1; }
.unit { color: var(--muted); }
.form-error { color: var(--bad); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px; border-radius: 12px;
  font: inherit; font-weight: 650; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { width: 100%; min-height: 60px; font-size: 1.08rem; margin-top: 4px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.record { background: var(--rec); color: #fff; border-color: transparent; font-size: 1.15rem; }
.btn.stop { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.danger { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.btn.link { background: none; border: none; color: var(--accent); width: 100%; font-weight: 600; }
.btn.small-btn { min-height: 44px; padding: 6px 14px; }
.danger-text { color: var(--bad) !important; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }

/* ---------- consent ---------- */
.consent { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; background: var(--bg); }
.consent summary { font-weight: 650; cursor: pointer; min-height: 32px; }
.consent-body p { font-size: .94rem; }
.rec-chip { color: var(--rec); font-weight: 700; white-space: nowrap; }

/* ---------- choices ---------- */
fieldset.choices { border: 0; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
fieldset.choices legend { font-weight: 650; margin-bottom: 8px; padding: 0; }
.choice { margin: 0; font-weight: 600; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: var(--tap); padding: 8px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg);
}
.choice input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--card)); }
.choice input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.ref-params { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.guidance { display: flex; gap: 14px; align-items: center; background: var(--bg); border-radius: 12px; padding: 12px; margin: 4px 0 12px; }
.guidance p { margin: 0; font-size: .94rem; }
.phone-icon { flex: none; width: 34px; height: 56px; border: 3px solid var(--text); border-radius: 8px; position: relative; }
.phone-icon::before { content: ""; position: absolute; left: 50%; top: -18px; transform: translateX(-50%); border: 7px solid transparent; border-bottom: 10px solid var(--accent); }
.phone-icon span { position: absolute; left: 50%; top: 4px; width: 8px; height: 3px; background: var(--text); transform: translateX(-50%); border-radius: 2px; }

/* ---------- banner ---------- */
.banner {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; font-weight: 800; font-size: 1.15rem; letter-spacing: .06em;
  color: #fff; background: var(--stopped);
}
.banner-dot { width: 18px; height: 18px; border-radius: 50%; background: #fff; flex: none; }
.banner-text { display: flex; flex-direction: column; min-width: 0; }
.banner-sub { font-size: .78rem; font-weight: 600; letter-spacing: .02em; opacity: .92; }
.banner-sub:empty { display: none; }
.banner-time { margin-left: auto; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.banner[data-state="recording"] { background: var(--rec); }
.banner[data-state="recording"] .banner-dot { animation: pulse 1.2s ease-in-out infinite; }
.banner[data-state="paused"] { background: var(--paused); }
.banner[data-state="paused"] .banner-dot { border-radius: 2px; width: 14px; height: 18px; background: linear-gradient(90deg, #fff 35%, transparent 35% 65%, #fff 65%); }
.banner[data-state="reconnecting"] { background: var(--reconn); }
.banner[data-state="reconnecting"] .banner-dot { animation: blink .8s steps(2) infinite; }
.banner[data-state="suspended"] { background: #7a1d10; }
.banner[data-state="suspended"] .banner-dot { background: #ffcf4a; }
.banner[data-state="stopping"], .banner[data-state="stopped"] { background: var(--stopped); }
.banner[data-state="stopped"] .banner-dot { border-radius: 3px; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.6); opacity: .55; } }
@keyframes blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .banner-dot { animation: none !important; } }

/* ---------- live stats ---------- */
.big-time { font-size: 3.4rem; font-weight: 750; text-align: center; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.stat span { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat b { font-size: 1.5rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat small { color: var(--muted); font-size: .8rem; }
.stat b.good { color: var(--ok); } .stat b.bad { color: var(--bad); } .stat b.meh { color: var(--warn); }
.sensor-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: .8rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); }
.chip.ok { border-color: var(--ok); color: var(--ok); }
.chip.no { border-color: var(--bad); color: var(--bad); }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 8px; }
.controls .btn.big { min-height: 72px; font-size: 1.2rem; margin: 0; }

.warnings { list-style: none; padding: 0; margin: 0 0 12px; }
.warnings li {
  background: var(--warn-bg); border: 1px solid var(--warn); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; font-size: .94rem;
}
.warnings li.bad { background: var(--bad-bg); border-color: var(--bad); }

/* ---------- sensor check ---------- */
.checklist { list-style: none; padding: 0; margin: 0 0 12px; }
.checklist li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .95rem; }
.checklist li:last-child { border-bottom: 0; }
.checklist .mark { flex: none; width: 22px; text-align: center; font-weight: 800; }
.checklist .ok .mark { color: var(--ok); }
.checklist .no .mark { color: var(--bad); }
.checklist .meh .mark { color: var(--warn); }
.readouts { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 12px; }
.readout { display: flex; justify-content: space-between; gap: 8px; background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: .9rem; }
.readout b { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.pill { font-size: .8rem; padding: 3px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-weight: 700; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.no { color: var(--bad); border-color: var(--bad); }
.pill.meh { color: var(--warn); border-color: var(--warn); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9rem; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.hint { background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; }

/* ---------- calibration ---------- */
.countdown { font-size: 4rem; font-weight: 800; text-align: center; padding: 12px 0; font-variant-numeric: tabular-nums; }
.countdown small { display: block; font-size: 1rem; font-weight: 600; color: var(--muted); }
.result { border-radius: 12px; padding: 12px; background: var(--bg); margin-top: 12px; }
.result.ok { border: 1.5px solid var(--ok); }
.result.no { border: 1.5px solid var(--warn); }

/* ---------- history ---------- */
.sessions { list-style: none; padding: 0; margin: 0; }
.sessions li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.sess-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.sess-title { font-weight: 700; overflow-wrap: anywhere; }
.sess-status { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.sess-status.recording { color: var(--rec); border-color: var(--rec); }
.sess-status.paused { color: var(--paused); border-color: var(--paused); }
.sess-status.interrupted { color: var(--warn); border-color: var(--warn); }
.sess-badges { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.sess-kind { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; border: 1px dashed var(--line); color: var(--muted); white-space: nowrap; }
.sess-kind.real { border-style: solid; color: var(--ok); border-color: var(--ok); }
.sess-kind.synthetic { color: var(--warn); border-color: var(--warn); }
.sess-meta { color: var(--muted); font-size: .9rem; margin: 4px 0 10px; }
.sess-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sess-actions .btn, .sess-actions a.btn { min-height: 44px; padding: 6px 12px; font-size: .9rem; text-decoration: none; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabs-h); color: var(--muted); text-decoration: none; font-size: .74rem; font-weight: 600;
}
.tabs a .ti { font-size: 1.2rem; line-height: 1; }
.tabs a .ti.rec { color: var(--rec); }
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs a[aria-disabled="true"] { opacity: .35; pointer-events: none; }

dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(92vw, 440px); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(10, 14, 20, .55); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  max-width: calc(100vw - 32px); z-index: 40; font-size: .94rem; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
