/* Phones held sideways (iPhone: about 932 x 430, less with Safari's bars).
   Loaded last; applies only to short landscape screens, so the iPad and laptop layouts are untouched.
   The menus are sized in rem, so lowering the root size scales them; the puzzle is sized in px and
   gets its own compact layout below. */

@media (orientation: landscape) and (max-height: 540px) {
  html { font-size: clamp(11px, 2.75vh, 16px); }

  /* ---------- menus ---------- */
  .banner { height: calc(3rem + env(safe-area-inset-top, 0px)); margin-bottom: 0.4rem; }
  .banner .deco { transform: scale(0.6); transform-origin: top center; }
  .title { font-size: 2.8rem; }
  .title-small { font-size: 2rem; }
  .who-body { gap: 0.5rem; padding-bottom: 0.6rem; }
  .who-body { padding-top: 0.6rem; }
  .who-body .title { margin-top: 0.6rem; font-size: 2.4rem; }
  .who-card { width: 9.5rem; min-height: 8.5rem; padding: 0.6rem 0.4rem; }
  .home-body { gap: 1.2rem; padding-top: 0; padding-bottom: 0.4rem; }
  .home-hero { flex-basis: 26%; }
  .home-main { gap: 0.45rem; }
  .home-buttons { gap: 0.6rem; }
  .home-buttons #btn-adventure { min-height: 3.8rem; font-size: 1.8rem; }
  .btn-big { min-height: 3.4rem; }
  .home-body { overflow-y: auto; }
  .screen-scroll .sub-body { padding-top: 3.4rem; padding-bottom: 1.5rem; }

  /* the game keeps clear of the notch and the rounded corners */
  .game-stage { left: env(safe-area-inset-left, 0px); right: env(safe-area-inset-right, 0px); }

  /* ---------- puzzle: three tight areas side by side ---------- */
  .pz-root {
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) max(4px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    font-size: 16px;
  }
  .pz-card { height: 100%; gap: 4px; padding: 6px 12px 8px; border-radius: 22px; }
  .pz-head { padding-left: 52px; min-height: 34px; }
  .pz-badge { min-height: 30px; font-size: 14px; padding: 2px 12px 2px 6px; gap: 6px; }
  .pz-badge-icon { font-size: 18px; }
  .pz-main { grid-template-columns: minmax(0, 55fr) minmax(0, 45fr); gap: 12px; }
  .pz-left { gap: 4px; }
  .pz-right { gap: 6px; justify-content: flex-start; }

  .pz-story, .pz-story-long { font-size: 14px; line-height: 1.25; padding: 4px 10px; }
  .pz-sum { font-size: clamp(30px, 11vh, 50px); }
  .pz-sum.pz-prompt { font-size: clamp(18px, 5.5vh, 24px); }
  .pz-working { max-height: 26vh; font-size: 16px; padding: 2px 6px; }

  .pz-box { min-height: 0; height: clamp(40px, 11vh, 50px); font-size: clamp(26px, 8vh, 34px); padding: 2px 10px; box-shadow: 0 3px 0 var(--ink); }
  .pz-box.pz-small { font-size: 24px; }
  .pz-box.pz-xsmall { font-size: 18px; }
  .pz-box-wrap:not(.pz-box-wrap-rem) .pz-box-label { display: none; }   /* the box is obvious; room is short */
  .pz-box-wrap-rem .pz-box-label { font-size: 30px; padding-bottom: 4px; }
  .pz-feedback { min-height: 0; font-size: 14px; padding: 3px 10px; }
  .pz-feedback:empty { display: none; }

  /* keypad: two wide rows instead of four tall ones */
  .pz-keypad, .pz-keypad-point { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .pz-keypad-point { grid-template-columns: repeat(7, 1fr); }
  .pz-keypad-point .pz-key, .pz-keypad-point .pz-key-q { grid-column: auto; }
  .pz-key { min-height: clamp(40px, 11.5vh, 50px); font-size: clamp(22px, 6.5vh, 28px); box-shadow: 0 4px 0 var(--ink); border-width: 3px; }
  .pz-btn { font-size: 16px; box-shadow: 0 4px 0 var(--ink); }
  .pz-btn-check { min-height: clamp(42px, 11vh, 50px); font-size: 22px; }
  .pz-btn-hintmain, .pz-btn-padtoggle { min-height: clamp(40px, 10vh, 46px); padding: 2px 6px; }
  .pz-btn-skip { min-height: 38px; }
  .pz-btn-hint, .pz-btn-hint-all { min-height: 40px; font-size: 15px; }
  .pz-btn-small { min-height: 38px; }
  .pz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }   /* 2 x 2 keeps Hint on screen */
  .pz-choice { min-height: clamp(40px, 11vh, 50px); font-size: 20px; padding-top: 2px; padding-bottom: 2px; box-shadow: 0 4px 0 var(--ink); }

  /* hints: smaller written methods that fit the narrow card */
  .pz-hints { min-height: 60px; padding: 4px; gap: 4px; }
  .pz-nudge, .pz-step { font-size: 14px; }
  .pz-step { padding: 4px 6px; margin-top: 4px; }
  .pz-step-num { width: 24px; height: 24px; font-size: 13px; }
  .pz-root .wk-grid, .pz-root .wk-bus { --fs: clamp(15px, calc(300px / (var(--cols) * 0.9 + 2.2)), 24px); }
  .pz-root .wk-say, .pz-root .wk-chip { font-size: 14px; }
  .pz-root .wk-big { font-size: 24px; }
  .pz-root .wk-multiples { font-size: 13px; }
  .pz-left:has(.pz-step) .pz-sum { font-size: clamp(22px, 7vh, 30px); }
  .pz-left:has(.pz-step) .pz-box { height: 38px; }
  .pz-praise { font-size: 32px; padding: 2px 18px; }

  /* scratchpad tools */
  .pz-tool { min-height: 40px; min-width: 40px; font-size: 14px; padding: 2px 8px; }

  /* ---------- lessons ---------- */
  .ls-root { padding: 4px max(8px, env(safe-area-inset-right, 0px)) 4px max(8px, env(safe-area-inset-left, 0px)); }
}

/* Upright phones: the game plays sideways. */
@media (orientation: portrait) and (max-width: 1100px) {
  .rotate-inner h2 { font-size: 1.8rem; }
}
