/* 버튼 느낌을 바꿀 때는 아래 변수와 .mode-btn 블록만 고치면 됩니다. */
:root {
  --bg: #07060d;
  --bg-glow: #1d1038;
  --text: #eef2ff;
  --muted: #8f8cab;
  --panel: #0f0d1a;
  --line: #2e2a4a;
  --neon-red: #ff2e63;
  --neon-blue: #00e5ff;
  --neon-yellow: #ffe14d;
  --neon-dark: #0b0a12;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

/* 게임 화면에서는 글자를 선택하거나 길게 눌러 복사·메뉴가 뜨는 일이 없게 함.
   연타하다가 버튼 글자가 선택돼 브라우저의 복사 기능이 뜨는 것을 막음. 입력칸과 방 코드만 예외 */
html {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* 빠르게 두 번 눌러도 확대하지 않음 */
}
input, textarea { -webkit-user-select: text; user-select: text; }
.room-code { -webkit-user-select: all; user-select: all; } /* 방 코드는 눌러서 복사할 수 있게 */

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  overflow-x: hidden;
}

/* 배경: 반실사 복싱 경기장(관중석과 천장 조명). tools/arena.mjs 로 그린 뒤 JPG 로 바꾼 assets/arena.jpg.
   스크롤해도 움직이지 않게 화면에 고정 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg) url(assets/arena.jpg?v=2) center / cover no-repeat;
}

.screen {
  display: none;
  min-height: 100%;
  padding: 76px 16px 32px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}
.screen.active { display: flex; }

/* ---------- 메인 메뉴 ---------- */
.title {
  margin: 0;
  font-size: clamp(56px, 16vw, 140px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 6px #fff,
    0 0 18px var(--neon-red),
    0 0 48px var(--neon-red),
    4px 4px 0 var(--neon-blue);
  animation: title-flicker 5s linear infinite;
}

@keyframes title-flicker {
  0%, 91%, 94%, 97%, 100% { opacity: 1; }
  92%, 96% { opacity: 0.55; }
}

.tagline { margin: 0 0 16px; color: var(--muted); font-size: 18px; }

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 28px;
  width: 100%;
  max-width: 1300px;
}

.mode-btn {
  --c: var(--neon-red);
  --cut: 22px;
  position: relative;
  isolation: isolate;
  flex: 1 1 280px;
  max-width: 360px;
  padding: 36px 24px;
  border: 0;
  background: none;
  color: var(--c);
  font: inherit;
  cursor: pointer;
  filter: drop-shadow(0 0 5px var(--c)) drop-shadow(0 0 16px var(--c));
  animation: neon-pulse 2s ease-in-out infinite;
  transition: transform 0.12s, filter 0.15s, color 0.15s;
}
.mode-btn.blue { --c: var(--neon-blue); }
.mode-btn.yellow { --c: var(--neon-yellow); }
.mode-btn.purple { --c: #b266ff; }
/* 아래에 안내 문구가 붙는 버튼 자리. 문구는 자리를 차지하지 않게 띄워서 다른 버튼과 높이가 같게 유지 */
.mode-slot { position: relative; flex: 1 1 280px; max-width: 360px; display: flex; }
.mode-slot .mode-btn { flex: 1; max-width: none; }
.mode-lock { position: absolute; top: 100%; left: 0; right: 0; margin: 8px 0 0; font-size: 14px; font-weight: 700; color: var(--muted); text-align: center; }
.mode-btn:disabled { filter: grayscale(0.7) brightness(0.5); animation: none; pointer-events: none; } /* 잠긴 버튼 */

/* 각진 모서리: ::before 가 네온 테두리, ::after 가 어두운 안쪽 면 */
.mode-btn::before, .mode-btn::after {
  content: "";
  position: absolute;
  z-index: -1;
  clip-path: polygon(
    var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut)
  );
}
.mode-btn::before { inset: 0; background: var(--c); }
.mode-btn::after { inset: 3px; background: var(--neon-dark); transition: background 0.15s; }

.mode-btn > span { display: block; }
.mode-name {
  font-size: 34px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.06em;
  text-shadow: 0 0 10px currentColor;
}
.mode-desc { margin-top: 10px; font-size: 15px; color: var(--text); opacity: 0.85; }

@keyframes neon-pulse {
  0%, 100% { filter: drop-shadow(0 0 4px var(--c)) drop-shadow(0 0 12px var(--c)); }
  50% { filter: drop-shadow(0 0 8px var(--c)) drop-shadow(0 0 28px var(--c)); }
}

