/* ===== スマホ・タブレット（タッチ操作・狭い画面） ===== */
.screen { height: 100vh; height: 100dvh; }
body.touch { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
body.touch #game, body.touch #b-grid, body.touch #b-list, body.touch .mgrid { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch img { -webkit-touch-callout: none; }
.m-only { display: none !important; }

/* タッチ端末ではホバーの拡大を止める（指を離しても拡大したままになるため） */
@media (hover: none) {
  .row.hand .card:hover, .row.field .card:hover, .row.land .card:hover, .row.hand .card.playable:hover { transform: none; }
  #b-grid .bc:hover, .dc:hover, .mgrid .mc:hover, .mode-card:hover { transform: none; }
  .dc .pm { opacity: 1; }
  button::after { display: none; }
  body.touch button { min-height: 36px; }
  body.touch #ctxmenu .mi { padding: 11px 14px; font-size: 14px; }
  body.touch #ctxmenu { min-width: 220px; }
}

/* タッチ用のボタン（詳細・ログ・設定） */
#m-bar { position: fixed; z-index: 75; display: flex; gap: 6px; }
#m-bar button { padding: 4px 10px; min-height: 32px; font-size: 12px; border-radius: 16px; background: rgba(12, 16, 28, .88); border: 1px solid var(--line2); }
#m-bar button.on { background: linear-gradient(180deg, #ffe7a1, #c8952f); color: #1d1405; }
.m-close { margin-left: auto; padding: 2px 12px !important; min-height: 30px; font-size: 16px; }

/* ----- メニュー ----- */
@media (max-width: 700px), (max-height: 560px) {
  #menu { align-items: flex-start; overflow-y: auto; padding: 14px 0 24px; }
  .title-wrap { gap: 12px; }
  .logo .jp { font-size: clamp(26px, 8vw, 44px); }
  .logo .en { font-size: 11px; letter-spacing: .3em; }
  .logo .sub { font-size: 11px; }
  .menu-box { padding: 14px 14px 12px; }
  .menu-grid { grid-template-columns: 1fr; gap: 4px 0; }
  .menu-grid > label { margin-top: 6px; }
  .menu-grid select { width: 100%; min-height: 38px; font-size: 15px; }
  .mode-cards { gap: 6px; }
  .mode-card { padding: 10px 4px 8px; }
  .mode-card .t { font-size: 13px; }
  .menu-buttons { flex-wrap: wrap; }
  .menu-buttons button { flex: 1; padding: 11px 10px; }
  .menu-buttons #btn-start { padding: 12px 10px; font-size: 17px; flex-basis: 100%; }
  .menu-foot { flex-direction: column; align-items: flex-start; gap: 8px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .title-wrap { width: min(860px, 96vw); display: grid; grid-template-columns: 1fr 1.6fr; align-items: center; }
}

/* ----- ダイアログ ----- */
@media (max-width: 700px), (max-height: 560px) {
  .mbox { padding: 10px; max-height: 94dvh; width: 97vw; }
  .mbox h3 { font-size: 15px; }
  .mgrid { gap: 6px; padding: 4px; }
  .mgrid .mc, .mgrid .mc img { width: 78px; }
  .mbody { grid-template-columns: 1fr; }
  .mdetail { max-height: 26dvh; }
  .mdetail img { max-width: 120px; }
  .mbtns { flex-wrap: wrap; }
  .mbtns button { flex: 1; min-height: 40px; }
  .mform { grid-template-columns: 1fr; }
  .fx-banner { min-width: 0; width: 92vw; padding: 12px 20px; }
  .fx-banner .bm { font-size: 26px; }
  .fx-end { font-size: 60px; }
  .rs-big { font-size: 40px; }
}

/* ----- 対戦画面: スマホ縦・タブレット縦 -----
   盤面を最大に。下は「操作欄（親指の届くところ）」と、その下の細いボタン列だけ。 */
@media (max-width: 900px) and (orientation: portrait) {
  :root {
    /* 1人分 = 情報欄 + 戦場 + 領地 + 手札。上下2人ぶんと中央バーを引いた残りを5.8等分 */
    --ch: clamp(34px, calc((100dvh - 300px) / 5.8), 150px);
  }
  #game { display: flex; flex-direction: column; }
  #game.tilt #plane, #plane { transform: none; height: 100%; margin-top: 0; }
  #board { flex: 1; min-height: 0; }
  #panel { flex: none; display: flex; flex-direction: column; max-height: 34dvh; padding-bottom: calc(46px + env(safe-area-inset-bottom, 0px)); border-left: none; border-top: 1px solid var(--line2); box-shadow: 0 -6px 20px rgba(0, 0, 0, .5); overflow: hidden; }
  #topbar { display: none; }
  #counts { display: none; }
  #log { display: none; }
  /* パイル（積まれた効果）は、あるときだけ操作欄の上に出す */
  #pile { order: -1; max-height: 12dvh; padding: 4px 8px; font-size: 12px; }
  #pile:not(:has(.item)) { display: none; }
  #prompt { order: 0; min-height: 0; padding: 8px 10px 10px; flex: 0 1 auto; overflow: auto; max-height: 26dvh; }
  #prompt .ptitle { font-size: 13px; margin-bottom: 4px; }
  #prompt .hint { display: none; }
  #prompt .btns { gap: 8px; }
  #prompt .btns button { min-height: 46px; padding: 8px 14px; flex: 1 1 40%; font-size: 15px; }
  #prompt > button, #prompt .mode-btn { min-height: 46px; }
  #online-bar { padding: 4px 8px; font-size: 11px; }
  /* 詳細は下から出るシート */
  #detail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; max-height: 58dvh; z-index: 85; border-right: none; border-top: 1px solid var(--line2); border-radius: 16px 16px 0 0; transform: translateY(105%); transition: transform .25s ease; box-shadow: 0 -10px 40px rgba(0, 0, 0, .8); padding-bottom: env(safe-area-inset-bottom, 0px); }
  body.m-detail #detail { transform: none; }
  #detail .dhead { display: flex; align-items: center; }
  #detail #preview { flex-direction: row; overflow: auto; padding: 10px; gap: 10px; }
  #detail #preview img { width: 36vw; max-width: 220px; align-self: flex-start; }
  #detail #preview .ptext { font-size: 12px; }
  .pempty::before { display: none; }
  /* ログ（＋カウント）は重ねて表示 */
  body.m-log #log { display: block; position: fixed; left: 3vw; right: 3vw; top: calc(8dvh + 96px); bottom: calc(52px + env(safe-area-inset-bottom, 0px)); z-index: 80; border: 1px solid var(--line2); border-radius: 0 0 12px 12px; background: rgba(8, 11, 20, .97); box-shadow: 0 10px 40px rgba(0, 0, 0, .8); }
  body.m-log #counts { display: block; position: fixed; left: 3vw; right: 3vw; top: 8dvh; height: 96px; overflow: auto; z-index: 80; border: 1px solid var(--line2); border-radius: 12px 12px 0 0; background: rgba(8, 11, 20, .97); }
  body.m-opts #topbar { display: flex; position: fixed; right: 6px; bottom: calc(52px + env(safe-area-inset-bottom, 0px)); z-index: 82; width: min(340px, 94vw); flex-direction: column; align-items: flex-start; gap: 6px; border: 1px solid var(--line2); border-radius: 12px; background: rgba(8, 11, 20, .98); padding: 10px; }
  body.m-opts #topbar label { min-height: 30px; display: inline-flex; align-items: center; }
  /* 下のボタン列（親指で押す） */
  #m-bar { left: 0; right: 0; bottom: 0; top: auto; height: calc(46px + env(safe-area-inset-bottom, 0px)); padding: 4px 162px calc(4px + env(safe-area-inset-bottom, 0px)) 6px; gap: 6px; background: rgba(6, 8, 16, .98); border-top: 1px solid var(--line2); z-index: 76; }
  #m-bar button { flex: 1 1 0; min-height: 38px; border-radius: 10px; font-size: 13px; padding: 2px 4px; }
  #m-bar button[data-m="m-opts"] { flex: 0 0 48px; }
  /* 対応・領土ボタン（盤面の中に置かれている）は、下のボタン列の右端に出す。
     fixed が盤面の遠近（perspective）に捕まらないよう、縦画面では遠近を切る */
  #board { perspective: none; }
  #board > .respond-btn { position: fixed; right: 6px; bottom: calc(5px + env(safe-area-inset-bottom, 0px)); min-width: 0; width: 74px; height: 38px; padding: 0 4px; z-index: 78; border-radius: 10px; justify-content: center; gap: 0; }
  #board > .land-btn { right: 84px; }
  #board > .respond-btn small { letter-spacing: 0; font-size: 10px; }
  #board > .respond-btn b { font-size: 14px; }
  /* 盤面 */
  .side { padding: 1px 3px; gap: 2px; }
  .row { gap: 3px; padding: 1px 2px; border-radius: 8px; min-height: 0; }
  .row.field { min-height: calc(var(--ch) + 8px); }
  .row.land { min-height: calc(var(--lh) + 4px); }
  .row.hand { min-height: calc(var(--hh) + 4px); gap: 0; }
  .row.hand .slot ~ .slot { margin-left: calc(var(--hw) * -.2); }
  .row .rlabel { display: none; }
  .pinfo { gap: 6px; padding: 2px 6px 2px 4px; min-height: 32px; font-size: 11px; overflow-x: auto; }
  .pinfo > * { flex-shrink: 0; }
  .pinfo .pname { font-size: 12px; max-width: 24vw; overflow: hidden; text-overflow: ellipsis; }
  .pinfo .life { font-size: 17px; height: 26px; min-width: 42px; padding: 0 6px; }
  .pinfo .life::before { font-size: 11px; margin-right: 3px; }
  .pinfo .zc { font-size: 10px; } .pinfo .zc b { font-size: 12px; }
  .pinfo button { min-height: 28px; padding: 1px 7px; font-size: 11px; }
  .side.top .pinfo { margin-right: 0; }
  #midbar { min-height: 28px; padding: 2px 4px; gap: 2px; overflow-x: auto; justify-content: flex-start; }
  #midbar .turn { font-size: 11px; margin-right: 4px; }
  #midbar .ph { font-size: 10px; padding: 2px 8px 2px 11px; }
  .card .pt { font-size: 10px; padding: 0 3px; bottom: -4px; right: -3px; }
  .card .kwb span, .card .ctrs span, .card .eqb, .card .cpb { font-size: 8px; }
  .card.sick::before, .card.swift::before, .card.quick::before { font-size: 8px; }
  .card .dmg { font-size: 10px; top: 8px; }
}

/* ----- 縦画面: ダイアログは下から出るシート ----- */
@media (max-width: 900px) and (orientation: portrait) {
  #modal:has(.mbox:not(.result)) { align-items: flex-end; }
  body:has(#modal:not(.hidden)) #m-bar, body:has(#modal:not(.hidden)) #board > .respond-btn { display: none !important; }
  .mbox:not(.result) { width: 100vw !important; max-width: none; max-height: 90dvh; border-radius: 18px 18px 0 0; border-bottom: none; padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); animation: sheet-up .25s ease-out; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
  .mbox h3 { font-size: 15px; line-height: 1.4; }
  .mbox .hint { font-size: 11px; }
  .mbody { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
  .mbody .mgrid { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px 6px; align-content: start; padding: 4px; }
  .mgrid .mc, .mgrid .mc img { width: 100%; }
  .mgrid .mc .cap { font-size: 10px; }
  .mgrid .mc .mz { padding: 0 6px; line-height: 24px; }
  .mdetail { flex: none; max-height: 24dvh; flex-direction: row; align-items: flex-start; }
  .mdetail:has(.pempty) { display: none; }
  .mdetail img { width: 30vw; max-width: 130px; align-self: flex-start; }
  .mbtns { flex: none; flex-wrap: wrap; gap: 8px; }
  .mbtns .info { flex: 1 1 100%; margin-right: 0; font-size: 12px; }
  .mbtns button { flex: 1; min-height: 46px; font-size: 15px; }
  #ctxmenu { max-width: 94vw; }
  body.touch #ctxmenu .mi { padding: 13px 16px; font-size: 15px; white-space: normal; }
}

/* ----- 対戦画面: スマホ横（高さが低い） ----- */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --ch: clamp(30px, calc((50dvh - 52px) / 2.9), 90px); }
  #game { display: grid; grid-template-columns: 1fr minmax(200px, 30vw); }
  #game.tilt #plane, #plane { transform: none; height: 100%; margin-top: 0; }
  #topbar { display: none; }
  #prompt { min-height: 0; padding: 6px 8px; max-height: 48dvh; overflow: auto; }
  #prompt .btns button { min-height: 36px; flex: 1 1 auto; }
  #pile { max-height: 22dvh; }
  #detail { position: fixed; left: 0; top: 0; bottom: 0; width: min(46vw, 380px); z-index: 85; transform: translateX(-105%); transition: transform .25s ease; box-shadow: 10px 0 40px rgba(0, 0, 0, .8); }
  body.m-detail #detail { transform: none; }
  #detail .dhead { display: flex; align-items: center; }
  #detail #preview { flex-direction: row; overflow: auto; }
  #detail #preview img { width: 40%; }
  .pempty::before { display: none; }
  body.m-opts #topbar { display: flex; position: fixed; right: 6px; top: 46px; z-index: 82; width: min(320px, 60vw); flex-direction: column; align-items: flex-start; border: 1px solid var(--line2); border-radius: 12px; background: rgba(8, 11, 20, .97); }
  #m-bar { top: 4px; right: calc(max(200px, 30vw) + 6px); }
  #m-bar [data-m="m-log"] { display: none; }
  .side { padding: 1px 3px; gap: 1px; }
  .row { gap: 3px; padding: 0 2px; }
  .row .rlabel { display: none; }
  .pinfo { gap: 6px; padding: 1px 6px 1px 4px; min-height: 26px; font-size: 11px; }
  .pinfo .pname { font-size: 12px; }
  .pinfo .life { font-size: 15px; height: 22px; min-width: 38px; }
  .pinfo button { min-height: 24px; padding: 0 6px; font-size: 10px; }
  .side.top .pinfo { margin-right: 160px; }
  #midbar { min-height: 22px; padding: 1px 4px; overflow-x: auto; justify-content: flex-start; }
  #midbar .ph { font-size: 10px; padding: 1px 8px 1px 11px; }
  .card .pt { font-size: 10px; padding: 0 3px; }
}

/* ----- タブレット横（幅が狭めのとき詳細欄は重ねて表示） ----- */
@media (min-height: 561px) and (max-width: 1180px) and (orientation: landscape) and (hover: none) {
  #game { grid-template-columns: 1fr 300px; }
  #game.tilt #plane { transform: rotateX(10deg); }
  #detail { position: fixed; left: 0; top: 0; bottom: 0; width: 320px; z-index: 85; transform: translateX(-105%); transition: transform .25s ease; box-shadow: 10px 0 40px rgba(0, 0, 0, .8); }
  body.m-detail #detail { transform: none; }
  #detail .dhead { display: flex; align-items: center; }
  #m-bar { top: 6px; right: 306px; }
  .side.top .pinfo { margin-right: 110px; }
}

/* ----- デッキ構築 ----- */
@media (max-width: 900px) {
  #builder { display: flex; flex-direction: column; height: 100dvh; }
  .bd-deck, .bd-pool { flex: 1; min-height: 0; }
  body:not(.b-pool) .bd-pool { display: none; }
  body.b-pool .bd-deck > :not(#b-preview) { display: none; }
  body.b-pool .bd-deck { flex: none; order: 2; border-right: none; border-top: 1px solid var(--line2); }
  body.b-pool #b-preview { height: 22dvh; min-height: 120px; }
  .bd-top { flex-wrap: wrap; padding: 8px 8px 4px; }
  .bd-top #b-name { min-width: 0; font-size: 15px; }
  .bd-top #b-load { max-width: none; flex: 1 1 100%; min-height: 36px; }
  .bd-actions { padding: 0 8px 6px; gap: 4px; }
  .bd-actions button { padding: 6px 9px; min-height: 34px; }
  .bd-stats { padding: 6px 8px; gap: 8px; overflow-x: auto; }
  .bd-cards.img { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
  .dc .pm { padding: 1px; }
  body.touch .dc .pm button { min-height: 0; padding: 0 5px; font-size: 13px; line-height: 22px; }
  .bd-actions button { padding: 4px 8px; min-height: 32px; font-size: 11px; }
  .bd-stats .st-curve { height: 48px; }
  #b-preview:has(.bp-empty) { display: none; }
  #b-list { padding: 4px 8px 8px; }
  #b-preview { height: 26dvh; min-height: 140px; padding: 8px; gap: 8px; }
  .bd-pool .b-filter { padding: 6px 8px; gap: 4px; }
  .bd-pool .b-filter select { min-height: 34px; }
  .bd-pool .b-filter #f-text { min-width: 0; flex: 1 1 100%; min-height: 36px; }
  #b-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; padding: 8px; }
  .bd-help { display: none; }
  #b-tabs { display: flex !important; gap: 0; flex: none; order: -1; border-bottom: 1px solid var(--line2); background: rgba(8, 11, 20, .97); }
  #b-tabs button { flex: 1; border-radius: 0; min-height: 40px; border: none; background: transparent; }
  #b-tabs button.on { background: linear-gradient(180deg, rgba(227, 192, 106, .3), rgba(227, 192, 106, .08)); color: var(--gold3); box-shadow: inset 0 -3px 0 var(--gold); }
}

/* ===== 縦画面（スマホ・タブレット縦）: タイトル ===== */
@media (max-width: 900px) and (orientation: portrait) {
  #menu { justify-content: flex-start; padding: calc(10px + env(safe-area-inset-top, 0px)) 0 0; }
  .title-wrap { width: min(560px, 100vw); gap: 8px; }
  .logo .sub, .logo .en { display: block; }
  .logo .jp { font-size: clamp(30px, 9vw, 52px); margin: 0; }
  .logo .line { display: none; }
  .menu-box { margin: 0 8px; padding: 12px 12px 0; }
  .acct-bar { margin-bottom: 8px; padding: 6px 10px; gap: 8px; }
  .acct-bar button { min-height: 38px; }
  /* 設定は「ラベル｜選択」の1行ずつ。縦に詰めて、スクロールを減らす */
  .menu-grid { display: grid; grid-template-columns: minmax(4.6em, 29%) 1fr; gap: 6px 10px; align-items: center; }
  .menu-grid > label { margin-top: 0; font-size: 12px; line-height: 1.3; }
  .menu-grid select, .menu-grid input, .dpick { min-height: 42px; }
  .dpick { font-size: 13px; padding: 6px 10px; }
  /* 開始ボタンは画面の下に固定。親指で押せる */
  .menu-buttons { position: sticky; bottom: 0; z-index: 5; margin: 10px -12px 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(180deg, rgba(8, 11, 22, 0), rgba(8, 11, 22, .96) 22%); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .menu-buttons .hidden { display: none; }
  .menu-buttons button { min-height: 48px; padding: 8px 6px; }
  .menu-buttons #btn-start, .menu-buttons #btn-install, .menu-buttons #btn-builder { grid-column: 1 / -1; }
  .menu-buttons #btn-start { font-size: 18px; min-height: 54px; }
  .menu-buttons[data-show="online"] #btn-random, .menu-buttons[data-show="online"] #btn-pw { min-height: 54px; }
  .menu-foot { padding-bottom: 6px; }
  .fan-note { margin: 12px 10px calc(16px + env(safe-area-inset-bottom, 0px)); font-size: 10.5px; }
}
@media (max-width: 900px) and (orientation: portrait) and (max-height: 760px) {
  .logo .en, .logo .sub { display: none; }
}

/* ===== 縦画面: デッキ構築 =====
   上＝今見ているタブの中身、いちばん下＝タブ切り替え（親指で押す）。
   カード一覧タブでも「追加先」と「画像/リスト」の切り替えが残る。 */
@media (max-width: 900px) and (orientation: portrait) {
  #builder { padding-bottom: 0; }
  #b-tabs { order: 99 !important; border-bottom: none !important; border-top: 1px solid var(--line2); padding-bottom: env(safe-area-inset-bottom, 0px); }
  #b-tabs button { min-height: 52px !important; font-size: 14px; font-weight: 700; white-space: nowrap; padding: 0 6px; }
  #b-tabs button[data-t="pool"] { flex: 1.7; }
  .bd-deck { order: 1; }
  body:not(.b-pool) .bd-deck { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
  body:not(.b-pool) .bd-deck > #b-list { flex: none; overflow: visible; min-height: 40dvh; }
  body:not(.b-pool) .bd-deck > #b-preview { position: sticky; bottom: 0; z-index: 6; height: 27dvh; min-height: 150px; background: #0b0f1c; }

  .bd-pool { order: 0; }
  /* デッキタブ */
  .bd-top { gap: 6px; padding: 8px 8px 4px; flex-wrap: wrap; }
  .bd-top #b-back { min-height: 40px; }
  .bd-top #b-name { flex: 1 1 0; min-height: 40px; }
  .bd-top #b-load { flex: 1 1 100%; min-height: 40px; max-width: none; }
  .bd-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 8px 8px; }
  .bd-actions > * { flex: none; white-space: nowrap; }
  .bd-target { order: -2; flex: 1 1 100%; justify-content: space-between; gap: 8px !important; font-size: 12px; }
  .bd-view { flex: 1 1 100%; order: 5; justify-content: flex-end; }
  .bd-actions button { min-height: 38px; padding: 6px 12px; font-size: 13px; }
  .bd-target, .bd-view { margin-left: 0; }
  .bd-actions button { flex: 1 1 auto; }
  .bd-target { padding: 2px 10px; gap: 12px; min-height: 38px; }
  .bd-target label, .bd-view label { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; font-size: 13px; }
  .bd-view { gap: 12px; align-items: center; }
  .bd-stats { padding: 4px 8px; }
  .bd-cards.img { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .bd-cards .bd-empty { grid-column: 1 / -1; }
  .dc .n { font-size: 14px; padding: 0 7px; }
  .dc .pm { opacity: 1; padding: 2px; }
  body.touch .dc .pm button { min-height: 26px; min-width: 28px; line-height: 26px; font-size: 16px; padding: 0 6px; background: rgba(8, 11, 20, .8); }
  /* カード一覧タブ: 上＝フィルター、中＝一覧、下＝追加先の切り替え */
  body.b-pool .bd-deck { flex: none; }
  body.b-pool .bd-deck > .bd-actions { display: flex !important; }
  body.b-pool .bd-deck .bd-actions > button { display: none; }
  body.b-pool .bd-deck .bd-view { display: none; }
  body.b-pool .bd-deck .bd-target { flex: 1 1 auto; order: 0; }
  body.b-pool .bd-deck > #b-preview:has(.bp-empty) { display: none; }
  body.b-pool .bd-deck .bd-actions { flex-wrap: wrap; padding: 6px 8px; border-bottom: none; border-top: 1px solid var(--line2); }
  body.b-pool .bd-deck > .bd-top, body.b-pool .bd-deck > .bd-stats, body.b-pool .bd-deck > #b-errors, body.b-pool .bd-deck > #b-list { display: none; }
  body.b-pool .bd-deck > #b-preview { display: flex; }
  body.b-pool #b-preview { height: 20dvh; min-height: 110px; }
  .bd-pool .b-filter { flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding: 6px 8px; scrollbar-width: none; }
  .bd-pool .b-filter::-webkit-scrollbar { display: none; }
  .bd-pool .b-filter > * { flex: none; }
  .bd-pool .b-filter #f-text { flex: none; width: 46vw; min-width: 0; min-height: 40px; }
  .bd-pool .b-filter select { min-height: 40px; }
  .bd-pool .b-filter label { white-space: nowrap; min-height: 32px; display: inline-flex; align-items: center; }
  .bd-pool .f-colors { display: inline-flex; gap: 4px; }
  #f-count { font-size: 12px; white-space: nowrap; }
  #b-grid { grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px 6px; padding: 8px; }
  #b-preview { height: 24dvh; }
}
@media (min-width: 700px) and (max-width: 900px) and (orientation: portrait) {
  .row.field, .row.land, .row.hand { justify-content: safe center; }
  .bd-cards.img { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  #b-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
  .menu-grid { grid-template-columns: 11em 1fr; gap: 10px 14px; }
  .menu-grid > label { font-size: 14px; }
  .menu-grid select, .menu-grid input, .dpick { min-height: 50px; font-size: 16px; }
  .title-wrap { width: min(700px, 92vw); gap: 16px; }
  #menu { padding-top: 5dvh; }
  .logo .jp { font-size: 64px; }
  .menu-box { padding: 18px 22px 0; }
  .menu-buttons { margin: 14px -22px 0; padding: 12px 22px 14px; }
  .menu-buttons button { min-height: 56px; font-size: 16px; }
  .mode-card { padding: 14px 6px 12px; }
  .mode-card .t { font-size: 15px; }
  .fan-note { font-size: 12px; }
}

/* 縦画面: 装備先の表示（装備→〇〇）がフェイズのバーや列の端に隠れないよう、カードの内側に出す */
@media (max-width: 900px) and (orientation: portrait) {
  .card .eqb { top: 2px; right: 2px; left: 2px; z-index: 6; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
}

/* 縦画面: 操作欄が伸びて盤面が低くなっても、上の列がフェイズのバーの下に潜らないよう、
   カードの大きさを盤面の実際の高さから決める（1人分 ≒ 戦場 + 領地 + 手札 = 2.87枚分 + 情報欄） */
@media (max-width: 900px) and (orientation: portrait) {
  #board { container-type: size; }
  #plane {
    --ch: clamp(30px, calc((100cqh - 170px) / 5.8), 150px); --cw: calc(var(--ch) * .716);
    --hh: calc(var(--ch) * 1.05); --hw: calc(var(--hh) * .716);
    --lh: calc(var(--ch) * .82); --lw: calc(var(--lh) * .716);
  }
}

/* 上からフリックしたときの「引っぱって更新」を止める */
html, body { overscroll-behavior-y: none; }

/* トップ画面: 画面全体はスクロールさせず、操作の箱の中だけをスクロールする */
@media (max-height: 560px) and (orientation: landscape) {
  #menu { overflow: hidden !important; justify-content: flex-start !important; padding: 8px 10px !important; height: 100dvh; box-sizing: border-box; }
  #menu .title-wrap { display: grid; grid-template-columns: 1fr 1.7fr; width: min(920px, 98vw); height: calc(100dvh - 16px); align-items: stretch; gap: 14px; margin: 0 auto; }
  #menu .title-wrap > .logo { align-self: center; padding-bottom: 80px; }
  #menu .menu-box { min-height: 0; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; margin: 0 !important; }
  #menu .rp-top { position: fixed; z-index: 3; left: 10px; bottom: 58px; width: calc(min(920px, 98vw) * .37 - 14px); margin: 0; }
  #menu .fan-note { position: fixed; z-index: 3; left: 10px; bottom: 6px; width: calc(min(920px, 98vw) * .37 - 14px); margin: 0; padding: 0; font-size: 9px; line-height: 1.45; }
}
@media (max-width: 900px) and (orientation: portrait) {
  #menu { overflow: hidden !important; justify-content: flex-start !important; height: 100dvh; box-sizing: border-box; padding-top: 8px !important; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important; }
  #menu .title-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  #menu .title-wrap > .logo { flex: none; }
  #menu .menu-box { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  #menu .rp-top { flex: none; margin: 6px 0 2px; }
  #menu .fan-note { flex: none; font-size: 9px; line-height: 1.45; margin-top: 2px; }
}
