:root { --blue:#2e8bff; --purple:#9b5cff; --bg:#070a1c; --panel:#10142e; --card:#171c40; --line:#2c3367; --text:#eef1ff; --muted:#8e97c4;
  --ok:#2fe38a; --warn:#ffb703; --bad:#ff5d7a; --cw: clamp(236px, 30vw, 360px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin:0; height:100%; background:var(--bg); color:var(--text); overflow:hidden; overscroll-behavior:none;
  font-family: Pretendard, 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif; }
button { font: inherit; color: inherit; border:0; cursor:pointer; touch-action:manipulation; }
button:disabled { opacity:.45; cursor:default; }
.ic { width:1.3em; height:1.3em; flex:none; }
#root { height:100dvh; display:flex; flex-direction:column; }

/* ───────── 16:9 TV 스테이지 (왼쪽 50% 사용자 · 오른쪽 50% 아바타) ───────── */
#stageWrap { flex:none; width:100%; height:min(47dvh, 112vw); position:relative; background:#000; transition:height .25s; }
.working #stageWrap { height:min(60dvh, 130vw); }
#stage { position:absolute; inset:0; container-type:size; overflow:hidden; --u:1.7cqw;
  background: radial-gradient(120cqw 90cqh at 25% 0%, #12255a 0%, transparent 60%),
              radial-gradient(120cqw 90cqh at 78% 0%, #2a1260 0%, transparent 60%),
              linear-gradient(180deg,#070a1c,#0b0820); }
.panels { position:absolute; left:calc(var(--u)*2); right:calc(var(--u)*2); top:calc(var(--u)*2); bottom:calc(var(--u)*8.4); display:flex; gap:calc(var(--u)*2); }
.panel { flex:1 1 0; min-width:0; display:flex; flex-direction:column; gap:var(--u); }  /* 50 : 50 */
.frame { position:relative; flex:1; min-height:0; border-radius:calc(var(--u)*1.6); overflow:hidden; background:#04050f; border:calc(var(--u)*.4) solid; }
.frame.blue { border-color:var(--blue); box-shadow: 0 0 calc(var(--u)*2.6) rgba(46,139,255,.45), inset 0 0 calc(var(--u)*1.6) rgba(46,139,255,.18); }
.frame.purple { border-color:var(--purple); box-shadow: 0 0 calc(var(--u)*2.6) rgba(155,92,255,.5), inset 0 0 calc(var(--u)*1.6) rgba(155,92,255,.2);
  background: radial-gradient(80% 60% at 50% 100%, rgba(155,92,255,.35), transparent 70%), linear-gradient(180deg,#120b32,#0a0620); }
.label { text-align:center; font-weight:800; font-size:max(calc(var(--u)*2.5), 13px); letter-spacing:.02em; line-height:1.2; }
.label.blue { color:#7db6ff; } .label.purple { color:#c4a2ff; }
.tvbar { position:absolute; left:calc(var(--u)*2); right:calc(var(--u)*2); bottom:calc(var(--u)*1.6); height:calc(var(--u)*3.9); display:flex; align-items:center; justify-content:center;
  border-radius:calc(var(--u)*2); font-weight:800; font-size:max(calc(var(--u)*1.9), 10px); letter-spacing:.05em; white-space:nowrap;
  background: linear-gradient(90deg, rgba(46,139,255,.28), rgba(155,92,255,.32)); border:1px solid rgba(255,255,255,.14); }

/* 사용자 카메라: 높이를 항상 꽉 채워 머리~발끝이 잘리지 않게 한다 */
.camBox { position:absolute; inset:0; width:100%; height:100%; overflow:hidden; }
.camBox.mirror { transform: scaleX(-1); }
.camBox video, .camBox canvas { position:absolute; inset:0; width:100%; height:100%; display:block; }
.camBox video, .camBox canvas { object-fit:cover; object-position:center; }
.camBox video { background:#000; }
#gl { position:absolute; inset:0; width:100%; height:100%; display:block; }

.idle { position:absolute; inset:0; display:grid; place-items:center; text-align:center; padding:4%; background:rgba(4,5,15,.78); }
.idle b { display:block; font-size:max(calc(var(--u)*2.2), 13px); margin-bottom:calc(var(--u)*.6); }
.idle span { color:var(--muted); font-size:max(calc(var(--u)*1.5), 11px); }
.chip { position:absolute; left:50%; top:calc(var(--u)*1.2); transform:translateX(-50%); padding:calc(var(--u)*.55) calc(var(--u)*1.4); border-radius:99px;
  font-size:max(calc(var(--u)*1.5), 11px); font-weight:700; background:rgba(8,10,28,.86); border:1px solid rgba(255,255,255,.2); max-width:92%; text-align:center; }
.chip.ok { color:#6dffb0; border-color:var(--ok); } .chip.warn { color:#ffd166; border-color:var(--warn); } .chip.info { color:#9fc4ff; }
.countdown { position:absolute; inset:0; display:grid; place-items:center; font-size:calc(var(--u)*22); font-weight:900; color:#fff;
  text-shadow:0 0 calc(var(--u)*4) var(--purple); pointer-events:none; z-index:3; }
.tvhud { position:absolute; top:calc(var(--u)*1.2); left:50%; transform:translate(-50%,-160%); display:none; gap:.6em; z-index:5; opacity:0; visibility:hidden; pointer-events:none; transition:transform .25s, opacity .18s ease, visibility .18s; }
.tvhud button { padding:.8em 1.3em; border-radius:99px; background:rgba(10,12,32,.92); border:1px solid rgba(255,255,255,.25); font-size:max(14px,1.4vw); }
.tvhud button.danger { background:#d6336c; }
.tv .tvhud { display:flex; } .tv .tvhud.show { transform:translate(-50%,10px); opacity:1; visibility:visible; pointer-events:auto; }

/* ───────── 조작 패널 ───────── */
#controls { flex:1; min-height:0; overflow:auto; padding:10px 14px calc(18px + env(safe-area-inset-bottom)); background:var(--panel); -webkit-overflow-scrolling:touch; }
.sbar { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:10px; }
.pill { display:inline-flex; align-items:center; gap:6px; padding:5px 10px; border-radius:99px; background:var(--card); font-size:12px; font-weight:600; color:var(--muted); white-space:nowrap; }
.pill i { width:8px; height:8px; border-radius:50%; background:#5b6397; flex:none; }
.pill em { font-style:normal; }
.pill.ok { color:#c8ffe3; } .pill.ok i { background:var(--ok); box-shadow:0 0 8px var(--ok); }
.pill.warn { color:#ffe6a6; } .pill.warn i { background:var(--warn); }
.pill.bad { color:#ffc2cd; } .pill.bad i { background:var(--bad); }
.msg { display:flex; gap:8px; align-items:flex-start; padding:10px 12px; border-radius:12px; background:#3a1630; border:1px solid var(--bad); font-size:14px; line-height:1.45; margin-bottom:10px; }
.msg.info { background:#142a52; border-color:var(--blue); }
.msg span { flex:1; } .x { background:none; font-size:22px; line-height:1; padding:0 4px; color:var(--muted); }

.main4 { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
.act { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px; min-height:68px; padding:10px 4px; border-radius:14px;
  background:var(--card); border:1px solid var(--line); font-size:13px; line-height:1.2; text-align:center; }
.act .ic { width:26px; height:26px; }
.act b { font-weight:700; }
.act.accent { background:linear-gradient(160deg,#1f5fd0,#6a3ad6); border-color:transparent; }
.act.on { background:#3a1e55; border-color:var(--purple); }
.wbar { display:flex; align-items:stretch; gap:8px; margin-top:10px; }
.timer { flex:none; min-width:84px; background:var(--card); border-radius:14px; padding:8px 12px; display:flex; flex-direction:column; justify-content:center; text-align:center; }
.timer span { font-size:11px; color:var(--muted); } .timer b { font-size:20px; font-variant-numeric:tabular-nums; }
.wbar button { flex:1; display:flex; align-items:center; justify-content:center; gap:8px; padding:14px 10px; min-height:56px; border-radius:14px; font-size:17px; font-weight:800; }
.primary { background:linear-gradient(90deg,var(--blue),var(--purple)); }
.danger { background:#d6336c; }
.ghost { background:#1b2046; border:1px solid var(--line); padding:12px 14px; border-radius:12px; width:100%; margin-top:8px; display:flex; gap:8px; align-items:center; justify-content:center; }
.big { width:100%; padding:16px; border-radius:14px; font-size:17px; font-weight:800; display:flex; gap:8px; align-items:center; justify-content:center; }
h3 { margin:16px 0 8px; font-size:13px; color:var(--muted); font-weight:700; letter-spacing:.04em; }
.chars { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
.char { background:var(--card); border:2px solid transparent; border-radius:14px; padding:8px 4px 10px; text-align:center; font-weight:700; font-size:13px; min-height:92px; }
.char .pic { width:46px; height:46px; margin:0 auto 4px; border-radius:50%; overflow:hidden; background:#0d1030 center/cover no-repeat; display:grid; place-items:center; font-size:26px; }
.char small { display:block; color:var(--muted); font-weight:500; margin-top:1px; font-size:11px; }
.char.on { border-color:var(--purple); background:#241a55; }
.modes { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
.mode { background:var(--card); border:2px solid transparent; border-radius:12px; padding:10px 4px; font-size:13px; font-weight:700; display:flex; flex-direction:column; align-items:center; gap:4px; }
.mode small { color:var(--muted); font-weight:500; font-size:10.5px; }
.mode.on { border-color:var(--blue); background:#14295a; }
details { margin-top:14px; background:var(--card); border-radius:12px; padding:0 12px; }
summary { padding:12px 0; font-weight:700; cursor:pointer; list-style:none; display:flex; gap:8px; align-items:center; }
summary::-webkit-details-marker { display:none; }
details[open] { padding-bottom:12px; }
.switch, .slider { display:flex; gap:10px; align-items:flex-start; margin:10px 0; font-size:14px; }
.slider { flex-direction:column; gap:6px; } .slider input { width:100%; accent-color:var(--purple); }
.switch input { width:22px; height:22px; margin-top:1px; accent-color:var(--purple); flex:none; }
small { display:block; color:var(--muted); font-size:11.5px; margin-top:2px; font-weight:400; }
.note { color:var(--muted); font-size:12px; margin-top:14px; line-height:1.5; }

/* 인앱 브라우저 안내 */
#inapp { position:fixed; z-index:100; left:0; right:0; top:0; display:flex; gap:8px; align-items:center; flex-wrap:wrap; padding:10px 12px calc(10px) ;
  padding-top:max(10px, env(safe-area-inset-top)); background:#4a1d1d; border-bottom:1px solid var(--bad); font-size:13px; line-height:1.4; }
#inapp div { flex:1 1 220px; } #inapp b { display:block; font-size:14px; }
.mini { padding:9px 12px; border-radius:10px; background:#d6336c; font-weight:700; font-size:13px; } .mini.ghost { background:#2a2f5c; width:auto; margin:0; border:0; }

/* TV 연결 / 도움말 다이얼로그 */
dialog { background:#12173a; color:var(--text); border:1px solid var(--line); border-radius:18px; width:min(520px,94vw); max-height:92dvh; overflow:auto; padding:18px; }
dialog::backdrop { background:rgba(0,0,0,.65); }
.dhead { display:flex; align-items:center; gap:10px; margin-bottom:10px; } .dhead h2 { margin:0; font-size:20px; flex:1; }
.dev { font-size:12px; padding:4px 10px; border-radius:99px; background:var(--card); color:var(--muted); }
.tvstatus { padding:10px 12px; border-radius:12px; background:var(--card); font-size:14px; font-weight:600; margin-bottom:12px; border-left:4px solid #5b6397; }
.tvstatus.ok { border-color:var(--ok); } .tvstatus.warn { border-color:var(--warn); }
dialog section { margin-bottom:14px; } dialog h4 { margin:0 0 6px; font-size:15px; }
dialog ol { padding-left:20px; line-height:1.65; margin:0 0 8px; font-size:14px; }
.hint { color:var(--muted); font-size:12.5px; margin:6px 0 0; line-height:1.5; }

/* ───────── 가로 화면: 스테이지(왼쪽) + 조작 패널(오른쪽) ───────── */
@media (orientation: landscape) {
  #root { flex-direction:row; background:#000; }
  #stageWrap, .working #stageWrap { width:min(calc(100vw - var(--cw)), calc(100dvh * 16 / 9)); height:auto; aspect-ratio:16/9; align-self:center; }
  #stage { --u:1cqw; }
  #controls { width:var(--cw); flex:none; height:100dvh; padding-top:calc(10px + env(safe-area-inset-top)); }
  .working .secondary { display:block; }
  .main4 { grid-template-columns:repeat(2,1fr); }
}
@media (orientation: landscape) and (max-height: 520px) {
  .act { min-height:48px; flex-direction:row; gap:8px; padding:8px; font-size:12.5px; } .act .ic { width:20px; height:20px; }
  .wbar button { min-height:46px; padding:8px; font-size:15px; } .timer { padding:4px 8px; } .timer b { font-size:16px; }
  .chars, .modes { grid-template-columns:repeat(2,1fr); } .char { min-height:0; padding:8px 4px; } .char .pic { display:none; }
  h3 { margin:12px 0 6px; } .pill { padding:3px 8px; font-size:11px; }
}
/* 운동 중(세로): 보조 메뉴를 숨겨 화면을 크게 */
.working .secondary { display:none; }
@media (orientation: landscape) { .working .secondary { display:block; } }

/* 운동 중에는 스테이지를 전체 화면으로 유지하고 조작 패널만 오버레이합니다. */
body.workout-fullscreen #root { display:block; height:100dvh; }
body.workout-fullscreen #stageWrap { position:fixed; inset:0; z-index:10; width:100vw; height:100dvh; margin:0; transition:none; }
body.workout-fullscreen #stage { position:relative; inset:auto; width:100%; height:100%; --u:1cqw; }
body.workout-fullscreen .panels { left:0; right:0; top:0; bottom:0; gap:0; }
body.workout-fullscreen .panel { gap:0; }
body.workout-fullscreen .frame { border:0; border-radius:0; box-shadow:none; }
body.workout-fullscreen .label,
body.workout-fullscreen .tvbar { display:none; }
body.workout-fullscreen #inapp { display:none !important; }
body.workout-fullscreen #controls {
  position:fixed; z-index:20; left:0; right:0; bottom:0; top:auto; width:100%; height:auto; max-height:min(72dvh, 640px);
  flex:none; padding:8px 12px calc(10px + env(safe-area-inset-bottom)); overflow:auto;
  background:linear-gradient(180deg,rgba(7,10,28,.82),rgba(7,10,28,.97));
  border-top:1px solid rgba(255,255,255,.16); backdrop-filter:blur(12px); -webkit-backdrop-filter:blur(12px);
  transition:opacity .18s ease, transform .18s ease; transform:translateY(0); opacity:1; visibility:visible;
}
body.workout-fullscreen:not(.workout-ui-visible) #controls { transform:translateY(calc(100% + 18px)); opacity:0; visibility:hidden; pointer-events:none; }
body.workout-fullscreen #controls.workout-ui-hidden { transform:translateY(calc(100% + 18px)) !important; opacity:0 !important; visibility:hidden !important; pointer-events:none !important; }
body.workout-fullscreen #controls .sbar,
body.workout-fullscreen #controls .note { display:none; }
body.workout-fullscreen.workout-ui-visible #controls .secondary { display:block; }
body.workout-fullscreen #controls .wbar { margin-top:8px; }
body.workout-fullscreen #controls .timer { min-width:72px; }
body.workout-fullscreen #controls .wbar button { min-height:48px; padding:10px; }
@media (orientation:landscape) {
  body.workout-fullscreen #stageWrap { width:100vw; height:100dvh; aspect-ratio:auto; }
  body.workout-fullscreen #controls { left:auto; right:12px; bottom:12px; width:min(420px, 46vw); max-height:80dvh; border:1px solid rgba(255,255,255,.16); border-radius:16px; }
}

/* ───────── TV 전체 화면: 브라우저 UI 없는 16:9 ───────── */
.tv #controls, .tv #inapp { display:none !important; }
.tv #root { display:block; background:#000; }
.tv #stageWrap, .tv.working #stageWrap { position:fixed; inset:0; width:100vw; height:100dvh; aspect-ratio:auto; margin:0; display:grid; place-items:center; z-index:50; }
.tv #stage { position:relative; inset:auto; --u:1cqw; width:min(100vw, calc(100dvh * 16 / 9)); height:min(100dvh, calc(100vw * 9 / 16)); }
.tv.workout-fullscreen #stage { width:min(100vw, calc(100dvh * 16 / 9)); height:min(100dvh, calc(100vw * 9 / 16)); }
.tv { cursor:none; }
.receiver #stage { --u:1cqw; }

.wbar button.ghost-work { background:#2a3170; border:1px solid var(--blue); }
