:root {
  --ui: 1;
  --bg: #110e0b; --panel: #1c1712; --panel2: #262019; --line: #3d3226; --text: #f1e8d8; --muted: #a8998a; --gold: #e2b35a;
  --left: #2f8cff; --right: #ff5a2a; --accent: #f0c46a; --good: #6fdc6f; --bad: #ff8a7a;
  --r: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: calc(14px * var(--ui))/1.4 "Pretendard", "Segoe UI", system-ui, sans-serif; }
body { display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; height: 100dvh; overscroll-behavior: none; }
body.board-hidden .board { display: none; }
button, select, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 0.4em 0.8em; }
button { cursor: pointer; touch-action: manipulation; user-select: none; }
input { background: #0d0b09; }
button:hover:not(:disabled), select:hover { border-color: #7a6240; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: #d4a24c; color: #1a1307; border-color: #d4a24c; font-weight: 600; } /* 놋쇠 강조색 하나 (unslop 정리 2026-11-08) */
button.primary:hover:not(:disabled) { background: #dfae58; border-color: #dfae58; }
button.danger { background: linear-gradient(#7a2a1c, #4a160e); border-color: #b0442a; color: #ffd8c8; }
button.big { padding: 0.8em; font-size: 1.1em; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
[hidden] { display: none !important; }

/* 화면 전환·모드 */
body[data-screen="menu"] .hud, body[data-screen="menu"] .board { display: none; }
body:not([data-screen="menu"]) #menu { display: none; }
body[data-mode="match"] [data-only="practice"], body[data-mode="practice"] [data-only="match"] { display: none !important; }
body.online .local-only { display: none; }

/* HUD */
.hud { display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 12px; padding: 6px 12px;
  background: linear-gradient(#221b14, #15110d); border-bottom: 1px solid #5a4630; box-shadow: 0 2px 0 #0006; min-width: 0; }
.hud-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-side.foe { justify-content: flex-end; text-align: right; }
.hud-info { min-width: 0; }
.team-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--left); box-shadow: 0 0 10px var(--left); flex: none; }
.team-dot.foe { background: var(--right); box-shadow: 0 0 10px var(--right); }
body.side-right #me-dot { background: var(--right); box-shadow: 0 0 10px var(--right); }
body.side-right #foe-dot { background: var(--left); box-shadow: 0 0 10px var(--left); }
.hud-label { font-size: 0.8em; color: var(--muted); letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-small { font-size: 0.85em; }
.coin { color: var(--gold); }
#credits { color: #ffe3a0; font-size: 1.15em; }
.hud-center { text-align: center; min-width: 0; }
.clock { font-family: Georgia, "Times New Roman", serif; color: #f6e2b0; text-shadow: 0 1px 0 #000, 0 0 12px #e2b35a44; font-size: 1.5em; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; line-height: 1.1; }
.phase-line { max-width: 34vw; }
.hud-tools { display: flex; gap: 6px; align-items: center; }
.local-only { display: contents; }
.icon-btn { min-width: 2.4em; }
.structs { display: flex; gap: 4px; align-items: flex-end; flex: none; }
.hud-side.foe .structs { flex-direction: row-reverse; }
.sbar { width: calc(42px * var(--ui)); height: 9px; background: #0009; border: 1px solid #5a4630; border-radius: 3px; overflow: hidden; position: relative; }
.sbar.core { width: calc(58px * var(--ui)); height: 12px; }
.sbar i { position: absolute; inset: 0 auto 0 0; background: var(--left); transition: width 0.2s; }
.hud-side.foe .sbar i { background: var(--right); }
body.side-right .hud-side.me .sbar i { background: var(--right); }
body.side-right .hud-side.foe .sbar i { background: var(--left); }
.sbar.locked i { background: #8a8478 !important; }
.sbar.down { opacity: 0.35; border-style: dashed; }
.emergency { display: flex; flex-direction: column; align-items: center; line-height: 1.1; padding: 0.25em 0.6em; border-color: #a0402a;
  background: linear-gradient(#5a1e14, #2e0f0a); color: #ffd2b0; font-weight: 700; position: relative; overflow: hidden; touch-action: none; -webkit-user-select: none; }
.emergency span { font-size: 0.7em; }
.emergency .ic, .pings .ic { width: 18px; height: 18px; display: block; margin: 0 auto; }
.emergency .ic-img, .pings .ic-img { width: 32px; height: 32px; display: block; margin: -4px auto -2px; image-rendering: pixelated; } /* 도트 폭탄 (assets/ui/bomb.png, 정수배) */
.emergency.holding::after { content: ""; position: absolute; inset: 0; background: #ff8a5a55; transform-origin: left; animation: hold 0.5s linear forwards; }
.emergency.spent { filter: grayscale(1); }
@keyframes hold { from { transform: scaleX(0); } to { transform: scaleX(1); } }

main { position: relative; min-height: 0; }
#view { width: 100%; height: 100%; display: block; touch-action: none; }
main::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, #000a 100%); }

.card-panel { position: absolute; right: 12px; top: 12px; width: calc(250px * var(--ui)); max-width: calc(100% - 24px); background: #1a140fee; border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px; z-index: 2; backdrop-filter: blur(4px); }
.close-x { position: absolute; top: 6px; right: 6px; border: none; background: transparent; font-size: 1.3em; padding: 0 0.4em; color: var(--muted); }
.sel-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; padding-right: 20px; }
.sel-head img { width: 56px; height: 56px; background: #0006; border-radius: 8px; }
#sel-name { font-weight: 700; }
#sel-stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-size: 0.9em; font-variant-numeric: tabular-nums; }
#sel-stats dt { color: var(--muted); }
#sel-stats dd { margin: 0; }

.result { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto;
  background: #1a140ff4; border: 1px solid #6a5232; border-radius: 14px; padding: 18px 22px; text-align: center; box-shadow: 0 20px 60px #000a; }
.result-title { font-family: Georgia, "Times New Roman", serif; font-size: 2.2em; font-weight: 800; letter-spacing: 0.08em; text-shadow: 0 2px 0 #000; }
.result-title.win { color: var(--accent); } .result-title.lose { color: var(--bad); }
.result-sub { color: var(--muted); margin-bottom: 12px; }
.result-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; text-align: left; }
.result-cols h3 { font-size: 0.9em; color: var(--muted); margin: 0 0 6px; }
.result-cols ol { margin: 0; padding-left: 1.2em; font-variant-numeric: tabular-nums; font-size: 0.9em; }
.result-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.toast { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: #000c; padding: 6px 14px; border-radius: 999px; max-width: calc(100% - 24px);
  text-align: center; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 4; }
.toast.show { opacity: 1; }

/* 편성판 */
.board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); gap: 14px; padding: 10px 14px calc(10px + var(--safe-b));
  background: linear-gradient(#1e1813, #120f0c); border-top: 1px solid #5a4630; max-height: 46vh; min-height: 0; }
.board.locked .board-grid { opacity: 0.55; pointer-events: none; }
.board-grid { display: flex; flex-direction: column; gap: 6px; min-height: 0; min-width: 0; }
.grid-head { display: flex; justify-content: space-between; font-weight: 600; }
.grid { display: grid; grid-template-columns: 12px repeat(var(--cols, 8), minmax(0, 1fr)); gap: 4px; min-height: 0;
  width: min(100%, calc((46vh - 90px) * var(--cols, 8) / var(--rows, 8) + 28px)); margin: 0 auto; } /* 칸이 정사각형이라 줄 수만큼 높이에 맞춘다 */
/* 빈 칸은 조용히, 유닛이 놓인 칸만 또렷하게 (unslop 정리 2026-11-08) */
.cell { position: relative; aspect-ratio: 1; border-radius: 6px; border: 1px solid rgba(239, 233, 222, 0.06); background: #15130f; padding: 0; overflow: hidden; min-width: 0;
  transition: background-color 120ms ease-out, border-color 120ms ease-out; }
.cell:not(.filled):hover { background: #1e1b16; border-color: rgba(239, 233, 222, 0.14); }
.cell.front { border-color: rgba(212, 162, 76, 0.22); background: #19160f; }
.cell.filled { border-color: rgba(239, 233, 222, 0.16); background: #25211b; }
/* 고유 표시: 군사 지도처럼 편성판 가장자리 좌표 눈금 */
.grid-tick { display: grid; place-items: center; min-width: 0; font: 500 10px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; color: #8a847a; font-variant-numeric: tabular-nums; }
.grid-tick.col { align-self: end; padding-bottom: 2px; }
.cell img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cell .c-cost { position: absolute; bottom: 1px; right: 3px; font-size: 0.66em; color: var(--accent); text-shadow: 0 1px 2px #000; }
.cell .c-new { position: absolute; top: 2px; right: 2px; font-size: 0.55em; font-weight: 800; color: #1a1205; background: #ffd27a; border-radius: 3px; padding: 0 3px; }
.cell.cursor { outline: 2px solid var(--accent); outline-offset: 1px; }
.cell.fresh { box-shadow: inset 0 0 0 2px #ffd27a88; }
.cell.moving { outline: 2px dashed var(--accent); outline-offset: -3px; }
.cell.target { border-color: #8a7040; }
.grid-help { font-size: 0.8em; text-align: center; }

.board-side { display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow-y: auto; }
.meters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.meter { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.meter > span:first-child { font-size: 0.75em; color: var(--muted); }
.meter b { font-size: 1.1em; }
.meter b.over { color: var(--bad); }
.research { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
/* 업그레이드 버튼: 위 줄 이름, 아래 줄 왼쪽 현재 단계·오른쪽 다음 단계와 비용 (글자 밀림 수정, 2026-11-09) */
.research-btn { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 8px; row-gap: 2px; padding: 6px 8px; font-size: 0.85em; text-align: left; line-height: 1.25; }
.research-btn .r-name { grid-column: 1 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.research-btn .r-lv { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.research-btn .r-next { color: var(--gold); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.research-prog { grid-column: 1 / -1; position: relative; display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-size: 0.8em; background: #0006; border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; min-height: 2em; overflow: hidden; }
.research-prog i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--gold); }
.research-cancel { font-size: 0.85em; padding: 0.1em 0.5em; }
.tabs { display: flex; gap: 4px; }
.tabs button { flex: 1; padding: 0.35em 0.3em; font-size: 0.85em; }
.tabs button[aria-selected="true"] { background: linear-gradient(#3a2e20, #2a2118); border-color: var(--accent); color: var(--accent); }
.tabs .crest { margin-right: 0.25em; opacity: 0.85; }
body[data-mode="match"]:not(.setup) .tabs { }
.side-actions { display: flex; gap: 6px; }
.side-actions button { flex: 1; }

/* 칸 선택 시트 */
dialog { background: #1c1712; color: var(--text); border: 1px solid #6a5232; border-radius: 12px; padding: 16px; box-shadow: 0 20px 60px #000c; }
dialog::backdrop { background: #0008; }
.sheet { width: min(760px, calc(100vw - 24px)); max-height: min(82vh, 760px); padding: 0; overflow: hidden; }
.sheet[open] { display: flex; flex-direction: column; }
.sheet-head { position: relative; display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
.sheet-title { font-weight: 800; font-size: 1.15em; }
#picker-body { overflow-y: auto; padding: 10px 14px 14px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(108px * var(--ui)), 1fr)); gap: 8px; }
.pick-card { position: relative; display: flex; flex-direction: column; align-items: center; padding: 4px 4px 6px; border-radius: 9px; background: var(--panel2); border: 1px solid var(--line); text-align: center; }
.pick-card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: radial-gradient(#4a5a3a, #1e2418 72%); border-radius: 6px; }
.pick-card .name { font-size: 0.86em; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pick-card .meta { font-size: 0.72em; color: var(--muted); }
.pick-card .cost { position: absolute; top: 6px; left: 6px; background: #000b; color: var(--accent); font-weight: 700; font-size: 0.78em; padding: 1px 6px; border-radius: 6px; }
.pick-card .tier { position: absolute; top: 6px; right: 6px; background: #000b; font-size: 0.7em; padding: 1px 5px; border-radius: 6px; color: var(--muted); }
.pick-card .why { position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); background: #000d; color: #ffd27a; font-size: 0.72em; font-weight: 700; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.pick-card.blocked { opacity: 0.5; }
.pick-card:not(.blocked):hover { border-color: var(--accent); }
.unit-detail { display: flex; gap: 12px; align-items: flex-start; }
.unit-detail img { width: 96px; height: 96px; background: radial-gradient(#4a5a3a, #1e2418 72%); border-radius: 8px; flex: none; }
.unit-detail > div { display: flex; flex-direction: column; gap: 4px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.sheet-actions button { flex: 1; min-width: 7em; padding: 0.6em; }

/* 메인 화면 */
.screen { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; overflow-y: auto; padding: 16px;
  background: radial-gradient(ellipse at 50% 35%, #0000 0%, #000a 70%), linear-gradient(#0006, #000c); }
.menu-box { width: min(460px, 100%); display: flex; flex-direction: column; gap: 14px; }
.logo { text-align: center; }
.logo h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: calc(3.2em); letter-spacing: 0.14em; color: #f6e2b0;
  text-shadow: 0 3px 0 #000, 0 0 30px #e2b35a66; }
.logo-crests { display: flex; justify-content: center; gap: 18px; font-size: 1.6em; color: var(--gold); text-shadow: 0 0 12px #e2b35a88; }
.logo-sub { color: var(--muted); letter-spacing: 0.1em; }
.menu-page { display: flex; flex-direction: column; gap: 10px; background: #15110dd8; border: 1px solid #5a4630; border-radius: 14px; padding: 16px; backdrop-filter: blur(6px); }
.menu-page h2 { margin: 0 0 4px; font-family: Georgia, serif; color: #f6e2b0; letter-spacing: 0.06em; }
.menu-btn { padding: 0.75em 1em; font-size: 1.05em; text-align: left; }
.menu-btn.primary { text-align: center; }
.menu-row { display: flex; gap: 8px; }
.menu-row > * { flex: 1; }
.menu-row .menu-btn { text-align: center; }
.join-row input { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-weight: 700; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85em; color: var(--muted); }
.field select, .field input { color: var(--text); font-size: 1.05em; }
.field-label { font-size: 0.85em; color: var(--muted); margin-bottom: -4px; }
.faction-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 6px; }
.fpick { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 0.5em 0.3em; }
.fpick .crest { font-size: 1.5em; color: var(--muted); }
.fpick small { font-size: 0.7em; color: var(--muted); }
.fpick.on { border-color: var(--accent); background: #2f2a22; }
.room-code { text-align: center; color: var(--muted); }
.room-code b { display: block; font-size: 2.4em; letter-spacing: 0.3em; color: #ffe3a0; font-family: Georgia, serif; }
.lobby-players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lobby-players li { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.lobby-players li .state { margin-left: auto; font-size: 0.85em; color: var(--muted); }
.lobby-players li.ready { border-color: #4a7a3a; }
.lobby-players li.ready .state { color: var(--good); }
.lobby-players li.empty { color: var(--muted); border-style: dashed; }
.howto ol { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }

#settings { width: min(420px, calc(100vw - 24px)); }
#settings form { display: flex; flex-direction: column; gap: 10px; }
#settings h2 { margin: 0; }
.check { display: flex; gap: 8px; align-items: center; }

/* ---- 모바일·작은 화면 ---- */
@media (max-width: 820px), (max-height: 560px) {
  :root { font-size: 13px; }
  .hud { grid-template-columns: 1fr auto 1fr; gap: 6px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); }
  .hud-tools { grid-column: 1 / -1; justify-content: flex-end; order: 4; gap: 4px; }
  .hud-small, .hide-sm, .hud-side .team-dot, .hud-side .hud-label { display: none; }
  .clock { font-size: 1.2em; }
  .phase-line { max-width: 46vw; font-size: 0.72em; }
  .sbar { width: 26px; height: 7px; }
  .sbar.core { width: 36px; height: 9px; }
  .hud-side { gap: 6px; }
  .board { grid-template-columns: 1fr; gap: 8px; padding: 8px 8px calc(8px + var(--safe-b)); max-height: 58vh; overflow-y: auto; }
  .grid { width: 100%; }
  .board-side { overflow: visible; }
  .research { grid-template-columns: repeat(4, 1fr); }
  .research-btn { padding: 4px 6px; }
  .sheet { width: 100vw; max-width: 100vw; max-height: 86dvh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
  .pick-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
  .unit-detail img { width: 72px; height: 72px; }
  .card-panel { top: auto; bottom: 8px; right: 8px; left: 8px; width: auto; }
  .result-cols { grid-template-columns: 1fr; gap: 8px; }
  .menu-btn { padding: 0.7em 0.9em; }
  .logo h1 { font-size: 2.4em; }
}
/* 가로 폰: 세로가 매우 낮으면 HUD 한 줄, 편성판은 오른쪽 패널을 접어 격자 위주 */
@media (max-height: 460px) and (orientation: landscape) {
  .hud { grid-template-columns: 1fr auto 1fr auto; }
  .hud-tools { grid-column: auto; order: 0; }
  .board { grid-template-columns: minmax(0, 1fr) minmax(170px, 34%); max-height: 62vh; }
  .grid { width: min(100%, calc((62vh - 70px) * var(--cols, 8) / var(--rows, 8) + 28px)); }
  .meters { grid-template-columns: repeat(3, 1fr); }
  .research { grid-template-columns: 1fr 1fr; }
  .logo h1 { font-size: 1.8em; }
  .menu-box { gap: 8px; }
}
/* 가로 폰 (사용자 지시 2026-11-08): 한 손 조작 — 편성판을 오른쪽 세로 패널로 붙여 엄지가 닿게 하고, 왼쪽은 전장.
   편성판 격자는 패널 높이에 맞춰 최대한 크게, 연구·출격은 그 오른쪽 좁은 열에 세로로 */
@media (max-height: 500px) and (orientation: landscape) {
  body { grid-template-columns: minmax(0, 1fr) min(58vw, 520px); grid-template-rows: auto minmax(0, 1fr); }
  body.board-hidden { grid-template-columns: minmax(0, 1fr) 0; }
  body[data-screen="menu"] { grid-template-columns: minmax(0, 1fr) 0; } /* 메인 화면에서는 전장이 화면 전체에 비치게 */
  .hud { grid-column: 1 / -1; }
  main { grid-column: 1; grid-row: 2; }
  .board { grid-column: 2; grid-row: 2; max-height: none; height: 100%; overflow: hidden; border-top: 0; border-left: 1px solid #5a4630;
    grid-template-columns: minmax(0, 1fr) 104px; gap: 6px; padding: 4px 6px calc(4px + var(--safe-b)) 6px; }
  .board-grid { gap: 3px; justify-content: center; }
  .grid-head { font-size: 0.8em; }
  .grid { gap: 3px; width: min(100%, calc((100dvh - 96px) * var(--cols, 8) / var(--rows, 8) + 12px)); }
  .cell { border-radius: 5px; }
  .grid-help { display: none; }
  .board-side { overflow-y: auto; gap: 5px; }
  .research { grid-template-columns: 1fr; gap: 4px; }
  .research-btn { padding: 4px 6px; min-height: 40px; font-size: 0.78em; }
  .research-prog { display: flex; font-size: 0.72em; }
  #deploy { margin-top: auto; min-height: 48px; font-size: 0.95em; padding: 0.5em 0.3em; letter-spacing: 0; }
  .pings button span { display: none; }
}
/* 출격·준비 버튼은 옆 패널이 스크롤돼도 항상 보이게 */
#deploy { position: sticky; bottom: 0; z-index: 1; box-shadow: 0 -6px 12px #120f0c; }

.volumes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.volumes input[type="range"] { padding: 0; accent-color: var(--gold); }
.result { width: min(860px, calc(100% - 24px)); }
.stats-wrap { overflow-x: auto; }
table.stats { width: 100%; border-collapse: collapse; font-size: 0.82em; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { padding: 3px 5px; text-align: right; white-space: nowrap; border-bottom: 1px solid #3d322666; }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--muted); font-weight: 600; }
table.stats tfoot td { font-weight: 700; color: var(--accent); border-top: 1px solid var(--line); }
table.stats small { color: #9ad06a; }
.hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 3; width: min(560px, calc(100% - 24px));
  display: flex; gap: 10px; align-items: center; background: #2a2016f2; border: 1px solid var(--gold); border-radius: 10px; padding: 8px 10px 8px 14px;
  box-shadow: 0 8px 24px #000a; font-size: 0.92em; }
.hint span { flex: 1; }
.hint button { flex: none; padding: 0.35em 0.8em; }
.small-btn { font-size: 0.75em; padding: 0.1em 0.5em; margin-left: auto; }
.format-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ally { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 0.8em; background: var(--panel); border: 1px solid #3a5a8a; border-radius: 8px; padding: 5px 8px; }
body.side-right .ally { border-color: #8a4a3a; }
.ally b { color: var(--accent); }
table.stats small.owner { color: var(--muted); font-size: 0.8em; border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; }

.lesson { position: absolute; left: 12px; top: 12px; z-index: 3; width: min(380px, calc(100% - 24px)); background: #1c1712ee; border: 1px solid var(--gold);
  border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 8px 24px #000a; }
.lesson .l-head { display: flex; justify-content: space-between; align-items: center; }
.lesson .l-title { color: var(--accent); }
.lesson .l-goal { font-weight: 600; }
.lesson .l-progress { color: #9ad06a; font-variant-numeric: tabular-nums; font-size: 0.9em; }
.lesson .l-brief { font-size: 0.85em; }
.lesson .l-fold { padding: 0 0.4em; min-width: 0; }
.lesson.folded .l-brief, .lesson.folded .l-goal { display: none; }
.lesson-list { display: flex; flex-direction: column; gap: 6px; }
.lesson-list .menu-btn small { font-size: 0.8em; }

.pings { display: none; grid-template-columns: repeat(4, 1fr); gap: 4px; }
body.duo .pings { display: grid; }
.pings button { display: flex; flex-direction: column; align-items: center; padding: 0.25em; font-size: 0.85em; line-height: 1.1; }
.pings button span { font-size: 0.75em; color: var(--muted); }
.ping-flash { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(0.8); font-size: 1.6em; font-weight: 800; color: #ffe3a0;
  text-shadow: 0 2px 0 #000, 0 0 18px #e2b35a; opacity: 0; pointer-events: none; z-index: 4; }
.ping-flash.show { animation: pingflash 1.6s ease-out; }
@keyframes pingflash { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }
.lobby-players li.empty { cursor: pointer; }

.pick-tier + .pick-tier { margin-top: 10px; }
.pick-tier h3 { margin: 0 0 6px; font-size: 0.85em; color: var(--accent); letter-spacing: 0.04em; }

/* 도트 그래픽: 확대할 때 번지지 않게 */
#view, .cell img, .pick-card img, .unit-detail img, .sel-head img { image-rendering: pixelated; }

/* 사용자 지정 방: 제목을 보고 입장, 방장이 준비 상태를 확인하고 시작. */
body:has(#menu-online:not([hidden])) .menu-box { width: min(660px, 100%); }
.room-browser { border: 1px solid #66533b; border-radius: 6px; overflow: hidden; background: #0d1318e8; }
.room-browser-head, .room-entry { display: grid; grid-template-columns: minmax(0, 1fr) 62px 52px; gap: 10px; align-items: center; }
.room-browser-head { padding: 10px 12px; background: #28323b; color: #c2cccd; font-size: .85em; }
.room-list { min-height: 150px; max-height: 280px; overflow-y: auto; }
.room-entry { width: 100%; text-align: left; padding: 12px; border: 0; border-bottom: 1px solid #334047; border-radius: 0; background: transparent; color: #ecdfbb; cursor: pointer; }
.room-entry:hover:not(:disabled), .room-entry:focus-visible { background: #304551; }
.room-entry > span:first-child { min-width: 0; }
.room-entry b { display: block; overflow-wrap: anywhere; }
.room-entry small { display: block; margin-top: 4px; color: #96a7ae; }
.room-entry:disabled { opacity: .5; cursor: default; }
.room-empty { padding: 28px 12px; text-align: center; color: #9aa5aa; font-size: .9em; }
.room-create { padding: 12px; border: 1px solid #a28a50; border-radius: 6px; background: #25251d; }
.room-create .menu-row { margin-top: 10px; }
.room-title { font-size: 1.35em; color: #ffe3a0; text-align: center; overflow-wrap: anywhere; padding: 8px; }
@media (max-width: 480px) { .room-browser-head, .room-entry { grid-template-columns: minmax(0,1fr) 42px 42px; gap: 6px; padding: 10px 8px; } }

.sudden-banner { position: fixed; z-index: 25; top: 86px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); box-sizing: border-box; padding: 12px 18px; border: 1px solid #efae4c; border-radius: 8px; background: #28170df0; color: #ffe1a0; text-align: center; font-weight: 700; pointer-events: none; box-shadow: 0 4px 20px #0009; }

/* 로딩 화면 (2026-11-09): 타이틀과 진행 막대 */
.boot { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: #161513; transition: opacity 300ms ease-out; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-logo { width: 380px; max-width: 80vw; height: auto; image-rendering: pixelated; }
.boot-bar { width: min(320px, 70vw); height: 8px; border-radius: 4px; background: #262421; border: 1px solid rgba(239, 233, 222, 0.08); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 2%; background: #d4a24c; transition: width 160ms ease-out; }
.boot-text { color: #aaa398; font-size: 13px; }

/* 유닛 설명 창 (2026-11-09): 조용한 패널, 놋쇠는 구매 불가 안내에만 */
.unit-tip { position: fixed; z-index: 30; width: min(300px, calc(100vw - 16px)); padding: 12px; border-radius: 12px; background: #1c1a18; border: 1px solid rgba(239, 233, 222, 0.14);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5); color: #efe9de; font-size: 13px; line-height: 1.4; pointer-events: none; margin: 0; }
.unit-tip.top { top: 8px; left: 50%; transform: translateX(-50%); }
.unit-tip.bottom { bottom: 8px; left: 50%; transform: translateX(-50%); }
.unit-tip.left { left: 8px; top: 8px; max-height: calc(100dvh - 16px); overflow: hidden; }
.unit-tip.right { right: 8px; top: 8px; max-height: calc(100dvh - 16px); overflow: hidden; }
.unit-tip .ut-head { display: flex; gap: 10px; align-items: center; }
.unit-tip .ut-head img { width: 44px; height: 44px; object-fit: contain; image-rendering: pixelated; background: #262421; border-radius: 8px; }
.unit-tip .ut-head b { display: block; font-size: 15px; font-weight: 600; }
.unit-tip .ut-head span { color: #aaa398; font-size: 12px; }
.unit-tip .ut-desc { margin: 8px 0; color: #d8d0c2; }
.unit-tip .ut-stats { display: grid; gap: 2px; margin: 0; padding: 8px 0; border-top: 1px solid rgba(239, 233, 222, 0.08); border-bottom: 1px solid rgba(239, 233, 222, 0.08); }
.unit-tip .ut-row { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; }
.unit-tip dt { color: #8a847a; }
.unit-tip dd { margin: 0; font-variant-numeric: tabular-nums; }
.unit-tip .ut-weak { margin: 8px 0 0; color: #aaa398; font-size: 12px; }
.unit-tip .ut-block { margin: 6px 0 0; color: #d4a24c; font-size: 12px; }
.pick-card { -webkit-touch-callout: none; user-select: none; }

/* 진영 문장은 이모지 그림이 아니라 글자 문양으로, 글자색을 따른다 */
.crest { font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", serif; font-variant-emoji: text; }
/* unslop by @heydamir, CC BY 4.0 */

/* 편성 카드 그림: 모바일에서 꾹 누를 때 '이미지 저장' 메뉴·끌기가 뜨지 않게. 누르기는 버튼이 받는다 (사용자 지시 2026-11-09) */
.pick-card img, .cell img { -webkit-touch-callout: none; -webkit-user-drag: none; user-select: none; -webkit-user-select: none; pointer-events: none; }
.pick-card { -webkit-user-select: none; }

/* 결과표 합산/개별 전환 버튼: 표 오른쪽 위 */
.result-tools { display: flex; justify-content: flex-end; margin: -4px 0 6px; }
.result-tools .small-btn { margin-left: 0; font-size: 0.8em; padding: 0.3em 0.8em; min-height: 32px; }

/* 서든데스 재정비 끝 5초 카운트다운: 화면 가운데 크게 (사용자 지시 2026-11-09) */
.sd-count { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none;
  font: 900 min(34vh, 220px)/1 Georgia, "Times New Roman", serif; color: #ffe3a0; font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 4px #2a0d06; paint-order: stroke fill; text-shadow: 0 6px 0 #000a, 0 0 40px #ff5a2aaa; }
.sd-count.tick { animation: sdcount 1s ease-out; }
@keyframes sdcount { 0% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .sd-count.tick { animation: none; } }