/* 올리면 네온으로 꽉 차고, 누르면 쑥 들어감 */
.mode-btn:hover {
  animation: none;
  color: var(--neon-dark);
  transform: scale(1.06);
  filter: drop-shadow(0 0 10px var(--c)) drop-shadow(0 0 36px var(--c));
}
.mode-btn:hover::after { background: var(--c); }
.mode-btn:hover .mode-name { text-shadow: none; }
.mode-btn:hover .mode-desc { color: var(--neon-dark); opacity: 1; }
.mode-btn:active {
  transform: scale(0.95);
  filter: drop-shadow(0 0 4px var(--c)) brightness(1.25);
}
.mode-btn:focus-visible, .sub-btn:focus-visible, input:focus-visible {
  outline: 3px solid var(--neon-yellow);
  outline-offset: 4px;
}

/* ---------- 하위 화면 ---------- */
.heading {
  margin: 0;
  font-size: 40px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 20px var(--neon-blue), 0 0 44px var(--neon-blue);
}
.status { margin: 0; font-size: 22px; font-weight: 700; }
.note { margin: 0; min-height: 1.4em; color: var(--muted); font-size: 14px; }

.dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

.spinner {
  width: 64px; height: 64px;
  border: 6px solid var(--line);
  border-top-color: var(--neon-red);
  border-radius: 50%;
  filter: drop-shadow(0 0 8px var(--neon-red));
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sub-btn {
  padding: 12px 28px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, color 0.15s, background 0.15s;
}
.sub-btn:hover {
  border-color: var(--neon-blue);
  color: var(--neon-blue);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.55);
}
.sub-btn.primary {
  border-color: var(--neon-blue);
  color: var(--neon-blue);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.45), inset 0 0 10px rgba(0, 229, 255, 0.2);
}
.sub-btn:disabled { opacity: 0.5; cursor: default; }
.sub-btn.primary:hover { background: var(--neon-blue); color: var(--neon-dark); }

.room-panel {
  width: 100%;
  max-width: 380px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 0;
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.12);
}
.room-code { margin: 0; font-size: 32px; font-weight: 900; letter-spacing: 0.25em; color: var(--neon-yellow); text-shadow: 0 0 12px var(--neon-yellow); }
.divider { color: var(--muted); font-size: 13px; }

.join-form { display: flex; gap: 8px; }
.join-form input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

/* ---------- 레벨 / 경험치 (왼쪽 위 고정) ---------- */
.player-level {
  position: fixed;
  top: 12px;
  left: 78px; /* 톱니바퀴 버튼 바로 오른쪽 */
  height: 58px; /* 톱니바퀴 버튼과 같은 높이 */
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border: 2px solid var(--neon-yellow);
  box-shadow: 0 0 12px rgba(255, 225, 77, 0.35);
}
.lv { font-size: 22px; font-weight: 900; font-style: italic; color: var(--neon-yellow); text-shadow: 0 0 10px var(--neon-yellow); }
.xp { width: 120px; display: flex; flex-direction: column; gap: 3px; }
.xp .bar i { width: 0; box-shadow: 0 0 8px var(--neon-yellow); transition: width 0.4s; }
.xp-text { font-size: 11px; color: var(--muted); text-align: left; }
.nick { font-size: 13px; font-weight: 900; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nick:empty { display: none; }

/* ---------- 설정 (오른쪽 위 톱니바퀴) ---------- */
.gear-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.gear-btn svg { transition: transform 0.4s; }
.gear-btn:hover { color: var(--neon-blue); border-color: var(--neon-blue); box-shadow: 0 0 12px rgba(0, 229, 255, 0.55); }
.gear-btn:hover svg { transform: rotate(60deg); }
.gear-btn:focus-visible { outline: 3px solid var(--neon-yellow); outline-offset: 4px; }

.settings {
  width: min(460px, calc(100vw - 32px)); /* 화면 가운데에 뜨는 모달 */
  max-height: calc(100vh - 32px);
  padding: 22px;
  border: 2px solid var(--neon-blue);
  background: var(--panel);
  color: var(--text);
  text-align: center;
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.35);
  overflow-y: auto;
}
.settings { scrollbar-width: thin; scrollbar-color: var(--line) transparent; } /* 스크롤 막대를 어두운 색으로 */
.settings::backdrop { background: rgba(7, 6, 13, 0.75); }
.settings .heading { margin-bottom: 14px; font-size: 32px; }
.set-group { margin-bottom: 16px; padding-top: 12px; border-top: 2px solid var(--line); text-align: left; }
.set-group h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.1em; color: var(--neon-yellow); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; font-size: 15px; font-weight: 700; }
.set-row input[type="range"] { flex: 0 1 200px; min-width: 0; accent-color: var(--neon-blue); cursor: pointer; }
.set-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--neon-blue); cursor: pointer; }
.set-buttons { display: flex; gap: 8px; }
.text-input, .join-form .text-input {
  min-width: 0;
  width: 150px;
  padding: 7px 10px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
}
.join-form .text-input { flex: 1; width: auto; padding: 12px; font-size: 16px; }
.settings .join-form { margin: 14px 0 8px; }
.set-group[hidden] { display: none; }
.sub-btn.small { padding: 7px 14px; font-size: 14px; }
.sub-btn.danger:hover { border-color: var(--neon-red); color: var(--neon-red); box-shadow: 0 0 12px rgba(255, 46, 99, 0.55); }
.sound-status { margin: 8px 0 0; padding: 8px 10px; border: 1px solid var(--line); font-size: 12px; line-height: 1.6; color: var(--muted); white-space: pre-line; }
.set-group .note { text-align: left; }

