/* ── MT 시뮬레이터: 포차 네온 테마 ─────────────────────────────── */
/* overscroll-behavior: 스크롤이 브라우저로 새어나가 '당겨서 새로고침'이 걸리는 걸 막는다
   (새로고침되면 술자리에서 강제로 튕겨나간다). 안쪽 스크롤 영역은 contain, 루트는 none. */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent;
    overscroll-behavior: contain; }
:root {
  --bg: #0b0710; --panel: #171022cc; --line: #3a2b52;
  --amber: #ffb347; --pink: #ff5c8a; --teal: #3ee6c8; --txt: #f4eefc;
  --dim: #a898c4; --danger: #ff4d5e;
  --jx: 0px; --jy: 0px;  /* 취기 버튼 지터 */
}
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--txt);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  user-select: none; touch-action: manipulation;
}
#c3d { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui-root { position: fixed; inset: 0; pointer-events: none; }
#ui-root > * { pointer-events: auto; }

/* 취기 시각효과 (ui-root 에 클래스 부여) */
#ui-root.drunk1 { filter: blur(0.6px); }
#ui-root.drunk2 { filter: blur(1.3px); animation: sway1 5s ease-in-out infinite; }
#ui-root.drunk3 { filter: blur(2.2px) saturate(1.25); animation: sway2 3.4s ease-in-out infinite; }
@keyframes sway1 { 0%,100% { transform: rotate(0deg) } 50% { transform: rotate(.6deg) translateX(3px) } }
@keyframes sway2 { 0%,100% { transform: rotate(-.8deg) translateX(-5px) } 50% { transform: rotate(.9deg) translateX(6px) } }
#double-vision { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: transparent;
  backdrop-filter: none; transition: opacity 1s; }
#double-vision.on { opacity: .55; box-shadow: inset 0 0 140px 40px rgba(255, 92, 138, .18); }

/* ── 화면 전환 ── */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }
/* flex 중앙정렬 + 넘치면 스크롤 (align-items:center 는 위가 잘리므로 margin:auto 방식) */
#screen-lobby.active, #screen-room.active {
  display: flex; overflow-y: auto; padding: 10px;
  background: radial-gradient(80% 60% at 50% 0%, #241536 0%, var(--bg) 70%);
}

