:root {
  --bg: #0b1a2b; --card: #12283d; --line: #2b4a63; --ink: #eaf7f5; --dim: #9dbcc6;
  --teal: #7fe3d4; --teal-d: #3f9e95; --gold: #ffd56b; --coral: #ff7a8a;
  --head: 'Black Han Sans', 'Pretendard', sans-serif;
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; background: #060e18; color: var(--ink); font-family: 'Pretendard', -apple-system, sans-serif; overflow: hidden; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; }
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

#panel { position: fixed; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100vw, 62vh); background: var(--bg); overflow: hidden; }
@media (max-aspect-ratio: 3/4) { #panel { width: 100vw; } }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; padding: calc(22px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; z-index: 3; }
.brand { text-align: center; margin-bottom: auto; padding-top: 2.5vh; }
.hero { display: flex; justify-content: center; align-items: flex-end; margin-top: 10px; }
.hero img { width: 64px; height: 64px; object-fit: contain; }
.hero img.big { width: 108px; height: 108px; margin: 0 -4px; }
@media (max-height: 760px) { .hero { display: none; } }
.brand h1 { font: 400 clamp(46px, 14vw, 60px)/1.05 var(--head); letter-spacing: -.5px; color: #fff; text-shadow: 0 4px 0 #0e5d6e; }
.brand p { margin-top: 10px; color: var(--teal); font-weight: 700; font-size: 15px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.lbl { font-size: 13px; font-weight: 700; color: var(--dim); }
.lbl small { font-weight: 500; opacity: .8; margin-left: 4px; }
.input { width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 700 17px 'Pretendard', sans-serif; outline: none; }
.input:focus { border-color: var(--teal); }
.input::placeholder { color: #5f7f8e; font-weight: 500; }
.input.code { text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.input.code::placeholder { letter-spacing: 0; }

.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chars button { position: relative; padding: 6px 2px 5px; border-radius: 12px; border: 2px solid transparent; background: var(--bg); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 700; color: var(--dim); min-width: 0; overflow: hidden; }
.chars button img { height: 46px; width: 46px; object-fit: contain; }
.chars button.on { border-color: var(--teal); background: #173a4c; color: #fff; }
.chars button:disabled { opacity: .35; }
.chars.tiny { grid-template-columns: repeat(8, 1fr); gap: 4px; }
.chars.tiny button { padding: 3px 0; }
.chars.tiny button img { height: 32px; width: 100%; }
.chars.tiny button span { display: none; }

.btns { display: flex; flex-direction: column; gap: 8px; }
.btn { height: 50px; padding: 0 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-weight: 800; font-size: 16px; color: var(--ink); }
.btn.primary { height: 58px; background: var(--teal); border: 0; color: #06303a; box-shadow: 0 5px 0 var(--teal-d); font: 400 22px var(--head); letter-spacing: .3px; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--teal-d); }
.btn.primary:disabled { background: #2c4a5c; color: #8fb0bb; box-shadow: 0 5px 0 #1e3646; transform: none; }
.btn.ghost { color: var(--dim); }
.btn.small { height: 42px; font-size: 15px; background: var(--bg); }
.codeRow { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.codeRow .input { height: 50px; }
.fan { text-align: center; font-size: 11px; color: #cfe6e6; }

#lobby { background: var(--bg); }
.roomHead { text-align: center; }
.roomHead b { display: block; font: 400 64px/1.1 var(--head); letter-spacing: 8px; color: var(--gold); margin-right: -8px; }
.qrCard { flex-direction: row; align-items: center; gap: 14px; }
.qr { width: 118px; height: 118px; flex: none; background: #fff; border-radius: 10px; padding: 8px; }
.qr svg { width: 100%; height: 100%; display: block; }
.qrSide { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.qrSide p { font-size: 14px; color: var(--dim); font-weight: 600; line-height: 1.4; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.slot { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 124px; justify-content: center; }
.slot img { height: 70px; width: 70px; object-fit: contain; }
.slot b { font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot small { font-size: 11px; color: var(--teal); font-weight: 700; }
.slot.empty { border-style: dashed; color: var(--dim); font-size: 14px; font-weight: 600; }
.slot.off { opacity: .5; }
#lobby .btns { margin-top: auto; }

#game { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
#hudTop { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
#dist { display: flex; align-items: baseline; gap: 6px; background: #0b1a2b; border: 1px solid var(--line); border-radius: 12px; padding: 5px 14px 6px; font-family: var(--head); }
#dNow { font-size: 30px; font-weight: 400; color: #fff; font-variant-numeric: tabular-nums; }
#dNext { font-size: 17px; color: var(--dim); }
#zone { font-size: 12px; font-weight: 800; color: var(--teal); }
#tip { position: absolute; top: calc(92px + env(safe-area-inset-top)); left: 16px; right: 16px; text-align: center; font-size: 15px; font-weight: 800; color: #06303a; background: var(--gold); border-radius: 12px; padding: 9px 12px; line-height: 1.35; word-break: keep-all; }
#count { position: absolute; top: 25%; left: 0; right: 0; text-align: center; font: 400 104px/1 var(--head); color: #fff; text-shadow: 0 6px 0 #0e5d6e; }
#count.pop { animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(1.6); } to { transform: scale(1); } }
#tapBar { position: absolute; left: 16px; right: 16px; bottom: calc(14px + env(safe-area-inset-bottom)); height: 66px; display: flex; align-items: center; justify-content: center; background: #0b1a2b; border: 1px solid var(--line); border-radius: 16px; transition: background .08s, border-color .08s; }
#tapBar { overflow: hidden; }
#tapFill { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; transform: scaleX(0); transform-origin: left; background: var(--gold); }
/* 스와이프 게이지: 손가락 옆에 뜬다. 위치는 game.js 의 placeGauge */
#swg { position: absolute; left: 0; top: 0; width: 28px; height: 186px; margin-left: -14px; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; opacity: .75; } /* 화면 가운데서 쥐면 캐릭터 위에 뜰 수 있어 비쳐 보이게 */
#swgBar { position: relative; flex: 1; width: 16px; background: #0b1a2b; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
#swgFill { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; transform: scaleY(0); transform-origin: bottom; background: var(--gold); }
#swgBar::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(to top, transparent 0 calc(100% / 6 - 2px), #0b1a2b calc(100% / 6 - 2px) calc(100% / 6)); }
#swg .chev { width: 10px; height: 10px; border: 3px solid var(--ink); border-right: 0; border-bottom: 0; }
#swg .chev.up { transform: translateY(3px) rotate(45deg); }
#swg .chev.dn { transform: translateY(-3px) rotate(225deg); }
#tapText { position: relative; font: 400 30px var(--head); color: #fff; }
#tapBar.hold { background: #0b1a2b; border-color: var(--gold); }
#tapBar.hold #tapText { color: #fff; text-shadow: 0 2px 0 #0b1a2b, 2px 0 0 #0b1a2b, -2px 0 0 #0b1a2b, 0 -2px 0 #0b1a2b; }
#tapBar.go { background: var(--teal); border-color: var(--teal); }
#tapBar.go #tapText { color: #06303a; }
#tapBar.pull { background: var(--gold); border-color: var(--gold); }
#tapBar.pull #tapText { color: #4a2f00; }
#tapBar.bad { background: #5c1e2b; border-color: var(--coral); }
#tapBar.bad #tapText { color: #ffd9de; }
#tapBar.wait #tapText { color: var(--dim); }
#tapBar.kick { animation: kick .14s ease-out; }
@keyframes kick { from { transform: scale(1.05); } to { transform: scale(1); } }

#result { background: var(--bg); text-align: center; align-items: stretch; }
#result > :first-child { margin-top: auto; } /* justify-content:center 는 넘친 위쪽을 스크롤 밖으로 민다 */
#result > :last-child { margin-bottom: auto; }
.kicker { font-size: 19px; font-weight: 800; color: var(--coral); line-height: 1.3; }
.pair { position: relative; display: flex; justify-content: center; align-items: flex-end; gap: 2px; height: 128px; }
.pair img { height: 92px; width: 92px; object-fit: contain; }
.pair img.siren { position: absolute; right: 2%; bottom: -8px; height: 124px; width: 124px; }
.score { font-family: var(--head); line-height: 1; }
.score b { font-size: 84px; font-weight: 400; color: #fff; }
.score span { font-size: 28px; color: var(--dim); margin-left: 4px; }
.sub { font-size: 14px; font-weight: 700; color: var(--dim); min-height: 18px; }
.peer { color: var(--gold); font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 2px; }
.stats dt { font-size: 12px; color: var(--dim); font-weight: 700; }
.stats dd { margin-top: 2px; font: 400 24px var(--head); color: var(--gold); }
#rBlame { color: var(--gold); margin-top: -8px; }

#pause, #rank, #busy { position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; background: #0b1a2b; padding: 16px; }
#pause { background: transparent; pointer-events: none; align-items: flex-start; padding-top: calc(140px + env(safe-area-inset-top)); }
.box { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px 16px; text-align: center; display: flex; flex-direction: column; gap: 8px; max-height: 100%; }
#pause .box b { font: 400 26px var(--head); color: var(--gold); }
#pause .box p { color: var(--dim); font-weight: 700; font-size: 15px; }
#rank h2 { font: 400 28px var(--head); color: #fff; font-weight: 400; }
#rkList { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 120px; max-height: 60vh; }
#rkList li { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--bg); border-radius: 10px; font-size: 14px; font-weight: 700; text-align: left; }
#rkList li.empty { justify-content: center; color: var(--dim); padding: 28px 0; background: none; }
#rkList li.me { outline: 2px solid var(--teal); }
#rkList .p { width: 24px; color: var(--teal); font-family: var(--head); font-weight: 400; font-size: 18px; text-align: center; flex: none; }
#rkList .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rkList .av { display: flex; flex: none; }
#rkList .av img { width: 26px; height: 26px; object-fit: contain; }
#rkList b { font-family: var(--head); font-weight: 400; font-size: 18px; color: var(--gold); flex: none; }
#busy { flex-direction: column; gap: 14px; text-align: center; }
#busy p { font-size: 17px; font-weight: 800; color: var(--teal); }
#toast { position: absolute; left: 16px; right: 16px; top: calc(16px + env(safe-area-inset-top)); z-index: 9; background: var(--gold); color: #3f2b00; font-weight: 800; font-size: 15px; text-align: center; padding: 10px 12px; border-radius: 12px; }
#game:not([hidden]) ~ #toast { top: calc(92px + env(safe-area-inset-top)); }
#snd { position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top)); z-index: 7; width: 40px; height: 40px; border-radius: 12px; background: #0b1a2b; border: 1px solid var(--line); font-size: 17px; }
#combo { position: absolute; left: 12px; top: calc(12px + env(safe-area-inset-top)); background: #0b1a2b; border: 1px solid var(--line); border-radius: 12px; padding: 7px 11px; font: 400 17px var(--head); color: var(--teal); }
#combo.fever { background: var(--gold); border-color: var(--gold); color: #4a2f00; }
#wind { position: absolute; right: 12px; top: calc(60px + env(safe-area-inset-top)); background: #0b1a2b; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; font-size: 14px; font-weight: 800; color: #dff6ff; }
#wind.warn { border-color: var(--gold); color: var(--gold); }
#big, #lcBox { position: absolute; left: 0; right: 0; top: 26%; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 0 16px; }
#big b { font: 400 48px/1.1 var(--head); color: #fff; text-shadow: 0 4px 0 #0e5d6e, 0 0 3px #0b1a2b; }
#big span, #lcBox span { font-size: 17px; font-weight: 800; color: #0b1a2b; background: var(--gold); border-radius: 10px; padding: 4px 12px; }
#big span:empty { display: none; }
#big.bad b { color: #ffd9de; text-shadow: 0 4px 0 #8a2238, 0 0 3px #0b1a2b; }
#big.gold b { color: var(--gold); text-shadow: 0 4px 0 #7a4a00, 0 0 3px #0b1a2b; }
#big.pop { animation: bigpop .32s cubic-bezier(.2, 1.7, .4, 1); }
@keyframes bigpop { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#lcBox { top: 20%; }
#lcBox b { font: 400 46px/1 var(--head); color: var(--coral); text-shadow: 0 4px 0 #4a0f1c, 0 0 3px #000; letter-spacing: .5px; }
#lcBox span { font: 400 36px/1.15 var(--head); background: var(--coral); color: #2a0610; padding: 6px 18px; animation: throb .42s ease-in-out infinite alternate; }
#lcBox.off span { background: #0b1a2b; color: var(--dim); font: 800 17px 'Pretendard', sans-serif; animation: none; }
@keyframes throb { to { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { #count.pop, #tapBar.kick, #big.pop, #lcBox span { animation: none; } }