/* ---------- 입장 화면 (자동 재생이 막혔을 때만) ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: var(--bg);
  cursor: pointer;
}
.gate[hidden] { display: none; }
.gate.pending > * { visibility: hidden; } /* 자동 재생 여부를 확인하는 동안은 빈 가림막 */
.gate-text {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--neon-yellow);
  text-shadow: 0 0 12px var(--neon-yellow);
  animation: gate-blink 1.2s ease-in-out infinite;
}
@keyframes gate-blink { 50% { opacity: 0.35; } }

/* ---------- 캐릭터 선택 (기울어진 포스터 카드) ---------- */
/* 제목·이름용 글꼴. 용량을 줄이려고 이 화면에 쓰는 글자만 담은 파일이라,
   캐릭터 이름·별명을 바꾸면 없는 글자는 기본 글꼴로 보임 (assets/fonts 의 파일을 다시 받아야 함) */
@font-face {
  font-family: "Black Han Sans";
  font-weight: 900;
  font-display: swap;
  src: url(assets/fonts/black-han-sans-subset.woff2?v=2) format("woff2");
}
/* --u: 이 화면의 크기 단위. 넓은 화면에서 1px 이고, 화면이 좁거나 낮으면 같은 비율로 줄어듦 */
/* 왼쪽에 대진표처럼 쌓인 선수 목록(스크롤), 오른쪽에 고른 선수의 포스터 */
#screen-select {
  --u: min(1px, 100vw / 1200, (100vh - 108px) / 640);
  --display: "Black Han Sans", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  flex-direction: row;
  gap: calc(40 * var(--u));
  text-align: left;
}
.select-left { width: calc(628 * var(--u)); height: calc(640 * var(--u)); display: flex; flex-direction: column; gap: calc(16 * var(--u)); }
.select-head { display: flex; align-items: flex-end; justify-content: space-between; }
.select-eyebrow { font-size: max(10px, calc(14 * var(--u))); font-weight: 900; letter-spacing: 0.35em; color: var(--neon-blue); }
.select-title {
  margin: calc(6 * var(--u)) 0 0;
  font-family: var(--display);
  font-size: max(26px, calc(54 * var(--u)));
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 18px rgba(0, 229, 255, 0.75);
}
.select-hint { font-size: max(11px, calc(15 * var(--u))); font-weight: 700; color: #c9c6e6; }

.char-grid {
  position: relative; /* 고른 선수 위치 계산의 기준 */
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: calc(14 * var(--u));
  padding: calc(6 * var(--u)) calc(36 * var(--u)) calc(6 * var(--u)) calc(4 * var(--u));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: #4a4478 transparent;
}
/* 선수 한 명 = 대진표 티켓 한 장: 왼쪽 번호표 + 오른쪽 이름·유형·그림 */
.char-card {
  --c: var(--neon-blue);
  position: relative;
  flex: none;
  display: flex;
  align-items: stretch;
  width: calc(560 * var(--u));
  height: calc(104 * var(--u));
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: pan-y;
  transition: transform 0.18s;
}
.char-card.selected { transform: translateX(calc(28 * var(--u))); }
.char-card:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.char-stub {
  flex: none;
  width: calc(86 * var(--u));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(2 * var(--u));
  background: #1b1733;
  border: 2px solid #37325c;
  border-right: 2px dashed #4a4478;
  transition: background 0.18s, border-color 0.18s;
}
.char-no { font-family: var(--display); font-size: max(15px, calc(38 * var(--u))); font-weight: 900; line-height: 1; color: #9a96bd; }
.char-stub-label { font-size: max(7px, calc(10 * var(--u))); font-weight: 900; letter-spacing: 0.2em; color: #9a96bd; }
.char-body {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(90deg, #131025, #0b0a16 70%);
  border: 2px solid #37325c;
  border-left: 0;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.char-card:hover .char-body, .char-card:hover .char-stub { border-color: var(--c); }
.char-card.selected .char-stub { background: var(--c); border-color: var(--c); }
.char-card.selected .char-no, .char-card.selected .char-stub-label { color: var(--neon-dark); }
.char-card.selected .char-body {
  border-color: var(--c);
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 26%, #0b0a16), #0b0a16 75%);
  box-shadow: 0 0 calc(26 * var(--u)) color-mix(in srgb, var(--c) 45%, transparent);
}
.char-card canvas { position: absolute; right: calc(-6 * var(--u)); top: calc(-30 * var(--u)); height: calc(300 * var(--u)); width: auto; } /* 머리와 어깨만 보이게 크게 */
.char-name { position: absolute; left: calc(20 * var(--u)); top: calc(14 * var(--u)); font-family: var(--display); font-size: max(15px, calc(34 * var(--u))); font-weight: 900; line-height: 1; color: var(--c); }
.char-type { position: absolute; left: calc(20 * var(--u)); top: calc(52 * var(--u)); font-size: max(10px, calc(14 * var(--u))); font-weight: 700; white-space: nowrap; color: #c9c6e6; }
.char-mini { position: absolute; left: calc(20 * var(--u)); bottom: calc(8 * var(--u)); display: flex; gap: calc(14 * var(--u)); font-size: max(9px, calc(13 * var(--u))); font-weight: 900; }

/* 오른쪽 포스터 */
.char-info {
  --c: var(--neon-blue);
  position: relative;
  flex: none;
  width: calc(500 * var(--u));
  height: calc(640 * var(--u));
  overflow: hidden;
  background: linear-gradient(180deg, rgba(19, 16, 37, 0.7), rgba(11, 10, 22, 0.95) 62%);
  border: 2px solid var(--c);
  box-shadow: 0 0 calc(40 * var(--u)) color-mix(in srgb, var(--c) 35%, transparent);
}
.poster-glow {
  position: absolute;
  left: 50%;
  top: calc(30 * var(--u));
  width: calc(400 * var(--u));
  height: calc(400 * var(--u));
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--c) 45%, transparent), transparent 68%);
}
#char-poster {
  position: absolute;
  left: 50%;
  top: calc(14 * var(--u));
  height: calc(316 * var(--u));
  width: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--c) 60%, transparent));
}
.poster-tag {
  position: absolute;
  left: calc(20 * var(--u));
  top: calc(18 * var(--u));
  padding: calc(4 * var(--u)) calc(10 * var(--u));
  background: var(--c);
  color: var(--neon-dark);
  font-size: max(8px, calc(12 * var(--u)));
  font-weight: 900;
  letter-spacing: 0.2em;
}
.poster-body { position: absolute; left: calc(30 * var(--u)); right: calc(30 * var(--u)); bottom: calc(24 * var(--u)); display: flex; flex-direction: column; gap: calc(10 * var(--u)); }
.poster-name { font-family: var(--display); font-size: max(22px, calc(52 * var(--u))); font-weight: 900; line-height: 1; color: var(--c); text-shadow: 0 0 18px color-mix(in srgb, var(--c) 70%, transparent); }
.char-nick { font-size: max(12px, calc(18 * var(--u))); font-weight: 900; line-height: 1.2; }
.char-desc { min-height: 2.9em; font-size: max(11px, calc(15 * var(--u))); line-height: 1.45; color: #e3e1f5; }
.char-stats { display: flex; flex-direction: column; gap: calc(9 * var(--u)); }
.stat { display: flex; align-items: center; gap: calc(12 * var(--u)); }
.stat span { flex: none; width: max(30px, calc(40 * var(--u))); font-size: max(11px, calc(15 * var(--u))); font-weight: 900; color: #c9c6e6; }
.pips { flex: 1 1 0; display: flex; gap: max(2px, calc(4 * var(--u))); }
.pip { flex: 1 1 0; height: max(5px, calc(10 * var(--u))); background: #2a2647; transform: skewX(-20deg); }
.pip.on { background: var(--c); box-shadow: 0 0 8px var(--c); }
.char-actions { display: flex; gap: calc(14 * var(--u)); margin-top: calc(6 * var(--u)); padding: 0 calc(4 * var(--u)); }
.char-actions .primary { flex: 1 1 0; }
.skew-btn {
  height: max(40px, calc(56 * var(--u)));
  padding: 0 max(14px, calc(30 * var(--u)));
  border: 2px solid #4a4478;
  border-radius: 0;
  background: #0f0d1a;
  color: var(--text);
  font: inherit;
  font-size: max(13px, calc(19 * var(--u)));
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
  transform: skewX(-7deg);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.skew-btn:hover { border-color: var(--text); }
.skew-btn.primary { border-color: var(--c); background: var(--c); color: var(--neon-dark); }
.skew-btn.primary:hover { box-shadow: 0 0 18px var(--c); }
.skew-btn:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }

/* ---------- 경기 화면 ---------- */
/* 화면이 낮아도 스크롤 없이 한눈에 들어오도록 링 너비를 높이에 맞춤 */
#screen-game { --ring-w: min(900px, max(320px, calc((100vh - 430px) * 16 / 9))); gap: 12px; padding: 76px 16px 16px; }

.practice-bar {
  width: 100%;
  max-width: var(--ring-w);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel);
  border: 2px solid var(--neon-yellow);
  box-shadow: 0 0 12px rgba(255, 225, 77, 0.25);
}
.practice-bar[hidden] { display: none; }
.practice-title { align-self: center; font-size: 18px; font-weight: 900; font-style: italic; color: var(--neon-yellow); text-shadow: 0 0 10px var(--neon-yellow); }
.practice-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); text-align: left; }
/* 선택 상자: 기본 <select> 는 숨기고(main.js 의 neonSelect), 버튼과 목록을 직접 그림 */
.nsel-native { display: none; }
.nsel { position: relative; display: block; }
.nsel-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 132px;
  padding: 8px 10px 8px 12px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.nsel-btn::after { /* 아래 화살표 */
  content: "";
  width: 7px;
  height: 7px;
  margin-top: -4px;
  border-right: 2px solid var(--neon-blue);
  border-bottom: 2px solid var(--neon-blue);
  transform: rotate(45deg);
  transition: transform 0.15s;
}
.nsel-btn[aria-expanded="true"]::after { margin-top: 4px; transform: rotate(-135deg); }
.nsel-btn:hover, .nsel-btn:focus-visible, .nsel-btn[aria-expanded="true"] { border-color: var(--neon-blue); outline: none; }
.nsel-btn[aria-expanded="true"] { box-shadow: 0 0 12px rgba(0, 229, 255, 0.45); }
.nsel-btn:disabled { opacity: 0.4; cursor: default; border-color: var(--line); }
.nsel-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  max-height: min(320px, 100vh - 80px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: rgba(11, 10, 22, 0.97);
  border: 2px solid var(--neon-blue);
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.4), 0 12px 30px rgba(0, 0, 0, 0.7);
}
.nsel-list[hidden] { display: none; }
.nsel-opt {
  padding: 9px 14px 9px 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0;
  background: none;
  color: #c9c6e6;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.nsel-opt:hover, .nsel-opt:focus-visible { background: rgba(0, 229, 255, 0.14); color: #fff; outline: none; }
.nsel-opt[aria-selected="true"] { border-left-color: var(--neon-yellow); background: rgba(255, 225, 77, 0.1); color: var(--neon-yellow); }

kbd {
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid currentColor;
  font: inherit;
  font-size: 13px;
  opacity: 0.8;
}

.hud {
  width: 100%;
  max-width: var(--ring-w);
  display: flex;
  align-items: center;
  gap: 16px;
}
.hud-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; text-align: left; }
.hud-side.right { text-align: right; }
.hud-name { font-size: 16px; font-weight: 900; letter-spacing: 0.08em; color: var(--c); text-shadow: 0 0 8px currentColor; }
.hud-timer {
  min-width: 64px;
  font-size: 40px;
  font-weight: 900;
  font-style: italic;
  color: var(--neon-yellow);
  text-shadow: 0 0 12px var(--neon-yellow);
}