/* ── 로비: 모바일 = 1컬럼(기본), 웹 = 2컬럼(@760px+) ── */
.lobby-box { width: min(480px, 96vw); padding: 18px 16px 22px; margin: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: blur(8px); text-align: center; }
.lobby-cols { display: grid; grid-template-columns: 1fr; gap: 0 28px; text-align: left; }
.logo { font-size: 1.6rem; letter-spacing: -1px;
  text-shadow: 0 0 18px #ff5c8a88, 0 0 40px #ffb34755; }
.tagline { color: var(--dim); font-size: .76rem; margin: 5px 0 12px; }
.skill-hint { color: var(--dim); font-size: .72rem; margin-top: 6px; min-height: 2.1em; }
@media (min-width: 760px) {
  #screen-lobby .lobby-box { width: min(860px, 96vw); padding: 24px 28px 26px; }
  .logo { font-size: 2rem; }
  .tagline { font-size: .82rem; margin-bottom: 16px; }
  .lobby-cols { grid-template-columns: 1.15fr 1fr; }
}
.field { text-align: left; margin: 12px 0; }
.field > label { display: block; font-size: .8rem; color: var(--amber); margin-bottom: 6px; font-weight: 700; }
input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #0e0918; color: var(--txt); font-size: 1rem; outline: none;
}
input:focus { border-color: var(--pink); }
.char-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.char-card { padding: 10px 6px; border: 1px solid var(--line); border-radius: 12px;
  background: #120b1e; cursor: pointer; text-align: center; transition: .15s; }
.char-card .ce { font-size: 1.7rem; }
.char-card .cn { font-size: .78rem; font-weight: 700; margin-top: 2px; }
.char-card .cs { font-size: .62rem; color: var(--dim); margin-top: 2px; line-height: 1.25; }
.char-card.sel { border-color: var(--amber); background: #241536; box-shadow: 0 0 12px #ffb34744; }
.row { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; font-size: .85rem; }
.seg { display: flex; gap: 4px; }
.seg button { padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: #120b1e; color: var(--dim); font-size: .85rem; cursor: pointer; }
.seg button.on { background: var(--amber); color: #221302; font-weight: 800; border-color: var(--amber); }
.lobby-btns { display: flex; flex-direction: column; gap: 9px; margin-top: 14px; }
button.big { padding: 14px; border-radius: 14px; border: none; font-size: 1.02rem; font-weight: 800;
  cursor: pointer; color: #1c0f02; transition: transform .1s; }
button.big:active { transform: scale(.97); }
.amber { background: linear-gradient(135deg, #ffb347, #ff8c47); }
.pink  { background: linear-gradient(135deg, #ff5c8a, #ff477e); color: #fff; }
.teal  { background: linear-gradient(135deg, #3ee6c8, #2bb9a0); }
.violet { background: linear-gradient(135deg, #a98bff, #7c5cf0); color: #fff; }
.violet small { display: block; font-weight: 600; font-size: .74rem; opacity: .85; }
/* button.big 보다 우선하도록 명시 — 모달 닫기 글자가 안 보이던 버그 수정 */
.ghost, button.ghost, button.big.ghost {
  background: transparent; border: 1px solid var(--line) !important; color: var(--txt) !important;
  padding: 10px; border-radius: 12px; cursor: pointer; margin-top: 10px; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 40%; text-transform: uppercase; text-align: center; letter-spacing: 4px; font-weight: 800; }
.join-row button { flex: 1; }
.err { color: var(--danger); font-size: .8rem; margin-top: 10px; min-height: 1em; }
.hint { color: var(--dim); font-size: .75rem; margin-top: 8px; }
.room-code { margin: 10px 0 14px; color: var(--dim); }
.room-code b { color: var(--teal); font-size: 1.6rem; letter-spacing: 6px; }
.roster { list-style: none; margin: 8px 0 16px; }
.roster li { padding: 9px 12px; border-bottom: 1px dashed var(--line); font-size: .95rem; text-align: left; }
.roster li .tag { float: right; color: var(--amber); font-size: .75rem; }

/* ── 게임 HUD ── */
.hud-me { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); width: 262px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; z-index: 5;
  max-height: calc(100vh - 24px); overflow-y: auto; }
.me-top { font-size: .9rem; margin-bottom: 6px; display: flex; align-items: center; gap: 4px; }
.skill-badge { display: inline-block; font-size: .6rem; background: #241536; border: 1px solid var(--line);
  color: var(--amber); border-radius: 6px; padding: 1px 5px; margin-left: 3px; cursor: pointer; }
.skill-badge.ready { border-color: var(--amber); box-shadow: 0 0 8px #ffb34766; }
.bar { position: relative; height: 15px; background: #0e0918; border-radius: 8px; margin: 5px 0; overflow: hidden; }
.bar i { position: absolute; inset: 0; border-radius: 8px; transition: width .4s; }
.bar.hp i { background: linear-gradient(90deg, #45e07f, #2bb9a0); }
.bar.alc i { background: linear-gradient(90deg, #ffb347, #ff477e); }
.bar span { position: absolute; inset: 0; font-size: .62rem; line-height: 15px; text-align: center;
  color: #fff; text-shadow: 0 1px 2px #000; }
.items { display: flex; gap: 5px; margin-top: 7px; min-height: 34px; }
.item-slot { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px;
  background: #0e0918; font-size: 1.15rem; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .15s; }
.item-slot:hover { border-color: var(--teal); box-shadow: 0 0 8px #3ee6c855; }

.hud-players { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); width: 195px;
  display: flex; flex-direction: column; gap: 4px; z-index: 5; }
.pp { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 8px; font-size: .72rem; display: flex; align-items: center; gap: 5px; }
.pp .mini-alc { flex: 1; height: 6px; background: #0e0918; border-radius: 4px; overflow: hidden; }
.pp .mini-alc i { display: block; height: 100%; background: linear-gradient(90deg, #ffb347, #ff477e); }
.pp.turn { border-color: var(--amber); box-shadow: 0 0 10px #ffb34755; }
.pp.ko { opacity: .45; text-decoration: line-through; }
.pp .pts { color: var(--amber); font-weight: 800; min-width: 18px; text-align: right; margin-left: auto; }
.hud-toggle { display: flex; gap: 4px; margin-bottom: 2px; }
.hud-toggle button { flex: 1; padding: 5px 0; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--dim); font-size: .68rem; font-weight: 700; cursor: pointer; }
.hud-toggle button.on { background: var(--amber); color: #221302; border-color: var(--amber); }

/* ── 상태바 접기/펼치기 버튼 ── */
.hud-fold { flex: none; width: 26px; height: 24px; padding: 0; border-radius: 7px;
  border: 1px solid var(--line); background: #241536; color: var(--txt);
  font-size: .9rem; line-height: 1; cursor: pointer; }
.hud-fold:hover { border-color: var(--teal); }
#fold-me { margin-left: auto; }
/* .hud-toggle button(flex:1·padding·dim색) 규칙을 덮어 폴드 버튼 모양 유지 */
#hud-players .hud-fold { flex: none; width: 26px; padding: 0; background: #241536; color: var(--txt); }
/* 접힘: 좌측은 이모지+버튼만, 우측은 폴드 버튼만 남기고 폭을 콘텐츠에 맞춘다 */
.hud-me.folded { width: auto; max-height: none; overflow: visible; padding: 6px 8px; }
.hud-me.folded .bar, .hud-me.folded .items, .hud-me.folded #shop-dock,
.hud-me.folded #me-name, .hud-me.folded #me-skill { display: none; }
.hud-me.folded .me-top { margin-bottom: 0; }
.hud-players.folded { width: auto; }
.hud-players.folded .hud-toggle { margin: 0; }

/* ── 배너/챈트 ── */
.banner { position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--amber); color: var(--amber);
  padding: 12px 26px; border-radius: 16px; font-size: 1.25rem; font-weight: 900; text-align: center;
  z-index: 8; max-width: 92vw; box-shadow: 0 0 30px #ffb34733; white-space: pre-line; }
.chant { position: absolute; top: 28%; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 1.6rem; font-weight: 900; z-index: 8; text-align: center;
  text-shadow: 0 0 16px var(--pink), 0 2px 4px #000; animation: chantPop .5s; white-space: nowrap; }
@keyframes chantPop { 0% { transform: translateX(-50%) scale(.4); opacity: 0 } 100% { transform: translateX(-50%) scale(1); opacity: 1 } }

/* ── 비트 바 ── */
.beat-bar { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 6; }
.beat-bar i { width: 16px; height: 16px; border-radius: 50%; background: #241536; border: 1px solid var(--line); }
.beat-bar i.on { background: var(--amber); box-shadow: 0 0 14px var(--amber); transform: scale(1.25); }

/* ── 게임 선택 ── */
.game-select { position: absolute; inset: auto 0 0 0; max-height: 62%;
  background: linear-gradient(180deg, transparent, #0b0710ee 18%);
  padding: 26px 12px calc(14px + env(safe-area-inset-bottom)); z-index: 7; overflow-y: auto; }
.game-select h3 { text-align: center; color: var(--amber); margin-bottom: 12px; font-size: 1.05rem; }
.game-select h3 small { display: block; color: var(--dim); font-weight: 400; font-size: .72rem; margin-top: 3px; }
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px;
  max-width: 700px; margin: 0 auto; }
.game-card { background: var(--panel); border: 1px solid var(--line); border-radius: 13px;
  padding: 10px; cursor: pointer; transition: .15s; }
.game-card:hover { border-color: var(--pink); transform: translateY(-2px); }
.game-card .ge { font-size: 1.5rem; }
.game-card .gn { font-weight: 800; font-size: .88rem; margin: 2px 0; }
.game-card .gd { font-size: .66rem; color: var(--dim); line-height: 1.3; }

/* ── 액션 패널 ── */
.action-panel { position: absolute; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 9; width: min(560px, 96vw);
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px; text-align: center; backdrop-filter: blur(6px); }
.action-panel .ap-title { font-size: .85rem; color: var(--amber); font-weight: 700; margin-bottom: 9px; }
.ap-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ap-btns button {
  padding: 13px 18px; border-radius: 13px; border: 1px solid var(--line);
  background: #241536; color: var(--txt); font-size: 1rem; font-weight: 800; cursor: pointer;
  transform: translate(var(--jx), var(--jy)); transition: transform .25s;
}
.ap-btns button.hot { background: linear-gradient(135deg, #ff5c8a, #ff477e); border: none; color: #fff;
  font-size: 1.2rem; padding: 16px 30px; box-shadow: 0 0 20px #ff5c8a66; }
.ap-btns button.calm { background: linear-gradient(135deg, #3ee6c8, #2bb9a0); border: none; color: #06251f; }
.ap-btns button:active { transform: translate(var(--jx), var(--jy)) scale(.94); }
.ap-input-row { display: flex; gap: 8px; margin-top: 4px; }
.ap-input-row input { flex: 1; font-size: 1.05rem; }
.ap-input-row button { padding: 0 22px; border-radius: 12px; border: none;
  background: var(--amber); font-weight: 900; cursor: pointer; }
.ap-note { font-size: .7rem; color: var(--dim); margin-top: 8px; }

/* ── 타이머 ── */
.timer-wrap { position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(4px + env(safe-area-inset-bottom)); width: min(560px, 96vw); height: 7px;
  background: #0e0918; border-radius: 5px; overflow: hidden; z-index: 9; }
.timer-wrap i { display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--teal), var(--amber)); transition: width .1s linear; }

/* ── 토스트 ── */
#toasts { position: absolute; bottom: 26%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 10; pointer-events: none; }
.toast { background: #171022ee; border: 1px solid var(--line); padding: 8px 16px; border-radius: 12px;
  font-size: .85rem; animation: toastIn .25s; max-width: 90vw; text-align: center; }
.toast.warn { border-color: var(--danger); color: #ffb9c0; }
.toast.good { border-color: var(--teal); color: #c8ffef; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) } }

/* ── 벌칙 연출 ── */
.penalty-fx { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: radial-gradient(circle, #ff477e33, #0b0710dd);
  animation: penaltyFlash .5s; }
.penalty-fx .soju { font-size: 5rem; animation: sojuShake .6s infinite; }
.penalty-fx .ptext { font-size: 2.2rem; font-weight: 900; color: #fff;
  text-shadow: 0 0 24px var(--pink); margin-top: 8px; white-space: pre-line; text-align: center; }
@keyframes penaltyFlash { 0% { opacity: 0 } }
@keyframes sojuShake { 0%,100% { transform: rotate(-14deg) } 50% { transform: rotate(14deg) } }

/* ── 모달/기타 ── */
.corner-btn { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); right: max(12px, env(safe-area-inset-right));
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--txt); font-size: 1.1rem; cursor: pointer; z-index: 11; }
.corner-btn.exit { right: auto; left: max(12px, env(safe-area-inset-left)); }
/* 사운드 토글은 도움말 왼쪽에 나란히 */
.corner-btn.sound { right: calc(max(12px, env(safe-area-inset-right)) + 50px); }
.modal { position: fixed; inset: 0; background: #000a; z-index: 30;
  display: flex; align-items: center; justify-content: center; }
.modal-box { width: min(460px, 92vw); max-height: 80vh; overflow-y: auto;
  background: #171022; border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.modal-box h3 { color: var(--amber); margin-bottom: 10px; }
#help-body { font-size: .85rem; line-height: 1.65; color: #d9cdee; white-space: pre-line; }
.hidden { display: none !important; }

/* ── 딸기 게임 비트 가이드 스트립 ── */
.ddalgi-strip { display: flex; gap: 7px; justify-content: center; margin-top: 10px; }
.ddalgi-strip .slot { width: 26px; height: 26px; border-radius: 50%;
  background: #241536; border: 1px solid var(--line); display: flex;
  align-items: center; justify-content: center; font-size: 13px;
  transition: transform .08s, background .08s; color: var(--dim); }
.ddalgi-strip .slot.req { border-color: var(--pink); }
.ddalgi-strip .slot.cur { transform: scale(1.4); background: #3a2b52;
  box-shadow: 0 0 12px var(--amber); }
.ddalgi-strip .slot.cur.req { background: var(--pink); box-shadow: 0 0 18px var(--pink); }
.ddalgi-strip .slot.hitok { background: #1d5c4c; border-color: var(--teal); }

/* ── 매점 독 (HUD 상시 표시, ^/v 접기) ── */
#shop-dock { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.sd-head { display: flex; justify-content: space-between; align-items: center;
  font-size: .72rem; color: var(--amber); font-weight: 800; }
.sd-head b { color: var(--txt); font-weight: 700; }
#sd-toggle { width: 24px; height: 20px; border-radius: 6px; border: 1px solid var(--line);
  background: #241536; color: var(--txt); cursor: pointer; font-size: .72rem; line-height: 1; }
.sd-body { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.sd-body.closed { display: none; }
.sd-item { display: flex; align-items: center; gap: 7px; padding: 5px 7px; text-align: left;
  border: 1px solid var(--line); border-radius: 9px; background: #120b1e;
  cursor: pointer; color: var(--txt); }
.sd-item .sd-e { font-size: 1.05rem; }
.sd-item .sd-t { flex: 1; min-width: 0; }
.sd-item .sd-t b { display: block; font-size: .72rem; }
.sd-item .sd-t small { display: block; font-size: .6rem; color: var(--dim); line-height: 1.25; }
.sd-item .sd-p { font-size: .68rem; color: var(--amber); font-weight: 800; white-space: nowrap; }
.sd-item:disabled { opacity: .35; cursor: not-allowed; }
.sd-item:not(:disabled):hover { border-color: var(--teal); }

/* ── 방 목록 모달 ── */
.room-list { display: flex; flex-direction: column; gap: 6px; }
.room-row { display: flex; justify-content: space-between; align-items: center;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: #120b1e; color: var(--txt); cursor: pointer; font-size: .9rem; }
.room-row:hover { border-color: var(--pink); }
.room-row span { color: var(--dim); font-size: .78rem; }

.ghost-row { display: flex; gap: 8px; }
.ghost-row .ghost { flex: 1; margin-top: 6px; }

/* ── 게임 규칙 모달 ── */
.rule-h { color: var(--amber); margin: 14px 0 4px; font-size: .95rem; }
.rule-h:first-child { margin-top: 0; }
.rule-t { color: #d9cdee; font-size: .8rem; line-height: 1.6; white-space: pre-line;
  border-bottom: 1px dashed var(--line); padding-bottom: 10px; }

/* ── 랭킹 모달 ── */
.rank-sub { color: var(--dim); font-size: .8rem; margin-bottom: 10px; }
.rank-list { list-style: none; }
.rank-list li { display: flex; align-items: center; gap: 8px;
  padding: 8px 4px; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.rank-list li b { min-width: 40px; color: var(--amber); }
.rank-list li span { margin-left: auto; color: var(--dim); font-size: .8rem; }
.rank-list li.me { background: rgba(255, 190, 60, .14); border-radius: 6px; }
.rank-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.rank-tabs button { padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--dim); font-size: .78rem; font-weight: 700; }
.rank-tabs button.on { background: var(--amber); border-color: transparent; color: #241503; }
.notice-list { list-style: disc; margin: 0 0 4px 18px; }
.notice-list li { font-size: .82rem; line-height: 1.5; margin-bottom: 7px; color: var(--txt); }
#my-record { color: var(--teal); font-size: .78rem; margin-top: 8px; min-height: 1em; }
.rank-form { display: flex; gap: 8px; margin-bottom: 8px; }
.rank-form input { flex: 1; min-width: 0; }
.rank-form button { flex: 0 0 auto; padding: 10px 18px; margin: 0; }

@media (max-width: 620px) {
  .hud-me { width: 196px; padding: 8px; }
  .hud-players { width: 150px; }
  .pp { font-size: .62rem; }
  .banner { font-size: 1rem; padding: 9px 16px; top: 13%; }
  .chant { font-size: 1.15rem; top: 24%; }
  .game-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════ 세로 회전 안내 (웹 브라우저 세로 대비 — 앱은 가로 고정) ═══════════ */
#rotate-hint { display: none; position: fixed; inset: 0; z-index: 999; padding: 24px;
  flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px;
  background: radial-gradient(80% 60% at 50% 32%, #241536 0%, var(--bg) 76%); }
#rotate-hint .rot-ico { font-size: 4rem; animation: rotNudge 2.4s ease-in-out infinite; }
@keyframes rotNudge { 0%,50% { transform: rotate(0) } 72%,100% { transform: rotate(-90deg) } }
#rotate-hint .rot-t { color: var(--amber); font-size: 1.2rem; font-weight: 900;
  text-shadow: 0 0 18px #ffb34755; }
#rotate-hint .rot-s { color: var(--dim); font-size: .84rem; }
/* 세로 + 좁은 화면(=폰)일 때만 표시. 태블릿/데스크톱 세로는 게임이 정상 동작하므로 제외 */
@media (orientation: portrait) and (max-width: 900px) {
  #rotate-hint { display: flex; }
}

/* ═══════════ 가로 태블릿/데스크톱: 액션·타이머가 사이드 HUD와 겹치지 않게 ═══════════ */
@media (orientation: landscape) and (min-height: 501px) {
  .action-panel, .timer-wrap { width: min(560px, calc(100vw - 560px)); }
}

/* ═══════════ 가로 폰(짧은 높이): 전면 컴팩트 재구성 ═══════════ */
@media (orientation: landscape) and (max-height: 500px) {
  /* ── 로비/대기실: 2컬럼 강제 + 컴팩트 (세로 넘침 방지) ── */
  #screen-lobby.active, #screen-room.active { padding: 5px; }
  .lobby-box { width: min(720px, 96vw); padding: 8px 16px 10px; }
  #screen-lobby .lobby-box { width: min(760px, 97vw); }
  .lobby-head { margin-bottom: 2px; }
  .logo { font-size: 1.05rem; }
  .lobby-cols { grid-template-columns: 1.1fr 1fr; gap: 0 18px; }
  .field { margin: 5px 0; }
  .field > label { font-size: .72rem; margin-bottom: 3px; }
  input { padding: 8px 11px; font-size: .9rem; border-radius: 10px; }
  .char-grid { gap: 5px; }
  .char-card { padding: 5px 4px; }
  .char-card .ce { font-size: 1.25rem; }
  .char-card .cn { font-size: .72rem; }
  .char-card .cs { display: none; }   /* 선택 시 하단 힌트로 노출되므로 카드에선 생략 → 세로 절약 */
  .skill-hint { font-size: .66rem; min-height: 1.4em; margin-top: 2px; }
  .row { margin: 4px 0; font-size: .78rem; }
  .seg button { padding: 5px 10px; font-size: .8rem; }
  /* 솔로/오늘의 술자리를 한 줄에 나란히 → 버튼이 늘어도 로비가 세로로 안 넘친다 */
  .lobby-btns { flex-direction: row; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
  .lobby-btns > * { flex: 1 1 100%; }
  #btn-solo, #btn-daily { flex: 1 1 calc(50% - 3px); }
  button.big { padding: 9px; font-size: .95rem; border-radius: 11px; }
  #btn-solo, #btn-daily { padding: 7px 8px; font-size: .84rem; }
  .violet small { font-size: .64rem; }
  .ghost, button.ghost, button.big.ghost { padding: 7px; margin-top: 5px; }
  .join-row { gap: 6px; }
  .err { margin-top: 5px; min-height: .8em; }
  #screen-room .lobby-box { padding: 10px 18px 12px; }
  .room-code { margin: 6px 0 8px; }
  .room-code b { font-size: 1.3rem; }
  .roster { margin: 6px 0 10px; max-height: 34vh; overflow-y: auto; }
  .roster li { padding: 6px 10px; font-size: .85rem; }

  /* ── 사이드 HUD: 폭 축소 + 높이 캡(하단 코너버튼 자리 확보) ── */
  .hud-me { width: 194px; padding: 8px; top: max(6px, env(safe-area-inset-top)); left: max(6px, env(safe-area-inset-left));
    max-height: calc(100vh - 72px); max-height: calc(100dvh - 72px); }
  .me-top { font-size: .82rem; margin-bottom: 4px; }
  .bar { height: 13px; margin: 4px 0; }
  .bar span { line-height: 13px; font-size: .58rem; }
  .items { min-height: 30px; gap: 4px; margin-top: 5px; }
  .item-slot { width: 30px; height: 30px; font-size: 1rem; }
  .hud-players { width: 150px; right: max(6px, env(safe-area-inset-right)); top: max(6px, env(safe-area-inset-top)); }
  .pp { font-size: .62rem; padding: 3px 6px; }

  /* 매점: 2열 그리드로 세로 높이 절반 */
  #shop-dock { margin-top: 6px; padding-top: 5px; }
  .sd-body { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .sd-item { flex-direction: column; align-items: flex-start; gap: 2px; padding: 5px 6px; }
  .sd-item .sd-e { font-size: .95rem; }
  .sd-item .sd-t b { font-size: .64rem; }
  .sd-item .sd-t small { font-size: .52rem; line-height: 1.2; }
  .sd-item .sd-p { font-size: .6rem; }

  /* ── 액션/타이머: 사이드 패널을 피한 중앙 레인 폭 ── */
  .action-panel { width: min(440px, calc(100vw - 400px)); padding: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom)); }
  .action-panel .ap-title { font-size: .78rem; margin-bottom: 6px; }
  .ap-btns { gap: 6px; }
  .ap-btns button { padding: 10px 14px; font-size: .92rem; }
  .ap-btns button.hot { padding: 12px 22px; font-size: 1.05rem; }
  .timer-wrap { width: min(440px, calc(100vw - 400px));
    bottom: calc(3px + env(safe-area-inset-bottom)); }

  /* ── 배너/챈트/토스트: 중앙 레인으로 폭 제한(사이드 패널 침범 방지) ── */
  .banner { top: 8px; font-size: .95rem; padding: 8px 16px; max-width: calc(100vw - 420px); }
  .chant { top: 22%; font-size: 1.1rem; }
  #toasts { bottom: 34%; }

  /* ── 게임 선택: 상단 여백 축소 + 촘촘한 그리드 ── */
  .game-select { padding: 12px 10px calc(10px + env(safe-area-inset-bottom)); max-height: 84%; }
  .game-select h3 { font-size: .92rem; margin-bottom: 8px; }
  .game-grid { grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); gap: 6px; }
  .game-card { padding: 8px; }
  .game-card .ge { font-size: 1.3rem; }
  .game-card .gn { font-size: .8rem; }
  .game-card .gd { font-size: .6rem; }

  /* ── 코너 버튼: 하단 모서리(사이드 패널 높이 캡으로 생긴 여백) ── */
  .corner-btn { width: 38px; height: 38px; font-size: 1rem;
    bottom: calc(8px + env(safe-area-inset-bottom)); }

  /* 규칙/랭킹 모달: 짧은 높이 대응 */
  .modal-box { max-height: 88vh; padding: 14px 16px; }
}
