:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --border: #262b34;
  --text: #f2f4f7;
  --muted: #8b93a1;
  --accent: #c6ff3d;
  --accent-ink: #0b0d10;
  --good: #3ddc84;
  --warn: #ffb020;
  --bad: #ff5a5f;
  --radius: 18px;
  --font: 'Inter Tight', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; letter-spacing: -0.02em; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px max(16px, env(safe-area-inset-left));
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
}

.badge {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

.view { display: flex; flex-direction: column; gap: 20px; }

.hero { padding: 24px 0 8px; }

.eyebrow {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.hero h1 { font-size: clamp(34px, 7vw, 56px); line-height: 1.02; font-weight: 800; }

.lede { color: var(--muted); max-width: 560px; margin: 16px 0 0; font-size: 17px; }

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

.setup-card { display: flex; flex-direction: column; gap: 18px; }

.field { border: 0; margin: 0; padding: 0; min-width: 0; }

.field legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0;
}

.segmented {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.segmented label { flex: 1; }

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented span {
  display: block;
  text-align: center;
  padding: 10px 8px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.segmented input:checked + span { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 16px;
  border: 1.5px dashed var(--border);
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s;
}

.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); }

.dropzone input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.dropzone-title { font-weight: 700; }

.dropzone-sub { color: var(--muted); font-size: 14px; word-break: break-word; }

.tips { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; color: var(--muted); font-size: 15px; }

.tips li { position: relative; padding-left: 16px; }

.tips li::before { content: ''; position: absolute; left: 0; top: 0.62em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.tips strong { color: var(--text); font-weight: 600; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 16px 20px;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn:disabled { opacity: 0.5; cursor: progress; }

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }

.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }

.error { color: var(--bad); margin: 0; font-size: 14px; }

.muted { color: var(--muted); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.section-head h2 { font-size: 18px; }

.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.history-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}

.history-item details { grid-column: 1 / -1; }

.history-item summary { cursor: pointer; color: var(--muted); font-size: 14px; }

.history-item pre { white-space: pre-wrap; font-family: inherit; margin: 8px 0 0; font-size: 14px; }

.score-chip {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 17px;
  background: var(--surface-2);
}

.score-good { color: var(--good); }
.score-warn { color: var(--warn); }
.score-bad { color: var(--bad); }

.history-meta { font-size: 13px; color: var(--muted); }

.stage-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 72dvh;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

@media (min-width: 720px) {
  .stage-frame { aspect-ratio: 16 / 10; }
}

.stage-frame video, .stage-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stage-frame.mirrored video, .stage-frame.mirrored canvas { transform: scaleX(-1); }

.hud { position: absolute; left: 12px; right: 12px; display: flex; justify-content: space-between; pointer-events: none; }

.hud-top { top: 12px; }

.hud-stat {
  display: flex;
  flex-direction: column;
  background: rgba(11, 13, 16, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 14px;
  min-width: 84px;
}

.hud-label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }

.hud-value { font-family: var(--mono); font-size: 30px; font-weight: 700; line-height: 1.1; }

.debug {
  position: absolute;
  top: 88px;
  left: 12px;
  background: rgba(11, 13, 16, 0.8);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  pointer-events: none;
}

.cue {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  background: rgba(11, 13, 16, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  text-align: center;
  transition: background 0.2s, color 0.2s;
}

.cue.cue-good { background: var(--good); color: #04130a; }
.cue.cue-bad { background: var(--bad); color: #fff; }

.stage-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(11, 13, 16, 0.85);
  font-weight: 600;
}

.stage-status:empty { display: none; }

.stage-controls { display: flex; flex-direction: column; gap: 10px; }

@media (min-width: 560px) {
  .stage-controls { flex-direction: row; }
  .stage-controls .btn-primary { flex: 1; }
}

.results-head { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }

.score-ring {
  --size: 132px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  background:
    radial-gradient(closest-side, var(--surface) 82%, transparent 83%),
    conic-gradient(var(--accent) calc(var(--score) * 1%), var(--surface-2) 0);
}

.score-ring span { font-family: var(--mono); font-size: 40px; font-weight: 700; line-height: 1; }

.score-ring small { color: var(--muted); font-size: 12px; margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(3, auto); gap: 8px 24px; margin: 0; }

.stats dt { color: var(--muted); font-size: 13px; }

.stats dd { margin: 0; font-family: var(--mono); font-size: 24px; font-weight: 700; }

.coach-body ul { margin: 0; padding-left: 20px; display: grid; gap: 10px; }

.coach-body li::marker { color: var(--accent); }

.rep-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.rep-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 12px;
}

.rep-num { font-family: var(--mono); color: var(--muted); font-size: 13px; }

.rep-flags { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }

.rep-flag { background: rgba(255, 90, 95, 0.12); color: var(--bad); border-radius: 999px; padding: 2px 10px; }

.rep-clean { background: rgba(61, 220, 132, 0.12); color: var(--good); border-radius: 999px; padding: 2px 10px; }

.rep-score { font-family: var(--mono); font-weight: 700; font-size: 18px; }

.rep-detail { grid-column: 2 / -1; font-family: var(--mono); font-size: 12px; color: var(--muted); }

.footer { text-align: center; font-size: 13px; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