.bar { display: flex; height: 16px; background: var(--panel); border: 2px solid var(--line); }
.bar.thin { height: 8px; }
/* 필살기 게이지: 다 차면 밝게 빛남 */
.bar.sp { height: 6px; }
.bar.sp i { width: 0; background: #c77dff; }
.bar.sp.full i { background: #fff; box-shadow: 0 0 10px #c77dff, 0 0 4px #fff; }
.hud-side.right .bar { justify-content: flex-end; }
.hud-side.right .bar.hp { flex-direction: row-reverse; justify-content: flex-start; } /* 체력은 오른쪽 끝부터, 차오를 부분은 그 왼쪽 */
.bar i { display: block; width: 100%; background: var(--neon-yellow); }
.bar.hp i { flex: none; background: var(--c); box-shadow: 0 0 10px var(--c); }
/* 맞아서 깎였지만 다시 차오를 부분 */
.bar.hp b { flex: none; display: block; width: 0; background: color-mix(in srgb, var(--c) 38%, transparent); }

.ring-wrap { position: relative; width: 100%; max-width: var(--ring-w); }
#ring {
  display: block;
  width: 100%;
  height: auto;
  background: rgba(7, 6, 13, 0.75);
  border: 2px solid var(--line);
  box-shadow: 0 0 24px rgba(255, 46, 99, 0.18);
}

.result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(7, 6, 13, 0.8);
}
.result[hidden] { display: none; }
.result-text {
  margin: 0;
  font-size: clamp(36px, 9vw, 72px);
  font-weight: 900;
  font-style: italic;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 22px var(--neon-red), 0 0 50px var(--neon-red);
}
.result-xp { margin: 0; font-size: 20px; font-weight: 900; color: var(--neon-yellow); text-shadow: 0 0 10px var(--neon-yellow); }
.result-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

