/* mobile16pm A1 (battle): iPhone 16 Pro Max phone layout only. Every rule must sit inside @media (max-width:999.98px) and start with body:not(.desktop-game) (desktop >=1000px must not change). Loaded last (index.html), so it overrides style.css / mobile.css / campaign.css. */
/* One-screen battle (430 x 932, DPR 3): top bar, chapter line, toolbar, encounter panel, mechanic chips + enemy buttons, team, then the
   whole 6 x 5 board (cells >= 58 px) above the home indicator. Everything that is not needed every turn (team skills summary, turn
   result, footer) sits below the board. The two columns and the squad section are flattened with display:contents so their children
   can be ordered as one flex column (phone only; desktop keeps the grid). */
@media (max-width: 650px) {
  /* ---------- top bar: notch / Dynamic Island inset, 44 px targets ---------- */
  body:not(.desktop-game) .topbar {
    height: calc(48px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
    gap: 4px;
  }
  body:not(.desktop-game) .topbar .brand { min-height: 44px; gap: 4px; font-size: 18px; }
  body:not(.desktop-game) .topbar .brand small { display: none; }
  body:not(.desktop-game) .topbar .brand-mark { width: 30px; height: 36px; font-size: 36px; }
  body:not(.desktop-game) .topbar .brand-mark:after { top: 10px; left: 9px; font-size: 14px; }
  body:not(.desktop-game) .header-tools { gap: 0; }
  body:not(.desktop-game) .header-tools .icon-button { width: 44px; height: 44px; min-width: 44px; font-size: 15px; }
  body:not(.desktop-game) .header-tools .icon-button svg { width: 19px; }
  body:not(.desktop-game) .topbar #ow-entry { min-height: 44px; height: 44px; margin-right: 2px; font-size: 14px; }
  body:not(.desktop-game) .topbar #mobile-profile { width: 44px; min-width: 44px; height: 44px; }

  /* ---------- page: chapter line + toolbar (one grid), safe areas, no horizontal scroll ---------- */
  body:not(.desktop-game) main {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    column-gap: 5px;
    row-gap: 4px;
    align-items: center;
    max-width: none;
    padding: 4px max(10px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left));
  }
  body:not(.desktop-game) main > * { grid-column: 1 / -1; min-width: 0; }
  body:not(.desktop-game) .page-heading { grid-column: 1 / span 2; grid-row: 1; min-height: 24px; margin: 0; gap: 6px; justify-content: flex-start; flex-wrap: nowrap; }
  body:not(.desktop-game) .page-heading > div:first-child { min-width: 0; }
  body:not(.desktop-game) .page-heading h1 { font-size: 16px; line-height: 24px; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body:not(.desktop-game) .chapter-tag { gap: 4px; flex: none; }
  body:not(.desktop-game) .chapter-tag > span { font-size: 16px; padding-right: 5px; }
  body:not(.desktop-game) .chapter-tag > div { font-size: 12px; letter-spacing: 0; white-space: nowrap; }
  body:not(.desktop-game) .campaign-toolbar { display: contents; }
  body:not(.desktop-game) .campaign-toolbar > * { grid-column: auto; }
  body:not(.desktop-game) #campaign-status {
    grid-column: 3 / -1; grid-row: 1; margin: 0; font-size: 12px; line-height: 1.2; color: #aab3ae; text-align: right;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  body:not(.desktop-game) .campaign-toolbar button {
    min-width: 0; min-height: 44px; height: 44px; padding: 2px 1px; font-size: 12px; line-height: 1.2; letter-spacing: 0;
    overflow: hidden; white-space: nowrap;
  }
  body:not(.desktop-game) .campaign-toolbar .mp-train-entry { font-size: 12px; }
  html.i18n-en body:not(.desktop-game) .campaign-toolbar button { white-space: normal; overflow-wrap: anywhere; line-height: 1.1; }

  /* ---------- battle column order ---------- */
  body:not(.desktop-game) .game-layout { display: flex; flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 4px 5px; }
  body:not(.desktop-game) .game-layout .adventure-column,
  body:not(.desktop-game) .game-layout .board-column,
  body:not(.desktop-game) .game-layout .squad-section { display: contents; }
  body:not(.desktop-game) .game-layout .adventure-column > *,
  body:not(.desktop-game) .game-layout .board-column > *,
  body:not(.desktop-game) .game-layout .squad-section > * { flex: 0 0 100%; min-width: 0; order: 8; margin: 0; }
  body:not(.desktop-game) .game-layout .battle-panel { order: 1; }
  body:not(.desktop-game) .game-layout #enemy-conditions { order: 2; flex: 1 1 0; }
  body:not(.desktop-game) .game-layout .target-toolbar { order: 3; flex: 0 0 auto; }
  body:not(.desktop-game) .game-layout #hero-roster { order: 4; }
  body:not(.desktop-game) .game-layout .board-panel { order: 5; }
  body:not(.desktop-game) .game-layout #synergy-strip { order: 6; }
  body:not(.desktop-game) .game-layout .turn-result { order: 7; }
  /* the enemy rows repeat the figures (which are the tap targets on phone); the long mechanic text lives behind the chips (enemy details) */
  body:not(.desktop-game) .game-layout #enemy-targets,
  body:not(.desktop-game) .game-layout #mechanic-info,
  body:not(.desktop-game) .game-layout .squad-section .section-heading,
  body:not(.desktop-game) .game-layout .journey-footer { display: none; }

  /* ---------- encounter panel ---------- */
  body:not(.desktop-game) .battle-panel,
  body:not(.desktop-game) .battle-panel.minion-battle { height: max(164px, calc(224px - env(safe-area-inset-top, 0px))); border-radius: 6px; }
  body:not(.desktop-game) .battle-topline { padding: 6px 10px; min-height: 30px; }
  body:not(.desktop-game) .location { gap: 4px; font-size: 12px; letter-spacing: 0; text-shadow: 0 1px 4px #000; }
  body:not(.desktop-game) .location svg { width: 15px; }
  body:not(.desktop-game) .location b { padding-inline: 3px; }
  body:not(.desktop-game) .wave-dots { gap: 4px; }
  body:not(.desktop-game) .wave-dots span { width: 12px; height: 4px; }
  body:not(.desktop-game) .enemy-info { top: 32px; left: 12px; right: 12px; max-width: 300px; }
  body:not(.desktop-game) .enemy-kicker { font-size: 12px; line-height: 16px; letter-spacing: .5px; color: #c9cfca; text-shadow: 0 1px 4px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body:not(.desktop-game) .enemy-info h2 { margin: 1px 0 4px; font-size: 20px; line-height: 26px; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body:not(.desktop-game) .enemy-health-row { gap: 6px; }
  body:not(.desktop-game) .enemy-health-row .element-badge { width: 18px; height: 18px; font-size: 12px; flex: none; }
  body:not(.desktop-game) .enemy-health-track { height: 5px; }
  body:not(.desktop-game) .enemy-health-row > span:last-child { font-size: 12px; text-shadow: 0 1px 3px #000; }
  body:not(.desktop-game) .battle-bottom { bottom: 7px; left: 10px; right: 10px; align-items: flex-end; }
  body:not(.desktop-game) .enemy-intent { gap: 6px; min-width: 0; }
  body:not(.desktop-game) .sword-icon { font-size: 18px; }
  body:not(.desktop-game) .enemy-intent > div { font-size: 12px; line-height: 16px; letter-spacing: 0; text-shadow: 0 1px 4px #000; }
  body:not(.desktop-game) .enemy-intent small { margin-top: 1px; font-size: 12px; line-height: 16px; color: #b8bfbc; }
  body:not(.desktop-game) .enemy-intent small b { font-size: 14px; }
  body:not(.desktop-game) .enemy-intent small > span:first-of-type { margin: 0 3px; }
  body:not(.desktop-game) .battle-stage { gap: 4px; font-size: 12px; letter-spacing: .5px; flex: none; }
  body:not(.desktop-game) .battle-stage strong { font-size: 26px; line-height: 1; }
  body:not(.desktop-game) .battle-stage > span { font-size: 12px; }
  body:not(.desktop-game) .battle-float small { font-size: 12px; }
  body:not(.desktop-game) .wave-intro span, body:not(.desktop-game) .wave-intro i { font-size: 12px; letter-spacing: 1px; }
  /* figures (minion layers, Boss with guards): right of the name block, each one a big tap target */
  body:not(.desktop-game) .battle-panel .enemy-sprites { inset: 34px 10px 46px 46%; gap: 6px; }
  body:not(.desktop-game) .battle-panel .enemy-sprites:not([hidden]) ~ .enemy-info { max-width: calc(46% - 18px); }
  body:not(.desktop-game) .battle-panel .enemy-figure { max-width: none; min-width: 0; flex: 1 1 0; }
  body:not(.desktop-game) .battle-panel .enemy-figure img { object-fit: contain; object-position: center 30%; }
  body:not(.desktop-game) .battle-panel .enemy-figure small { bottom: 0; padding: 3px 4px 4px; font-size: 12px; line-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body:not(.desktop-game) .battle-panel .enemy-figure .figure-name { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
  body:not(.desktop-game) .battle-panel .enemy-figure .figure-health { display: block; height: 3px; margin: 2px 0; }
  body:not(.desktop-game) .battle-panel .enemy-figure .figure-mechanics i { font-size: 12px; }
  body:not(.desktop-game) .battle-panel .enemy-figure .figure-mechanics { margin-left: 4px; }
  /* English: element badges carry a word, names are longer */
  html.i18n-en body:not(.desktop-game) .enemy-health-row .element-badge,
  html.i18n-en body:not(.desktop-game) #hero-roster .hero-element { width: auto; min-width: 18px; padding: 0 3px; }
  html.i18n-en body:not(.desktop-game) .enemy-info h2 { font-size: 17px; line-height: 20px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-bottom: 5px; }
  html.i18n-en body:not(.desktop-game) .chapter-tag > div { display: none; }
  html.i18n-en body:not(.desktop-game) .chapter-tag > span { border-right: 0; }

  /* ---------- chips + enemy buttons: one 44 px row ---------- */
  body:not(.desktop-game) #enemy-conditions {
    display: flex; flex-wrap: nowrap; align-items: center; gap: 5px; min-height: 44px; margin: 0; padding: 0;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; cursor: pointer;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
            mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
  }
  body:not(.desktop-game) #enemy-conditions::-webkit-scrollbar { display: none; }
  body:not(.desktop-game) #enemy-conditions:empty { display: none; }
  body:not(.desktop-game) #enemy-conditions .condition-chip { flex: none; display: inline-flex; align-items: center; min-height: 32px; padding: 0 9px; font-size: 12px; line-height: 1.2; white-space: nowrap; border-radius: 16px; }
  body:not(.desktop-game) #enemy-conditions .condition-chip:last-child { margin-right: 14px; }
  body:not(.desktop-game) .target-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-height: 44px; margin: 0; font-size: 12px; }
  body:not(.desktop-game) .target-toolbar #target-mode { display: none; }
  body:not(.desktop-game) .game-layout:has(#enemy-conditions:empty) .target-toolbar { flex: 1 1 100%; justify-content: space-between; }
  body:not(.desktop-game) .game-layout:has(#enemy-conditions:empty) .target-toolbar #target-mode { display: block; min-width: 0; color: #9aa6a1; line-height: 1.3; }
  body:not(.desktop-game) .target-toolbar > span:last-child { display: flex; gap: 5px; flex: none; }
  body:not(.desktop-game) .target-toolbar button { min-width: 66px; min-height: 44px; margin: 0; padding: 0 8px; font-size: 12px; white-space: nowrap; }

  /* ---------- team cards ---------- */
  body:not(.desktop-game) #hero-roster { gap: 5px; }
  body:not(.desktop-game) #hero-roster .hero-card { height: 76px; }
  body:not(.desktop-game) #hero-roster .hero-element { top: 3px; left: 3px; width: 18px; height: 18px; font-size: 12px; }
  body:not(.desktop-game) #hero-roster .hero-name { bottom: 18px; left: 4px; right: 2px; font-size: 12px; line-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: clip; letter-spacing: 0; text-shadow: 0 1px 3px #000; }
  body:not(.desktop-game) #hero-roster .hero-ready { bottom: 3px; left: 3px; right: 1px; font-size: 12px; line-height: 14px; letter-spacing: -.6px; white-space: nowrap; overflow: hidden; text-shadow: 0 1px 3px #000; }
  body:not(.desktop-game) #hero-roster .hero-ready > span { display: none; }

  /* ---------- board panel: life, turn + timer, board ---------- */
  body:not(.desktop-game) .board-panel { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 5px 6px 6px; }
  body:not(.desktop-game) .board-panel > * { flex: 0 0 100%; min-width: 0; order: 9; }
  body:not(.desktop-game) .board-panel > .active-effects { order: 0; margin: 0 0 4px; font-size: 12px; line-height: 1.35; }
  body:not(.desktop-game) .board-panel > .player-health { order: 1; margin: 0 1px; }
  body:not(.desktop-game) .board-panel > .board-heading { order: 2; flex: 0 0 auto; margin: 3px 8px 0 1px; }
  body:not(.desktop-game) .board-panel > .move-status { order: 3; flex: 1 1 0; margin: 3px 1px 0; }
  body:not(.desktop-game) .board-panel > .timer-track { order: 4; margin: 3px 1px 4px; height: 3px; }
  body:not(.desktop-game) .board-panel > .board-wrap { order: 5; flex: 0 0 auto; }
  body:not(.desktop-game) .board-heading > div:first-child { display: none; }
  body:not(.desktop-game) .turn-badge { gap: 4px; padding-left: 0; border: 0; font-size: 12px; letter-spacing: .5px; align-items: baseline; }
  body:not(.desktop-game) .turn-badge b { font-size: 16px; line-height: 20px; }
  body:not(.desktop-game) .health-label { margin-bottom: 3px; font-size: 12px; line-height: 16px; }
  body:not(.desktop-game) .health-label > strong { font-size: 13px; }
  body:not(.desktop-game) .health-label > strong > span { font-size: 12px; }
  body:not(.desktop-game) .heart-small { margin-right: 3px; font-size: 12px; }
  body:not(.desktop-game) .player-health-track { height: 5px; }
  body:not(.desktop-game) .move-status { font-size: 12px; line-height: 20px; }
  body:not(.desktop-game) .move-status > span:last-child { font-size: 12px; }
  body:not(.desktop-game) .move-status b { font-size: 14px; margin-left: 4px; }
  /* 6 x 5 board: 60 px cells (>= 58), centred; the strip of board rules (引力 / 星砂 / 吞色 …) follows right under it */
  body:not(.desktop-game) .board-wrap { width: min(100%, 390px); margin-inline: auto; padding: 4px; }
  body:not(.desktop-game) .board { gap: 3px; }
  body:not(.desktop-game) .orb-cell { padding: 3px; }
  /* board rule strip: one row (chips shrink with an ellipsis; tapping a chip with ? opens its rule card, the compass keeps its size) */
  body:not(.desktop-game) .board-wrap .mx-telegraph { flex-wrap: nowrap; gap: 4px; }
  body:not(.desktop-game) .board-wrap .mx-chip { display: block; flex: 0 1 auto; min-width: 0; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 20px; padding: 0 8px 0 6px; }
  body:not(.desktop-game) .board-wrap .mx-chip b { display: inline; margin-right: 3px; }
  body:not(.desktop-game) .board-wrap .mx-chip[data-rule-intro] { position: relative; padding-right: 24px; }
  body:not(.desktop-game) .board-wrap .mx-chip[data-rule-intro]::after { position: absolute; right: 5px; top: 50%; width: 15px; height: 15px; margin: -7.5px 0 0; font-size: 11px; }
  body:not(.desktop-game) .board-wrap .mx-compass { flex: none; }
  body:not(.desktop-game) .board-hint { order: 6; min-height: 28px; padding: 4px 2px 0; font-size: 12px; line-height: 1.35; justify-content: flex-start; }
  body:not(.desktop-game) .board-hint span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  body:not(.desktop-game) .board-actions { order: 7; padding-top: 6px; margin-top: 4px; }
  body:not(.desktop-game) .board-actions .secondary-button { min-height: 44px; padding: 6px 14px; font-size: 13px; }
  body:not(.desktop-game) .board-actions .text-button { min-height: 44px; padding-inline: 10px; font-size: 13px; }

  /* ---------- below the board: team skills, turn result, footer ---------- */
  /* 合击 button: lifted to the top of the cards so it never covers the names or the cooldown line */
  body:not(.desktop-game) #hero-roster > .sy-combo { transform: translateY(-14px); }
  body:not(.desktop-game) #hero-roster > .sy-thread { transform: translateY(-14px); }
  body:not(.desktop-game) #hero-roster > .sy-combo:hover, body:not(.desktop-game) #hero-roster > .sy-combo:focus-visible { transform: translateY(-14px) scale(1.08); }
  body:not(.desktop-game) #synergy-strip { margin-top: 2px; }
  body:not(.desktop-game) #synergy-strip .sy-summary { min-height: 44px; font-size: 13px; }
  body:not(.desktop-game) .turn-result { padding: 8px 0 2px; }
  body:not(.desktop-game) .turn-result > div { padding-left: 12px; }
  body:not(.desktop-game) .turn-result span { font-size: 12px; letter-spacing: .5px; }
  body:not(.desktop-game) .turn-result strong { margin-top: 2px; font-size: 20px; }
  body:not(.desktop-game) .turn-result small { font-size: 12px; letter-spacing: 0; }
  body:not(.desktop-game) .page-footer { flex-wrap: wrap; justify-content: space-between; gap: 2px 8px; margin-top: 6px; padding: 6px 0 0; font-size: 12px; letter-spacing: .5px; }
  body:not(.desktop-game) .page-footer > span { display: none; }
  body:not(.desktop-game) .page-footer .element-legend { order: 3; flex: 1 0 100%; justify-content: center; font-size: 12px; }
  body:not(.desktop-game) .page-footer .element-legend span { font-size: 12px; }
  body:not(.desktop-game) .page-footer button { min-height: 44px; padding-inline: 4px; font-size: 13px; }
  body:not(.desktop-game) .toast { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); font-size: 13px; } /* verify: was 11 px on phone */
}

/* First visit on a phone: 「元素之塔」 welcome page before stage 1 and its battle tutorial (game.mjs phoneWelcome; created on phones only).
   The tower art is the world map web copy (2752 x 1536) shown 512 px tall = 1536 device px at DPR 3, never upscaled. */
@media (max-width: 650px) {
  body:not(.desktop-game) .m16-welcome {
    position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden;
    background: #0b1014; color: var(--text);
    padding: env(safe-area-inset-top, 0px) max(20px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left));
  }
  body:not(.desktop-game) .m16-welcome[hidden] { display: none; }
  body:not(.desktop-game) .m16w-art {
    position: absolute; left: 0; right: 0; top: 0; height: min(512px, 60vh);
    background: url("./assets/ui-display/world-tower/world-map-2752.webp") 50% 0 / auto 100% no-repeat;
  }
  body:not(.desktop-game) .m16w-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, #0b101466, transparent 18%, transparent 55%, #0b1014 98%); }
  body:not(.desktop-game) .m16w-body { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
  body:not(.desktop-game) .m16w-brand { display: flex; align-items: center; gap: 8px; font: 600 30px/1.2 var(--serif); letter-spacing: 6px; color: #f1e6c8; text-shadow: 0 2px 12px #000; }
  body:not(.desktop-game) .m16w-mark { font: 36px/1 Georgia, serif; color: var(--gold); }
  body:not(.desktop-game) .m16w-kicker { margin: -4px 0 0; font-size: 13px; letter-spacing: 6px; color: var(--gold); }
  body:not(.desktop-game) .m16w-body h2 { margin: 6px 0 0; font: 500 21px/1.45 var(--serif); letter-spacing: 2px; }
  body:not(.desktop-game) .m16w-text { margin: 0 0 6px; max-width: 360px; text-wrap: balance; font-size: 14px; line-height: 1.6; color: #b9c2bd; }
  body:not(.desktop-game) .m16w-body .m16w-start { width: 100%; max-width: 360px; min-height: 52px; margin: 0; font-size: 16px; }
  body:not(.desktop-game) .m16w-body .m16w-opening { width: 100%; max-width: 360px; min-height: 46px; margin: 0; font-size: 14px; }
}
/* mobile16pm verify: Hades soul vessel (god-fx .gf-vessel.is-m) moves from the panel's top-right corner (it covered the rightmost
   enemy figure) to the empty left side under the HP bar; its count is 12-14 px. The transient board combo pop keeps a 12 px label. */
@media (max-width: 650px) {
  body:not(.desktop-game) .gf-vessel.is-m { right: auto; left: 14px; top: 100px; width: 44px; }
  body:not(.desktop-game) .gf-vessel.is-m .gf-vessel-num { margin-top: -2px; padding: 0 5px; font-size: 12px; line-height: 16px; white-space: nowrap; }
  body:not(.desktop-game) .gf-vessel.is-m .gf-vessel-num b { font-size: 14px; }
  body:not(.desktop-game) .gf-vessel.is-m .gf-vessel-num small { font-size: 12px; }
  body:not(.desktop-game) .combo-overlay small { font-size: 12px; letter-spacing: 3px; }
  /* Codex #5: the board-rule chips under the board stay 22 px pills (one-screen budget) but get a 44 px tap box: 5 px / 19 px transparent
     top/bottom borders (never over the board, stops before 寻找灵感), pulled back with negative margins (row height unchanged); the 1 px outline is an inset shadow on the padding box. */
  body:not(.desktop-game) .board-wrap .mx-chip[data-rule-intro] { border-width: 5px 1px 19px; border-color: transparent; margin-block: -5px -19px; background-clip: padding-box; border-radius: 10px 10px 10px 10px / 15px 15px 29px 29px; box-shadow: inset 0 0 0 1px #c9b47a88; }
  body:not(.desktop-game) .board-wrap .mx-chip[data-rule-intro]:hover { border-color: transparent; }
  body:not(.desktop-game) .board-wrap .mx-chip.mx-danger[data-rule-intro] { box-shadow: inset 0 0 0 1px #ff6ad5; }
  body:not(.desktop-game) .board-wrap .mx-chip.mx-ready[data-rule-intro] { box-shadow: inset 0 0 0 1px #ffd76a, inset 0 0 6px #ffd76a66; }
}
@media (min-width: 651px) { .m16-welcome { display: none !important; } }
