:root {
  --bg: #061319;
  --bg-2: #0c2029;
  --card: #10262f;
  --card-2: #143038;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eaf4f6;
  --muted: #93aab2;
  --accent: #38e0a6;
  --accent-2: #48b6ff;
  --warn: #ffd659;
  --bad: #ff7a6b;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }

body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(180deg, #071820 60%, rgba(7, 24, 32, 0.9));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; }
.brand b { display: block; font-size: 17px; letter-spacing: 0.2px; }
.brand small { display: block; color: var(--muted); font-size: 12px; max-width: 46vw; }

.steps {
  position: sticky;
  top: 62px;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 12px;
  background: rgba(6, 19, 25, 0.94);
  border-bottom: 1px solid var(--line);
}

.step-tab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 4px;
  min-height: 44px; // comfortable thumb target for the main navigation
  font-size: 13px;
  font-weight: 600;
}

.step-tab.is-active { background: var(--accent); border-color: var(--accent); color: #04231a; }
.step-tab[disabled] { opacity: 0.45; }

main { max-width: 1000px; margin: 0 auto; padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }

.panel { display: none; }
.panel.is-active { display: block; animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

h2 { font-size: 22px; margin: 6px 0 4px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.lead { font-size: 16px; margin: 0 0 10px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--accent); margin: 0 0 6px; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.btn.big { flex: 1 1 220px; min-height: 52px; font-size: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04231a; }
.btn.danger { background: #b8352c; border-color: #d2473c; color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active { transform: translateY(1px); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}

.tips ol { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.tips li { margin: 6px 0; }

.settings { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.settings select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  min-height: 44px;
}
.check { flex-direction: row; align-items: center; gap: 10px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* contain: a portrait phone clip must be letterboxed, not stretched. The skeleton
   overlay assumes letterboxing when it maps video pixels onto the canvas. */
.preview, .clip { width: 100%; max-height: 46vh; object-fit: contain; background: #000; border-radius: 12px; border: 1px solid var(--line); }
/* Keeps the video box equal to its content box, so the skeleton overlay lines up. */
.clip { margin-inline: auto; height: auto; }

.stage { position: relative; margin: 12px 0; }
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}
#calib-canvas { position: relative; width: 100%; height: auto; background: #000; border-radius: 12px; }

#scrub { flex: 1; accent-color: var(--accent); }

.progress { height: 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s; }

.status { min-height: 22px; font-size: 14px; color: var(--muted); }
.status.error { color: var(--bad); }
.status.ok { color: var(--accent); }

.score-card { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.dial-wrap { position: relative; width: 96px; height: 96px; }
.dial { width: 96px; height: 96px; }
.dial-value { position: absolute; inset: 0; display: grid; place-items: center; font-size: 26px; font-weight: 700; }
.score-meta { flex: 1 1 260px; }

ul.kv { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 6px 14px; }
ul.kv li { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--line); padding: 5px 0; font-size: 14px; }
ul.kv li b { font-variant-numeric: tabular-nums; }

.bar-row { display: grid; grid-template-columns: 96px 1fr 40px; gap: 10px; align-items: center; margin: 8px 0; font-size: 13px; }
.bar { height: 10px; border-radius: 999px; background: var(--bg-2); overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; }
.bar i.good { background: var(--accent); }
.bar i.mid { background: var(--warn); }
.bar i.bad { background: var(--bad); }
.bar i.na { background: transparent; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

.top-fix { border-color: var(--accent); background: linear-gradient(180deg, rgba(56, 224, 166, 0.14), var(--card)); }
.top-fix h2 { margin: 2px 0 8px; }

.finding { border: 1px solid var(--line); border-left-width: 4px; border-radius: 12px; padding: 12px; margin: 10px 0; background: var(--card-2); }
.finding.high { border-left-color: var(--bad); }
.finding.medium { border-left-color: var(--warn); }
.finding.low { border-left-color: var(--accent-2); }
.finding.good { border-left-color: var(--accent); }
.finding h4 { margin: 0 0 6px; font-size: 16px; display: inline; }
.finding header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.finding p { margin: 6px 0; font-size: 15px; }
.finding .drill { color: var(--muted); font-size: 14px; }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  white-space: nowrap;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 4px solid var(--chip, var(--accent));
  background: var(--card-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  min-height: 40px;
}
.chip.is-active { outline: 2px solid var(--warn); }
.chip-kind { color: var(--muted); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.shot-ref { border: 1px solid var(--line); background: var(--bg-2); color: var(--text); border-radius: 8px; padding: 4px 8px; margin: 4px 4px 0 0; font-size: 12px; cursor: pointer; }

.shot-detail .relabel { display: inline-flex; gap: 8px; align-items: center; margin: 6px 12px 6px 0; font-size: 14px; color: var(--muted); }
.shot-detail select { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-height: 44px; }

.court-map { width: 100%; max-width: 320px; border-radius: 12px; border: 1px solid var(--line); margin-top: 8px; }

.history { list-style: none; padding: 0; margin: 0 0 12px; }
.history li { display: flex; gap: 10px; align-items: center; border-bottom: 1px dashed var(--line); padding: 8px 0; font-size: 14px; }
.history li b { color: var(--accent); }
.history li button { margin-left: auto; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.warn-card ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px 12px 28px; }

@media (max-width: 560px) {
  .steps { top: 58px; }
  .brand small { display: none; }
  .score-card { align-items: flex-start; }
}
