/* ===== Liquid Glass tokens ===== */
:root {
  --bg: #e9f2ee;
  --text: #0d1a14;
  --muted: rgba(13, 26, 20, .58);
  --glass: rgba(255, 255, 255, .52);
  --glass-strong: rgba(255, 255, 255, .72);
  --glass-border: rgba(255, 255, 255, .75);
  --glass-edge: rgba(13, 26, 20, .08);
  --hl: rgba(255, 255, 255, .9);
  --shadow: 0 10px 30px rgba(20, 50, 35, .14), 0 1px 2px rgba(20, 50, 35, .08);
  --blob1: #9ff0c4; --blob2: #a7d8ff; --blob3: #ffe3a3;
  --accent: #19b366;
  --accent-ink: #ffffff;
  --good: #19b366; --warn: #f0a020; --bad: #ff4f45; --info: #2f8cff;
  --cyan: #5ee0ff;
  --radius: 26px;
  --blur: blur(24px) saturate(180%);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1210;
    --text: #eef6f1;
    --muted: rgba(238, 246, 241, .58);
    --glass: rgba(28, 40, 36, .48);
    --glass-strong: rgba(34, 48, 43, .7);
    --glass-border: rgba(255, 255, 255, .14);
    --glass-edge: rgba(0, 0, 0, .35);
    --hl: rgba(255, 255, 255, .18);
    --shadow: 0 12px 34px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .3);
    --blob1: #0f6b45; --blob2: #10466e; --blob3: #5b4a14;
    --accent: #3ddc84;
    --accent-ink: #04170c;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1210; --text: #eef6f1; --muted: rgba(238, 246, 241, .58);
  --glass: rgba(28, 40, 36, .48); --glass-strong: rgba(34, 48, 43, .7);
  --glass-border: rgba(255, 255, 255, .14); --glass-edge: rgba(0, 0, 0, .35); --hl: rgba(255, 255, 255, .18);
  --shadow: 0 12px 34px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .3);
  --blob1: #0f6b45; --blob2: #10466e; --blob3: #5b4a14; --accent: #3ddc84; --accent-ink: #04170c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  -webkit-font-smoothing: antialiased; letter-spacing: -.01em;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
button, select, input { font: inherit; color: inherit; }

/* ambient blobs behind glass */
.ambient { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.ambient i { position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(70px); opacity: .55; }
.ambient i:nth-child(1) { background: var(--blob1); top: -20vmax; left: -15vmax; animation: drift 22s ease-in-out infinite alternate; }
.ambient i:nth-child(2) { background: var(--blob2); bottom: -25vmax; right: -20vmax; animation: drift 28s ease-in-out infinite alternate-reverse; }
.ambient i:nth-child(3) { background: var(--blob3); top: 35%; left: 40%; width: 35vmax; height: 35vmax; opacity: .35; animation: drift 34s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate(6vmax, 4vmax) scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .ambient i { animation: none; } }

/* glass material */
.glass, .sheet, .card, .glass-btn, .status-pill, .big-score, .toast {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 0 var(--hl), inset 0 -1px 0 var(--glass-edge);
}

/* top bar */
.topbar {
  position: sticky; top: max(10px, env(safe-area-inset-top)); z-index: 20;
  margin: 10px 16px 0; padding: 8px 8px 8px 16px; border-radius: 999px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 18px; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.glass-btn { border-radius: 999px; padding: 10px 16px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: transform .15s ease, background .2s; }
.glass-btn:active, .cta:active, .tab:active { transform: scale(.96); }
.glass-btn.round { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; }
.glass-btn.chip { padding: 8px 14px; font-size: 13px; }
.glass-btn.danger { color: var(--bad); margin-top: 6px; }
.cta { border: 0; border-radius: 999px; padding: 12px 22px; font-weight: 700; font-size: 15px; cursor: pointer;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 85%, white), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 40%, transparent), inset 0 1px 0 rgba(255,255,255,.55);
  transition: transform .15s ease; }
