:root {
  --bg: #0b0f0d;
  --surface: #151b18;
  --surface-2: #1e2622;
  --line: #2a342f;
  --text: #eef3ef;
  --muted: #9aa8a0;
  --accent: #3ddc84;
  --accent-ink: #04210f;
  --good: #3ddc84;
  --warn: #ffb020;
  --bad: #ff5d5d;
  --rec: #ff3b30;
  --tabs-h: 58px;
  --voice-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h2, h3, p { margin: 0; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  padding-top: var(--safe-t);
}

/* ---------- 视图切换 ---------- */
.view { display: none; flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 20px; }
#app[data-tab="practice"] #view-practice,
#app[data-tab="result"] #view-result,
#app[data-tab="history"] #view-history,
#app[data-tab="settings"] #view-settings { display: block; }
#app[data-tab="practice"] #view-practice { display: flex; flex-direction: column; padding: 0; overflow: hidden; }

.title { font-size: 22px; font-weight: 700; margin: 4px 0 14px; }
.view h3 { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; margin: 22px 2px 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.55; }
.center { text-align: center; margin-top: 18px; }
.empty { text-align: center; color: var(--muted); padding: 56px 20px; }
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.btn.ghost { background: var(--surface-2); color: var(--text); font-weight: 600; }
.btn.small { min-height: 36px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
.btn:active { filter: brightness(.9); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(10, 14, 12, .55); color: #fff; backdrop-filter: blur(8px);
}
.pill { min-width: 54px; height: 34px; padding: 0 12px; border-radius: 17px; background: var(--surface-2); font-size: 13px; font-weight: 600; }
.pill[aria-pressed="false"] { color: var(--muted); }
.pill[aria-pressed="true"] { color: var(--accent); }

/* ---------- 练习：取景 ---------- */
.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#cam.mirror { transform: scaleX(-1); }
.frame-guide {
  position: absolute; left: 16%; right: 16%; top: 9%; bottom: 7%;
  border: 2px dashed rgba(255, 255, 255, .38); border-radius: 26px; pointer-events: none;
}
.stage.recording .frame-guide { border-color: transparent; }
.stage-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; }
.seg { display: flex; padding: 3px; border-radius: 22px; background: rgba(10, 14, 12, .55); backdrop-filter: blur(8px); }
.seg button { min-width: 56px; height: 38px; padding: 0 14px; border-radius: 19px; font-size: 14px; font-weight: 600; color: #d5ded8; }
.seg button.on { background: #fff; color: #0b0f0d; }
.chip {
  position: absolute; top: 66px; left: 50%; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 16px; font-size: 14px; font-weight: 600; white-space: nowrap;
  background: rgba(10, 14, 12, .7); color: #fff;
}
.chip.ok { background: rgba(31, 138, 78, .9); }
.chip.no { background: rgba(190, 110, 0, .92); }
.stage-hint {
  position: absolute; left: 0; right: 0; bottom: 12px; padding: 0 18px;
  text-align: center; font-size: 13px; color: rgba(255, 255, 255, .85); text-shadow: 0 1px 3px #000;
}
.stage.recording .stage-hint, .stage.counting .stage-hint { display: none; }
.rec-badge {
  position: absolute; top: 66px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 16px;
  background: rgba(10, 14, 12, .7); font-weight: 700; font-variant-numeric: tabular-nums;
}
.rec-badge i { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 44vmin; font-weight: 800; color: #fff; text-shadow: 0 4px 30px rgba(0, 0, 0, .6);
  background: rgba(0, 0, 0, .18);
}
.cam-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: 30px; text-align: center; background: var(--bg); color: var(--muted);
}

.controls {
  flex: none; display: flex; align-items: center; justify-content: space-around;
  padding: 14px 10px 12px; background: var(--bg);
}
.side-btn { width: 84px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); cursor: pointer; }
.side-btn[aria-pressed="true"] { color: var(--accent); }
.rec-btn { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; }
.rec-btn i { width: 58px; height: 58px; border-radius: 50%; background: var(--rec); transition: all .18s; }
.rec-btn.on i { width: 28px; height: 28px; border-radius: 7px; }
.rec-btn:disabled { opacity: .4; }

/* ---------- 分析：播放器 ---------- */
.player { position: relative; width: 100%; max-height: 58vh; background: #000; border-radius: 16px; overflow: hidden; margin: 0 auto; }
.player video, .player canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.player video { object-fit: contain; }
.player canvas { pointer-events: none; }
.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 8, 7, .72); }
.busy-box { width: 76%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.busy-stage { font-weight: 600; text-align: center; }
.bar { width: 100%; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .18); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }

.transport { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.transport .icon-btn { background: var(--surface-2); flex: none; }
#scrub { flex: 1; min-width: 0; accent-color: var(--accent); height: 30px; }
.phases { display: grid; grid-template-columns: repeat(4, 1fr) 44px 44px; gap: 6px; margin-top: 8px; }
.phases button { height: 38px; border-radius: 10px; background: var(--surface-2); font-size: 14px; font-weight: 600; }
.phases button:active { background: var(--line); }
.swing-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.swing-picker button { height: 32px; padding: 0 12px; border-radius: 16px; background: var(--surface-2); font-size: 13px; color: var(--muted); }
.swing-picker button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ---------- 分析：报告 ---------- */
#report { margin-top: 14px; }
.score-card { display: flex; align-items: center; gap: 16px; }
.ring {
  --p: 0; --c: var(--accent);
  flex: none; width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(closest-side, var(--surface) 80%, transparent 81% 100%), conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-2) 0);
  display: flex; align-items: baseline; justify-content: center; padding-top: 26px;
}
.ring b { font-size: 34px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.ring small { font-size: 12px; color: var(--muted); margin-left: 2px; }
.score-meta { min-width: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.grade { font-size: 20px; font-weight: 700; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { font-size: 12px; padding: 2px 9px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.notes { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.notes p { font-size: 13px; color: var(--warn); background: rgba(255, 176, 32, .09); border-radius: 10px; padding: 8px 12px; }

.issue { margin-bottom: 10px; border-left: 4px solid var(--warn); }
.issue.bad { border-left-color: var(--bad); }
.issue-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.issue-head b { font-size: 16px; }
.issue-head span { font-size: 13px; color: var(--muted); white-space: nowrap; }
.issue p { margin-top: 6px; font-size: 15px; }
.issue .fix { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.issue .fix b { display: block; font-size: 12px; color: var(--accent); margin-bottom: 2px; letter-spacing: .04em; }
.all-good { color: var(--good); font-weight: 600; }

.metrics { padding: 4px 16px; }
.metric { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.metric:last-child { border-bottom: 0; }
.metric i { width: 10px; height: 10px; border-radius: 50%; background: var(--good); }
.metric.warn i { background: var(--warn); }
.metric.bad i { background: var(--bad); }
.metric.info i { background: var(--muted); }
.metric .name { font-size: 15px; }
.metric .name small { display: block; font-size: 12px; color: var(--muted); }
.metric .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .val small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.fail { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.fail h3 { margin: 0; color: var(--text); font-size: 17px; }

/* ---------- 记录 ---------- */
.trend { margin-bottom: 14px; }
.trend-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.trend-head b { color: var(--text); }
#trend-svg { width: 100%; height: 70px; margin-top: 6px; display: block; }
.hist { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; margin-bottom: 10px; width: 100%; text-align: left; }
.hist .s { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; font-weight: 800; background: var(--surface-2); color: var(--good); }
.hist .s.warn { color: var(--warn); }
.hist .s.bad { color: var(--bad); }
.hist .t b { display: block; font-size: 15px; }
.hist .t small { font-size: 13px; color: var(--muted); }
.hist .del { width: 40px; height: 40px; border-radius: 50%; color: var(--muted); font-size: 20px; }

/* ---------- 设置 ---------- */
.form { display: flex; flex-direction: column; padding: 2px 16px; }
.form label { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); font-size: 15px; }
.form label:last-of-type { border-bottom: 0; }
.form input[type="number"], .form input[type="password"], .form select {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; height: 38px; padding: 0 10px; max-width: 58%; min-width: 96px; text-align: right;
}
.form input[type="password"] { flex: 1; text-align: left; }
.form input[type="checkbox"] { width: 46px; height: 28px; appearance: none; border-radius: 14px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.form input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.form input[type="checkbox"]:checked { background: var(--accent); }
.form input[type="checkbox"]:checked::after { transform: translateX(18px); }
.form .hint { padding: 10px 0; }
.help p { font-size: 14px; color: #cfd8d2; margin-bottom: 10px; }
.help p:last-child { margin-bottom: 0; }
.help b { color: var(--text); }

/* ---------- 语音条 / 底部导航 ---------- */
.voice-bar {
  flex: none; height: var(--voice-h); display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.mic { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.mic[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.mic.hearing { box-shadow: 0 0 0 5px rgba(61, 220, 132, .25); }
.voice-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.3; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.voice-text.coach { color: var(--text); }
.voice-text.me { color: var(--accent); }
.ask { flex: none; width: 34%; display: none; }
#app[data-tab="result"] .ask { display: block; }
.ask input { width: 100%; height: 38px; border-radius: 19px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 14px; font-size: 14px; }

.tabs { flex: none; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); }
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tabs button.on { color: var(--accent); }
.tabs button .dot { position: absolute; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--tabs-h) + var(--voice-h) + var(--safe-b) + 14px); transform: translateX(-50%);
  max-width: 86%; padding: 10px 16px; border-radius: 12px; background: #2c3631; color: #fff; font-size: 14px; text-align: center; z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}

@media (min-width: 560px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
