:root {
  --ink: #3a2a1a;
  --paper: #fffaf0;
  --cream: #fff3d6;
  --line: #3a2a1a;
  --muted: #8a6a4a;
  --yellow: #ffcf3f;
  --orange: #ff8a3d;
  --green: #4fc35a;
  --red: #e04848;
  --sky: #9fd3f0;
  --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(160, 210, 240, 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; }
}

.menu { grid-template-columns: 1fr 1fr 1fr; }

/* ─────────── 경기 화면 ─────────── */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
#btn-menu { pointer-events: auto; }
.sbox {
  position: absolute; top: max(4px, env(safe-area-inset-top)); display: grid; grid-template-columns: auto auto; column-gap: 8px; align-items: center;
  background: var(--paper); border: 3px solid var(--line); border-radius: 10px; padding: 1px 10px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18); min-width: 120px;
}
#sb0 { left: max(50px, calc(env(safe-area-inset-left) + 50px)); }
#sb1 { right: max(50px, calc(env(safe-area-inset-right) + 50px)); }
.sbox b { font-weight: 400; font-size: 15px; max-width: 6em; overflow: hidden; white-space: nowrap; }
.sbox strong { font-family: var(--pixel); font-weight: 400; font-size: 18px; grid-row: span 2; text-align: right; }
.sbox.red b, .sbox.red strong { color: #c03030; } .sbox.blue b, .sbox.blue strong { color: #2f6aaa; }
.sbox .dots { display: flex; gap: 3px; padding-bottom: 2px; }
.sbox .dots i { width: 9px; height: 9px; border-radius: 50%; background: #d3d1c7; border: 1px solid var(--line); }
.sbox.red .dots i.on { background: #e04848; } .sbox.blue .dots i.on { background: #3f86d1; }
.sbox.turn { background: #fff3b0; border-color: #c0540c; }
.sbox.up { animation: plhit 0.35s; }
@keyframes plhit { 40% { transform: scale(1.12); } }
#center {
  position: absolute; left: 50%; top: max(4px, env(safe-area-inset-top)); transform: translateX(-50%); text-align: center; white-space: nowrap;
  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);
}
#center b { font-weight: 400; font-size: 15px; display: block; }
#center small { display: block; font-size: 12px; color: var(--muted); min-height: 1em; }
#power {
  position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); z-index: 6; pointer-events: none;
  display: flex; align-items: center; gap: 6px; background: rgba(255, 250, 240, 0.92); border: 3px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: 15px;
}
#power .track { position: relative; width: min(220px, 30vw); height: 16px; background: #e8e4da; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; }
#power .zone { position: absolute; top: 0; bottom: 0; background: rgba(79, 195, 90, 0.55); }
#power .zone i { position: absolute; left: 50%; top: -1px; transform: translateX(-50%); font-style: normal; font-size: 10px; color: #1f5a25; }
#power .fill { position: absolute; left: 0; top: 4px; bottom: 4px; background: #ff8a3d; border-radius: 3px; }
#power em { font-style: normal; min-width: 5.5em; font-size: 14px; }
#power.good em { color: #2f8a3a; }
#hint {
  position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; pointer-events: none; white-space: nowrap;
  font-size: clamp(14px, 4.5vh, 19px); color: #fff; text-shadow: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
}
#power:not(.hidden) ~ #hint { left: auto; right: max(16px, env(safe-area-inset-right)); transform: none; }
#btn-sweep {
  position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); z-index: 7;
  font-size: 22px; padding: 10px 22px; border: 4px solid var(--line); border-radius: 14px; background: #ff8a3d; color: #fff; cursor: pointer;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); box-shadow: 0 5px 0 var(--line); touch-action: manipulation;
}
#btn-sweep.blue { background: #3f86d1; }
#btn-sweep.hit { animation: swp 0.15s; }
@keyframes swp { 50% { transform: translateY(3px) scale(0.96); box-shadow: 0 2px 0 var(--line); } }
.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.blue { color: #bfe0ff; }
#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: 40%; transform: translate(-50%, -50%); z-index: 7; pointer-events: none;
  font-size: clamp(28px, 10vh, 54px); 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.38em; }
#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; }
.my-card canvas, .pslot canvas { width: 28px; height: 32px; image-rendering: pixelated; }
table.ends { border-collapse: collapse; background: var(--paper); border: 3px solid var(--line); border-radius: 10px; font-size: 15px; }
table.ends th, table.ends td { padding: 2px 10px; text-align: center; border-bottom: 1px solid #e0d8c8; font-weight: 400; }
table.ends th { color: var(--muted); font-size: 13px; }
table.ends .nm { text-align: left; max-width: 7em; overflow: hidden; }
table.ends tr.red .nm, table.ends tr.red .sum { color: #c03030; } table.ends tr.blue .nm, table.ends tr.blue .sum { color: #2f6aaa; }
table.ends .sum { font-family: var(--pixel); font-size: 13px; }
#scr-result { background: rgba(160, 210, 240, 0.45); pointer-events: auto; }
#scr-result .inner { height: auto; justify-content: center; margin: auto; gap: 8px; }
/* 밝은 얼음 위에서도 흰 글씨가 보이게 첫 화면을 조금 어둡게 */
#scr-title, #scr-pick { background: rgba(40, 90, 140, 0.42); }

/* 중계석 해설 자막 (얼음판 바로 아래) */
#caption {
  position: absolute; left: 50%; top: 80%; transform: translateX(-50%); z-index: 6; pointer-events: none;
  display: flex; align-items: center; gap: 8px; max-width: min(660px, 80vw); white-space: nowrap;
  background: rgba(31, 53, 80, 0.92); color: #fff; border: 3px solid var(--line); border-radius: 10px; padding: 2px 12px 2px 4px;
  font-size: clamp(13px, 4vh, 17px); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2); animation: cappop 0.25s cubic-bezier(.2, 1.5, .4, 1);
}
#caption b { flex: none; font-weight: 400; font-size: 0.82em; padding: 1px 7px; border-radius: 6px; color: #fff; }
#caption.c0 b { background: #ff8a3d; } #caption.c1 b { background: #7f77dd; }
#caption span { overflow: hidden; text-overflow: ellipsis; }
@keyframes cappop { 0% { opacity: 0; transform: translate(-50%, 6px); } 100% { opacity: 1; transform: translate(-50%, 0); } }
