/* Legacy layout and paint share one cascade layer. Theme recipes own opt-in appearance. */
@layer legacy {
  :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);
    --paper: #f5f1e6;
    --ink: #112d35;
    --muted: #647b7c;
    --line: #cad0c6;
    --accent: #e9c46a;
    --safe: #81b5bf;
    --danger: #f08168;
    color-scheme: light;
  }
  * {
    box-sizing: border-box;
  }
  body {
    margin: 0;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: var(--paper);
    color: var(--ink);
    font: 14px/1.5 var(--fk-font-ui, sans-serif);
  }
  button,
  input,
  select {
    font: inherit;
  }
  button,
  a,
  input,
  select {
    touch-action: manipulation;
  }
  button {
    cursor: pointer;
  }
  button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
  }
  button,
  a {
    -webkit-tap-highlight-color: transparent;
  }
  a {
    color: inherit;
    text-underline-offset: 4px;
  }
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  [tabindex]:focus-visible {
    outline: 3px solid #ba832d;
    outline-offset: 3px;
  }
  [hidden] {
    display: none !important;
  }
  .controller-focus {
    outline: 3px solid var(--ink) !important;
    outline-offset: 3px;
    box-shadow: 0 0 0 6px var(--accent);
    scroll-margin: 12px;
  }
  .controller-editor {
    padding: 10px 12px;
    margin: 8px 0;
    border: 2px solid var(--ink);
    background: var(--accent);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    overflow-wrap: anywhere;
  }
  .controller-hint {
    padding: 8px 0;
    max-width: 56ch;
  }
  .masthead {
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1392px;
    margin: auto;
    padding: 0 36px;
    border-bottom: 1px solid var(--line);
  }
  .wordmark {
    font-weight: 800;
    font-size: 21px;
    letter-spacing: -0.8px;
    text-decoration: none;
    display: flex;
    gap: 10px;
    align-items: center;
  }
  .brand-mark {
    font-size: 29px;
    color: #5f8587;
  }
  .slash {
    font-weight: 400;
    color: #8ca49c;
  }
  .masthead nav,
  .page-footer nav {
    display: flex;
    align-items: center;
    gap: 23px;
    font-size: 12px;
  }
  .version {
    font: 10px var(--fk-font-mono, monospace);
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 4px 7px;
  }
  main {
    max-width: 1336px;
    margin: auto;
    padding: 24px 24px 0;
  }
  .edition,
  .deck-heading,
  .section-line {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font: 10px/1.4 var(--fk-font-mono, monospace);
    letter-spacing: 1.4px;
  }
  .edition {
    margin-bottom: 20px;
    color: var(--muted);
  }
  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 286px;
    gap: 32px;
    align-items: start;
  }
  .arena-panel {
    width: 100%;
    max-width: min(100%, calc((100svh - var(--safe-top) - var(--safe-bottom) - 273px) * 1.333333));
    margin: 0 auto;
  }
  .telemetry {
    height: 68px;
    display: grid;
    grid-template-columns: 1.65fr 1fr 1fr 1fr;
    gap: 16px;
    align-items: start;
  }
  .telemetry > div {
    border-left: 1px solid var(--line);
    padding-left: 14px;
  }
  .telemetry > div:first-child {
    border: 0;
    padding-left: 0;
    position: relative;
  }
  .telemetry span {
    display: block;
    font: 9px var(--fk-font-mono, monospace);
    letter-spacing: 1.3px;
    color: var(--muted);
  }
  .telemetry strong {
    display: block;
    font: 22px/1.25 var(--fk-font-mono, monospace);
    margin-top: 5px;
    letter-spacing: -1px;
  }
  .telemetry small {
    font-size: 12px;
    letter-spacing: 0;
  }
  .telemetry #lives {
    font-size: 15px;
    letter-spacing: 2px;
    padding-top: 4px;
    color: #627f7f;
  }
  .coverage strong {
    display: inline-block;
  }
  .meter {
    position: absolute;
    left: 68px;
    top: 27px;
    right: 0;
    height: 3px;
    background: #d5dacd;
  }
  .meter i {
    display: block;
    width: 100%;
    height: 100%;
    background: #507d83;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.25s;
  }
  .meter b {
    position: absolute;
    top: -3px;
    width: 1px;
    height: 9px;
    background: var(--ink);
  }
  .coverage em {
    display: block;
    font: 8px var(--fk-font-mono, monospace);
    color: var(--muted);
    margin-top: 1px;
  }
  .arena-shell {
    position: relative;
    width: 100%;
    aspect-ratio: var(--board-ratio, 4 / 3);
    background: #102831;
    box-shadow: 0 18px 35px #16353e1c;
    border: 1px solid #344e50;
    isolation: isolate;
  }
  .first-flight-panel {
    margin: 12px 0;
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--paper);
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .first-flight-session [data-course-hide] {
    display: none;
  }
  .first-flight-session .loadout-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .first-flight-panel[hidden],
  .first-flight-markers[hidden] {
    display: none;
  }
  .first-flight-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 12px;
  }
  .first-flight-heading h2 {
    margin: 0;
    font-size: 16px;
  }
  .first-flight-heading > span {
    font-size: 11px;
  }
  .first-flight-panel p {
    margin: 8px 0;
    font-size: 12px;
    line-height: 1.5;
  }
  .first-flight-task {
    display: none;
    margin: 0 0 6px;
    font-size: 12px;
    line-height: 1.4;
    font-weight: 700;
    overflow-wrap: anywhere;
  }
  .first-flight-session .first-flight-task {
    display: block;
  }
  .first-flight-session .arena-shell {
    scroll-margin-block: 12px;
  }
  /* Training adds a task row. Reserve its space without changing ordinary boards
   or the compact layout where board and primary controls already fit together. */
  @media (min-width: 681px) and (min-height: 501px) and (max-height: 900px) {
    .first-flight-session .arena-panel {
      max-width: min(
        100%,
        calc((100svh - var(--safe-top) - var(--safe-bottom) - 410px) * 1.333333)
      );
    }
  }
  @media (min-width: 681px) and (max-width: 1100px) and (min-height: 501px) and (max-height: 900px) {
    .first-flight-session .arena-panel {
      max-width: min(
        100%,
        calc((100svh - var(--safe-top) - var(--safe-bottom) - 430px) * 1.333333)
      );
    }
  }
  @media (min-width: 681px) and (min-height: 901px) {
    .first-flight-session .arena-panel {
      max-width: min(
        100%,
        850px,
        calc((100svh - var(--safe-top) - var(--safe-bottom) - 470px) * 1.333333)
      );
    }
  }
  @media (min-width: 681px) and (max-height: 500px) {
    .first-flight-session .arena-panel > .arena-shell {
      max-width: min(
        100%,
        max(200px, calc((100svh - var(--safe-top) - var(--safe-bottom) - 175px) * 1.333333))
      );
    }
  }
  .first-flight-panel label {
    display: block;
    margin-top: 8px;
    font-size: 12px;
  }
  .first-flight-panel select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    color: var(--ink);
    background: var(--paper);
    font: inherit;
    padding: 8px;
  }
  .first-flight-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
  }
  .first-flight-actions .button,
  #first-flight-help-enter,
  #first-flight-entry-cancel,
  .first-flight-steps summary {
    min-height: 44px;
    min-width: 44px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .first-flight-actions .button {
    flex: 1 1 130px;
  }
  .first-flight-steps summary {
    cursor: pointer;
    padding: 12px 0;
    font-size: 12px;
  }
  .first-flight-steps ol {
    margin: 0;
    padding-left: 20px;
    font-size: 12px;
    line-height: 1.6;
  }
  .first-flight-markers {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
  }
  .first-flight-markers * {
    pointer-events: none;
  }
  .first-flight-marker {
    position: absolute;
    border: 1px dashed #fff3bf;
    color: #fff9df;
  }
  .first-flight-marker-start,
  .first-flight-marker-objective {
    border-style: solid;
    border-radius: 50%;
  }
  .first-flight-marker-return {
    border-style: double;
    border-width: 3px;
  }
  .first-flight-marker-band {
    background: #ffe7a00b;
  }
  .first-flight-marker > span {
    position: absolute;
    top: 0;
    left: 0;
    max-width: 150px;
    background: #112d35e8;
    padding: 2px 4px;
    font: 10px/1.2 var(--fk-font-mono, monospace);
    white-space: nowrap;
  }
  .first-flight-marker-start > span,
  .first-flight-marker-divider > span,
  .first-flight-marker-objective > span {
    left: 100%;
  }
  .first-flight-marker-return > span {
    top: auto;
    bottom: 100%;
  }
  #game-canvas {
    width: 100%;
    height: 100%;
    outline-offset: 4px;
  }
  #game-canvas canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    image-rendering: pixelated;
  }
  .game-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #0b2328e8, #0d2936bb);
    color: #f3eddb;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    z-index: 2;
  }
  .overlay-card {
    max-width: 450px;
    width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
  }
  .overlay-message {
    min-height: 90px;
    overflow-y: auto;
  }
  #overlay-title {
    white-space: pre-line;
    overflow-wrap: anywhere;
  }
  .game-overlay[data-kind='ready'][data-intro='false'] #overlay-title {
    font-size: clamp(23px, 2.7vw, 34px);
    margin-bottom: 12px;
  }
  .game-overlay[data-kind='ready'] #overlay-copy {
    white-space: pre-line;
  }
  .game-overlay[data-kind='ready'] .overlay-actions {
    flex-wrap: nowrap;
  }
  .game-overlay[data-kind='ready'] .overlay-actions .button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding-inline: 9px;
  }
  .overlay-actions,
  .overlay-footnote {
    flex-shrink: 0;
  }
  .eyebrow {
    font: 9px/1.6 var(--fk-font-mono, monospace);
    letter-spacing: 1.8px;
    color: var(--accent);
    margin: 0 0 14px;
  }
  h1 {
    font-size: clamp(25px, 3.5vw, 48px);
    font-weight: 600;
    line-height: 1.06;
    letter-spacing: -1.8px;
    margin: 0 0 20px;
  }
  #overlay-copy {
    max-width: 370px;
    color: #bacbcc;
    font-size: 13px;
    line-height: 1.65;
    margin: 0 0 23px;
  }
  #retry-consequence {
    color: #bacbcc;
    font-size: 11px;
    line-height: 1.5;
    margin: 0 0 16px;
  }
  #overlay-difficulty {
    color: #bacbcc;
    font-size: 12px;
    line-height: 1.5;
    margin: 0 0 16px;
  }
  #difficulty-note {
    font-size: 11px;
    line-height: 1.5;
  }
  #difficulty-select,
  #gallery-difficulty {
    min-height: 44px;
  }
  #difficulty-field,
  #difficulty-details {
    grid-column: 1 / -1;
  }
  .difficulty-details {
    margin: -8px 0 16px;
    font-size: 11px;
    line-height: 1.5;
  }
  .difficulty-details summary {
    min-height: 44px;
    align-content: center;
    cursor: pointer;
  }
  .difficulty-details ul {
    padding-left: 18px;
  }
  .difficulty-details li + li {
    margin-top: 8px;
  }
  .overlay-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  .button {
    border: 1px solid #a1b4ad;
    background: transparent;
    color: var(--ink);
    border-radius: 2px;
    padding: 11px 17px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    min-height: 43px;
  }
  .primary {
    background: var(--accent);
    color: #233234;
    border-color: var(--accent);
  }
  .secondary {
    background: #ffffff35;
  }
  .overlay-actions .secondary {
    color: #eff2e8;
    border-color: #617e7f;
    background: #173a4359;
  }
  .overlay-footnote {
    font: 9px/1.6 var(--fk-font-mono, monospace);
    color: #9cb3b3;
    margin: 20px 0 0;
  }
  .result-auto-next {
    flex-basis: 100%;
    width: fit-content;
    margin: 14px 0 0;
    padding: 7px 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: #d8e9df;
    font: 10px/1.4 var(--fk-font-mono, monospace);
    letter-spacing: 0.35px;
  }
  .game-overlay[data-kind='won'] .result-auto-next[hidden][data-reserve-space='true'] {
    display: block !important;
    visibility: hidden;
  }
  .landing-version {
    margin: 10px 0 0;
    color: var(--muted);
    font: 8px/1 var(--fk-font-mono, monospace);
    letter-spacing: 1px;
    opacity: 0.72;
    text-align: right;
    text-transform: uppercase;
  }
  .result-medals {
    font-size: 26px;
    letter-spacing: 5px;
    color: var(--accent);
    margin-bottom: 17px;
  }
  .flight-status {
    display: flex;
    gap: 15px;
    justify-content: space-between;
    align-items: center;
    height: 36px;
    font: 9px var(--fk-font-mono, monospace);
    color: var(--muted);
  }
  .flight-status > span:first-child {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
  }
  .flight-status strong {
    font-weight: 400;
  }
  .flight-status i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #6e9691;
  }
  .play-controls {
    --flight-target-size: 44px;
    --flight-target-gap: 4px;
    display: flex;
    align-items: start;
    gap: 8px;
    justify-content: space-between;
    border-top: 1px solid var(--line);
    padding-top: 12px;
  }
  .play-controls .direction-controls {
    display: grid;
    flex: none;
    grid-template-columns: repeat(3, var(--flight-target-size));
    grid-template-rows: repeat(3, var(--flight-target-size));
    gap: var(--flight-target-gap);
  }
  .play-controls .direction-controls button {
    width: var(--flight-target-size);
    height: var(--flight-target-size);
    min-width: var(--flight-target-size);
    min-height: var(--flight-target-size);
  }
  .direction-controls button {
    border: 1px solid #bbc8be;
    background: #e7ece1;
    color: var(--ink);
    border-radius: 3px;
    font: 19px var(--fk-font-mono, monospace);
    padding: 0;
  }
  .direction-controls [data-move='up'] {
    grid-column: 2;
  }
  .direction-controls [data-move='left'] {
    grid-row: 2;
  }
  .direction-controls #stop-button {
    grid-row: 2;
    font-size: 9px;
  }
  .direction-controls [data-move='right'] {
    grid-row: 2;
  }
  .direction-controls [data-move='down'] {
    grid-column: 2;
    grid-row: 3;
  }
  .direction-controls button.pressed,
  #boost-button.pressed {
    background: var(--ink);
    color: var(--paper);
  }
  .play-controls .ability-buttons {
    flex: 1;
    min-width: 0;
  }
  .play-controls .ability-buttons .button {
    min-width: var(--flight-target-size);
    min-height: var(--flight-target-size);
    max-width: 100%;
    gap: 8px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .play-controls .ability-buttons kbd {
    flex: none;
    max-width: 100%;
  }
  .ability-buttons {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
  }
  .ability {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
    min-width: 110px;
  }
  kbd {
    font: 9px var(--fk-font-mono, monospace);
    opacity: 0.65;
  }
  .ability-buttons > span {
    width: 100%;
    font: 9px var(--fk-font-mono, monospace);
    color: var(--muted);
  }
  .utility-buttons {
    display: flex;
    gap: 5px;
  }
  .play-controls .utility-buttons {
    flex: none;
    flex-direction: column;
    gap: var(--flight-target-gap);
  }
  .play-controls .icon-button {
    flex: none;
    width: var(--flight-target-size);
    height: var(--flight-target-size);
    min-width: var(--flight-target-size);
    min-height: var(--flight-target-size);
  }
  .icon-button {
    width: 34px;
    height: 35px;
    border: 1px solid var(--line);
    color: var(--ink);
    background: transparent;
    font-size: 18px;
  }
  .icon-button[aria-pressed='true'] {
    background: var(--ink);
    color: var(--paper);
  }
  .run-message {
    font-size: 11px;
    min-height: 17px;
    margin: 11px 0 8px;
    color: #4e6d70;
  }
  .settings-assists {
    display: flex;
    flex-wrap: wrap;
    gap: 0 20px;
  }
  .settings-assists label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
  }
  .minor-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    font: 9px/1.5 var(--fk-font-mono, monospace);
    color: var(--muted);
    align-items: center;
  }
  .minor-controls label {
    display: flex;
    gap: 4px;
    align-items: center;
  }
  .minor-controls input {
    accent-color: var(--ink);
  }
  .minor-controls > span {
    margin-left: auto;
  }
  .text-button {
    border: 0;
    padding: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 4px;
  }
  .flight-deck {
    border-left: 1px solid var(--line);
    padding-left: 27px;
  }
  .deck-heading {
    margin-bottom: 22px;
  }
  .deck-heading span:last-child {
    color: var(--muted);
  }
  .mission-brief {
    margin: 0 0 16px;
    border-block: 1px solid var(--line);
    font-size: 12px;
    line-height: 1.6;
    overflow-wrap: anywhere;
  }
  .mission-brief summary {
    min-height: 44px;
    padding: 10px 0;
    cursor: pointer;
    font-weight: 600;
  }
  .mission-brief p {
    margin: 0 0 12px;
  }
  .mission-brief-title {
    font-weight: 600;
  }
  #mission-brief-facts {
    white-space: pre-line;
    color: var(--muted);
  }
  .reading-toolbar {
    flex-shrink: 0;
    margin: 8px 0;
  }
  .controller-boost-settings {
    margin-block: 20px;
  }
  .controller-boost-settings select {
    min-height: 44px;
    width: 100%;
    margin-top: 6px;
  }
  .controller-boost-cue {
    font-size: 11px;
    line-height: 1.5;
    border-left: 3px solid var(--accent);
    padding: 5px 8px;
    margin-block: 6px;
    overflow-wrap: anywhere;
  }
  .reading-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
    gap: 6px;
  }
  .reading-actions button {
    min-height: 44px;
    min-width: 0;
    border: 1px solid currentColor;
    border-radius: 3px;
    padding: 7px;
    background: transparent;
    color: inherit;
    font-size: 11px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }
  .reading-actions button:disabled {
    opacity: 0.45;
  }
  .reading-hint,
  .mission-brief .reading-hint {
    margin: 4px 0 0;
    min-height: 2.8em;
    font-size: 10px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  .game-overlay {
    overflow-y: auto;
    overflow-x: hidden;
    align-items: safe center;
  }
  [data-game-reading] {
    overflow-x: hidden;
    overflow-wrap: anywhere;
    overscroll-behavior: contain;
  }
  [data-game-reading]:focus-visible,
  [data-game-reading].controller-focus {
    outline: 2px solid currentColor;
    outline-offset: -2px;
  }
  #mission-brief-reading,
  [data-menu-reading] {
    max-height: min(40vh, 320px);
    overflow-y: auto;
    padding: 4px;
    margin-bottom: 8px;
  }
  #mission-brief-copy {
    white-space: pre-wrap;
  }
  .field {
    display: grid;
    gap: 5px;
    font: 10px var(--fk-font-mono, monospace);
    color: var(--muted);
    margin-bottom: 13px;
  }
  .field select,
  .field input {
    font: 12px var(--fk-font-ui, sans-serif);
    width: 100%;
    min-width: 0;
    border: 1px solid #b6c4bc;
    border-radius: 2px;
    background: #ffffff50;
    padding: 10px;
    color: var(--ink);
    min-height: 39px;
  }
  .content-switcher {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    margin: 0 0 13px;
    padding: 12px;
    border: 1px solid #b8c6b7;
    border-left: 3px solid var(--accent);
    background: #e9eadf;
  }
  .content-switcher .field {
    margin: 0;
  }
  .content-switcher select:disabled {
    opacity: 0.65;
  }
  .content-select-status {
    min-height: 2.8em;
    margin: -5px 0 13px;
  }
  .content-select-status[data-kind='error'] {
    color: #9d3f33;
  }
  @media (max-width: 500px) {
    .content-switcher {
      grid-template-columns: 1fr;
    }
  }
  .loadout-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .class-description {
    font-size: 11px;
    line-height: 1.6;
    margin: 0 0 15px;
    min-height: 36px;
    color: #587579;
  }
  #hangar-state {
    overflow-wrap: anywhere;
  }
  .micro-note {
    font-size: 9px;
    color: var(--muted);
    line-height: 1.55;
    margin: -3px 0 21px;
  }
  .section-line {
    font-size: 8px;
    letter-spacing: 0.8px;
    border-top: 1px solid var(--line);
    padding-top: 16px;
    margin-bottom: 12px;
  }
  .missions {
    display: grid;
    gap: 5px;
  }
  .mission {
    display: flex;
    align-items: center;
    text-align: left;
    width: 100%;
    gap: 10px;
    padding: 9px 10px;
    background: none;
    border: 1px solid transparent;
    color: var(--ink);
    border-radius: 2px;
  }
  .mission .number {
    font: 10px var(--fk-font-mono, monospace);
    color: var(--muted);
  }
  .mission .name {
    font-size: 12px;
    flex: 1;
  }
  .mission .medal {
    font: 9px var(--fk-font-mono, monospace);
    color: #97712c;
    letter-spacing: 2px;
  }
  .mission.selected {
    background: #e3e9dc;
    border-color: #b8c6b7;
  }
  .mission:not(:disabled):hover {
    background: #e8ebdf;
  }
  .deck-footer {
    border-top: 1px solid var(--line);
    margin-top: 22px;
    padding-top: 18px;
  }
  .deck-footer p {
    font-size: 21px;
    letter-spacing: -0.7px;
    margin: 0;
  }
  .deck-footer span {
    font-size: 10px;
    color: var(--muted);
  }
  .page-footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 23px 0 19px;
    margin-top: 20px;
    border-top: 1px solid var(--line);
    font: 9px var(--fk-font-mono, monospace);
    color: var(--muted);
  }
  .page-footer nav {
    font: 9px var(--fk-font-mono, monospace);
    gap: 15px;
  }
  .warning {
    font-size: 11px;
    border-left: 3px solid var(--danger);
    padding: 8px;
    background: #edcfb630;
  }
  dialog {
    border: 1px solid #aebfb2;
    max-width: min(560px, calc(100vw - 30px));
    max-height: 85svh;
    padding: 35px;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 30px 100px #0006;
  }
  dialog::backdrop {
    background: #09202899;
  }
  dialog h2 {
    font-size: 29px;
    line-height: 1.15;
    letter-spacing: -1px;
    margin-top: 0;
  }
  dialog p,
  dialog li {
    font-size: 12px;
    line-height: 1.8;
  }
  dialog li {
    margin-bottom: 8px;
  }
  dialog .eyebrow {
    color: #728b80;
  }
  .dialog-close {
    position: absolute;
    top: 10px;
    right: 12px;
    border: 0;
    background: none;
    color: inherit;
    font-size: 26px;
  }
  .achievement {
    padding: 13px 0;
    border-bottom: 1px solid var(--line);
  }
  .achievement strong {
    font-size: 13px;
    display: block;
  }
  .achievement span {
    font-size: 11px;
    color: var(--muted);
  }
  .achievement:not(.earned) {
    opacity: 0.5;
  }
  @media (min-width: 1100px) and (min-height: 900px) {
    .arena-panel {
      max-width: 850px;
    }
    .telemetry {
      height: 73px;
    }
    .masthead {
      height: 86px;
    }
  }
  @media (max-width: 1000px) {
    .game-layout {
      gap: 22px;
      grid-template-columns: minmax(0, 1fr) 245px;
    }
    .flight-deck {
      padding-left: 20px;
    }
    .arena-panel {
      max-width: 100%;
    }
    .masthead {
      padding: 0 24px;
    }
    .telemetry {
      gap: 7px;
    }
    .telemetry > div {
      padding-left: 9px;
    }
    .telemetry strong {
      font-size: 19px;
    }
    .meter {
      left: 58px;
    }
    .utility-buttons {
      flex-direction: column;
    }
    .play-controls {
      gap: 8px;
    }
    .ability-buttons .button {
      padding: 9px 12px;
      min-width: 88px;
    }
  }
  @media (max-width: 680px) {
    .masthead {
      height: 58px;
      padding: 0 16px;
    }
    .wordmark {
      font-size: 17px;
      gap: 7px;
    }
    .brand-mark {
      font-size: 24px;
    }
    .masthead nav {
      gap: 12px;
      font-size: 10px;
    }
    .masthead .version {
      display: none;
    }
    main {
      padding: 17px 16px 0;
    }
    .edition {
      font-size: 8px;
      letter-spacing: 0.8px;
      margin-bottom: 14px;
    }
    .game-layout {
      display: block;
    }
    .arena-panel {
      max-width: 100%;
    }
    .telemetry {
      height: 56px;
      grid-template-columns: 1.5fr 0.85fr 0.8fr 1fr;
      gap: 7px;
    }
    .telemetry span {
      font-size: 8px;
      letter-spacing: 0.6px;
    }
    .telemetry strong {
      font-size: 18px;
    }
    .telemetry #lives {
      font-size: 11px;
      letter-spacing: 1px;
    }
    .meter {
      left: 56px;
      top: 25px;
    }
    .coverage em {
      font-size: 7px;
    }
    .game-overlay {
      padding: 22px;
    }
    h1 {
      font-size: 30px;
      margin-bottom: 12px;
      letter-spacing: -1px;
    }
    #overlay-copy {
      font-size: 11px;
      line-height: 1.55;
      margin-bottom: 16px;
    }
    .eyebrow {
      font-size: 8px;
      margin-bottom: 9px;
    }
    .overlay-footnote {
      font-size: 8px;
      margin-top: 13px;
    }
    .button {
      min-height: 42px;
      font-size: 12px;
      padding: 10px 13px;
    }
    .overlay-actions {
      gap: 6px;
    }
    .flight-status {
      font-size: 8px;
      height: 31px;
    }
    .flight-status > span:last-child {
      text-align: right;
      max-width: 65%;
    }
    .utility-buttons {
      flex-direction: column;
      gap: 3px;
    }
    .icon-button {
      font-size: 15px;
    }
    .ability-buttons {
      flex-direction: column;
      align-items: stretch;
      gap: 4px;
    }
    .ability-buttons .button {
      min-height: 37px;
      font-size: 11px;
    }
    .ability-buttons > span {
      font-size: 8px;
    }
    .run-message {
      font-size: 10px;
      min-height: 30px;
    }
    .minor-controls {
      gap: 10px;
      font-size: 8px;
    }
    .minor-controls > span {
      display: none;
    }
    .flight-deck {
      margin-top: 28px;
      padding: 23px 0 0;
      border-left: 0;
      border-top: 1px solid var(--line);
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0 15px;
    }
    .deck-heading,
    .mission-brief,
    .class-description,
    .micro-note,
    .section-line,
    .missions,
    .deck-footer {
      grid-column: 1/-1;
    }
    .deck-heading {
      margin-bottom: 17px;
    }
    .loadout-grid {
      gap: 7px;
    }
    .class-description {
      min-height: 0;
    }
    .missions {
      grid-template-columns: 1fr 1fr;
    }
    .mission {
      padding: 10px 7px;
      gap: 6px;
    }
    .mission .name {
      font-size: 11px;
    }
    .deck-footer {
      display: none;
    }
    .page-footer {
      display: block;
      line-height: 1.8;
    }
    .page-footer nav {
      margin-top: 8px;
      flex-wrap: wrap;
      gap: 10px;
    }
    .result-medals {
      font-size: 20px;
      margin-bottom: 10px;
    }
  }
  @media (max-width: 350px) {
    main {
      padding: 13px 10px 0;
    }
    .masthead {
      padding: 0 10px;
    }
    .masthead nav {
      gap: 8px;
      font-size: 9px;
    }
    .wordmark {
      font-size: 15px;
    }
    .brand-mark {
      display: none;
    }
    .edition {
      font-size: 7px;
    }
    .game-overlay {
      padding: 16px;
    }
    h1 {
      font-size: 25px;
    }
    .overlay-footnote {
      display: none;
    }
    .overlay-actions .button {
      font-size: 11px;
    }
    .telemetry strong {
      font-size: 16px;
    }
    .ability-buttons .button {
      min-width: 89px;
      padding: 7px 9px;
    }
    .flight-deck {
      column-gap: 9px;
    }
    .loadout-grid {
      grid-template-columns: 1fr;
    }
    .missions {
      gap: 1px;
    }
    .mission .medal {
      letter-spacing: 0;
    }
  }
  @media (max-height: 500px) and (min-width: 681px) {
    .masthead {
      height: 40px;
    }
    .masthead .wordmark {
      font-size: 16px;
    }
    .masthead .brand-mark {
      font-size: 21px;
    }
    main {
      padding: 10px 18px 0;
    }
    .edition {
      margin-bottom: 8px;
      font-size: 8px;
    }
    .game-layout {
      grid-template-columns: minmax(0, 1fr) 228px;
      gap: 20px;
    }
    .arena-panel {
      max-width: calc((100svh - var(--safe-top) - var(--safe-bottom) - 125px) * 1.333333);
    }
    .telemetry {
      height: 40px;
    }
    .telemetry span {
      font-size: 7px;
    }
    .telemetry strong {
      font-size: 16px;
      margin-top: 2px;
    }
    .telemetry #lives {
      font-size: 11px;
    }
    .coverage em {
      display: none;
    }
    .meter {
      top: 20px;
    }
    .flight-status {
      height: 24px;
      font-size: 8px;
    }
    .flight-deck {
      max-height: calc(100svh - var(--safe-top) - var(--safe-bottom) - 83px);
      overflow: auto;
      padding-right: 5px;
    }
    .deck-heading {
      margin-bottom: 12px;
    }
    .field {
      margin-bottom: 9px;
    }
    .class-description {
      min-height: 0;
    }
    .game-overlay {
      padding: 22px;
    }
    h1 {
      font-size: 26px;
      margin-bottom: 10px;
    }
    #overlay-copy {
      font-size: 11px;
      line-height: 1.4;
      margin-bottom: 12px;
    }
    .overlay-footnote {
      display: none;
    }
    .eyebrow {
      font-size: 7px;
      margin-bottom: 8px;
    }
    .overlay-actions .button {
      min-height: 36px;
      padding: 8px 13px;
      font-size: 11px;
    }
    .ability-buttons {
      gap: 3px;
      justify-content: center;
    }
    .ability-buttons .button {
      min-height: 28px;
      min-width: 84px;
      padding: 4px;
      font-size: 10px;
    }
    .ability-buttons > span {
      font-size: 7px;
      text-align: center;
    }
    .utility-buttons {
      flex-direction: row;
    }
    .arena-panel {
      margin-right: 0;
    }
    .minor-controls,
    .run-message,
    .page-footer {
      display: none;
    }
    .result-medals {
      font-size: 16px;
      margin-bottom: 7px;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      scroll-behavior: auto !important;
      transition: none !important;
      animation: none !important;
    }
  }

  /* The in-game Reduced effects switch must provide the same DOM-motion contract
   as the operating-system preference. Canvas feedback remains governed by the
   renderer so essential trail, impact and danger state stays visible. */
  body[data-effects='reduced'] *,
  body[data-effects='reduced'] *::before,
  body[data-effects='reduced'] *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }

  /* Keep held touch controls independent from page scrolling. */
  .direction-controls button,
  #boost-button {
    touch-action: none;
  }

  .picture-return {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 4;
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--ink);
    padding: 12px 18px;
    font-size: 12px;
    box-shadow: 0 2px 12px #10283125;
  }

  /* Compact layouts keep gameplay actions at usable touch sizes. */
  @media (max-width: 680px) {
    .arena-panel {
      max-width: min(
        100%,
        max(280px, calc((100svh - var(--safe-top) - var(--safe-bottom) - 430px) * 1.333333))
      );
    }
    .play-controls {
      display: grid;
      grid-template-columns: 144px minmax(0, 1fr);
      align-items: start;
      gap: 8px;
    }
    .ability-buttons .button {
      min-width: 0;
      min-height: 44px;
      padding: 8px 5px;
    }
    .play-controls .utility-buttons {
      grid-column: 1 / -1;
      flex-direction: row;
      justify-content: flex-end;
    }
    .game-overlay {
      overflow: auto;
      align-items: safe center;
    }
  }
  @media (max-height: 500px) and (min-width: 681px) {
    .ability-buttons > span {
      line-height: 8px;
    }
    .game-overlay {
      overflow: auto;
      align-items: safe center;
    }
  }

  #replay-json {
    display: block;
    scroll-margin-block: 8px;
    width: 100%;
    height: 180px;
    margin: 18px 0;
    border: 1px solid var(--line);
    padding: 12px;
    font: var(--fk-text-control, 16px) / 1.5 var(--fk-font-mono, monospace);
    resize: vertical;
  }

  @media (min-width: 681px) and (min-height: 501px) and (max-height: 900px) {
    .masthead {
      height: 64px;
    }
    main {
      padding-top: 16px;
    }
    .edition {
      margin-bottom: 12px;
    }
    .telemetry {
      height: 55px;
    }
    .arena-panel {
      max-width: min(
        100%,
        calc((100svh - var(--safe-top) - var(--safe-bottom) - 360px) * 1.333333)
      );
    }
  }
  @media (min-width: 681px) and (max-width: 1100px) and (min-height: 501px) {
    .arena-panel {
      max-width: min(
        100%,
        calc((100svh - var(--safe-top) - var(--safe-bottom) - 380px) * 1.333333)
      );
    }
    .ability-buttons .button {
      min-height: 44px;
    }
  }

  /* Tall windows still reserve space for the full direction and utility columns. */
  @media (min-width: 681px) and (min-height: 901px) {
    .arena-panel {
      max-width: min(
        100%,
        850px,
        calc((100svh - var(--safe-top) - var(--safe-bottom) - 420px) * 1.333333)
      );
    }
  }

  .masthead nav {
    flex-wrap: wrap;
    gap: 14px;
  }
  .deck-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
  }
  .deck-actions button {
    flex: 1;
    min-height: 44px;
    padding: 8px;
    font-size: 11px;
  }
  .wide-dialog {
    width: min(920px, calc(100vw - 28px));
    max-width: 920px;
  }
  dialog {
    max-height: calc(100svh - var(--safe-top) - var(--safe-bottom) - 32px);
    overflow: auto;
  }
  dialog .field {
    margin: 18px 0;
  }
  dialog select,
  dialog input[type='file'],
  dialog input[type='date'] {
    min-height: 44px;
  }
  dialog button {
    min-height: 44px;
  }
  dialog details {
    margin: 18px 0;
  }
  dialog summary {
    cursor: pointer;
    padding: 12px 0;
  }
  dialog textarea {
    display: block;
    width: 100%;
    min-height: 170px;
    margin: 12px 0;
    padding: 12px;
    border: 1px solid var(--line);
    font: 11px/1.5 var(--fk-font-mono, monospace);
    resize: vertical;
  }
  .library-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 20px 0;
  }
  .library-tabs button {
    font-size: 12px;
    padding: 8px 12px;
  }
  .scoreboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
  }
  .scoreboard h3 {
    font-size: 16px;
    margin: 8px 0;
  }
  .scoreboard ol {
    padding-left: 22px;
    font-size: 12px;
    line-height: 1.8;
  }
  .scoreboard section {
    padding: 10px 0;
    border-top: 1px solid var(--line);
  }
  .pack-list article {
    padding: 18px 0;
    border-bottom: 1px solid var(--line);
  }
  .pack-list button {
    margin: 5px 8px 5px 0;
    font-size: 12px;
  }
  .slider-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin: 20px 0;
  }
  .slider-field input {
    flex: 1;
    max-width: 280px;
  }
  .gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 18px;
    margin: 24px 0;
  }
  .gallery-card {
    display: flex;
    flex-direction: column;
    text-align: left;
    padding: 0 0 12px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
  }
  .gallery-card canvas {
    display: block;
    width: 100%;
    aspect-ratio: 4/3;
    image-rendering: pixelated;
  }
  .gallery-card strong,
  .gallery-card span {
    padding: 0 12px;
    margin-top: 9px;
  }
  .gallery-card strong {
    font-size: 14px;
  }
  .gallery-card span {
    font-size: 10px;
    letter-spacing: 1px;
  }
  #gallery-canvas {
    display: block;
    width: 100%;
    max-height: 65svh;
    aspect-ratio: 4/3;
    object-fit: contain;
    image-rendering: pixelated;
    margin: 18px 0;
  }
  @media (min-width: 681px) and (max-height: 500px) {
    #gallery-view-dialog[open] {
      display: grid;
      grid-template-columns: minmax(0, 1fr) minmax(240px, 0.72fr);
      grid-template-rows: auto auto auto minmax(0, 1fr) auto;
      grid-template-areas:
        'picture meta'
        'picture title'
        'picture difficulty'
        'picture seals'
        'picture actions';
      gap: 8px 20px;
      height: calc(100svh - var(--safe-top) - var(--safe-bottom) - 32px);
      padding: 16px;
    }
    #gallery-view-dialog .dialog-close {
      top: 8px;
      right: 8px;
      width: 44px;
      height: 44px;
    }
    #gallery-view-meta {
      grid-area: meta;
      margin: 0;
      padding-right: 44px;
      overflow-wrap: anywhere;
    }
    #gallery-view-title {
      grid-area: title;
      margin: 0;
      padding-right: 44px;
      font-size: 24px;
      overflow-wrap: anywhere;
    }
    #gallery-view-masteries {
      grid-area: seals;
      min-height: 0;
      max-height: 100%;
      margin: 0;
      overflow-y: auto;
    }
    #gallery-difficulty-field {
      grid-area: difficulty;
      margin: 0;
      min-width: 0;
    }
    #gallery-canvas {
      grid-area: picture;
      width: 100%;
      height: 100%;
      min-width: 0;
      min-height: 0;
      max-height: 100%;
      margin: 0;
    }
    #gallery-view-dialog > .overlay-actions {
      grid-area: actions;
      display: grid;
      gap: 8px;
    }
    #gallery-view-dialog > .overlay-actions .button {
      min-width: 0;
      min-height: 44px;
      padding: 8px 12px;
    }
  }
  #collection-dialog {
    width: min(840px, calc(100vw - 28px));
    max-width: 840px;
  }
  .appearance-hint {
    font-size: 12px;
    line-height: 1.5;
    margin: 8px 0 14px;
  }
  #collection-choose-appearance {
    min-height: 44px;
  }
  .appearance-unlock {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    font-weight: 600;
    font-size: 12px;
    line-height: 1.5;
    margin: 12px 0;
    overflow-wrap: anywhere;
  }
  .appearance-rewards {
    display: grid;
    gap: 12px;
  }
  .appearance-reward {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    border: 1px solid var(--line);
    padding: 16px;
    overflow-wrap: anywhere;
  }
  .appearance-reward.earned {
    border-left: 3px solid var(--accent);
  }
  .appearance-reward img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    image-rendering: pixelated;
  }
  .appearance-reward h4 {
    margin: 0 0 8px;
  }
  .appearance-reward p {
    font-size: 12px;
    line-height: 1.5;
    margin: 5px 0 0;
  }
  .appearance-reward .reward-progress {
    font-weight: 600;
  }
  .appearance-reward .reward-detail {
    opacity: 0.8;
  }
  @media (max-width: 480px) {
    .appearance-reward {
      grid-template-columns: 1fr;
    }
  }
  /* Existing dialog owners keep their original status and escape controls together. */
  #library-operation-rail,
  .dialog-operation-rail {
    position: sticky;
    inset-block-start: 0;
    z-index: 3;
    display: grid;
    gap: var(--fk-space-2, 8px);
    margin-block: var(--fk-space-3, 12px);
    padding: var(--fk-space-3, 12px);
    border: var(--fk-border-width, 1px) solid var(--fk-line, #425563);
    background: var(--fk-panel, #101923);
  }
  #library-operation-rail[hidden],
  .dialog-operation-rail[hidden] {
    display: none;
  }
  #library-operation-message,
  .dialog-operation-message {
    min-inline-size: 0;
    max-block-size: 40dvh;
    overflow-y: auto;
    overflow-wrap: anywhere;
  }
  #library-operation-message > .operation-status,
  .dialog-operation-message > .operation-status {
    margin: 0;
  }
  #library-operation-controls,
  .dialog-operation-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--fk-space-2, 8px);
  }
  #library-operation-controls > button,
  .dialog-operation-controls > button {
    min-block-size: max(44px, var(--fk-target-size, 44px));
    margin: 0;
  }
  #save-status,
  #pack-status {
    overflow-wrap: anywhere;
  }
  @media (max-width: 680px) {
    .masthead {
      height: auto;
      min-height: 72px;
      gap: 12px;
      align-items: flex-start;
      padding-top: 16px;
      padding-bottom: 12px;
    }
    .masthead nav {
      justify-content: flex-end;
      gap: 8px;
      max-width: 65%;
      font-size: 10px;
    }
    .masthead .wordmark {
      font-size: 12px;
    }
    .masthead .version {
      display: none;
    }
    .wide-dialog {
      padding: 22px;
    }
    .library-tabs {
      gap: 6px;
    }
    .library-tabs button {
      flex: 1;
      min-width: 100px;
    }
    .deck-actions button {
      font-size: 12px;
    }
    .gallery-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }
  }
  @media (pointer: coarse) {
    .button,
    .icon-button,
    .direction-controls button {
      min-width: 44px;
      min-height: 44px;
    }
    .masthead button,
    .masthead a {
      min-height: 44px;
      display: inline-flex;
      align-items: center;
    }
  }

  dialog input[type='search'] {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    color: var(--ink);
    background: transparent;
    font: inherit;
  }

  .boot-status {
    position: fixed;
    z-index: 20;
    left: 50%;
    top: 16px;
    transform: translateX(-50%);
    padding: 12px 20px;
    background: var(--ink);
    color: var(--paper);
    font-size: 12px;
    box-shadow: 0 4px 18px #0002;
  }
  .key-binding-list {
    display: grid;
    gap: 8px;
    margin: 14px 0;
  }
  .key-binding-list button {
    min-height: 44px;
    width: 100%;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .mastery-note {
    color: #665019;
    font-size: 0.8rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-line;
  }
  .game-overlay .overlay-actions .button {
    min-height: 44px;
  }
  .mastery-list {
    max-height: 6rem;
    overflow-y: auto;
    margin: 0.5rem 0 1rem;
    padding-left: 1.2rem;
    color: #665019;
    font-size: 0.85rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
  }
  .game-overlay .mastery-note {
    color: #f2d889;
  }

  .encounter-status {
    display: grid;
    gap: 4px;
    margin: 8px 12px;
    padding: 8px 10px;
    border: 1px solid var(--muted);
    border-left: 4px solid var(--accent);
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  .encounter-status[hidden] {
    display: none;
  }
  .encounter-status strong {
    letter-spacing: 0.04em;
  }
  .encounter-status[data-phase='warning'] {
    border-left-style: dashed;
  }
  .encounter-status[data-phase='active'] {
    border-left-color: var(--danger);
  }
  .encounter-status[data-phase='open'] {
    border-left-color: var(--safe);
  }

  /* Reading controls need a usable board on ordinary missions too. Keep the
   available-column cap; shorter landscape and mobile layouts retain their sizes. */
  @media (min-width: 681px) and (min-height: 501px) {
    .arena-panel {
      min-width: min(100%, 320px);
    }
  }

  /* Preserve a readable board when phase text needs more than the viewport can fit.
   Small windows scroll vertically instead of shrinking the arena toward zero. */
  @media (min-width: 681px) {
    .arena-panel:has(> .encounter-status:not([hidden])) {
      --encounter-reserve: 273px;
      --encounter-min-width: 320px;
      max-width: min(
        100%,
        max(
          var(--encounter-min-width),
          calc(
            (100svh - var(--safe-top) - var(--safe-bottom) - var(--encounter-reserve)) * 1.333333
          )
        )
      );
    }
    .arena-panel:has(> .encounter-status:not([hidden])) > .arena-shell {
      width: 100%;
      margin-inline: auto;
      max-width: min(
        100%,
        max(
          var(--encounter-min-width),
          calc(
            (100svh - var(--safe-top) - var(--safe-bottom) - var(--encounter-reserve) - 90px) *
              1.333333
          )
        )
      );
    }
  }
  @media (min-width: 681px) and (min-height: 501px) and (max-height: 900px) {
    .arena-panel:has(> .encounter-status:not([hidden])) {
      --encounter-reserve: 360px;
    }
  }
  @media (min-width: 681px) and (max-width: 1100px) and (min-height: 501px) {
    .arena-panel:has(> .encounter-status:not([hidden])) {
      --encounter-reserve: 380px;
    }
  }
  @media (min-width: 681px) and (min-height: 901px) {
    .arena-panel:has(> .encounter-status:not([hidden])) {
      --encounter-reserve: 420px;
    }
  }
  @media (min-width: 681px) and (max-height: 500px) {
    .arena-panel:has(> .encounter-status:not([hidden])) {
      --encounter-reserve: 125px;
      --encounter-min-width: 200px;
    }
    .arena-panel:has(> .encounter-status:not([hidden])) > .arena-shell {
      margin-right: 0;
    }
  }

  /* A short landscape rail shares document flow with the board. Longer labels can
   grow the page without pushing fixed controls above the viewport or over play. */
  @media (min-width: 681px) and (max-height: 500px) {
    .arena-panel,
    .arena-panel:has(> .encounter-status:not([hidden])) {
      display: grid;
      grid-template-columns: 144px minmax(0, 1fr);
      grid-template-areas:
        'controls telemetry'
        'controls task'
        'controls arena'
        'controls status'
        'controls music'
        'controls boost'
        'controls encounter'
        'controls hunt'
        'controls reward'
        'controls course'
        'controls message'
        'controls minor'
        'controls warning'
        'controls mastery'
        'controls announcement'
        'controls help'
        'controls asset';
      column-gap: 16px;
      row-gap: 0;
      align-items: start;
      width: 100%;
      max-width: 100%;
    }
    .arena-panel > .telemetry {
      grid-area: telemetry;
    }
    .arena-panel > .arena-shell,
    .arena-panel:has(> .encounter-status:not([hidden])) > .arena-shell {
      grid-area: arena;
      width: 100%;
      min-width: min(100%, 200px);
      max-width: min(
        100%,
        max(200px, calc((100svh - var(--safe-top) - var(--safe-bottom) - 125px) * 1.333333))
      );
      margin-inline: auto 0;
    }
    .arena-panel > .flight-status {
      grid-area: status;
    }
    .arena-panel > .game-now-playing {
      grid-area: music;
    }
    .arena-panel > .first-flight-panel {
      grid-area: course;
    }
    .arena-panel > .first-flight-task {
      grid-area: task;
    }
    #controller-boost-cue {
      grid-area: boost;
    }
    #encounter-status {
      grid-area: encounter;
    }
    #appearance-unlock {
      grid-area: reward;
    }
    .play-controls {
      grid-area: controls;
      display: grid;
      grid-template-columns: minmax(0, 1fr) var(--flight-target-size);
      grid-template-areas: 'directions directions' 'actions utilities';
      align-items: stretch;
      border: 0;
      padding: 0;
      gap: 4px;
    }
    .play-controls .direction-controls {
      grid-area: directions;
      justify-self: center;
    }
    .play-controls .ability-buttons {
      grid-area: actions;
      flex: none;
      flex-direction: column;
      align-items: stretch;
    }
    .play-controls .utility-buttons {
      grid-area: utilities;
      flex-direction: column;
      justify-content: start;
    }
    #run-message {
      grid-area: message;
    }
    .arena-panel > .minor-controls {
      grid-area: minor;
    }
    #save-warning {
      grid-area: warning;
    }
    #mastery-status {
      grid-area: mastery;
    }
    #mastery-announcement {
      grid-area: announcement;
    }
    #controller-ui-hint {
      grid-area: help;
    }
    #asset-warning {
      grid-area: asset;
    }
  }

  /* A course also needs the rail in medium-height windows. Keep the ordinary
   500px breakpoint and reserve the taller header used in this range. */
  @media (min-width: 681px) and (min-height: 501px) and (max-height: 600px) {
    .first-flight-session .arena-panel {
      display: grid;
      grid-template-columns: 144px minmax(0, 1fr);
      grid-template-areas:
        'controls telemetry'
        'controls task'
        'controls arena'
        'controls status'
        'controls music'
        'controls boost'
        'controls encounter'
        'controls hunt'
        'controls reward'
        'controls course'
        'controls message'
        'controls minor'
        'controls warning'
        'controls mastery'
        'controls announcement'
        'controls help'
        'controls asset';
      column-gap: 16px;
      row-gap: 0;
      align-items: start;
      width: 100%;
      min-width: 0;
      max-width: 100%;
    }
    .first-flight-session .arena-panel > .telemetry {
      grid-area: telemetry;
    }
    .first-flight-session .arena-panel > .arena-shell {
      grid-area: arena;
      width: 100%;
      min-width: min(100%, 200px);
      max-width: min(
        100%,
        max(200px, calc((100svh - var(--safe-top) - var(--safe-bottom) - 245px) * 1.333333))
      );
      margin-inline: auto 0;
    }
    .first-flight-session .arena-panel > .flight-status {
      grid-area: status;
    }
    .first-flight-session .arena-panel > .game-now-playing {
      grid-area: music;
    }
    .first-flight-session .arena-panel > .first-flight-panel {
      grid-area: course;
    }
    .first-flight-session .arena-panel > .first-flight-task {
      grid-area: task;
    }
    .first-flight-session #controller-boost-cue {
      grid-area: boost;
    }
    .first-flight-session #encounter-status {
      grid-area: encounter;
    }
    .first-flight-session #appearance-unlock {
      grid-area: reward;
    }
    .first-flight-session .play-controls {
      grid-area: controls;
      display: grid;
      grid-template-columns: minmax(0, 1fr) var(--flight-target-size);
      grid-template-areas: 'directions directions' 'actions utilities';
      align-items: stretch;
      border: 0;
      padding: 0;
      gap: 4px;
    }
    .first-flight-session .play-controls .direction-controls {
      grid-area: directions;
      justify-self: center;
    }
    .first-flight-session .play-controls .ability-buttons {
      grid-area: actions;
      flex: none;
      flex-direction: column;
      align-items: stretch;
    }
    .first-flight-session .play-controls .utility-buttons {
      grid-area: utilities;
      flex-direction: column;
      justify-content: start;
    }
    .first-flight-session #run-message {
      grid-area: message;
    }
    .first-flight-session .arena-panel > .minor-controls {
      grid-area: minor;
    }
    .first-flight-session #save-warning {
      grid-area: warning;
    }
    .first-flight-session #mastery-status {
      grid-area: mastery;
    }
    .first-flight-session #mastery-announcement {
      grid-area: announcement;
    }
    .first-flight-session #controller-ui-hint {
      grid-area: help;
    }
    .first-flight-session #asset-warning {
      grid-area: asset;
    }
  }

  .game-now-playing {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 12px;
    overflow-wrap: anywhere;
    margin: 4px 0;
  }
  .game-now-playing[hidden] {
    display: none;
  }
  .game-now-playing a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
}

