/* ═══════════════════════════════════════════════════════════
   手機橫屏專用佈局（主驗收尺寸）
   ───────────────────────────────────────────────────────────
   呢個唔係「直版壓扁」，係一套獨立版面：

     戰鬥 ┌──────────┬─────────────┬──────────┐
          │ 敵人     │  戰鬥日誌   │ 玩家 HUD │
          │ 立繪/HB  │  （可滾）   │ 血/能量  │
          │ 意圖     │             │ 擋       │
          ├──────────┴─────────────┼──────────┤
          │ 牌堆（4 格）           │ 結束回合 │
          ├────────────────────────┤ 暫停     │
          │ 手牌（一排橫滑）       │          │
          └────────────────────────┴──────────┘

   判斷式：orientation: landscape + max-height: 500px
   （手機橫屏高 320–430；桌面橫屏通常 >600，唔會誤中）

   真機要點：
   - 用 100dvh（保留 100vh 兜底）——手機瀏覽器 chrome 會令 100vh
     大於可見區，再加 overflow:hidden 就會「手牌裁底／睇唔到結束回合」
   - 操作欄 flex-shrink:0，結束回合／暫停永遠喺屏內
   - 手牌卡 max-height:100%，跟行高縮，唔好撑出嚟被裁
   ═══════════════════════════════════════════════════════════ */

