:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #161b2e;
  --muted: #69718a;
  --border: #e1e5ef;
  --primary: #4f5bff;
  --primary-soft: #e8eaff;
  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #ef4444;
  --user: #4f5bff;
  --ref: #f97316;
  --shadow: 0 1px 2px rgba(20, 27, 46, .04), 0 8px 24px rgba(20, 27, 46, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e111b;
    --surface: #171b29;
    --surface-2: #20253a;
    --text: #e8ebf5;
    --muted: #8c93ab;
    --border: #2a3047;
    --primary: #7c85ff;
    --primary-soft: #262b52;
    --user: #7c85ff;
    --ref: #fb923c;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  line-height: 1.55;
}
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; }
.logo { color: var(--primary); font-size: 22px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 500; font-size: 14px;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, opacity .15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.round { width: 42px; height: 42px; padding: 0; justify-content: center; border-radius: 50%; font-size: 15px; }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }

/* ---------- upload view ---------- */
.hero { text-align: center; margin: 24px 0 32px; }
.hero h1 { font-size: clamp(26px, 4vw, 38px); }
.hero p { margin-top: 10px; }
.upload-grid { display: grid; grid-template-columns: 320px 1fr; gap: 16px; max-width: 900px; margin: 0 auto; }
.upload-grid .card + .card { margin-top: 0; }
.ref-card h2 { margin-bottom: 12px; }
.portrait { aspect-ratio: 9 / 16; max-height: 460px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #000; }
.portrait video { width: 100%; height: 100%; object-fit: cover; display: block; }
.samples { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 14px; }
.credit { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.credit a { color: inherit; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: 14px; padding: 36px 16px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { font-size: 28px; color: var(--primary); }
.dz-title { font-weight: 500; margin-top: 6px; }
.dz-sub { font-size: 13px; }
.dz-file { margin-top: 12px; font-weight: 500; color: var(--primary); word-break: break-all; }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.tips { margin-top: 18px; background: var(--surface-2); border-radius: 12px; padding: 12px 16px; }
.tips-title { font-weight: 700; font-size: 14px; }
.tips ul { margin: 6px 0 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
.error { color: var(--bad); font-weight: 500; margin: 12px 0 0; }

/* ---------- progress ---------- */
.progress-card { max-width: 480px; margin: 80px auto; text-align: center; }
.progress-card h2 { font-size: 18px; margin: 16px 0; }
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--primary); border-radius: 99px; transition: width .3s; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto; border-radius: 50%;
  border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- results: summary ---------- */
.banner {
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
}
.summary { display: grid; grid-template-columns: 320px 1fr; gap: 16px; margin-bottom: 16px; }
.summary .card + .card { margin-top: 0; }
.score-card { display: flex; align-items: center; gap: 20px; }
.score-ring {
  --p: 0; --c: var(--ok);
  width: 104px; height: 104px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center; position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--surface); }
.score-ring span { position: relative; font-size: 30px; font-weight: 700; }
.score-text { font-size: 18px; font-weight: 700; }
.issue {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border);
}
.issue:first-child { border-top: 0; padding-top: 0; }
.sev { flex: none; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-top: 2px; }
.sev.high { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.sev.medium { background: color-mix(in srgb, var(--warn) 18%, transparent); color: #b45309; }
.sev.info { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) { .sev.medium { color: var(--warn); } }
.issue-title { font-weight: 700; }
.issue-tip { font-size: 14px; color: var(--muted); }
.all-good { color: var(--ok); font-weight: 500; }

/* ---------- player ---------- */
.player-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.player-head .card-label { margin: 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.dash { display: inline-block; width: 18px; border-top: 2px dashed var(--text); margin-right: 5px; vertical-align: 3px; }
.toggles { display: flex; gap: 14px; font-size: 14px; }
.toggles label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.toggles input { accent-color: var(--primary); }

.compare { display: grid; grid-template-columns: auto auto minmax(320px, 1fr); gap: 16px; align-items: start; }
.player { margin: 0; }
.player { min-width: 0; }
.player figcaption { font-size: 14px; font-weight: 500; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player:first-child figcaption { color: var(--user); }
.player:nth-child(2) figcaption { color: var(--ref); }
.stage {
  position: relative; background: #000; border-radius: 12px; overflow: hidden;
  aspect-ratio: 9 / 16; height: min(66vh, 580px);
}
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.side-panel { min-width: 0; }
.small-note { font-size: 12px; margin: 8px 0 0; }

.com-gauge { margin: 14px 0 6px; }
.gauge-title { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.gauge { position: relative; height: 14px; border-radius: 99px; background: color-mix(in srgb, var(--bad) 22%, var(--surface-2)); }
.gauge-zone { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--ok) 45%, var(--surface-2)); border-radius: 99px; }
.gauge-marker {
  position: absolute; top: -4px; width: 6px; height: 22px; margin-left: -3px; border-radius: 3px;
  background: var(--text); transition: left .08s linear;
}
.gauge-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

.proportions { display: grid; grid-template-columns: auto 1fr; gap: 8px 20px; align-items: center; }
.proportions .text { grid-column: 1 / -1; }
.ratio-row { display: contents; font-size: 14px; }
.ratio-bars { display: flex; flex-direction: column; gap: 4px; }
.ratio-bar { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ratio-bar .bar { height: 8px; border-radius: 99px; }
.ratio-bar .who { width: 36px; color: var(--muted); }
.controls { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.controls input[type=range] { flex: 1; accent-color: var(--primary); }
.controls select {
  font: inherit; font-size: 14px; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.rep-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.readout { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 14px; }
.readout th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.readout td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.readout tr:last-child td { border-bottom: 0; }
.diff.ok { color: var(--ok); } .diff.warn { color: #d97706; } .diff.bad { color: var(--bad); font-weight: 700; }

/* ---------- chart ---------- */
.tabs { display: flex; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tab { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chart-wrap { position: relative; height: 280px; }

/* ---------- rep cards ---------- */
.section-title { margin: 28px 0 12px; font-size: 18px; }
.rep-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.rep-cards .card + .card { margin-top: 0; }
.rep-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.rep-head h4 { margin: 0; font-size: 16px; }
.rep-score { font-weight: 700; font-size: 20px; }
.metrics { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.metrics td { padding: 4px 0; border-bottom: 1px dashed var(--border); font-variant-numeric: tabular-nums; }
.metrics td:not(:first-child) { text-align: right; }
.metrics td:first-child { color: var(--muted); }
.rep-issue { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; padding: 6px 0; }
.rep-issue .body { flex: 1; }
.rep-issue .detail { color: var(--muted); font-size: 13px; }

.footer-links { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 28px; }

@media (max-width: 1100px) {
  .compare { grid-template-columns: 1fr 1fr; }
  .player { display: flex; flex-direction: column; align-items: center; }
  .stage { height: min(70vh, 640px); max-width: 100%; }
  .side-panel { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .upload-grid, .summary { grid-template-columns: 1fr; }
  .compare { gap: 8px; }
  .stage { height: auto; width: 100%; }
  .controls { flex-wrap: wrap; }
  .controls input[type=range] { order: 5; flex-basis: 100%; }
}

/* ---------- navigation ---------- */
.brand { color: var(--text); text-decoration: none; }
.stepper { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; font-size: 13px; }
.stepper li { display: flex; align-items: center; gap: 6px; color: var(--muted); padding: 4px 10px; border-radius: 99px; }
.stepper li::before {
  counter-increment: step; content: counter(step);
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface-2); font-size: 12px; font-weight: 700;
}
.stepper { counter-reset: step; }
.stepper li.done { color: var(--text); }
.stepper li.done::before { background: var(--primary-soft); color: var(--primary); }
.stepper li.active { color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.stepper li.active::before { background: var(--primary); color: #fff; }
.back { margin-bottom: 12px; }

/* ---------- exercise picker ---------- */
.exercise-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.ex-card {
  display: flex; flex-direction: column; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0; overflow: hidden; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.ex-card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--primary); }
.ex-card:disabled { cursor: default; opacity: .6; }
.ex-thumb { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.ex-thumb video { width: 100%; height: 100%; object-fit: cover; }
.ex-thumb .placeholder { font-size: 44px; opacity: .5; }
.ex-badge {
  position: absolute; top: 10px; left: 10px; font-size: 12px; font-weight: 700;
  padding: 2px 10px; border-radius: 99px; background: rgba(0,0,0,.6); color: #fff;
}
.ex-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ex-title { display: flex; align-items: baseline; gap: 8px; }
.ex-title h3 { font-size: 18px; }
.ex-title small { color: var(--muted); }
.ex-body p { margin: 0; font-size: 14px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 99px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.chip.accent { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 700; }
.ex-cta { margin-top: auto; padding-top: 8px; font-weight: 700; color: var(--primary); font-size: 14px; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.history-item:hover { border-color: var(--primary); }
.history-score { font-size: 20px; font-weight: 700; text-align: center; }
.history-meta { font-size: 13px; color: var(--muted); }

/* ---------- upload step ---------- */
.upload-grid { max-width: 1000px; grid-template-columns: 320px 1fr; }
.upload-col { display: flex; flex-direction: column; gap: 16px; }
.upload-col .card + .card { margin-top: 0; }
.ref-card .portrait { margin: 12px 0; }
.camera-guide { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: center; }
.camera-svg { width: 100%; height: auto; }
.camera-svg .ground { stroke: var(--border); stroke-width: 2; }
.camera-svg .person line, .camera-svg .person circle { stroke: var(--text); stroke-width: 4; stroke-linecap: round; fill: none; }
.camera-svg .phone rect { fill: var(--primary); }
.camera-svg .phone line { stroke: var(--muted); stroke-width: 2; }
.camera-svg .sight { stroke: var(--primary); stroke-width: 2; stroke-dasharray: 5 5; }
.camera-svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.cam-specs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.cam-specs li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dashed var(--border); padding-bottom: 6px; }
.cam-specs b { font-weight: 700; }

/* ---------- result header ---------- */
.result-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.result-head .chip { font-size: 14px; padding: 4px 12px; margin-right: 8px; }

/* landscape crops (horizontal exercises) */
.compare.landscape { grid-template-columns: 1fr 1fr; }
.compare.landscape .stage { aspect-ratio: 16 / 9; height: auto; width: 100%; }
.compare.landscape .side-panel { grid-column: 1 / -1; }

@media (max-width: 820px) {
  .stepper li { padding: 4px 6px; }
  .stepper li:not(.active) { font-size: 0; gap: 0; }
  .camera-guide { grid-template-columns: 1fr; }
}

.brand, .stepper li { white-space: nowrap; }
@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .brand small { display: none; }
}

.ref-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }
/* Captions and notes wrap to the video's width instead of widening the column. */
.player figcaption, .player .ref-note { width: 0; min-width: 100%; }

/* Keep the back button aligned with the centred upload layout. */
#view-upload { max-width: 1000px; margin: 0 auto; }
#view-upload .upload-grid { max-width: none; }

/* Recording straight from the camera only makes sense on touch devices. */
.record-btn { width: 100%; justify-content: center; padding: 12px; margin-bottom: 12px; font-size: 15px; }
@media (hover: hover) and (pointer: fine) {
  .record-btn { display: none; }
}
@media (hover: none), (pointer: coarse) {
  .desktop-only { display: none; }
}

@media (max-width: 820px) {
  .upload-grid { grid-template-columns: 1fr; }
  .upload-col { order: -1; }            /* on phones, recording/uploading comes first */
  .ref-card .portrait { max-height: 360px; }
}
