/* Mobile catalogue lessons, including standalone lessons in the player iframe. */
@media (max-width: 900px), (max-height: 540px), (pointer: coarse) {
  :is(.cl-play[data-world="imitation"], .cl-play[data-world="grammar"], .cl-play[data-world="syllables"], body[data-mobile-lesson]) {
    --lesson-left: max(8px, env(safe-area-inset-left));
    --lesson-right: max(8px, env(safe-area-inset-right));
    --lesson-top: max(6px, env(safe-area-inset-top));
    --lesson-bottom: max(6px, env(safe-area-inset-bottom));
    --lesson-paper: #fff8e9f2;
    --lesson-ink: #243731;
    --lesson-hit: 44px;
  }

  .cl-play:is([data-world="imitation"], [data-world="grammar"], [data-world="syllables"]) :is(#cl-exit, #cl-settings, #cl-mute, #cl-hide),
  .cl-play:is([data-world="imitation"], [data-world="grammar"], [data-world="syllables"]) #cl-drawer :is(select, label, .cl-desk-tools button),
  body[data-mobile-lesson] :is(header button, nav button, footer button, .tool, .icon-button, dialog select) {
    min-width: var(--lesson-hit);
    min-height: var(--lesson-hit);
  }

  .cl-play:is([data-world="imitation"], [data-world="grammar"], [data-world="syllables"]) > #cl-drawer {
    width: min(310px, 87vw);
  }

  body[data-mobile-lesson] dialog {
    max-inline-size: calc(100vw - var(--lesson-left) - var(--lesson-right));
    max-block-size: 88dvh;
    overscroll-behavior: contain;
    overflow: auto;
  }

  body[data-mobile-lesson="42"] #tiles,
  body[data-mobile-lesson="115"] .gallery,
  body[data-mobile-lesson="315"] .tiles {
    grid-auto-rows: minmax(44px, 1fr);
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }

  body[data-mobile-lesson="115"] .gallery { grid-template-rows: none; }
  body[data-mobile-lesson="315"] .tile { min-height: 44px; }
  body[data-mobile-lesson="154"] .footer p { font-size: clamp(15px, 4.8vmin, 25px); }

  .cl-play[data-world-game="17"] #cl-stage .sail-board {
    padding-inline: 4px;
  }

  .cl-play[data-world-game="50"] #cl-stage :is(.mq-previous, .mq-next),
  .cl-play[data-world-game="39"] #cl-stage .city-replay,
  .cl-play[data-world-game="30"] #cl-stage .sb-replay {
    min-height: 44px;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  body[data-mobile-lesson="42"] #lesson,
  body[data-mobile-lesson="315"] #lesson {
    padding-inline: var(--lesson-left) var(--lesson-right);
  }

  body[data-mobile-lesson="42"] .art {
    min-height: min(38dvh, 83vw);
  }

  body[data-mobile-lesson="315"] .board .scene {
    min-height: 0;
  }

  body[data-mobile-lesson="315"] .tray .tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  body[data-mobile-lesson="21"] .screen .scene {
    max-inline-size: none;
    max-block-size: none;
    block-size: 100%;
  }

  body[data-mobile-lesson="21"] .scene .scenery {
    object-fit: cover;
  }

  body[data-mobile-lesson="25"] #market,
  body[data-mobile-lesson="296"] > main {
    width: 100%;
    height: min(69dvh, 150vw);
    aspect-ratio: auto;
  }

  body[data-mobile-lesson="330"] #lesson {
    width: 100%;
  }

  body[data-mobile-lesson="330"] .pond { min-height: min(60dvh, 127vw); }
  body[data-mobile-lesson="330"] .toolbar { padding-inline: var(--lesson-left) var(--lesson-right); }

  .cl-play[data-world="grammar"]:is([data-world-game="89"], [data-world-game="50"], [data-world-game="250"]) .cl-viewport,
  .cl-play[data-world="syllables"]:is([data-world-game="37"], [data-world-game="39"]) .cl-viewport {
    width: 100%;
    max-width: none;
  }

  .cl-play[data-world-game="50"] #cl-stage .mq-field {
    min-height: min(48dvh, 100vw);
  }

  .cl-play[data-world-game="89"] #cl-stage .owners-stage {
    min-height: min(44dvh, 100vw);
  }

  .cl-play[data-world-game="39"] #cl-stage .city-square {
    max-height: none;
    min-height: min(58dvh, 124vw);
  }
}

