/* Touch layout: keep the arena clear and reserve the lower corners for both thumbs. */
@media (max-width: 780px), (pointer: coarse) and (max-width: 1050px) {
  .game-shell {
    --touch-top: max(6px, env(safe-area-inset-top));
    --touch-bottom: max(8px, env(safe-area-inset-bottom));
    --touch-left: max(8px, env(safe-area-inset-left));
    --touch-right: max(8px, env(safe-area-inset-right));
    min-height: 0;
    height: 100dvh;
  }
  button, a, summary { -webkit-tap-highlight-color: transparent; }
  button, a { touch-action: manipulation; }
  .primary, .secondary, .economy-context-btn, .boss-traffic-btn,
  .topic-guide button, .contract-card, .meta-branch, .meta-remix,
  .role-select .platform-group > summary {
    min-height: 48px;
  }

  .top-hud {
    grid-template-columns: minmax(0, 1fr) 100px;
    gap: 4px 6px;
    padding: var(--touch-top) var(--touch-right) 0 var(--touch-left);
    background: none;
  }
  .top-hud .player-card { width: auto; min-height: 48px; padding: 3px 4px; gap: 5px; }
  .top-hud .portrait { flex: none; width: 36px; height: 36px; }
  .top-hud .player-meta { min-width: 0; }
  .top-hud .player-meta > div:first-child { margin-bottom: 3px; }
  .top-hud .player-meta strong { overflow: hidden; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
  .top-hud .player-meta #statusLabel { display: none; }
  .top-hud .health { height: 12px; }
  .top-hud .health b { font-size: 10px; }
  .top-hud .run-clock { width: 100px; min-height: 48px; padding: 2px 4px; gap: 2px; }
  .top-hud .run-chapter { white-space: nowrap; }
  .top-hud .run-chapter span { font-size: 10px; }
  .top-hud .run-chapter small { display: none; }
  .top-hud .run-clock .chapter-track { height: 5px; }
  .top-hud .run-clock #timer { font-size: 19px; letter-spacing: 1px; }
  .run-clock .story-objective { display: none; }
  .top-hud .resources {
    grid-column: 1 / -1;
    width: calc(100% - 108px);
    justify-self: start;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    margin: 0;
  }
  .top-hud .resources > span { min-width: 0; min-height: 44px; padding: 3px 4px; grid-template-columns: 16px minmax(0, 1fr); gap: 0 3px; }
  .top-hud .resources i { font-size: 14px; }
  .top-hud .resources b { font-size: 14px; }
  .top-hud .resources small { font-size: 9px; line-height: 1.25; white-space: normal; }
  .pause-btn {
    top: calc(var(--touch-top) + 52px);
    right: var(--touch-right);
    width: 48px;
    height: 48px;
    min-height: 48px;
  }
  .audio-controls {
    top: calc(var(--touch-top) + 52px);
    right: calc(var(--touch-right) + 54px);
    height: 48px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none !important;
  }
  .audio-controls #audioToggle { width: 48px; height: 48px; font-size: 20px; border: 2px solid #7596ad; background: #112c43; }
  .audio-controls #screenShakeToggle { width:48px; height:48px; min-height:48px; font-size:11px; border-width:2px; }
  .audio-controls #audioVolume { display: none; }

  .trend-board, .tip, .combo-hud, .meme-feed { display: none; }
  .event-strip {
    top: calc(var(--touch-top) + 104px);
    left: 50%;
    width: max-content;
    max-width: calc(100vw - var(--touch-left) - var(--touch-right));
    min-height: 0;
    padding: 4px 7px;
    transform: translateX(-50%);
    font-size: 10px;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
  }
  .event-strip b { font-size: 10px; }
  .event-strip span { overflow: hidden; text-overflow: ellipsis; }
  .announcer, .announcer.show { top: calc(var(--touch-top) + 110px); width: max-content; max-width: calc(100vw - 28px); padding: 6px 9px; font-size: 13px; line-height: 1.4; text-align: center; }
  .live-task-dock {
    position: absolute;
    z-index: 6;
    top: calc(var(--touch-top) + 136px);
    left: var(--touch-left);
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: min(270px, calc(100vw - 92px));
    max-height: min(42dvh, calc(100dvh - 220px - var(--touch-top) - var(--touch-bottom)));
    overflow-y: auto;
    overscroll-behavior: contain;
    pointer-events: none;
  }
  .trend-surge, #postProgress, .topic-hud, .topic-hud.choices,
  .game-shell.surge-live #postProgress, .game-shell.surge-live .topic-hud.choices {
    position: relative;
    flex: none;
    top: auto;
    bottom: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-width: none;
    max-height: min(34dvh, 245px);
    margin: 0;
    padding: 0;
    transform: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    touch-action: pan-y;
    font-size: 11px;
    line-height: 1.4;
  }
  .trend-surge-head { gap: 7px; }
  .trend-surge-head strong { font-size: 12px; }
  .trend-surge p { margin: 4px 0; font-size: 11px; line-height: 1.4; }
  .trend-surge small { font-size: 10px; }
  .trend-surge .trend-surge-progress { height: 6px; margin: 4px 0; }
  .live-details { width: 100%; min-width: 0; }
  .live-details > summary { display: flex; align-items: center; min-height: 48px; font-size: 11px; cursor: pointer; }
  .live-details[open] { max-height: 28dvh; overflow-y: auto; overscroll-behavior: contain; }
  .live-details-body { max-height: min(24dvh, 180px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
  #postProgress { display: block; }
  #postProgress[hidden] { display: none; }
  #postProgressText { flex-basis: 100%; font-size: 11px; }
  #fanPostCallBtn, #trendBidBtn { width: 100%; min-height: 48px; padding: 7px; font-size: 11px; }
  .topic-guide { gap: 7px; }
  .topic-guide button { min-height: 48px; padding: 7px 8px; font-size: 11px; }
  .topic-guide strong { font-size: 12px; }
  .topic-guide span, .topic-guide em { font-size: 11px; }
  .game-shell .boss-hud, .game-shell.surge-live .boss-hud {
    top: calc(var(--touch-top) + 106px);
    left: 50%;
    right: auto;
    width: calc(100vw - var(--touch-left) - var(--touch-right));
    min-width: 0;
    padding: 5px 7px;
    transform: translateX(-50%);
  }
  .boss-hud b { margin-bottom: 4px; font-size: 12px; }
  .boss-hud small { font-size: 10px; }
  .boss-hud > div { height: 8px; }
  .boss-hud .boss-traffic-btn { min-height: 48px; padding: 6px 10px; font-size: 11px; }
  .game-shell:has(#bossHud:not([hidden])) .event-strip { display: none; }
  .game-shell:has(#bossHud:not([hidden])) .live-task-dock { top: calc(var(--touch-top) + 216px); }

  .xp-row {
    left: var(--touch-left);
    right: var(--touch-right);
    bottom: var(--touch-bottom);
    width: auto;
    min-height: 24px;
    padding: 3px 5px;
    grid-template-columns: 38px minmax(0, 1fr) 49px;
    gap: 4px;
    transform: none;
  }
  .xp-row > b { font-size: 11px; }
  .xp-row > div { height: 8px; }
  .xp-row > span { font-size: 9px; }
  .weapon-dock {
    top: auto;
    left: 50%;
    right: auto;
    bottom: calc(var(--touch-bottom) + 33px);
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 4px;
    width: max-content;
    max-width: calc(100vw - 30px);
    overflow: visible;
    transform: translateX(-50%);
  }
  .weapon-dock .weapon { flex: none; width: 29px; height: 29px; }
  .weapon-dock .weapon .icon { width: 29px; height: 29px; margin: 0; border-width: 2px; font-size: 17px; }
  .weapon-dock .weapon b { top: auto; right: -2px; bottom: -2px; width: 16px; height: 16px; border-width: 1px; border-radius: 50%; font-size: 8px; line-height: 1; }
  .weapon-dock .weapon-empty { display: none; }
  .weapon-dock .weapon-overflow { top: 4px; left: calc(100% + 3px); font-size: 8px; }
  .skill-dock {
    left: auto;
    right: calc(var(--touch-right) + 8px);
    bottom: calc(var(--touch-bottom) + 86px);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
  }
  .skill-dock #dashBtn { order: 1; }
  .skill-dock #postBtn { order: 2; }
  .skill-dock button, .skill-dock #dashBtn, .skill-dock #postBtn { position: relative; width: 64px; height: 64px; min-height: 64px; padding: 4px; border-width: 2px; touch-action: none; }
  .skill-dock button b { font-size: 23px; line-height: 1.1; }
  .skill-dock button span { font-size: 11px; line-height: 1.2; }
  .skill-dock button small { position: static; display: block; margin-top: 3px; font-size: 9px; line-height: 1; }
  .skill-dock button[hidden] { display: none; }
  .skill-dock button:active:not(:disabled) { filter: brightness(1.2); }
  .skill-dock button.touch-held:not(:disabled) { filter: brightness(1.2); }
  .joystick {
    display: none;
    left: auto;
    top: auto;
    bottom: auto;
    width: 104px;
    height: 104px;
    transform: translate(-50%, -50%);
    border: 2px solid #c0e6f4a6;
    border-radius: 50%;
    background: #0b254a65;
    box-shadow: inset 0 0 0 5px #1747655c;
    pointer-events: none;
  }
  .joystick.active { display: block; }
  .joystick::before { inset: 24px; border-color: #b6e3fb63; }
  .joystick i { inset: auto; left: 50%; top: 50%; width: 32px; height: 32px; margin: -16px 0 0 -16px; border: 2px solid #b9e6ff; border-radius: 50%; background: #7bc6e7dc; box-shadow: inset 0 0 0 3px #317db0, 0 2px 0 #102c44; }
  .joystick span { display: none; }

  /* Menus scroll independently; the footer remains reachable above the home indicator. */
  .overlay { padding: var(--touch-top) var(--touch-right) var(--touch-bottom) var(--touch-left); }
  .modal-panel { max-height: calc(100dvh - var(--touch-top) - var(--touch-bottom)); padding: 14px 12px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
  .chapter-reward .modal-panel, .game-over .modal-panel { max-height: calc(100dvh - var(--touch-top) - var(--touch-bottom)); }
  .modal-panel h2 { font-size: 23px; line-height: 1.3; }
  .modal-panel.small { width: min(490px, 100%); }
  .modal-panel.small .primary, .modal-panel.small .secondary { margin: 6px 0 0; min-width: 0; width: 100%; }
  .pause-help { font-size: 12px; line-height: 1.6; }
  .start-screen.overlay {
    align-items: stretch;
    padding: 0;
    background: linear-gradient(180deg, #0b235c45 0%, #08172b00 26%, #07182d00 48%, #07182dd1 65%, #07182eef 83%, #07182ee8 100%), url('assets/x-survivors-title-world-v1.png') 85% top / cover no-repeat, #07182e;
  }
  .start-copy {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(145px, 1fr) auto auto auto auto;
    gap: 0 8px;
    width: 100%;
    max-width: none;
    min-height: 100%;
    padding: calc(var(--touch-top) + 22px) 22px calc(var(--touch-bottom) + 8px);
  }
  .start-copy .start-eyebrow { grid-column: 1 / -1; grid-row: 1; flex-wrap: wrap; gap: 9px; margin: 0 0 10px; color: #cfebff; font-size: 10px; letter-spacing: 1.5px; }
  .start-copy .start-eyebrow span { font-size: 9px; }
  .start-copy h1 { grid-column: 1 / -1; grid-row: 2; font-size: clamp(48px, 14vw, 66px); line-height: 1.08; letter-spacing: -3px; }
  .start-copy h2 { grid-column: 1 / -1; grid-row: 4; margin: 0 0 7px; font-size: 17px; line-height: 1.45; }
  .start-copy .start-premise { grid-column: 1 / -1; grid-row: 5; max-width: 370px; margin: 0 0 18px; color: #cbdeec; font-size: 12px; line-height: 1.65; }
  .start-highlights, .start-copy .start-controls, .start-edition { display: none; }
  .start-actions { display: contents; }
  .start-actions .primary { grid-column: 1 / -1; grid-row: 6; min-width: 0; min-height: 58px; margin: 0 0 8px; padding: 13px 18px; font-size: 17px; justify-content: space-between; }
  .start-actions .secondary { grid-column: 1; grid-row: 7; min-width: 0; min-height: 48px; padding: 8px 4px; border: 0; background: transparent; box-shadow: none !important; font-size: 12px; gap: 9px; }
  .start-copy .bestiary-open { grid-column: 2; grid-row: 7; display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; margin: 0; padding: 8px 4px; border: 0; color: #c0d7ee; font-size: 12px; letter-spacing: 0; }

  .role-select.overlay { padding: 0; }
  .role-select .role-panel {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    padding: calc(var(--touch-top) + 6px) var(--touch-right) var(--touch-bottom) var(--touch-left);
    overflow: hidden;
    border-width: 2px;
  }
  .role-select .role-panel > h2 { margin: 0; font-size: 21px; line-height: 1.25; }
  .role-select .role-panel > p { margin: 4px 0 8px; font-size: 11px; }
  .role-select .role-grid { flex: 0 0 auto; display: flex; width: 100%; max-height: none; padding: 1px 3px 6px; gap: 8px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; touch-action: pan-x; }
  .role-select .role-card { flex: 0 0 min(250px, 70vw); grid-template-columns: 50px minmax(0, 1fr); min-height: 85px; padding: 6px; gap: 7px; transform: none; scroll-snap-align: start; }
  .role-select .role-art-wrap { width: 50px; height: 66px; }
  .role-select .role-card .role-art { width: 48px; height: 62px; object-fit: contain; }
  .role-select .role-copy { gap: 3px; padding-right: 10px; }
  .role-select .role-copy b { font-size: 14px; }
  .role-select .role-copy .role-index { font-size: 10px !important; }
  .role-select .role-copy .role-trait { font-size: 11px !important; line-height: 1.35; -webkit-line-clamp: 1; }
  .role-select .role-copy em { font-size: 11px !important; }
  .role-select .role-copy em .role-ui-icon { width: 19px; height: 19px; }
  .role-select .role-card::after { right: 6px; font-size: 22px; }
  .role-select .role-card:hover, .post-option:hover, .chapter-reward .upgrade:hover { transform: none; }
  .role-select .role-scroll-hint { margin: 0 0 5px; font-size: 10px; }
  .role-select .role-detail { flex: 1 1 0; min-height: 0; padding: 0 9px 12px; overflow-y: auto; touch-action: pan-y; }
  .role-select .role-detail-head { grid-template-columns: 63px minmax(0, 1fr) 34px; min-height: 87px; margin: 0 -9px 10px; padding: 7px 9px; gap: 7px; }
  .role-select .role-detail-head::before { width: 60px; height: 70px; background-size: contain; }
  .role-select .role-detail-head strong { font-size: 18px; }
  .role-select .role-detail-head span { font-size: 11px; }
  .role-select .role-detail-head .weapon-pixel-art { width: 34px; height: 34px; }
  .role-select .role-detail-grid, .role-select .contract-grid,
  .role-select .meta-branches, .role-select .platform-branches { grid-template-columns: 1fr; gap: 7px; }
  .role-select .role-detail-grid > div { padding: 8px; min-height: 0; }
  .role-select .role-detail-grid small { font-size: 11px; }
  .role-select .role-detail-grid p { font-size: 12px; line-height: 1.5; }
  .role-select .contract-card, .role-select .meta-branch { min-height: 64px; padding: 9px; }
  .role-select .contract-card b, .role-select .meta-branch > span { font-size: 12px; }
  .role-select .contract-card small, .role-select .meta-branch small { font-size: 11px; line-height: 1.4; }
  .role-select .platform-group > summary { display: flex; align-items: center; }
  .role-select .role-story { margin: 8px 0; padding: 8px 9px; }
  .role-select .role-story > p { font-size: 12px; line-height: 1.5; }
  .role-select .role-actions { position: static; flex: none; display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 7px; padding: 8px 0 2px; background: #081b34; }
  .role-select .role-unlock-status { grid-column: 1 / -1; font-size: 10px; line-height: 1.35; }
  .role-select .role-actions .role-x-link { grid-column: 1 / -1; min-width: 0; min-height: 48px; margin: 0; padding: 8px; font-size: 12px; }
  .role-select .role-actions .primary, .role-select .role-actions .secondary { min-width: 0; min-height: 48px; margin: 0; padding: 8px; font-size: 13px; }
  .role-select .role-actions #roleBackBtn { min-width: 0; }

  .level-up.overlay { padding: var(--touch-top) var(--touch-right) var(--touch-bottom) var(--touch-left); }
  .level-up .upgrade-panel { width: 100%; height: calc(100dvh - var(--touch-top) - var(--touch-bottom)); margin: 0; padding: 9px; overflow: hidden; }
  .upgrade-heading { flex: none; min-height: 0; padding: 2px 2px 8px; }
  .upgrade-heading h2 { font-size: 22px !important; }
  .upgrade-heading > span { display: none; }
  .upgrade-layout { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
  .build-sidebar { flex: none; min-height: 0; max-height: 68px; overflow: hidden; }
  .build-sidebar h3, .build-synergy { display: none; }
  .build-sidebar-content { padding: 4px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; }
  .build-weapon-count { margin-bottom: 4px; font-size: 10px; }
  .build-weapon-list { display: flex; flex-wrap: nowrap; width: max-content; }
  .build-weapon { flex: none; width: 94px; min-height: 32px; grid-template-columns: 24px minmax(0, 1fr); }
  .build-weapon .weapon-pixel-art { width: 24px; height: 24px; }
  .build-weapon strong, .build-weapon small { font-size: 9px; }
  .upgrade-stage { flex: 1; display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; gap: 8px; }
  .level-up #upgradeGrid, .level-up #upgradeGrid:has(.super-choice) { display: flex; flex-direction: column; gap: 10px; max-height: none; padding: 3px 5px 5px 3px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
  #upgradeGrid .upgrade { grid-template-columns: 48px minmax(0, 1fr); flex: none; min-height: 0; height: auto; padding: 9px !important; gap: 5px 8px; overflow: visible; }
  #upgradeGrid .upgrade.top-pick { padding-top: 29px !important; }
  #upgradeGrid .upgrade:hover { transform: none; }
  #upgradeGrid .ticket-visual { grid-column: 1; grid-row: 1; align-self: start; width: 48px; height: 53px; min-height: 0; }
  #upgradeGrid .upgrade-icon { width: 46px; height: 46px; }
  #upgradeGrid .ticket-copy { grid-column: 2; grid-row: 1; gap: 4px; padding: 0; height: auto; overflow: visible; }
  #upgradeGrid .ticket-title-row { display: flex; flex-wrap: wrap; gap: 2px 7px; }
  #upgradeGrid .ticket-title-row h3 { white-space: normal; overflow: visible; font-size: 16px; line-height: 1.35; }
  #upgradeGrid .ticket-rank { font-size: 10px; }
  #upgradeGrid .ticket-impact, #upgradeGrid .ticket-impact.ticket-impact-long { white-space: normal; overflow: visible; font-size: 13px; line-height: 1.5; }
  #upgradeGrid .upgrade p, #upgradeGrid .rarity-effect, #upgradeGrid .recipe-tag,
  #upgradeGrid .weapon-fusion-recipe, #upgradeGrid .upgrade-recommendation,
  #upgradeGrid .upgrade-recommendation b, #upgradeGrid .upgrade-recommendation span { white-space: normal; overflow: visible; font-size: 11px; line-height: 1.45; }
  #upgradeGrid .upgrade-recommendation { max-height: none; }
  #upgradeGrid .ticket-action { grid-column: 1 / -1; grid-row: 2; display: block; width: 100%; margin-top: 3px; padding: 5px 0 0; border: 0; border-top: 1px solid #456981; }
  #upgradeGrid .upgrade footer { display: flex; flex-direction: row; justify-content: space-between; gap: 8px; width: 100%; text-align: left; }
  #upgradeGrid .upgrade footer b { width: auto; min-width: 88px; min-height: 48px; padding: 6px 10px; font-size: 12px; }
  #upgradeGrid .upgrade.top-pick .build-best-badge { left: 9px; top: 5px; font-size: 10px; }
  .upgrade-stage-footer { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 6px; padding: 4px 5px; }
  .level-up .upgrade-reroll { min-height: 48px; max-width: 100%; padding: 8px; font-size: 11px; }
  .upgrade-ready { font-size: 10px; white-space: normal; text-align: right; }
  .upgrade-info summary { display: flex; align-items: center; min-height: 48px; font-size: 11px; }
  .upgrade-info .build-hint { max-height: 72px; font-size: 11px; }

  .post-panel, .chapter-reward .modal-panel, .bestiary-panel { width: 100%; }
  .post-options, .chapter-reward #chapterChoices { display: grid; grid-template-columns: minmax(0, 1fr); max-height: none; gap: 10px; overflow: visible; }
  .post-option, .chapter-reward .upgrade { min-height: 0; padding: 12px; transform: none; }
  .post-option h3 { font-size: 16px; }
  .post-option p, .post-option footer, .post-panel > small { font-size: 12px; line-height: 1.5; }
  .chapter-reward .upgrade { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 5px 9px; }
  .chapter-reward .upgrade .upgrade-icon { grid-column: 1; grid-row: 1 / 3; width: 42px; height: 42px; margin: 0; font-size: 27px; }
  .chapter-reward .upgrade h3 { margin: 0; font-size: 16px; line-height: 1.35; text-align: left; }
  .chapter-reward .upgrade p { min-height: 0; margin: 0; font-size: 12px; line-height: 1.5; text-align: left; }
  .chapter-reward .chapter-risk, .chapter-reward .upgrade footer { grid-column: 1 / -1; font-size: 11px; }
  .chapter-reward .upgrade footer { min-height: 48px; margin: 3px 0 0; align-items: center; }
  .bestiary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
  .bestiary-panel #bestiaryClose { display: block; width: 100%; min-height: 48px; margin: 12px 0 0; }

  /* Menus use native text at full resolution, never a retained animation layer. */
  .overlay { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .overlay.open .modal-panel {
    animation: none !important;
    transform: none !important;
    filter: none;
    opacity: 1;
    font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  .modal-panel h2, .role-select .role-detail-head strong { font-family: inherit; text-shadow: none !important; }
  .upgrade-heading h2 { text-shadow: none !important; letter-spacing: 0; }
  .role-select .role-card, .post-option, .chapter-reward .upgrade, #upgradeGrid .upgrade {
    filter: none;
    transform: none;
    text-shadow: none;
    transition: border-color .12s;
  }
  .role-select .role-copy b { font-size: 16px; line-height: 22px; font-weight: 700; }
  .role-select .role-copy .role-index { font-size: 12px !important; line-height: 16px; }
  .role-select .role-copy .role-trait, .role-select .role-copy em { font-size: 12px !important; line-height: 18px; }
  .role-select .role-detail-grid small, .role-select .contract-card b, .role-select .meta-branch > span { font-size: 13px; }
  .role-select .role-detail-grid p, .role-select .role-story > p { font-size: 14px; line-height: 21px; }
  .role-select .contract-card small, .role-select .meta-branch small { font-size: 13px; line-height: 19px; }
  #upgradeGrid .ticket-title-row h3 { font-size: 18px; line-height: 24px; font-weight: 700; }
  #upgradeGrid .ticket-impact, #upgradeGrid .ticket-impact.ticket-impact-long { font-size: 15px; line-height: 22px; font-weight: 600; }
  #upgradeGrid .upgrade p { font-size: 14px; line-height: 21px; }
  #upgradeGrid .kind-tag, #upgradeGrid .rarity-tag, #upgradeGrid .ticket-rank,
  #upgradeGrid .rarity-effect, #upgradeGrid .recipe-tag, #upgradeGrid .weapon-fusion-recipe,
  #upgradeGrid .upgrade-recommendation, #upgradeGrid .upgrade-recommendation b,
  #upgradeGrid .upgrade-recommendation span { font-size: 12px; line-height: 18px; }
  #upgradeGrid .upgrade footer span, #upgradeGrid .upgrade footer b { font-size: 13px; }
  #upgradeGrid .ticket-visual { width: 48px; height: 52px; }
  #upgradeGrid .upgrade-icon { width: 48px; height: 48px; image-rendering: pixelated; }
}

/* Short, wide phones keep the top rail and controls compact, with two-column dossiers. */
@media (max-width: 780px) and (orientation: landscape), (pointer: coarse) and (max-width: 1050px) and (max-height: 540px) {
  .top-hud { grid-template-columns: minmax(120px, 1fr) 142px minmax(200px, 1fr); gap: 5px; padding-right: calc(var(--touch-right) + 112px); }
  .top-hud .player-card { min-height: 42px; }
  .top-hud .portrait { width: 30px; height: 30px; }
  .top-hud .player-meta strong { font-size: 11px; }
  .top-hud .run-clock { grid-column: 2; grid-row: 1; width: 142px; min-height: 42px; }
  .top-hud .run-clock #timer { font-size: 17px; }
  .top-hud .resources { grid-column: 3; grid-row: 1; width: 100%; gap: 4px; }
  .top-hud .resources > span { min-height: 42px; padding: 3px; grid-template-columns: 13px minmax(0, 1fr); gap: 0 2px; }
  .top-hud .resources i { font-size: 12px; }
  .top-hud .resources b { font-size: 12px; }
  .top-hud .resources small { font-size: 8px; }
  .pause-btn, .audio-controls { top: var(--touch-top); }
  .event-strip { top: calc(var(--touch-top) + 49px); max-width: 56vw; }
  .announcer, .announcer.show { top: calc(var(--touch-top) + 60px); max-width: 58vw; }
  .live-task-dock { top: calc(var(--touch-top) + 74px); width: min(285px, 38vw); max-height: calc(100dvh - 155px - var(--touch-top) - var(--touch-bottom)); }
  .game-shell .boss-hud, .game-shell.surge-live .boss-hud { top: calc(var(--touch-top) + 49px); width: min(410px, 54vw); padding: 4px 7px; }
  .boss-hud .boss-traffic-btn { position: absolute; top: 1px; left: calc(100% + 7px); width: 84px; min-height: 48px; font-size: 10px; }
  .game-shell:has(#bossHud:not([hidden])) .live-task-dock { top: calc(var(--touch-top) + 110px); }
  .weapon-dock { bottom: calc(var(--touch-bottom) + 30px); gap: 5px; }
  .weapon-dock .weapon, .weapon-dock .weapon .icon { width: 28px; height: 28px; }
  .skill-dock { bottom: calc(var(--touch-bottom) + 36px); gap: 10px; }
  .skill-dock button, .skill-dock #dashBtn, .skill-dock #postBtn { width: 56px; height: 56px; min-height: 56px; }
  .skill-dock button b { font-size: 20px; }
  .skill-dock button span { font-size: 10px; }
  .skill-dock button small { font-size: 8px; }

  .start-screen.overlay { align-items: center; padding: calc(var(--touch-top) + 12px) calc(var(--touch-left) + 20px) calc(var(--touch-bottom) + 12px); background-size: cover; background-position: 42% center; }
  .start-copy { display: block; width: min(455px, 65vw); max-width: 455px; min-height: 0; padding: 0; }
  .start-copy .start-eyebrow { margin-bottom: 10px; font-size: 9px; }
  .start-copy h1 { font-size: 42px; }
  .start-copy h2 { margin-top: 9px; font-size: 15px; }
  .start-copy .start-premise { font-size: 11px; line-height: 1.5; }
  .start-highlights { margin: 12px 0; }
  .start-highlights span { padding: 5px 10px; }
  .start-highlights b { font-size: 19px; }
  .start-copy .start-controls { display: none; }
  .start-actions { display: flex; gap: 9px; }
  .start-actions .primary { min-height: 48px; margin: 0; padding: 10px 13px; font-size: 14px; }
  .start-actions .secondary { min-height: 48px; padding: 8px; border: 1px solid #739cc1; background: #15375b; }
  .start-copy .bestiary-open { justify-content: flex-start; width: max-content; margin-top: 4px; }

  .role-select .role-panel { display: grid; grid-template-columns: minmax(205px, .75fr) minmax(0, 1.55fr); grid-template-rows: auto minmax(0, 1fr) auto; column-gap: 10px; row-gap: 7px; padding-top: var(--touch-top); }
  .role-select .role-panel > h2 { grid-column: 1 / -1; grid-row: 1; font-size: 19px; }
  .role-select .role-panel > p, .role-select .role-scroll-hint { display: none; }
  .role-select .role-grid { grid-column: 1; grid-row: 2; display: grid; grid-template-columns: 1fr; align-content: start; width: 100%; height: 100%; min-height: 0; max-height: none; overflow-x: hidden; overflow-y: auto; padding: 1px 4px 4px 1px; touch-action: pan-y; }
  .role-select .role-card { width: 100%; min-height: 72px; grid-template-columns: 42px minmax(0, 1fr); gap: 6px; padding: 5px; }
  .role-select .role-art-wrap { width: 42px; height: 56px; }
  .role-select .role-card .role-art { width: 40px; height: 53px; }
  .role-select .role-copy b { font-size: 14px; }
  .role-select .role-copy .role-trait { display: none; }
  .role-select .role-detail { grid-column: 2; grid-row: 2; height: 100%; padding-bottom: 9px; }
  .role-select .role-detail-head { min-height: 76px; grid-template-columns: 53px minmax(0, 1fr) 30px; margin-bottom: 8px; }
  .role-select .role-detail-head::before { width: 50px; height: 60px; }
  .role-select .role-detail-head strong { font-size: 17px; }
  .role-select .role-detail-head .weapon-pixel-art { width: 30px; height: 30px; }
  .role-select .role-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .role-select .role-detail-grid > div:last-child { grid-column: 1 / -1; }
  .role-select .role-actions { grid-column: 1 / -1; grid-row: 3; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 78px; align-items: center; gap: 8px; padding: 0 2px 2px; }
  .role-select .role-unlock-status { display: none; }
  .role-select .role-actions .role-x-link { grid-column: auto; min-height: 48px; }

  .level-up .upgrade-panel { padding: 7px 8px; }
  .upgrade-heading { padding-bottom: 5px; }
  .upgrade-heading p { display: none; }
  .upgrade-heading h2 { font-size: 19px !important; margin: 2px 0 !important; }
  .upgrade-layout { gap: 5px; }
  .build-sidebar { max-height: 38px; }
  .build-sidebar-content { display: flex; align-items: center; gap: 7px; padding: 2px 5px; }
  .build-weapon-count { flex: none; display: block; margin: 0; font-size: 9px; }
  .build-weapon-count span { display: none; }
  .build-weapon-list { gap: 3px; }
  .build-weapon { width: 74px; min-height: 28px; grid-template-columns: 20px minmax(0, 1fr); }
  .build-weapon .weapon-pixel-art { width: 20px; height: 20px; }
  .build-weapon strong, .build-weapon small { font-size: 8px; }
  .upgrade-stage { gap: 5px; }
  .level-up #upgradeGrid, .level-up #upgradeGrid:has(.super-choice) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: max-content; align-content: start; gap: 8px; overflow-y: auto; }
  #upgradeGrid .upgrade { grid-template-columns: 40px minmax(0, 1fr); padding: 7px !important; gap: 5px; }
  #upgradeGrid .ticket-visual { width: 40px; height: 44px; }
  #upgradeGrid .upgrade-icon { width: 40px; height: 40px; }
  #upgradeGrid .ticket-title-row h3 { font-size: 16px; line-height: 22px; }
  #upgradeGrid .ticket-impact, #upgradeGrid .ticket-impact.ticket-impact-long { font-size: 14px; line-height: 20px; }
  #upgradeGrid .upgrade footer b { min-width: 72px; }
  .upgrade-stage-footer { grid-template-columns: minmax(0, 1fr) auto; min-height: 52px; }
  .upgrade-info { grid-column: auto; grid-row: 1; }
  .upgrade-info summary { min-height: 48px; padding: 4px; font-size: 10px; }
  .upgrade-ready { display: none; }
  .upgrade-info[open] { grid-column: 1 / -1; grid-row: 2; }
  .upgrade-info[open] summary { min-height: 48px; }
  .post-options, .chapter-reward #chapterChoices { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chapter-reward .upgrade { display: flex; flex-direction: column; gap: 6px; }
  .chapter-reward .upgrade .upgrade-icon { width: 38px; height: 38px; }
  .chapter-reward .upgrade h3 { font-size: 14px; }
  .chapter-reward .upgrade footer { margin-top: auto; }
  .bestiary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