.cta.stop { background: linear-gradient(180deg, #ff7a70, var(--bad)); color: #fff;
  box-shadow: 0 8px 22px rgba(255, 79, 69, .35), inset 0 1px 0 rgba(255,255,255,.5); }

main { max-width: 860px; margin: 0 auto; padding: 14px 16px 24px; }
.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* camera / video stage */
.stage { position: relative; width: 100%; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 3 / 4; max-height: 68vh; background: #0b1410; margin: 0 auto; }
@media (orientation: landscape) and (min-width: 700px) { .stage { aspect-ratio: 16 / 9; } }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage.mirror video, .stage.mirror canvas { transform: scaleX(-1); }
.empty-state { position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  color: rgba(255,255,255,.8); font-size: 15px; line-height: 1.6; padding: 16px; }
.empty-icon { font-size: 38px; margin-bottom: 6px; }
.status-pill { position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  padding: 7px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; white-space: nowrap;
  color: #fff; background: rgba(14, 21, 33, .55); border-color: rgba(255,255,255,.22); }
.status-pill.ready { background: rgba(61, 220, 132, .78); color: #03170b; }
.status-pill.swing { background: rgba(255, 194, 71, .85); color: #1d1300; }
.status-pill.warn { background: rgba(255, 95, 80, .8); }
.phase-meter { position: absolute; bottom: 12px; left: 12px; display: flex; gap: 4px; }
.phase-meter span { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; color: rgba(255,255,255,.65);
  background: rgba(14, 21, 33, .5); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); transition: all .2s; }
.phase-meter span.on { background: var(--cyan); color: #04202a; }
.big-score { position: absolute; bottom: 12px; right: 12px; padding: 6px 16px; border-radius: 18px;
  font-size: 34px; font-weight: 900; color: #fff; background: rgba(14, 21, 33, .6); border-color: rgba(255,255,255,.22); }
.big-score small { font-size: 14px; font-weight: 700; opacity: .75; }

.legend { display: flex; justify-content: center; gap: 14px; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; align-items: center; }
.controls select { appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }

.segmented { display: inline-flex; padding: 3px; border-radius: 999px; gap: 2px; }
.segmented button { border: 0; background: none; padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; }
.segmented button.on { background: var(--glass-strong); box-shadow: 0 2px 8px rgba(0,0,0,.12); }

/* upload */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: var(--radius);
  padding: 30px 16px; text-align: center; cursor: pointer; margin-bottom: 14px; border-style: dashed; }
.dropzone small { color: var(--muted); }
.progress { position: relative; height: 34px; border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
#progressBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--cyan)); opacity: .75; transition: width .2s; }
#progressText { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }

/* cards & feedback */
.card { border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 800; }
.card h4 { margin: 0 0 6px; font-size: 15px; font-weight: 800; }
.card p { margin: 6px 0; line-height: 1.6; font-size: 14px; }
.card ol { padding-left: 20px; line-height: 1.75; margin: 0; font-size: 14px; }
.summary { display: flex; align-items: center; gap: 16px; }
.score-ring { --p: 0; --c: var(--good); width: 84px; height: 84px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), color-mix(in srgb, var(--text) 10%, transparent) 0); position: relative; }
.score-ring::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--glass-strong); }
.score-ring b { position: relative; z-index: 1; font-size: 28px; font-weight: 900; }
.headline { font-size: 15px; line-height: 1.55; font-weight: 600; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; margin: 0 4px 6px 0;
  background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--muted); }
.fault { position: relative; overflow: hidden; }
.fault::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--warn); }
.fault.bad::before { background: var(--bad); }
.fault.good::before { background: var(--good); }
.fault .cue { background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 10px 12px; border-radius: 14px; font-weight: 600; }
.fault .drill { font-size: 13px; color: var(--muted); }
.fault a { color: var(--info); font-size: 13px; font-weight: 600; text-decoration: none; }
.fault img.snap { width: 100%; border-radius: 16px; margin: 8px 0 4px; display: block; background: #0b1410; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 13px; }
table.metrics td { padding: 8px 2px; border-bottom: 1px solid color-mix(in srgb, var(--text) 8%, transparent); }
table.metrics tr:last-child td { border-bottom: 0; }
table.metrics td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.info { background: var(--info); }

/* history */
.hist-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 18px; margin-bottom: 8px; font-size: 14px; }
.hist-item b { font-size: 18px; }
.bar-row { display: grid; grid-template-columns: 1fr 2fr auto; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0; }
.bar-row .bar { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--warn), var(--bad)); }
#trendCanvas { width: 100%; display: block; }

/* bottom floating tab bar */
.tabbar { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom)); width: min(calc(100% - 32px), 460px);
  display: flex; padding: 6px; border-radius: 999px; gap: 2px; }
.tab { flex: 1; border: 0; background: none; cursor: pointer; padding: 7px 4px 6px; border-radius: 999px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted);
  transition: background .25s, color .25s, transform .15s; }
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); background: var(--glass-strong); box-shadow: 0 2px 10px rgba(0,0,0,.1), inset 0 1px 0 var(--hl); }

/* sheets */
.sheet { border-radius: 30px; padding: 6px 4px; width: min(calc(100vw - 32px), 440px); color: var(--text);
  background: var(--glass-strong); }
.sheet::backdrop { background: rgba(0, 0, 0, .28); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.sheet[open] { animation: pop .28s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(12px); } }
.sheet h3 { margin: 12px 16px 14px; font-size: 18px; font-weight: 800; }
.club-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 12px 12px; }
.club-grid button { border: 1px solid var(--glass-border); border-radius: 22px; padding: 16px 10px; cursor: pointer;
  background: var(--glass); display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: inset 0 1px 0 var(--hl); transition: transform .15s; }
.club-grid button span { font-size: 26px; }
.club-grid button small { color: var(--muted); font-size: 12px; }
.club-grid button.on { outline: 2px solid var(--accent); }
.settings { padding: 0 12px 12px; }
.settings .group { background: var(--glass); border: 1px solid var(--glass-border); border-radius: 20px; padding: 4px 14px; margin-bottom: 12px; }
.settings label { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; font-size: 15px;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 8%, transparent); }
.settings .group label:last-child { border-bottom: 0; }
.settings select { border: 0; background: transparent; color: var(--accent); font-weight: 700; text-align: right; }
.settings .slider input { width: 50%; accent-color: var(--accent); }
.settings menu { margin: 0; padding: 0; display: flex; justify-content: flex-end; }
.switch input { display: none; }
.switch i { width: 50px; height: 30px; border-radius: 999px; background: color-mix(in srgb, var(--text) 18%, transparent); position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform .22s cubic-bezier(.2, .9, .3, 1.2); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 40;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); text-align: center; }

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass: rgba(255,255,255,.92); }
  @media (prefers-color-scheme: dark) { :root { --glass: rgba(28,40,36,.95); } }
}
