:root {
  --bg: #f4f2ec;
  --bg-accent: #e9efe9;
  --surface: #ffffff;
  --surface-2: #f8f7f3;
  --text: #1d2125;
  --muted: #6a7078;
  --border: #e3e0d7;
  --accent: #2f7d6d;
  --accent-2: #e58a5b;
  --accent-soft: #dcefe9;
  --ok: #2e9e5b;
  --warn: #d99a1e;
  --bad: #d64545;
  --unknown: #9aa0a6;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 8px 24px rgba(20, 30, 25, .07);
  --shadow-lift: 0 2px 4px rgba(20, 30, 25, .08), 0 16px 36px rgba(20, 30, 25, .12);
  --radius: 16px;
  --figure-bg: linear-gradient(160deg, #eef6f2 0%, #f6efe6 100%);
  --figure-stroke: #2f7d6d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121416;
    --bg-accent: #16201d;
    --surface: #1b1f22;
    --surface-2: #22272b;
    --text: #e8eaec;
    --muted: #98a0a8;
    --border: #2d3338;
    --accent: #5fc2ab;
    --accent-2: #f0a37b;
    --accent-soft: #1d3530;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 16px 36px rgba(0, 0, 0, .4);
    --figure-bg: linear-gradient(160deg, #1d2a27 0%, #2a241e 100%);
    --figure-stroke: #7fd6c1;
  }
}
:root[data-theme="dark"] {
  --bg: #121416; --bg-accent: #16201d; --surface: #1b1f22; --surface-2: #22272b;
  --text: #e8eaec; --muted: #98a0a8; --border: #2d3338; --accent: #5fc2ab; --accent-2: #f0a37b;
  --accent-soft: #1d3530; --figure-bg: linear-gradient(160deg, #1d2a27 0%, #2a241e 100%);
  --figure-stroke: #7fd6c1;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Noto Sans HK", system-ui, "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--bg-accent), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; padding: 6px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  fill: #fff; stroke: #fff;
}
.brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: .02em; }
.tagline { margin: 0; font-size: .8rem; color: var(--muted); }

main {
  max-width: 1440px; margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) 48px;
  display: grid; gap: 28px;
}

/* ---------- pose cards ---------- */
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { font-size: 1.25rem; }
.section-head p { margin: 0; font-size: .9rem; }
.cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.pose-card {
  all: unset; box-sizing: border-box; cursor: pointer;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.pose-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.pose-card:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px; }
.pose-card[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent), var(--shadow-lift);
}
.pose-figure {
  position: relative; aspect-ratio: 4 / 3; background: var(--figure-bg);
  display: grid; place-items: center; overflow: hidden;
}
.pose-figure img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.pose-card:hover .pose-figure img { transform: scale(1.04); }
.pose-figure svg { width: 72%; height: 82%; }
.pose-figure svg line, .pose-figure svg polyline { stroke: var(--figure-stroke); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.pose-figure svg circle { fill: var(--figure-stroke); }
.check {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  transform: scale(0); transition: transform .18s ease;
}
.check svg { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 3; }
.pose-card[aria-checked="true"] .check { transform: scale(1); }
.pose-body { padding: 10px 12px 12px; display: grid; gap: 6px; }
.pose-name { font-weight: 700; font-size: 1rem; }
.pose-en { font-family: Outfit, sans-serif; font-size: .8rem; color: var(--muted); margin-top: -4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: .72rem; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.chip.dynamic { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--accent-2); border-color: transparent; }
.chip.static { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- workspace ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 960px) { .workspace { grid-template-columns: 1fr; } }
.card-surface {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stage { padding: 14px; }
.stage-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.current { display: grid; }
.current-label { font-size: .75rem; color: var(--muted); }
.current strong { font-size: 1.1rem; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  font: inherit; font-size: .92rem; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn svg { width: 18px; height: 18px; stroke: currentColor; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .92rem; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.slider { width: 38px; height: 22px; border-radius: 999px; background: var(--border); position: relative; transition: background .2s; }
.slider::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }

.viewport {
  position: relative; background: #0d0f10; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9;
}
.viewport video, .viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.viewport.mirror video, .viewport.mirror canvas { transform: scaleX(-1); }
.placeholder {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px;
  color: #aab2b8; text-align: center; padding: 16px;
  background: radial-gradient(circle at 50% 40%, #1d2624, #0d0f10 70%);
}
.placeholder[hidden], [hidden] { display: none !important; }
.placeholder svg { width: 64px; height: 64px; fill: #5fc2ab; stroke: #5fc2ab; opacity: .8; }
.placeholder p { margin: 0; }
.hint {
  margin: 12px 2px 0; padding: 10px 12px; border-radius: 10px; font-size: .9rem;
  background: var(--accent-soft); color: var(--text);
}
.hint:empty { display: none; }

/* ---------- side panel ---------- */
.panel { padding: 20px; position: sticky; top: 84px; }
@media (max-width: 960px) { .panel { position: static; } }
.score-ring {
  --size: 168px; --c: var(--unknown);
  width: var(--size); height: var(--size); margin: 4px auto 0; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center; transition: --p .4s ease;
}
.score-ring.ok { --c: var(--ok); } .score-ring.warn { --c: var(--warn); } .score-ring.bad { --c: var(--bad); }
.score-inner {
  width: calc(var(--size) - 22px); height: calc(var(--size) - 22px); border-radius: 50%;
  background: var(--surface); display: grid; place-content: center; text-align: center;
}
.score { font-family: Outfit, sans-serif; font-size: 3.4rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.score-label { color: var(--muted); font-size: .85rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat span { display: block; font-family: Outfit, sans-serif; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.panel h3 { font-size: .85rem; margin: 20px 0 8px; color: var(--muted); font-weight: 500; letter-spacing: .04em; }
.tips { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tips li { padding: 9px 12px; border-radius: 10px; background: var(--surface-2); font-size: .92rem; }
.tips li:first-child:not(.muted) {
  border-left: 4px solid var(--accent-2); font-weight: 700;
  background: color-mix(in srgb, var(--accent-2) 10%, var(--surface));
}
.joints { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.joints li { display: flex; align-items: center; gap: 8px; font-size: .88rem; padding: 4px 8px; border-radius: 8px; background: var(--surface-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); } .dot.unknown { background: var(--unknown); }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; margin: 18px 0 0; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.dot-live.on { background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tagline { display: none; }
  .score-ring { --size: 140px; }
  .score { font-size: 2.8rem; }
}
