:root {
  color-scheme: dark;
  --ink: #f4fbf7;
  --muted: #9eb2a8;
  --panel: rgba(9, 24, 18, 0.86);
  --panel-solid: #0d1f17;
  --line: rgba(220, 255, 236, 0.16);
  --lime: #b6f14a;
  --mint: #36d399;
  --gold: #f7c948;
  --danger: #ff6b6b;
  --court: #266f43;
  --kitchen: #2f83a3;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #07130f;
  color: var(--ink);
}

button, select, input { font: inherit; }

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(320px, 58vw) minmax(360px, 42vw);
}

.capture-stage {
  position: sticky;
  top: 0;
  height: 100svh;
  overflow: hidden;
  background: #050907;
}

video, #overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlayCanvas { z-index: 2; }

.stage-shade {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: linear-gradient(180deg, rgba(0,0,0,.72), transparent 34%, transparent 58%, rgba(0,0,0,.76));
  pointer-events: none;
}

.top-bar, .sensor-card, .control-panel {
  position: relative;
  z-index: 4;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: max(18px, env(safe-area-inset-top)) 18px 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--lime);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; }
h2 { margin-bottom: 5px; font-size: 22px; }
h3 { margin-bottom: 4px; font-size: 16px; }
p { color: var(--muted); line-height: 1.45; }

.status-pill {
  border: 1px solid var(--line);
  background: rgba(0,0,0,.45);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  white-space: nowrap;
}

.sensor-card {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  backdrop-filter: blur(16px);
}

.meter-row {
  display: grid;
  grid-template-columns: auto 1fr 42px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.meter-track {
  height: 9px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
}

.meter-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--gold), var(--danger));
}

.sensor-grid, .summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.sensor-grid div, .summary-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255,255,255,.04);
}

.sensor-grid span, .summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sensor-grid strong, .summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.control-panel {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
}

button, select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 44px;
  color: var(--ink);
  background: #12271e;
}

button {
  padding: 0 14px;
  cursor: pointer;
}

button:disabled { opacity: .48; cursor: not-allowed; }

.primary-button {
  border-color: rgba(182,241,74,.68);
  background: var(--lime);
  color: #102009;
  font-weight: 800;
}

.secondary-button {
  background: #173e2c;
  border-color: rgba(54,211,153,.45);
}

.ghost-button { background: transparent; }
.icon-button { min-width: 68px; }

.workspace {
  min-height: 100svh;
  padding: 18px;
  background: radial-gradient(circle at top left, rgba(54,211,153,.12), transparent 30%), #0a1712;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 18px;
}

.tab {
  min-height: 40px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
}

.tab.active {
  color: var(--ink);
  border-color: rgba(182,241,74,.45);
  background: rgba(182,241,74,.12);
}

.view { display: none; }
.view.active { display: block; }

.section-heading { margin-bottom: 16px; }

.setup-grid {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

select {
  width: 100%;
  padding: 0 12px;
}

input[type="range"] { width: 100%; accent-color: var(--lime); }

.toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.calibration-panel, .data-note, .rally-card {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-solid);
}

.calibration-panel {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.data-note {
  color: var(--muted);
  line-height: 1.45;
}

.data-note.warning {
  border-color: rgba(247, 201, 72, .36);
  color: #eadfbd;
}

.timeline {
  position: relative;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #07110d;
  overflow: hidden;
}

.hit-marker {
  position: absolute;
  top: 16px;
  width: 4px;
  height: 60px;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 18px rgba(247,201,72,.45);
}

.court-map {
  position: relative;
  margin-top: 14px;
  aspect-ratio: 22 / 44;
  max-height: 62svh;
  border: 3px solid rgba(242,255,231,.8);
  background: var(--court);
  overflow: hidden;
}

.court-map::before {
  content: "";
  position: absolute;
  inset: 0 50% 0 auto;
  width: 1px;
  background: rgba(242,255,231,.62);
}

.court {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 2px solid rgba(242,255,231,.78);
  border-bottom: 2px solid rgba(242,255,231,.78);
  background: rgba(47,131,163,.38);
}

.kitchen-top { top: 34%; height: 16%; }
.kitchen-bottom { top: 50%; height: 16%; }
.net { top: 50%; height: 0; border-bottom: 3px solid rgba(255,255,255,.9); background: transparent; }

.court-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(247,201,72,.2);
}

.rally-list { display: grid; gap: 10px; margin-top: 14px; }

.rally-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.rally-card p { margin-bottom: 0; }

.winner-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.winner-buttons button {
  min-height: 36px;
  font-size: 13px;
}

.winner-buttons button.active {
  background: var(--lime);
  color: #102009;
  font-weight: 800;
}

.export-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .capture-stage { position: relative; height: 62svh; min-height: 480px; }
  .workspace { min-height: 38svh; }
  .calibration-panel { grid-template-columns: 1fr; }
  .rally-card { grid-template-columns: 1fr; }
  .winner-buttons { justify-content: flex-start; }
}
