:root {
  --lime: #c8f24e;
  --gold: #ffd23a;
  --p1: #ff3b3b;
  --p2: #3ba0ff;
  --panel: rgba(6, 22, 9, 0.88);
  --ink: #0b2a10;
  --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; 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;
  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: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.78));
  touch-action: pan-y;
}
.screen:not(#scr-title) { background: rgba(0, 12, 3, 0.72); }
.inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 560px; }
.inner.wide { max-width: 1040px; }
h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; text-align: center; text-shadow: 0 3px 0 var(--ink); }
h2 { font-size: 34px; color: var(--gold); }
h3 { font-size: 20px; color: #fff; }
.sub { margin: 0; color: #dfe; text-align: center; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.hint { font-size: 12px; color: #bcd; text-align: center; margin: 0; }

.btn {
  font-family: var(--display); font-size: 22px; color: #fff; line-height: 1.15;
  background: linear-gradient(#2f8a2a, #1b5a19); border: 3px solid var(--lime); border-radius: 12px;
  padding: 9px 22px; min-width: 250px; cursor: pointer; box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s, background 0.1s;
}
.btn small { display: block; font-family: inherit; font-size: 12px; font-weight: 400; opacity: 0.8; letter-spacing: 0.5px; }
.btn.small { font-size: 17px; min-width: 120px; padding: 7px 16px; }
.btn.primary { background: linear-gradient(#ff5a3c, #c22a14); border-color: var(--gold); }
.btn:hover, .btn:focus-visible, .btn:focus { outline: none; background: linear-gradient(#ffe066, #e8a400); color: #2a1500; border-color: #fff; transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ─────────── 타이틀 ─────────── */
.logo { text-align: center; margin-bottom: 6px; }
.logo-top { font-family: var(--pixel); font-size: 18px; color: var(--lime); letter-spacing: 8px; text-shadow: 3px 3px 0 var(--ink); }
.logo-main {
  font-family: var(--display); font-size: 66px; line-height: 1.05; color: var(--gold);
  text-shadow: 0 5px 0 #a33a00, 0 9px 0 var(--ink), 0 0 30px rgba(255, 200, 40, 0.45);
  animation: bob 2.4s ease-in-out infinite;
}
.logo-sub { font-family: var(--pixel); font-size: 11px; color: #fff; letter-spacing: 3px; margin-top: 8px; text-shadow: 2px 2px 0 var(--ink); }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-1deg); } }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu .btn { min-width: 0; width: 100%; }
.copyright { margin-top: 4px; font-size: 12px; color: rgba(255, 255, 255, 0.75); text-decoration: none; text-shadow: 0 1px 2px #000; letter-spacing: 0.3px; }
.copyright:hover { color: var(--gold); text-decoration: underline; }
#btn-sound {
  position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 5;
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--lime); background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 20px; cursor: pointer;
}

/* ─────────── 팀 선택 ─────────── */
.grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; width: 100%; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px 5px; background: rgba(0, 0, 0, 0.55); border: 2px solid rgba(255, 255, 255, 0.18); border-radius: 8px;
  color: #fff; cursor: pointer; font-family: var(--display); font-size: 13px; min-width: 0;
}
.card .flag { border: 1px solid rgba(255, 255, 255, 0.6); width: 44px; height: auto; }
.card span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.card em { font-style: normal; font-size: 9px; color: var(--gold); height: 10px; line-height: 10px; letter-spacing: -1px; }
.card .tag { position: absolute; top: -8px; font-style: normal; font-family: var(--pixel); font-size: 8px; padding: 2px 3px; border-radius: 3px; display: none; }
.card .t1 { left: -4px; background: var(--p1); }
.card .t2 { right: -4px; background: var(--p2); }
.card.c1 { border-color: var(--p1); box-shadow: 0 0 0 2px var(--p1) inset; }
.card.c2 { border-color: var(--p2); box-shadow: 0 0 0 2px var(--p2) inset; }
.card.c1.c2 { border-color: #fff; box-shadow: 0 0 0 2px var(--p1) inset, 0 0 0 4px var(--p2) inset; }
.card.c1 .t1, .card.c2 .t2 { display: block; }
.card.l1, .card.l2 { background: rgba(255, 210, 58, 0.25); }
.card:hover { background: rgba(255, 255, 255, 0.12); }
.sel-bottom { display: flex; gap: 12px; align-items: stretch; width: 100%; justify-content: center; }
.vs { font-family: var(--pixel); font-size: 22px; color: var(--gold); align-self: center; text-shadow: 3px 3px 0 var(--ink); }
.side { flex: 1; max-width: 400px; background: var(--panel); border: 3px solid #555; border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.side.p1 { border-color: var(--p1); }
.side.p2 { border-color: var(--p2); }
.side.ready { box-shadow: 0 0 18px rgba(255, 210, 58, 0.45); }
.sp-head { display: flex; align-items: center; gap: 10px; }
.sp-head .tag { font-family: var(--pixel); font-size: 10px; padding: 4px 5px; border-radius: 4px; background: var(--p1); }
.p2 .sp-head .tag { background: var(--p2); }
.sp-head b { font-family: var(--display); font-weight: 400; font-size: 22px; display: block; }
.sp-head em { font-style: normal; font-size: 12px; color: var(--gold); }
.sp-head .flag { border: 2px solid #fff; }
.sp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; margin-top: 8px; font-size: 12px; }
.sp-stats > div { display: flex; align-items: center; gap: 6px; }
.sp-stats span { width: 38px; color: #cde; }
.bar { flex: 1; height: 8px; background: rgba(255, 255, 255, 0.12); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #38e05a, var(--lime)); }
.sp-state { margin-top: 6px; font-family: var(--display); font-size: 14px; color: var(--gold); text-align: right; }
.sp-wait { text-align: center; padding: 22px 0; color: #cde; font-family: var(--display); }

/* ─────────── 설정 ─────────── */
#set-rows { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); padding: 8px 12px; border-radius: 10px; font-family: var(--display); font-size: 17px; }
.seg { display: flex; gap: 5px; }
.seg-btn { min-width: 0; font-size: 15px; padding: 5px 12px; border-width: 2px; box-shadow: none; background: rgba(255, 255, 255, 0.08); }
.seg-btn.on { background: linear-gradient(#ffe066, #e8a400); color: #2a1500; border-color: #fff; }

/* ─────────── 조작법 ─────────── */
.keys { border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; font-size: 15px; }
.keys th, .keys td { padding: 7px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); text-align: left; }
.keys th { font-family: var(--pixel); font-size: 12px; }
.keys .c1 { color: var(--p1); } .keys .c2 { color: var(--p2); }
kbd { display: inline-block; min-width: 24px; padding: 2px 6px; margin: 1px; border-radius: 5px; background: #eee; color: #111; border-bottom: 3px solid #999; font-family: inherit; font-size: 13px; text-align: center; }
.tips { margin: 0; padding: 12px 16px 12px 30px; background: var(--panel); border-radius: 12px; font-size: 14px; line-height: 1.6; max-width: 760px; }
.tips b { color: var(--gold); }

/* ─────────── 온라인 ─────────── */
#on-home, #on-wait { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.join-row { display: flex; gap: 8px; }
#on-code {
  width: 150px; font-family: var(--pixel); font-size: 20px; text-align: center; text-transform: uppercase;
  border: 3px solid var(--lime); border-radius: 10px; background: rgba(0, 0, 0, 0.6); color: #fff; padding: 8px; user-select: text;
}
.room-code { font-family: var(--pixel); font-size: 44px; color: var(--gold); letter-spacing: 10px; text-shadow: 4px 4px 0 var(--ink); background: var(--panel); padding: 14px 20px 12px 30px; border-radius: 14px; border: 3px solid var(--gold); }
.link { font-size: 12px; color: #bcd; word-break: break-all; text-align: center; user-select: text; }
.status { min-height: 20px; margin: 0; color: var(--lime); font-family: var(--display); text-align: center; }

/* ─────────── 토너먼트 ─────────── */
#tour-body .next { display: flex; align-items: center; gap: 12px; font-family: var(--display); font-size: 24px; background: var(--panel); padding: 10px 18px; border-radius: 14px; border: 3px solid var(--gold); }
#tour-body .next span { font-family: var(--pixel); font-size: 16px; color: var(--gold); }
#tour-body .next .flag { border: 2px solid #fff; }
.tour-wrap { display: flex; gap: 14px; width: 100%; flex-wrap: wrap; justify-content: center; }
.groups { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 1 1 520px; }
.gtab { background: var(--panel); border-radius: 10px; padding: 6px 8px; border: 2px solid transparent; }
.gtab.mine { border-color: var(--gold); }
.gtab h4, .bracket h4 { margin: 0 0 4px; font-family: var(--display); font-weight: 400; color: var(--lime); }
.gtab table { width: 100%; border-collapse: collapse; font-size: 12px; }
.gtab th { color: #9ab; font-weight: 400; text-align: center; }
.gtab td { text-align: center; padding: 2px 3px; white-space: nowrap; }
.gtab td:first-child { text-align: left; }
.gtab tr.me td { color: var(--gold); }
.gtab tr.adv td:first-child { box-shadow: inset 3px 0 0 #38e05a; }
.gtab .flag { vertical-align: middle; }
.bracket { display: flex; gap: 8px; flex: 1 1 380px; background: var(--panel); border-radius: 10px; padding: 8px; }
.bracket > div { flex: 1; display: flex; flex-direction: column; gap: 6px; justify-content: space-around; }
.bm { background: rgba(255, 255, 255, 0.06); border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.bm .win { color: #fff; font-weight: 700; } .bm .lose { opacity: 0.45; } .bm .me { color: var(--gold); }
.bsc { font-family: var(--pixel); font-size: 9px; color: var(--lime); padding: 2px 0; }
.champ { display: flex; align-items: center; gap: 16px; }
.champ h2 { font-size: 40px; }

/* ─────────── 결과 ─────────── */
.res-head { font-size: 48px; }
.res-head.win { color: var(--gold); animation: bob 1.2s ease-in-out infinite; }
.res-score { display: flex; align-items: center; gap: 12px; font-family: var(--display); font-size: 22px; background: var(--panel); padding: 10px 16px; border-radius: 14px; }
.res-score span { font-family: var(--pixel); font-size: 30px; color: var(--gold); padding: 0 8px; }
.res-score .flag { border: 2px solid #fff; }
.res-pk { font-family: var(--display); color: var(--lime); font-size: 18px; }
.res-goals { display: flex; gap: 40px; font-size: 14px; min-height: 10px; }
.res-goals small { color: #9ab; }
.res-goals .r { text-align: right; }
.res-stats { width: 100%; display: flex; flex-direction: column; gap: 6px; background: var(--panel); padding: 10px 14px; border-radius: 12px; }
.st { display: grid; grid-template-columns: 44px 1fr 74px 1fr 44px; align-items: center; gap: 8px; font-size: 13px; }
.st span { text-align: center; color: #cde; font-family: var(--display); }
.st b { font-family: var(--pixel); font-size: 11px; text-align: center; }
.sbar { height: 8px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; overflow: hidden; display: flex; justify-content: flex-end; }
.sbar i { background: var(--p1); }
.sbar.r { justify-content: flex-start; }
.sbar.r i { background: var(--p2); }

/* ─────────── 경기 중 버튼 ─────────── */
#btn-menu {
  position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); z-index: 4;
  font-family: var(--pixel); font-size: 14px; color: var(--lime); background: none; border: none; cursor: pointer; padding: 6px;
  text-shadow: -2px 0 var(--ink), 2px 0 var(--ink), 0 -2px var(--ink), 0 2px var(--ink);
}
.touchdev #btn-menu { top: max(84px, env(safe-area-inset-top)); bottom: auto; background: rgba(0, 0, 0, 0.45); border-radius: 8px; }

/* ─────────── 터치 컨트롤 ─────────── */
#touch { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.tset { position: absolute; top: 28%; bottom: 0; pointer-events: none; }
.tset.full { left: 0; right: 0; }
.tset.half-l { left: 0; width: 50%; }
.tset.half-r { right: 0; width: 50%; border-left: 2px dashed rgba(255, 255, 255, 0.12); }
.stick-zone { position: absolute; left: 0; top: 0; bottom: 0; width: 55%; pointer-events: auto; touch-action: none; }
.stick-base { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.35); background: rgba(0, 0, 0, 0.18); pointer-events: none; }
.stick-base.active { border-color: rgba(255, 255, 255, 0.75); }
.stick-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); transform: translate(-50%, -50%); }
.tbtns { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); width: 172px; height: 172px; pointer-events: none; }
.tbtn {
  position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--display); color: #fff; border: 3px solid rgba(255, 255, 255, 0.6); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}
.b-shoot { width: 88px; height: 88px; right: 0; bottom: 0; background: rgba(255, 60, 60, 0.42); font-size: 24px; }
/* 슛 버튼(모서리)을 반지름 92px 부채꼴로 감싸는 배치: 왼쪽 태클, 왼쪽 위 패스, 위 달리기 */
.b-tackle { width: 62px; height: 62px; right: 105px; bottom: 13px; background: rgba(255, 210, 58, 0.38); font-size: 16px; }
.b-pass { width: 62px; height: 62px; right: 78px; bottom: 78px; background: rgba(60, 160, 255, 0.42); font-size: 17px; }
.b-sprint { width: 62px; height: 62px; right: 13px; bottom: 105px; background: rgba(255, 130, 30, 0.42); font-size: 14px; }
.tbtn.on { transform: scale(0.9); background: rgba(255, 255, 255, 0.5); }
.dual .tbtns { transform: scale(0.78); transform-origin: bottom right; }
.dual .stick-base { transform: scale(0.85); }
.tlabel { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font-family: var(--pixel); font-size: 11px; padding: 3px 6px; border-radius: 4px; opacity: 0.8; }
.tlabel.p1 { background: var(--p1); } .tlabel.p2 { background: var(--p2); }

/* ─────────── 오버레이 ─────────── */
#rotate { position: absolute; inset: 0; z-index: 20; background: #0b1d0e; display: none; flex-direction: column; align-items: center; justify-content: center; font-family: var(--display); font-size: 22px; }
#rotate.on { display: flex; }
#rotate div { font-size: 64px; animation: bob 1.5s infinite; }
#toast {
  position: absolute; left: 50%; bottom: 70px; transform: translate(-50%, 30px); z-index: 30; opacity: 0; pointer-events: none;
  background: rgba(0, 0, 0, 0.85); border: 2px solid var(--lime); border-radius: 12px; padding: 10px 18px; font-family: var(--display); font-size: 17px;
  transition: opacity 0.25s, transform 0.25s; max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 15; }
#confetti i { position: absolute; top: -20px; width: 9px; height: 14px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ─────────── 작은 화면 ─────────── */
@media (max-width: 820px) {
  .grid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-height: 520px) {
  .inner { gap: 7px; }
  .logo-main { font-size: 44px; }
  .logo-top { font-size: 13px; }
  .logo-sub { display: none; }
  .btn { font-size: 18px; padding: 6px 16px; }
  .btn small { font-size: 10px; }
  .btn.small { font-size: 15px; padding: 5px 12px; }
  h2 { font-size: 26px; }
  .grid { grid-template-columns: repeat(10, 1fr); gap: 4px; }
  .card { padding: 4px 1px 3px; font-size: 11px; }
  .card .flag { width: 34px; }
  .sp-stats { margin-top: 4px; font-size: 11px; }
  .sp-head b { font-size: 18px; }
  .side { padding: 6px 10px; }
  .hint { display: none; }
  .res-head { font-size: 34px; }
  .champ canvas { width: 70px; height: 88px; }
}
@media (max-height: 520px) and (max-width: 620px) {
  .grid { grid-template-columns: repeat(7, 1fr); }
}
@media (max-width: 560px) and (min-height: 521px) {
  .menu { grid-template-columns: 1fr; }
  .logo-main { font-size: 48px; }
  .sel-bottom { flex-direction: column; }
  .vs { display: none; }
  .side { max-width: none; }
  .res-score { font-size: 16px; gap: 6px; }
  .res-score .flag { width: 36px; height: 24px; }
  .set-row { flex-direction: column; align-items: stretch; }
  .groups { grid-template-columns: 1fr; }
}