@media (orientation: landscape) and (max-height: 500px) {
  /* ── 全域：壓縮垂直間距，禁水平捲動／偏右 ── */
  html,
  body {
    overflow-x: hidden;
    overflow-y: hidden;
    max-width: 100vw;
    width: 100%;
    height: 100%;
    height: 100dvh;
  }

  .app {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    padding: 0.28rem 0.4rem;
    padding-top: max(0.2rem, env(safe-area-inset-top, 0px));
    padding-right: max(0.35rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(0.35rem, env(safe-area-inset-left, 0px));
    align-items: stretch;
    justify-items: stretch;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: hidden;
    width: 100%;
    max-width: 100%;
  }

  .screen,
  .screen-wide,
  .screen-battle {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    gap: 0.25rem;
    margin-inline: auto;
  }

  /* ════════════════════════════════════════════
     ① 戰鬥頁：三區 grid（左敵 / 中日誌 / 右 HUD）
     ════════════════════════════════════════════ */
  .screen-battle {
    display: grid;
    /* 左 26% 敵人｜中間自適應日誌｜右 25% HUD + 操作 */
    grid-template-columns: minmax(0, 26%) minmax(0, 1fr) minmax(0, 25%);
    grid-template-rows: minmax(0, 1fr) auto minmax(0, 0.95fr);
    grid-template-areas:
      "enemy log    player"
      "piles piles  player"
      "hand  hand   act";
    column-gap: 0.35rem;
    row-gap: 0.22rem;
    /* 100vh 兜底（舊機）→ 100dvh 對齊可見視口（防裁底） */
    height: calc(100vh - 0.56rem);
    height: calc(100dvh - 0.56rem);
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
    overflow: hidden;
  }

  /* 關鍵：battle-top 用 display:contents，令敵人／玩家直接成為 grid item。
     咁就唔使改 HTML 結構。 */
  .battle-top {
    display: contents;
  }

  /* ── 左：敵人 ── */
  #fighter-enemy {
    grid-area: enemy;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.3rem;
    border-radius: 9px;
    min-height: 0;
    overflow: hidden;
  }

  #enemy-portrait {
    width: 100%;
    max-height: 45%;
    object-fit: cover;
    object-position: 50% 22%;
    border-radius: 7px;
    flex: 0 1 auto;
  }

  #fighter-enemy .fighter-meta {
    display: flex;
    flex-direction: column;
    gap: 0.08rem;
    min-height: 0;
  }

  #fighter-enemy .fighter-meta strong {
    font-size: 0.72rem;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* 意圖：擺敵人卡底，一眼睇到 */
  #enemy-intent {
    font-size: 0.68rem;
    padding: 0.12rem 0.3rem;
    gap: 0.18rem;
    align-self: flex-start;
    flex-wrap: wrap;
    row-gap: 0;
    color: rgba(220, 232, 248, 0.92);
  }

  #enemy-intent .intent-icon {
    font-size: 0.74rem;
  }

  /* 戰前句：首回合一行，唔好撐爆敵人欄 */
  #fighter-enemy .enemy-flavor-line {
    font-size: 0.64rem;
    line-height: 1.3;
    margin: 0.05rem 0 0;
    max-height: 2.8em;
    color: rgba(220, 232, 248, 0.9);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  /* ── 中：戰鬥日誌（可滾，唔會撐高） ── */
  .battle-log {
    grid-area: log;
    margin: 0;
    padding: 0.28rem 0.4rem;
    font-size: 0.72rem;
    line-height: 1.45;
    color: rgba(220, 232, 248, 0.9);
    overflow-y: auto;
    overscroll-behavior: contain;
    min-height: 0;
    border-radius: 8px;
  }

  .battle-log li {
    padding-block: 0.04rem;
  }

  /* ── 右上：玩家 HUD ── */
  #fighter-player {
    grid-area: player;
    display: flex;
    flex-direction: column;
    gap: 0.16rem;
    padding: 0.3rem;
    border-radius: 9px;
    min-height: 0;
    overflow: hidden;
  }

  #fighter-player .fighter-meta {
    display: flex;
    flex-direction: column;
    gap: 0.09rem;
    min-height: 0;
  }

  #player-anchor {
    font-size: 0.74rem;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .battle-route {
    font-size: 0.58rem;
    opacity: 0.8;
  }

  .passive-chip {
    font-size: 0.68rem;
    padding: 0.06rem 0.24rem;
    align-self: flex-start;
  }

  .passive-chip-state {
    font-size: 0.62rem;
  }

  #fighter-player .hp-bar {
    height: 7px;
    border-radius: 4px;
  }

  #fighter-player .hp-text {
    font-size: 0.62rem;
    line-height: 1.1;
  }

  .stat-row {
    gap: 0.2rem;
    flex-wrap: nowrap;
  }

  .stat-pill {
    padding: 0.06rem 0.28rem;
    font-size: 0.6rem;
    gap: 0.1rem;
  }

  .stat-pill .stat-num {
    font-size: 0.76rem;
  }

  .stat-pill .stat-max {
    font-size: 0.54rem;
  }

  .energy-hint {
    font-size: 0.56rem;
    line-height: 1.25;
  }

  /* ── 中下：牌堆列（四格逼一行） ── */
  .pile-row {
    grid-area: piles;
    margin: 0;
    gap: 0.2rem;
    flex-wrap: nowrap;
  }

  .pile-row > * {
    min-height: 24px;
    padding: 0.02rem 0.24rem;
    font-size: 0.58rem;
    gap: 0.12rem;
  }

  .pile-row .pile-icon {
    font-size: 0.56rem;
  }

  /* ── 左下：手牌（一排橫滑，唔換行；卡高跟內容，硬上限＝行高） ── */
  .hand {
    grid-area: hand;
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    align-content: flex-start;
    gap: 0.28rem;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    height: 100%;
    padding: 0.05rem 0 0.08rem;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .hand .card-face,
  .card-face {
    flex: 0 0 92px;
    width: 92px;
    max-width: 92px;
    /* 硬上限：唔可以高過手牌行，否則 overflow:hidden 會裁底 */
    max-height: calc(100% - 2px);
    height: auto;
    padding: 0.2rem 0.22rem 0.22rem;
    gap: 0.06rem;
    border-radius: 8px;
    min-height: 0;
    overflow: hidden;
  }

  .hand .card-art,
  .card-art {
    aspect-ratio: 16 / 10;
    max-height: 3rem;
    width: 100%;
    object-fit: cover;
    border-radius: 5px;
    flex: 0 1 auto;
  }

  .card-name {
    font-size: 0.68rem;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .card-type,
  .card-stats {
    font-size: 0.56rem;
    line-height: 1.2;
  }

  .card-cost {
    width: 17px;
    height: 17px;
    font-size: 0.58rem;
    top: 2px;
    left: 2px;
  }

  /* 手牌上嘅 flavor 唔顯示（長按有詳情） */
  .hand .card-blurb {
    display: none;
  }

  /*
   * 選牌獎卡：唔跟手牌嘅 92px 高／overflow:hidden。
   * 否則青字 .card-stats 會壓住橙金 .reward-why（横屏同樣叠字）。
   */
  .reward-cell .card-face {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    max-height: none;
    height: auto;
    min-height: 0;
    overflow: hidden;
    padding: 0.28rem 0.3rem 0.32rem;
    gap: 0.1rem;
  }

  .reward-cell .card-art {
    max-height: 2.6rem;
    aspect-ratio: 16 / 10;
  }

  .reward-cell .card-stats {
    font-size: 0.62rem;
    line-height: 1.25;
    flex: 0 0 auto;
  }

  .reward-why {
    font-size: 0.72rem;
    line-height: 1.35;
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
  }

  .reward-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
    min-height: 0;
    overflow: auto;
  }

  /* ── 右下：操作（結束回合 + 暫停，永遠可見，唔畀壓縮） ── */
  .battle-actions {
    grid-area: act;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: stretch;
    gap: 0.22rem;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    padding-bottom: 0.05rem;
    flex-shrink: 0;
    overflow: visible;
    z-index: 6;
  }

  .battle-actions .btn {
    min-height: 42px;
    font-size: 0.8rem;
    width: 100%;
    padding: 0.32rem 0.45rem;
    flex: 0 0 auto;
  }

  .pause-btn--battle {
    min-height: 34px;
    font-size: 0.7rem;
    width: 100%;
    flex: 0 0 auto;
  }

  /* 音效掣喺戰鬥頁收起（設定頁有） */
  .screen-battle .sfx-toggle {
    display: none;
  }

  /* ── 牌組預覽展開：佔手牌區，內部自己滾 ── */
  .deck-panel--battle {
    grid-area: hand;
    margin: 0;
    padding: 0.3rem 0.4rem;
    max-height: 100%;
    overflow-y: auto;
    gap: 0.3rem;
  }

  .deck-panel--battle h2 {
    font-size: 0.76rem;
    margin: 0;
  }

  .deck-panel--battle .deck-overview {
    font-size: 0.7rem;
    color: rgba(220, 232, 248, 0.9);
  }

  .deck-panel--battle .deck-row {
    padding: 0.14rem 0.3rem;
    font-size: 0.64rem;
  }

  .deck-panel--battle .deck-cost {
    width: 1.15rem;
    height: 1.15rem;
    font-size: 0.58rem;
  }

  .deck-panel--battle .deck-toggle {
    min-height: 30px;
    font-size: 0.68rem;
  }

  /* ── 勝／敗 banner：絕對定位，唔食版面 ── */
  .battle-banner {
    position: absolute;
    top: 0.35rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 12;
    font-size: 0.86rem;
    padding: 0.14rem 0.6rem;
    border-radius: 999px;
  }

  .boss-afterword {
    display: none;
  }

  /* ════════════════════════════════════════════
     ② 地圖頁：三欄（6 格 → 2 行）
     ════════════════════════════════════════════ */
  .screen-wide {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "bar"
      "strip"
      "list"
      "foot";
    gap: 0.24rem;
    height: calc(100vh - 0.56rem);
    height: calc(100dvh - 0.56rem);
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
    overflow: hidden;
  }

  .run-bar {
    grid-area: bar;
    margin: 0;
    padding: 0;
    gap: 0.4rem;
    align-items: center;
  }

  .run-bar .eyebrow {
    font-size: 0.6rem;
  }

  .run-bar .run-title {
    font-size: 0.82rem;
    line-height: 1.15;
  }

  .run-stats {
    font-size: 0.62rem;
    gap: 0.28rem;
    flex-wrap: nowrap;
  }

  .pause-btn {
    min-height: 28px;
    font-size: 0.62rem;
    padding: 0.1rem 0.42rem;
  }

  .act-strip {
    grid-area: strip;
    margin: 0;
    gap: 0.24rem;
  }

  .act-strip li {
    padding: 0.1rem 0.3rem;
    font-size: 0.58rem;
    line-height: 1.2;
  }

  .map-panel {
    grid-area: list;
    margin: 0;
    padding: 0.3rem 0.4rem;
    min-height: 0;
    /* 矮屏：寧可面板內滾，唔好壓扁節點令 type／sub／title 叠字 */
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
  }

  .map-panel h2 {
    font-size: 0.74rem;
    margin: 0;
    flex-shrink: 0;
  }

  /* 六格三欄兩行，全部入一屏 */
  .map-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.26rem;
    min-height: 0;
    align-content: start;
  }

  .map-node {
    padding: 0.24rem 0.3rem;
    gap: 0.1rem 0.24rem;
    border-radius: 7px;
    /* min-content：唔畀 grid 把節點壓矮過文案，避免 flex 子項叠字 */
    min-height: min-content;
    align-content: start;
  }

  .map-body {
    flex-shrink: 0;
    min-height: min-content;
    gap: 0.12rem;
  }

  .map-body > * {
    flex-shrink: 0;
  }

  .map-idx {
    width: 1.05rem;
    height: 1.05rem;
    font-size: 0.56rem;
    flex-shrink: 0;
  }

  .map-type {
    color: rgba(220,232,248,0.9);
    font-size: 0.6rem;
  }

  .map-sub,
  .map-title {
    font-size: 0.64rem;
    line-height: 1.28;
    color: rgba(220, 232, 248, 0.9);
  }

  .map-cta,
  .map-done {
    font-size: 0.66rem;
    padding: 0.12rem 0.36rem;
    /* 橫屏都要掂得到：唔可以再 min-height:0 壓到 15px */
    min-height: 28px;
    min-width: 52px;
    color: rgba(220, 232, 248, 0.92);
  }

  .foot-note {
    grid-area: foot;
    margin: 0;
    font-size: 0.64rem;
    color: rgba(200, 214, 232, 0.88);
  }

  .opening-block {
    font-size: 0.7rem;
    display: none;
  }

  .status-map {
    color: rgba(220,232,248,0.9);
    font-size: 0.68rem;
    margin: 0;
  }

  /* ════════════════════════════════════════════
     ③ 事件頁：三選項橫排；整頁鎖高，大掣可見
     ════════════════════════════════════════════ */
  .screen:has(.event-choices) {
    height: calc(100vh - 0.56rem);
    height: calc(100dvh - 0.56rem);
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 0.2rem;
  }

  .screen:has(.event-choices) .brand-block {
    margin: 0;
  }

  .screen:has(.event-choices) .panel {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .screen:has(.event-choices) .panel > .lede {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.62rem;
    line-height: 1.3;
    margin: 0;
  }

  .screen:has(.event-choices) .actions {
    flex-shrink: 0;
  }

  .event-choices {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.3rem;
    min-height: 0;
    flex: 1 1 auto;
  }

  /* 選項多過 3（士多／休息）：改兩欄，內部自己滾，底欄離開掣固定 */
  .event-choices:has(> :nth-child(4)) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-y: auto;
    overscroll-behavior: contain;
    max-height: none;
  }

  .event-choice {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0.1rem;
    padding: 0.28rem 0.36rem;
    font-size: 0.64rem;
    line-height: 1.28;
    min-height: 0;
    text-align: left;
  }

  .event-choice .choice-label {
    font-size: 0.66rem;
    line-height: 1.2;
  }

  .event-choice .choice-effect {
    font-size: 0.56rem;
    line-height: 1.25;
  }

  .event-art {
    max-height: 2.8rem;
    object-fit: cover;
    border-radius: 7px;
  }

  .event-art img {
    max-height: 2.8rem;
    width: 100%;
    object-fit: cover;
  }

  /* 休息／士多：長列表唔好逼成頁 scroll；內容區滾、離開掣鎖底 */
  .screen:has(.panel-shop),
  .screen:has([data-action="leave-shop"]) {
    height: calc(100vh - 0.56rem);
    height: calc(100dvh - 0.56rem);
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
  }

  .screen:has(.panel-shop) > .panel,
  .screen:has(.panel-shop) > .panel-shop,
  .screen:has([data-action="leave-shop"]) > .panel,
  .screen:has([data-action="leave-shop"]) > .panel-shop {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1 1 auto;
  }

  .screen:has([data-action="leave-shop"]) > .actions {
    flex: 0 0 auto;
    margin-top: 0;
  }

  .screen:has([data-action="leave-shop"]) > .actions .btn {
    min-height: 36px;
  }

  /* ════════════════════════════════════════════
     ④ 戰果頁：兩欄 + 固定底欄（全寬，唔鎖 430）
     ════════════════════════════════════════════ */
  .screen-result {
    /* 底欄高 47px（padding 0.2rem×2 + btn 40）→ 預留 3.1rem 夠，唔好留太多 */
    padding-bottom: 3.1rem;
    gap: 0.2rem;
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
    height: calc(100vh - 0.56rem);
    height: calc(100dvh - 0.56rem);
    min-height: 0;
    overflow: hidden;
  }

  .screen-result .brand {
    font-size: 0.98rem;
    line-height: 1.15;
  }

  .screen-result .result-sub,
  .screen-result .tagline {
    font-size: 0.62rem;
  }

  .clear-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.16rem 0.45rem;
    align-items: start;
    padding: 0.3rem 0.42rem;
  }

  .clear-hero h2 {
    font-size: 0.78rem;
    margin: 0;
    grid-column: 1 / -1;
    line-height: 1.2;
  }

  .clear-badge {
    font-size: 0.66rem;
    padding: 0.06rem 0.34rem;
    justify-self: start;
    margin: 0;
    line-height: 1.25;
  }

  .clear-hero .eyebrow {
    font-size: 0.56rem;
    margin: 0;
    line-height: 1.2;
  }

  .clear-hero .lede {
    font-size: 0.58rem;
    line-height: 1.3;
    margin: 0;
  }

  .clear-summary,
  .rerun-hook {
    font-size: 0.58rem;
    line-height: 1.3;
    margin: 0;
  }

  /* 六格數據：一行三個，每格只有一行（數字同標籤並排） */
  .clear-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.1rem 0.3rem;
    font-size: 0.64rem;
    line-height: 1.2;
    grid-column: 1 / -1;
    margin: 0;
    padding: 0;
    color: rgba(220, 232, 248, 0.92);
  }

  .clear-stats li {
    display: flex;
    align-items: baseline;
    gap: 0.2rem;
    padding: 0.06rem 0.2rem;
    min-height: 0;
    white-space: nowrap;
    overflow: hidden;
  }

  .clear-stats li span {
    font-size: 0.54rem;
    opacity: 0.8;
  }

  .clear-stats li strong {
    font-size: 0.64rem;
  }

  .clear-keys {
    grid-column: 1 / -1;
    font-size: 0.56rem;
    line-height: 1.3;
    margin: 0;
    display: flex;
    gap: 0.25rem;
    align-items: baseline;
  }

  .clear-keys-label {
    font-size: 0.54rem;
    flex: 0 0 auto;
  }

  .clear-keys-line {
    font-size: 0.64rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: rgba(220, 232, 248, 0.9);
  }

  /* 細節收納區：橫屏唔展開都唔阻主掣 */
  .result-details {
    margin: 0;
  }

  .result-details-summary {
    min-height: 32px;
    padding: 0.24rem 0.45rem;
    font-size: 0.66rem;
  }

  /* 底欄：兩粒掣並排貼底；橫屏用滿寬（唔再 min(430px)） */
  .result-bar {
    padding: 0.2rem 0.4rem;
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom, 0px));
    gap: 0.3rem;
    flex-direction: row;
    align-items: center;
    min-height: 0;
    width: min(100%, calc(100vw - 0.7rem));
    max-width: 100%;
    left: 50%;
    transform: translateX(-50%);
  }

  .result-bar .btn {
    min-height: 38px;
    font-size: 0.78rem;
    padding: 0.28rem 0.6rem;
    border-radius: 9px;
  }

  .result-bar .btn-rerun {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    min-height: 40px;
    flex-direction: row;
    gap: 0.36rem;
    padding: 0.28rem 0.7rem;
    border-radius: 9px;
  }

  .result-bar .btn-rerun-sub {
    display: none;
  }

  .result-bar .btn-ghost {
    flex: 0 0 auto;
    width: auto;
    min-width: 92px;
  }

  /* 敗北頁面板 */
  .near-miss {
    font-size: 0.66rem;
    line-height: 1.4;
    margin: 0 0 0.24rem;
  }

  .next-run {
    gap: 0.16rem;
  }

  .next-run-title {
    font-size: 0.64rem;
    margin: 0;
  }

  .next-run-list {
    font-size: 0.6rem;
    line-height: 1.35;
    gap: 0.12rem;
  }

  /* ════════════════════════════════════════════
     ⑤ 選角頁：角色卡橫排四欄
     ════════════════════════════════════════════ */
  /*
   * 選角：一屏塞四卡＋詳情＋starter＋開局掣。
   * 子項 flex-shrink:0，高度唔夠就捲，唔好叠字。
   */
  .screen:has(.char-list) {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
  }

  .screen:has(.char-list) > * {
    flex-shrink: 0;
  }

  .char-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.28rem;
    min-height: 0;
  }

  /* 必須 display:flex——main.css 係 grid（左圖右字）；橫屏改直向，立繪喺上 */
  .char-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.3rem 0.3rem;
    gap: 0.2rem;
    min-height: min-content;
  }

  .avatar-portrait {
    width: 64px;
    max-width: 100%;
    height: 72px;
    flex: 0 0 auto;
    flex-shrink: 0;
  }

  /* 全身立繪：對準頭／胸，唔好裁到淨黑色地下 */
  .avatar-portrait .char-portrait {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 8%;
    display: block;
  }

  .char-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.06rem;
    min-width: 0;
    flex-shrink: 0;
  }

  .char-name {
    font-size: 0.66rem;
    line-height: 1.15;
  }

  .char-desc,
  .char-playstyle,
  .char-route,
  .char-passive-tag {
    font-size: 0.52rem;
    line-height: 1.15;
  }

  /* 長描述喺橫屏收起（撳卡有詳情） */
  .char-desc,
  .char-playstyle {
    display: none;
  }

  .passive-box {
    font-size: 0.56rem;
    line-height: 1.35;
    padding: 0.2rem 0.34rem;
    margin: 0;
    flex-shrink: 0;
  }

  .deck-toggle {
    flex-shrink: 0;
  }

  /* 橫屏選角空間緊：rerun hook 收起，優先保住立繪／詳情／開局掣 */
  .screen:has(.char-list) .rerun-hook {
    display: none;
  }

  .screen:has(.char-list) .panel {
    overflow: visible;
  }

  /* ════════════════════════════════════════════
     ⑥ 設定頁：橫屏兩欄（左音效＋點玩，右本機進度）
     ════════════════════════════════════════════ */
  .screen-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "head head"
      "sfx  prog"
      "acts acts";
    gap: 0.22rem 0.4rem;
    max-height: calc(100vh - 0.56rem);
    overflow: hidden;
  }

  .screen-settings .brand-block {
    grid-area: head;
  }

  .screen-settings .panel:nth-of-type(1) {
    grid-area: sfx;
  }

  .screen-settings .panel:nth-of-type(2) {
    grid-area: prog;
  }

  .screen-settings .actions {
    grid-area: acts;
  }

  .screen-settings .settings-keys {
    max-height: 2.2rem;
    overflow-y: auto;
  }

  /* ════════════════════════════════════════════
     ⑦ Boss 戰前：左圖右引句
     ════════════════════════════════════════════ */
  .screen-boss-gate {
    display: grid;
    grid-template-columns: minmax(0, 0.75fr) minmax(0, 1.25fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "head head"
      "art  quote"
      "hint hint";
    gap: 0.18rem 0.45rem;
    max-height: calc(100vh - 0.56rem);
    overflow: hidden;
  }

  .screen-boss-gate .brand-block {
    grid-area: head;
  }

  .boss-gate-art {
    grid-area: art;
    margin: 0;
    min-height: 0;
    overflow: hidden;
  }

  .boss-gate-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
  }

  .boss-gate-quote {
    grid-area: quote;
    margin: 0;
    font-size: 0.66rem;
    line-height: 1.4;
    align-self: center;
    padding: 0.3rem 0.4rem;
  }

  .boss-gate-hint {
    grid-area: hint;
    font-size: 0.56rem;
    margin: 0;
  }

  .screen-boss-gate .actions {
    grid-area: hint;
    justify-self: end;
    align-self: center;
  }

  .screen-boss-gate .actions .btn {
    min-height: 32px;
    font-size: 0.7rem;
    padding: 0.2rem 0.65rem;
  }

  /* ════════════════════════════════════════════
     ⑧ 標題／確認：禁止 flex 壓扁叠字
     ────────────────────────────────────────────
     根因：landscape 下 html/body/.app 鎖 100dvh + overflow:hidden，
     .screen 係 column flex，子項預設 flex-shrink:1。
     矮屏（Safari chrome ≈320）或開「覆蓋存檔」確認時，
     .panel-hero-copy 會被壓到 12–20px，但 overflow:visible，
     令 h2／lede 畫出盒子叠到「繼續」鈕或 overwrite modal 上。
     ════════════════════════════════════════════ */
  .screen-title {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    max-height: calc(100vh - 0.56rem);
    max-height: calc(100dvh - 0.56rem);
    gap: 0.28rem;
  }

  .screen-title > * {
    flex-shrink: 0;
  }

  /*
   * slogan panel 喺橫屏屬裝飾（brand 已有 tagline／badge）。
   * 收起之後：繼續鈕／覆蓋確認唔會再被 lede 路线句叠住。
   */
  .screen-title .panel-hero-copy {
    display: none;
  }

  .screen-title .foot-note {
    display: none;
  }

  .screen-title .actions {
    flex-shrink: 0;
    gap: 0.28rem;
  }

  .screen-title .btn-continue {
    flex-shrink: 0;
    min-height: 44px;
    gap: 0.12rem;
  }

  .screen-title .overwrite-confirm {
    flex-shrink: 0;
    /* 加實底，避免半透明透出 brand／daily 造成「叠字」錯覺 */
    background: rgba(48, 10, 14, 0.92);
  }

  /*
   * 開覆蓋確認時只留 modal：brand／daily／sfx 一齊收，
   * 避免矮屏下標題句同警告句抢同一條 Y 軸。
   */
  .screen-title:has(.overwrite-confirm) .brand-block,
  .screen-title:has(.overwrite-confirm) .daily-line,
  .screen-title:has(.overwrite-confirm) .sfx-toggle {
    display: none;
  }

  /* ════════════════════════════════════════════
     ⑨ 其他頁（設定／教學／暫停）：整體壓縮
     ════════════════════════════════════════════ */
  .brand-block {
    gap: 0.08rem;
  }

  .brand,
  .section-title {
    font-size: 0.94rem;
    line-height: 1.18;
  }

  .tagline,
  .lede {
    font-size: 0.6rem;
    line-height: 1.35;
    margin: 0;
  }

  .panel {
    padding: 0.32rem 0.42rem;
    border-radius: 9px;
    gap: 0.24rem;
    min-height: 0;
  }

  .panel h2 {
    font-size: 0.74rem;
    margin: 0;
    line-height: 1.2;
  }

  .actions {
    gap: 0.24rem;
  }

  .actions .btn {
    min-height: 36px;
    font-size: 0.74rem;
    padding: 0.26rem 0.55rem;
  }

  .howto-list {
    font-size: 0.58rem;
    gap: 0.16rem;
    padding-left: 0.9rem;
  }

  .howto-list li {
    font-size: 0.58rem;
    line-height: 1.35;
  }

  /* 教學三步：橫排三欄 */
  .tut-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.28rem;
    min-height: 0;
  }

  .tut-step {
    padding: 0.26rem 0.34rem;
    gap: 0.3rem;
    align-items: flex-start;
    min-height: 0;
  }

  .tut-num {
    width: 1.15rem;
    height: 1.15rem;
    font-size: 0.6rem;
        flex: 0 0 auto;
  }

  .tut-title {
    font-size: 0.68rem;
    line-height: 1.2;
  }

  .tut-key {
    font-size: 0.54rem;
    padding: 0.04rem 0.26rem;
  }

  .tut-text {
    font-size: 0.72rem;
    line-height: 1.3;
  }

  .tut-note {
    font-size: 0.68rem;
    line-height: 1.28;
  }

  .sfx-toggle {
    min-height: 32px;
    font-size: 0.72rem;
    padding: 0.12rem 0.55rem;
  }

  .settings-keys {
    padding: 0.24rem 0.34rem;
    gap: 0.16rem;
    max-height: 3.2rem;
    overflow-y: auto;
  }

  .settings-keys li {
    font-size: 0.56rem;
    line-height: 1.25;
  }

  .foot-note {
    font-size: 0.6rem;
    margin: 0;
    color: rgba(200, 214, 232, 0.88);
  }

  /* ════════════════════════════════════════════
     ⑩ 極矮橫屏（≤360）：再削一層，保住結束回合／暫停
     ════════════════════════════════════════════ */
  @media (max-height: 360px) {
    .app {
      padding: 0.16rem 0.3rem;
    }

    .screen-battle {
      row-gap: 0.14rem;
      column-gap: 0.28rem;
      height: calc(100vh - 0.32rem);
      height: calc(100dvh - 0.32rem);
      max-height: calc(100vh - 0.32rem);
      max-height: calc(100dvh - 0.32rem);
    }

    .screen-wide,
    .screen-result,
    .screen:has(.event-choices),
    .screen:has([data-action="leave-shop"]) {
      height: calc(100vh - 0.32rem);
      height: calc(100dvh - 0.32rem);
      max-height: calc(100vh - 0.32rem);
      max-height: calc(100dvh - 0.32rem);
    }

    #enemy-portrait {
      max-height: 38%;
    }

    .battle-log {
      font-size: 0.56rem;
      padding: 0.18rem 0.3rem;
    }

    .hand .card-face,
    .card-face {
      flex: 0 0 78px;
      width: 78px;
      max-width: 78px;
      padding: 0.14rem 0.16rem;
    }

    /* 矮横屏：獎卡仍跟內容長高，唔被上面 78px 鎖死 */
    .reward-cell .card-face {
      flex: 0 0 auto;
      width: 100%;
      max-width: 100%;
      max-height: none;
      height: auto;
      padding: 0.2rem 0.22rem;
    }

    .card-name {
      font-size: 0.6rem;
      -webkit-line-clamp: 1;
    }

    .card-type,
    .card-stats {
      font-size: 0.5rem;
    }

    .reward-cell .card-stats {
      font-size: 0.56rem;
    }

    .battle-actions .btn {
      min-height: 36px;
      font-size: 0.74rem;
      padding: 0.22rem 0.35rem;
    }

    .pause-btn--battle {
      min-height: 28px;
      font-size: 0.64rem;
    }

    .result-bar .btn,
    .result-bar .btn-rerun {
      min-height: 34px;
      font-size: 0.72rem;
    }
  }
}
