/* ==========================================================================
   手机横屏适配（高度 ≤ 540 的横屏）：
   顶栏 32px · 左：战场 · 右：我方信息栏 · 底：手牌条
   ========================================================================== */
/* 手机布局：由 JS 设置 body.m-land（横屏矮屏）；竖屏手机额外加 body.m-port 改排版 */
html:has(body.m-land), body.m-land, body.m-land { height: 100%; overscroll-behavior: none; }
body.m-land #game-app.game-container {
    position: fixed !important; inset: 0 !important;
    display: grid !important;
    width: auto !important; height: auto !important;
    grid-template-columns: minmax(0, 1fr) 118px;
    grid-template-rows: 32px auto auto auto minmax(0, 1fr) auto 92px;
    background: #120e0a !important;
  }
body.m-land:not(.at-home) #game-app { touch-action: none; }
/* ---- 顶栏：敌方信息压缩成一行 ---- */
body.m-land #top-bar.hud-top-bar {
    grid-column: 1 / 3; grid-row: 1;
    height: 32px !important; min-height: 0 !important; gap: 6px !important; padding: 0 6px !important;
  }
body.m-land #top-bar .faction-emblem { width: 22px !important; height: 22px !important; min-width: 22px; font-size: 12px !important; }
body.m-land #top-bar .faction-char { font-size: 12px !important; }
body.m-land #top-bar .opponent-meta { gap: 6px !important; min-width: 0; }
body.m-land #top-bar .hq-status-group { width: 96px !important; min-width: 0 !important; }
body.m-land #top-bar .hq-label-row { font-size: 10px !important; line-height: 1.1; }
body.m-land #top-bar .hq-hp-bar { height: 4px !important; }
body.m-land #top-bar .phase-badge { padding: 2px 10px !important; font-size: 12px !important; min-height: 0 !important; height: 24px; }
body.m-land #top-bar .phase-badge * { font-size: 12px !important; }
body.m-land #top-bar .opponent-resources { gap: 4px !important; }
body.m-land #top-bar .resource-badge { padding: 1px 6px !important; height: 22px; min-height: 0 !important; font-size: 11px !important; gap: 3px !important; }
body.m-land #top-bar .resource-badge .resource-icon { font-size: 11px !important; }
body.m-land #top-bar .resource-badge .resource-val { font-size: 11px !important; }
body.m-land #top-bar .prestige-pips, body.m-land #top-bar .deck-count-badge, body.m-land #top-bar .discard-count-badge { display: none !important; }
body.m-land #top-bar .latency-badge { padding: 1px 5px !important; font-size: 10px !important; height: 20px; }
body.m-land #top-bar .hud-action-btn { height: 26px; padding: 0 8px; font-size: 0 !important; gap: 0; }
body.m-land #top-bar .hud-action-btn span { font-size: 15px !important; }
body.m-land #top-bar #btn-fullscreen { display: inline-flex; }
body.m-land.is-standalone #top-bar #btn-fullscreen { display: none !important; }
/* ---- 战场 ---- */
body.m-land #battlefield-main.battlefield-viewport { grid-column: 1; grid-row: 2 / 7; padding: 2px 4px !important; min-height: 0; min-width: 0; }
/* ---- 我方栏：拆到右侧竖栏 + 底部手牌条 ---- */
body.m-land #player-dock.dock-bottom-bar { display: contents !important; }
body.m-land #player-dock #turn-timer.dock-timer { grid-column: 2; grid-row: 2; height: 22px; margin: 4px 6px 0; gap: 4px; }
body.m-land #player-dock #turn-timer .turn-timer-track { display: none; }
body.m-land #player-dock #turn-timer .turn-timer-chip { width: 100%; justify-content: center; font-size: 12px; padding: 1px 4px; }
body.m-land #player-dock .player-hq-meta {
    grid-column: 2; grid-row: 3; margin: 4px 6px 0; padding: 4px 6px !important; gap: 6px !important;
  }
body.m-land #player-dock .player-hq-meta .faction-emblem { width: 24px !important; height: 24px !important; min-width: 24px; }
body.m-land #player-dock .player-hq-meta .faction-char { font-size: 13px !important; }
body.m-land #player-dock .player-hq-meta .hq-label { display: none; }
body.m-land #player-dock .player-hq-meta .hq-label-row { font-size: 11px !important; justify-content: flex-end; }
body.m-land #player-dock .player-resources {
    grid-column: 2; grid-row: 4; margin: 4px 6px 0 !important; padding: 4px 6px !important; gap: 4px !important;
  }
