:root {
  --ink: #3a2a1a;
  --paper: #fffaf0;
  --cream: #fff3d6;
  --line: #3a2a1a;
  --muted: #8a6a4a;
  --yellow: #ffcf3f;
  --orange: #ff8a3d;
  --green: #4fc35a;
  --red: #e04848;
  --sky: #7cc8f8;
  --display: 'Jua', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --pixel: 'Press Start 2P', monospace;
  --s: 1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--ink);
  font-family: var(--display);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
#fxcv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 5; image-rendering: pixelated; image-rendering: crisp-edges; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }
/* 막판(누군가 풍선 2개 이하): 가장자리가 빨갛게 두근두근 */
#danger { position: absolute; inset: 0; pointer-events: none; z-index: 2; display: none; background: radial-gradient(ellipse at center, transparent 45%, rgba(230, 20, 20, 0.6) 100%); }
#app.rage #danger { display: block; animation: beat 0.65s infinite; }
@keyframes beat { 0%, 40%, 100% { opacity: 0.55; } 15% { opacity: 1; } 28% { opacity: 0.7; } 33% { opacity: 0.95; } }
.plate.danger { border-color: #e04848; background: #ffe3e3; animation: platebeat 0.65s infinite; }
@keyframes platebeat { 0%, 100% { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18), 0 0 0 0 rgba(255, 60, 60, 0); } 15% { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18), 0 0 0 6px rgba(255, 60, 60, 0.55); } }
button { font-family: var(--display); color: var(--ink); }
input { font-family: var(--display); }

/* ─────────── 화면 공통 ─────────── */
.screen {
  position: absolute; inset: 0; overflow-y: auto; display: flex; z-index: 10;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(124, 200, 248, 0.35);
  touch-action: pan-y;
}
#scr-settings, #scr-help, #scr-pause, #scr-online, #scr-pick { background: rgba(60, 120, 170, 0.45); }
#scr-result { background: transparent; pointer-events: none; }
#scr-result .inner { pointer-events: auto; }
.inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; max-width: 560px; }
.inner.wide { max-width: 820px; }
h2 { font-family: var(--display); font-weight: 400; margin: 0; font-size: 30px; color: #fff; text-align: center; text-shadow: 0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; }
.card { background: var(--paper); border: 3px solid var(--line); border-radius: 10px; padding: 10px 14px; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2); display: flex; flex-direction: column; gap: 8px; width: 100%; }

