@media (max-width: 700px), (max-height: 540px) and (hover: none) and (pointer: coarse) {
  body {
    --phone-left: max(12px, env(safe-area-inset-left));
    --phone-right: max(12px, env(safe-area-inset-right));
    --phone-top: max(12px, env(safe-area-inset-top));
    --phone-bottom: max(8px, env(safe-area-inset-bottom));
  }

  /* Let UI rows size themselves while the scene stays behind them. */
  #station-app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto minmax(0, 1fr) repeat(6, auto);
    gap: 5px 8px;
    padding: var(--phone-top) var(--phone-right) var(--phone-bottom) var(--phone-left);
  }

  #station-app > :is(.issue-header, .departure, .base-console, .view-nav, .view-caption, .magazine-controls, .edge-tools, .station-imprint, .station-credit, .bloom-intro) {
    position: relative;
    inset: auto;
    min-width: 0;
    max-width: none;
    width: auto;
    margin: 0;
  }

  #station-app > .issue-header { grid-area: 1 / 1 / 2 / -1; }
  .issue-header h1 { font-size: clamp(32px, 11.4vw, 44.4px); margin: 9px 0 5px; }
  .issue-deck { margin-top: 6px; }
  #station-app > .departure {
    grid-area: 2 / 1 / 3 / -1;
    justify-self: end;
    display: flex;
    align-items: baseline;
    gap: 8px;
    border: 0;
    padding: 0;
    pointer-events: none;
  }
  .departure-time { gap: 6px; margin: 0; }
  .departure-time time { font-size: 29px; }
  .departure-time > span { font-size: 10px; white-space: nowrap; }

  #station-app > .bloom-intro {
    grid-area: 3 / 1 / 4 / -1;
    align-self: start;
    z-index: 1;
    padding: 2px 0 0;
    color: var(--ink);
    text-align: center;
  }
  body:is([data-time="2"], [data-time="3"]) #station-app > .bloom-intro { color: var(--paper); }
  .bloom-intro p { margin: 0; font-size: 16px; line-height: 1.4; }
  .bloom-intro button { min-width: 84px; min-height: 44px; }

  #station-app > .base-console {
    grid-area: 4 / 1 / 5 / -1;
    --console-ink-height: 36px;
    --console-label-size: clamp(12px, 3.25vw, 14px);
    padding: 0 8px;
  }
  .ticket-is-open #station-app > .base-console { visibility: hidden; }
  .base-console .time-controls {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(34px, 1fr)) minmax(60px, 1.5fr) minmax(34px, 1fr);
  }
  .base-console .console-actions {
    flex: 0 0 auto;
    grid-template-columns: minmax(60px, max-content) minmax(40px, max-content);
  }
  .base-console button { min-width: 0; padding: 0 3px; gap: 2px; letter-spacing: 0; }
  .base-console button[aria-pressed="true"]::before { left: 2px; right: 2px; }
  .base-console .console-actions svg { display: none; }

  #station-app > .view-nav {
    grid-area: 5 / 1 / 6 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    border: 0;
    padding: 3px 0;
  }
  .view-nav button {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas: "number name" "english english";
    align-content: center;
    justify-content: center;
    gap: 3px 4px;
    min-height: 53px;
    min-width: 0;
    padding: 4px 2px;
    text-align: center;
  }
  .view-nav button::before { left: calc(50% - 1.5px); top: 2px; }
  .view-nav .view-number { grid-area: number; min-width: 0; font-size: 12px; }
  .view-nav .view-zh { grid-area: name; margin: 0; font-size: 13px; }
  .view-nav .view-en { grid-area: english; font-size: 13px; line-height: 1.08; white-space: normal; }

  #station-app > .view-caption {
    grid-area: 6 / 1 / 7 / -1;
    display: block;
    min-height: 0;
    padding: 3px 4px;
  }
  .view-caption p { font-size: 15px; line-height: 1.5; margin: 0 0 1px; }
  .view-caption > span { display: block; font-size: 11px; line-height: 1.3; }

  #station-app > .magazine-controls { grid-area: 7 / 1 / 8 / -1; padding: 3px 4px 0; }
  .magazine-controls > p { margin: 0 0 2px; font-size: 15px; line-height: 1.4; }
  .magazine-actions {
    display: grid;
    grid-template-columns: minmax(44px, 1fr) minmax(30px, .65fr) minmax(44px, 1fr) repeat(2, minmax(58px, 1.2fr));
    gap: 0;
  }
  .magazine-actions button, .magazine-actions .magazine-open {
    justify-content: center;
    min-height: 44px;
    padding: 0;
    margin: 0;
    font-size: 13px;
    white-space: nowrap;
  }
  .magazine-actions output { width: auto; font-size: 17px; }
  .magazine-actions svg { width: 10px; height: 10px; }
  #magazine-mirror-slot { margin: 0; }
  #magazine-mirror-slot button { width: 100%; }
  body:is([data-view="2"], [data-view="3"], [data-view="4"]) #station-app > :is(.issue-header, .view-caption, .magazine-controls) {
    box-shadow: none;
  }

  #station-app > .edge-tools { grid-area: 8 / 2; justify-self: end; gap: 2px; }
  .edge-tools button { min-height: 44px; padding: 0 5px; gap: 4px; font-size: 13px; white-space: nowrap; }
  .edge-tools svg { width: 14px; height: 14px; }
  #station-app > .station-imprint { grid-area: 8 / 1; align-self: center; font-size: 11px; }
  #station-app > .station-credit {
    grid-area: 9 / 1 / 10 / -1;
    justify-self: start;
    padding: 2px 4px;
    font-size: min(10px, 2.75vw);
    line-height: 1.45;
    white-space: nowrap;
  }

  #settings-dialog {
    inset: auto var(--phone-right) calc(var(--phone-bottom) + 54px) auto;
    width: min(360px, calc(100% - var(--phone-left) - var(--phone-right)));
    max-height: calc(100dvh - var(--phone-top) - var(--phone-bottom) - 54px);
    overflow: auto;
    overscroll-behavior: contain;
  }
  #settings-dialog .setting-row { grid-template-columns: max-content minmax(0, 1fr) 26px; }
  #settings-dialog input[type="range"], #settings-dialog .icon-button { min-height: 44px; }
  #settings-dialog .icon-button { min-width: 44px; }
  #settings-dialog input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -8px; }

  #ticket-dialog {
    width: min(860px, calc(100% - var(--phone-left) - var(--phone-right)));
    max-height: calc(100dvh - var(--phone-top) - var(--phone-bottom));
    overflow: hidden auto;
    overscroll-behavior: contain;
  }
  #ticket-dialog .ticket-dialog-inner { padding-inline: 12px; padding-top: 8px; }
  #ticket-dialog .ticket-form input { min-height: 44px; font-size: 16.8px; }
  #ticket-dialog .ticket-form label { font-size: 13px; }
  #ticket-dialog :is(.icon-button, .ticket-actions button) { min-height: 44px; min-width: 44px; }
  #ticket-dialog .ticket-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #ticket-dialog .ticket-actions button { padding-inline: 4px; white-space: normal; }
  #tear-instruction, .tear-meta { font-size: 13px; }
}

