/* 데스크펫 v1.0.1 — 모바일 · 태블릿 화면 (index.html 의 내장 CSS 뒤에 로드 → 같은 우선순위면 이 파일이 이김)
 *  ≤ 900px (폰 · 아이패드 세로): 로비를 세로로 쌓고 스크롤. js/app.js MOBILE_W 와 같은 값
 *  ≤ 560px (폰): 상단 바 · 게임 카드 · 메뉴 버튼을 작게
 *  PC(901px 이상)는 바뀌는 것 없음 */

/* ---------- 공통: 터치 기기 ---------- */
@media (hover: none) {
  /* 손가락으로 누를 때 회색 사각형 깜빡임 · 두 번 눌러 확대 막기 */
  html { -webkit-tap-highlight-color: transparent; }
  button, a, [role="button"], .game-card, .pill { touch-action: manipulation; }
  /* 키보드 단축키 표시는 터치 화면에서 의미 없음 */
  #topbar kbd, .intro-skip kbd, #panelClose kbd, .howto-btns kbd, .modal-btns kbd { display: none; }
  /* v1.3 모바일 게임처럼: 아래로 끌어 새로고침 · 가장자리 튕김 막기, 게임 중 길게 누르기 메뉴·글자 선택 막기 */
  html, body { overscroll-behavior: none; }
  body[data-scene="game"], body[data-scene="game"] * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

/* ---------- 폰 · 아이패드 세로 ---------- */
@media (max-width: 900px) {
  /* 로비: 캐릭터 위 · 게임 카드와 메뉴 아래, 넘치면 세로 스크롤 */
  #scene-main { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  #scene-main .main-bg { position: fixed; inset: var(--bar-h) 0 0 0; }
  .main { display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    height: auto; min-height: 100%; gap: 18px; padding: 8px 16px 120px; --menu-w: 100%; }
  .main-left { width: 100%; align-self: center; }
  .pet-spot { margin-top: 60px; }
  .main-right { width: 100%; max-width: 640px; gap: 16px; justify-content: flex-start; }
  .cards { gap: 14px; }
  .game-card .gc-desc { min-height: 0; }
  /* 오른쪽 '친구' 탭: 스크롤해도 화면에 붙어 있게 */
  .side-friends { position: fixed; top: calc(var(--bar-h) + 14px); transform: none; z-index: 30; }
  /* 아래쪽: 사이트 링크는 한 줄 가운데, 공유 버튼·접속자 수는 그 위로 */
  .lobby-links { left: 8px; right: 8px; bottom: max(6px, env(safe-area-inset-bottom)); justify-content: center; gap: 4px 10px; font-size: 12px; border-radius: 14px; padding: 4px 10px; }
  .fab-share { bottom: calc(max(6px, env(safe-area-inset-bottom)) + 40px); right: 12px; }
  #liveCount { left: 12px; bottom: calc(max(6px, env(safe-area-inset-bottom)) + 46px); }
  .ver-tag { display: none; }
  /* 창(뽑기·도감·랭킹 …): 화면을 거의 꽉 채움 */
  .panel-back { padding: 8px; }
  .panel-card { width: 100%; height: min(100%, 1000px); padding: 18px 24px 16px; border-radius: 22px; }
  .panel-head { padding: 0 2px 6px; gap: 8px; }
  .panel-head h2 { font-size: 22px; }
  .panel-head img { width: 32px; height: 32px; }
  .panel-body { padding: 10px 4px 12px; }
  .pill { white-space: nowrap; }
  /* 창 내용: 칸 수 줄이기 */
  .dex-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .buddy-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .buddy-body .floor-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .wp-grid, .set-wp .wp-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); max-height: none; }
  .battle { grid-template-columns: minmax(0, 1fr); height: auto; }
  .fr-top { grid-template-columns: minmax(0, 1fr); }
  .rank-me { margin-left: -4px; margin-right: -4px; }
  /* 알림 창 · 결과 카드 */
  .modal { min-width: 0; max-width: calc(100vw - 24px); }
  .modal.share-modal { width: calc(100vw - 24px); max-width: calc(100vw - 24px); }
  /* 메뉴 버튼: 그림 위 · 글자 아래 (아이패드 세로부터) */
  .subs .sub-btn { height: 84px; flex-direction: column; justify-content: center; gap: 2px; padding: 4px 4px 10px; }
  .subs .sub-btn > img, .subs .sub-btn > .sub-ico { position: static; width: 46px; height: 46px; font-size: 34px; transform: rotate(-6deg); }
  .subs .sub-btn:hover > img, .subs .sub-btn:hover > .sub-ico { transform: rotate(-6deg) scale(1.08); }
  .subs .sub-btn > span:not(.sub-ico), :lang(ja) .subs .sub-btn > span:not(.sub-ico), :lang(en) .subs .sub-btn > span:not(.sub-ico) {
    flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
}

