/* Phone battle workspace: timeline, board and commands share one viewport. */
.mobile-battle-deck {
  display: none;
}

@media (max-width: 900px), (pointer: coarse) {
  html:has(.app.mobile-battle-workspace),
  body:has(.app.mobile-battle-workspace) {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app.device-mobile.battle-started.mobile-battle-workspace {
    position: fixed;
    inset: 0;
    display: grid;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: max(4px, env(safe-area-inset-top, 0px)) 6px max(4px, env(safe-area-inset-bottom, 0px));
    gap: 4px;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .app.mobile-battle-workspace .topbar.in-battle {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px;
    padding: 4px 5px;
    border-radius: 10px;
  }

  .app.mobile-battle-workspace .topbar.in-battle .topbar-timeline-host:not(:empty) {
    min-width: 0;
  }

  .app.mobile-battle-workspace .timeline-float.in-topbar .timeline {
    display: flex;
    gap: 4px;
    max-height: 42px;
    padding: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .app.mobile-battle-workspace .timeline-float.in-topbar .timeline::-webkit-scrollbar,
  .app.mobile-battle-workspace .mobile-battle-panels::-webkit-scrollbar,
  .app.mobile-battle-workspace .action-dock .stamina-bar::-webkit-scrollbar,
  .app.mobile-battle-workspace .action-dock .skill-list::-webkit-scrollbar {
    display: none;
  }

  .app.mobile-battle-workspace .timeline-float.in-topbar .timeline .tl {
    flex: 0 0 min(128px, 36vw);
    min-width: 0;
    padding: 3px 5px;
  }

  .app.mobile-battle-workspace .timeline-float.in-topbar .timeline .tl strong,
  .app.mobile-battle-workspace .timeline-float.in-topbar .timeline .tl .small {
    font-size: 10px;
    line-height: 1.15;
  }

  .app.mobile-battle-workspace .topbar.in-battle .actions {
    display: grid;
    width: 62px;
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .app.mobile-battle-workspace .topbar.in-battle .actions button {
    min-width: 0;
    min-height: 20px;
    padding: 2px 4px;
    font-size: 10px;
    line-height: 1.1;
  }

  .app.mobile-battle-workspace .battle-stage,
  .app.mobile-battle-workspace.battle-started .battle-stage {
    display: grid;
    min-height: 0;
    height: 100%;
    gap: 4px;
    padding: 0;
    overflow: hidden;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .app.mobile-battle-workspace .board-shell,
  .app.mobile-battle-workspace.battle-started .board-shell {
    display: grid;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  .app.mobile-battle-workspace .board-panel,
  .app.mobile-battle-workspace.battle-started .board-panel {
    display: grid;
    min-height: 0;
    height: 100%;
    padding: 4px;
    place-items: center;
  }

  .app.mobile-battle-workspace .battle-board-wrap,
  .app.mobile-battle-workspace.battle-started .battle-board-wrap {
    display: grid;
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: 100%;
    margin: 0;
    padding: 0;
    grid-template-rows: auto auto;
    align-content: center;
    overflow: visible;
  }

  .app.mobile-battle-workspace .mobile-board-status {
    min-height: 24px;
    margin: 0 0 3px;
    padding: 3px 5px;
  }

  .app.mobile-battle-workspace .board {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 0;
    padding: 2px;
    gap: 0;
  }

  .app.mobile-battle-workspace .mobile-battle-deck {
    display: grid;
    min-width: 0;
    gap: 3px;
    padding: 4px;
    border: 1px solid rgba(215, 175, 84, 0.3);
    border-radius: 12px;
    background: rgba(10, 13, 10, 0.98);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.35);
  }

  .app.mobile-battle-workspace .mobile-battle-tools {
    display: grid;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) 46px 46px;
    gap: 4px;
    align-items: center;
  }

  .app.mobile-battle-workspace .mobile-operated-unit {
    min-width: 0;
    overflow: hidden;
    color: #f3dda3;
    font-size: 11px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app.mobile-battle-workspace .mobile-operated-summary {
    display: grid;
    min-width: 0;
    gap: 2px;
    overflow: hidden;
  }

  .app.mobile-battle-workspace .mobile-operated-resources {
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .app.mobile-battle-workspace .mobile-operated-resources::-webkit-scrollbar {
    display: none;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .school-resource-row {
    width: max-content;
    min-width: 100%;
    min-height: 28px;
    flex-direction: row-reverse;
    justify-content: flex-end;
    gap: 4px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .flower-meter {
    width: 34px;
    height: 34px;
    transform: none;
    margin-right: 0;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .flower-meter-bud-count {
    right: 0;
    bottom: 0;
    min-width: 12px;
    height: 12px;
    padding: 0 2px;
    font-size: 8px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .sword-qi {
    width: 92px;
    height: 36px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yaowang-medicine-meter {
    width: 96px;
    height: 96px;
    flex: 0 0 96px;
  }

  /* 燕行术保留燕子与燕踪展翼本体；不在移动资源栏塞入背景占位。 */
  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-meter-board {
    width: 112px;
    height: 60px;
    flex: 0 0 112px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-wings {
    width: 112px;
    height: 60px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-wing-left,
  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-wing-right {
    width: 56px;
    height: 42px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-wing-left {
    transform: translateY(-50%) translateX(28px) scale(0.2);
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-wing-right {
    transform: translateY(-50%) translateX(-28px) scale(0.2);
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-swallow {
    width: 80px;
    height: 40px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .yanyun-state-text {
    bottom: 0;
    font-size: 8px;
  }

  /* 仙茗量谱只占图标本身的透明定位空间，不保留一块背景底图。 */
  .app.mobile-battle-workspace .mobile-operated-resources .xianming-resource-controls {
    width: 142px;
    height: 84px;
    flex-basis: 142px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-resource-group.xianming-chess-zone {
    top: 0;
    left: 0;
    width: 62px;
    height: 62px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-resource-group.xianming-tea-zone {
    right: 0;
    bottom: 0;
    width: 62px;
    height: 62px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-chess .xianming-resource-frame,
  .app.mobile-battle-workspace .mobile-operated-resources .xianming-tea .xianming-resource-frame {
    width: 44px;
    height: 44px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-chess .xianming-resource-frame b {
    font-size: 22px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-tea .xianming-resource-frame b {
    font-size: 20px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-invest-choices {
    display: none;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-miaoshou-diagonal {
    top: 5px;
    height: 74px;
  }

  .app.mobile-battle-workspace .mobile-operated-resources .xianming-miaoshou-meter b,
  .app.mobile-battle-workspace .mobile-operated-resources .xianming-miaoshou-meter.xianming-miaoshou-ready b {
    font-size: 16px;
  }

  .app.mobile-battle-workspace .mobile-battle-tools button {
    min-height: 26px;
    padding: 3px 5px;
    font-size: 11px;
  }

  .app.mobile-battle-workspace .mobile-battle-tools button[aria-expanded="true"] {
    border-color: var(--gold);
    color: var(--gold);
  }

  .app.mobile-battle-workspace .mobile-battle-prompt {
    min-height: 15px;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    line-height: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app.mobile-battle-workspace .mobile-battle-panels {
    display: grid;
    min-width: 0;
    max-height: 128px;
    gap: 3px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
  }

  .app.mobile-battle-workspace .mobile-battle-panels > .hidden,
  .app.mobile-battle-workspace .mobile-battle-panels > :not(.active).extra-float,
  .app.mobile-battle-workspace .mobile-battle-deck > :not(.active).extra-float,
  .app.mobile-battle-workspace .mobile-battle-panels > :not(.active).combo-float {
    display: none !important;
  }

  .app.mobile-battle-workspace .mobile-battle-panels > .action-dock,
  .app.mobile-battle-workspace .mobile-battle-panels > .extra-float,
  .app.mobile-battle-workspace .mobile-battle-panels > .combo-float {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none;
    margin: 0 !important;
    padding: 3px !important;
    overflow: visible;
    transform: none !important;
    border-radius: 9px;
    background: rgba(19, 23, 17, 0.96);
    box-shadow: none;
  }

  /* 普通衔接紧贴操作区上沿，不占技能列表空间、不覆盖量谱与操作按钮。 */
  .app.device-mobile.battle-started.mobile-battle-workspace .mobile-battle-deck {
    position: relative;
  }

  .app.device-mobile.battle-started.mobile-battle-workspace .mobile-battle-deck > .extra-float.extra-actions.active:not(.reaction-window) {
    position: absolute !important;
    inset: auto 0 calc(100% + 6px) auto !important;
    display: block !important;
    width: max-content !important;
    max-width: calc(100vw - 20px) !important;
    min-height: 0;
    max-height: none !important;
    margin: 0 !important;
    padding: 8px !important;
    transform: none !important;
    z-index: 65;
  }

  /* 拼招触发时保留原有方形罗盘，不随手机屏宽拉成横条。 */
  .app.mobile-battle-workspace .mobile-battle-deck > .extra-float.extra-actions.active.reaction-window {
    position: fixed !important;
    inset: auto auto calc(var(--mobile-dock-stack-height, 144px) + 8px) 50% !important;
    display: block !important;
    width: min(280px, calc(100vw - 24px)) !important;
    max-width: min(280px, calc(100vw - 24px)) !important;
    aspect-ratio: 1;
    max-height: none !important;
    margin: 0 !important;
    padding: 5px 6px !important;
    overflow: visible;
    transform: translateX(-50%) !important;
    z-index: 70;
    border-radius: 10px;
    box-shadow: 0 -12px 34px rgba(0, 0, 0, 0.52);
  }

  .app.mobile-battle-workspace #mobileBattlePanels > .hidden {
    display: none !important;
  }

  .app.mobile-battle-workspace #turnFloat:has([data-skill]),
  .app.mobile-battle-workspace #turnFloat:has(#endBtn:not(:disabled)) {
    order: -10;
  }

  .app.mobile-battle-workspace .mobile-battle-panels .action-dock .turn-actions {
    width: 48px;
    margin-left: 4px;
  }

  .app.mobile-battle-workspace .mobile-battle-panels .action-dock #endBtn {
    width: 48px;
    height: 48px;
    font-size: 11px;
  }

  .app.mobile-battle-workspace .mobile-battle-panels .action-dock .stamina-bar,
  .app.mobile-battle-workspace .mobile-battle-panels .action-dock .skill-list {
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .app.mobile-battle-workspace .mobile-battle-panels .action-dock .skill-tooltip-anchor {
    flex-basis: 48px;
    width: 48px;
  }

  .app.mobile-battle-workspace .mobile-battle-panels .dock-skill-button {
    width: 48px;
    height: 48px;
  }

  .app.mobile-battle-workspace .mobile-battle-panels .skill-dock-glyph {
    font-size: 18px;
  }

  .app.device-mobile.battle-started.mobile-battle-workspace .focus-float,
  .app.device-mobile.battle-started.mobile-battle-workspace #logPanel {
    display: none !important;
  }

  .app.device-mobile.battle-started.mobile-battle-workspace[data-mobile-panel-open="focus"] .focus-float,
  .app.device-mobile.battle-started.mobile-battle-workspace[data-mobile-panel-open="log"] #logPanel {
    position: fixed !important;
    inset: auto 6px max(6px, env(safe-area-inset-bottom, 0px)) !important;
    z-index: 80;
    display: flex !important;
    width: auto !important;
    height: auto;
    max-width: none;
    max-height: min(70dvh, 580px);
    margin: 0;
    padding: 8px;
    overflow: auto;
    transform: none !important;
    border-radius: 14px;
    background: rgba(12, 15, 12, 0.99);
    box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.72);
  }

  .app.mobile-battle-workspace[data-mobile-panel-open="focus"] .focus-float {
    flex-direction: column;
  }

  .app.mobile-battle-workspace[data-mobile-panel-open="focus"] .focus-float.collapsed > :not(.float-handle),
  .app.mobile-battle-workspace[data-mobile-panel-open="log"] #logPanel.collapsed > :not(.float-handle) {
    display: block !important;
  }

  .app.mobile-battle-workspace[data-mobile-panel-open="log"] #logPanel .log-stream {
    min-height: 120px;
    max-height: 52dvh;
  }

  /* Keep the dimmer inside the battle-stage stacking context. The status/log
     sheets also live there, so their controls remain above and clickable. */
  .app.mobile-battle-workspace[data-mobile-panel-open="focus"] .battle-stage::before,
  .app.mobile-battle-workspace[data-mobile-panel-open="log"] .battle-stage::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 79;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(2px);
  }

  .app.mobile-battle-workspace .focus-float .panel-collapse-btn,
  .app.mobile-battle-workspace #logPanel .panel-collapse-btn {
    display: none;
  }

  .app.mobile-battle-workspace .mobile-sheet-close {
    display: inline-flex;
    min-height: 28px;
    padding: 3px 8px;
    font-size: 11px;
  }

  .app.mobile-battle-workspace .battle-stage-fx,
  .app.mobile-battle-workspace .board-fx-layer,
  .app.mobile-battle-workspace .selected-portrait {
    pointer-events: none;
  }
}

@media (min-width: 901px) and (pointer: fine) {
  .mobile-sheet-close {
    display: none;
  }
}
