:root {
  --bg: #151826;
  --bg2: #1d2133;
  --card: #232842;
  --line: #343a5c;
  --text: #eef0fa;
  --muted: #9aa1c4;
  --accent: #ffcf3f;
  --accent-ink: #2a2100;
  --good: #2ee59d;
  --bad: #ff4d6a;
  --radius: 14px;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.screen { display: none; position: fixed; inset: 0; }
.screen.active { display: flex; }
#menu { overflow-y: auto; justify-content: center; align-items: flex-start; }

.lobby-wrap { width: min(760px, 100%); padding: 24px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.brand { text-align: center; padding: 10px 0 4px; }
.brand h1 { margin: 0; font-size: clamp(36px, 8vw, 56px); letter-spacing: -1px; font-weight: 900; }
.brand h1 span { color: var(--accent); }
.brand p { margin: 6px 0 0; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card h2 b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; }
.card.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card.two .col { display: flex; flex-direction: column; gap: 10px; }
.card.two .col + .col { border-left: 1px solid var(--line); padding-left: 18px; }
.card.two h2 { margin: 0; }
@media (max-width: 620px) {
  .card.two { grid-template-columns: 1fr; }
  .card.two .col + .col { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 14px; }
}
.desc { margin: 0; color: var(--muted); font-size: 14px; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span, .row-label { font-size: 13px; color: var(--muted); }
input, select { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.row-label { width: 52px; flex: none; }
.row select { flex: 1; }

.seg { display: flex; gap: 6px; flex: 1; }
.seg button { flex: 1; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 700; transition: .12s; }
.seg button small { font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: 1px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg button.on small { color: #5c4a00; }


.btn { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-weight: 800; transition: transform .08s, filter .12s; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.join { display: flex; gap: 6px; }
.join input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }
.mini { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.mini.ghost { background: transparent; }

.badge { display: inline-block; font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 5px; vertical-align: middle; letter-spacing: .5px; }
.badge.ai { background: #6c5ce7; color: #fff; }
.badge.me { background: var(--accent); color: var(--accent-ink); }
.badge.host { background: #3a4370; color: #cfd6ff; }
.badge.off { background: #5b2633; color: #ffb3c0; }
.badge.user { background: #1f4d43; color: #a9f5d8; }

/* 대기실 */
/* 대기실 장면 (경기 화면 위 오버레이) */
#game.lobby-mode .race-only, #game.lobby-mode .stats, #game.lobby-mode .ranks { display: none !important; }
#game:not(.lobby-mode) .lobby-only { display: none !important; }
/* 완주 후 결승 구역: 글자 버튼·키 표시줄 대신 이동·점프·도발 버튼 */
#game.goal-mode .lobby-bar { display: flex !important; }
#game.goal-mode .pad, #game.goal-mode .keystrip { display: none !important; }
.lobby-panel { position: absolute; left: 8px; top: 8px; width: min(250px, calc(100% - 16px)); background: rgba(15, 17, 30, .8); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; backdrop-filter: blur(3px); z-index: 2; }
.lp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-kind { font-weight: 900; font-size: 16px; }
.room-set { background: var(--bg2); border-radius: 6px; padding: 3px 7px; font-weight: 700; font-size: 11px; white-space: nowrap; }
.room-code { color: var(--muted); margin-top: 6px; }
.room-code b { color: var(--accent); letter-spacing: 3px; font-size: 18px; }
.slots { list-style: none; margin: 4px 0 4px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.room-count { margin-top: 6px; font-size: 11px; color: var(--muted); font-weight: 700; }
.slots li { display: flex; align-items: center; gap: 6px; background: var(--bg2); border-radius: 8px; padding: 5px 8px; }
.slots li { min-width: 0; }
.slots li.me { box-shadow: 0 0 0 1.5px var(--accent) inset; }
.slots li.off { opacity: .45; }
.slots .crown { font-size: 11px; margin-right: -3px; }
.slots li b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.slots li.empty { color: var(--muted); border: 1px dashed var(--line); background: transparent; }
.slots .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.room-status { font-weight: 700; margin: 8px 0 0; min-height: 1.4em; color: var(--accent); }
.lp-host { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.lp-host .check { margin-top: 0; font-size: 12px; }
.lobby-panel .hint { font-size: 11px; margin-top: 6px; }
.touch-only { display: none; }
@media (pointer: coarse) { .kbd-only { display: none; } .touch-only { display: inline; } }
.lobby-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: var(--bg2); border-top: 1px solid var(--line); touch-action: none; user-select: none; -webkit-user-select: none; }
.lobby-bar .move { width: clamp(64px, 22vw, 120px); height: clamp(52px, 9vh, 70px); border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 24px; touch-action: none; }
.lobby-bar .move.down { background: var(--accent); color: var(--accent-ink); }
.lobby-bar .lb-right { display: flex; gap: 8px; }
.lobby-bar .move.jump { font-size: 15px; font-weight: 800; width: clamp(56px, 16vw, 90px); }
.lobby-bar .move.jump:active { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 520px) { .lobby-panel { font-size: 12px; width: min(210px, calc(100% - 16px)); padding: 8px 10px; } .room-code b { font-size: 15px; } }

/* 경기 화면 */
#game { flex-direction: column; background: var(--bg); }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--bg2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.match-tag { font-size: 13px; font-weight: 700; color: var(--muted); }
.stats { display: flex; gap: 16px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 54px; }
.stat span { font-size: 11px; color: var(--muted); }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat.time b.warn { color: var(--bad); }
.stat b.bump { animation: bump .18s; }
@keyframes bump { 50% { transform: scale(1.25); } }
@media (max-width: 720px) {
  .hud { padding: 6px 8px; gap: 6px; }
  .stats { order: 3; width: 100%; justify-content: space-around; gap: 4px; }
  .stat b { font-size: 17px; }
  .match-tag { display: none; }
}

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ranks { position: absolute; left: 8px; top: 8px; margin: 0; padding: 6px; list-style: none; background: rgba(15, 17, 30, .72); border-radius: 10px; font-size: 13px; min-width: 170px; pointer-events: none; backdrop-filter: blur(3px); }
.ranks li { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 6px; }
.ranks li.me { background: rgba(255, 207, 63, .16); }
.ranks .rk { width: 22px; font-weight: 900; text-align: right; }
.ranks li.gap { justify-content: center; color: var(--muted); padding: 0; line-height: 1; }
.ranks .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ranks .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.ranks .vl { font-variant-numeric: tabular-nums; color: var(--muted); }
.ranks li.fin .vl { color: var(--good); font-weight: 700; }
@media (max-width: 520px) { .ranks { font-size: 11px; min-width: 130px; } .ranks .nm { max-width: 70px; } }

.banner { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: rgba(15, 17, 30, .85); border: 1px solid var(--accent); color: var(--accent); padding: 6px 14px; border-radius: 999px; font-weight: 800; font-size: 14px; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap; }
.banner.show { opacity: 1; }
@media (max-width: 520px) { .banner { top: auto; bottom: 10px; font-size: 12px; } }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(80px, 20vw, 180px); font-weight: 900; color: var(--accent); text-shadow: 0 6px 0 rgba(0,0,0,.35); pointer-events: none; }
.countdown.go { color: var(--good); }
.countdown .pop { animation: cd .9s ease-out both; }
@keyframes cd { 0% { transform: scale(1.6); opacity: 0; } 20% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: .0; } }
.conn { position: absolute; right: 10px; top: 10px; background: var(--bad); color: #fff; padding: 4px 10px; border-radius: 8px; font-weight: 700; font-size: 13px; }

.keystrip { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg2); border-top: 1px solid var(--line); position: relative; }
.cur-wrap { position: relative; flex: none; }
.cur { width: 76px; height: 76px; border-radius: 16px; display: grid; place-items: center; font-size: 44px; font-weight: 900; color: #111; box-shadow: 0 0 0 4px #fff inset, 0 6px 0 rgba(0,0,0,.35); transition: transform .06s; }
.cur.ok { animation: okpop .14s; }
.cur.miss { animation: shake .25s; filter: grayscale(.6) brightness(.7); }
@keyframes okpop { 40% { transform: scale(1.12); } }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
.lockbar { position: absolute; left: 6px; right: 6px; bottom: -6px; height: 5px; border-radius: 3px; background: var(--bad); transform-origin: left; transform: scaleX(0); }
.next { display: flex; gap: 8px; align-items: center; overflow: hidden; flex: 1; }
.next div { flex: none; width: 46px; height: 46px; border-radius: 11px; display: grid; place-items: center; font-weight: 900; font-size: 22px; color: #111; }
.fb { position: absolute; left: 100px; top: -26px; font-weight: 900; font-size: 18px; pointer-events: none; opacity: 0; }
.fb.ok { color: var(--good); animation: fbup .45s ease-out; }
.fb.miss { color: var(--bad); animation: fbup .6s ease-out; }
@keyframes fbup { 0% { opacity: 1; transform: translateY(6px); } 100% { opacity: 0; transform: translateY(-14px); } }
.keystrip.done .cur { background: var(--good) !important; font-size: 18px; }
.fb.taunt { color: #fff; animation: fbup .9s ease-out; white-space: nowrap; }
.taunts { display: flex; gap: 5px; flex: none; }
.taunts button { position: relative; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 19px; display: grid; place-items: center; padding: 0; touch-action: none; }
.taunts button small { position: absolute; left: 3px; top: 1px; font-size: 10px; font-weight: 800; color: var(--muted); }
.taunts button.used { animation: tpop .35s; border-color: var(--accent); }
@keyframes tpop { 40% { transform: scale(1.2); } }
@media (max-width: 520px) { .taunts button { width: 30px; height: 34px; font-size: 15px; } .taunts { gap: 2px; } }
@media (max-width: 520px) { .lobby-bar { gap: 6px; padding: 8px; } .lobby-bar .move { width: 52px; } .lobby-bar .move.jump { width: 48px; font-size: 13px; } .lobby-bar .lb-right { gap: 6px; } }

.pad { display: flex; gap: 8px; padding: 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--bg2); touch-action: none; user-select: none; -webkit-user-select: none; }
.pad .gap { width: 18px; flex: none; }
.pad button { flex: 1; height: clamp(56px, 11vh, 86px); border-radius: 14px; border: 0; font-size: 26px; font-weight: 900; color: #111; box-shadow: 0 5px 0 rgba(0,0,0,.4); transition: transform .05s, box-shadow .05s, filter .1s; touch-action: none; }
.pad button.down { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.4); }
.pad button.flash-ok { filter: brightness(1.35); }
.pad button.flash-miss { background: var(--bad) !important; color: #fff; }
.pad.locked button { filter: grayscale(.8) brightness(.6); }
@media (hover: hover) and (pointer: fine) { .pad button { height: 58px; } }

/* 결과 */
.overlay { position: absolute; inset: 0; background: rgba(8, 10, 20, .72); display: grid; place-items: center; padding: 16px; z-index: 5; backdrop-filter: blur(4px); }
.result-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: min(640px, 100%); max-height: 100%; overflow: auto; }
.result-card h2 { margin: 0; font-size: 26px; }
.res-sub { color: var(--muted); margin: 4px 0 12px; }
.table-wrap { overflow-x: auto; }
.res-table { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.res-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.res-table td { padding: 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.res-table tr.me td { background: rgba(255, 207, 63, .1); }
.res-table .rk { font-weight: 900; font-size: 18px; }
.res-table .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.res-table .fin { color: var(--good); font-weight: 800; }
.res-table .dnf { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-weight: 700; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.res-note { color: var(--muted); font-size: 13px; margin: 8px 0 0; min-height: 1em; }
.res-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.res-actions .btn { flex: 1; min-width: 140px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #fff; color: #111; padding: 10px 16px; border-radius: 10px; font-weight: 700; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