/* ---------- 폰 · 작은 태블릿: 2단 창을 1단으로 ---------- */
@media (max-width: 700px) {
  /* 설정: 칸마다 따로 스크롤하지 않고 창 전체가 한 번에 스크롤 */
  .settings { display: flex; flex-direction: column; height: auto; gap: 14px; }
  .set-col { overflow: visible; padding: 0; }
  .set-wp { max-height: none; overflow: visible; }
  .set-wp-host { overflow: visible; margin-right: 0; padding: 4px 0 6px; }
  /* 함께하는 친구 바꾸기: 미리보기를 위에 붙여 두고 목록은 아래 */
  .buddy-pets { grid-template-columns: minmax(0, 1fr); }
  .buddy-preview { order: -1; z-index: 3; grid-template-columns: 130px minmax(0, 1fr); grid-template-areas: "stage tier" "stage name" "stage btn"; column-gap: 10px; align-items: center; justify-items: start; padding: 6px 10px 8px; }
  .buddy-preview .bp-stage { grid-area: stage; height: 140px; }
  .buddy-preview .bp-tier { grid-area: tier; align-self: end; }
  .buddy-preview .bp-name { grid-area: name; font-size: 19px; white-space: normal; }
  .buddy-preview .btn { grid-area: btn; align-self: start; }
  .buddy-preview .bp-floor { width: 120px; height: 88px; }
  .buddy-preview .bp-floor.rug { height: 60px; }
  .gacha { grid-template-columns: minmax(0, 1fr); height: auto; gap: 10px; align-items: start; }
  .gacha-left { height: auto; }
  .machine-wrap { height: 210px; }
  .machine { max-height: 210px; }
  .gacha-stage { height: 220px; }
  .gacha-hello { font-size: 17px; }
  .gacha-rule { font-size: 12px; }
}

