@media (pointer: coarse) and (orientation: portrait) and (max-width: 700px) {
  #game {
    --pad-size: clamp(70px, 19vw, 84px);
    --deck-gap: clamp(6px, 1.9vw, 12px);
    --deck-left: max(var(--deck-gap), env(safe-area-inset-left));
    --deck-right: max(var(--deck-gap), env(safe-area-inset-right));
    --deck-foot: max(8px, env(safe-area-inset-bottom));
    --menu-size: 48px;
    --panel-green: #182721;
    --paper: #f1e5c8;
  }
  #game .deck {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 0;
    height: 100dvh;
    overflow: hidden;
  }
  #game .viewport {height: 100%; min-height: 0}
  #game .scene {
    display: grid;
    grid-template-columns: calc(var(--deck-left) + var(--pad-size) + var(--deck-gap)) minmax(0, 1fr) calc(var(--deck-gap) + var(--menu-size) + var(--deck-right));
    grid-template-rows: auto minmax(0, 1fr) auto calc(var(--pad-size) + 8px + var(--deck-foot));
    height: 100%;
    background: var(--panel-green);
  }
  #game .scene #art, #game .scene .carriage-plan {
    position: static;
    grid-area: 2 / 1 / 3 / -1;
    height: 100%;
    min-height: 0;
    width: 100%;
  }
  #game .scene .aim {grid-area: 2 / 1 / 3 / -1}
  #game .scenehud {
    position: static;
    grid-area: 1 / 1 / 2 / -1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    background: #17221e;
    border-bottom: 1px solid #65634c;
  }
  #game #loc {min-width: 0; margin-top: 1px; font-weight: 650; font-size: .91rem}
  #game .scenehud :is(#loc-map,#needs-open,#light-toggle,#clock-open) {align-self: flex-start; align-items: center; min-width: 44px; min-height: 44px; margin: 0}
  #game #clock-open {height: 44px}
  #game .scene .ride-status {
    position: static;
    grid-area: 1 / 1 / 2 / -1;
    align-self: start;
    justify-self: stretch;
    max-width: none;
    min-width: 0;
    margin: calc(44px + env(safe-area-inset-top)) 0 3px;
    padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    border: 0;
    gap: .6em;
    background: none;
    color: #d5ccae;
    font-size: .875rem;
    line-height: 1.25;
  }
  #game .ride-status #station {display: flex; flex: 0 1 auto; align-items: baseline; max-width: 100%; min-width: 0; color: inherit}
  .ride-status .station-call {min-width: 0; white-space: normal; word-break: normal; overflow-wrap: anywhere}
  .ride-status :is(#station-time,#rail-speed) {flex: none; white-space: nowrap; font-variant-numeric: tabular-nums}
  .ride-status #station-native {display: none}
  .ride-status #station {order: -1}
  #game .masthead {
    position: fixed;
    inset: auto var(--deck-right) calc(var(--deck-foot) + (var(--pad-size) - 54px) / 2) auto;
  }
  #game .masthead #show-key-guide {
    width: var(--menu-size);
    height: 54px;
    padding: 0;
    border: 1px solid #5a675c;
    border-radius: 7px;
    background: #25372d;
    text-align: center;
    color: #e2e1cf;
    font-size: .78rem;
  }
  #show-key-guide .menu-prefix {display: none}
  #show-key-guide::before {
    content: "";
    display: block;
    width: 15px;
    height: 9px;
    margin: 0 auto 5px;
    border-block: 1.5px solid currentColor;
    background: linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat;
  }
  #game .scene .stick-home {
    position: static;
    grid-area: 4 / 1;
    place-self: start;
    margin: 8px 0 0 var(--deck-left);
    width: var(--pad-size);
    height: var(--pad-size);
    border: 1px solid #798873;
    background: radial-gradient(circle, #354c3f 0 39%, #64735e 41%, #23382d 43%);
    color: var(--paper);
    font-weight: 600;
  }
  #game .view-tools, #game .passenger-invite > div {
    position: static;
    grid-area: 4 / 2;
    align-self: start;
    display: flex;
    gap: var(--deck-gap);
    width: 100%;
    max-width: none;
    margin-top: calc(8px + (var(--pad-size) - 54px) / 2);
  }
  #game .view-tools button, #game .passenger-invite button {
    display: grid;
    place-content: center;
    flex: 1 1 0;
    min-width: 0;
    min-height: 54px;
    margin: 0;
    padding: 5px;
    border: 1px solid #6f7a68;
    border-radius: 7px;
    background: #2b3c30;
    color: #f2eddb;
    font: 600 clamp(.8rem, 3.5vw, .96rem)/1.28 var(--cabin-type, sans-serif);
    text-align: center;
    word-break: keep-all;
  }
  #game #interact, #game .passenger-invite button:first-child {
    order: 0;
    background: var(--paper);
    color: #293327;
    border-color: #e0cfac;
  }
  #game .passenger-invite:not([hidden]) {display: contents}
  #game #passenger-call:not([hidden]) ~ #first-evening {display: none}
  #game .passenger-invite p {
    grid-area: 3 / 1 / 4 / -1;
    margin: 0;
    padding: 9px max(14px, env(safe-area-inset-right)) 2px max(14px, env(safe-area-inset-left));
    border-top: 1px solid #68705b;
    color: #f4eddb;
    font: 400 clamp(.9rem, 3.9vw, 1.04rem)/1.5 var(--cabin-type, sans-serif);
  }
  #game .scene:has(.passenger-invite:not([hidden])) .view-tools {display: none}
  #game .rail-announcement, #game #destination-cue, #game #speech-caption, #game #view-status.plan-status {
    position: static;
    grid-area: 3 / 1 / 4 / -1;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 6px max(14px, env(safe-area-inset-left));
    transform: none;
    border: 0;
    border-radius: 0;
    border-top: 1px solid #556454;
    background: #1b2a23;
    color: #e1dcc8;
    text-align: left;
    font-size: .83rem;
    line-height: 1.45;
  }
  #game .scene:has(.passenger-invite:not([hidden])) :is(.rail-announcement, #destination-cue, #speech-caption, #view-status.plan-status),
  #game .scene:has(#speech-caption:not([hidden])) :is(.rail-announcement, #destination-cue, #view-status.plan-status),
  #game .scene:has(#destination-cue:not([hidden])) :is(.rail-announcement, #view-status.plan-status),
  #game .scene:has(.rail-announcement:not([hidden]):not(:empty)) #view-status.plan-status,
  #game .rail-announcement:empty {display: none}
  #game:has(#encounter:not([hidden])) .scene {
    grid-template-rows: auto minmax(0, 1fr) 0 0;
  }
  #game:has(#encounter:not([hidden])) :is(.masthead, .rail-announcement, #destination-cue, #view-status.plan-status) {visibility: hidden}
  #game:has(#encounter:not([hidden])) .ride-status {visibility: visible}
  #game #encounter {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: none;
    max-height: 54dvh;
    padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    transform: none;
    border: 0;
    border-top: 1px solid #78806a;
    border-radius: 0;
    background: var(--panel-green);
    box-shadow: none;
    overscroll-behavior: contain;
    scrollbar-gutter: auto;
  }
  #game #end-encounter {position: sticky; top: 0; min-width: 48px; min-height: 48px; background: #2c3b31; border-radius: 6px; text-align: center}
  #game #encounter .conversation-line {font-size: 1.02rem; line-height: 1.55}
  #game #encounter #actions, #game #encounter #extra-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    clear: both;
  }
  #game #encounter :is(#actions, #extra-actions) button, #game #other-actions {
    min-height: 48px;
    padding: 8px 10px;
    background: #2b3c30;
    border: 1px solid #63705c;
    border-radius: 5px;
    line-height: 1.35;
  }
  #game #encounter.offering-fruit #actions, #game #encounter.listening #actions {display: none}
  #game #encounter.dialogue #other-actions {
    min-height: 44px;
    padding: 4px 2px;
    border: 0;
    background: none;
    color: #d3c6a8;
    text-decoration: underline;
    text-underline-offset: .22em;
    font-size: .83rem;
  }
  #game #encounter summary {padding-block: 12px}
  #game #ask-text {min-width: 0; font-size: 16px}
  #game #ask-passenger:not([hidden]) {flex-wrap: wrap}
  #game #ask-passenger label {flex-basis: 100%}
  .boarding #game .scene, .looking-out #game .scene, .travel-framing #game .scene,
  #game .scene:has(#handset-controls:not([hidden])) {grid-template-rows: 0 minmax(0, 1fr) 0 0}
  #game:has(#handset-controls:not([hidden])) :is(.stick-home, .masthead, .ride-status, .scenehud, #speech-caption, #destination-cue, .rail-announcement, #view-status.plan-status) {visibility: hidden}
  #game #handset-controls {bottom: var(--deck-foot); gap: 4px}
  #game #handset-controls button {min-height: 44px}
  .looking-out #game #view-status.plan-status {display: none}
}
#phase > span {font: inherit; color: inherit}
@media (pointer: coarse) and (orientation: portrait) and (max-width: 430px) {
  /* The pace is still read with the clock and shown in its timetable. Leave the first line for the coach and the time. */
  #game #clock-multiplier {position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap}
}
@media (pointer: coarse) and (orientation: portrait) and (max-width: 360px) {
  #game #phase > span {position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap}
}
