:root {
  --bg: #15131f;
  --card: #211e2e;
  --line: #322d47;
  --text: #f6f3ff;
  --mute: #a39dbb;
  --yellow: #ffd23f;
  --pink: #ff4f79;
  --red: #e63946;
  --green: #2bd96b;
  --display: 'Black Han Sans', 'Pretendard', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 'Pretendard', -apple-system, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.screen { max-width: 480px; margin: 0 auto; padding: 20px 16px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; min-height: 100%; }
.top { display: flex; justify-content: space-between; align-items: center; }
.logo { font-family: var(--display); font-size: 22px; color: var(--yellow); font-weight: 400; }
.code { font-family: var(--display); font-size: 18px; letter-spacing: 2px; background: var(--card); border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.card-h { font-size: 13px; color: var(--mute); margin-bottom: 10px; display: flex; justify-content: space-between; }
.card-h b { color: var(--text); }

.input { width: 100%; height: 52px; border-radius: 14px; border: 2px solid var(--line); background: #0f0d18; color: var(--text); font: 600 18px 'Pretendard', sans-serif; padding: 0 14px; outline: none; }
.input:focus { border-color: var(--yellow); }
.field span { display: block; font-size: 13px; color: var(--mute); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row .input { flex: 1; }

.btn { height: 52px; padding: 0 20px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); font-weight: 700; font-size: 16px; }
.btn.primary { background: var(--yellow); color: #1a1500; border-color: var(--yellow); box-shadow: 0 5px 0 #b8901a; }
.btn.primary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #b8901a; }
.btn.big { height: 64px; font-family: var(--display); font-size: 24px; font-weight: 400; width: 100%; }
.btn.ghost { background: transparent; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }

.hero { padding: 28px 0 8px; }
.logo-big { font-family: var(--display); font-size: 64px; line-height: 1; color: var(--yellow); text-shadow: 4px 4px 0 var(--pink); }
.hero p { margin-top: 14px; font-size: 18px; color: var(--mute); }
.or { text-align: center; color: var(--mute); font-size: 13px; margin-top: 6px; }
.code-in { text-transform: uppercase; letter-spacing: 6px; font-family: var(--display); font-weight: 400; text-align: center; }
.foot { text-align: center; color: var(--mute); font-size: 13px; margin-top: auto; }
.gamelist { display: flex; flex-wrap: wrap; gap: 6px; }
.gamelist span { font-size: 13px; background: var(--card); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; }

.qr-card { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qr { width: min(64vw, 240px); aspect-ratio: 1; background: #fff; border-radius: 14px; padding: 10px; }
.qr svg { width: 100%; height: 100%; display: block; }
.hint { color: var(--mute); font-size: 14px; }

.plist { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 8px; background: #0f0d18; border-radius: 12px; padding: 8px 10px; min-width: 0; }
.plist li.off { opacity: .45; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.loss { font-size: 12px; color: var(--pink); flex: none; }
.kick { font-size: 12px; color: var(--mute); padding: 2px 6px; }
.empty { opacity: .3; justify-content: center; font-size: 13px; }

.games { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gbtn { text-align: left; padding: 12px; border-radius: 14px; background: #0f0d18; border: 2px solid transparent; }
.gbtn b { display: block; font-size: 16px; }
.gbtn small { display: block; color: var(--mute); font-size: 12px; line-height: 1.35; margin-top: 2px; }
.gbtn.on { border-color: var(--yellow); background: #2a2410; }
.gbtn:disabled { opacity: 1; }
.gbtn:disabled:not(.on) { opacity: .4; }
.bets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.bets button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }
.bets button.on { background: var(--pink); border-color: var(--pink); color: #fff; }
.bet-text { font-family: var(--display); font-size: 26px; color: var(--pink); }
.wait p { color: var(--mute); text-align: center; }

/* game pads */
.pad { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 70px 20px calc(30px + env(safe-area-inset-bottom)); background: var(--bg); transition: background .08s; touch-action: none; }
.ghead { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; font-weight: 700; }
.ghead .bet { color: var(--pink); }
.big { font-family: var(--display); font-size: clamp(44px, 14vw, 88px); line-height: 1.05; }
.sub { color: var(--mute); margin-top: 10px; font-size: 17px; }
.pad.red { background: var(--red); }
.pad.red .sub, .pad.green .sub { color: rgba(255,255,255,.85); }
.pad.green { background: var(--green); color: #062b14; }
.pad.green .ghead .bet { color: #062b14; }
.clock { font-family: var(--display); font-size: clamp(72px, 26vw, 140px); font-variant-numeric: tabular-nums; }
.stop { margin-top: 24px; width: min(70vw, 260px); aspect-ratio: 1; border-radius: 50%; background: var(--pink); box-shadow: 0 8px 0 #a92a4a; font-family: var(--display); font-size: 48px; color: #fff; }
.stop:active { transform: translateY(6px); box-shadow: 0 2px 0 #a92a4a; }
.mash.live { background: #2a2410; }
.mash .count { font-family: var(--display); font-size: clamp(96px, 34vw, 180px); color: var(--yellow); line-height: 1; }
.mash .bar { width: 80%; height: 10px; background: var(--line); border-radius: 5px; margin-top: 20px; overflow: hidden; }
.mash .bar i { display: block; height: 100%; width: 100%; background: var(--yellow); transform-origin: left; }
.waitbox { margin-top: 24px; width: 100%; max-width: 420px; }
.progress { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.progress span { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: rgba(0,0,0,.25); }
.progress span.ok { background: var(--c); color: #111; font-weight: 700; }

.bomb-ico { font-size: 120px; line-height: 1; }
.pad.hot { background: #3a0d16; }
.pad.hot .bomb-ico { animation: shake .12s infinite; }
.bomb .bomb-ico { animation: shake .5s infinite; }
@keyframes shake { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) scale(1.06); } }
.targets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 420px; margin-top: 22px; }
.targets button { height: 64px; border-radius: 16px; background: var(--c); color: #111; font-weight: 800; font-size: 18px; box-shadow: 0 4px 0 rgba(0,0,0,.35); }

.wheel-wrap { position: relative; width: min(84vw, 360px); aspect-ratio: 1; margin-top: 10px; }
.pointer { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid var(--yellow); z-index: 2; filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); }
.wheel { width: 100%; height: 100%; border-radius: 50%; border: 6px solid #fff; position: relative; overflow: hidden; }
.wheel .lbl { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.wheel .lbl span { position: absolute; transform: translate(-50%, -50%); font-weight: 800; color: #111; font-size: 15px; white-space: nowrap; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }

/* result */
.result { text-align: center; }
.boom { font-size: 88px; line-height: 1; margin-top: 16px; }
.kicker { color: var(--mute); }
.loser { font-family: var(--display); font-weight: 400; font-size: clamp(36px, 11vw, 56px); line-height: 1.1; word-break: keep-all; }
.loser em { font-style: normal; color: var(--yellow); }
.bet-big { display: inline-block; align-self: center; font-family: var(--display); font-size: 26px; background: var(--pink); color: #fff; padding: 6px 18px; border-radius: 12px; transform: rotate(-2deg); }
.me-lost { animation: flash .5s 3; }
@keyframes flash { 50% { background: var(--pink); } }
.rank { list-style: none; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.rank li { display: flex; align-items: center; gap: 10px; background: #0f0d18; border-radius: 12px; padding: 10px 12px; }
.rank li.lose { background: #3a0d16; }
.rank .n { width: 22px; color: var(--mute); font-weight: 700; }
.rank .v { font-variant-numeric: tabular-nums; font-weight: 700; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }

.spinner { width: 44px; height: 44px; border: 4px solid var(--line); border-top-color: var(--yellow); border-radius: 50%; animation: spin .8s linear infinite; margin: 40vh auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; color: var(--mute); }
.err { text-align: center; margin-top: 30vh; display: flex; flex-direction: column; gap: 16px; }
.err h2 { font-family: var(--display); font-weight: 400; font-size: 32px; }

.net { position: fixed; top: 0; left: 0; right: 0; z-index: 50; background: var(--red); color: #fff; text-align: center; font-size: 14px; font-weight: 700; padding: calc(6px + env(safe-area-inset-top)) 12px 6px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: #fff; color: #111; font-weight: 700; padding: 10px 18px; border-radius: 999px; max-width: 90vw; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .pad.hot .bomb-ico, .bomb .bomb-ico, .me-lost { animation: none; }
}

/* characters */
.chars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cbtn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); font-size: 13px; font-weight: 700; }
.cbtn img { height: 52px; width: auto; max-width: 100%; object-fit: contain; }
.cbtn.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, var(--card)); }
.av { width: 34px; height: 30px; object-fit: contain; flex: none; }
.plist li small { color: var(--mute); font-weight: 400; }
.progress span { display: inline-flex; align-items: center; gap: 4px; }
.progress img { height: 18px; }
.runner { height: 90px; margin-bottom: 8px; }
.runner.hop { animation: hop .12s; }
@keyframes hop { 50% { transform: translateY(-14px); } }
.holder { display: flex; align-items: center; gap: 10px; margin: 12px 0 6px; font-size: 20px; font-weight: 800; }
.holder img { height: 64px; }
.targets button { display: flex; align-items: center; justify-content: center; gap: 6px; }
.targets img { height: 36px; }
.wheel .lbl span { display: flex; flex-direction: column; align-items: center; top: calc(min(84vw, 360px) * -0.32); font-size: 12px; transform: translate(-50%, -50%); }
.wheel .lbl img { height: 34px; }
.losers { display: flex; justify-content: center; gap: 6px; margin-top: 12px; }
.losers img { height: 110px; max-width: 45%; object-fit: contain; }
@media (prefers-reduced-motion: reduce) { .runner.hop { animation: none; } }
.pad { justify-content: safe center; overflow-y: auto; padding-top: calc(70px + env(safe-area-inset-top)); }
.bomb-ico { font-size: min(120px, 14vh); }
.holder img { height: min(64px, 8vh); }
.targets button { height: min(64px, 9vh); min-height: 44px; }
.targets button.off { opacity: .55; }

/* sound + bomb fuse */
.snd { position: fixed; left: 50%; transform: translateX(-50%); top: calc(8px + env(safe-area-inset-top)); z-index: 40; width: 40px; height: 40px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); font-size: 20px; }
.fuse { font-family: var(--display); font-size: clamp(48px, 16vw, 80px); color: var(--yellow); font-variant-numeric: tabular-nums; line-height: 1; margin-bottom: 6px; }
.pad.final .bomb-ico { animation: shakeHard .06s infinite; }
.pad.final .fuse { color: var(--red); }
.pad.final { box-shadow: inset 0 0 0 6px var(--red); }
@keyframes shakeHard { 0%,100% { transform: translate(-6px, 2px) rotate(-14deg) scale(1.15); } 50% { transform: translate(6px, -2px) rotate(14deg) scale(1.22); } }
.targets small { font-size: 12px; background: rgba(0,0,0,.2); border-radius: 999px; padding: 1px 7px; margin-left: 2px; }
/* 마지막 5초: 들고 있든 아니든 모두의 화면이 같이 난리 (넘기기 버튼은 안 흔들어서 누르기 쉽게) */
.pad.final { animation: redFlash .5s infinite; }
.pad.final .fuse, .pad.final .holder, .pad.final .big { animation: jitter .09s infinite; }
.pad.final .holder img { animation: shake .15s infinite; }
@keyframes redFlash { 0%,100% { background: #2a0a10; } 50% { background: #8a1020; } }
@keyframes jitter { 0%,100% { transform: translate(-3px, 1px); } 25% { transform: translate(3px, -2px); } 50% { transform: translate(-2px, -1px); } 75% { transform: translate(2px, 2px); } }
/* 동작 줄이기 켠 폰: 흔들림은 끄되 빨간 깜빡임은 남겨 마지막인 걸 알게 */
@media (prefers-reduced-motion: reduce) { .pad.final .bomb-ico, .pad.final .fuse, .pad.final .holder, .pad.final .big, .pad.final .holder img { animation: none; } }

/* 눈치게임 */
.circle { position: relative; width: min(86vw, 360px); aspect-ratio: 1; margin: 34px 0 10px; }
.seat { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; font-size: 12px; font-weight: 700; width: 84px; text-align: center; }
.seat img { height: 54px; }
.seat span { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble { position: absolute; bottom: 100%; background: #fff; color: #111; font-family: var(--display); font-size: 26px; min-width: 44px; padding: 2px 10px; border-radius: 16px; animation: pop .25s; }
.bubble::after { content: ''; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 7px solid transparent; border-top-color: #fff; }
.seat.clash .bubble { background: var(--red); color: #fff; }
.seat.clash .bubble::after { border-top-color: var(--red); }
.seat.lost img { animation: shake .3s infinite; }
.next { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-family: var(--display); font-size: 64px; color: var(--yellow); }
.stop.call { width: min(56vw, 200px); font-size: 36px; margin-top: 0; }
.stop.call:disabled { opacity: .45; }
@keyframes pop { from { transform: scale(.4); } }
.next.go { color: var(--red); font-size: 72px; animation: goPop .25s; }
@keyframes goPop { from { transform: translate(-50%, -50%) scale(.4); } }

/* 청기백기 */
.flags { padding-left: 0; padding-right: 0; justify-content: flex-start; }
.cmd { font-family: var(--display); font-size: clamp(30px, 10vw, 52px); min-height: 2.3em; display: flex; align-items: center; justify-content: center; padding: 0 16px; word-break: keep-all; line-height: 1.15; }
.fstat { color: var(--mute); font-weight: 700; margin-bottom: 8px; }
.halves { flex: 1; width: 100%; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.half { overflow: hidden; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 18px; font-size: 22px; touch-action: none; }
.half.blue { background: #1b3a8a; }
.half.white { background: #e9e6f2; color: #1a1726; }
.half .flag { position: absolute; left: 22%; bottom: 60px; width: 8px; height: 46%; background: #8a6a3d; border-radius: 4px; transition: transform .12s; transform: translateY(35%); }
.half .flag::after { content: ''; position: absolute; left: 8px; top: 0; width: min(90px, 26vw); height: 62px; border-radius: 4px; }
.half.blue .flag::after { background: #4d7cfe; box-shadow: 0 0 0 3px #fff; }
.half.white .flag::after { background: #fff; box-shadow: 0 0 0 3px #1a1726; }
.half.up .flag { transform: translateY(-8%); }
.flagger { position: absolute; left: 50%; bottom: calc(40px + env(safe-area-inset-bottom)); transform: translateX(-50%); height: 70px; pointer-events: none; }
.fbar { position: absolute; left: 0; right: 0; bottom: 0; width: auto; margin: 0; border-radius: 0; }
.fbar i { display: block; height: 100%; background: var(--yellow); transform-origin: left; }
.flags.good { animation: okflash .3s; }
.flags.bad { animation: badflash .3s; }
@keyframes okflash { 50% { box-shadow: inset 0 0 0 8px var(--green); } }
@keyframes badflash { 50% { box-shadow: inset 0 0 0 8px var(--red); } }

/* 허들 */
.hurdle { padding: 0; justify-content: flex-start; }
.hurdle canvas { position: absolute; left: 0; right: 0; top: calc(52px + env(safe-area-inset-top)); bottom: calc(112px + env(safe-area-inset-bottom)); width: 100%; height: calc(100% - 164px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.hurdle .cd { position: absolute; top: 30%; left: 50%; transform: translateX(-50%); font-family: var(--display); font-size: 96px; color: var(--yellow); pointer-events: none; }
.hmsg { position: absolute; left: 0; right: 0; bottom: calc(10px + env(safe-area-inset-bottom)); text-align: center; color: var(--mute); font-size: 14px; font-weight: 700; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .seat.lost img, .bubble, .flags.good, .flags.bad { animation: none; } }

/* 전력질주 */
.dash { position: absolute; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); width: 128px; height: 84px; border-radius: 20px; background: var(--pink); color: #fff; box-shadow: 0 5px 0 #a92a4a; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; touch-action: none; z-index: 3; }
.dash b { font-size: 16px; }
.dash i { width: 84%; height: 8px; background: rgba(0,0,0,.3); border-radius: 4px; overflow: hidden; }
.dash u { display: block; height: 100%; background: var(--yellow); transform-origin: left; }
.dash.on { transform: translateY(4px); box-shadow: 0 1px 0 #a92a4a; background: #ff2d5f; }
.dash.tired { background: #6b5a66; box-shadow: 0 5px 0 #3d3340; }
.hurdle .hmsg { right: 156px; text-align: left; left: 14px; bottom: calc(30px + env(safe-area-inset-bottom)); font-size: 13px; line-height: 1.4; }
html, body { touch-action: manipulation; }