.btn {
  font-size: 21px; line-height: 1.15; color: var(--ink);
  background: #fff; border: 3px solid var(--line); border-radius: 10px;
  padding: 8px 20px; min-width: 200px; cursor: pointer; box-shadow: 0 4px 0 var(--line);
  transition: transform 0.08s;
}
.btn small { display: block; font-size: 12px; color: var(--muted); }
.btn.small { font-size: 17px; min-width: 110px; padding: 6px 14px; }
.btn.primary { background: var(--orange); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn.primary small { color: #fff3e0; }
.btn:hover, .btn:focus-visible { outline: none; background: var(--yellow); color: var(--ink); text-shadow: none; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn.off { opacity: 0.5; }

/* ─────────── 타이틀 ─────────── */
.logo { text-align: center; }
.logo-top { font-family: var(--pixel); font-size: 13px; color: #fff; letter-spacing: 5px; text-shadow: 2px 2px 0 var(--ink); }
.logo-main {
  font-family: var(--display); font-size: 54px; line-height: 1.1; color: var(--yellow); margin-top: 6px;
  text-shadow: 0 4px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 -3px 0 var(--ink), 4px 6px 0 rgba(0, 0, 0, 0.2);
  animation: bob 2.4s ease-in-out infinite;
}
.logo-main span { color: #fff; }
.logo-sub { font-size: 17px; color: #fff; margin-top: 6px; text-shadow: 0 2px 0 var(--ink); }
@keyframes bob { 50% { transform: translateY(-5px); } }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.menu .btn { min-width: 0; width: 100%; }
.my-card { display: flex; align-items: center; gap: 10px; background: var(--paper); border: 3px solid var(--line); border-radius: 10px; padding: 4px 14px 4px 6px; font-size: 16px; }
.my-card canvas { width: 40px; height: 48px; image-rendering: pixelated; }
.my-card b { font-weight: 400; font-size: 19px; }
.my-card span { color: var(--muted); font-size: 14px; }
.copyright { font-size: 12px; color: #fff; text-decoration: none; text-shadow: 0 1px 2px var(--ink); font-family: sans-serif; }
.copyright:hover { text-decoration: underline; }
#btn-sound, #btn-menu {
  width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--line); background: rgba(255, 250, 240, 0.9); font-size: 17px; cursor: pointer; padding: 0;
}
#btn-sound { position: absolute; right: max(8px, env(safe-area-inset-right)); top: max(6px, env(safe-area-inset-top)); z-index: 20; width: 34px; height: 34px; font-size: 14px; }
#btn-menu { position: absolute; left: max(8px, env(safe-area-inset-left)); top: max(6px, env(safe-area-inset-top)); width: 34px; height: 34px; font-size: 12px; pointer-events: auto; }

/* ─────────── 고르기·설정 ─────────── */
.set-line { display: flex; align-items: center; gap: 12px; font-size: 18px; }
.set-line > span { min-width: 64px; color: var(--muted); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; max-width: 420px; background: var(--paper); border: 3px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 18px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 16px; background: #fff; border: 3px solid #cfc6b6; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.chip.on { background: var(--yellow); border-color: var(--line); }
.chip.ro { cursor: default; }
.tips { margin: 0; padding: 12px 18px 12px 32px; background: var(--paper); border: 3px solid var(--line); border-radius: 10px; line-height: 1.6; font-size: 15px; font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; }
.tips b { color: #c0540c; }
kbd { font-family: var(--pixel); font-size: 10px; background: #fff; border: 2px solid var(--line); border-bottom-width: 3px; border-radius: 5px; padding: 1px 5px; }

/* ─────────── 결과 ─────────── */
.banner { margin-top: -4px; background: var(--yellow); border: 4px solid var(--line); border-radius: 10px; padding: 4px 26px; text-align: center; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2); animation: drop 0.5s cubic-bezier(.2, 1.5, .4, 1); }
.banner b { display: block; font-weight: 400; font-size: clamp(28px, 9vh, 46px); color: #5a3a00; }
.banner span { font-size: 16px; color: #7a5200; }
@keyframes drop { 0% { transform: translateY(-120px); } 100% { transform: translateY(0); } }
.res-gap { flex: 1; }
.res-mid { flex: 1; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 0; }
.res-stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.res-stats div { background: var(--paper); border: 3px solid var(--line); border-radius: 8px; padding: 1px 9px; font-size: 14px; }
.res-stats span { color: var(--muted); }
.res-stats b { font-weight: 400; }
.res-stats em { font-style: normal; margin-left: 5px; background: #e04848; color: #fff; border-radius: 4px; padding: 0 5px; font-size: 12px; animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
.res-bottom { gap: 6px; }
.badges.side { width: 30%; max-width: 250px; display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.badge { position: relative; background: var(--yellow); border: 4px solid var(--line); border-radius: 12px; padding: 4px 12px 5px; text-align: center; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25); opacity: 0; animation: badgein 0.45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.badge::before { content: '★'; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: clamp(18px, 6vh, 28px); color: #ff8a3d; text-shadow: 0 2px 0 var(--ink); }
.badge b { display: block; font-weight: 400; font-size: clamp(18px, 6vh, 26px); line-height: 1.1; color: #3a2a1a; }
.badge small { display: block; font-size: clamp(11px, 3.4vh, 14px); color: #7a5200; }
.badge small.tag { font-size: 11px; color: #c0540c; letter-spacing: 1px; }
@keyframes badgein { 0% { opacity: 0; transform: scale(0.3) rotate(-8deg); } 100% { opacity: 1; transform: none; } }
#scr-result .inner { height: 100%; max-width: 100%; justify-content: space-between; margin: 0 auto; gap: 6px; }

/* ─────────── 온라인 ─────────── */
.note { font-size: 14px; color: #fff; text-shadow: 0 1px 2px var(--ink); text-align: center; margin: 0; font-family: 'Apple SD Gothic Neo', sans-serif; }
.on-home { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#on-code { font-family: var(--pixel); font-size: 18px; width: 150px; text-align: center; padding: 8px; border: 3px solid var(--line); border-radius: 8px; text-transform: uppercase; }
.on-room { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.on-head { display: flex; gap: 14px; align-items: center; background: var(--paper); border: 3px solid var(--line); border-radius: 10px; padding: 6px 12px; width: 100%; }
.on-head .note { color: var(--muted); text-shadow: none; }
.room-code { font-family: var(--pixel); font-size: 24px; letter-spacing: 4px; }
.on-link-box { flex: 1; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; min-width: 0; }
.on-link { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: text; -webkit-user-select: text; font-family: sans-serif; }
.pslots { display: flex; gap: 10px; width: 100%; }
.pslot { flex: 1; background: var(--paper); border: 3px solid var(--line); border-radius: 10px; padding: 6px; display: flex; align-items: center; gap: 10px; font-size: 18px; }
.pslot canvas { width: 50px; height: 60px; image-rendering: pixelated; }
.pslot.empty { color: var(--muted); justify-content: center; border-style: dashed; min-height: 76px; }
.pslot small { display: block; color: var(--muted); font-size: 13px; }
.status { min-height: 1.2em; font-size: 15px; color: #fff; text-shadow: 0 1px 2px var(--ink); margin: 0; }

#toast { position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 30px); opacity: 0; z-index: 30; background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 10px; font-size: 16px; transition: 0.25s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#rotate { display: none; position: absolute; inset: 0; z-index: 50; background: var(--sky); color: #fff; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; text-shadow: 0 2px 0 var(--ink); }
#rotate div { font-size: 56px; }
@media (orientation: portrait) and (max-width: 700px) { #rotate { display: flex; } }
@media (max-height: 430px) {
  h2 { font-size: 24px; }
  .logo-main { font-size: 44px; }
  .btn { font-size: 19px; padding: 6px 16px; }
  .inner { gap: 7px; }
  #deco-cv { width: 150px; height: 180px; }
  .card { padding: 6px 12px; gap: 5px; }
  .set-line { font-size: 16px; }
  .sw { width: 26px; height: 26px; }
  .chip { font-size: 15px; padding: 3px 8px; }
}

/* ─────────── 경기 화면 ─────────── */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.plate {
  position: absolute; left: 0; top: 0; transform: translate(-50%, 0); white-space: nowrap; min-width: 118px;
  background: var(--paper); border: 3px solid var(--line); border-radius: 8px; padding: 0 7px 1px; font-size: 13px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18); display: grid; grid-template-columns: auto 1fr; column-gap: 6px; align-items: center;
}
.plate b { font-weight: 400; line-height: 1.25; max-width: 6em; overflow: hidden; }
.plate .hp { height: 9px; background: #5a4a3a; border-radius: 3px; overflow: hidden; min-width: 54px; }
.plate .hp i { display: block; height: 100%; width: 100%; background: #7bd85a; transition: width 0.15s; }
.plate.mid .hp i { background: #ffc93c; } .plate.low .hp i { background: #ff5a4a; }
.plate span { grid-column: 1 / 3; font-size: 11px; color: var(--muted); text-align: center; line-height: 1.1; }
.plate.red b { color: #c03030; } .plate.blue b { color: #2f6aaa; }
.plate.hit { animation: plhit 0.25s; }
@keyframes plhit { 30% { transform: translate(-50%, 0) scale(1.08); } }
.plate.shield { border-color: #7f77dd; box-shadow: 0 0 0 3px rgba(157, 140, 255, 0.6); }
#clock {
  position: absolute; left: 50%; top: max(4px, env(safe-area-inset-top)); transform: translateX(-50%); text-align: center;
  background: var(--paper); border: 3px solid var(--line); border-radius: 12px; padding: 0 12px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}
#clock b { font-family: var(--pixel); font-size: 15px; font-weight: 400; display: block; padding-top: 4px; }
#clock small { display: block; font-size: 12px; color: var(--muted); min-height: 1em; }
#app.rage #clock { border-color: #e04848; background: #ffe3e3; }
#app.rage #clock b { color: #c03030; animation: blink 0.6s steps(2) infinite; }
/* 성 꼭대기 용머리의 말풍선 */
.say {
  position: absolute; transform: translate(10px, -50%); max-width: 40vw; white-space: nowrap;
  background: #fffaf0; border: 3px solid var(--line); border-radius: 12px; padding: 2px 10px; font-size: clamp(12px, 3.6vh, 16px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2); animation: saypop 0.25s cubic-bezier(.2, 1.6, .4, 1);
}
.say.r { transform: translate(calc(-100% - 10px), -50%); }
.say::after { content: ''; position: absolute; left: -11px; top: 50%; margin-top: -6px; border: 6px solid transparent; border-right: 8px solid var(--line); border-left: 0; }
.say.r::after { left: auto; right: -11px; border-right: 0; border-left: 8px solid var(--line); }
.say b { color: #c0540c; font-weight: 400; }
@keyframes saypop { 0% { opacity: 0; } 100% { opacity: 1; } }

/* 슬롯 10칸 */
#bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: stretch; justify-content: center; gap: 6px;
  padding: 4px max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(44, 44, 42, 0.82); border-top: 3px solid var(--line);
}
.bar-side { display: flex; flex-direction: column; justify-content: space-around; font-size: 13px; color: #d3d1c7; width: 64px; }
.bar-side.right { text-align: right; width: 110px; font-size: 12px; }
#gold-tip { color: #ffd23f; }
.slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; width: min(560px, 66vw); }
.sl {
  --p: 0; --pc: #ffb02e; position: relative; border: 0; border-radius: 9px; padding: 3px; cursor: pointer; height: clamp(38px, 11.5vh, 52px);
  background: conic-gradient(var(--pc) calc(var(--p) * 1turn), #6b6a66 0);
  touch-action: manipulation;
}
.sl .in { display: flex; align-items: center; gap: 4px; height: 100%; border-radius: 6px; background: #444441; padding: 0 5px; color: #f1efe8; overflow: hidden; }
.sl canvas { width: clamp(24px, 7vh, 34px); height: auto; image-rendering: pixelated; flex: 0 0 auto; }
.sl b { font-weight: 400; font-size: clamp(12px, 3.7vh, 16px); line-height: 1.05; text-align: left; flex: 1; white-space: nowrap; overflow: hidden; }
.sl small { position: absolute; right: 6px; bottom: 3px; font-size: 11px; color: #b4b2a9; }
.sl:active .in { background: #5a5955; }
.sl.charging { --pc: #ffb02e; }
.sl.charging .in { background: #5a4a2a; }
.sl.locked { opacity: 0.45; }
.sl.ready { background: #ffd23f; }
.sl.ready.def .in { background: #4a4740; }
.sl.cd { --pc: #8fc4ff; }
.sl.cd .in { background: #3a3a38; color: #a8a69e; }
.sl.cd canvas { opacity: 0.5; }
.sl.gold { box-shadow: 0 0 0 2px #ffd23f; }
.sl.shake { animation: slshake 0.3s; }
@keyframes slshake { 25%, 75% { transform: translateX(-3px); } 50% { transform: translateX(3px); } }
.sl.flashy { animation: slflash 0.35s; }
@keyframes slflash { 0% { filter: brightness(1.8); } 100% { filter: none; } }

.ft {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font-size: 20px; color: #fff; pointer-events: none;
  text-shadow: 0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
  animation: rise 1.1s ease-out forwards;
}
.ft.big { font-size: 28px; } .ft.gold { color: #ffd23f; } .ft.hot { color: #ffb02e; font-size: 16px; } .ft.blue { color: #b9a8ff; }
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
@keyframes rise { 0% { opacity: 0; margin-top: 10px; transform: translate(-50%, -50%) scale(0.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } 30% { transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; margin-top: -30px; transform: translate(-50%, -50%) scale(1); } }
#callout {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 7; pointer-events: none;
  font-size: clamp(30px, 11vh, 60px); color: #fff; white-space: nowrap; text-align: center;
  text-shadow: 0 4px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 -3px 0 var(--ink);
}
#callout small { display: block; font-size: 0.4em; }
#callout.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(0.4); } 100% { transform: translate(-50%, -50%) scale(1); } }
.name-in { font-size: 19px; width: 160px; padding: 4px 10px; border: 3px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.card.narrow { width: auto; flex-direction: row; }
.my-card { padding: 6px 14px; }