.pad { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 24px; }
.pad-group { display: flex; align-items: center; gap: 10px; }
/* 이동 조이스틱: 누른 채 끌면 가운데 손잡이가 따라옴 */
.stick {
  position: relative;
  flex: none;
  width: 112px;
  height: 112px;
  border: 2px solid var(--neon-blue);
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 38%, color-mix(in srgb, var(--neon-blue) 14%, transparent) 39%, transparent 72%),
    rgba(11, 10, 18, 0.72);
  box-shadow: 0 0 12px color-mix(in srgb, var(--neon-blue) 50%, transparent), inset 0 0 18px color-mix(in srgb, var(--neon-blue) 22%, transparent);
  cursor: grab;
  touch-action: none;
}
.stick-knob {
  position: absolute;
  inset: 0;
  width: 46px;
  height: 46px;
  margin: auto;
  border-radius: 50%;
  background: var(--neon-blue);
  box-shadow: 0 0 14px var(--neon-blue);
  opacity: 0.8;
  pointer-events: none;
}
.stick.on { cursor: grabbing; }
.stick.on .stick-knob { opacity: 1; box-shadow: 0 0 22px var(--neon-blue), 0 0 6px #fff; }
.pad-btn {
  --c: var(--neon-blue);
  min-width: 64px;
  padding: 14px 16px;
  border: 2px solid var(--c);
  background: var(--neon-dark);
  color: var(--c);
  font: inherit;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 50%, transparent);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad-btn.red { --c: var(--neon-red); }
.pad-btn.yellow { --c: var(--neon-yellow); }
.pad-btn:active { background: var(--c); color: var(--neon-dark); }
.pad-btn.locked { opacity: 0.3; box-shadow: none; } /* 가드가 깨져서 잠깐 못 올리는 동안 */
/* 필살기 버튼: 게이지가 다 차기 전에는 흐리고, 다 차면 밝게 깜박임 */
.pad-btn.special {
  --c: #c77dff;
  --sp: 0%; /* 게이지가 찬 만큼 버튼이 아래부터 채워짐 */
  background: linear-gradient(to top, color-mix(in srgb, var(--c) 45%, var(--neon-dark)) var(--sp), var(--neon-dark) var(--sp));
  color: #e9d5ff;
}
.pad-btn.special.ready { background: var(--c); color: var(--neon-dark); animation: sp-ready 0.7s ease-in-out infinite alternate; }
@keyframes sp-ready {
  from { box-shadow: 0 0 8px color-mix(in srgb, var(--c) 50%, transparent); }
  to { box-shadow: 0 0 22px var(--c), 0 0 6px #fff; }
}

/* ---------- 모바일 ---------- */
/* 휴대폰을 세로로 들었을 때: 가로로 돌리라는 안내로 화면을 덮음 (태블릿처럼 넓은 화면은 세로로도 그대로 사용) */
.rotate { display: none; }
@media (pointer: coarse) and (orientation: portrait) and (max-width: 600px) {
  .rotate {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px;
    background: var(--bg);
    text-align: center;
  }
  .rotate-icon {
    width: 56px;
    height: 96px;
    border: 4px solid var(--neon-blue);
    box-shadow: 0 0 16px var(--neon-blue);
    animation: rotate-hint 2.4s ease-in-out infinite;
  }
  .rotate-text { margin: 0; font-size: 22px; font-weight: 900; color: var(--neon-yellow); text-shadow: 0 0 10px var(--neon-yellow); }
}
@keyframes rotate-hint { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

/* 가로로 든 휴대폰처럼 높이가 낮은 화면: 모든 화면을 한눈에 들어오게 줄이고, 경기 화면은 링을 꽉 채움 */
@media (orientation: landscape) and (max-height: 520px) {
  html, body { overscroll-behavior: none; }
  button { touch-action: manipulation; }

  .gear-btn { top: 6px; left: max(6px, env(safe-area-inset-left)); width: 46px; height: 46px; }
  .gear-btn svg { width: 22px; height: 22px; }
  .player-level { top: 6px; left: calc(max(6px, env(safe-area-inset-left)) + 54px); height: 46px; padding: 0 10px; }
  .lv { font-size: 18px; }
  .xp { width: 96px; gap: 1px; }
  .nick { font-size: 11px; }
  .xp-text { font-size: 10px; }

  .screen {
    padding: 50px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
    gap: 10px;
  }
  .heading { font-size: 26px; }

  /* 메인 메뉴: 버튼 세 개를 한 줄에 */
  .title { font-size: clamp(40px, 20vh, 84px); }
  .tagline { display: none; }
  .mode-buttons { flex-wrap: nowrap; gap: 10px; }
  .mode-btn, .mode-slot { --cut: 14px; flex: 1 1 0; min-width: 0; }
  .mode-btn { padding: 16px 8px; }
  .mode-lock { margin-top: 5px; font-size: 11px; }
  .mode-name { font-size: 19px; }
  .mode-desc { margin-top: 5px; font-size: 11px; }

  /* 캐릭터 선택: 화면이 낮으므로 제목을 위쪽 줄로 올리고, 영어 머리글·안내·설명·작은 능력치를 뺌 */
  #screen-select { --u: min(1px, 100vw / 1200, (100vh - 66px) / 640); gap: calc(40 * var(--u)); }
  .select-eyebrow, .select-hint, .char-desc, .char-mini, .char-stub-label { display: none; }
  .select-head { position: fixed; top: 6px; right: max(12px, env(safe-area-inset-right)); width: auto; height: 46px; align-items: center; } /* 제목은 레벨 창 오른쪽, 같은 줄에 */
  .select-title { margin: 0; }
  .char-type { top: calc(60 * var(--u)); }
  #char-poster { height: calc(290 * var(--u)); }
  .skew-btn { height: 36px; }

  .spinner { width: 40px; height: 40px; border-width: 4px; }
  .status { font-size: 17px; }
  .room-panel { max-width: 560px; padding: 12px; gap: 8px; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; }
  .room-code { font-size: 24px; }
  .room-panel .note { flex-basis: 100%; }
  .sub-btn { padding: 9px 18px; font-size: 14px; }

  /* 경기 화면: 위에 체력 막대, 가운데 링이 남은 높이를 꽉 채우고, 조작 버튼은 화면 양쪽 아래에 겹쳐 놓음 */
  body[data-screen="game"] { overflow: hidden; touch-action: none; } /* 경기 중에는 스크롤·확대 같은 손동작을 모두 끔 */
  body[data-screen="game"] .player-level { display: none; }
  #screen-game {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 4px;
    justify-content: flex-start;
  }
  .hud { max-width: min(100% - 110px, 620px); gap: 10px; }
  .hud-name { font-size: 12px; }
  .hud-timer { min-width: 44px; font-size: 26px; }
  .bar { height: 10px; }
  .bar.thin { height: 5px; }
  .hud-side { gap: 2px; }
  .ring-wrap { flex: 1 1 0; min-height: 0; width: auto; max-width: 100%; aspect-ratio: 16 / 9; }
  #ring { width: 100%; height: 100%; }
  .result { gap: 10px; }
  .result-text { font-size: clamp(28px, 14vh, 56px); }
  .result-xp { font-size: 15px; }

  .practice-bar { max-width: min(100% - 110px, 620px); padding: 3px 8px; gap: 8px; border-width: 1px; }
  .practice-title { display: none; }
  .practice-bar label { flex-direction: row; align-items: center; gap: 4px; font-size: 10px; }
  .nsel-btn { min-width: 0; gap: 8px; padding: 2px 6px; font-size: 12px; border-width: 1px; }
  .nsel-btn::after { width: 5px; height: 5px; margin-top: -3px; }
  .nsel-list { top: calc(100% + 3px); max-height: calc(100vh - 44px); border-width: 1px; }
  .nsel-opt { padding: 5px 10px 5px 8px; font-size: 13px; }

  /* 설정 창: 휴대폰 폭의 좁은 창 하나에 세로로 쌓고, 창 안에서 위아래로 스크롤. 닫기 버튼은 아래에 항상 붙어 있음 */
  .settings {
    width: min(100vw - 16px, 400px);
    max-height: calc(100dvh - 12px);
    padding: 10px 16px 0;
    overflow-y: auto;
    overscroll-behavior: contain;      /* 끝까지 스크롤해도 뒤 화면이 따라 움직이지 않게 */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;               /* 경기 중에 열어도 창 안 스크롤은 되게 */
  }
  .settings .heading { margin-bottom: 8px; font-size: 22px; }
  .set-group { margin-bottom: 10px; padding-top: 8px; }
  .set-row { min-height: 42px; font-size: 15px; }
  .set-row input[type="range"] { flex: 0 0 58%; height: 34px; } /* 길이를 맞추고 손가락으로 잡기 쉽게 */
  .set-row input[type="checkbox"] { width: 28px; height: 28px; }
  .sub-btn.small { padding: 9px 16px; font-size: 14px; }
  .text-input { width: 130px; padding: 8px; font-size: 15px; }
  #settings > #close-settings {
    position: sticky;
    bottom: 0;
    width: calc(100% + 32px);
    margin: 0 -16px;
    padding: 12px;
    background: var(--panel);
    border-width: 2px 0 0;
    box-shadow: 0 -8px 12px var(--panel);
  }
  #nickname-dialog { padding-bottom: 12px; }

  .key-note { display: none; }
  #screen-game > .sub-btn { /* 나가기: 오른쪽 위 구석 */
    position: fixed;
    top: 6px;
    right: max(6px, env(safe-area-inset-right));
    z-index: 5;
    padding: 7px 12px;
    font-size: 12px;
  }
  .pad {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 4;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none; /* 버튼 사이 빈 곳은 눌리지 않게 */
  }
  .pad-group { width: 132px; flex-wrap: wrap; gap: 8px; pointer-events: none; }
  .pad-group:last-child { width: 202px; justify-content: flex-end; } /* 윗줄 잽·훅·어퍼컷, 아랫줄 위빙·가드 */
  .stick { width: 124px; height: 124px; pointer-events: auto; }
  .stick-knob { width: 52px; height: 52px; }
  .pad-btn {
    pointer-events: auto;
    min-width: 0;
    width: 62px;
    height: 58px;
    padding: 0;
    font-size: 17px;
    background: rgba(11, 10, 18, 0.72); /* 링과 겹쳐도 뒤가 비치게 */
    -webkit-touch-callout: none;
  }
}

