:root {
  --bg: #000;
  --panel: rgba(18, 18, 20, 0.92);
  --fg: #f5f5f7;
  --muted: #a1a1aa;
  --accent: #ffd54a;
  --good: #5cf0a0;
  --warn: #ffb347;
  --chip: rgba(255, 255, 255, 0.12);
  --chip-on: #fff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; overscroll-behavior: none; }
body { font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* 상단 바 */
#topbar { display: flex; justify-content: space-around; padding: calc(var(--safe-top) + 4px) 6px 4px; z-index: 5; }
.tb { display: flex; flex-direction: column; align-items: center; min-width: 48px; padding: 4px 2px; border-radius: 10px; }
.tb b { font-size: 15px; line-height: 20px; }
.tb small { font-size: 10px; color: var(--muted); }
.tb.on b { color: var(--accent); }

/* 뷰파인더 */
#viewport { flex: 1; position: relative; display: flex; align-items: flex-start; justify-content: center; min-height: 0; }
#stage { position: relative; overflow: hidden; background: #111; border-radius: 4px; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: filter .25s; }
#video.mirror { transform: scaleX(-1); }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

#coach {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: calc(100% - 24px);
  padding: 9px 14px; border-radius: 14px; font-size: 14px; line-height: 1.35; font-weight: 600; text-align: center;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .12); transition: background .2s, border-color .2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
#coach.warn { border-color: var(--warn); color: #ffe2b8; }
#coach.good { border-color: var(--good); color: var(--good); background: rgba(0, 40, 20, .6); }
#coachAction { flex: none; background: var(--accent); color: #000; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }

#sceneChip {
  position: absolute; top: 64px; left: 12px; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: rgba(0, 0, 0, .5); border: 1px solid rgba(255, 255, 255, .15); backdrop-filter: blur(6px);
}
#stageBottom { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pill { padding: 6px 12px; border-radius: 999px; background: rgba(0, 0, 0, .5); border: 1px solid rgba(255, 255, 255, .18); font-size: 12px; font-weight: 600; }
#zoomChips { display: flex; gap: 4px; background: rgba(0, 0, 0, .45); border-radius: 999px; padding: 3px; }
#zoomChips:empty { display: none; }
#zoomChips button { width: 34px; height: 34px; border-radius: 50%; font-size: 11px; font-weight: 700; }
#zoomChips button.on { background: rgba(255, 255, 255, .2); color: var(--accent); }

#countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 120px; font-weight: 800; text-shadow: 0 4px 30px rgba(0, 0, 0, .6); pointer-events: none; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
#loading { position: absolute; bottom: 56px; left: 50%; transform: translateX(-50%); font-size: 12px; background: rgba(0, 0, 0, .6); padding: 5px 12px; border-radius: 999px; white-space: nowrap; }

/* 하단 컨트롤 */
#controls { padding: 6px 0 calc(var(--safe-bot) + 8px); background: linear-gradient(to top, #000 70%, rgba(0, 0, 0, .6)); z-index: 5; }
.hscroll { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 0 12px; }
.hscroll::-webkit-scrollbar { display: none; }
#poseStrip { padding-bottom: 6px; }
.pose-card {
  flex: none; width: 70px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px 4px;
  border-radius: 12px; background: var(--chip); color: #d4d4d8; position: relative; border: 1.5px solid transparent;
}
.pose-card svg { opacity: .9; }
.pose-card span { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 66px; }
.pose-card.on { border-color: var(--accent); color: var(--accent); background: rgba(255, 213, 74, .12); }
.pose-card .star { position: absolute; top: 3px; right: 5px; font-size: 10px; }
.pose-card.none { justify-content: center; font-size: 22px; }