body.m-land #player-dock .granary-title, body.m-land #player-dock .prestige-title { font-size: 11px !important; }
body.m-land #player-dock .granary-numbers, body.m-land #player-dock .prestige-numbers { font-size: 12px !important; }
body.m-land #player-dock .granary-pips-row { gap: 1px !important; }
body.m-land #player-dock .grain-pip { width: 7px !important; height: 9px !important; min-width: 0 !important; }
body.m-land #player-dock .prestige-medals { font-size: 12px !important; }
body.m-land #player-dock .prestige-discount-chip { font-size: 9px !important; padding: 1px 4px !important; }
body.m-land #player-dock .player-deck-actions {
    grid-column: 2; grid-row: 6 / 8; margin: 4px 6px 6px !important;
    grid-template-columns: 1fr 1fr !important; grid-template-rows: 30px 1fr !important; gap: 4px !important;
  }
body.m-land #player-dock .deck-pile-widget, body.m-land #player-dock .btn-graveyard { height: 30px !important; padding: 0 4px !important; font-size: 11px !important; gap: 2px !important; }
body.m-land #player-dock .deck-pile-widget .deck-icon, body.m-land #player-dock .btn-graveyard .btn-icon { font-size: 12px !important; }
body.m-land #player-dock .deck-label { display: none; }
body.m-land #player-dock .btn-graveyard .btn-text { font-size: 11px; }
body.m-land #player-dock #btn-end-turn { min-height: 0 !important; font-size: 15px !important; letter-spacing: 2px; }
/* 手牌条 */
body.m-land #player-dock #hand-tray.hand-fan-tray {
    grid-column: 1; grid-row: 7;
    height: 92px !important; padding: 0 4px !important;
    overflow-x: auto; overflow-y: visible; justify-content: flex-start;
    border-top: 1px solid rgba(217,179,106,.3);
    background: linear-gradient(180deg, rgba(38,30,20,.96), rgba(18,14,10,.96));
    touch-action: none; overflow-x: hidden !important;
  }
body.m-land #player-dock .hand-card-fan { justify-content: center !important; gap: 4px !important; height: 100%; align-items: center !important; width: max-content !important; min-width: 100% !important; }
body.m-land #player-dock .hand-card-fan .card-hand { zoom: .56; flex: 0 0 116px !important; transition: transform .12s; }
body.m-land #player-dock .hand-card-fan .card-hand.selected { transform: translateY(-14px) !important; box-shadow: 0 0 0 3px #f0cf6a, 0 8px 16px rgba(0,0,0,.6) !important; }
body.m-land #player-dock .hand-card-fan .card-hand:hover { transform: none !important; }
/* 战场在手机上更紧凑：降低天然高度 → 缩放后单位更大 */
body.m-land .board-aspect-wrapper { gap: 4px !important; }
body.m-land .slot { height: 122px !important; }
body.m-land .battlefield-line.line-support { padding-top: 3px !important; padding-bottom: 3px !important; min-height: 0 !important; }
body.m-land .line-frontline { padding: 3px 6px !important; }
body.m-land .frontline-zone { padding-bottom: 3px !important; min-height: 0 !important; }
body.m-land .zone-terrain-banner { padding: 2px 8px !important; }
body.m-land .zone-terrain-banner .terrain-name { font-size: 18px !important; }
body.m-land .terrain-effect-line { font-size: 13px !important; }
body.m-land .board-unit .unit-name, body.m-land .board-unit .unit-header, body.m-land .board-unit [class*="unit-name"] { font-size: 15px !important; }
body.m-land .board-unit .unit-stat-pill { font-size: 17px !important; }
body.m-land .board-unit .unit-stat-pill .val { font-size: 19px !important; font-weight: 800; }
/* 右栏文字精简为图标 */
body.m-land #player-dock .granary-title, body.m-land #player-dock .prestige-title { font-size: 0 !important; }
body.m-land #player-dock .granary-title::before { content: '🌾 粮草'; font-size: 11px; }
body.m-land #player-dock .prestige-title::before { content: '🎖️ 声望'; font-size: 11px; }
body.m-land #player-dock .granary-header, body.m-land #player-dock .prestige-header { align-items: center; white-space: nowrap; }
body.m-land #player-dock .prestige-display { flex-wrap: nowrap; }
body.m-land #player-dock .prestige-discount-chip { white-space: nowrap; max-width: 60px; overflow: hidden; text-overflow: ellipsis; }
body.m-land #player-dock .btn-graveyard .btn-text { white-space: nowrap; font-size: 10px !important; }
/* 提示条、战报抽屉 */
body.m-land .tactical-drawer { bottom: 0 !important; top: 32px !important; width: min(320px, 70vw) !important; }
body.m-land .card-inspector-tooltip { max-width: 260px !important; }


