:root {
  --bg: #08090b;
  --panel: rgba(16, 18, 22, .82);
  --line: #2a2f38;
  --ink: #f2f5f8;
  --dim: #9aa4b0;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --accent: #7dd3fc;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.screen { min-height: 100%; }
[hidden] { display: none !important; }

/* ---------- setup ---------- */
#setup { padding: 34px 22px 48px; max-width: 560px; margin: 0 auto; }

.brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--dim); font-weight: 600; margin-bottom: 28px;
}
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 12px var(--good);
}

#setup h1 { font-size: 38px; letter-spacing: -.02em; margin: 0 0 12px; font-weight: 650; }
.lede { font-size: 16px; color: var(--dim); margin: 0 0 26px; max-width: 46ch; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 20px; margin-bottom: 16px;
  backdrop-filter: blur(8px);
}
.card h2 {
  font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--dim); margin: 0 0 12px; font-weight: 600;
}
.card.warn { border-color: #6b4b12; background: rgba(80, 55, 10, .35); }
.card.warn h2 { color: var(--warn); }
.checks { margin: 0; padding-left: 18px; }
.checks li { margin: 9px 0; font-size: 14.5px; color: #d7dde3; }
.checks b { color: var(--ink); }

button {
  font: inherit; cursor: pointer; border-radius: 11px;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  transition: transform .08s ease, background .15s ease;
}
button:active { transform: scale(.985); }

.primary {
  width: 100%; padding: 16px; font-size: 17px; font-weight: 600;
  background: var(--ink); color: #08090b; border: none; margin-top: 6px;
}
.ghost {
  width: 100%; padding: 13px; font-size: 14.5px; color: var(--dim);
  margin-top: 10px;
}
.fine { font-size: 12.5px; color: #6b7580; margin-top: 16px; line-height: 1.5; }
code { background: #1a1e24; padding: 1px 6px; border-radius: 4px; font-size: .92em; }

/* ---------- live ---------- */
#live { position: fixed; inset: 0; overflow: hidden; }
#view { width: 100%; height: 100%; display: block; object-fit: cover; }

.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.62), transparent);
}
.pill {
  font-size: 12.5px; letter-spacing: .04em; padding: 6px 12px;
  border-radius: 999px; background: rgba(0,0,0,.55);
  border: 1px solid var(--line); color: var(--dim);
}
.pill.ok { color: var(--good); border-color: #1f5136; }
.pill.bad { color: var(--bad); border-color: #5b2327; }

.mini {
  font-size: 13px; padding: 7px 13px; border-radius: 999px;
  background: rgba(0,0,0,.55);
}

.hud-angle {
  position: absolute; top: calc(58px + env(safe-area-inset-top));
  left: 16px; right: 16px;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 9px 13px; border-radius: 10px;
  background: rgba(0,0,0,.55); border: 1px solid var(--line);
  font-size: 13px;
}
.hud-angle .label { color: var(--dim); }
.hud-angle .verdict { font-weight: 650; }
.hud-angle .note { color: var(--dim); font-size: 12px; flex-basis: 100%; }

.hud-bottom {
  position: absolute; left: 0; right: 0;
  bottom: 0;
  padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(0,0,0,.85), rgba(0,0,0,.35) 60%, transparent);
}

.counter { display: flex; align-items: baseline; gap: 8px; }
.counter .num {
  font-size: 78px; line-height: .9; font-weight: 700;
  letter-spacing: -.045em; font-variant-numeric: tabular-nums;
}
.counter .unit { font-size: 15px; color: var(--dim); letter-spacing: .08em; }

.metrics {
  display: flex; gap: 22px; margin: 14px 0 14px;
  font-variant-numeric: tabular-nums;
}
.metrics .m { display: flex; flex-direction: column; gap: 2px; }
.metrics .k { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.metrics .v { font-size: 17px; font-weight: 600; }

.row { display: flex; gap: 10px; }

.trace {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 54px; height: 38%;
  border-radius: 10px; background: rgba(0,0,0,.35);
  border: 1px solid var(--line); overflow: hidden;
}
#traceCanvas { width: 100%; height: 100%; display: block; }

/* rep confirmation flash */
.flash {
  position: absolute; inset: 0; pointer-events: none;
  border: 3px solid var(--good);
  animation: pulse .45s ease-out forwards;
}
@keyframes pulse {
  0% { opacity: .85; }
  100% { opacity: 0; }
}

#error { padding: 34px 22px; max-width: 560px; margin: 0 auto; }
#error h1 { font-size: 26px; }
#errText {
  background: #12151a; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; font-size: 12.5px; color: var(--warn);
  white-space: pre-wrap; word-break: break-word; overflow-x: auto;
}

/* ================= set report ================= */
#report { position: fixed; inset: 0; overflow-y: auto; background: var(--bg); z-index: 5; }
.report-wrap { max-width: 680px; margin: 0 auto; padding: 26px 18px 60px; }

.report-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 14px; margin-bottom: 22px;
}
.kicker {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); font-weight: 600; margin-bottom: 6px;
}
.report-head h1 { font-size: 34px; margin: 0; letter-spacing: -.02em; }
.src-line { font-size: 12.5px; color: var(--dim); margin-top: 4px; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 15px;
}
.stat .n { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11.5px; color: var(--dim); margin-top: 3px; }