@media (orientation: landscape) and (max-height: 540px),
       (orientation: landscape) and (pointer: coarse) {
  body[data-mobile-lesson] {
    margin: 0;
    padding: 0;
    min-height: 100dvh;
  }

  body:is([data-mobile-lesson="42"], [data-mobile-lesson="115"], [data-mobile-lesson="315"], [data-mobile-lesson="34"], [data-mobile-lesson="112"], [data-mobile-lesson="154"], [data-mobile-lesson="21"]) :is(#lesson,.screen) {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: 0;
    gap: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
  }

  body:is([data-mobile-lesson="42"], [data-mobile-lesson="115"], [data-mobile-lesson="315"]) :is(.content, .field, .board) {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(192px, 28%);
    gap: 0;
    padding: 0;
  }

  body:is([data-mobile-lesson="42"], [data-mobile-lesson="115"], [data-mobile-lesson="315"]) :is(.stage, .gallery, .picker, .tray) {
    min-height: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body[data-mobile-lesson="42"] .art canvas { object-fit: cover; }
  body[data-mobile-lesson="42"] :is(.caption, footer, .picker),
  body[data-mobile-lesson="315"] :is(.top, .tray, .instruction-bar) {
    padding: 4px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left));
  }
  body[data-mobile-lesson="42"] .picker { gap: 4px; }
  body[data-mobile-lesson="42"] #tiles { grid-template-columns: repeat(4,minmax(0,1fr)); }
  body[data-mobile-lesson="42"] .tile { padding: 2%; }

  body[data-mobile-lesson="115"] .screen > header { padding: var(--lesson-top) var(--lesson-right) 3px var(--lesson-left); }
  body[data-mobile-lesson="115"] .instruction { border-radius: 0; height: 44px; font-size: clamp(15px,4.9dvh,25px); }
  body[data-mobile-lesson="115"] .gallery { gap: 3px; padding: 4px; }

  body[data-mobile-lesson="158"] nav {
    padding-inline: var(--lesson-left) var(--lesson-right);
    padding-top: var(--lesson-top);
  }

  body[data-mobile-lesson="296"] {
    --board-width: 100vw;
    --board-height: 100dvh;
  }

  body[data-mobile-lesson="296"] > main,
  body[data-mobile-lesson="25"] #market {
    width: 100%;
    height: 100dvh;
    aspect-ratio: auto;
  }

  body[data-mobile-lesson="315"] #lesson {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }
  body[data-mobile-lesson="315"] .board .scene { min-height: 0; gap: 0; }
  body[data-mobile-lesson="315"] .stage { aspect-ratio: auto; }
  body[data-mobile-lesson="315"] .tray { gap: 4px; }
  body[data-mobile-lesson="315"] .tiles { gap: 3px; }

  body[data-mobile-lesson="34"] #lesson {
    display: grid;
    grid-template-rows: auto minmax(0,1fr) auto;
  }
  body[data-mobile-lesson="34"] #field { width: 100%; height: 100%; aspect-ratio: auto; }
  body[data-mobile-lesson="34"] :is(.toolbar, .instructions) {
    min-height: 44px;
    padding: 3px var(--lesson-right) 3px var(--lesson-left);
  }

  body[data-mobile-lesson="112"] .toolbar,
  body[data-mobile-lesson="154"] .bar,
  body[data-mobile-lesson="21"] .toolbar {
    padding: 3px var(--lesson-right) 3px var(--lesson-left);
  }
  body[data-mobile-lesson="112"] .instructions,
  body[data-mobile-lesson="154"] .footer { min-height: 44px; padding-block: 3px; }

  body[data-mobile-lesson="330"] #lesson {
    box-sizing: border-box;
    display: grid;
    width: 100%;
    height: 100dvh;
    grid-template-rows: minmax(0, 1fr) auto;
    box-shadow: none;
  }
  body[data-mobile-lesson="330"] .pond { aspect-ratio: auto; height: 100%; }
  body[data-mobile-lesson="330"] .instructions { min-height: 46px; }
  body[data-mobile-lesson="21"] .screen .scene { max-inline-size: none; }
  body[data-mobile-lesson="21"] .screen > footer { padding-block: 3px; }

  .cl-play:is([data-world-game="89"], [data-world-game="50"], [data-world-game="250"], [data-world-game="37"], [data-world-game="39"]) .cl-viewport {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: 0;
    border-radius: 0;
  }

  .cl-play[data-world-game="250"] { --apiary-stage: 100vw; }
  .cl-play[data-world-game="250"] #cl-stage .apiary { width: 100%; height: 100dvh; aspect-ratio: auto; }

  .cl-play:is([data-world-game="89"], [data-world-game="50"], [data-world-game="37"], [data-world-game="39"]) #cl-stage {
    min-height: 0;
    padding: 0;
    margin: 0;
  }

  .cl-play[data-world-game="89"] #cl-stage .owners-stage,
  .cl-play[data-world-game="50"] #cl-stage .mq-field,
  .cl-play[data-world-game="39"] #cl-stage .city-square {
    width: 100%;
    height: clamp(134px, calc(100dvh - 110px), 100dvh);
    max-height: none;
    aspect-ratio: auto;
  }

  .cl-play[data-world-game="89"] #cl-stage .owners-lesson,
  .cl-play[data-world-game="50"] #cl-stage .mountain-queue {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .cl-play[data-world-game="89"] .cl-viewport .cl-head { margin: 0; }
  .cl-play[data-world-game="89"] #cl-stage .owners-footer { padding-block: 4px; }
  .cl-play[data-world-game="89"] .cl-viewport {
    display: grid;
    grid-template-rows: auto minmax(0,1fr);
  }

  .cl-play[data-world-game="89"] #cl-stage .owners-lesson,
  .cl-play[data-world-game="50"] #cl-stage .mountain-queue {
    display: grid;
    height: 100%;
  }

  .cl-play[data-world-game="89"] #cl-stage .owners-lesson { grid-template-rows: minmax(0,1fr) auto; }
  .cl-play[data-world-game="50"] #cl-stage .mountain-queue {
    height: 100dvh;
    grid-template-rows: auto minmax(0,1fr) auto;
  }

  .cl-play[data-world-game="89"] #cl-stage .owners-stage,
  .cl-play[data-world-game="50"] #cl-stage .mq-field {
    height: 100%;
    min-height: 0;
  }

  .cl-play[data-world-game="50"] #cl-stage .mq-top,
  .cl-play[data-world-game="50"] #cl-stage .mq-footer { padding-block: 4px; }

  .cl-play.tatti-player[data-world-game="37"] .cl-viewport,
  .cl-play.city-player[data-world-game="39"] .cl-viewport { grid-template-rows: auto minmax(0, 1fr); }

  .cl-play.tatti-player[data-world-game="37"] .cl-viewport .cl-head,
  .cl-play.city-player[data-world-game="39"] .cl-viewport .cl-head {
    min-height: 44px;
    padding-block: 2px;
  }

  .cl-play[data-world-game="37"] #cl-stage .tatti-scene {
    height: 100%;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .cl-play[data-world-game="37"] #cl-stage .tatti-instruction,
  .cl-play[data-world-game="39"] #cl-stage .city-footer {
    min-height: 44px;
    padding-block: 4px;
  }

  .cl-play[data-world-game="39"] #cl-stage .city-scene {
    box-sizing: border-box;
    display: grid;
    height: 100%;
    grid-template-rows: minmax(0,1fr) auto;
    border: 0;
  }
  .cl-play[data-world-game="39"] #cl-stage .city-square { min-height: 0; height: 100%; }

  .cl-play[data-world-game="46"]:has(.hh-scene) .cl-viewport .cl-head { min-height: 44px; padding-block: 3px; }
  .cl-play[data-world-game="46"] #cl-stage .hh-scene { min-height: 0; border-radius: 0; }
  .cl-play[data-world-game="17"] #cl-stage .sail-scene { border-radius: 0; }
  .cl-play[data-world-game="30"] #cl-stage .sb-game { grid-template-rows: minmax(0, 1fr) 48px; }

  .cl-play[data-world-game="197"] .cl-viewport {
    box-sizing: border-box;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
    min-height: 0;
    padding: 5px 12px;
  }
  .cl-play[data-world-game="197"] .cl-head { margin-bottom: 0; }
  .cl-play[data-world-game="197"] #cl-stage .sv-stage {
    box-sizing: border-box;
    display: grid;
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 4px;
    padding: 0;
  }
  .cl-play[data-world-game="197"] #cl-stage .sv-stage .ag-board { min-height: 0; }

  body[data-mobile-lesson="2"] .mast { min-height: 46px; }
  body[data-mobile-lesson="2"] #app {
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 4px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  body[data-mobile-lesson="2"] .script {
    min-height: 0;
    padding: 5px 12px;
  }
  body[data-mobile-lesson="2"] .cue h2 { font-size: 17px; }
  body[data-mobile-lesson="2"] .cue p { font-size: 14px; margin-top: 2px; line-height: 1.18; }
}