/* 全屏按钮：仅触屏显示 */
#btn-fullscreen { display: none; }

/* 触屏取消按钮（任何选中/瞄准状态都会出现） */
.touch-cancel-btn {
  position: fixed; left: 50%; top: 40px; transform: translateX(-50%); z-index: 960;
  display: none; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 20px; border: 1px solid rgba(255,190,170,.6);
  background: rgba(120,30,20,.92); color: #fff; font-size: 14px; letter-spacing: 1px;
  box-shadow: 0 6px 16px rgba(0,0,0,.5);
}
body.is-selecting .touch-cancel-btn { display: inline-flex; }
/* 拖动时手牌条变成取消区 */
body.is-dragging #hand-tray { position: relative; }
body.is-dragging #hand-tray::after {
  content: '拖回这里取消'; position: absolute; inset: 0; z-index: 5; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(120,30,20,.55); color: #fff; font-size: 14px; letter-spacing: 2px; border: 2px dashed rgba(255,200,180,.7);
}
.card-inspector-tooltip { pointer-events: none; }
body.m-land .card-inspector-tooltip { width: 270px !important; max-width: 270px !important; zoom: .72; left: 6px !important; top: 46px !important; right: auto !important; bottom: auto !important; max-height: 360px; overflow: hidden; opacity: .96; }

/* 手牌：触摸拖动时不让浏览器滚动；多牌时互相叠压以放下全部 */
body.m-land .card-hand, body.m-land .board-unit, body.m-land .battlefield-viewport { touch-action: none; }
body.m-land #player-dock .hand-card-fan .card-hand.selected { z-index: 30 !important; }

/* 刘海屏/底部横条安全区 */
body.m-land #game-app.game-container {
  box-sizing: border-box;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
body.m-land .touch-cancel-btn { top: calc(40px + env(safe-area-inset-top, 0)); }

/* ==========================================================================
   手机竖屏：顶栏 · 战场（三条前线改为上下排列）· 我方信息一行 · 手牌条
   ========================================================================== */
body.m-port #game-app.game-container {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: 34px minmax(0, 1fr) 48px 104px;
}
body.m-port #top-bar.hud-top-bar { grid-column: 1 / -1; grid-row: 1; gap: 4px !important; padding: 0 4px !important; }
body.m-port #top-bar .hq-status-group { width: 64px !important; }
body.m-port #top-bar .hq-name { display: none; }
body.m-port #top-bar .phase-badge { padding: 2px 6px !important; height: 22px; }
body.m-port #top-bar .turn-num, body.m-port #top-bar .phase-divider { display: none; }
body.m-port #top-bar .phase-badge * { font-size: 11px !important; }
body.m-port #top-bar .latency-badge, body.m-port #top-bar #btn-fullscreen { display: none !important; }
body.m-port #top-bar .resource-badge { padding: 1px 4px !important; }
body.m-port #top-bar .hud-actions { gap: 4px; margin-left: 2px; }
body.m-port #top-bar .hud-action-btn { padding: 0 6px; }

body.m-port #battlefield-main.battlefield-viewport { grid-column: 1 / -1; grid-row: 2; padding: 2px !important; }
body.m-port .board-aspect-wrapper { width: 600px !important; grid-template-rows: auto auto auto !important; height: auto !important; aspect-ratio: auto !important; }
body.m-port .line-frontline { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 4px !important; align-items: stretch !important; }
body.m-port .zone-terrain-banner .terrain-effect-line { white-space: nowrap; }
body.m-port .frontline-zone { width: auto !important; max-width: none !important; min-width: 0 !important; display: flex !important; flex-direction: column !important; }
body.m-port .frontline-zone .zone-slots-container { flex-direction: column !important; justify-content: flex-start !important; gap: 4px !important; flex: 1 1 auto; }
body.m-port .zone-terrain-banner { flex-wrap: wrap !important; justify-content: center !important; gap: 2px 6px !important; text-align: center; }
body.m-port .zone-terrain-banner .terrain-effect-line { flex-basis: 100% !important; order: 5 !important; margin: 0 !important; font-size: 12px !important; white-space: normal !important; }
body.m-port .zone-terrain-banner .zone-occupant-badge { margin-left: 0 !important; }
body.m-port .frontline-zone .zone-slots-container { justify-content: center; }