/* ---------- 폰 ---------- */
@media (max-width: 560px) {
  :root { --bar-h: 54px; }
  /* v1.1 게임 카드 3장: 폰에선 최고점 칩을 🏆 + 숫자만 (글자가 세로로 쪼개지지 않게) */
  .game-card .gc-best [data-i18n="main.best"] { display: none; }
  .game-card .gc-best { padding: 3px 10px 3px 6px; }
  /* 상단 바: 로고 작게 · 글자 빼고 아이콘만 · 소리 버튼은 ⚙️ 설정 안에 있으니 숨김 */
  #topbar { gap: 6px; padding: 0 8px; }
  .logo { padding: 2px; }
  .logo img.logo-art { height: 30px; }
  .bar-right { gap: 5px; min-width: 0; margin-left: auto; overflow-x: auto; scrollbar-width: none; padding: 4px 2px 6px; }
  .bar-right::-webkit-scrollbar { display: none; }
  .bar-right > * { flex: none; }
  .pill { height: 34px; padding: 0 9px 0 5px; gap: 4px; font-size: 15px; border-width: 2px; box-shadow: 0 2px 0 var(--ink); }
  .pill img { width: 22px; height: 22px; }
  .pill.notice-pill, .pill.set-pill { padding: 0 8px; }
  .pill .notice-t, #soundBtn { display: none; }
  img.notice-ico, img.set-ico { width: 22px; height: 22px; }
  .pill.login-pill { padding: 0 8px 0 5px; }
  .pill.login-pill b { font-size: 13px; max-width: 5.5ch; }
  .pill.login-pill .admin-badge { font-size: 10px; padding: 2px 4px; }
  /*TEST-START*/ .test-pill { font-size: 11px; padding: 0 7px; } /*TEST-END*/
  body[data-scene="game"] .bar-game { display: none; }

  /* 로비 */
  .main { gap: 14px; padding: 4px 12px 116px; }
  .pet-spot { margin-top: 54px; }
  .speech { font-size: 15px; }
  .pet-tag { padding: 5px 8px 5px 14px; column-gap: 8px; }
  .pet-tag b { font-size: 17px; }
  .cards { gap: 10px; }
  .game-card { padding: 8px 8px 10px; gap: 4px; border-width: 3px; border-radius: 22px; box-shadow: 0 5px 0 var(--ink); }
  .game-card .gc-thumb { margin-bottom: -20px; border-radius: 16px; border-width: 2.5px; }
  .game-card .gc-name img { height: 44px; }
  .game-card .gc-desc, :lang(ja) .game-card .gc-desc { font-size: 12px; line-height: 1.25; }
  .game-card .gc-best { font-size: 12px; padding: 3px 9px 3px 6px; gap: 4px; border-width: 2px; }
  .game-card .gc-best b { font-size: 16px; }
  .game-card .gc-best-ico { font-size: 13px; }
  .game-card .gc-go { display: none; }
  /* 메뉴 버튼 5개: 그림 위 · 글자 아래 */
  .subs { gap: 6px; }
  .subs .sub-btn { height: 70px; flex-direction: column; justify-content: center; gap: 2px; padding: 4px 2px 8px; border-radius: 18px; border-width: 2.5px;
    box-shadow: 0 4px 0 var(--ink), inset 0 -5px 0 var(--c3), inset 0 2px 0 rgba(255,255,255,.65); }
  .subs .sub-btn::before { left: 8px; right: 8px; top: 4px; border-radius: 10px; }
  .subs .sub-btn > img, .subs .sub-btn > .sub-ico { position: static; width: 34px; height: 34px; font-size: 28px; transform: rotate(-6deg); }
  .subs .sub-btn:hover > img, .subs .sub-btn:hover > .sub-ico { transform: rotate(-6deg); }
  .subs .sub-btn > span:not(.sub-ico), :lang(ja) .subs .sub-btn > span:not(.sub-ico), :lang(en) .subs .sub-btn > span:not(.sub-ico) {
    flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 12px; letter-spacing: 0;
    text-shadow: -1.5px 0 var(--ink), 1.5px 0 var(--ink), 0 -1.5px var(--ink), 0 1.5px var(--ink), -1px -1px var(--ink), 1px -1px var(--ink), -1px 1px var(--ink), 1px 1px var(--ink), 0 2px 0 var(--ink); }
  .subs .sub-btn em { right: -4px; top: -10px; font-size: 10px; padding: 1px 6px; }
  .sub-btn em.test-badge { font-size: 9px; }
  .side-friends { padding: 8px 5px 8px 7px; font-size: 12px; border-width: 2.5px; border-right: 0; }
  .side-friends .sf-ico, .side-friends > span[aria-hidden] { width: 28px; height: 28px; font-size: 22px; line-height: 28px; }
  .fab-share { padding: 6px 12px 6px 8px; font-size: 15px; }
  .fab-share .fab-ico, .fab-share > span[aria-hidden] { width: 24px; height: 24px; }
  /* 로비에선 로고(=메인으로 버튼)가 필요 없어 자리를 비움 */
  body[data-scene="main"] .logo { display: none; }

  /* 창: 그림 테두리를 얇게 */
  .panel-back { padding: 4px; }
  .panel-card, .result-card, .modal, .guard-card { border-image: url("ui/frame.webp") 120 fill / 34px stretch; }
  .panel-card { padding: 16px 22px 14px; }
  .panel-head h2, .modal-title { padding: 4px 30px 9px; border-image-width: 0 28px; }
  .panel-head h2, :lang(ja) .panel-head h2 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .panel-head img { width: 28px; height: 28px; }
  .panel-head .btn { padding: 4px 12px; font-size: 14px; }
  .panel-body { padding: 6px 2px 20px; }
  .modal { padding: 26px 20px 22px; }
  .modal-title, :lang(ja) .modal-title { font-size: 22px; }
  .modal-text { font-size: 16px; }
  .result-card { padding: 28px 20px 26px; width: calc(100vw - 20px); }
  .guard-card { padding: 28px 22px; }
  /* 창 내용 */
  .tabs { flex-wrap: wrap; gap: 6px; }
  .dex-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .dex-cell { padding: 4px 2px 4px; border-radius: 12px; border-width: 2px; }
  .dex-cell img { height: 48px; }
  .dex-cell span { font-size: 11px; }
  .buddy-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .buddy-body .floor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wp-grid, .set-wp .wp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ach-grid { grid-template-columns: minmax(0, 1fr); }
  .rank td { padding: 6px 8px; }
  .rank th { padding: 0 8px; font-size: 13px; }
  .rank td:first-child { width: 48px; }
  .rank .nick { max-width: 110px; font-size: 15px; }
  .rank .sc { font-size: 18px; }
  .rank .dt { font-size: 12px; }
  .rank-scope button { font-size: 14px; padding: 5px 10px; }
  .battle-box, .battle-rules, .login-form { padding: 12px 12px; }
  .battle-box label { grid-template-columns: 76px minmax(0, 1fr); }
  .battle-code { font-size: 40px; padding: 4px 16px; }
  .battle-games { flex-direction: column; }
  .login-field { grid-template-columns: 70px minmax(0, 1fr); font-size: 15px; }
  .gacha-btns .btn-big, :lang(en) .gacha-btns .btn-big, :lang(ja) .gacha-btns .btn-big { font-size: 14px; padding-left: 8px; padding-right: 8px; }
}

