:root {
  --bg: #12170f;
  --panel: #1c2618;
  --panel-2: #243220;
  --line: #33422c;
  --ink: #e8eedf;
  --muted: #a7b59a;
  --cream: #f4ecd8;
  --good: #b6d98a;
  --watch: #e2b65c;
  --fix: #e36b4a;
  --grass: #1e3a24;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #24321c 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.brand .name {
  margin: 0;
  font-family: "Avenir Next Condensed", "Arial Narrow", sans-serif;
  font-size: 28px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand .tag { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: 0.06em; }
.brand .tag a { color: inherit; text-decoration: none; }

.ball {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffaf0, #ddd4c2 70%);
  box-shadow: inset -5px -4px 0 #c9c0ad;
  position: relative;
}
.ball::before {
  content: "";
  position: absolute;
  inset: 3px 7px;
  border: 1.5px solid #c4473b;
  border-radius: 50%;
  transform: rotate(24deg);
}

nav { display: flex; gap: 8px; }
button, select, input { font: inherit; color: var(--ink); }
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
nav button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: "Avenir Next Condensed", "Arial Narrow", sans-serif;
  cursor: pointer;
}
nav button.on { background: var(--cream); color: #1a2114; }

#status { margin-left: auto; color: var(--muted); font-size: 14px; max-width: 42ch; text-align: right; }
.account { min-width: 0; }

.view {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.85fr);
  gap: 18px;
  padding: 18px;
}
#view-sessions { grid-template-columns: minmax(280px, 0.7fr) minmax(0, 2fr); align-items: start; }
#view-machine { grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.4fr); align-items: start; }
#view-lane { grid-template-rows: auto auto; }
#view-lane .controls { grid-column: 1 / -1; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}

.stage-wrap {
  position: relative;
  background: #0d120c;
  border: 1px solid var(--line);
  border-radius: 18px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}
#live-video { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #10160e; }
.caption {
  position: absolute;
  left: 14px;
  bottom: 12px;
  margin: 0;
  color: var(--cream);
  background: rgba(12, 16, 10, 0.72);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 13px;
}

.panel-head, .switch, .buttons, .delivery-row, .session-card, .ball-row, .row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.panel-head { justify-content: space-between; flex-wrap: wrap; }
h2 { margin: 0 0 8px; font-size: 18px; letter-spacing: 0.03em; }
.row { flex-wrap: wrap; }
.row label { flex: 1 1 140px; }

.switch button, .buttons button, form button, .delivery-row button, .ball-row button, .session-card button, .account button, .pace-row button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.switch button.on, .primary, #start-camera {
  background: var(--cream) !important;
  color: #1a2114;
  border-color: var(--cream) !important;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.ghost { background: transparent !important; }
.danger { color: #f3a48d; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }

.cues { display: flex; flex-direction: column; gap: 10px; }
.cue { border-left: 4px solid var(--watch); background: #182014; border-radius: 12px; padding: 10px 12px; }
.cue.good { border-color: var(--good); }
.cue.fix { border-color: var(--fix); }
.cue h3 { margin: 0; font-size: 16px; }
.cue p { margin: 4px 0 0; }
.kicker { margin: 0; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.measure { color: var(--cream); font-variant-numeric: tabular-nums; }
.empty, .hint, .note { color: var(--muted); }
.hint, .note { font-size: 14px; }
.error { color: #f3a48d; }

.controls, .session-tools form, .machine-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select { background: #10160e; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
input[type="file"] { padding: 6px; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

.session-tools { display: flex; flex-direction: column; gap: 18px; }
.session-tools form, .machine-form { flex-direction: column; align-items: stretch; }
.session-list, .machine-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.session-card, .ball-row { justify-content: space-between; background: #182014; border-radius: 12px; padding: 10px; border: 1px solid transparent; }
.session-card.on { border-color: var(--cream); }
.session-card strong, .ball-row strong { display: block; }
.session-card span, .ball-row span { color: var(--muted); font-size: 13px; }

.review { min-width: 0; }
.video-box { position: relative; margin: 10px 0; }
.video-box video { width: 100%; max-height: 520px; border-radius: 12px; background: #000; display: block; }
#track-overlay { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
#loupe {
  position: absolute;
  width: 168px;
  height: 168px;
  border: 2px solid var(--cream);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
}
.calib-bar { background: #2b2414; border: 1px solid #6b5a2c; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.calib-bar p { margin: 0 0 6px; }
.calib-bar input { width: 90px; }

.job { margin: 10px 0; }
.job .bar { height: 8px; background: #10160e; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.job .bar span { display: block; height: 100%; width: 0; background: var(--good); transition: width 0.4s ease; }
.job p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.delivery-row { flex-wrap: wrap; margin: 10px 0; }
.delivery-row button { display: flex; flex-direction: column; align-items: center; line-height: 1.15; border-width: 2px; }
.delivery-row button small { color: var(--muted); font-size: 11px; }
.delivery-row button.on { background: var(--cream); color: #1a2114; }
.delivery-row button.on small { color: #3a4630; }
.delivery-row button.unsure { border-style: dashed; }
#outcomes button { text-transform: capitalize; }
#outcomes button.on { color: #1a2114; }

.review-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.facts dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 0 0 8px; }
.facts dt { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 0; color: var(--cream); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 11px; border-radius: 999px; padding: 1px 8px; margin-left: 4px; vertical-align: middle; }
.badge.sure { background: #2f4a25; color: var(--good); }
.badge.unsure { background: #4a3a1c; color: var(--watch); }
.pace-row input { width: 110px; }

.pitch-wrap { display: flex; flex-direction: column; gap: 8px; }
#pitch { width: 100%; max-width: 280px; height: auto; border-radius: 12px; cursor: crosshair; }
#pitch .band { fill: var(--muted); font-size: 7.5px; }

dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 18px; padding: 20px; max-width: 380px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { display: flex; flex-direction: column; gap: 12px; }

footer { padding: 0 22px 22px; color: var(--muted); font-size: 13px; }

@media (max-width: 960px) {
  header { flex-wrap: wrap; }
  #status { margin-left: 0; text-align: left; }
  .view, #view-sessions, #view-machine, .review-grid { grid-template-columns: 1fr; }
  .stage-wrap { min-height: 240px; }
}
