/* The route strip stays a single row on every size of game screen. */
#stall-route {
  flex-wrap: nowrap;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  padding: 3px 2px 5px;
}
#stall-route .stall-stop { flex: none; white-space: nowrap; }

@media (orientation: landscape) {
  body:not(.on-main) .shell {
    display: flex; flex-direction: column;
    width: min(100%, 1440px); max-width: none;
    height: 100vh; height: 100dvh;
    padding: max(4px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right))
      max(4px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left));
    gap: 5px;
  }
  body:not(.on-main) .mast { flex: none; min-height: 42px; padding: 0 0 3px; }
  body:not(.on-main) .heading { padding: 2px 0; --stall-heading-size: clamp(20px,3.2vh,32px); }
  body:not(.on-main) #stall-route { margin: 0; }
  body:not(.on-main) footer { margin: auto 0 0; padding-block: 2px; }
  body:not(.on-main) #cart-news:not([hidden]) { margin: 0; padding: 4px 10px; }
  body:not(.on-main) #cart-news ul { max-height: 3em; overflow-y: auto; }
  body:not(.on-main) .layout {
    flex: 1; min-height: 0; min-width: 0;
    display: grid; grid-template-columns: minmax(0,min(60%,var(--stage-fit,62vh))) minmax(0,1fr);
    grid-template-rows: auto auto minmax(0,1fr);
    grid-template-areas: "scene dock" "scene pantry" "scene ticket";
    align-items: start; align-content: start; margin: 0; gap: 6px 12px;
  }
  body:not(.on-main) .left-column { display: contents; }
  body:not(.on-main) .screen-frame { grid-area: scene; width: 100%; }
  body:not(.on-main) .order-stations { grid-area: dock; margin: 0; }
  body:not(.on-main) .pantry-box { grid-area: pantry; margin: 0; padding: 6px; }
  body:not(.on-main):not(.touch-ticket-open) .rail {
    grid-area: ticket; display: flex; flex-direction: column;
    min-height: 0; max-height: 100%; width: 100%; gap: 5px;
  }
  body:not(.on-main):not(.touch-ticket-open) .rail > .paper {
    display: block; min-height: 0; overflow: auto; padding: 12px 16px;
  }
  body:not(.on-main) .rail-controls { min-block-size: 0; }
  body:is(.is-playing,.is-paused) .heading { display: none; }
  body:not(.on-main) .prep-ticket { min-height: 44px; }
}
@media (orientation: landscape) and (max-height: 660px) {
  body:not(.on-main) .shell { gap: 3px; }
  body:not(.on-main) .heading { display: none; }
  body:not(.on-main) footer { display: none; }
  body:not(.on-main) .layout { gap: 4px 8px; }
  body:not(.on-main) #cart-news ul { max-height: 1.55em; }
  body:not(.on-main) .screen-top,body:not(.on-main) .screen-bottom { padding-block: 2px; min-height: 22px; }
  body:not(.on-main) .pantry { grid-template-columns: repeat(4,minmax(0,1fr)); --ingredient-size: 24px; --ingredient-type: 11px; gap: 3px; }
  body:not(.on-main) .ingredient { gap: 1px; padding-block: 2px; }
  body:not(.on-main) #mobile-ticket { display: inline-flex; }
  body:not(.on-main):not(.touch-ticket-open) .rail > :is(.paper,#stall-save-transfer,#offline-city,#offline-remove,#offline-note) { display: none; }
  body:not(.on-main) .rail-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 7px; }
  body:not(.on-main) .rail-note { font-size: 11px; }
  body:not(.on-main) .rail-controls > button { min-height: 44px; }
  body.touch-ticket-open #mobile-ticket-backdrop { display: block; position: fixed; inset: 0; z-index: 41; background: #071613ae; }
  body.touch-ticket-open #rail {
    display: flex; flex-direction: column; position: fixed; z-index: 42;
    inset: 4px max(8px,env(safe-area-inset-right)) 4px auto; transform: none;
    width: min(92%,510px); max-height: none; padding: 10px; gap: 6px;
    background: #1c342a; overflow: auto; overscroll-behavior: contain;
  }
  body.touch-ticket-open #mobile-ticket-close { display: inline-flex; align-self: flex-end; }
  body.touch-ticket-open #rail > .paper { display: block; }
}

