:root {
  --bg: #0b0b14;
  --panel: rgba(13, 18, 48, 0.9);
  --line: rgba(255, 255, 255, 0.16);
  --cyan: #2ee6ff;
  --pink: #ff4fd8;
  --yellow: #ffe14d;
  --green: #3dff8a;
  --ink: #0b0b14;
  --muted: #b9bdd3;
  --display: 'Black Han Sans', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --pixel: 'Press Start 2P', monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #000; color: #fff;
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ─────────── 화면 공통 ─────────── */
.screen {
  position: absolute; inset: 0; overflow-y: auto; display: flex; z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(8, 10, 28, 0.72);
  touch-action: pan-y;
}
#scr-creator, #scr-result, #scr-settings, #scr-help, #scr-pause, #scr-duo, #scr-champ, #scr-share, #scr-online { background: rgba(8, 10, 28, 0.86); }
#scr-title { background: radial-gradient(ellipse at center, rgba(8, 10, 28, 0.35), rgba(8, 10, 28, 0.85)); }
.inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 560px; }
.inner.wide { max-width: 860px; }
h2 { font-family: var(--display); font-weight: 400; margin: 0; font-size: 30px; color: var(--yellow); text-align: center; text-shadow: 0 3px 0 var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.btn {
  font-family: var(--display); font-size: 21px; color: #fff; line-height: 1.15;
  background: #1c2350; border: 3px solid var(--cyan); border-radius: 12px;
  padding: 8px 20px; min-width: 200px; cursor: pointer; box-shadow: 0 4px 0 #05061a;
  transition: transform 0.08s, background 0.1s;
}
.btn small { display: block; font-family: inherit; font-size: 12px; color: var(--muted); letter-spacing: 0.3px; }
.btn.small { font-size: 16px; min-width: 110px; padding: 7px 14px; }
.btn.primary { background: var(--pink); color: var(--ink); border-color: #ffd0f4; box-shadow: 0 4px 0 #a3168a; }
.btn.primary small { color: #3a0634; }
.btn:hover, .btn:focus-visible { outline: none; background: var(--yellow); color: var(--ink); border-color: #fff; transform: translateY(-2px); }
.btn:hover small, .btn:focus-visible small { color: #3a2a00; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #05061a; }
.btn.off { opacity: 0.55; }

/* ─────────── 타이틀 ─────────── */
.logo { text-align: center; }
.logo-top { font-family: var(--pixel); font-size: 15px; color: var(--cyan); letter-spacing: 6px; text-shadow: 3px 3px 0 var(--ink); }
.logo-main {
  font-family: var(--pixel); font-size: 48px; line-height: 1.15; color: var(--yellow); margin-top: 8px;
  text-shadow: 4px 4px 0 #b02a9a, 8px 8px 0 var(--ink);
  animation: bob 2.4s ease-in-out infinite;
}
.logo-main span { font-family: var(--display); font-size: 44px; color: #fff; }
.logo-sub { font-family: var(--display); font-size: 15px; color: #fff; margin-top: 8px; text-shadow: 0 2px 0 var(--ink); }
@keyframes bob { 50% { transform: translateY(-4px); } }
.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(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 6px 14px; font-family: var(--display); font-size: 16px; }
.my-card img { width: 30px; height: 20px; border: 1px solid #fff8; }
.my-card .pb { font-family: var(--pixel); font-size: 11px; color: var(--yellow); }
.copyright { font-size: 12px; color: rgba(255, 255, 255, 0.8); text-decoration: none; text-shadow: 0 1px 2px #000; }
.copyright:hover { color: var(--yellow); text-decoration: underline; }
#btn-sound, #btn-menu {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--cyan); background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 18px; cursor: pointer;
}
#btn-sound { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20; }
#hud-btns { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); z-index: 5; }

/* ─────────── 선수 만들기 ─────────── */
.creator { margin: auto; display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.4fr); gap: 18px; width: 100%; max-width: 900px; align-items: center; }
.preview { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.card-frame { width: 100%; max-width: 260px; background: linear-gradient(#1c2350, #0d1230); border: 3px solid var(--yellow); border-radius: 16px; padding: 10px; text-align: center; box-shadow: 0 0 0 3px var(--ink), 0 8px 0 #05061a; }
#pv { width: 100%; aspect-ratio: 4 / 3; image-rendering: pixelated; background: #c0533c; border-radius: 8px; display: block; }
.pv-name { font-family: var(--display); font-size: 24px; margin-top: 8px; color: #fff; }
.pv-meta { font-size: 13px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 6px; }
.pv-meta img { width: 24px; height: 16px; border: 1px solid #fff8; }
.options { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.options h2 { text-align: left; font-size: 24px; }
.opt { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; }
.opt > span { font-family: var(--display); font-size: 15px; color: var(--muted); }
.opt .ctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { font-family: var(--display); font-size: 14px; color: #fff; background: #1c2350; border: 2px solid var(--line); border-radius: 9px; padding: 5px 10px; cursor: pointer; }
.chip.on { border-color: var(--pink); background: #3a1450; color: #fff; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff4; cursor: pointer; padding: 0; }
.sw.on { border: 3px solid var(--yellow); box-shadow: 0 0 0 2px var(--ink); }
.arrow { width: 34px; height: 32px; border-radius: 8px; border: 2px solid var(--cyan); background: #1c2350; color: #fff; font-size: 14px; cursor: pointer; }
.pick { display: flex; align-items: center; gap: 6px; min-width: 120px; justify-content: center; font-family: var(--display); font-size: 15px; }
.pick img { width: 30px; height: 20px; border: 1px solid #fff8; }
.opt input { font-family: var(--display); font-size: 17px; width: 160px; padding: 6px 10px; border-radius: 9px; border: 2px solid var(--cyan); background: #0d1230; color: #fff; }
.trait-desc { font-size: 12px; color: var(--muted); width: 100%; }

/* ─────────── 설정·도움말 ─────────── */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; max-width: 420px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; font-family: var(--display); font-size: 17px; }
.seg { display: flex; gap: 6px; }
.tips { margin: 0; padding: 14px 18px 14px 34px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; line-height: 1.7; font-size: 15px; max-width: 560px; }
.tips b { color: var(--yellow); font-weight: 600; }
kbd { font-family: var(--pixel); font-size: 10px; background: #1c2350; border: 1px solid var(--cyan); border-bottom-width: 3px; border-radius: 5px; padding: 2px 6px; }

/* ─────────── 경기 중 큰 글자 ─────────── */
#callout {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none;
  font-family: var(--display); font-size: clamp(34px, 9vh, 72px); color: #fff; white-space: nowrap; text-align: center;
  text-shadow: 0 4px 0 var(--ink), 0 0 18px rgba(0, 0, 0, 0.6);
}
#callout.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
#callout.gun { color: var(--yellow); font-size: clamp(48px, 14vh, 110px); }
#callout.bad { color: #ff5a5a; }
#callout.gold { color: var(--yellow); }
#callout small { display: block; font-size: 0.38em; color: #fff; margin-top: 4px; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* ─────────── 결승 순서 ─────────── */
#winner {
  position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%); z-index: 7; pointer-events: none;
  display: flex; align-items: center; gap: 12px; white-space: nowrap;
  background: rgba(11, 11, 20, 0.82); border: 3px solid var(--yellow); border-radius: 16px; padding: 8px 20px;
  font-family: var(--display); font-size: clamp(26px, 7vh, 48px); color: var(--yellow); text-shadow: 0 3px 0 var(--ink);
  animation: win 0.45s cubic-bezier(.2, 1.6, .4, 1);
}
#winner img { height: 0.8em; border: 2px solid #fff; }
#winner small { font-family: var(--pixel); font-size: 0.42em; color: #fff; }
#winner.me { border-color: var(--pink); }
#winner.me.p2 { border-color: var(--cyan); }
@keyframes win { 0% { transform: translate(-50%, -50%) scale(0.3) rotate(-6deg); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
#podium {
  position: absolute; right: max(64px, calc(env(safe-area-inset-right) + 64px)); top: max(10px, env(safe-area-inset-top)); z-index: 5;
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; pointer-events: none;
}
#podium li {
  display: flex; align-items: center; gap: 7px; background: rgba(11, 11, 20, 0.82); border: 2px solid var(--line); border-radius: 10px;
  padding: 3px 10px; font-family: var(--display); font-size: 15px; animation: slide 0.3s ease-out;
}
#podium li.me { border-color: var(--pink); background: rgba(90, 16, 80, 0.9); }
#podium li img { width: 22px; height: 15px; border: 1px solid #fff8; }
#podium li b { font-family: var(--pixel); font-size: 10px; color: var(--yellow); font-weight: 400; margin-left: auto; padding-left: 6px; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─────────── 해설 자막 ─────────── */
#caster {
  position: absolute; left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; pointer-events: none;
  max-width: min(70vw, 620px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: rgba(11, 11, 20, 0.85); border-left: 4px solid var(--yellow); border-radius: 0 10px 10px 0;
  padding: 5px 14px; font-family: var(--display); font-size: clamp(14px, 4vh, 19px); color: #fff;
}
#caster::before { content: '🎙️ '; }
#caster.in { animation: casterIn 0.25s ease-out; }
@keyframes casterIn { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ─────────── 2인 대결·챔피언십·공유 ─────────── */
.duo-cards { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.duo-card { width: 220px; background: linear-gradient(#1c2350, #0d1230); border: 3px solid var(--pink); border-radius: 16px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.duo-card.p2 { border-color: var(--cyan); }
.duo-tag { font-family: var(--pixel); font-size: 14px; color: var(--pink); }
.duo-card.p2 .duo-tag { color: var(--cyan); }
.duo-card canvas.mini { width: 100%; image-rendering: pixelated; border-radius: 8px; }
.duo-name { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 20px; }
.duo-name img { width: 30px; height: 20px; border: 1px solid #fff8; }
.duo-hint, .duo-note { font-size: 12.5px; color: var(--muted); margin: 0; text-align: center; }
.champ-path { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.champ-step { min-width: 150px; background: var(--panel); border: 3px solid var(--line); border-radius: 14px; padding: 10px 14px; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.champ-step b { font-family: var(--display); font-weight: 400; font-size: 22px; }
.champ-step span { font-size: 13px; color: var(--muted); }
.champ-step.done { border-color: var(--green); }
.champ-step.done b::after { content: ' ✓'; color: var(--green); }
.champ-step.now { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 225, 77, 0.25); }
.champ-step.out { border-color: #ff5a5a; }
.champ-step.next { opacity: 0.6; }
.champ-arrow { color: var(--muted); font-size: 14px; }
.champ-msg { margin: 0; font-family: var(--display); font-size: 18px; text-align: center; }
.champ-medals { margin: 0; font-size: 14px; color: var(--muted); }
#share-img { width: min(70vh, 360px); border-radius: 12px; border: 3px solid var(--pink); }
a.btn { text-decoration: none; display: inline-block; text-align: center; }
.res-table tr.me2 td { background: rgba(46, 230, 255, 0.18); }

/* ─────────── 온라인 ─────────── */
.on-home, .on-room { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
#on-code { font-family: var(--pixel); font-size: 18px; width: 150px; text-align: center; text-transform: uppercase; padding: 8px; border-radius: 10px; border: 3px solid var(--cyan); background: #0d1230; color: #fff; }
.on-head { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; }
.room-code { font-family: var(--pixel); font-size: 34px; color: var(--yellow); letter-spacing: 6px; text-shadow: 3px 3px 0 var(--ink); }
.on-link-box { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.on-link { font-size: 12px; color: var(--muted); user-select: all; -webkit-user-select: all; max-width: 320px; word-break: break-all; }
.on-meta { display: flex; gap: 10px; align-items: center; font-family: var(--display); }
.on-players { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; max-width: 640px; }
.on-player { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 6px 10px; font-family: var(--display); font-size: 16px; min-width: 0; }
.on-player span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.on-player img { width: 26px; height: 17px; border: 1px solid #fff8; flex: none; }
.on-player em { font-style: normal; font-size: 11px; background: var(--yellow); color: var(--ink); border-radius: 6px; padding: 1px 6px; margin-left: auto; }
.on-player.me { border-color: var(--pink); }
.on-player.empty { color: var(--muted); border-style: dashed; justify-content: center; font-size: 13px; }

/* ─────────── 결과 ─────────── */
.res-head { font-family: var(--display); font-size: 36px; color: var(--yellow); text-shadow: 0 3px 0 var(--ink); text-align: center; }
.res-head small { display: block; font-size: 15px; color: #fff; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.badge { font-family: var(--display); font-size: 15px; padding: 4px 12px; border-radius: 999px; background: var(--yellow); color: var(--ink); }
.badge.wr { background: var(--pink); animation: bob 1s ease-in-out infinite; }
.res-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 12px; width: 100%; }
.res-table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; font-size: 14px; }
.res-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.res-table tr.me td { background: rgba(255, 79, 216, 0.22); }
.res-table .pl { font-family: var(--display); font-size: 17px; width: 34px; text-align: center; }
.res-table img { width: 24px; height: 16px; vertical-align: -3px; margin-right: 6px; border: 1px solid #fff6; }
.res-table .tm { font-family: var(--pixel); font-size: 11px; text-align: right; color: var(--yellow); }
.res-table .rt { font-size: 12px; color: var(--muted); text-align: right; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start; }
.stat { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.stat b { display: block; font-family: var(--pixel); font-size: 15px; color: #fff; margin-top: 4px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.big { grid-column: 1 / -1; border-color: var(--pink); }
.stat.big b { font-size: 26px; color: var(--yellow); }
.stat.big.p2 { border-color: var(--cyan); }
.stat.sm b { font-size: 11px; line-height: 1.6; }

#toast {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); z-index: 30; pointer-events: none;
  background: rgba(11, 11, 20, 0.9); border: 2px solid var(--cyan); border-radius: 12px; padding: 8px 16px; font-family: var(--display); font-size: 16px;
  opacity: 0; transition: opacity 0.25s;
}
#toast.show { opacity: 1; }

/* ─────────── 세로 화면 안내 ─────────── */
#rotate { display: none; position: absolute; inset: 0; z-index: 50; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-family: var(--display); }
#rotate div { font-size: 56px; animation: tilt 1.6s ease-in-out infinite; }
#rotate p { margin: 0; font-size: 20px; }
@keyframes tilt { 50% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 820px) { #rotate { display: flex; } }

/* ─────────── 낮은 가로 화면 (폰) ─────────── */
@media (max-height: 460px) {
  .room-code { font-size: 26px; }
  .on-player { padding: 4px 8px; font-size: 14px; }
  .duo-card { width: 190px; padding: 6px; gap: 4px; }
  .champ-step { min-width: 120px; padding: 6px 10px; }
  .champ-step b { font-size: 18px; }
  .inner { gap: 8px; }
  .logo-top { font-size: 11px; }
  .logo-main { font-size: 34px; margin-top: 4px; }
  .logo-main span { font-size: 32px; }
  .logo-sub { font-size: 13px; margin-top: 4px; }
  .btn { font-size: 18px; padding: 6px 14px; }
  .btn small { font-size: 11px; }
  .btn.small { font-size: 14px; padding: 5px 12px; }
  h2 { font-size: 24px; }
  .options h2 { font-size: 20px; }
  .opt { grid-template-columns: 54px minmax(0, 1fr); }
  .chip { font-size: 13px; padding: 4px 8px; }
  .sw { width: 26px; height: 26px; }
  .pv-name { font-size: 20px; }
  .res-head { font-size: 28px; }
  .stat b { font-size: 13px; }
  .stat.big b { font-size: 20px; }
  .res-table td { padding: 3px 6px; }
}
