:root {
  --bg: #f4f6f3; --card: #ffffff; --text: #1b2420; --muted: #66736c; --line: #e1e6e2;
  --brand: #0f6b4a; --brand-dark: #0f3d2e; --bad: #d64545; --warn: #e3a008; --good: #2f9e64;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1411; --card: #17211c; --text: #e8efe9; --muted: #93a39a; --line: #26332c; --brand: #2fbf84; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-text-size-adjust: 100%; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.screen { display: none; max-width: 640px; margin: 0 auto; padding: 16px 16px 40px; }
.screen.active { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
h1 { font-size: 28px; margin: 8px 0 4px; }
h2 { font-size: 18px; }
.section-title { margin: 24px 4px 10px; }
.hero { padding: 16px 4px 8px; }
.hero p { margin: 0; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.big { width: 100%; padding: 18px; font-size: 18px; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.actions { display: grid; gap: 10px; margin: 16px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.card summary { font-weight: 700; cursor: pointer; }
.tips ul { margin: 10px 0 0; padding-left: 18px; line-height: 1.6; }
.warn { border-color: var(--warn); }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history li { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; cursor: pointer; }
.history img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: #000; flex: none; }
.history .h-main { font-weight: 700; }
.history .h-sub { font-size: 13px; color: var(--muted); }

.badge { display: inline-block; white-space: nowrap; flex: none; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; color: #fff; }
.badge.bad { background: var(--bad); } .badge.warn { background: var(--warn); } .badge.good { background: var(--good); }

/* 촬영 화면 */
.camera { position: fixed; inset: 0; max-width: none; padding: 0; background: #000; z-index: 10; }
.camera.active { display: block; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cam-hint { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 16px; right: 16px; text-align: center;
  color: #fff; background: rgba(0,0,0,.5); padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.cam-countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 120px; font-weight: 800; text-shadow: 0 4px 20px rgba(0,0,0,.6); pointer-events: none; }
.cam-rec { position: absolute; top: calc(60px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  color: #fff; background: rgba(214,69,69,.9); padding: 6px 14px; border-radius: 99px; font-weight: 700; }
.cam-controls { position: absolute; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-around; }
.cam-controls .btn { color: #fff; border-color: rgba(255,255,255,.4); min-width: 96px; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: #d64545; cursor: pointer; }
.shutter.recording { border-radius: 18px; transform: scale(.8); }

/* 분석 중 */
.center-col.active { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80vh; text-align: center; }
.spinner { width: 48px; height: 48px; border: 5px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 80%; height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 12px 0; }
#an-bar { height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* 결과 */
.topbar { display: flex; justify-content: space-between; align-items: center; }
.player { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; margin: 8px 0; }
.player { width: 100%; max-height: 72vh; margin-left: auto; margin-right: auto; }
.stage { position: absolute; }
.stage video { display: block; width: 100%; height: 100%; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.controls-row, .phase-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.phase-row .btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.legend { font-size: 12px; color: var(--muted); margin: 4px 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 4px 0 8px; vertical-align: -1px; }
.dot.red { background: #ff3b30; } .dot.blue { background: #1e90ff; } .dot.gray { background: #c8c8c8; }
.summary-card { background: var(--brand-dark); color: #fff; border: none; }
.summary-card h3 { margin: 0 0 6px; font-size: 16px; }
.summary-card p { margin: 0 0 10px; line-height: 1.55; }
.issue h3 { margin: 0 0 6px; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.issue p { margin: 6px 0; line-height: 1.55; }
.issue .label { font-weight: 700; color: var(--muted); font-size: 13px; display: block; }
.tempo-bars { display: flex; height: 14px; border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.tempo-bars div { height: 100%; }
.metrics { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.metrics td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.metrics td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom)); background: #222; color: #fff;
  padding: 12px 16px; border-radius: 12px; text-align: center; z-index: 20; }
.view-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0; font-size: 14px; }
