:root {
  --bg: #0b0f0c;
  --surface: #151b17;
  --surface-2: #1e2620;
  --text: #eef3ef;
  --muted: #9aa69d;
  --line: #2a342d;
  --primary: #34c759;
  --primary-text: #04210d;
  --danger: #ff453a;
  --accent: #ff3b30;
  --grid: rgba(255, 255, 255, 0.14);
  --trace-muted: rgba(255, 255, 255, 0.32);
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}

.topbar h1 { font-size: 18px; margin: 0; letter-spacing: 0.01em; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 68vh;
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: manipulation;
}

body[data-state="mark"] .stage { cursor: crosshair; }

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

.stage canvas { pointer-events: none; }

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background:
    radial-gradient(ellipse at 50% 120%, #1d3a24 0%, transparent 60%),
    linear-gradient(#0f1a2a, #0b0f0c);
}

.placeholder p { max-width: 32ch; margin: 0; }

.rec {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font: 600 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rec .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

.hint {
  margin: 0;
  min-height: 2.9em;
  color: var(--muted);
  font-size: 15px;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--muted); }

.scrub-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scrub-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--primary); }

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress .bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.15s linear;
}

.controls .group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  flex: 1 1 0;
  min-width: 96px;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: 600 15px/1.2 inherit;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
}

.icon-btn.small { width: 34px; height: 34px; background: var(--surface-2); }

.link-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}

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

.card h2 { font-size: 17px; margin: 0 0 8px; }

.card-head { display: flex; align-items: center; justify-content: space-between; }

#result-card h2 { font-size: 24px; color: var(--accent); }

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 16px;
  row-gap: 4px;
  align-items: baseline;
  margin: 0;
}

.stats dt { color: var(--muted); font-size: 14px; }
.stats dd { margin: 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.fine { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

.session-chart {
  width: 100%;
  height: 220px;
  display: block;
  border-radius: 10px;
  background: var(--surface-2);
}

.shot-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.shot-list li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  gap: 8px;
  padding: 8px 6px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  font-size: 15px;
}

.shot-list li.active { color: var(--accent); }
.shot-list .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.shot-list .detail { color: var(--muted); font-size: 13px; text-align: right; }

.tips summary { cursor: pointer; font-weight: 600; }
.tips ul { padding-left: 20px; margin: 10px 0 0; color: var(--muted); }
.tips li { margin-bottom: 6px; }
.tips strong { color: var(--text); }

.sheet {
  width: min(480px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 18px;
}

.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }

.sheet h2 { margin: 0 0 12px; font-size: 19px; }

.sheet form { display: flex; flex-direction: column; gap: 14px; }

.sheet label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.sheet label.row { flex-direction: row; align-items: flex-start; gap: 10px; }
.sheet label.row input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--primary); }
.sheet output { color: var(--text); font-weight: 600; }

.sheet select,
.sheet input[type="color"] {
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.sheet input[type="color"] { padding: 4px; width: 64px; }
.sheet input[type="range"] { accent-color: var(--primary); }
.sheet-actions { display: flex; justify-content: flex-end; }
.sheet-actions .btn { flex: 0 0 auto; }
