:root {
  --ink: #1f2540;
  --paper: #fffaf2;
  --pink: #e8457c;
  --pink-2: #ffd9e6;
  --red: #ff3b30;
  --mint: #2fbf9f;
  --line: rgba(31, 37, 64, 0.12);
  --shadow: 0 10px 30px rgba(20, 24, 45, 0.18);
  --ui: 'Noto Sans KR', system-ui, sans-serif;
  --fun: 'Jua', 'Noto Sans KR', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9cbea; color: var(--ink); font-family: var(--ui); }
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#labels { position: fixed; inset: 0; pointer-events: none; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* 이름표 */
.tag {
  font: 600 11px var(--ui); color: #fff; padding: 2px 7px; border-radius: 999px;
  background: rgba(25, 28, 45, 0.55); white-space: nowrap; transform: translateY(-4px);
  transition: background 0.15s, color 0.15s;
}
.tag.me { background: var(--pink); font-size: 13px; padding: 3px 10px; box-shadow: 0 0 0 2px #fff; }
.tag.me::after { content: ''; position: absolute; left: 50%; bottom: -6px; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--pink); border-bottom: 0; }
.tag.win { background: var(--mint); }
.tag.watch { background: var(--ink); font-size: 13px; padding: 3px 10px; box-shadow: 0 0 0 2px #fff; }
.tag.dead { background: rgba(80, 80, 90, 0.55); color: rgba(255, 255, 255, 0.7); text-decoration: line-through; }
.tag.locked { background: var(--red); animation: blink 0.12s steps(2) infinite; }
.tag.locked::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 4px; border: 2px solid #fff; border-radius: 50%; vertical-align: -1px; }
@keyframes blink { 50% { opacity: 0.55; } }

/* 오버레이 */
#blackout { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 5; }
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; transition: opacity 0.2s;
  background: radial-gradient(ellipse closest-side at center, transparent 82%, rgba(255, 20, 20, 0.34) 100%);
}
#vignette.on { opacity: 1; animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.65; } }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.hud-tl { position: absolute; top: 16px; left: 16px; }
.counts { display: flex; gap: 6px; }
.counts div {
  background: rgba(255, 250, 242, 0.92); border-radius: 12px; padding: 6px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; min-width: 58px;
}
.counts span { font-size: 11px; color: #6a6f86; }
.counts b { font: 22px var(--fun); }
.counts .p b { color: var(--mint); }
.counts .o b { color: var(--pink); }
.room { margin-top: 8px; font-size: 12px; font-weight: 600; color: #fff; background: rgba(25, 28, 45, 0.5); padding: 4px 10px; border-radius: 999px; display: inline-block; }

.timer {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font: 700 34px 'Courier New', monospace; letter-spacing: 2px; color: var(--red);
  background: #151518; border: 3px solid #36363c; border-radius: 10px; padding: 2px 16px;
  text-shadow: 0 0 10px rgba(255, 59, 48, 0.6); z-index: 7;
}
.timer.low { animation: blink 0.5s steps(2) infinite; }

.lobby {
  position: absolute; top: 76px; left: 50%; transform: translateX(-50%);
  background: rgba(255, 250, 242, 0.95); padding: 8px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow);
}
.lobby b { color: var(--pink); font-size: 17px; }

.center {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%);
  font: 84px var(--fun); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 rgba(31, 37, 64, 0.35); white-space: nowrap;
}
.center.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
.center.count { font-size: 120px; }
.center.go { color: var(--mint); }
.center.win { color: #ffe14d; }
.center.out { color: var(--pink); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } }

.notice {
  position: absolute; bottom: 25%; left: 50%; transform: translate(-50%, 10px); opacity: 0; transition: 0.3s;
  background: var(--ink); color: #fff; padding: 7px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
}
.notice.show { opacity: 1; transform: translate(-50%, 0); }

