:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #17202b;
  --muted: #586273;
  --line: #dde2e9;
  --accent: #0e7a52;
  --accent-soft: #e3f3ec;
  --ok: #0e7a52;
  --warn: #a86200;
  --warn-soft: #fff3dc;
  --bad: #bf3329;
  --bad-soft: #fde8e6;
  --stage: #0d1016;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { min-height: 100vh; line-height: 1.5; font-size: 15px; }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
p { margin: 0 0 10px; }
button, select, input { font: inherit; color: inherit; }

/* Header and step navigation */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.steps { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.steps button {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px;
  border: 0; border-radius: 999px; background: none;
  color: var(--muted); white-space: nowrap; cursor: pointer;
}
.steps button b {
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--line); color: var(--ink); font-size: 0.8rem;
}
.steps button:hover:not(:disabled) { background: var(--bg); }
.steps button.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.steps button.current b, .steps button.done b { background: var(--accent); color: #fff; }
.steps button:disabled { opacity: 0.45; cursor: not-allowed; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }
.lead { max-width: 760px; margin-bottom: 18px; }
.lead p { color: var(--muted); }

/* Cards and lists */
.cards { display: grid; gap: 16px; margin-bottom: 16px; }
.cards.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.cards .card { margin-bottom: 0; }
.figure { margin-bottom: 14px; border-radius: 8px; overflow: hidden; background: #eef1f5; }
.figure svg { display: block; width: 100%; height: auto; }
.template { display: block; width: 100%; aspect-ratio: 16 / 9; }
.points, .checks { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.points li { position: relative; padding-left: 22px; }
.checks li { position: relative; padding-left: 28px; }
.points li::before {
  content: ""; position: absolute; left: 6px; top: 0.62em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.checks li::before {
  content: ""; position: absolute; left: 2px; top: 0.3em;
  width: 13px; height: 13px; border: 2px solid var(--accent); border-radius: 4px;
}
.note { color: var(--muted); font-size: 0.87rem; margin: 10px 0 0; }

/* Controls */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions.end { justify-content: flex-end; }
.btn {
  padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 600;
}
.btn:hover:not(:disabled) { border-color: #b8c0cc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #0b6846; }
.btn.small { padding: 6px 11px; font-size: 0.87rem; font-weight: 500; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { margin: 12px 0; }
.field.inline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field-label { display: block; font-size: 0.87rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field.inline .field-label { margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
select, input[type="number"] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  max-width: 100%;
}
input[type="number"] { width: 110px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0; cursor: pointer; }
.check input { margin-top: 0.3em; accent-color: var(--accent); }

.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: #e8ebf0; flex-wrap: wrap; }
.segmented button {
  padding: 6px 13px; border: 0; border-radius: 8px; background: none; cursor: pointer; white-space: nowrap;
}
.segmented button.on { background: var(--surface); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 14%); }
.segmented.dark { background: rgb(255 255 255 / 18%); }
.segmented.dark button { color: #fff; }
.segmented.dark button.on { background: #fff; color: var(--ink); }

/* Upload */
.dropzone {
  display: grid; gap: 4px; place-items: center; text-align: center;
  padding: 44px 20px; margin-bottom: 16px;
  border: 2px dashed #b8c0cc; border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.loading { opacity: 0.6; pointer-events: none; }
.dropzone input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone strong { font-size: 1.1rem; }
.dropzone span { color: var(--muted); font-size: 0.9rem; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.flags, .checklist, .point-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.flags li, .alert {
  padding: 9px 12px 9px 36px; border-radius: 8px; position: relative;
  background: var(--accent-soft); font-size: 0.92rem;
}
.flags li::before, .alert::before {
  content: "✓"; position: absolute; left: 12px; top: 8px; font-weight: 700; color: var(--ok);
}
.flags li.warn, .alert.warn { background: var(--warn-soft); }
.flags li.warn::before, .alert.warn::before { content: "!"; color: var(--warn); }
.flags li.bad, .alert.bad { background: var(--bad-soft); }
.flags li.bad::before, .alert.bad::before { content: "✕"; color: var(--bad); }
.alert { margin: 12px 0 0; }
.flags li.info, .alert.info { background: #eceff3; }
.flags li.info::before, .alert.info::before { content: "i"; color: var(--muted); }
.alert:empty { display: none; }

/* Workspace: frame viewer plus side panel */
.work { display: grid; grid-template-columns: minmax(0, 1fr) 372px; gap: 16px; align-items: start; }
.stage { min-width: 0; }
.canvas-wrap {
  position: relative; background: var(--stage); border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; max-height: 74vh; width: 100%;
}
#viewer { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.busy {
  position: absolute; left: 10px; bottom: 10px; padding: 5px 10px; border-radius: 8px;
  background: rgb(0 0 0 / 65%); color: #fff; font-size: 0.85rem; pointer-events: none;
}
.task {
  margin: 0 0 8px; padding: 9px 12px; border-radius: 9px;
  background: #fff7d1; border: 1px solid #f0dc7a; font-weight: 600;
}
.task:empty { display: none; }
.framebar, .viewbar { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.viewbar { justify-content: space-between; }
.framebar button, .zoom button {
  min-width: 40px; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.framebar input[type="range"] { flex: 1; min-width: 60px; accent-color: var(--accent); }
.zoom { display: flex; gap: 6px; }
#frame-label { font-variant-numeric: tabular-nums; font-size: 0.87rem; color: var(--muted); }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.panel p { font-size: 0.92rem; }

.mini-court { border-radius: 8px; overflow: hidden; background: #eef1f5; }
.mini-court svg { display: block; width: 100%; height: auto; }
.mini-court .floor { fill: #2f7d5b; }
.mini-court .hitter-half { fill: rgb(255 221 51 / 24%); }
.mini-court .court-line { stroke: #fff; stroke-width: 1.1; }
.mini-court .net { stroke: #17202b; stroke-width: 2.6; }
.mini-court .caption { font-size: 10.5px; fill: var(--muted); }
.mini-court .ref { fill: #fff; stroke: #17202b; stroke-width: 1.2; }
.mini-court .ref.suggested { fill: #ffdd33; }
.mini-court .ref.placed { fill: #17202b; stroke: #fff; }
.mini-court .ref.active { stroke: #ff3b6b; stroke-width: 3; }
.mini-court .hit { fill: transparent; cursor: pointer; }
.mini-court .post-link { stroke: #17202b; stroke-width: 1; stroke-dasharray: 2.5 2; }
.active-point { margin: 10px 0; padding: 9px 12px; border-radius: 8px; background: #fff7d1; font-weight: 600; }
.active-point small { display: block; font-weight: 400; color: var(--muted); }

.point-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px 5px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 0.87rem;
}
.point-list li span { flex: 1; min-width: 0; }
.point-list li em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.point-list li em.warn { color: var(--warn); font-weight: 600; }
.point-list li em.bad { color: var(--bad); font-weight: 600; }
.point-list li.here { border-color: var(--accent); background: var(--accent-soft); }
.point-list button {
  width: 26px; height: 26px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--muted);
}
.point-list button:hover { background: var(--bad-soft); color: var(--bad); }
.point-list .jump { width: auto; padding: 0 6px; color: var(--accent); }
.point-list .jump:hover { background: var(--accent-soft); color: var(--accent); }

.report { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.badge { padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--accent-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.checklist li { display: grid; grid-template-columns: 18px 1fr auto; gap: 2px 8px; font-size: 0.9rem; align-items: start; }
.checklist li::before { content: "✓"; font-weight: 700; color: var(--ok); }
.checklist li.warn::before { content: "!"; color: var(--warn); }
.checklist li.bad::before { content: "✕"; color: var(--bad); }
.checklist li em { font-style: normal; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.checklist li small { grid-column: 2 / -1; color: var(--ink); background: var(--warn-soft); padding: 5px 8px; border-radius: 6px; }
.checklist li.bad small { background: var(--bad-soft); }

.tools { display: grid; gap: 8px; margin: 12px 0; }
.tools button {
  display: grid; grid-template-columns: 16px 1fr auto; gap: 10px; align-items: start; text-align: left;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer;
}
.tools button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tools small { display: block; color: var(--muted); font-size: 0.84rem; }
.tools i { font-style: normal; font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.tools i.set { color: var(--ok); font-weight: 700; }
.swatch { width: 14px; height: 14px; border-radius: 50%; margin-top: 4px; border: 2px solid #17202b; }
.swatch.feet { background: #ff9f1c; border-radius: 3px; }
.swatch.contact { background: #ff3b6b; }
.swatch.flight { background: #ffdd33; }
.swatch.fall { background: #7fe3ff; }

.preview { margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--bg); }
.preview strong { font-size: 1.5rem; }
.preview small { display: block; color: var(--muted); }
.preview small.ok, .preview small.bad { margin-top: 8px; }
.preview small.bad { color: var(--bad); font-weight: 600; }

/* Result */
.result-head {
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; margin-bottom: 16px;
}
.result-head .speed { font-size: 3.4rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.result-head .speed span { font-size: 1.3rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.result-head .range { color: var(--muted); margin-top: 8px; }
.result-head .caption { color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
.grade { text-align: center; padding: 12px 18px; border-radius: 12px; background: var(--accent-soft); color: var(--ok); }
.grade b { display: block; font-size: 2.2rem; line-height: 1; }
.grade.B { background: #e8f1fb; color: #1d5fa8; }
.grade.C { background: var(--warn-soft); color: var(--warn); }
.grade.D { background: var(--bad-soft); color: var(--bad); }
#result-warnings .alert { margin: 0 0 8px; }
#result-warnings { margin-bottom: 16px; }

.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.84rem; }
.table tfoot td { font-weight: 700; border-bottom: 0; }
.scroll { overflow-x: auto; }

/* Plan drawing in the guide */
.plan-court { fill: #2f7d5b; }
.plan-zone { fill: rgb(255 221 51 / 20%); }
.plan-line { stroke: #fff; stroke-width: 1.6; }
.plan-net { stroke: #17202b; stroke-width: 3.5; }
.plan-fov { fill: rgb(14 122 82 / 12%); }
.plan-ray { stroke: var(--accent); stroke-width: 1.3; stroke-dasharray: 6 5; }
.plan-dim { stroke: #17202b; stroke-width: 1.4; }
.plan-dim.on-court { stroke: #fff; stroke-dasharray: 4 4; }
.plan-tick { stroke: #17202b; stroke-width: 1.8; }
.plan-tick.on-court { stroke: #fff; }
.plan-dim-label { font-size: 15px; font-weight: 700; fill: var(--ink); }
.plan-label { font-size: 14px; fill: var(--ink); }
.plan-label.strong { font-weight: 700; }
.plan-label.on-court { fill: #fff; paint-order: stroke; stroke: rgb(0 0 0 / 55%); stroke-width: 3px; }
.plan-smash { stroke: #ffdd33; stroke-width: 3.5; }
.plan-arrow-head { fill: #ffdd33; }
.plan-player { fill: #fff; stroke: #17202b; stroke-width: 2; }
.plan-feeder { fill: #c9d1dc; stroke: #17202b; stroke-width: 1.5; }
.plan-camera rect { fill: #17202b; }
.plan-lens { fill: #7fe3ff; }

/* Live camera */
.livecam { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; }
.livecam video, .livecam canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.livecam video { object-fit: contain; }
.livecam-top, .livecam-bottom {
  position: absolute; left: 0; right: 0; display: flex; gap: 10px; align-items: center;
  padding: 12px max(14px, env(safe-area-inset-left));
}
.livecam-top { top: 0; justify-content: space-between; background: linear-gradient(rgb(0 0 0 / 70%), transparent); }
.livecam-bottom { bottom: 0; flex-direction: column; align-items: flex-start; gap: 2px; background: linear-gradient(transparent, rgb(0 0 0 / 75%)); }
.livecam-bottom p { margin: 0; }
.livecam .btn { color: var(--ink); }
#livecam-status { font-weight: 700; }
.livecam-hint { font-size: 0.85rem; opacity: 0.85; }

/* The decoder video must stay rendered for frame callbacks to fire, so hide it visually only. */
.decoder { position: fixed; left: 0; bottom: 0; width: 4px; height: 4px; opacity: 0.01; pointer-events: none; }

/* On a wide screen the panel scrolls by itself, so the picture never scrolls out of view. */
@media (min-width: 981px) {
  .panel { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; }
}
@media (max-width: 980px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .cards.two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
  .steps button span { display: none; }
  .steps button.current span { display: inline; }
  main { padding: 16px 12px 48px; }
  .result-head { grid-template-columns: 1fr; }
  .facts { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .result-head .speed { font-size: 2.6rem; }
  .framebar { flex-wrap: wrap; }
  .framebar input[type="range"] { order: -1; flex-basis: 100%; }
  .framebar button { flex: 1; }
}

/* Account, leaderboard and clips */
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.account-user { display: inline-flex; align-items: center; gap: 8px; }
.link {
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px;
}
.dev-login { display: flex; gap: 6px; }
.dev-login input, .dialog input[type="text"] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-width: 0;
}
.dialog input[type="text"] { width: 100%; margin: 6px 0 4px; font-size: 1.05rem; }
.muted { color: var(--muted); font-weight: 500; }

.board th:nth-child(2), .board td:nth-child(2) { text-align: left; }
.board td small { color: var(--muted); }
.grade-chip { display: inline-block; min-width: 26px; padding: 1px 8px; border-radius: 999px; font-weight: 700; text-align: center; background: var(--accent-soft); color: var(--ok); }
.grade-chip.B { background: #e8f1fb; color: #1d5fa8; }
.grade-chip.C { background: var(--warn-soft); color: var(--warn); }
.grade-chip.D { background: var(--bad-soft); color: var(--bad); }

.video-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.video-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.video-list li > span { flex: 1; min-width: 0; }
.video-list small { display: block; color: var(--muted); }
.video-list em { font-style: normal; font-size: 0.84rem; color: var(--muted); }
.video-list em.warn { color: var(--warn); font-weight: 600; }
.video-list li.empty { color: var(--muted); border-bottom: 0; }

.dialog {
  width: min(440px, calc(100vw - 32px)); padding: 20px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.dialog.wide { width: min(860px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(13 16 22 / 55%); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; }
.player { display: block; width: 100%; max-height: 60vh; border-radius: 8px; background: var(--stage); }

@media (max-width: 640px) {
  .account { margin-left: 0; }
  .dialog { padding: 14px; }
}