/* Earned community clips use the same picture-sized stage as the win reveal. */
.earned-video-dialog {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}
.earned-video-dialog::backdrop {
  background: transparent;
}
.earned-video-close {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 3;
}
.reward-media-cinematic {
  position: absolute;
  inset: 0;
}
.reward-media-cinematic > img,
.reward-media-cinematic > video {
  position: absolute;
  inset: 0;
  height: 100%;
  object-fit: contain;
}
.reward-media-cinematic > div,
.reward-media-cinematic > p,
.reward-media-cinematic > details {
  position: relative;
  z-index: 2;
  width: fit-content;
  max-width: calc(100% - 2rem);
  margin: 0.5rem 1rem;
  background: #070914d9;
}
.reward-media-cinematic > div {
  margin-top: max(1rem, env(safe-area-inset-top));
}
.reward-media-cinematic > details[open] {
  max-height: 40vh;
  overflow: auto;
}

/* Result commands stay inside one card; pictures never own the action surface. */
.field-kit.game-shell .game-overlay:is([data-kind='won'], [data-kind='lost']) {
  overflow: auto;
  align-items: safe center;
}
.field-kit.game-shell .game-overlay:is([data-kind='won'], [data-kind='lost']) > .overlay-card {
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.field-kit.game-shell
  .game-overlay:is([data-kind='won'], [data-kind='lost'])
  .continuous-result-actions {
  flex-shrink: 0;
  grid-column: 1 / -1;
  grid-row: auto;
  display: flex;
  overflow: visible;
  border-top: 1px solid var(--fk-line, #576166);
}
#result-mission-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}
#result-mission-actions[hidden] {
  display: none;
}
.continuous-play-quick-actions {
  position: fixed;
  z-index: 40;
  inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  width: fit-content;
  max-width: calc(100% - 24px);
  margin-inline: auto;
  padding: 0.6rem;
  background: var(--fk-panel, #24292b);
  border: 1px solid var(--fk-line, #576166);
}
.continuous-play-quick-actions[hidden] {
  display: none;
}
.continuous-play-quick-actions .button {
  min-height: 44px;
}
@media (max-width: 600px), (max-height: 500px) {
  .field-kit.game-shell .game-overlay:is([data-kind='won'], [data-kind='lost']) > .overlay-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .field-kit.game-shell .game-overlay:is([data-kind='won'], [data-kind='lost']) #overlay-reading {
    min-height: 0;
    max-height: none;
    overflow: visible;
    flex-shrink: 0;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #result-picture {
    max-height: 20dvh;
    width: 100%;
    object-fit: contain;
  }
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    margin-top: auto;
    padding: 0.4rem 0;
  }
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions
    > :is(button, details) {
    order: 1;
    width: 100%;
    margin: 0;
  }
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions
    :is(.button, summary) {
    min-height: 44px;
    min-width: 0;
    padding: 0.4rem;
    font-size: 0.875rem;
  }
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions
    > button {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] .continuous-result-actions > #next-button {
    order: 0;
    grid-column: 1 / -1;
  }
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions
    > .continuous-play-controls {
    order: 2;
    grid-column: 1 / -1;
    justify-content: space-between;
    gap: 0.25rem;
  }
  .field-kit.game-shell .continuous-result-actions > .earned-result-more[open] {
    position: static;
    grid-column: auto;
  }
  .field-kit.game-shell .continuous-result-actions > .earned-result-more > summary {
    width: 100%;
    justify-content: center;
  }
  .field-kit.game-shell .continuous-result-actions .earned-result-more-content {
    position: absolute;
    inset: auto 0 calc(100% + 0.35rem);
    max-height: min(40dvh, 220px);
    padding: 0.65rem;
    border: 1px solid var(--fk-line, #576166);
    background: var(--fk-panel, #24292b);
    overscroll-behavior: contain;
  }
}
@media (min-width: 601px) and (max-height: 500px) {
  .field-kit.game-shell .game-overlay[data-kind='won'] > .overlay-card {
    gap: 0.3rem;
    padding: 0.5rem 0.75rem;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #overlay-reading {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    grid-auto-rows: min-content;
    gap: 0.2rem 0.75rem;
    flex: 0 0 auto;
    min-height: 0;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #overlay-reading > * {
    grid-column: 2;
    grid-row: auto;
    margin: 0;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #result-picture {
    grid-column: 1;
    grid-row: 1 / span 5;
    align-self: center;
    width: 110px;
    height: 100px;
    max-height: 100px;
    aspect-ratio: auto;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #overlay-eyebrow {
    font-size: 0.75rem;
    line-height: 1.2;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #overlay-title {
    font-size: 26px;
    line-height: 1.05;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #overlay-copy {
    font-size: 0.9rem;
    line-height: 1.25;
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] #result-medals {
    justify-self: start;
    font-size: 26px;
    line-height: 1;
  }
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions {
    grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr));
  }
  .field-kit.game-shell .game-overlay[data-kind='won'] .continuous-result-actions > #next-button {
    grid-column: auto;
  }
}
@media (max-width: 380px) {
  .field-kit.game-shell
    .game-overlay:is([data-kind='won'], [data-kind='lost'])
    .continuous-result-actions
    > :is(#retry-button, #overlay-menu)::before {
    display: none;
  }
}
