/* Compact landscape shell. No game-world scaling or progression logic lives here. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (orientation: landscape) and (max-height: 700px) and (max-width: 1400px) {
  :root {
    --compact-rank-height: 40px;
    --screen-padding: 6px;
    --card-gap: 8px;
    --touch-target: 44px;
    --screen-insets: 6px max(6px, var(--safe-right)) max(6px, var(--safe-bottom)) max(6px, var(--safe-left));
  }
  html, body { background: #061019; }
  html, body, #brightness { height: 100vh; height: 100dvh; max-height: 100dvh; }
  #brightness, #app { min-width: 0; min-height: 0; box-sizing: border-box; }
  #brightness.account-rank-menu { grid-template-rows: auto minmax(0, 1fr); }
  #brightness.account-rank-menu > #app { max-height: 100%; min-height: 0; }
  #account-rank-header.account-rank-header {
    min-height: var(--compact-rank-height);
    height: calc(var(--compact-rank-height) + var(--safe-top));
    padding: calc(3px + var(--safe-top)) max(10px, var(--safe-right)) 3px max(10px, var(--safe-left));
    box-sizing: border-box;
  }
  #account-rank-header .account-rank-component {
    width: min(860px, 100%); grid-template-columns: 32px minmax(105px, 172px) minmax(90px, 1fr) 34px;
    grid-template-rows: auto; gap: 8px;
  }
  #account-rank-header .account-rank-insignia { grid-column: 1; grid-row: 1; height: 32px; }
  #account-rank-header .account-rank-insignia img { width: 32px; height: 32px; }
  #account-rank-header .account-rank-identity { grid-column: 2; grid-row: 1; gap: 2px; }
  #account-rank-header .account-rank-label { font-size: 8px; letter-spacing: .1em; }
  #account-rank-header .account-rank-name { font-size: 12px; line-height: 1.1; }
  #account-rank-header .account-rank-progress { grid-column: 3; grid-row: 1; padding: 0; }
  #account-rank-header .account-rank-meter { height: 24px; }
  #account-rank-header .account-rank-xp { font-size: 12px; }
  #account-rank-header .account-rank-number { grid-column: 4; grid-row: 1; font-size: 30px; }
  #account-rank-header .account-rank-promotion { bottom: -10px; font-size: 8px; }

  /* Information pages: fixed controls, a genuinely scrollable reading area. */
  #app.information-screen { padding: var(--screen-insets); }
  #app.information-screen .information-panel { height: 100%; max-height: 100%; padding: 10px 14px !important; gap: 7px; }
  #app.information-screen .information-panel > header small { display: none; }
  #app.information-screen .information-panel h1 { font-size: 23px; margin: 0 0 6px; }
  #app.information-screen .information-categories { flex-wrap: nowrap; overflow-x: auto; min-height: 44px; max-height: 44px; gap: 6px; touch-action: pan-x; }
  #app.information-screen .information-categories button { min-height: 44px; flex: 0 0 auto; font-size: 12px; padding: 6px 12px; }
  #app.information-screen .information-content { flex: 1; min-height: 0; font-size: 14px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
  #app.information-screen .information-panel footer { padding-top: 5px; }
  #app.information-screen .information-back { min-height: 44px; height: 44px; font-size: 13px; }
  #app.information-screen .faq-entry summary { min-height: 44px; box-sizing: border-box; padding: 12px; font-size: 14px; }

  /* Account identity stays present while settings, avatars and records scroll. */
  #app .account-shell { inset: var(--screen-padding) max(var(--screen-padding), var(--safe-right)) max(var(--screen-padding), var(--safe-bottom)) max(var(--screen-padding), var(--safe-left)); padding: 10px 14px; border-radius: 10px; }
  #app .account-shell > header { flex: none; }
  #app .account-shell header > div { gap: 10px; }
  #app .account-shell header .profile-avatar { width: 40px; height: 40px; }
  #app .account-shell h1 { font-size: 22px; margin: 0; }
  #app .account-shell > header p { margin: 2px 0; font-size: 12px; }
  #app .account-rank-detail { font-size: 11px; line-height: 1.2; margin-top: 2px !important; }
  #app .account-rank-detail img { width: 18px; height: 22px; flex-basis: 18px; }
  #app .account-content { padding: 8px 4px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
  #app .account-atomcore { padding: 6px 9px; gap: 8px; margin: 5px 0 10px; }
  #app .account-atomcore img { width: 32px; height: 44px; }
  #app .account-atomcore h2 { font-size: 15px; line-height: 1.2; }
  #app .account-atomcore p { font-size: 11px; line-height: 1.35; margin: 3px 0; }
  #app .account-shell footer { padding-top: 5px; flex: none; }
  #app .account-shell footer button, #app .account-content button { min-height: 44px; }
  #app .avatar-options { grid-template-columns: repeat(5, minmax(0, 1fr)); max-height: 160px; max-width: 740px; touch-action: pan-y; }
  #app .avatar-options button { min-height: 86px; padding: 5px; }
  #app .avatar-options .profile-avatar { width: 44px; height: 44px; }
  #app .avatar-preview .profile-avatar { width: 64px; height: 64px; }
  #app .account-settings input { min-height: 44px; font-size: 16px; }
  #app .password-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Settings keeps its section navigation and Back outside the scroll pane. */
  #app.settings-page { padding: var(--screen-padding); }
  #app .settings-shell { height: 100%; max-height: 100%; width: min(940px, 100%); grid-template-rows: auto minmax(0, 1fr) auto; }
  #app .settings-shell header, #app .settings-shell footer { padding: 5px 12px; }
  #app .settings-shell header .eyebrow { display: none; }
  #app .settings-shell header h1 { margin: 0; font-size: 23px; }
  #app .settings-layout { grid-template-columns: 126px minmax(0, 1fr); }
  #app .settings-nav { padding: 5px; overflow-y: auto; min-height: 0; gap: 4px; touch-action: pan-y; }
  #app .settings-nav button { min-height: 44px; padding: 7px; font-size: 12px; }
  #app .settings-content { min-width: 0; min-height: 0; padding: 8px 12px; touch-action: pan-y; }
  #app .setting-control { display: grid; grid-template-columns: minmax(125px, 1fr) minmax(100px, 160px) !important; gap: 3px 12px; padding: 8px 0; }
  #app .setting-control > span { grid-column: 1; grid-row: 1; }
  #app .setting-control > small { grid-column: 1; grid-row: 2; padding: 0; font-size: 12px; }
  #app .setting-control > :is(input, select, button) { grid-column: 2; grid-row: 1 / span 2; min-height: 44px; }
  #app .toggle-switch { height: 44px; min-height: 44px; background: transparent !important; border: 0 !important; }
  #app .toggle-switch::before { content: ""; position: absolute; inset: 8px 0; border: 1px solid #627b89; border-radius: 20px; background: #111d25; pointer-events: none; }
  #app .toggle-switch.on::before { background: #075985; border-color: #67d8ff; }
  #app .toggle-switch i { position: absolute; left: 4px; top: 12px; }
  #app .settings-shell footer button { min-height: 44px; padding: 7px 12px; }
  #app .settings-shell footer { flex-wrap: nowrap; align-items: center; gap: 6px; padding: 4px 8px; }
  #app .settings-shell footer button { font-size: 12px; flex: 0 0 auto; }
  #app .settings-shell footer .save-status { min-width: 0; font-size: 10px; }
  #app .settings-content :is(label, p) { font-size: 13px; line-height: 1.4; }
  #app .settings-content :is(h2, h3) { font-size: 17px; margin-block: 6px 10px; }
  #app.settings-page { padding: var(--screen-insets); }

  /* Databases use real remaining space, with Back independent of the list. */
  /* The legacy database skin sets both centered positioning and transform with
     !important. Override that pair together when switching to inset geometry. */
  #app .database-panel { position: absolute !important; inset: var(--screen-padding) !important; transform: none !important; width: auto; max-width: none; max-height: none; padding: 10px; display: flex; flex-direction: column; overflow: hidden; box-sizing: border-box; }
  #app .database-panel > .eyebrow { display: none; }
  #app .database-panel > h2 { font-size: 23px; margin: 0 0 7px; flex: none; }
  #app .database-grid { flex: 1; min-height: 0; overflow: auto; touch-action: pan-x pan-y; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; grid-auto-rows: max-content; align-content: start; gap: 8px; }
  #app .database-card { min-width: 0; min-height: 0; height: auto; padding: 8px; gap: 8px; }
  #app .tower-reference-card { grid-template-columns: 60px minmax(0, 1fr) !important; }
  #app .tower-reference-card img { width: 60px !important; height: 90px !important; }
  #app .tower-reference-card p { font-size: 13px; line-height: 1.4; margin: 6px 0; }
  #app .tower-reference-card table { display: block; max-width: 100%; overflow-x: auto; table-layout: auto; font-size: 12px; touch-action: pan-x pan-y; overscroll-behavior: contain auto; }
  #app .tower-reference-card th, #app .tower-reference-card td { overflow: visible; text-overflow: clip; white-space: nowrap; }
  #app .enemy-reference-card { grid-template-columns: 76px minmax(0, 1fr) !important; }
  #app .enemy-reference-card img { width: 76px !important; height: 90px !important; max-height: 90px !important; }
  #app .database-panel > button { flex: none; margin: 5px auto 0; min-height: 44px; padding: 7px 20px; }
  #app .database-panel { inset: var(--screen-insets) !important; }
  #app.menu-bg > .missions-panel.mission-archive, #app.reference-store .store-shell { inset: var(--screen-insets); }
  #app.daily-rewards-page { padding-inline: max(6px, var(--safe-left)) max(6px, var(--safe-right)); padding-bottom: max(6px, var(--safe-bottom)); }
  .account-ranks-screen { padding: max(6px, var(--safe-top)) max(6px, var(--safe-right)) max(6px, var(--safe-bottom)) max(6px, var(--safe-left)); }

  /* Legal navigator becomes a touch strip; body text is never shrunk to fit. */
  #app .terms-modal { padding: var(--screen-insets) !important; }
  #app .terms-modal > section { height: 100%; max-height: 100% !important; }
  #app .terms-modal header, #app .terms-modal footer { padding: 5px 12px; flex: none; }
  #app .terms-modal header h2 { margin: 0; font-size: 22px; }
  #app .terms-content-layout { display: flex; flex-direction: column-reverse; }
  #app .terms-navigator { flex-direction: row; flex: 0 0 52px; min-height: 52px; max-height: 52px; padding: 4px; overflow-x: auto; overflow-y: hidden; border-left: 0; gap: 4px; touch-action: pan-x; }
  #app .terms-nav-button { width: 44px; min-height: 44px; padding: 8px; justify-content: center; }
  #app .terms-nav-button span { display: none; }
  #app .terms-document { flex: 1; min-height: 0; padding: 10px !important; touch-action: pan-y; }
  #app .terms-content-layout .terms-section { padding: 14px !important; }
  #app .terms-close { min-height: 44px; padding: 7px 20px; }

  /* Local dialogs can scroll under the keyboard without obscuring actions. */
  #app .game-confirm, #app .settings-unsaved { padding: 6px; box-sizing: border-box; }
  #app .game-confirm > section, #app .settings-unsaved > section { box-sizing: border-box; max-height: 100%; max-width: 100%; padding: 15px; overflow-y: auto; overscroll-behavior: contain; }
  #app .game-confirm footer button, #app .settings-unsaved button { min-height: 44px; }
  #app .game-confirm footer { margin-top: 10px; flex-wrap: wrap; }
  #app .game-confirm form label { display: grid; gap: 5px; }
  #app .game-confirm input:not([type="checkbox"]):not([type="radio"]) { width: 100%; min-height: 44px; font-size: 16px; }
  #app :is(.information-back, .terms-close, .account-shell > footer button, .settings-shell > footer button) { min-width: 84px; min-height: 44px; }
  #app :is(button, summary, [role="button"]) { -webkit-user-select: none; user-select: none; }
  #app :is(.information-content, .terms-document) { -webkit-user-select: text; user-select: text; }
  #app :is(.information-content, .account-content, .settings-content, .database-grid, .terms-document, .terms-navigator) { overscroll-behavior: contain; scrollbar-width: thin; }

  /* Other existing archives use the same compact-header/scrolling-content policy. */
  #app.endless-selection .endless-selection-shell { height: 100%; max-height: 100%; width: 100%; padding: 8px 12px; gap: 5px; display: flex; flex-direction: column; overflow: hidden; }
  #app.endless-selection { padding: var(--screen-insets); }
  #app .endless-selection-header { flex: none; gap: 12px; padding-bottom: 4px; }
  #app .endless-selection-heading { flex: 1; }
  #app .endless-selection-heading h1 { font-size: 21px; margin: 0; }
  #app .endless-selection-heading .endless-selection-eyebrow, #app .endless-selection-heading .endless-selection-intro { display: none; }
  #app .endless-global-record { padding: 0 10px; }
  #app .endless-global-record strong { font-size: 21px; }
  #app .endless-global-record small { font-size: 9px; }
  #app .endless-language { min-height: 44px; padding: 6px 12px; }
  #app .endless-access-row { flex: none; margin: 0; padding: 0; gap: 8px; }
  #app .endless-access-copy { margin: 0; font-size: 11px; line-height: 1.3; }
  #app .endless-slot-grid { flex: none; gap: 6px; margin: 0; }
  #app .endless-slot-card { padding: 6px 9px; min-height: 50px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; align-content: center; line-height: 1.15; }
  #app .endless-slot-card > strong { grid-column: 1; grid-row: 1 / span 3; }
  #app .endless-slot-card > :not(strong) { grid-column: 2; }
  #app .endless-slot-card > :empty { display: none; }
  #app .endless-slot-card strong, #app .endless-slot-card b { font-size: 12px; margin: 0; }
  #app .endless-slot-card small, #app .endless-slot-card span { font-size: 10px; }
  #app .endless-slot-actions button { min-height: 44px; font-size: 12px; }
  #app.endless-selection .endless-map-grid { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; padding: 2px; touch-action: pan-y; }
  #app .endless-card-art { aspect-ratio: 2.8; }
  #app .endless-card-copy { padding: 6px; }
  #app .endless-card-copy strong { font-size: 13px; padding: 0; }
  #app .endless-card-description { font-size: 11px; }
  #app .endless-selection-footer { flex: none; display: grid; grid-template-columns: minmax(90px, 1fr) auto; gap: 8px; align-items: center; margin: 0; padding-top: 4px; }
  #app .endless-selected-summary h2 { font-size: 14px; margin: 0; }
  #app .endless-selected-label, #app .endless-selected-records, #app .endless-saved-notice { font-size: 10px; margin: 1px 0; }
  #app .endless-selected-label, #app .endless-saved-notice:empty { display: none; }
  #app .endless-selected-records { display: flex; flex-wrap: wrap; gap: 2px 8px; line-height: 1.2; }
  #app .endless-saved-notice { line-height: 1.2; }
  #app .endless-selection-actions { flex-wrap: nowrap; gap: 5px; }
  #app .endless-selection-actions button { min-height: 44px; min-width: 74px; font-size: 12px; padding: 6px 10px; }
  #app .endless-status:empty { display: none; }

  #app.training-hub.reference-minigames-hub { padding: 6px max(10px, var(--safe-right)) max(6px, var(--safe-bottom)) max(10px, var(--safe-left)); touch-action: pan-y; overscroll-behavior: contain; }
  #app.reference-minigames-hub .minigames-shell { gap: 10px; }
  #app.reference-minigames-hub .minigames-shell > header { position: sticky; top: 0; z-index: 4; min-height: 58px; padding: 8px 14px; background-color: #061520; }
  #app.reference-minigames-hub header h1 { font-size: 24px; margin: 0; }
  #app.reference-minigames-hub header span { font-size: 8px; }
  #app.reference-minigames-hub .minigames-back { min-height: 44px; height: 44px; padding: 5px 16px; }
  #app.reference-minigames-hub .mini-chest-meter { padding: 10px 14px; grid-template-columns: minmax(0, 1fr) 100px; }
  #app.reference-minigames-hub .mini-chest-art img { max-height: 70px; object-fit: contain; }
  #app.reference-minigames-hub .minigames-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #app.reference-minigames-hub .minigames-grid article { min-width: 0; }
  #app.reference-minigames-hub .minigames-grid button { min-height: 44px; }

  #atomcore-screen { padding: max(6px, var(--safe-top)) max(6px, var(--safe-right)) max(6px, var(--safe-bottom)) max(6px, var(--safe-left)); }
  #atomcore-screen .atomcore-panel { height: 100%; max-height: 100%; padding: 10px 14px; touch-action: pan-y; overscroll-behavior: contain; }
  #atomcore-screen header { position: sticky; top: -10px; z-index: 3; padding: 5px 0; background: #061b18; }
  #atomcore-screen header small { font-size: 9px; }
  #atomcore-screen h1 { font-size: 23px; margin: 3px 0 0; }
  #atomcore-screen .atomcore-back { min-height: 44px; }
  #atomcore-screen .atomcore-reactor-layout { grid-template-columns: 100px minmax(0, 1fr); gap: 15px; margin: 10px 0; }
  #atomcore-screen .atomcore-identity { min-height: 110px; }
  #atomcore-screen .atomcore-identity img { width: 95px; height: 105px; }
  #atomcore-screen .atomcore-meter { min-height: 32px; }
  #atomcore-screen .atomcore-milestone-nav button { min-height: 44px !important; }

  /* Auth/keyboard form geometry is now owned by responsive-system.css. */
}

/* A tablet has room for another database column, not larger phone cards. */
@media (orientation: landscape) and (min-width: 1000px) and (max-width: 1400px) and (max-height: 700px) {
  #app .database-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
}

/* Small visual viewports caused by the software keyboard retain a usable form pane. */
@media (orientation: landscape) and (max-height: 260px) {
  #app .account-shell:has(input:focus) > header { display: none; }
  #app .account-shell:has(input:focus) { padding-block: 5px; }
  #app .account-shell:has(input:focus) footer { padding-top: 2px; }
}
