/* 다크 테마 주변 UI. 게임 캔버스 주변 레터박스는 #0B0E16 */
:root {
  --bg: #0B0E16; --bg2: #121725; --panel: #171D2C; --panel2: #1E2538; --line: #2A3349; --line2: #3A4560;
  --text: #E8ECF4; --text2: #A9B3C7; --muted: #7C879E;
  --accent: #4C8DFF; --accent2: #2F6FE0; --ok: #3BD16F; --warn: #FFB21E; --danger: #FF5A5A;
  --radius: 10px; --radius-s: 7px; --tap: 44px;
  --font: "Pretendard", "Pretendard Variable", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
  /* 화면 높이: JS(viewport.js)가 visualViewport 기준 --vvh 를 넣고, 없으면 100dvh → 100vh 폴백. 인앱 브라우저 하단 툴바에 버튼이 가려지지 않게 */
  --app-h: 100vh;
  --view-h: var(--vvh, var(--app-h));
}
@supports (height: 100dvh) { :root { --app-h: 100dvh; } }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; height: var(--view-h); }
#app { height: 100%; outline: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .tabular, output { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: 8px 12px; z-index: 1000; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid #9CC0FF; outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* ---------- 버튼 ---------- */
.btn { min-height: var(--tap); padding: 0 16px; border-radius: var(--radius-s); border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; touch-action: manipulation; }
.btn:hover:not(:disabled) { background: #263050; border-color: #4A5778; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent2); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.danger { background: #5A1F26; border-color: #8A2C36; color: #FFD9DC; }
.btn.ok { background: #1D5A36; border-color: #2E8A52; color: #D8FFE6; }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: var(--radius-s); border: 1px solid transparent; background: transparent; cursor: pointer; font-size: 18px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--panel2); }
kbd { font: 11px var(--mono); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line2); background: var(--bg2); color: var(--text2); }

/* ---------- 폼 ---------- */
.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field-label { font-size: 13px; color: var(--text2); }
input[type=text], input[type=search], input[type=number], input[type=password], input:not([type]), select, textarea {
  min-height: var(--tap); padding: 0 12px; border-radius: var(--radius-s); border: 1px solid var(--line2); background: var(--bg2); width: 100%;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(76,141,255,.25); }
input.num { width: 110px; text-align: right; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type=range] { flex: 1; min-width: 60px; }
.range-row .val { min-width: 56px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.step { width: var(--tap); height: var(--tap); flex: none; border-radius: var(--radius-s); border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; font-size: 20px; line-height: 1; touch-action: manipulation; user-select: none; }
.step:hover:not(:disabled) { background: #263050; }
input[type=range] { -webkit-appearance: none; appearance: none; height: var(--tap); background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line2); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line2); background: var(--bg2); font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed=true], .chip.on { background: var(--accent2); border-color: var(--accent); color: #fff; }
.switch-field { grid-template-columns: 1fr auto; align-items: center; min-height: var(--tap); cursor: pointer; }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: var(--line2); transition: background .15s; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(22px); }
.switch input:focus-visible + .switch-track { outline: 2px solid #9CC0FF; outline-offset: 2px; }
.segment { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: var(--radius-s); background: var(--bg2); border: 1px solid var(--line); }
.seg-item { position: relative; flex: 1 1 auto; }
.seg-item input { position: absolute; opacity: 0; inset: 0; margin: 0; pointer-events: none; }
.seg-item label { display: flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 10px; border-radius: 5px; cursor: pointer; font-size: 14px; color: var(--text2); white-space: nowrap; }
.seg-item input:checked + label { background: var(--accent2); color: #fff; font-weight: 600; }
.seg-item input:focus-visible + label { outline: 2px solid #9CC0FF; }
.seg-item input:disabled + label { cursor: not-allowed; opacity: .6; }
.tabs { min-height: var(--tap); flex: none; display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { min-height: var(--tap); padding: 0 14px; border: 0; background: none; color: var(--text2); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- 레이어(모달/시트/드로어) ---------- */
#layers { position: fixed; left: 0; right: 0; top: 0; height: var(--view-h); pointer-events: none; z-index: 50; }
.layer { position: absolute; inset: 0; background: rgba(5,7,12,.6); display: flex; pointer-events: auto; opacity: 0; transition: opacity .16s; }
.layer.open { opacity: 1; }
.layer.modal { align-items: center; justify-content: center; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
.layer.sheet { align-items: flex-end; justify-content: center; }
.layer.drawer { justify-content: flex-end; }
.layer-panel { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 100%; outline: none; }
.layer-panel.modal { border-radius: 14px; width: min(560px, 100%); max-height: min(calc(var(--view-h) * .88), 900px); transform: translateY(8px); transition: transform .16s; }
.layer-panel.modal.confirm { width: min(380px, 100%); }
.layer-panel.modal.wide { width: min(760px, 100%); }
.layer-panel.sheet { width: min(760px, 100%); border-radius: 16px 16px 0 0; max-height: calc(var(--view-h) * .78); transform: translateY(30px); transition: transform .18s; padding-bottom: env(safe-area-inset-bottom); }
.layer-panel.drawer { width: min(400px, 92vw); height: 100%; border-radius: 14px 0 0 14px; transform: translateX(30px); transition: transform .18s; padding-bottom: env(safe-area-inset-bottom); }
.layer.open .layer-panel { transform: none; }
.layer-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--line); }
.layer-head h2 { flex: 1; }
.layer-body { padding: 16px 18px; overflow: auto; flex: 1; }
.layer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.confirm .layer-body { display: none; }

/* ---------- 토스트 ---------- */
#toasts { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { padding: 11px 14px; border-radius: 10px; background: #222A3E; border: 1px solid var(--line2); box-shadow: var(--shadow); opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s; font-size: 14px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #3A1A20; border-color: #7A2E38; color: #FFE0E3; }
.toast.warn { background: #3A2E12; border-color: #7A5E1E; color: #FFF0CC; }
.toast.ok { background: #143323; border-color: #2B6A47; color: #DAFFE8; }

/* ---------- 화면 공통 ---------- */
.screen { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg2); min-height: 56px; padding-top: max(8px, env(safe-area-inset-top)); }
.brand { font-weight: 800; letter-spacing: .02em; font-size: 18px; background: linear-gradient(90deg, #FFD08A, #F07C55); -webkit-background-clip: text; background-clip: text; color: transparent; }
.content { flex: 1; overflow: auto; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; background: var(--panel2); border: 1px solid var(--line2); color: var(--text2); white-space: nowrap; }
.badge.host { background: #3A2E12; border-color: #7A5E1E; color: #FFE6A8; }
.badge.ready { background: #143323; border-color: #2B6A47; color: #9FF0BE; }
.badge.cpu { background: #1E2A48; border-color: #34508A; color: #B8CCFF; }
.badge.off { background: #2A1B1F; border-color: #5A2E36; color: #FFB6BE; }

/* 닉네임 */
.nick-screen { display: grid; place-items: center; height: 100%; padding: 20px; background: radial-gradient(1200px 600px at 70% 110%, #3A1C2C 0%, transparent 60%), radial-gradient(900px 500px at 10% -10%, #18264A 0%, transparent 60%), var(--bg); }
.nick-card { width: min(400px, 100%); padding: 28px 24px; }
.nick-card .title { font-size: 30px; margin-bottom: 4px; }
.nick-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 13px; }

/* 방 목록 */
.room-list { display: grid; gap: 8px; max-width: 900px; margin: 0 auto; }
.room-row { display: grid; grid-template-columns: 1fr auto auto auto auto; gap: 12px; align-items: center; padding: 12px 14px; min-height: 60px; text-align: left; width: 100%; cursor: pointer; }
.room-row:hover:not(:disabled) { border-color: var(--line2); background: var(--panel2); }
.room-row:disabled { cursor: not-allowed; opacity: .6; }
.room-row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row .h { font-size: 12px; color: var(--muted); }
.room-head { display: flex; gap: 10px; align-items: center; max-width: 900px; margin: 0 auto 12px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* 대기실 */
.room-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); gap: 14px; height: 100%; max-width: 1200px; margin: 0 auto; }
.slots { display: grid; gap: 8px; align-content: start; }
.slot { display: grid; grid-template-columns: 34px 72px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; min-height: 64px; }
.slot.me { border-color: #3D5A99; }
.slot.empty { opacity: .8; border-style: dashed; grid-template-columns: 34px 1fr auto; }
.slot canvas { width: 72px; height: 48px; display: block; }
.slot .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.slot-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.slot-actions select { min-height: 36px; width: auto; font-size: 13px; }
.marker { width: 26px; height: 26px; display: block; }
.chat { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-log { flex: 1; overflow: auto; padding: 10px 12px; display: grid; gap: 4px; align-content: start; min-height: 140px; }
.chat-line { font-size: 14px; word-break: break-word; }
.chat-line b { color: #CFE0FF; margin-right: 6px; }
.chat-line.sys { color: var(--muted); font-size: 13px; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.bottombar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: max(10px, env(safe-area-inset-bottom)); flex-wrap: wrap; }
.opt-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.tank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tank-card { padding: 10px; text-align: left; cursor: pointer; display: grid; gap: 4px; min-height: 140px; }
.tank-card canvas { width: 100%; height: 64px; }
.tank-card[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(76,141,255,.35) inset; }
.tank-card:disabled { opacity: .45; cursor: not-allowed; }
.tank-card .d { font-size: 12px; color: var(--muted); }
.sky-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.sky-opt { position: relative; }
.sky-opt input { position: absolute; opacity: 0; }
.sky-opt label { display: grid; gap: 4px; justify-items: center; padding: 6px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; font-size: 12px; }
.sky-opt .sw { width: 100%; height: 34px; border-radius: 5px; border: 1px solid rgba(255,255,255,.08); }
.sky-opt input:checked + label { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(76,141,255,.35) inset; }
.sky-opt input:focus-visible + label { outline: 2px solid #9CC0FF; }
.wall-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
details.adv summary { cursor: pointer; color: var(--text2); min-height: 36px; display: flex; align-items: center; }

/* ---------- 게임 ---------- */
.game { display: grid; height: 100%; grid-template-columns: minmax(0, 1fr) 240px; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "hud hud" "stage side" "ctrl ctrl"; background: var(--bg); }
.hud { grid-area: hud; display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg2); flex-wrap: wrap; min-height: 52px; padding-top: max(6px, env(safe-area-inset-top)); }
.hud .who { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.hud .who .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.hud .round { font-size: 13px; color: var(--text2); }
.stage { grid-area: stage; display: grid; place-items: center; overflow: hidden; background: #0B0E16; position: relative; min-height: 200px; touch-action: none; }
.stage canvas { display: block; image-rendering: auto; }
.stage.targeting { cursor: crosshair; }
.stage .banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(11,14,22,.85); border: 1px solid var(--line2); padding: 6px 14px; border-radius: 999px; font-size: 14px; pointer-events: none; white-space: nowrap; }
.side { grid-area: side; border-left: 1px solid var(--line); background: var(--bg2); overflow: auto; padding: 8px; }
.plist { display: grid; gap: 4px; }
.prow { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; border: 1px solid transparent; font-size: 14px; }
.prow.turn { border-color: var(--accent); background: #18223A; }
.prow.dead { opacity: .45; }
.prow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .sub { grid-column: 2 / 4; display: flex; gap: 8px; font-size: 12px; color: var(--muted); }
.prow .bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; grid-column: 2 / 4; }
.prow .bar i { display: block; height: 100%; background: var(--ok); }
.ctrl { grid-area: ctrl; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "a p f" "t t f"; gap: 6px 14px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.ctrl > .aim:nth-child(1) { grid-area: a; } .ctrl > .aim:nth-child(2) { grid-area: p; } .ctrl > .tools { grid-area: t; } .ctrl > .fire-wrap { grid-area: f; }
.aim { display: grid; grid-template-columns: 36px 48px minmax(0, 1fr); align-items: center; gap: 6px; }
.aim .lab { font-size: 13px; color: var(--text2); }
.aim .big { font: 700 22px/1 var(--font); font-variant-numeric: tabular-nums; text-align: right; }
.aim .range-row { gap: 4px; }
.fire-btn { min-width: 120px; min-height: 56px; font-size: 18px; font-weight: 800; border-radius: 14px; background: linear-gradient(180deg, #FF6A3B, #D9431E); border: 1px solid #FF8A5A; color: #fff; cursor: pointer; touch-action: manipulation; }
.fire-btn:disabled { filter: grayscale(.8); opacity: .5; cursor: not-allowed; }
.fire-btn:not(:disabled):hover { filter: brightness(1.1); }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.weapon-chip { display: flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 12px; border-radius: var(--radius-s); border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; max-width: 240px; }
.weapon-chip .wn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.weapon-chip .wc { color: var(--text2); font-variant-numeric: tabular-nums; }
.quick { display: flex; gap: 4px; flex-wrap: wrap; }
.qi { min-height: 36px; min-width: 44px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-size: 12px; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; color: var(--text2); }
.qi.on { border-color: var(--ok); color: #CFFFE0; background: #143323; }
.qi:disabled { opacity: .4; cursor: not-allowed; }
.wind { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; min-width: 96px; }
.wind svg { width: 44px; height: 20px; }
.energy { display: grid; gap: 2px; min-width: 120px; }
.energy .eb { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.energy .eb i { display: block; height: 100%; background: linear-gradient(90deg, #3BD16F, #C8F23A); transition: width .2s; }
.energy .et { font-size: 12px; color: var(--text2); font-variant-numeric: tabular-nums; }
.timer { display: grid; gap: 2px; min-width: 92px; }
.timer .tt { font: 700 18px/1 var(--font); font-variant-numeric: tabular-nums; }
.timer .tb { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.timer .tb i { display: block; height: 100%; background: var(--accent); }
.timer.urgent .tt { color: var(--danger); }
.timer.urgent .tb i { background: var(--danger); }
.timer.urgent.blink .tt { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .timer.urgent.blink .tt { animation: none; } * { transition: none !important; } }
.weapon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.wcard { text-align: left; padding: 10px; display: grid; gap: 2px; cursor: pointer; min-height: 72px; }
.wcard[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(76,141,255,.35) inset; }
.wcard .n { font-weight: 600; }
.wcard .c { font-size: 12px; color: var(--text2); }
.wcard .s { font-size: 12px; color: var(--muted); }
.cp-grid { display: grid; gap: 12px; }
.cp-item { padding: 12px; display: grid; gap: 8px; }
.cp-item .top { display: flex; align-items: center; gap: 8px; }
.cp-item .top h3 { flex: 1; }
.move-pad { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.move-pad .btn { min-height: 64px; font-size: 22px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }

/* ---------- 상점 ---------- */
.shop { position: absolute; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
.shop-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg2); padding-top: max(10px, env(safe-area-inset-top)); }
.money { display: flex; gap: 14px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.money div { display: grid; }
.money small { font-size: 11px; color: var(--muted); }
.money b { font-size: 18px; }
.shop-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 280px; min-height: 0; }
.shop-main { overflow: auto; padding: 12px 14px; display: grid; gap: 10px; align-content: start; }
.shop-filter { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.shop-filter input { max-width: 220px; min-height: 38px; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.item { padding: 12px; display: grid; gap: 6px; align-content: start; }
.item:focus-within { border-color: var(--accent); }
.item .n { font-weight: 700; }
.item .s { font-size: 12px; color: var(--muted); min-height: 32px; }
.item .p { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 14px; }
.item .own { color: var(--text2); font-size: 13px; }
.mine { border-left: 1px solid var(--line); overflow: auto; padding: 12px; background: var(--bg2); }
.mine-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; min-height: 40px; font-size: 14px; border-bottom: 1px solid var(--line); }
.wait-shop { display: grid; place-items: center; gap: 10px; padding: 40px; text-align: center; }

/* ---------- 결과 ---------- */
.result { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(5,7,12,.82); padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
.result .card { width: min(560px, 100%); padding: 20px; display: grid; gap: 14px; max-height: 100%; overflow: auto; }
.rank { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rank th, .rank td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.rank th:nth-child(2), .rank td:nth-child(2) { text-align: left; }
.rank tr.win td { color: #FFE6A8; font-weight: 700; }
.rank tr.me td:nth-child(2) { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 반응형 ---------- */
@media (min-width: 1024px) { .hide-d { display: none !important; } }
@media (max-width: 1023px) {
  .game { grid-template-columns: minmax(0, 1fr); grid-template-areas: "hud" "stage" "ctrl"; }
  .side { display: none; }
  .side.open { display: block; position: absolute; right: 8px; top: 60px; width: 240px; max-height: calc(var(--view-h) * .6); z-index: 10; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }

  .room-grid { grid-template-columns: 1fr; height: auto; }
  .chat { height: 320px; }
  .shop-body { grid-template-columns: 1fr; }
  .mine { border-left: 0; border-top: 1px solid var(--line); max-height: calc(var(--view-h) * .34); }
}
@media (max-width: 599px) {
  body { font-size: 14px; }
  .content { padding: 10px; }
  .room-row { grid-template-columns: 1fr auto; }
  .room-row .hide-m { display: none; }
  .ctrl { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "a a" "p p" "t f"; gap: 6px 8px; padding: 6px 8px; }
  .ctrl .aim { grid-template-columns: 34px 40px minmax(0, 1fr); }
  .ctrl .tools { gap: 4px; }
  .ctrl .quick { order: 9; width: 100%; }
  .weapon-chip { max-width: 100%; }
  .aim .big { font-size: 18px; }
  .hud { gap: 6px 10px; }
  .hud .energy { min-width: 90px; }
  .hud .hide-m { display: none; }
  .slot { grid-template-columns: 28px 56px 1fr; }
  .slot canvas { width: 56px; height: 40px; }
  .slot-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .sky-grid { grid-template-columns: repeat(2, 1fr); }
  .fire-btn { min-width: 96px; }
}

/* ---------- 게임 화면 레이아웃(캔버스 최대화) ----------
   기본(좁은 화면): HUD / 캔버스 / 조작. wide(가로 ≥1024): 좌 조작 패널 | 캔버스(--cw) | 우 플레이어 패널.
   portrait(세로): 캔버스 폭 = 뷰포트 폭(종횡비 --aspect), 조작은 아래 시트. 캔버스 주변 배경은 렌더러가 하늘 연장+비네팅으로 칠함 */
.game { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "hud" "stage" "ctrl"; }
.game .stage { background: transparent; min-height: 120px; }
.game .hud { min-height: 40px; padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; background: rgba(18,23,37,.82); }
.game .hud .round { white-space: nowrap; }
.game .ctrl { background: rgba(18,23,37,.82); }
.game:not(.wide) .side { display: none; }
.game:not(.wide) .side.open { display: block; position: absolute; right: 8px; top: 52px; width: 240px; max-height: calc(var(--view-h) * .6); z-index: 10; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.maxp { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pl-fold > summary { cursor: pointer; font-size: 12px; color: var(--text2); padding: 4px 6px; list-style-position: inside; user-select: none; }
.pl-fold[open] > summary { margin-bottom: 4px; }
.stage canvas { border-radius: 2px; }

.game.wide { grid-template-columns: minmax(0, 1fr) var(--cw, 960px) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "hud hud hud" "ctrl stage side"; }
.game.wide .pl-toggle { display: none; }
.game.wide .ctrl { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 8px; padding: 12px; border-top: 0; border-right: 1px solid var(--line); overflow: auto; min-width: 0; background: rgba(18,23,37,.62); backdrop-filter: blur(4px); }
.game.wide .side { display: block; border-left: 1px solid var(--line); background: rgba(18,23,37,.62); backdrop-filter: blur(4px); min-width: 0; }
.game.wide .ctrl .aim { grid-template-columns: auto 1fr; gap: 4px 8px; }
.game.wide .ctrl .aim .big { text-align: left; }
.game.wide .ctrl .aim .range-row { grid-column: 1 / -1; min-width: 0; }
.game.wide .ctrl .aim .range-row input[type=range] { min-width: 0; flex: 1; }
.game.wide .ctrl .tools { flex-direction: column; align-items: stretch; }
.game.wide .ctrl .weapon-chip { max-width: none; }
.game.wide .ctrl .quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.game.wide .ctrl .fire-btn { width: 100%; }
/* wide: HUD는 별도 가로 행 없이 좌 조작 패널 상단에 2줄로(캔버스가 화면 맨 위까지) */
.game.wide { grid-template-areas: "hud stage side" "ctrl stage side"; }
.game.wide .hud { flex-wrap: wrap; align-content: flex-start; gap: 6px 8px; min-height: 0; padding: max(8px, env(safe-area-inset-top)) 12px 4px; border-bottom: 0; border-right: 1px solid var(--line); background: rgba(18,23,37,.62); backdrop-filter: blur(4px); min-width: 0; }
.game.wide .hud .who { flex: 1 1 0; }
.game.wide .hud .who .name { max-width: none; }
.game.wide .hud .round { font-size: 12px; }
.game.wide .hud .spacer { flex: 0 0 100%; height: 0; }
.game.wide .hud .wind { min-width: 0; gap: 4px; }
.game.wide .hud .wind svg { width: 36px; }
.game.wide .hud .timer { flex: 1 1 0; min-width: 56px; }
.game.wide .hud .icon-btn { flex: none; width: 36px; height: 36px; }
.game.wide .hud .energy { order: 1; flex: 1 1 100%; min-width: 0; }

.game.portrait { grid-template-rows: auto auto minmax(0, 1fr); }
.game.portrait .stage { aspect-ratio: var(--aspect, 1.3333); width: 100%; min-height: 0; }
.game.portrait .ctrl { align-content: start; overflow: auto; }
.game.wide .ctrl .aim .range-row { flex-wrap: wrap; gap: 6px; }
.game.wide .ctrl .aim .range-row input[type=range] { order: -1; flex: 1 0 100%; }
.game.wide .ctrl .aim .range-row .maxp { margin-left: auto; }
.game.wide .ctrl > * { flex: none; }
.game.wide .ctrl > :first-child { margin-top: auto; }
.game.wide .ctrl .step { width: 34px; height: 34px; font-size: 17px; }
.game.wide .ctrl .aim .big { font-size: 20px; }
.game.wide .ctrl .quick { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 32px; gap: 4px; }
.game.wide .ctrl .qi { min-height: 0; min-width: 0; padding: 0 4px; font-size: 11px; justify-content: center; overflow: hidden; white-space: nowrap; }
.game.wide .ctrl .tools .btn.small { min-height: 32px; }
.game.wide .ctrl .weapon-chip { min-height: 38px; }
.game.wide .ctrl .fire-btn { min-height: 50px; }
.game.wide .ctrl .tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.game.wide .ctrl .tools > .weapon-chip, .game.wide .ctrl .tools > .quick { grid-column: 1 / -1; }
.game.wide .ctrl .tools .btn.small { padding: 0 4px; font-size: 12px; }
/* 각도: 단조 슬라이더, 트랙 중앙(수직) 기준 좌우로 채움 */
.aim .big.ang { font-size: 16px; white-space: nowrap; min-width: 0; }
.game .aim, .game .ctrl .aim { grid-template-columns: auto minmax(64px, auto) minmax(0, 1fr); }
input.angle-range::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--line2) var(--lo, 50%), var(--accent) var(--lo, 50%), var(--accent) var(--hi, 50%), var(--line2) var(--hi, 50%)); }
input.angle-range::-moz-range-track { background: linear-gradient(to right, var(--line2) var(--lo, 50%), var(--accent) var(--lo, 50%), var(--accent) var(--hi, 50%), var(--line2) var(--hi, 50%)); }
.aim .big.clamped { animation: clampFlash .6s ease-out; }
@keyframes clampFlash { 0% { color: var(--warn); transform: scale(1.15); } 100% { color: inherit; transform: none; } }
@media (prefers-reduced-motion: reduce) { .aim .big.clamped { animation: none; } }
/* 아이템 아이콘: 분류 강조색 테두리 + 우하단 분류 기호(색만으로 구분하지 않음) */
.iic { --sz: 32px; --acc: var(--line2); position: relative; display: inline-grid; place-items: center; flex: none; width: var(--sz); height: var(--sz); border-radius: calc(var(--sz) * .2); border: 1.5px solid var(--acc); background: #161B27; overflow: visible; }
.iic img { width: calc(var(--sz) - 4px); height: calc(var(--sz) - 4px); display: block; }
.iic-g { position: absolute; right: -3px; bottom: -3px; width: max(10px, calc(var(--sz) * .3)); height: max(10px, calc(var(--sz) * .3)); color: var(--acc); background: #161B27; border-radius: 50%; padding: 1px; display: grid; place-items: center; }
.iic-g svg { width: 100%; height: 100%; display: block; }
.item-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.item-head .n { min-width: 0; overflow-wrap: anywhere; }
.mine-nm { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tinfo { display: inline-flex; align-items: center; gap: 6px; }
.wc-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wc-head .n { min-width: 0; overflow-wrap: anywhere; }
.weapon-chip .wi { display: inline-flex; }
.weapon-chip .wn { white-space: normal; overflow-wrap: anywhere; line-height: 1.2; text-align: left; overflow: visible; }
.qi { gap: 4px; }
.qi .iic { --sz: 24px; }
.qi .iic-g { display: none; }
.game.wide .ctrl .quick { grid-auto-rows: 34px; }
.game.wide .ctrl .qi { justify-content: flex-start; padding: 0 3px; gap: 3px; }
.game.wide .ctrl .qi .ql { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.game.wide .ctrl .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stage canvas:focus { outline: none; }
@media (max-width: 599px) {
  .range-row { gap: 4px; min-width: 0; }
  .range-row input[type=range] { min-width: 40px; }
  .range-row input.num { width: 64px; flex: none; }
  .range-row .step { width: 38px; height: 38px; }
  .game .hud { flex-wrap: nowrap; gap: 6px; padding-left: 8px; padding-right: 6px; }
  .game .hud .who .name { max-width: 84px; }
  .game .hud .round { font-size: 11px; }
  .game .hud .wind { min-width: 0; gap: 3px; }
  .game .hud .wind svg { width: 32px; }
  .game .hud .timer { min-width: 52px; }
  .game .hud .icon-btn { flex: none; }
}
/* 세로 모바일: 남는 아래 공간은 플레이어 목록으로 채움 */
.game.portrait { grid-template-rows: auto auto auto minmax(0, 1fr); grid-template-areas: "hud" "stage" "ctrl" "side"; }
.game.portrait .side { display: block; position: static; width: auto; max-height: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; overflow: auto; min-height: 0; background: rgba(18,23,37,.82); }
.game.portrait .pl-toggle { display: none; }
.game.portrait .ctrl { overflow: visible; }
/* 게임 채팅: 캔버스 바로 아래(wide 제외, wide 는 아래 우 패널 규칙). 로그는 고정 4줄·스크롤, 좁은 가로는 입력 한 줄로 접힘 */
.game .gchat { grid-area: chat; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: rgba(18,23,37,.82); border-top: 1px solid var(--line); }
.game .gchat .chat-log { flex: none; min-height: 0; height: calc(var(--chat-lines, 4) * 18px + 8px); padding: 4px 10px; gap: 0; overscroll-behavior: contain; border-bottom: 1px solid var(--line); }
.game .gchat .chat-line { font-size: 13px; line-height: 18px; }
.game .gchat .chat-form { padding: 3px 6px; gap: 4px; border-top: 0; align-items: center; min-width: 0; }
.game .gchat .chat-form input { flex: 1; min-height: 32px; min-width: 0; padding: 0 8px; font-size: 14px; }
.game .gchat .chat-form .btn { min-height: 32px; padding: 0 10px; font-size: 13px; flex: none; }
.game .gchat .chat-fold { width: 32px; height: 32px; font-size: 14px; flex: none; }
.game .gchat .chat-peek { display: none; }
.game .gchat.folded .chat-log { display: none; }
.game .gchat.folded .chat-peek { display: block; flex: 0 1 auto; max-width: 45%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text2); padding-left: 4px; }
@media (pointer: coarse) { .game .gchat .chat-form input { font-size: 16px; } } /* iOS 포커스 확대 방지 */
.game { grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: "hud" "stage" "chat" "ctrl"; }
/* wide: 채팅은 우 패널(.side) 안 플레이어 목록 아래 남는 높이를 채움, 입력줄은 패널 하단. 캔버스 높이에 영향 없음 */
.game.wide { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "hud stage side" "ctrl stage side"; }
.game.wide .side { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.game.wide .side .pl-fold { flex: 0 1 auto; min-height: 0; overflow: auto; }
.game.wide .side .gchat { flex: 1 1 0; min-height: 140px; margin: 8px -8px 0; background: transparent; padding-bottom: env(safe-area-inset-bottom); }
.game.wide .side .gchat .chat-log { flex: 1 1 0; height: auto; }
.game.wide .side .chat-fold { display: none; }
.game.portrait { grid-template-rows: auto minmax(0, max-content) auto auto minmax(0, 1fr); grid-template-areas: "hud" "stage" "chat" "ctrl" "side"; }
/* 보이는 높이가 짧을 때(인앱 하단 툴바 등) 캔버스 행이 먼저 줄어 채팅·조작을 덮지 않게: 행 높이 안에서 렌더러가 비율 유지로 맞춤 */
.game.portrait .stage { max-height: 100%; }
.game.portrait .gchat { border-bottom: 1px solid var(--line); min-height: auto; } /* 보이는 높이가 줄면(키보드) 채팅 행은 줄지 않고 캔버스 행이 먼저 줄어 입력줄이 조작부에 덮이지 않게 */
/* 좁은 가로(높이 부족): 채팅 한 줄만큼 조작부를 줄여 캔버스 크기 유지 */
@media (max-height: 500px) {
  .game:not(.wide):not(.portrait) .stage { min-height: 0; }
  .game:not(.wide):not(.portrait) .gchat { --chat-lines: 3; }
  .game:not(.wide):not(.portrait) .gchat .chat-form { padding: 2px 6px; }
  .game:not(.wide):not(.portrait) .gchat .chat-form input, .game:not(.wide):not(.portrait) .gchat .chat-form .btn, .game:not(.wide):not(.portrait) .gchat .chat-fold { min-height: 30px; height: 30px; }
  .game:not(.wide):not(.portrait) .ctrl { gap: 4px 10px; padding-top: 4px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .game:not(.wide):not(.portrait) .ctrl .qi .ql { display: none; }
}

/* ---------- 게임 화면 입력 보호: 텍스트·이미지 선택, 길게 누름 메뉴, 더블탭·핀치 확대 차단 ---------- */
/* 로비·대기실은 그대로(선택·확대 허용). 채팅 입력·채팅 기록은 선택·복사 가능 유지 */
body[data-view="game"] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
/* touch-action 은 스크롤 컨테이너에서 끊기므로 모든 요소에 적용. :where 로 특이도 0 → .stage·canvas 의 none 이 우선 */
html:has(body[data-view="game"]), :where(body[data-view="game"]), :where(body[data-view="game"]) * { touch-action: pan-x pan-y; }
body[data-view="game"] .stage, body[data-view="game"] canvas { touch-action: none; }
body[data-view="game"] img, body[data-view="game"] canvas, body[data-view="game"] svg { -webkit-user-drag: none; }
body[data-view="game"] input:not([type=range]):not([type=checkbox]):not([type=radio]),
body[data-view="game"] textarea,
body[data-view="game"] .chat-log { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
