:root {
  --bg: #0b0f14;
  --panel: rgba(12, 17, 24, 0.78);
  --panel-solid: #121924;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f3f6fa;
  --muted: #9aa7b6;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --accent: #38bdf8;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button, select, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; height: 100dvh; }
#view { position: absolute; inset: 0; }
#view.mirror { transform: scaleX(-1); }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: cover; background: #000; }

/* HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,.65), transparent);
}
.reps { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.reps span { font-size: 34px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.reps small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.status { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pill {
  align-self: flex-start; padding: 3px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-weight: 600; font-size: 13px;
}
.pill.descending, .pill.ascending { background: var(--accent); color: #04121c; border-color: transparent; }
.pill.depth { background: var(--good); color: #04140a; border-color: transparent; }
.meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-actions { display: flex; gap: 8px; }
button.icon {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); display: grid; place-items: center; padding: 0;
}
button.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

#warning {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 78px); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 12px;
  background: rgba(245, 158, 11, .92); color: #1a1000; font-weight: 600; text-align: center; font-size: 14px;
}
#warning.info { background: var(--panel); color: var(--text); border: 1px solid var(--line); font-weight: 500; }

/* Depth gauge */
#gauge {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
#gauge .track {
  position: relative; width: 14px; height: 34dvh; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); overflow: hidden;
}
#gauge .fill { position: absolute; left: 0; right: 0; top: 0; height: 0; background: var(--accent); transition: height .08s linear; }
#gauge .fill.hit { background: var(--good); }
#gauge .target { position: absolute; left: -2px; right: -2px; height: 3px; background: #fff; box-shadow: 0 0 0 1px #000; }
.gauge-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg); }

/* Dock */
#dock {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 24px 12px calc(var(--safe-b) + 12px);
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(to top, rgba(0,0,0,.75) 60%, transparent);
}
.live { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.live div {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 4px; display: flex; flex-direction: column; align-items: center;
}
.live span { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.live small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.rep-card {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; min-height: 72px;
}
.rep-card.flash { animation: flash .6s ease-out; }
@keyframes flash { from { transform: scale(1.03); border-color: #fff; } to { transform: none; } }
.score {
  flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  font-size: 20px; font-weight: 800; border: 3px solid var(--muted); font-variant-numeric: tabular-nums;
}
.score.good { border-color: var(--good); color: var(--good); }
.score.ok { border-color: var(--warn); color: var(--warn); }
.score.bad { border-color: var(--bad); color: var(--bad); }
.rep-body { min-width: 0; }
.cue { font-weight: 700; font-size: 16px; }
.rep-card.empty .cue { font-weight: 500; color: var(--muted); font-size: 14px; }
#repFaults { margin: 2px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
#repFaults li::before { content: "• "; }
#repFaults li.ok { color: var(--good); }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.controls button, button.primary {
  min-height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 600;
}
button.primary { background: var(--good); color: #04140a; border: 0; font-size: 17px; width: 100%; }
button:active { transform: scale(.98); }
button:disabled { opacity: .6; }

/* Start screen */
.screen {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 20%, #13202e, var(--bg) 70%);
  overflow-y: auto;
}
.card { width: 100%; max-width: 440px; }
.card h1 { margin: 0 0 6px; font-size: 32px; }
.lede { color: var(--muted); margin: 0 0 16px; }
.tips { margin: 0 0 22px; padding-left: 20px; display: grid; gap: 8px; }
.status-line { min-height: 1.4em; color: var(--muted); text-align: center; margin: 12px 0 0; }
.status-line.error { color: var(--bad); }

/* Sheets */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 80dvh; overflow-y: auto;
  background: var(--panel-solid); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(var(--safe-b) + 18px); display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 20px; }
.close { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
.sheet label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.sheet label.row { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.sheet select { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; }
.sheet input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--good); }
.fine { color: var(--muted); font-size: 13px; margin: 0; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary div { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.summary strong { display: block; font-size: 20px; }
.summary small { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.rep-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.rep-list li { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.rep-list .row1 { display: flex; justify-content: space-between; font-weight: 700; }
.rep-list .row2 { color: var(--muted); font-size: 13px; margin-top: 2px; }
.rep-list .good { color: var(--good); }
.rep-list .ok { color: var(--warn); }
.rep-list .bad { color: var(--bad); }
.rep-list .faults { font-size: 13px; margin-top: 4px; }
.empty-note { color: var(--muted); text-align: center; padding: 12px 0; }

@media (min-aspect-ratio: 1/1) {
  #gauge .track { height: 50dvh; }
  #dock { left: auto; width: min(420px, 50%); }
}