.table-scroll { overflow-x: auto; }
table.reps { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.reps th {
  text-align: right; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--dim); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
table.reps th:first-child, table.reps td:first-child { text-align: left; }
table.reps td { text-align: right; padding: 9px 8px; border-bottom: 1px solid #1b1f26; }
table.reps tr:last-child td { border-bottom: none; }
.grade-good { color: var(--good); }
.grade-fair { color: var(--warn); }
.grade-poor { color: var(--bad); }
.note-cell { font-size: 11.5px; color: var(--dim); text-align: left; }

#speedChart { width: 100%; display: block; }
.caption { font-size: 12px; color: var(--dim); margin: 10px 0 0; }

.caveat-card { border-color: #5b3f12; background: rgba(70, 48, 10, .3); }
.caveat-card h2 { color: var(--warn); }
.caveat-card ul { margin: 0; padding-left: 18px; }
.caveat-card li { font-size: 13.5px; color: #d9cfb8; margin: 7px 0; }

.row-buttons { display: flex; gap: 10px; margin-top: 4px; }
.row-buttons .primary { flex: 1; margin-top: 0; }
.ghost-inline {
  padding: 14px 18px; font-size: 14px; color: var(--dim);
}
.mini.accent { color: #08090b; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.row-buttons { flex-wrap: wrap; }
.row-buttons .ghost-inline { flex: 0 0 auto; }

/* ================= upload + analysis ================= */
.or {
  display: flex; align-items: center; gap: 12px; margin: 18px 0 12px;
  color: var(--dim); font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

#uploadBtn.secondary {
  width: 100%; padding: 15px; border-radius: 10px; font-size: 15px; font-weight: 600;
  background: #15181d; color: var(--text); border: 1px solid #2f353f;
}
#uploadBtn.secondary:active { background: #1c2027; }

#analyse .video-wrap {
  position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 46vh;
  background: #000; border-radius: 12px; overflow: hidden; margin: 14px 0;
}
#analyse #playback { display: none; }
#analyse #videoView { width: 100%; height: 100%; display: block; }

.progress-outer {
  height: 6px; background: #1b1f26; border-radius: 3px; overflow: hidden; margin-top: 6px;
}
.progress-inner {
  height: 100%; width: 0%; background: var(--accent); border-radius: 3px;
  transition: width .25s ease;
}
.hud-verdict {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 14px; color: var(--text);
}
.counter-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-top: 14px;
}
.scrub-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.scrub-row input[type="range"] { flex: 1; accent-color: var(--accent); }

/* Must stay composited: opacity 0 and display:none both let iOS suspend the
   decoder, which is the bug this element exists to prevent. */
.thumb-keepalive {
  position: fixed; right: 0; bottom: 0;
  width: 2px; height: 2px; opacity: 0.01; pointer-events: none; z-index: -1;
}
.technical {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: #8b93a1; word-break: break-word; margin-top: 10px;
}
