/* Phone landscape is a short working surface, not the portrait tablet layout.
   Loaded after page styles. Scene paintings keep their original aspect ratio. */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --phone-left: max(8px, env(safe-area-inset-left, 0px));
    --phone-right: max(8px, env(safe-area-inset-right, 0px));
    --phone-bottom: env(safe-area-inset-bottom, 0px);
    --phone-height: calc(100dvh - env(safe-area-inset-top, 0px) - var(--phone-bottom));
  }
  html { scroll-padding: 60px var(--phone-right) 20px var(--phone-left); }
  input, select, textarea { font-size: 16px !important; }
  button, a, summary { touch-action: manipulation; }
  dialog:not(.peblet-landscape-guard) {
    max-width: calc(100vw - var(--phone-left) - var(--phone-right)) !important;
    max-height: calc(var(--phone-height) - 16px) !important;
    overflow-y: auto; overscroll-behavior: contain;
    padding: 16px 22px;
  }
  dialog button, dialog a, .reward-actions a { min-height: 44px !important; }
  dialog h2 { font-size: 24px; }
  dialog.pet-mealtime-dialog { padding: 10px 16px; }
  .pet-mealtime-dialog .pet-mealtime-eyebrow { display: none; }
  .pet-mealtime-dialog h2 { margin: 2px 58px 6px 0; }
  .pet-mealtime-dialog p { font-size: 15px; line-height: 1.3; margin: 6px 0; }
  .pet-mealtime-pictures { position: absolute; top: 10px; right: 14px; max-width: 54px; margin: 0; }
  .pet-mealtime-pictures img { width: 48px; height: 42px; max-width: 100%; }
  .pet-mealtime-accounts { gap: 8px; margin-top: 6px; }
  .pet-mealtime-dialog button { padding: 8px; }
  .pet-mealtime-dialog button span { margin-top: 3px; }
  .pet-mealtime-dialog .pet-mealtime-tip { margin: 8px 0 0; padding: 6px 10px; }
  .dialog-actions, .reward-actions { gap: 8px; }
  .peblet-audio-control { transform: scale(.8); transform-origin: bottom left; }
  .topbar, .game-header, .job-header, .home-header, .account-header {
    height: 52px !important; min-height: 52px !important;
    padding: 4px var(--phone-right) 4px var(--phone-left) !important;
    gap: 8px !important; flex-wrap: nowrap !important;
  }
  .brand img { width: 126px !important; }
  .game-header .back, .job-header > a, .home-header a, .account-header a,
  .topbar-actions a { min-height: 44px !important; padding: 6px 10px; font-size: 14px; }
  .topbar-actions { gap: 6px; min-width: 0; }
  .player-pill { padding: 5px 10px; min-height: 44px; }
  .player-pill > small, .player-pill > i, .bank-brand small, .job-brand small { display: none; }
  .bank-brand, .job-brand { gap: 7px; }
  .bank-brand strong, .job-brand strong { font-size: 18px; }
  .bank-brand > span, .job-brand > span { width: 34px; height: 34px; }
  .score { padding: 5px 9px; }
  .score strong { font-size: 19px; }

  /* The village and all painted maps fit between the safe edges. */
  .game-shell { height: var(--phone-height); padding-top: env(safe-area-inset-top, 0px); }
  .village { height: calc(var(--phone-height) - 52px) !important; }
  .village-scene {
    width: min(calc(100% - var(--phone-left) - var(--phone-right)), calc((var(--phone-height) - 52px) * 1.78533475)) !important;
    height: auto !important; min-width: 0 !important; aspect-ratio: 1680 / 941;
  }
  .place-hotspot, .place-hotspot.bank, .place-hotspot.cafe, .place-hotspot.post, .place-hotspot.home-building { min-height: 44px; }
  .place-hotspot.bank { width: 25% !important; height: 37% !important; }
  .place-hotspot.cafe { width: 31% !important; height: 31% !important; }
  .place-hotspot.post { width: 25% !important; height: 32% !important; }
  .place-hotspot.home-building { width: 23% !important; height: 26% !important; }
  .sky-ferry-link { width: 14% !important; height: 27% !important; }
  .sky-scene, .farm-scene, .wind-scene, .weather-scene, .routes-scene,
  .cinder-scene, .cinder-job-scene {
    width: min(calc(100vw - var(--phone-left) - var(--phone-right)), calc(var(--phone-height) * 1.7777778)) !important;
    height: auto !important; max-width: none; aspect-ratio: 16 / 9 !important;
    left: 50%; top: 50%; transform: translate(-50%, -50%);
  }

  /* Bank: a complete counter, loose cash and bell without scrolling away. */
  .bank-game { height: 100dvh; min-height: 0; padding: env(safe-area-inset-top,0px) var(--phone-right) var(--phone-bottom) var(--phone-left); }
  .bank-floor { height: calc(var(--phone-height) - 52px) !important; min-height: 0 !important; }
  .bank-customer { top: 0 !important; right: 1% !important; bottom: 0 !important; width: 39% !important; height: 100% !important; }
  .bank-customer .bank-speech { top: 6px !important; left: 0 !important; width: 100% !important; max-height: 48%; overflow: auto; padding: 7px 10px !important; }
  .bank-customer .bank-speech p, .bank-customer .bank-speech > span { font-size: 14px !important; }
  .bank-speech strong { font-size: 27px !important; }
  .bank-speech .kid-prompt { font-size: 16px !important; margin-top: 4px; padding-top: 4px; }
  .bank-customer #customer { height: calc(var(--phone-height) * .37) !important; bottom: 2% !important; }
  .bank-teller { left: 4%; top: 17%; width: 19%; height: 39%; }
  .counter-cash { left: 23% !important; top: 24% !important; bottom: auto !important; width: 36% !important; height: 42% !important; min-height: 0 !important; }
  .counter-readout { top: 0; min-width: 155px; padding: 6px 8px; }
  .counter-money { top: 37% !important; overflow: auto !important; }
  .counter-readout strong { font-size: 20px; }
  .piece-meter { top: 38px; font-size: 14px; }
  .bank-cash-source { left: 2% !important; bottom: 12px !important; width: 73% !important; height: 27% !important; gap: 9px !important; align-items: center !important; }
  .bank-cash-source > button.bank-note { width: clamp(58px,8vw,88px) !important; height: 50px !important; min-height: 44px !important; transform: rotate(-3deg); }
  .bank-cash-source > button.bank-coin { width: 46px !important; height: 46px !important; min-height: 44px !important; }
  .bank-cash-source button span { font-size: 19px !important; }
  .bank-cash-source button small { font-size: 10px !important; }
  .drawer-tools { left: 3% !important; bottom: 34% !important; right: auto !important; }
  .drawer-tool { width: 44px !important; height: 44px !important; }
  .customer-handover { left: 64% !important; right: auto !important; bottom: 28% !important; width: 70px; height: 55px; }
  .customer-handover .counter-bell { width: 65px; height: 48px; }
  .bank-feedback { left: 22% !important; right: auto !important; bottom: 27% !important; width: 41% !important; font-size: 16px !important; max-height: 26%; overflow: auto; }

  /* Post: the request stays above a compact, three-route workbench. */
  .post-game, .cafe-game { min-height: 0; height: 100dvh; padding: env(safe-area-inset-top,0px) var(--phone-right) var(--phone-bottom) var(--phone-left); }
  .post-scene, .cafe-scene { height: calc(var(--phone-height) - 52px) !important; min-height: 0 !important; }
  .post-scene .scene-art { background-size: cover !important; }
  .post-request { left: 24% !important; top: 4px !important; right: auto !important; width: 51% !important; max-height: 43%; overflow: auto; padding: 8px 14px !important; clip-path: none; border-radius: 12px; transform: none; }
  .post-request > strong { font-size: 21px; }
  .post-request > span, .post-request b, .post-request > em { font-size: 14px; }
  .post-action { font-size: 16px !important; margin: 4px 0 0; padding-top: 4px; }
  .post-customer { left: 0 !important; top: auto !important; bottom: 12% !important; width: 22% !important; height: 52% !important; }
  .post-customer img { height: calc(var(--phone-height) * .43) !important; }
  .post-progress { top: 8px; left: 8px; padding: 7px; font-size: 14px; }
  .post-workbench { left: 24% !important; right: 2% !important; bottom: 4% !important; width: auto !important; height: 55% !important; }
  .post-workbench::before { inset: 9% 0 0; border-radius: 18px; }
  .parcel-shelf { left: 2% !important; top: 23% !important; width: 22% !important; height: 52% !important; }
  .parcel-prop { width: 80px; --stamp-x: 95px; }
  .parcel-prop > small { font-size: 10px; }
  .stamp-pad { left: 27% !important; top: 38% !important; width: 16% !important; height: 38% !important; }
  .post-stamp { top: -48% !important; width: 50px !important; min-height: 44px; }
  .delivery-yard { right: 0 !important; top: 0 !important; width: 54% !important; height: 100% !important; }
  .delivery-lane { min-height: 44px !important; padding: 3px 5px 3px 35% !important; }
  .delivery-lane .vehicle { left: 5% !important; font-size: 26px; }
  .delivery-lane strong { font-size: 16px !important; }
  .delivery-lane small { font-size: 14px !important; margin-top: 1px; }
  .delivery-lane em { font-size: 12px; }
  .post-feedback { left: 2%; right: auto !important; bottom: 0 !important; width: 22% !important; max-height: 40%; overflow: auto; font-size: 14px !important; }
  .post-scene[data-phase="reason"] .post-request { max-height: 92%; z-index: 20; }

  .cafe-scene { --counter-line: 68%; --art-height: 100%; }
  .cafe-scene .scene-art { inset: 0; height: 100%; background-size: cover; background-position: center; }
  .cafe-scene::before { inset: 68% 0 0; }
  .cafe-chalkboard { left: 69%; top: 5%; width: 29%; height: auto; min-height: 0; min-width: 0; padding: 6px; background: #183a32eb; border-radius: 12px; }
  .cafe-chalkboard h1 { font-size: 17px; margin: 3px 0; }
  .cafe-chalkboard #challenge-rule { display: block; font-size: 16px; }
  .cafe-chalkboard #challenge-kicker { font-size: 14px; }
  .cafe-chalkboard .budget-coins { display: none; }
  .chalk-math { margin-top: 5px; padding-top: 4px; font-size: 14px; gap: 16px; }
  .chalk-math strong { font-size: 19px; }
  .cafe-mobile-task { display: none !important; }
  .cafe-customer { left: 68%; top: auto; bottom: 25%; width: 29%; height: 33%; }
  .cafe-customer img { height: calc(var(--phone-height) * .34) !important; }
  .food-counter, .food-props { inset: 0 !important; height: 100% !important; }
  .food-prop { min-height: 44px !important; }
  .food-prop[data-item="roll"] { left: 0 !important; top: 29% !important; width: 12% !important; height: 20% !important; }
  .food-prop[data-item="cake"] { left: 10% !important; top: 37% !important; width: 12% !important; height: 20% !important; }
  .food-prop[data-item="tea"] { left: 23% !important; top: 34% !important; width: 12% !important; height: 20% !important; }
  .food-prop[data-item="muffin"] { left: 37% !important; top: 29% !important; width: 12% !important; height: 20% !important; }
  .food-prop[data-item="soup"] { left: 52% !important; top: 29% !important; width: 12% !important; height: 20% !important; }
  .food-prop strong, #menu-grid > button strong { bottom: -10px !important; left: 50% !important; font-size: 14px; }
  .food-prop > .food-picture { display: block !important; opacity: 1; width: 100%; height: 100%; object-fit: contain; }
  .serving-tray { left: 4% !important; top: auto !important; bottom: 16px !important; width: 32% !important; min-width: 0 !important; height: 70px !important; padding: 8px 12px; }
  .serving-tray .tray-food { width: 60px; height: 54px; }
  .cafe-register { left: auto !important; right: 4% !important; top: auto !important; bottom: 0 !important; width: 135px !important; height: 135px; }
  .cafe-register .till-display strong { font-size: 23px; }
  .cafe-play-counter .counter-bell { left: 40% !important; top: auto !important; bottom: 16px !important; width: 64px; height: 58px; }
  .customer-payment-zone { left: 56% !important; right: auto !important; bottom: 26% !important; top: auto !important; }
  .change-saucer { left: 48% !important; right: auto !important; bottom: 3% !important; top: auto !important; width: 27%; min-width: 0; height: 76px; }
  .cafe-register .cash-drawer { left: auto; right: 0; bottom: 4px; width: 300px; }
  /* Change has its own counter space; the saucer must never cover the money. */
  .cafe-scene[data-phase="change"] .serving-tray,
  .cafe-scene[data-phase="change"] .counter-bell { visibility: hidden; pointer-events: none; }
  .cafe-scene[data-phase="change"] .change-saucer {
    left: 4% !important; width: 30% !important; bottom: 8px !important;
    top: auto !important; height: 76px; z-index: 20;
  }
  .cafe-scene[data-phase="change"] .cafe-register { z-index: 21; }
  .cafe-scene[data-phase="change"] .cash-drawer {
    top: auto !important; bottom: 4px !important; left: auto !important; right: 0 !important;
    width: min(360px,52vw); max-width: none; transform: none;
  }
  .cash-option { min-width: 44px; min-height: 44px; }
  .cafe-feedback { top: auto !important; left: 18% !important; right: auto !important; bottom: 29% !important; width: 48% !important; max-height: 30%; overflow: auto; font-size: 16px; }
  .part-rack, .part-rack:has(.wind-part:nth-child(4)) { top: auto !important; bottom: 5%; left: 5% !important; width: 58% !important; height: 20% !important; }
  .wind-part { min-height: 48px; }
  .wind-part small { left: 5%; top: 10%; width: 53%; }
  .wind-part small b { font-size: 20px; }
  .wind-part small span { font-size: 12px; line-height: 1.05; }
  .wind-part strong { right: 5%; top: 23%; font-size: 22px; }

  /* Forest tools use their own scroll area; the picture and Finish stay put. */
  .forest-job .forest-top { padding: 4px 8px !important; flex-wrap: nowrap !important; }
  .forest-job-title { order: 0 !important; width: auto !important; }
  .forest-job-title h1 { font-size: 18px; }
  .forest-job .job-order { width: calc(100% - 16px); padding: 4px 8px; margin-bottom: 4px; gap: 8px; flex-wrap: nowrap !important; max-height: 25dvh; }
  .forest-job .job-order > img { width: 34px; height: 40px; }
  .forest-job .job-order h2 { font-size: 16px; line-height: 1.2; }
  .forest-job #customer-name { font-size: 14px; margin: 0 0 3px; }
  .forest-job .job-order .shift-counter { width: auto; min-width: 110px; font-size: 14px; display: block; }
  .shift-counter strong { font-size: 14px; }
  .forest-job .job-surface { width: calc(100% - 16px); }
  .forest-job .job-footer { width: calc(100% - 16px); padding: 4px 8px; margin-top: 4px; }
  .forest-job .job-footer p { font-size: 14px; max-height: 2.5em; margin: 0; }
  .job-footer #job-submit { min-height: 44px; font-size: 16px; padding: 7px 14px; }
  .forest-job .canopy-surface { display: grid !important; grid-template-columns: minmax(190px,34%) minmax(0,1fr); gap: 8px; overflow: hidden !important; }
  .canopy-surface .build-tools { order: 0; overflow: auto !important; padding: 8px; }
  .canopy-surface .build-board { order: 0 !important; height: 100% !important; min-height: 0 !important; }
  .build-board .build-toolbar { padding: 3px 6px; }
  .build-board .build-view-label { font-size: 14px; }
  .tower-viewport { overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .build-board .tower-viewport #tower-grid { display: block; min-width: 410px; min-height: 224px; height: 100%; touch-action: pan-x pan-y; }
  .dig-grid { grid-template-columns: repeat(6,44px); width: max-content; }
  .dig-panel { overflow: auto; }
  .material { font-size: 14px; min-height: 58px; padding: 5px; }
  .forest-job .timber-surface { padding: 8px 12px; }
  .timber-surface .measuring-area { height: 105px; }
  .timber-surface .measure-caption, .timber-surface .measure-pay { margin: 4px 0; font-size: 16px; }
  .measure-buttons { gap: 5px; flex-wrap: wrap; }
  .measure-buttons button { min-width: 44px; min-height: 44px; padding: 6px; }
  .search-tools { padding: 3px 6px; }
  .search-tools button { min-height: 44px; }

  .home-world { height: 100dvh !important; min-height: 0 !important; overflow: hidden; }
  .home-header { grid-template-columns: auto 1fr auto; }
  .home-title { justify-self: center; }
  .home-title small { display: none; }
  .home-title strong { font-size: 17px; }
  .home-money { gap: 6px; }
  .room { top: 52px !important; right: 43% !important; bottom: var(--phone-bottom) !important; left: var(--phone-left) !important; height: auto !important; min-height: 0; }
  .wardrobe { left: auto !important; right: var(--phone-right) !important; top: 56px !important; bottom: max(6px,var(--phone-bottom)) !important; width: calc(43% - var(--phone-right) - 6px) !important; height: auto !important; min-height: 0 !important; padding: 8px !important; border-radius: 16px; }
  .wardrobe-heading { gap: 4px; }
  .wardrobe-heading h1 { font-size: 18px !important; }
  .wardrobe-heading button { font-size: 12px !important; min-height: 44px; padding: 4px; }
  .wardrobe .tabs { gap: 3px; margin: 4px 0; }
  .wardrobe .tab { font-size: 14px; min-height: 44px; padding: 4px; }
  .wardrobe .options { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); grid-template-rows: none; grid-auto-flow: row; grid-auto-columns: auto; overflow: auto; padding: 6px 2px; gap: 5px; }
  .wardrobe .option { min-height: 76px; font-size: 14px; padding: 4px; }
  .wardrobe .option img { height: 46px; }
  .wardrobe-footer { padding-top: 5px; gap: 5px; }
  .wardrobe-footer button { min-height: 44px; font-size: 14px; padding: 5px; }
  .room-copy { top: 4px; padding: 3px; font-size: 14px; }
  .room-copy input { min-height: 44px; max-width: 165px; }
  .pet-house-hub .pet-house-menu { position: fixed; left: var(--phone-left); top: 56px; right: auto; bottom: auto; width: calc(57vw - var(--phone-left) - 8px); max-height: calc(100dvh - 64px - var(--phone-bottom)); overflow: auto; padding: 9px; }
  .pet-house-hub .pet-house-menu::after { display: none; }
  .house-header { height: 52px; padding: 4px var(--phone-right) 4px var(--phone-left); gap: 8px; }
  .house-title img, .house-title small { display: none; }
  .house-title strong { font-size: 17px; }
  .house-stage { height: calc(var(--phone-height) - 52px); padding: 4px var(--phone-right) var(--phone-bottom) var(--phone-left); }
  .house-scene { width: min(100%,calc((var(--phone-height) - 64px) * 1.7768)); }
  .furniture-drawer { top: 56px !important; bottom: max(8px,var(--phone-bottom)) !important; max-height: calc(var(--phone-height) - 64px); overflow: auto; }
  .grotto-wallet { right: var(--phone-right); top: 8px; min-height: 44px; }
  .grotto-wallet span { min-width: 76px; padding: 4px 8px; }
  .grotto-actions { bottom: max(8px,var(--phone-bottom)); max-width: calc(100vw - var(--phone-left) - var(--phone-right)); gap: 5px; }
  .grotto-actions button { min-width: 44px; min-height: 44px; padding: 5px 8px; }
  .account-shell { padding-left: var(--phone-left); padding-right: var(--phone-right); }
  .account-hero { margin-top: 12px; padding: 20px; }
  .account-hero h1 { font-size: 30px; }
  .festival-workbench { top: 27%; bottom: 3%; max-height: 70%; width: 88%; padding: 12px; }
  .festival-workbench h2 { font-size: 23px; margin: 4px 0 8px; }
  .festival-workbench p { font-size: 16px; margin: 8px 0; }
  .festival-primary { min-height: 44px; }
  .money-practice { height: 100dvh; min-height: 0; padding-bottom: var(--phone-bottom); }
  .practice-header { min-height: 52px; height: 52px; padding: 4px var(--phone-right) 4px var(--phone-left); }
  .practice-header > a { min-height: 44px; font-size: 14px; }
  .practice-header strong { font-size: 20px; }
  .practice-scene { height: calc(var(--phone-height) - 52px) !important; min-height: 0 !important; }
  .practice-customer { left: var(--phone-left); top: 8px; bottom: 0; width: 24%; height: auto; }
  .practice-customer img { height: 48%; }
  .practice-speech { left: 0; top: 0; width: 100%; padding: 8px; }
  .practice-speech strong { font-size: 26px; }
  .practice-speech p, .practice-speech small { font-size: 14px; }
  .practice-counter { left: 27%; right: var(--phone-right); top: 8px; bottom: 8px; width: auto !important; height: auto !important; min-height: 0; border-width: 4px; border-radius: 18px; }
  .practice-drawer { top: 4%; bottom: 4%; left: 2%; width: 48%; padding: 5px; gap: 5px; overflow: auto; border-width: 3px; }
  .practice-coins { grid-template-columns: repeat(3,minmax(44px,1fr)); }
  .practice-notes { grid-template-columns: repeat(2,minmax(60px,1fr)); }
  .practice-drawer .cash-piece { min-width: 44px; min-height: 44px; }
  .practice-drawer .cash-piece.coin { width: 44px; height: 44px; --coin-size: 40px; font-size: 14px; }
  .practice-drawer .cash-piece.note { width: 66px; height: 44px; }
  .practice-total { left: 52%; top: 4%; padding: 5px; gap: 4px; }
  .practice-total strong, .practice-total b { font-size: 19px; }
  .practice-placed { left: 52%; right: 2%; top: 26%; bottom: 29%; width: auto; height: auto; min-height: 0; overflow: auto; }
  .practice-tools { left: 52%; right: 2%; bottom: 4%; gap: 6px; }
  .practice-tools button { min-width: 44px; min-height: 44px; }
  .practice-tools #practice-check { width: 56px; height: 50px; }
  .practice-feedback { left: 51%; width: 47%; bottom: 23%; font-size: 14px; max-height: 22%; overflow: auto; }

  /* Entry, names and purchases can scroll with the keyboard open. */
  .welcome-world { height: 100dvh; min-height: 0; padding: 60px var(--phone-right) 8px var(--phone-left); }
  .welcome-world > header { min-height: 52px; padding-block: 4px; }
  .welcome-card { max-height: 100% !important; padding: 16px; border-width: 3px; }
  .welcome-card h1 { font-size: 26px; }
  .peblet-choices { grid-template-columns: repeat(4,1fr); }
  .peblet-choice { min-height: 88px; }
  .peblet-choice img { height: 64px; }
  .year-choices { grid-template-columns: repeat(3,1fr); }
  .choice-grid small { font-size: 14px; }
  .peblet-landscape-guard__symbol { width: 220px; }
}