#row2 { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px 12px; }
.seg { display: flex; flex: none; background: var(--chip); border-radius: 999px; padding: 3px; }
.seg button { padding: 6px 9px; white-space: nowrap; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: #000; }
#presetStrip { flex: 1; padding-left: 0; }
.chip { flex: none; padding: 6px 11px; border-radius: 999px; background: var(--chip); font-size: 12px; font-weight: 600; color: #d4d4d8; white-space: nowrap; }
.chip.on { background: var(--chip-on); color: #000; }

#bottombar { display: flex; align-items: center; justify-content: space-around; padding-top: 4px; }
#btnGallery { width: 52px; height: 52px; border-radius: 12px; overflow: hidden; background: #222; border: 2px solid rgba(255, 255, 255, .25); padding: 0; }
#btnGallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
#btnGallery img:not([src]) { display: none; }
#btnFlip { width: 52px; height: 52px; border-radius: 50%; background: var(--chip); font-size: 22px; }
#shutter { position: relative; width: 82px; height: 82px; border-radius: 50%; padding: 0; touch-action: none; }
#ring { position: absolute; inset: 0; transform: rotate(-90deg); }
#ring circle { fill: none; stroke-width: 6; }
#ring .track { stroke: rgba(255, 255, 255, .85); }
#ring .meter { stroke: var(--good); stroke-linecap: round; stroke-dasharray: 289; stroke-dashoffset: 289; transition: stroke-dashoffset .25s, stroke .25s; }
#shutterInner { position: absolute; inset: 11px; border-radius: 50%; background: #fff; transition: transform .1s, background .2s; }
#shutter:active #shutterInner { transform: scale(.9); }
#shutter.burst #shutterInner { background: #ff5a5a; }
#scoreLabel { position: absolute; inset: 0; display: grid; place-items: center; color: #000; font-weight: 800; font-size: 17px; }

/* 시작 화면 */
.overlay { position: fixed; inset: 0; z-index: 50; background: radial-gradient(120% 80% at 50% 0%, #2a2140 0%, #0b0b10 60%); display: grid; place-items: center; overflow-y: auto; padding: 24px 18px; }
.start-card { max-width: 420px; width: 100%; }
.logo { font-size: 54px; text-align: center; }
.start-card h1 { text-align: center; margin: 6px 0 6px; font-size: 26px; letter-spacing: -.5px; }
.sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.feat { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 9px; }
.feat li { background: rgba(255, 255, 255, .06); border-radius: 14px; padding: 11px 13px; font-size: 13px; line-height: 1.45; color: #d4d4d8; }
.feat b { display: block; color: #fff; font-size: 14px; margin-bottom: 1px; }
.primary { width: 100%; padding: 15px; border-radius: 14px; background: var(--accent); color: #111; font-weight: 800; font-size: 16px; }
.primary:disabled { opacity: .5; }
.fine { color: #71717a; font-size: 11.5px; text-align: center; margin-top: 10px; }

/* 시트 */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(10, 10, 12, .98); display: flex; flex-direction: column; padding: calc(var(--safe-top) + 6px) 0 calc(var(--safe-bot) + 12px); }
.sheet[hidden], [hidden] { display: none !important; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 10px; }
.ghost { padding: 8px 10px; border-radius: 10px; font-size: 14px; color: #e4e4e7; }
#rvImgWrap { flex: 1; min-height: 0; position: relative; overflow: hidden; }
#rvImg { position: absolute; inset: 0 8px; width: calc(100% - 16px); height: 100%; object-fit: contain; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 60px; font-size: 36px; color: rgba(255, 255, 255, .8); text-shadow: 0 1px 8px #000; }
#rvPrev { left: 4px; } #rvNext { right: 4px; }
#rvBadge { position: absolute; top: 8px; left: 16px; font-size: 11px; padding: 3px 9px; border-radius: 999px; background: rgba(0, 0, 0, .6); }
#rvPresets { padding: 12px 12px 6px; }
.rv-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 14px 12px; }
.slider { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex: 1; }
.slider input { flex: 1; accent-color: var(--accent); }
#rvSave { width: calc(100% - 24px); margin: 0 12px; }

.guide-body { overflow-y: auto; padding: 0 16px 20px; flex: 1; -webkit-user-select: text; user-select: text; }
.guide-body h3 { font-size: 15px; margin: 22px 0 8px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
#sceneGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-bottom: 14px; }
#sceneGrid button { padding: 12px 4px; border-radius: 12px; background: var(--chip); font-size: 13px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#sceneGrid button span { font-size: 22px; }
#sceneGrid button.on { background: #fff; color: #000; }
#tipList, .rules { padding-left: 0; list-style: none; display: grid; gap: 8px; margin: 0; }
#tipList li, .rules li { background: rgba(255, 255, 255, .06); padding: 10px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; }
#aiResult { margin-top: 10px; font-size: 13.5px; line-height: 1.55; }
#aiResult .ai-box { background: rgba(92, 240, 160, .08); border: 1px solid rgba(92, 240, 160, .3); border-radius: 12px; padding: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid rgba(255, 255, 255, .08); font-size: 14px; }
.row small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.row input[type=number], #stKey { background: #1c1c1f; color: #fff; border: 1px solid #333; border-radius: 10px; padding: 10px; font-size: 14px; }
.row input[type=number] { width: 72px; }
#stKey { width: 100%; }

#toast { position: fixed; left: 50%; bottom: calc(var(--safe-bot) + 200px); transform: translateX(-50%); z-index: 60; width: max-content; background: rgba(30, 30, 34, .95); padding: 10px 16px; border-radius: 12px; font-size: 13.5px; max-width: calc(100% - 32px); text-align: center; border: 1px solid rgba(255, 255, 255, .1); display: flex; gap: 10px; align-items: center; }
#toast button { background: var(--accent); color: #000; border-radius: 999px; padding: 5px 11px; font-weight: 700; font-size: 12px; flex: none; }

@media (min-width: 900px) {
  #controls { max-width: 720px; width: 100%; margin: 0 auto; }
}

/* 셀카: 링라이트 & 화면 플래시 */
#app.ring #viewport { background: #fff3df; padding: 16px 16px 10px; align-items: center; }
#app.ring #stage { border-radius: 18px; }
#btnRing.on { background: #fff3df; color: #000; }
#frontFlash { position: fixed; inset: 0; z-index: 70; background: #fff8ec; opacity: 0; pointer-events: none; transition: opacity .08s; }
#frontFlash.on { opacity: 1; }