body.m-port #player-dock .player-hq-meta { grid-column: 1 / 4; grid-row: 3; margin: 4px 2px 4px 4px; }
body.m-port #player-dock .player-hq-meta .faction-emblem { display: none; }
body.m-port #player-dock .player-resources {
  grid-column: 4 / 10; grid-row: 3; margin: 4px 2px !important; min-width: 0; overflow: hidden;
  flex-direction: row !important; align-items: center !important; gap: 6px !important;
}
body.m-port #player-dock .granary-cluster { flex: 1 1 60%; }
body.m-port #player-dock .prestige-cluster { flex: 1 1 40%; }
body.m-port #player-dock .prestige-display { display: none; }
body.m-port #player-dock .granary-title::before { content: '🌾'; }
body.m-port #player-dock .prestige-title::before { content: '🎖️'; }
body.m-port #player-dock #turn-timer.dock-timer { grid-column: 10 / 11; grid-row: 3; margin: 4px 1px; height: auto; min-width: 0; }
body.m-port #player-dock #turn-timer .turn-timer-chip { font-size: 11px; height: 100%; padding: 0 !important; flex-direction: column; justify-content: center; gap: 0; line-height: 1.15; }
body.m-port #player-dock .player-deck-actions {
  grid-column: 11 / 13; grid-row: 3; margin: 4px 4px 4px 2px !important;
  grid-template-columns: 1fr !important; grid-template-rows: 1fr !important;
}
body.m-port #player-dock .deck-pile-widget, body.m-port #player-dock .btn-graveyard { display: none !important; }
body.m-port #player-dock #btn-end-turn { font-size: 13px !important; letter-spacing: 0; }
body.m-port #player-dock #hand-tray.hand-fan-tray { grid-column: 1 / -1; grid-row: 4; height: 104px !important; }
body.m-port #player-dock .hand-card-fan .card-hand { zoom: .6; }
body.m-port .card-inspector-tooltip { top: auto !important; bottom: 160px !important; left: 6px !important; }

