/* ===== スマホ・タブレット（タッチ操作・狭い画面） ===== */
.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 {
    /* 盤面は画面の約64%。1人分 = 情報欄 + 戦場 + 領地 + 手札 */
    --ch: clamp(34px, calc((32dvh - 62px) / 2.9), 104px);
  }
  #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; max-height: 36dvh; border-left: none; border-top: 1px solid var(--line2); box-shadow: 0 -6px 20px rgba(0, 0, 0, .5); }
  #topbar { display: none; }
  #log { display: none; }
  #prompt { min-height: 0; padding: 8px 10px; flex: none; overflow: auto; max-height: 26dvh; }
  #prompt .ptitle { font-size: 13px; margin-bottom: 4px; }
  #prompt .btns button { min-height: 40px; padding: 6px 14px; flex: 1 1 auto; }
  #pile { max-height: 12dvh; padding: 4px 8px; }
  /* 詳細は下から出るシート */
  #detail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; max-height: 64dvh; 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); }
  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: 38vw; max-width: 200px; 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: 8dvh; bottom: 38dvh; z-index: 80; border: 1px solid var(--line2); border-radius: 12px; background: rgba(8, 11, 20, .97); box-shadow: 0 10px 40px rgba(0, 0, 0, .8); }
  body.m-opts #topbar { display: flex; position: fixed; right: 6px; top: 46px; z-index: 82; width: min(320px, 94vw); flex-direction: column; align-items: flex-start; border: 1px solid var(--line2); border-radius: 12px; background: rgba(8, 11, 20, .97); }
  #m-bar { top: 6px; right: 6px; }
  /* 盤面 */
  .side { padding: 1px 3px; gap: 1px; }
  .row { gap: 3px; padding: 1px 2px; border-radius: 8px; }
  .row .rlabel { display: none; }
  .pinfo { gap: 6px; padding: 2px 6px 2px 4px; min-height: 30px; font-size: 11px; overflow-x: auto; }
  .pinfo > * { flex-shrink: 0; }
  .pinfo .pname { font-size: 12px; max-width: 20vw; overflow: hidden; text-overflow: ellipsis; }
  .pinfo .life { font-size: 16px; height: 24px; min-width: 40px; 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: 26px; padding: 1px 6px; font-size: 10px; }
  .side.top .pinfo { margin-right: 150px; }
  #midbar { min-height: 26px; 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-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); }
}