/* 태블릿처럼 손가락으로 쓰는 큰 화면의 경기 화면: 링이 화면을 꽉 채우고, 조작 버튼은 화면 양쪽 아래 구석에 겹쳐 놓음 */
@media (pointer: coarse) and (min-width: 601px) and (min-height: 521px) {
  body[data-screen="game"] { overflow: hidden; touch-action: none; overscroll-behavior: none; } /* 경기 중에는 스크롤·확대 같은 손동작을 모두 끔 */
  body[data-screen="game"] .player-level { display: none; }
  #screen-game {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 12px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 8px;
    justify-content: flex-start;
  }
  .hud, .practice-bar { max-width: min(100% - 210px, 900px); } /* 왼쪽 설정 버튼과 오른쪽 나가기 버튼 사이 */
  .hud { min-height: 58px; }
  .ring-wrap { flex: none; width: 100%; max-width: none; }
  .key-note { display: none; }
  #screen-game > .sub-btn { /* 나가기: 오른쪽 위 구석 */
    position: fixed;
    top: 12px;
    right: max(12px, env(safe-area-inset-right));
    z-index: 5;
    height: 58px;
    padding: 0 18px;
    font-size: 16px;
  }
  .pad {
    position: fixed;
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 4;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none; /* 버튼 사이 빈 곳은 눌리지 않게 */
  }
  .pad-group { width: 168px; flex-wrap: wrap; gap: 10px; pointer-events: none; }
  .pad-group:last-child { width: 268px; justify-content: flex-end; } /* 윗줄 잽·훅·어퍼컷, 아랫줄 위빙·가드 */
  .stick { width: 160px; height: 160px; pointer-events: auto; }
  .stick-knob { width: 66px; height: 66px; }
  .pad-btn {
    pointer-events: auto;
    min-width: 0;
    width: 82px;
    height: 74px;
    padding: 0;
    font-size: 20px;
    background: rgba(11, 10, 18, 0.72); /* 링과 겹쳐도 뒤가 비치게 */
    -webkit-touch-callout: none;
  }
}
/* 가로로 든 태블릿: 링이 남은 높이에 맞춰 커짐 (세로로 들면 위 규칙대로 화면 폭에 맞춤) */
@media (pointer: coarse) and (min-width: 601px) and (min-height: 521px) and (orientation: landscape) {
  .ring-wrap { flex: 1 1 0; min-height: 0; display: flex; justify-content: center; align-items: flex-start; }
  #ring { width: min(100%, (100vh - 100px) * 16 / 9); height: auto; }
  @supports (width: 1cqh) {
    .ring-wrap { container-type: size; }
    #ring { width: min(100cqw, 100cqh * 16 / 9); }
  }
}

@media (prefers-reduced-motion: reduce) {
  .title { animation: none; } /* 로딩 표시(도는 원, 점)는 기다리는 중임을 알려야 하므로 그대로 움직임 */
  .mode-btn { transition: none; animation: none; }
}