@media (max-width: 700px) and (max-height: 720px) and (orientation: portrait) {
  .issue-masthead { padding-bottom: 5px; }
  .issue-header h1 { margin: 4px 0 2px; }
  .issue-deck { margin-top: 3px; }
}

@media (max-width: 400px) and (max-height: 610px) and (orientation: portrait) {
  #station-app {
    --mobile-stage-top: calc(50dvh - 55vw);
    --mobile-stage-bottom: calc(var(--mobile-stage-top) + 86.625vw);
    row-gap: 3px;
  }
  #stage { width: 154vw; height: 86.625vw; left: -27vw; }
  .view-nav button { min-height: 48px; }
  #station-app > .view-caption { color: #352b45 !important; background: rgba(247, 241, 227, .94); }
  .view-caption > span { color: inherit; }
}

@media (max-width: 700px) and (max-height: 540px) and (orientation: landscape),
       (max-height: 540px) and (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #station-app {
    grid-template-columns: minmax(0, 1fr) minmax(0, .55fr) minmax(166px, .85fr);
    grid-template-rows: auto minmax(0, 1fr) repeat(4, auto);
    column-gap: 10px;
  }
  #stage { inset: 0; width: 100%; height: 100dvh; }
  #station-app > .issue-header { grid-area: 1 / 1 / 2 / 3; width: min(100%, 284px); }
  .issue-masthead { padding-bottom: 2px; font-size: 12px; }
  .issue-header h1 { margin: 2px 0; font-size: clamp(26px, 5vw, 34px); }
  .issue-deck { margin-top: 2px; font-size: 15px; }
  #station-app > .departure { grid-area: 1 / 3; align-self: start; flex-direction: column; align-items: flex-end; gap: 1px; }
  .departure-label { font-size: 12px; white-space: nowrap; }
  #station-app > .bloom-intro { grid-area: 2 / 1 / 3 / 3; justify-self: center; }
  #station-app > .view-nav {
    grid-area: 2 / 3 / 4 / 4;
    align-self: start;
    justify-self: end;
    width: min(100%, 230px);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #station-app > .view-caption { grid-area: 3 / 1 / 4 / 3; width: min(100%, 344px); }
  #station-app > .magazine-controls { grid-area: 4 / 1 / 5 / 3; width: min(100%, 360px); }
  #station-app > .base-console { grid-area: 5 / 1 / 6 / -1; justify-self: center; width: min(100%, 520px); }
  .base-console .console-actions svg { display: block; }
  #station-app > .edge-tools { grid-area: 4 / 3 / 5 / 4; align-self: end; flex-wrap: wrap; justify-content: end; }
  #station-app > .station-imprint { grid-area: 6 / 3; justify-self: end; }
  #station-app > .station-credit { grid-area: 6 / 1 / 7 / 3; }
  #station-app > :is(.view-caption, .magazine-controls, .edge-tools) {
    color: #352b45 !important;
    background: rgba(247, 241, 227, .94);
  }
  .view-caption > span, .magazine-actions button:hover, .edge-tools button:hover { color: inherit; }
}