.sub {
  position: absolute; bottom: 12%; left: 50%; transform: translateX(-50%); white-space: pre;
  font: 58px var(--fun); color: #fff; -webkit-text-stroke: 2px rgba(20, 22, 38, 0.85); paint-order: stroke fill;
  opacity: 0; transition: opacity 0.25s; z-index: 7;
}
.sub.show { opacity: 1; }
.sub.faded { opacity: 0.06; transition: opacity 0.9s linear; }
.sub span { opacity: 0.22; display: inline-block; transition: opacity 0.08s; }
.sub span.on { opacity: 1; color: #fff7d6; animation: syl 0.18s ease-out; }
.sub.paused::after { content: '...'; animation: blink 0.4s steps(2) infinite; }
body[data-lang="en"] .sub { font-size: clamp(18px, 4.6vw, 44px); } /* 로마자는 한글보다 길어 한 줄에 들어가게 */
@keyframes syl { from { transform: translateY(-10px) scale(1.25); } }

.speed {
  position: absolute; bottom: 4.5%; left: 50%; transform: translateX(-50%); width: 220px; height: 26px;
  background: rgba(25, 28, 45, 0.55); border-radius: 999px; overflow: hidden; z-index: 7;
}
.speed i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255, 255, 255, 0.35); transition: width 0.05s; }
.speed span { position: relative; display: block; text-align: center; line-height: 26px; font-size: 12px; font-weight: 800; color: #fff; }
.speed.moving i { background: rgba(47, 191, 159, 0.8); }
.speed.danger { animation: blink 0.15s steps(2) infinite; }
.speed.danger i { background: var(--red); }

.afk {
  position: absolute; top: 120px; left: 50%; transform: translateX(-50%); z-index: 8;
  background: #ffe14d; color: var(--ink); font-weight: 800; padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow);
}
.queue {
  position: absolute; top: 76px; left: 50%; transform: translateX(-50%); z-index: 8; pointer-events: auto;
  background: var(--ink); color: #fff; padding: 10px 12px 10px 18px; border-radius: 14px; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center; font-size: 14px; font-weight: 600;
}
.queue button { border: 0; background: var(--pink); color: #fff; font-weight: 800; padding: 7px 14px; border-radius: 999px; }

.hud-bl { position: absolute; left: 16px; bottom: 16px; }
.feed { display: flex; flex-direction: column-reverse; gap: 4px; margin-bottom: 10px; }
.feed-item {
  font-size: 13px; font-weight: 600; color: #fff; background: rgba(25, 28, 45, 0.55); padding: 4px 10px;
  border-radius: 8px; transition: opacity 1s; align-self: flex-start;
}
.feed-item.out { background: rgba(232, 69, 124, 0.85); }
.feed-item.win { background: rgba(47, 191, 159, 0.9); }
.feed-item.fade { opacity: 0; }
.legend { font-size: 12px; color: #fff; background: rgba(25, 28, 45, 0.5); padding: 6px 10px; border-radius: 8px; display: flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.lg.ice { background: #cfefff; border: 2px solid #fff; }
.lg.glue { background: #5a2c63; border: 2px solid #f2c63c; margin-left: 8px; }
.keys { position: absolute; right: 16px; bottom: 16px; font-size: 12px; color: #fff; background: rgba(25, 28, 45, 0.5); padding: 6px 10px; border-radius: 8px; }
kbd { font: 700 11px var(--ui); background: #fff; color: var(--ink); border-radius: 4px; padding: 1px 5px; margin: 0 2px 0 6px; }
.debug { position: absolute; right: 16px; bottom: 50px; font: 11px monospace; color: #fff; background: rgba(0, 0, 0, 0.4); padding: 2px 6px; border-radius: 4px; }
.debug:empty { display: none; }

/* 언어 선택 (우측 상단, 모든 화면) */
.lang {
  position: fixed; top: 16px; right: 16px; z-index: 30; display: flex; padding: 3px;
  background: rgba(255, 250, 242, 0.96); border: 2px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow);
}
.lang button { border: 0; background: transparent; color: var(--ink); font: 700 13px var(--ui); padding: 5px 12px; border-radius: 999px; }
.lang button.on { background: var(--ink); color: #fff; }

/* 랭킹 */
.rank {
  position: fixed; top: 60px; right: 16px; width: 240px; z-index: 9; background: rgba(255, 250, 242, 0.96);
  border-radius: 16px; box-shadow: var(--shadow); padding: 14px; font-size: 13px;
}
.rank-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.rank-head b { font: 22px var(--fun); }
.rank-head span { font-size: 11px; color: #6a6f86; }
.rank-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.rank-tabs button { flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 999px; font-size: 11px; padding: 3px 0; color: #6a6f86; }
.rank-tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.rank-tabs button:disabled { opacity: 0.5; cursor: default; }
.rank ol { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; padding: 5px 6px; border-radius: 8px; }
.rank li:nth-child(odd) { background: rgba(31, 37, 64, 0.04); }
.rank li b { font: 15px var(--fun); color: #8a8fa6; }
.rank li.top b { color: var(--pink); }
.rank li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank li em { font-style: normal; font-weight: 800; }
.rank li.me { background: var(--pink-2); }
.rank-me { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }
.rank-me:empty { display: none; }

/* 결과 */
.result {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9; min-width: 300px;
  background: var(--paper); border-radius: 20px; box-shadow: var(--shadow); padding: 22px 28px; text-align: center;
  border-top: 8px solid var(--ink);
}
.result.pass { border-top-color: var(--mint); }
.result.out, .result.timeout { border-top-color: var(--pink); }
.res-kind { font: 54px var(--fun); }
.result.pass .res-kind { color: var(--mint); }
.result.out .res-kind, .result.timeout .res-kind { color: var(--pink); }
.res-sub { font-size: 15px; margin-top: 4px; }
.res-stat { font-size: 13px; color: #6a6f86; margin-top: 6px; }
.res-next { margin-top: 14px; font-size: 13px; background: rgba(31, 37, 64, 0.06); border-radius: 999px; padding: 6px 0; }

/* 화면: 닉네임 / 캐릭터 */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
#screen-nick { background: linear-gradient(180deg, rgba(20, 24, 45, 0.05) 30%, rgba(20, 24, 45, 0.55)); align-items: flex-end; padding-bottom: 8vh; }
.title-card { text-align: center; color: #fff; max-width: 560px; width: 100%; }
h1.brand {
  font: 900 88px/1 var(--ui); letter-spacing: -2px; margin: 0; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 8px 0 rgba(31, 37, 64, 0.3);
}
.game-name {
  display: inline-block; margin: 14px 0 10px; font: 30px var(--fun); color: #fff; background: var(--pink);
  border: 3px solid var(--ink); border-radius: 999px; padding: 4px 22px; box-shadow: 0 5px 0 rgba(31, 37, 64, 0.3);
}
body[data-lang] h1.brand { font-size: clamp(36px, 8vw, 64px); letter-spacing: -1px; margin-bottom: 14px; word-break: keep-all; text-wrap: balance; }
.game-name:empty { display: none; }
.tagline { font: 600 16px var(--ui); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); margin: 0; }
#nick-form { display: flex; gap: 8px; margin: 22px auto 12px; max-width: 420px; }
#nick-form input {
  flex: 1; min-width: 0; font: 600 17px var(--ui); padding: 14px 18px; border-radius: 999px; border: 3px solid var(--ink); outline: none;
}
#nick-form input:focus { border-color: var(--pink); }
.btn { border: 3px solid var(--ink); background: #fff; color: var(--ink); font: 800 16px var(--ui); padding: 12px 22px; border-radius: 999px; }
.btn.primary { background: var(--pink); color: #fff; }
.btn:active { transform: translateY(2px); }
.online { font-size: 13px; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }
.online i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4dff9a; margin-right: 6px; box-shadow: 0 0 8px #4dff9a; }

#screen-create { background: rgba(20, 24, 45, 0.35); }
.creator {
  display: flex; flex-wrap: wrap; gap: 0; background: var(--paper); border-radius: 24px; box-shadow: var(--shadow);
  overflow: hidden; max-width: 900px; width: 100%; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
}
.pv-wrap { position: relative; flex: 1 1 320px; min-height: min(360px, calc(100dvh - 32px)); background: linear-gradient(180deg, #bfe0f7, #f3e3c3); }
#preview { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.pv-name { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); background: var(--pink); color: #fff; font-weight: 800; padding: 4px 14px; border-radius: 999px; }
.pv-hint { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; font-size: 12px; color: rgba(31, 37, 64, 0.6); }
.opts-wrap { flex: 1 1 380px; padding: 22px 24px; overflow-y: auto; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
.opts-wrap h2 { font: 30px var(--fun); margin: 0 0 12px; }
.opt { margin-bottom: 12px; }
.opt label { display: block; font-size: 12px; font-weight: 800; color: #6a6f86; margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--ink); }
.chip.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.sw { width: 28px; height: 28px; border-radius: 50%; background: var(--c); border: 2px solid rgba(31, 37, 64, 0.2); padding: 0; }
.sw.on { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .primary { flex: 1; }

/* 좁은 화면: 미리보기를 위에 고정하고 옵션만 스크롤. 입장 버튼은 항상 보이게 */
.watch {
  position: absolute; left: 50%; bottom: 4.5%; transform: translateX(-50%); white-space: nowrap;
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; padding: 7px 16px; border-radius: 999px; box-shadow: var(--shadow);
}
@media (max-width: 740px) {
  .creator { flex-direction: column; flex-wrap: nowrap; }
  .pv-wrap { flex: 0 0 26dvh; min-height: 0; }
  .opts-wrap { flex: 1 1 auto; min-height: 0; max-height: none; padding: 14px 16px 16px; }
  .opts-wrap h2 { font-size: 22px; margin-bottom: 8px; }
}
@media (max-width: 740px), (max-height: 520px) {
  .actions { position: sticky; bottom: -16px; margin: 14px -16px -16px; padding: 10px 16px 14px; background: var(--paper); }
}

@media (max-width: 700px) {
  h1.brand { font-size: 60px; }
  .game-name { font-size: 22px; }
  .sub { font-size: 34px; }
  .center { font-size: 56px; }
  .rank { width: 190px; top: auto; bottom: 90px; }
  .keys { display: none; }
  .timer { font-size: 24px; }
}

/* QA 캡처: 전환·애니메이션을 끄고 최종 상태로 고정 */
body.qa *, body.qa *::before, body.qa *::after { transition: none !important; animation: none !important; }
.online i.off { background: #c9c9d1; box-shadow: none; }
