/* Keep the artwork and the first line of every label on common baselines. */
.pantry-box { container: pantry / inline-size; }
.pantry {
  --ingredient-size: 30px;
  --ingredient-type: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 5px;
}
.ingredient {
  display: grid;
  grid-template-rows: var(--ingredient-size) auto;
  align-content: start;
  justify-items: center;
  gap: 3px;
  padding: 4px 2px;
  min-height: 44px;
}
.ingredient img {
  display: block;
  width: var(--ingredient-size);
  height: var(--ingredient-size);
  object-fit: contain;
}
.ingredient span {
  width: 100%;
  min-height: 2.3em;
  font: 700 var(--ingredient-type)/1.15 var(--mono);
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
}
@container pantry (max-width: 21rem) {
  .pantry { --ingredient-size: 26px; --ingredient-type: 11px; gap: 4px; }
}
@container pantry (max-width: 18.5rem) {
  .pantry { --ingredient-type: 10.5px; }
}
@container pantry (max-width: 17.5rem) {
  .pantry { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container pantry (min-width: 44rem) {
  .pantry {
    --ingredient-size: 36px;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 6px;
  }
}

/* The full 3:2 street is also the pointer coordinate space for every utensil. */
#mobile-ticket, #mobile-ticket-close, #mobile-ticket-backdrop { display: none; }

@media (max-width: 740px), (max-width: 1100px) and (orientation: portrait), (pointer: coarse) and (max-width: 1440px), (min-width: 741px) and (max-width: 1100px) and (orientation: landscape), (max-height: 550px) and (max-width: 1100px) and (orientation: landscape) {
  .shell {
    width: 100%;
    max-width: none;
    padding: max(5px, env(safe-area-inset-top)) max(9px, env(safe-area-inset-right))
             max(12px, env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left));
  }
  .mast { min-height: 46px; padding: 0 0 4px; gap: 6px; }
  .mast-actions { gap: 5px; flex-shrink: 0; }
  .top-button, .game-action, .action-button, .secondary, .stall-stop {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }
  .top-button { padding: 0 9px; gap: 5px; font-size: 12px; }
  .brand { min-width: 0; gap: 7px; font-size: 10px; letter-spacing: .6px; }
  .brand-mark { flex: none; }
  .stall-stop { justify-content: center; font-size: 12px; }
  .screen-frame, .order-stations, .rail, .pantry-box { min-width: 0; }
  .pantry-box { margin: 0; padding: 7px; }
  .pantry-title { gap: 6px; margin-bottom: 5px; }
  .pantry-title h2 { font-size: 18px; }
  .pantry-title > span { font: 11px/1.2 var(--mono); text-align: right; }
  .prep-ticket { min-height: 48px; gap: 5px; padding: 4px 6px; }
  .prep-details, .prep-ticket .prep-status { font-size: 11px; }
  .prep-details b { font-size: 12px; }
  .order-stations { margin: 0; gap: 5px; }
  .meter-val { font-size: clamp(9px, 1.3cqw, 12px); }
  .guest-number { font-size: clamp(9px, 1.35cqw, 12px); }
  .screen-frame > .scene-help { min-height: 32px; align-content: center; font-size: clamp(11px, 1.8vw, 13px); line-height: 1.15; padding: 3px 7px; }
  .modal-back { padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .modal-card { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; }
  .modal-card :is(.action-button,.secondary) { min-height: 44px; }
  body:is(.is-playing,.is-paused) .heading { display: none; }
  body:is(.is-playing,.is-paused) .layout { margin-top: 6px; }
  .left-column { min-width: 0; }
}

/* In portrait the document scrolls vertically. The city strip owns its horizontal scroll. */
@media (orientation: portrait) {
  html, body { overflow-x: clip; overscroll-behavior-x: none; }
  .shell { max-inline-size: 100%; overflow-x: clip; }
}

/* A compact portrait counter keeps the pantry below the scene and within thumb reach. */
@media (max-width: 740px) and (orientation: portrait) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "scene" "dock" "ticket" "pantry";
    gap: 8px;
  }
  .left-column { display: contents; }
  .screen-frame { grid-area: scene; }
  .order-stations { grid-area: dock; }
  .pantry-box { grid-area: pantry; }
  .rail { grid-area: ticket; }
  .heading { padding-block: 9px; }
  #stall-route { display: flex; flex-wrap: nowrap; align-items: stretch; min-width: 0; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; gap: 5px; padding: 3px 2px 5px; margin: 0 0 5px; }
  .stall-stop { position: relative; flex: none; white-space: nowrap; }
  .screen-top { min-height: 25px; padding: 4px 7px; font-size: 10px; letter-spacing: .4px; }
  .screen-top .service b { font-size: 9px; }
  .screen-top .state { font-size: 9px; }
  .screen-bottom { min-height: 26px; padding: 4px 7px; font-size: 11px; }
  .guest-total { font-size: 10px; }
  .screen-top > span { gap: 4px; }
  .prep-photo { width: clamp(32px, 9vw, 45px); height: clamp(29px, 8vw, 36px); }
  body:is(.is-playing,.is-paused) .layout {
    grid-template-areas: "scene" "dock" "pantry" "actions";
    gap: 6px;
  }
}

