:root {
  color-scheme: dark;
  --bg: #0b0c0e;
  --surface: rgba(20, 22, 26, 0.86);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f2f3f5;
  --text-dim: rgba(242, 243, 245, 0.6);
  --accent: #3ddc84;
  --accent-dim: rgba(61, 220, 132, 0.35);
  --danger: #ff5c5c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  background: #000;
}

/* Start screen */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  background: radial-gradient(circle at 50% 30%, #14171a 0%, #000 75%);
  padding: 24px;
}

.start-card {
  max-width: 360px;
  text-align: center;
}

.start-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}

.start-card p {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 28px;
}

.btn-primary {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #04150a;
  font-size: 17px;
  font-weight: 600;
  padding: 14px 40px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-primary:active { transform: scale(0.97); }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 16px;
  min-height: 1em;
}

/* Video layers */
#liveVideo, #replayVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#replayVideo { z-index: 10; }
#liveVideo { z-index: 5; }

/* Status pill */
.pill {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.pill-replay { background: rgba(61, 220, 132, 0.16); border-color: var(--accent-dim); color: var(--accent); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-dim);
  animation: pulse 1.6s infinite;
}

.dot.detecting { background: #ffb020; }
.dot.hit { background: var(--danger); animation: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--accent-dim); }
  70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

/* Controls */
.controls {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 18px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn-main {
  width: 60px;
  height: 60px;
  font-size: 24px;
  background: var(--accent);
  color: #04150a;
  border-color: transparent;
}

.icon-btn:active { transform: scale(0.94); }
.icon-btn.small { width: 30px; height: 30px; font-size: 13px; }

/* Settings panel */
.settings-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  background: var(--surface);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px max(20px, env(safe-area-inset-bottom));
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.meter-row label {
  width: 52px;
  font-size: 12px;
  color: var(--text-dim);
}

.meter {
  position: relative;
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: visible;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 60ms linear;
}

.meter-mark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--danger);
  left: 50%;
}

.slider-row {
  display: grid;
  grid-template-columns: 130px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.slider-row label {
  font-size: 12px;
  color: var(--text-dim);
}

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

.slider-val {
  font-size: 12px;
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.hint-text {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
  margin: 6px 0 0;
}

.btn-secondary {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-secondary:active { transform: scale(0.96); }

.settings-section { margin-bottom: 14px; }

.calib-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Calibration overlay */
.calib-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(6, 7, 9, 0.97);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.calib-card {
  position: relative;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.calib-close {
  position: absolute;
  top: -8px;
  right: 0;
}

.calib-card h2 {
  font-size: 20px;
  margin: 0 0 10px;
}

.calib-card p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}

.calib-step { padding-top: 8px; }

#calibPreviewVideo {
  width: 100%;
  max-height: 200px;
  border-radius: 12px;
  background: #000;
  object-fit: contain;
  margin-bottom: 12px;
}

.calib-chart {
  width: 100%;
  height: 90px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 16px;
}

.marker-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  text-align: left;
}

.marker-label {
  font-size: 12px;
  font-weight: 700;
  position: relative;
  padding-left: 14px;
}

.marker-label::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.marker-start::before { background: #4da3ff; }
.marker-top::before { background: #b26bff; }
.marker-impact::before { background: var(--danger); }
.marker-end::before { background: var(--accent); }

.marker-row input[type="range"] { width: 100%; }
#markerStart { accent-color: #4da3ff; }
#markerTop { accent-color: #b26bff; }
#markerImpact { accent-color: var(--danger); }
#markerEnd { accent-color: var(--accent); }

.calib-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.calib-actions button { flex: 1; }

[hidden] { display: none !important; }