/* ======================= 2단계: 미니게임 · 대결 · 결과 ======================= */
@media (max-width: 900px) {
  /* 게임 중 상단 바: 일시정지 · 코인 · 소리 · 설정만 */
  body[data-scene="game"] .notice-pill, body[data-scene="game"] .login-pill, body[data-scene="game"] #shardPill { display: none; }
  /*TEST-START*/ body[data-scene="game"] .test-pill { display: none; } /*TEST-END*/
  body[data-scene="game"] .bar-title { max-height: 34px; }
  /* 게임 화면: 위 = 캐릭터 무대 + 콤보 카드(가로 한 줄) · 아래 = 판 */
  .game { display: flex; flex-direction: column; gap: 8px; padding: 8px 10px 10px; }
  .game-side { flex: none; }
  .stage-host { flex-direction: row; flex: none; gap: 8px; }
  .stage-card { flex: 0 0 36%; height: 150px; min-height: 0; border-radius: 18px; }
  .stage-info { flex: 1; min-width: 0; align-content: center; padding: 8px 12px; gap: 5px; }
  .stage-banner { font-size: 22px; top: 8px; }
  .stage-banner.s3, .stage-banner.fever { font-size: 26px; }
  .stage-banner.oops { font-size: 18px; }
  .game-keys { display: none; }
  .game-main { flex: 1; min-height: 0; }
  .countdown b { font-size: 110px; }
  .countdown b.go { font-size: 80px; }
  /* 펫블록: 카드 줄을 판 아래로 */
  .pb-root { flex-direction: column; align-items: center; row-gap: 10px; }
  .pb-side { width: 100%; max-width: 560px; grid-template-columns: 1.1fr 1fr; grid-template-rows: auto auto auto; gap: 8px; padding-bottom: 0; }
  .pb-c-score { grid-row: 1; grid-column: 1; } .pb-c-time { grid-row: 1; grid-column: 2; }
  .pb-c-gauge { grid-row: 2; grid-column: 1 / -1; } .pb-c-coin { grid-row: 3; grid-column: 1; } .pb-pause { grid-row: 3; grid-column: 2; }
  .pb-card { padding: 6px 12px; gap: 4px; border-radius: 16px; box-shadow: 0 4px 0 rgba(43,27,23,.2); }
  .pb-lab { font-size: 13px; }
  .pb-scoreN { font-size: 30px; }
  .pb-timeN { font-size: 20px; }
  .pb-coinN { font-size: 24px; }
  .pb-coinico, .pb-petico { width: 28px; height: 28px; }
  .pb-c-gauge { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 12px; }
  .pb-c-gauge .pb-row { flex: 1 1 180px; }
  .pb-frame { padding: 10px; border-radius: 26px; }
  .pb-board { border-radius: 14px; }
  /* v1.1 펫 머지: 카드 줄을 판 아래로 (2칸 격자). 판 크기는 js/merge.js layout 이 남은 높이로 계산 */
  .pm-root { flex-direction: column; align-items: center; row-gap: 8px; }
  .pm-boardcol { height: auto; }
  .pm-side { width: 100%; max-width: 560px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .pm-side .pb-card { padding: 6px 10px; gap: 4px; border-radius: 14px; box-shadow: 0 4px 0 rgba(43,27,23,.2); }
  .pm-side .pb-lab { font-size: 13px; }
  .pm-side .pb-scoreN { font-size: 26px; }
  .pm-c-chain, .pm-c-opp { grid-column: 1 / -1; }
  .pm-chain img { width: calc(14px + var(--i) * 1.8px); }
  .pm-nextImg { width: 32px; height: 32px; }
  .pm-oppCv { width: 64px; }
  .pm-pause { display: none; }   /* 좁은 화면은 위 바의 '일시정지' 버튼을 쓴다 — 판을 더 크게 */
}
@media (max-width: 900px) and (hover: none) {
  .pb-pause kbd { display: none; }
}
/* 폰 세로: 무대를 낮게 · 간식타임 판은 세로로 긴 판(10×17)이 화면 높이에 들어가게 */
@media (max-width: 560px) {
  .stage-card { height: 96px; flex-basis: 32%; }
  .combo-n { font-size: 40px; -webkit-text-stroke-width: 1.5px; text-shadow: 0 3px 0 var(--ink); }
  .combo-l { font-size: 15px; }
  .stage-chip { font-size: 12px; padding: 2px 8px; border-width: 2px; }
  .fever-gauge { height: 20px; }
  .fever-gauge .fever-text, .fever-text { font-size: 12px; }
  .mult-row { font-size: 12px; }
  .mult-n { font-size: 20px; }
  /* 세로로 긴 판(10×17): 판 높이 ≈ 폭 × 1.7 + 위 점수줄 → 화면 높이에 맞는 폭 */
  .st-app { width: min(100%, calc((100dvh - var(--bar-h) - 250px) * .588 + 44px)); }
  .st-app .fb-root { border-image-width: 30px; border-image-outset: 6px; padding: 12px 10px; }
  .st-app .fb-hud { margin-bottom: 6px; row-gap: 4px; }
  .st-app .fb-board { border-width: 4px; padding: 4px; border-radius: 16px; }
  .st-app .fb-score b { font-size: 22px; }
  .st-app .fb-time { font-size: 18px; }
  .st-app .fb-sel-sum { font-size: 13px; top: -24px; }
  .st-app .fb-float { font-size: 20px; }
  /* v1.2.1 결과 '최고 동물' 칸: 좁은 칸에서 이름이 밖으로 삐져나가지 않게 (그림 위 · 이름 아래, 글자 작게) */
  .res-tier { flex-direction: column; gap: 0; font-size: 0.78em; white-space: normal; line-height: 1.1; }
  /* v1.2.1 업적 알림: 좁은 폰에서 글자가 한 글자씩 줄바꿈되던 것 → 화면 폭까지 넓게 · 글자 작게 */
  .toast.ach-toast { width: max-content; max-width: calc(100vw - 24px); font-size: 15px; border-radius: 22px; padding: 6px 14px 6px 8px; gap: 8px; }
  .ach-toast .ach-ti { width: 28px; height: 28px; font-size: 16px; flex: none; }
  .ach-toast b { flex: none; }
  /* v1.2.1 펫 머지 폰 세로: 진화 순서 카드를 한 줄로(이름표 옆에 얼굴) → 상자를 더 크게 */
  .pm-c-chain { flex-direction: row; align-items: center; gap: 8px; }
  .pm-c-chain .pb-lab { flex: none; }
  .pm-c-chain .pm-chain { flex: 1; min-width: 0; flex-wrap: nowrap; justify-content: space-between; gap: 2px; }
  .pm-side .pb-scoreN { font-size: 22px; }
}
/* v1.2.1 펫 머지 · 짧은 폰(아이폰 SE·일반 아이폰 사파리 등): 캐릭터 무대를 숨기고 콤보 카드만 납작하게 → 상자 폭 확보 */
@media (max-width: 560px) and (max-height: 760px) {
  body[data-game="merge"] .stage-card { display: none; }
  body[data-game="merge"] .stage-info { padding: 6px 12px; gap: 3px; }
  body[data-game="merge"] .mult-row { display: none; }
  body[data-game="merge"] .combo-n { font-size: 30px; }
  body[data-game="merge"] .fever-gauge { height: 19px; }
  body[data-game="merge"] .fever-gauge .fever-text { font-size: 11px; line-height: 15px; }
  body[data-game="merge"] .game { gap: 6px; padding-top: 6px; }
  .pm-root { row-gap: 6px; }
  .pm-side { gap: 5px; }
  .pm-side .pb-card { padding: 4px 10px; gap: 2px; }
  .pm-side .pb-scoreN { font-size: 20px; }
  .pm-nextImg { width: 26px; height: 26px; }
}
/* 폰 가로(낮은 화면): 무대는 숨기고 콤보 카드만 왼쪽에 좁게 */
@media (max-height: 520px) and (orientation: landscape) {
  .game { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 8px; padding: 6px 10px 8px; }
  .stage-host { flex-direction: column; }
  .stage-card { display: none; }
  .stage-info { padding: 8px 10px; }
  .combo-n { font-size: 36px; }
  .game-keys { display: none; }
  .st-app { width: min(100%, calc((100dvh - var(--bar-h) - 120px) * 1.62 + 32px)); }
  .pb-root { flex-direction: row; column-gap: 10px; }
  .pb-side { width: 200px; grid-template-columns: 1fr; grid-template-rows: none; gap: 6px; }
  .pb-c-score, .pb-c-time, .pb-c-gauge, .pb-c-coin, .pb-pause { grid-row: auto; grid-column: auto; }
  .pb-c-gauge .pb-fav { display: none; }
  /* v1.2.1 펫 머지 폰 가로: 카드는 상자 옆에 세로로 (위아래로 쌓으면 상자가 너무 작아짐) */
  .pm-root { flex-direction: row; align-items: center; column-gap: 10px; }
  .pm-side { width: 170px; grid-template-columns: 1fr; gap: 5px; }
  .pm-c-chain { display: none; }
}
/* 결과 화면: 카드가 화면보다 길면 위에서부터 놓고 스크롤 (폰 가로 · 작은 폰) */
@media (max-height: 760px) and (max-width: 1100px), (max-width: 560px) {
  #scene-result { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #scene-result .result-bg { position: fixed; inset: var(--bar-h) 0 0 0; }
  .result-card { position: relative; left: auto; top: auto; transform: none; margin: 14px auto 90px; animation-name: popInFlow; }
  @keyframes popInFlow { from { opacity: 0; transform: translateY(4%) scale(.9); } }
}
/* 폰 가로: 상단 바를 낮게 */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --bar-h: 48px; }
  #topbar { gap: 8px; padding: 0 10px; }
  .logo img.logo-art { height: 30px; }
  .pill { height: 32px; font-size: 15px; padding: 0 9px 0 5px; }
  .pill img { width: 22px; height: 22px; }
  .bar-right { gap: 6px; }
  body[data-scene="game"] .bar-title { max-height: 28px; }
  .result-card { padding: 22px 26px 24px; border-image: url("ui/frame.webp") 120 fill / 34px stretch; }
}
/* 게임 방법 안내 · 1:1 배틀 점수판 (좁은 화면) */
@media (max-width: 900px) {
  body[data-battle] .game { padding-top: 54px; }
  /* left:50% 이면 줄어들 수 있는 폭이 화면 절반뿐이라 글자가 겹침 → 양쪽 0 + 가운데 맞춤 */
  .battle-hud { left: 0; right: 0; transform: none; margin: 0 auto; width: max-content; top: 6px; gap: 8px; padding: 4px 12px; max-width: calc(100vw - 16px); border-width: 2.5px; }
  .battle-hud b { font-size: 19px; }
  .battle-hud .bh-name { max-width: 6ch; font-size: 13px; }
  .battle-hud .bh-pet { width: 26px; height: 26px; }
}
@media (max-width: 560px) {
  .howto { padding: 8px; }
  .howto-card { padding: 26px 18px 22px; border-image: url("ui/frame.webp") 120 fill / 34px stretch; }
  .howto-title { height: 56px; }
  .howto-steps li { grid-template-columns: 28px minmax(0, 1fr); grid-template-areas: "n art" "n t"; gap: 4px 10px; padding: 8px 10px; }
  .howto-steps .ht-n { grid-area: n; } .howto-steps .ht-art { grid-area: art; justify-content: flex-start; min-height: 0; } .howto-steps .ht-t { grid-area: t; }
  .ht-t { font-size: 14px; }
  .ht-jelly { width: 28px; height: 28px; }
  .ht-ten { font-size: 22px; }
  .ht-title { height: 34px; }
  .ht-line i { width: 13px; height: 13px; }
  .battle-hud .bh-live, .battle-hud .bh-name { display: none; }   /* 폰: 이름 대신 펫 그림으로 구분 */
  .battle-hud { gap: 12px; }
  .battle-hud b { min-width: 0; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .pb-card { padding: 4px 10px; gap: 2px; }
  .pb-scoreN { font-size: 24px; }
  .pb-coinN { font-size: 20px; }
  .pb-side { gap: 5px; }
  body[data-battle] .game { padding-top: 6px; }
  .battle-hud { left: auto; right: 10px; margin: 0; top: auto; bottom: 8px; }
}

/* ======================= v1.3 폰 세로 로비 = 모바일 게임형 =======================
 *  위에서부터: 함께하는 친구(가운데) → 게임 카드 3D 캐러셀(js/carousel.js, 손가락으로 옆으로) → 아이콘 메뉴 줄 → 아래 고정 바(사이트 링크 + 공유)
 *  carousel.js 의 QUERY 와 같은 조건 */
@media (max-width: 560px) and (orientation: portrait) {
  :root { --navh: 46px; --safe-b: env(safe-area-inset-bottom, 0px); }
  #scene-main { overscroll-behavior: none; }
  .main { min-height: 100%; gap: 10px; padding: 0 12px calc(var(--navh) + var(--safe-b) + 12px); justify-content: flex-end; }
  .main-left { flex: 1 1 auto; justify-content: center; min-height: 170px; }
  .pet-spot { margin-top: 36px; }
  /* 함께하는 친구: 이름 + 바꾸기 아이콘(⇄)만 */
  .pet-tag { margin-top: 20px; padding: 3px 4px 3px 16px; gap: 10px; }
  .pet-tag > span { display: none; }
  .pet-tag b { font-size: 18px; }
  .pet-tag i { font-size: 0; width: 32px; height: 32px; padding: 0; border-radius: 50%; flex: none;
    background: var(--butter) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232B1B17' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 8.5h14l-4-4'/%3E%3Cpath d='M20 15.5H6l4 4'/%3E%3C/svg%3E") center / 19px no-repeat; }
  .main-right { gap: 10px; }

  /* 게임 카드 캐러셀: 가운데 1장 크게 · 양옆은 돌아간 채 살짝 보임 */
  .cards.carousel { display: block; position: relative; margin: 0 -12px; perspective: 900px; perspective-origin: 50% 45%; transform-style: preserve-3d; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
  .cards.carousel { pointer-events: none; }   /* 뒤로 들어간(translateZ) 옆 카드가 상자에 가려 안 눌리던 것 → 카드만 누름 */
  .cards.carousel .game-card { pointer-events: auto; position: absolute; left: 50%; top: 0; width: 64%; margin-left: -32%; will-change: transform; backface-visibility: hidden;
    transition: transform .42s cubic-bezier(.2,.85,.25,1.05), opacity .3s, box-shadow .2s; }
  .cards.carousel.cr-dragging .game-card { transition: none; }
  .cards.carousel .game-card:hover { box-shadow: 0 5px 0 var(--ink); }
  .cards.carousel .game-card:active { box-shadow: 0 5px 0 var(--ink); }
  .cards.carousel .game-card.cr-front:active { box-shadow: 0 2px 0 var(--ink); }
  .cards.carousel .game-card:not(.cr-front) { filter: saturate(.8) brightness(.96); }
  .cards.carousel .game-card .gc-go { display: block; right: 10px; top: 10px; width: 44px; height: 44px; opacity: 0; transform: scale(.6); transition: opacity .25s, transform .25s; }
  .cards.carousel .game-card .gc-go::before { left: 15px; top: 10px; border-width: 9px 0 9px 14px; }
  .cards.carousel .game-card.cr-front .gc-go { opacity: 1; transform: none; animation: crPlay 1.6s ease-in-out .4s infinite; }
  @keyframes crPlay { 50% { transform: scale(1.1); } }
  .cards.carousel .game-card .gc-desc { white-space: normal; }
  .cards.carousel .game-card .gc-thumb { aspect-ratio: 16 / 8.5; }
  .cr-dots { display: flex; justify-content: center; gap: 7px; margin-top: -2px; }
  .cr-dot { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 999px; background: rgba(43,27,23,.25); cursor: pointer; transition: width .25s, background .25s; }
  .cr-dot.on { width: 22px; background: var(--ink); }

  /* 메뉴 = 아이콘만 (글자는 화면 읽기용으로만 남김) · 알림은 빨간 점 */
  .subs { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
  .subs .sub-btn { height: 58px; padding: 0; gap: 0; border-radius: 18px; justify-content: center; align-items: center; }
  .subs .sub-btn > img, .subs .sub-btn > .sub-ico { width: 40px; height: 40px; font-size: 30px; transform: none; }
  .subs .sub-btn:hover > img, .subs .sub-btn:hover > .sub-ico { transform: none; }
  .subs .sub-btn:active > img, .subs .sub-btn:active > .sub-ico { transform: scale(.9); }
  .subs .sub-btn > span:not(.sub-ico), :lang(ja) .subs .sub-btn > span:not(.sub-ico), :lang(en) .subs .sub-btn > span:not(.sub-ico) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .subs .sub-btn em:not(:empty):not(.test-badge) { font-size: 0; width: 15px; height: 15px; padding: 0; right: -3px; top: -4px; border-radius: 50%; background: #FF4D6D; border-width: 2.5px; }
  .subs .sub-btn em.test-badge { font-size: 9px; padding: 0 5px; right: -2px; top: -8px; }   /* 1:1 배틀 'Test' 표시는 글자 그대로 (알림 점 아님) */

  /* 아래 고정 바: 사이트 링크(옆으로 밀어서 보기) + 오른쪽 공유 */
  .lobby-links { left: 0; right: 0; bottom: 0; height: calc(var(--navh) + var(--safe-b)); padding: 0 62px var(--safe-b) 14px; z-index: 35;
    display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: 16px; overflow-x: auto; scrollbar-width: none; white-space: nowrap;
    background: var(--paper); border-radius: 20px 20px 0 0; border-top: 2.5px solid var(--ink); box-shadow: 0 -3px 0 rgba(43,27,23,.08); font-size: 13px; }
  .lobby-links::-webkit-scrollbar { display: none; }
  .lobby-links a { flex: none; }
  body[data-scene="main"] .fab-share { bottom: calc(var(--safe-b) + 3px); right: 8px; width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 50%; z-index: 41; box-shadow: 0 3px 0 var(--ink); }
  body[data-scene="main"] .fab-share > span:not(.fab-ico):not([aria-hidden]) { display: none; }
  body[data-scene="main"] .fab-share .fab-ico, body[data-scene="main"] .fab-share > span[aria-hidden] { width: 24px; height: 24px; }
  /* 접속자 수: 메뉴 아이콘을 가리지 않게 화면 위 왼쪽(상단 바 아래 빈 하늘)으로 */
  #liveCount { top: calc(var(--bar-h) + 10px); bottom: auto; left: 10px; font-size: 12px; z-index: 6; }
}

/* ======================= v1.3 폰 세로 게임 화면 = 게임판 최우선 =======================
 *  캐릭터 무대는 빼고(세 게임 통일) 콤보는 얇은 한 줄 HUD: [콤보 수][피버 게이지 ─────][×배율]
 *  남은 높이는 전부 게임판에 (간식타임 판 폭 · 펫블록 판 · 펫 머지 상자는 각 엔진이 남은 칸에 맞춤) */
@media (max-width: 560px) and (orientation: portrait) {
  .game { gap: 6px; padding: 6px 8px 8px; }
  .stage-host { gap: 0; }
  .stage-card, body[data-game="merge"] .stage-card { display: none; }
  .stage-info, body[data-game="merge"] .stage-info { position: relative; display: flex; align-items: center; gap: 8px; padding: 5px 12px 7px; border-radius: 16px; overflow: hidden; }
  .combo-row { flex: none; align-items: center; gap: 4px; }
  .combo-n, body[data-game="merge"] .combo-n { font-size: 28px; -webkit-text-stroke-width: 1.2px; text-shadow: 0 2px 0 var(--ink); min-width: 1.1ch; }
  .combo-l { font-size: 13px; }
  .stage-chip { display: none; }
  .combo-window { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; margin: 0; border: 0; border-radius: 0; background: transparent; }
  .fever-gauge, body[data-game="merge"] .fever-gauge { flex: 1; min-width: 0; height: 20px; border-width: 2px; }
  .fever-gauge .fever-text, .fever-text, body[data-game="merge"] .fever-gauge .fever-text { font-size: 11px; line-height: 16px; }
  .mult-row, body[data-game="merge"] .mult-row { display: flex; flex: none; gap: 0; }
  .mult-row > span { display: none; }
  .mult-n { font-size: 17px; }
  /* 간식타임 세로 판: 무대가 빠진 만큼 더 크게 (판 높이 ≈ 폭 × 1.7 + 점수줄) */
  .st-app { width: min(100%, calc((100dvh - var(--bar-h) - 176px) * .588 + 44px)); }
  .st-app.st-phone { width: min(100%, calc((100dvh - var(--bar-h) - 182px) * .64 + 44px)); }   /* v1.3.2 폰 판 8×13 */
  /* 펫블록: 아래 카드를 납작한 두 줄로 → 판이 화면 폭을 거의 다 씀 (일시정지는 위쪽 바 버튼) */
  .pb-root { row-gap: 6px; }
  .pb-side { grid-template-columns: 1fr 1.25fr 0.9fr; grid-template-rows: auto auto; gap: 5px; }
  .pb-c-score { grid-row: 1; grid-column: 1; } .pb-c-time { grid-row: 1; grid-column: 2; } .pb-c-coin { grid-row: 1; grid-column: 3; }
  .pb-c-gauge { grid-row: 2; grid-column: 1 / -1; }
  .pb-pause { display: none; }
  .pb-side .pb-card { padding: 4px 9px 5px; gap: 1px; border-radius: 14px; }
  .pb-side .pb-lab { font-size: 11px; }
  .pb-side .pb-ico { font-size: 11px; }
  .pb-scoreN { font-size: 20px; }
  .pb-timeN { font-size: 15px; }
  .pb-coinN { font-size: 18px; }
  .pb-coinico, .pb-petico { width: 22px; height: 22px; }
  .pb-c-gauge { flex-direction: row; flex-wrap: nowrap; align-items: center; column-gap: 8px; }
  .pb-c-gauge > .pb-lab { display: none; }
  .pb-c-gauge .pb-row { flex: 1 1 auto; min-width: 0; }
  .pb-c-gauge .pb-fav { flex: none; font-size: 11px; }
  .pb-c-gauge .pb-fav > span { display: none; }
  .pb-c-gauge .pb-fav img { width: 20px; height: 20px; }
  .pb-gN { font-size: 11px; }
  .pb-frame { padding: 7px; border-radius: 22px; }
}