/* iOS 添加到主屏幕引导 */
.ios-install { position: fixed; inset: 0; z-index: 2600; display: flex; align-items: center; justify-content: center; background: rgba(8,6,4,.8); padding: 16px; }
.ios-install.hidden { display: none; }
.ios-install-box { width: min(360px, 92vw); max-height: 92dvh; overflow-y: auto; padding: 18px 20px; border-radius: 14px; background: #221a12; border: 1px solid rgba(217,179,106,.5); color: #f3e2b5; font-size: 14px; line-height: 1.7; }
.ios-install-title { font-size: 18px; color: #f0cf6a; margin-bottom: 6px; letter-spacing: 2px; }
.ios-install ol { padding-left: 20px; margin: 8px 0 14px; }
.ios-share { display: inline-block; padding: 0 5px; border: 1px solid rgba(255,255,255,.4); border-radius: 4px; font-size: 12px; }
.home-touch-only { display: none; }
@media (pointer: coarse) { .home-touch-only { display: inline-flex; } body.is-standalone .home-touch-only { display: none; } }
body.m-land .slot .board-unit { height: 100% !important; max-height: 100% !important; }
body.m-port .frontline-zone { padding-top: 2px !important; }
body.m-port .zone-terrain-banner { margin-bottom: 2px !important; }
body.m-port .zone-slots-container { min-height: 0 !important; padding: 0 !important; }
body.m-port .line-support .line-header { display: none !important; }
body.m-port #player-dock #btn-end-turn { font-size: 12px !important; white-space: nowrap; padding: 0 2px !important; }
/* 很矮的横屏（浏览器地址栏+标签栏占掉高度时）：手牌条和顶栏再压缩 */
@media (max-height: 360px) {
  body.m-land:not(.m-port) #game-app.game-container { grid-template-rows: 28px auto auto auto minmax(0, 1fr) auto 74px; }
  body.m-land:not(.m-port) #top-bar.hud-top-bar { height: 28px !important; }
  body.m-land:not(.m-port) #player-dock #hand-tray.hand-fan-tray { height: 74px !important; }
  body.m-land:not(.m-port) #player-dock .hand-card-fan .card-hand { zoom: .46; }
  body.m-land:not(.m-port) #player-dock .player-resources .prestige-display { display: none; }
}
/* 竖屏手牌：牌多时叠压，保证一屏放下 */
body.m-port #player-dock .hand-card-fan .card-hand { position: relative; }
@media (max-width: 400px) {
  body.m-port #top-bar .prestige-badge { display: none !important; }
  body.m-port #top-bar .hq-status-group { width: 52px !important; }
}

.insert-marker.horizontal { background: linear-gradient(90deg, transparent, #f3d892 15%, #f3d892 85%, transparent); }

/* 固定定位的浮层也避开刘海/底部横条 */
body.m-land .card-inspector-tooltip { left: calc(6px + env(safe-area-inset-left, 0px)) !important; }
body.m-land .toast-stack { left: calc(10px + env(safe-area-inset-left, 0px)) !important; }
/* 居中提示：保持居中并限制宽度（之前被改成靠左但仍左移 50%，左半截被切掉） */
.toast-alert { max-width: calc(100vw - 24px); white-space: normal; text-align: center; box-sizing: border-box; }
body.tactic-targeting .toast-alert { top: auto !important; bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important; max-width: min(560px, calc(100vw - 24px)); }
body.m-land .tactical-drawer { right: env(safe-area-inset-right, 0px) !important; }

/* ===== 手机上的主页与弹窗：不换行、不被裁掉 ===== */
.touch-only { display: none; }
@media (pointer: coarse) { .touch-only { display: block; } .desktop-only { display: none !important; } }
.home-sub-actions { flex-wrap: wrap; row-gap: 6px; }
.home-link { white-space: nowrap; }
.modal-box { max-height: calc(100dvh - 16px); overflow-y: auto; }
@media (max-width: 420px) {
  .home-sub-actions { gap: 4px 10px !important; }
  .game-over-title { font-size: 24px !important; letter-spacing: 2px !important; }
}
@media (max-height: 540px) {
  .home-panel { max-height: calc(100dvh - 12px); overflow-y: auto; padding-top: 12px !important; padding-bottom: 12px !important; }
  .home-panel .home-seal { display: none; }
  .home-title { font-size: 30px !important; margin: 0 !important; }
  .home-subtitle { margin: 2px 0 8px !important; }
  .home-btn { padding-top: 6px !important; padding-bottom: 6px !important; }
  .home-sub-actions { margin-top: 8px !important; }
  #modal-game-menu .modal-box { padding-top: 10px !important; padding-bottom: 10px !important; }
  #modal-game-menu .modal-box button { padding-top: 6px !important; padding-bottom: 6px !important; }
  .game-over-title { font-size: 26px !important; }
}

/* ==========================================================================
   性能：手机上关闭“一直在跑”的阴影呼吸动画。
   box-shadow / background-position 动画每帧都要重新栅格化整块区域，
   在 3 倍屏手机上会让 GPU 持续满载 → 发热降频 → 隔一会儿突然掉帧。
   改为静态发光，视觉提示保留。
   ========================================================================== */
@media (hover: none), (pointer: coarse) {
  .board-unit.status-can-act,
  .legal-attack-target,
  .btn-end-turn.state-active,
  .frontline-zone.terrain-water::after { animation: none !important; }
  .legal-attack-target { outline-color: #fc8181 !important; box-shadow: 0 0 14px rgba(229, 62, 62, 0.85) !important; }
  .btn-end-turn.state-active { box-shadow: 0 0 14px rgba(240, 201, 120, 0.6); }
}
body.m-land .board-unit.status-can-act,
body.m-land .legal-attack-target,
body.m-land .btn-end-turn.state-active,
body.m-land .frontline-zone.terrain-water::after { animation: none !important; }

/* 竖屏：倒计时只显示秒数、收窄，给粮草/声望让出空间，避免互相遮挡 */
body.m-port #player-dock .prestige-cluster, body.m-port #player-dock .granary-cluster { min-width: 0; }
body.m-port #player-dock .prestige-header, body.m-port #player-dock .granary-header { gap: 2px !important; }
body.m-port #player-dock .prestige-numbers, body.m-port #player-dock .granary-numbers { white-space: nowrap; letter-spacing: -0.5px; }
/* “取消”按钮放到左下角手牌条上，不再盖住敌方支援阵线（原来会挡住那里的敌军，点了没反应） */
.touch-cancel-btn,
body.m-land .touch-cancel-btn {
  top: auto !important; left: calc(8px + env(safe-area-inset-left, 0px)) !important; transform: none !important;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important; padding: 7px 14px;
}
@media (max-width: 340px) { body.m-port #player-dock #btn-end-turn { font-size: 11px !important; } }
body.m-port .touch-cancel-btn { padding: 5px 10px !important; font-size: 12px; bottom: calc(112px + env(safe-area-inset-bottom, 0px)) !important; }
body.m-land #player-dock #turn-timer .turn-timer-total { font-size: 10px; }
body.m-port #player-dock #turn-timer .turn-timer-total { display: none; }
body.m-port #player-dock #turn-timer.total-warning { outline: 2px solid #ff5a45; border-radius: 8px; }