@media (orientation: landscape) {
  body:not(.on-main) { min-height: 100dvh; }
}
@media (orientation: landscape) and (max-height: 660px) {
  body:not(.on-main) .mast-actions #review-notes-button { margin: 0; }
  body:not(.on-main) .rail-controls .rail-note { font-size: 11px; margin: 0; line-height: 1.15; min-height: 0; padding: 0; }
  body:not(.on-main) .screen-bottom .pips { display: none; }
  body:not(.on-main) .screen-top { font-size: 10px; }
  body:not(.on-main) .screen-bottom { font-size: 10px; }
}

@media (orientation: landscape) and (max-height: 660px) {
  body:not(.touch-ticket-open) #rail > #cart-news { display: none; }
  body.touch-ticket-open #rail > #cart-news ul { max-height: none; }
}
@media (orientation: landscape) and (max-height: 360px) {
  body:not(.touch-ticket-open) .rail-controls .rail-note { display: none; }
}
@media (orientation: landscape) and (max-height: 360px) {
  body:not(.on-main) #stall-route { padding-block: 0; }
}

.city-search { display:block; width:100%; min-height:44px; padding:8px 12px; margin:6px 0 10px; border:1px solid #807760; border-radius:4px; font:16px system-ui,sans-serif; color:#172c24; background:#fff9e8; }
@media (orientation: portrait) {
  body:not(.on-main) .shell { box-sizing:border-box; height:100dvh; width:100%; display:flex; flex-direction:column; gap:4px; padding-block:max(4px,env(safe-area-inset-top)) max(4px,env(safe-area-inset-bottom)); }
  body:not(.on-main) :is(.heading,footer) { display:none; }
  body:not(.on-main) .layout { display:grid; flex:1; min-height:0; grid-template-columns:minmax(0,1fr); grid-template-rows:auto auto auto auto; grid-template-areas:"scene" "dock" "pantry" "actions"; align-content:start; margin:0; gap:5px; }
  body:not(.on-main) .left-column,body:not(.on-main):not(.touch-ticket-open) .rail { display:contents; }
  body:not(.on-main) .screen-frame { grid-area:scene; width:100%; justify-self:center; }
  body:not(.on-main) #scene { width:min(100%,var(--portrait-stage,100%)); margin-inline:auto; }
  body[data-city="quanzhou"]:is(.is-playing,.is-paused) .pantry {grid-auto-rows:auto}
  body[data-city="quanzhou"]:is(.is-playing,.is-paused) .screen-frame {width:min(100%,calc(var(--portrait-stage,100%) + 4px))}
  body[data-city="quanzhou"]:is(.is-playing,.is-paused) #scene {width:100%}
  body:not(.on-main) .order-stations { grid-area:dock; margin:0; }
  body:not(.on-main) .pantry-box { grid-area:pantry; margin:0; }
  body:not(.on-main) .rail-controls { grid-area:actions; }
  body:not(.on-main) #mobile-ticket { display:inline-flex; }
  body:not(.on-main):not(.touch-ticket-open) #rail > :not(.rail-controls) { display:none; }
  body:not(.on-main):not(.touch-ticket-open) .rail-controls .rail-note { display:none; }
  body.touch-ticket-open #mobile-ticket-backdrop { display:block; position:fixed; inset:0; z-index:41; background:#071613ae; }
  body.touch-ticket-open #rail { position:fixed; z-index:42; display:flex; flex-direction:column; bottom:0; left:50%; transform:translateX(-50%); width:min(100%,520px); max-height:90dvh; padding:12px; overflow-y:auto; background:#1c342a; }
  body.touch-ticket-open #rail > .paper,body.touch-ticket-open #mobile-ticket-close { display:block; }
}

@media (orientation: portrait) and (max-height: 720px) {
  body:not(.on-main) .pantry { --ingredient-size:24px; --ingredient-type:11px; gap:3px; grid-template-columns:repeat(4,minmax(0,1fr)); }
  body:not(.on-main) .ingredient { padding:2px; gap:1px; }
}

/* Both tracks keep their dimensions when their contents are hidden. */
.task-readout { display: none; }
body:is(.is-playing, .is-paused) .task-readout {
  grid-area: task;
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: clamp(42px, 6dvh, 56px) 29px;
  background: #1d342d;
  border: 1px solid #647458;
  border-radius: 4px;
  overflow: hidden;
}
.task-readout #scene-help {
  grid-row: 1;
  min-width: 0;
  padding: 0 6px;
  border-left: 4px solid #efa957;
  background: #19392f;
  color: #ffdf94;
  font: 700 clamp(16px, 2.2vw, 20px)/1.15 var(--mono);
  text-align: center;
  overflow-wrap: anywhere;
}
.task-readout #scene-help:not([hidden]) {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  align-items: center;
}
.task-readout #motion-meter {
  grid-row: 2;
  min-height: 0;
  padding-block: 2px;
}
body:not(.on-main) .shell { height: var(--game-window-height, 100dvh); }
body:is(.is-playing, .is-paused):not(.on-main) .shell {
  zoom: var(--game-scale, 1);
  width: 100%;
  max-width: none;
}
@media (orientation: landscape) {
  body:is(.is-playing, .is-paused):not(.on-main) .layout {
    grid-template-columns: minmax(0, min(var(--stage-fit, 62vh), calc(100% - clamp(245px, 32%, 480px) - 12px))) minmax(0, 1fr);
    grid-template-rows: max-content max-content max-content minmax(0, 1fr);
    grid-template-areas: "scene task" "scene dock" "scene pantry" "scene ticket";
  }
}
@media (orientation: portrait) {
  body:is(.is-playing, .is-paused):not(.on-main) .layout {
    grid-template-rows: repeat(5, max-content);
    grid-template-areas: "scene" "task" "dock" "pantry" "actions";
  }
}
@media (orientation: portrait) and (max-width: 740px) {
  body:is(.is-playing, .is-paused) .rail-controls { min-block-size: 0; }
}
@media (orientation: portrait) and (min-width: 540px) and (min-aspect-ratio: 2/3) {
  body:is(.is-playing, .is-paused):not(.on-main) .layout {
    --shared-control-row: 1;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-template-rows: repeat(4, max-content);
    grid-template-areas: "scene scene" "task task" "dock pantry" "actions actions";
  }
  body:is(.is-playing, .is-paused) .order-stations { grid-template-columns: minmax(0, 1fr); }
}
@media (orientation: portrait) and (max-width: 740px) and (max-height: 680px) {
  body:is(.is-playing, .is-paused):not(.on-main) .layout { row-gap: 3px; }
  body:is(.is-playing, .is-paused) .task-readout { grid-template-rows: 40px 22px; }
  body:is(.is-playing, .is-paused) .pantry-box { padding-block: 3px; }
  body:is(.is-playing, .is-paused) .pantry-title { margin-block-end: 2px; }
  body:is(.is-playing, .is-paused):not(.on-main) .pantry { --ingredient-size: 20px; }
}
@media (orientation: portrait) and (max-width: 740px) and (max-height: 620px) {
  body:is(.is-playing, .is-paused):not(.on-main) .layout { row-gap: 1px; }
  body:is(.is-playing, .is-paused) .screen-top { min-height: 20px; padding-block: 2px; }
  body:is(.is-playing, .is-paused) .task-readout { grid-template-rows: 36px 16px; }
  .task-readout #motion-meter { padding-block: 0; }
  body:is(.is-playing, .is-paused) .order-stations .prep-ticket {
    min-height: 44px; row-gap: 0; padding-block: 2px;
  }
  .order-stations .prep-photo { width: 25px; height: 22px; }
  .order-stations .prep-variation { font-size: 11px; line-height: 1.15; }
  .order-stations .prep-line { margin-block: 0; }
  body:is(.is-playing, .is-paused):not(.on-main) .pantry { --ingredient-size: 16px; }
  body:is(.is-playing, .is-paused):not(.on-main) .ingredient { gap: 0; padding-block: 0; }
}
@media (orientation: landscape) and (max-height: 380px) {
  body:is(.is-playing, .is-paused) .task-readout { grid-template-rows: 36px 16px; }
  .task-readout #motion-meter { padding-block: 0; }
  body:is(.is-playing, .is-paused):not(.on-main) .pantry { --ingredient-size: 16px; }
  body:is(.is-playing, .is-paused):not(.on-main) .ingredient { gap: 0; padding-block: 0; }
  body:is(.is-playing, .is-paused) .pantry-box { padding-block: 3px; }
}
