* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #101418;
  --panel: #1a2028;
  --panel-2: #232b36;
  --text: #e8edf2;
  --muted: #8b98a5;
  --accent: #ff8c42;
  --make: #3ddc84;
  --miss: #ff5d5d;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, sans-serif;
  min-height: 100vh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid #2a3340;
}

header h1 { font-size: 20px; letter-spacing: 0.5px; }

.status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.status.ready { color: var(--make); }
.status.loading { color: var(--accent); }
.status.error { color: var(--miss); }

main {
  display: flex;
  gap: 18px;
  padding: 18px 22px;
  align-items: flex-start;
  flex-wrap: wrap;
}

#stage-wrap { flex: 1 1 640px; min-width: 320px; }

#stage {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9; /* JS updates this to match the actual video */
  max-height: 78vh;
  margin: 0 auto;
}

#stage video, #stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#stage video { object-fit: contain; }
#stage:fullscreen {
  aspect-ratio: auto !important;
  max-width: none !important;
  max-height: none;
  border-radius: 0;
}
#overlay { pointer-events: none; }
#overlay.rim-mode { pointer-events: auto; cursor: crosshair; touch-action: none; }

#stage-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  padding: 20px;
}

#hud {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 13, 17, 0.62);
  backdrop-filter: blur(4px);
  border-radius: 999px;
  padding: 4px 18px;
  font-size: clamp(16px, 4.5vw, 30px);
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
  pointer-events: none;
}
#hud.hidden { display: none; }
#hud.idle { opacity: 0.6; }
#hud .hud-pct { color: var(--accent); }
#hud .hud-count { color: var(--text); font-weight: 600; }
#hud .hud-paused { color: var(--muted); font-size: 0.55em; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
#hud .hud-rec { color: var(--miss); animation: rec-blink 1.6s infinite; }
@keyframes rec-blink { 0%, 60% { opacity: 1; } 80% { opacity: 0.25; } 100% { opacity: 1; } }

#btn-fullscreen {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: rgba(10, 13, 17, 0.55);
  border: none;
  border-radius: 8px;
  z-index: 2;
}
#btn-fullscreen.hidden { display: none; }

#stage-toast {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 140, 66, 0.92);
  color: #14100c;
  font-size: clamp(13px, 3.5vw, 16px);
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}
#stage-toast.hidden { display: none; }

#flash {
  position: absolute;
  top: 12%;
  width: 100%;
  text-align: center;
  font-size: 64px;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#flash.show { opacity: 1; }
#flash.make { color: var(--make); }
#flash.miss { color: var(--miss); }

#video-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}
#video-controls.hidden { display: none; }
#video-controls button {
  width: 42px; height: 32px;
  font-size: 15px;
}
#seek { flex: 1; accent-color: var(--accent); }

#panel {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#scoreboard {
  background: var(--panel);
  border-radius: 10px;
  padding: 18px;
}

.stat { text-align: center; }
.stat.big .stat-value { font-size: 56px; font-weight: 800; color: var(--accent); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: 1px; margin-top: 2px; }
.stat-row { display: flex; justify-content: space-around; margin-top: 14px; }

#shot-history {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  min-height: 16px;
}
#shot-history .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
}
#shot-history .dot.make { background: var(--make); }
#shot-history .dot.miss { background: var(--miss); }

#controls {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

button, .file-btn {
  background: var(--panel-2);
  border: 1px solid #303c4a;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  user-select: none;
}
button:hover:not(:disabled), .file-btn:hover { background: #2c3644; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary, .file-btn.primary { border-color: var(--accent); }
button.active { background: var(--accent); color: #14100c; border-color: var(--accent); }

.toggle { font-size: 13px; color: var(--muted); display: flex; gap: 7px; align-items: center; cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.track-btn {
  font-weight: 800;
  font-size: 16px;
  padding: 13px 12px;
  background: #1d4030;
  border-color: var(--make);
  color: var(--make);
}
.track-btn.on {
  background: #46201e;
  border-color: var(--miss);
  color: var(--miss);
}
.hidden { display: none !important; }

/* ---------- Shot replay list ---------- */
#shots-panel {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px;
}
#shots-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#shot-filters { display: flex; gap: 5px; }
.chip {
  padding: 4px 11px;
  font-size: 12px;
  border-radius: 999px;
}
.chip.active { background: var(--accent); color: #14100c; border-color: var(--accent); }
#shot-list { margin-top: 10px; max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.shot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.shot-row:hover { border-color: #3a4756; }
.shot-row .r-icon { font-size: 15px; }
.shot-row.make .r-icon { color: var(--make); }
.shot-row.miss .r-icon { color: var(--miss); }
.shot-row .r-time { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.shot-row .r-play { color: var(--accent); }
.shot-row.expired { opacity: 0.45; cursor: default; }
#shot-list .empty { color: var(--muted); font-size: 12.5px; text-align: center; padding: 8px; }

/* ---------- Replay overlay ---------- */
#replay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 8, 11, 0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
#replay-box {
  width: min(100%, 960px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#replay-bar { display: flex; align-items: center; gap: 8px; }
#replay-bar .spacer { flex: 1; }
#replay-title { font-weight: 700; font-size: 15px; }
#replay-bar button { min-width: 44px; height: 38px; font-size: 16px; }
#replay-bar button.on { background: var(--accent); color: #14100c; border-color: var(--accent); }
#replay-video {
  width: 100%;
  max-height: 78vh;
  border-radius: 10px;
  background: #000;
  object-fit: contain;
}

#help {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}
#help summary { color: var(--text); font-weight: 700; cursor: pointer; user-select: none; }
#help b { color: var(--text); }
#help ol { margin: 8px 0 0 18px; }
#debug-line { margin-top: 10px; font-family: ui-monospace, monospace; font-size: 11px; min-height: 14px; }

/* ---------- Touch devices: bigger targets ---------- */
@media (pointer: coarse) {
  button, .file-btn {
    padding: 13px 14px;
    font-size: 16px;
    border-radius: 10px;
  }
  .toggle { font-size: 15px; padding: 4px 0; }
  .toggle input { width: 20px; height: 20px; }
  #video-controls button { width: 52px; height: 44px; }
  #seek { height: 30px; }
}

/* ---------- Narrow screens (phones, portrait) ---------- */
@media (max-width: 700px) {
  header { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  header h1 { font-size: 17px; }
  main { flex-direction: column; padding: 10px; gap: 10px; }
  #stage-wrap { flex: none; width: 100%; min-width: 0; }
  #panel { flex: none; width: 100%; }

  /* The HUD over the video carries the headline number; keep the
     scoreboard compact — one row, no giant duplicate percentage. */
  #scoreboard { padding: 12px; }
  .stat.big .stat-value { font-size: 34px; }
  .stat-row { margin-top: 8px; }
  .stat-value { font-size: 21px; }

  /* Controls: 2-column grid of thumb-sized buttons */
  #controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  #controls .toggle { grid-column: span 1; justify-content: center; }
  #controls .track-btn { grid-column: span 2; }
}

/* ---------- Phone landscape: video beside a slim panel ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  header { display: none; }
  main { flex-wrap: nowrap; padding: 8px; gap: 10px; }
  #stage { max-height: calc(100vh - 16px); }
  #panel { flex: 0 0 230px; overflow-y: auto; max-height: calc(100vh - 16px); }
  #help { display: none; }
  .stat.big .stat-value { font-size: 34px; }
}