/* On a portrait tablet the stage uses the full upper half, with the pantry and ticket side by side below it. */
@media (min-width: 741px) and (max-width: 1100px) and (orientation: portrait) {
  .shell { padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); }
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(240px, 1fr);
    grid-template-areas: "scene scene" "dock dock" "pantry ticket";
    gap: 10px 14px;
  }
  .left-column { display: contents; }
  .screen-frame { grid-area: scene; }
  .order-stations { grid-area: dock; }
  .pantry-box { grid-area: pantry; }
  .rail { grid-area: ticket; }
  .screen-top,.screen-bottom { min-height: 32px; }
  .prep-ticket { min-height: 56px; }
  .prep-details, .prep-ticket .prep-status { font-size: 13px; }
  .prep-details b { font-size: 14px; }
  .paper { padding: 16px; }
}

/* A phone held sideways has room for the pantry beside the street, even when its height is short. */
@media (max-width: 1100px) and (max-height: 550px) and (orientation: landscape) {
  .shell { padding-block: max(3px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-bottom)); }
  .mast { padding-bottom: 1px; min-height: 44px; }
  .layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0,1fr); align-items: start; gap: 7px; }
  .left-column, .rail { width: auto; }
  .left-column { display: grid; gap: 6px; }
  .heading { padding-block: 6px; }
  #stall-route { margin: 0 0 6px; gap: 4px; }
  .screen-top { min-height: 22px; padding: 3px 6px; font-size: 9px; letter-spacing: .4px; }
  .screen-top > span { gap: 4px; }
  .screen-top .service b { font-size: 8px; }
  .screen-bottom { min-height: 24px; padding: 3px 6px; font-size: 10px; }
  body:is(.is-playing,.is-paused) .layout {
    grid-template-columns: minmax(0, min(58%,calc(150vh - 164px))) minmax(0,1fr);
    grid-template-columns: minmax(0, min(58%,calc(150svh - 164px))) minmax(0,1fr);
    grid-template-areas: "scene dock" "scene pantry" "scene actions";
    grid-template-rows: auto auto minmax(0,1fr);
    margin-top: 4px;
    align-items: start;
    gap: 5px 8px;
  }
  body:is(.is-playing,.is-paused) .left-column { display: contents; }
  body:is(.is-playing,.is-paused) .screen-frame { grid-area: scene; }
  body:is(.is-playing,.is-paused) .order-stations { grid-area: dock; }
  body:is(.is-playing,.is-paused) .pantry-box { grid-area: pantry; }
  .prep-photo { width: 32px; height: 30px; }
  .prep-ticket { min-height: 44px; padding: 3px 5px; }
  .prep-details, .prep-ticket .prep-status { font-size: 10.5px; }
  .prep-details b { font-size: 11.5px; }
  .pantry-box { padding: 5px; }
  .pantry-title h2 { font-size: 16px; }
  .pantry-title > span { font-size: 10px; }
}

/* The command stays on the counter; the expanded ticket overlays it without moving the food. */
@media (max-width: 740px) and (orientation: portrait), (max-width: 1100px) and (max-height: 550px) and (orientation: landscape) {
  body:is(.is-playing,.is-paused) .rail { display: contents; }
  body:is(.is-playing,.is-paused) .rail > .paper { display: none; }
  body:is(.is-playing,.is-paused) .rail-controls { grid-area: actions; align-self: start; min-width: 0; gap: 4px; }
  body:is(.is-playing,.is-paused) .rail-controls .rail-note { display: none; }
  body.is-playing #mobile-ticket { display: inline-flex; }
  body.is-playing.touch-ticket-open { overflow: hidden; }
  body.is-playing.touch-ticket-open #mobile-ticket-backdrop { display: block; position: fixed; inset: 0; z-index: 41; background: #071613ae; }
  body.is-playing.touch-ticket-open #rail {
    position: fixed; z-index: 42; display: flex; flex-direction: column;
    grid-area: auto; gap: 8px; width: min(100%, 520px);
    bottom: 0; left: 50%; transform: translateX(-50%); max-height: 90vh; max-height: 90svh;
    padding: 12px max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
    background: #1c342a; border: 1px solid #6f8366; border-bottom: 0; border-radius: 8px 8px 0 0; box-shadow: 0 -4px 18px #081a1480;
    overflow-y: auto; overscroll-behavior: contain;
  }
  body.is-playing.touch-ticket-open #rail > .paper { display: block; }
  body.is-playing.touch-ticket-open #mobile-ticket-close { display: inline-flex; align-self: flex-end; min-height: 44px; }
  .order-tags { flex-wrap: wrap; }
}
@media (max-width: 389px) and (orientation: portrait) {
  .brand { gap: 4px; max-width: 100px; }
  .brand span:nth-child(2) { font-size: 9px; }
  .top-button { padding-inline: 6px; gap: 4px; }
  .pantry-box { padding: 5px; }
  .pips { gap: 1px; }
}
@media (min-width: 741px) and (min-height: 551px) and (orientation: landscape) and (pointer: coarse) and (max-width: 1440px),
       (min-width: 741px) and (max-width: 1100px) and (min-height: 551px) and (orientation: landscape) {
  .layout { grid-template-columns: minmax(0, 2.1fr) minmax(250px, 1fr); gap: 14px; }
  .left-column { display: grid; gap: 8px; }
  .prep-ticket { min-height: 54px; }
}
#offline-city, #offline-remove {align-self:start;justify-self:start}
#offline-note {font:13px/1.4 var(--mono);color:var(--cream)}
body:not(.is-recipe):not(.is-title) :is(#offline-city,#offline-remove,#offline-note) {display:none}
