/* Speech-sound exercises on phones and tablets. Individual scenes keep their
   original geometry on wider desktops. */
@media (max-width: 820px), (max-height: 520px), (pointer: coarse) {
  .cl-play[data-world="phonemes"] {
    --phonemes-hit: 44px;
    --phonemes-side: max(8px, env(safe-area-inset-right));
  }

  .cl-play[data-world="phonemes"] :is(#cl-exit, #cl-mute, #cl-settings, #cl-skip, #cl-hide),
  .cl-play[data-world="phonemes"] #cl-stage .bs-head :is(#cl-exit, #cl-mute, #cl-settings),
  .cl-play[data-world="phonemes"] #cl-stage :is(.eh-pause, .qb-pause, .bs-hear, .bs-listen, .bs-action, .bs-hint, .qb-listen, .sp-listen, .flock-listen),
  .cl-play[data-world="phonemes"] #cl-drawer :is(.cl-options label, select, .cl-desk-tools button) {
    min-width: var(--phonemes-hit);
    min-height: var(--phonemes-hit);
  }

  .cl-play[data-world="phonemes"] > #cl-drawer {
    width: min(300px, 87vw);
  }

  .cl-play[data-world="phonemes"] .cl-drawer-body {
    box-sizing: border-box;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .cl-play[data-world="phonemes"]:has(> #cl-drawer:not([hidden])) #cl-stage {
    right: 0;
  }

  .cl-play[data-world="phonemes"] :is(.bs-head, .qb-head, .bs-foot, .qb-foot) {
    padding-inline: max(6px, env(safe-area-inset-left)) var(--phonemes-side);
  }

  .cl-play[data-world="phonemes"] #cl-stage .eh-row {
    gap: max(4px, 1.2cqw);
  }

  .cl-play[data-world="phonemes"] #cl-stage .eh-stage .eh-bead {
    width: max(44px, 5cqw);
    height: max(44px, 7cqh);
  }

  .cl-play[data-world="phonemes"] #cl-stage .eh-bead img.ag-cast-image {
    width: min(94%, 48px);
    height: min(80%, 34px);
  }

  .cl-play[data-world="phonemes"] #cl-stage .kitten-stage .kt-coin {
    width: clamp(44px, 10.6dvh, 90%);
  }

  .cl-play[data-world="phonemes"] #cl-stage .sound-place .ag-status:not(:empty) {
    bottom: max(57px, calc(env(safe-area-inset-bottom) + 50px));
    left: max(8px, env(safe-area-inset-left));
    max-width: calc(100% - 16px);
    box-sizing: border-box;
  }

  .cl-play[data-world="phonemes"] #cl-stage .sound-place .ag-controls {
    bottom: max(6px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  .cl-play[data-world="phonemes"] #cl-stage .d3-stage .d3-board,
  .cl-play[data-world="phonemes"] #cl-stage > .kitten-stage > .ag-board {
    background-size: cover;
  }

  .cl-play[data-world="phonemes"] #cl-stage .d3-dragon {
    left: 2%;
    bottom: 41%;
    width: 31%;
    height: 27%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .d3-cloud {
    left: 32%;
    top: 19%;
    width: 43%;
    height: 23%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .d3-chests {
    left: 12%;
    right: 12%;
    bottom: 16%;
    height: auto;
    grid-auto-flow: row;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .cl-play[data-world="phonemes"] #cl-stage .d3-chest {
    height: auto;
    aspect-ratio: 1.06;
    min-height: 44px;
  }

  .cl-play[data-world="phonemes"] #cl-stage .d3-chest .d3-letter {
    font-size: clamp(16px, 4vw, 32px);
  }

  .cl-play[data-world="phonemes"] #cl-stage .kitten-stage .kt-coins {
    left: 4%;
    right: 4%;
    top: 12%;
    height: 28%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .kitten-stage .kt-coin {
    width: min(92%, 68px);
  }

  .cl-play[data-world="phonemes"] #cl-stage .kitten-stage .kt-yard {
    top: 40%;
    bottom: 34%;
  }

  .cl-play[data-world="phonemes"] #cl-stage > .sound-place {
    overflow: hidden;
    background: #58bfc3;
  }

  .cl-play[data-world="phonemes"] #cl-stage > .sound-place::before {
    content: "";
    position: absolute;
    inset: -22px;
    background: linear-gradient(#effbe160, #0b645d55), url("games/sound-place/pool.webp") center / cover;
    filter: blur(18px);
    pointer-events: none;
  }

  .cl-play[data-world="phonemes"] #cl-stage .sound-place .sp-pool {
    position: absolute;
    top: 47%;
    left: 0;
    height: auto;
    aspect-ratio: 3 / 2;
    transform: translateY(-50%);
    box-shadow: 0 12px 32px #135e6450;
  }

  .cl-play[data-world="phonemes"] #cl-stage .sp-sign {
    min-height: 44px;
  }

  .cl-play[data-world="phonemes"] #cl-stage .sound-place .ag-controls {
    top: calc(47% + 100vw / 3 + 24px);
    bottom: auto;
  }

  .cl-play[data-world="phonemes"] #cl-stage .sound-place .ag-status:not(:empty) {
    top: calc(47% + 100vw / 3 + 78px);
    bottom: auto;
  }

  .cl-play[data-world="phonemes"] #cl-stage .eh-stage .eh-tray {
    width: min(94%, 510px);
    height: max(150px, 34%);
    padding-inline: 3cqw;
  }

  .cl-play[data-world="phonemes"] #cl-stage .bs-world {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    background-size: cover;
    background-position: center 65%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .bs-game .bs-brother {
    top: 21%;
    width: 18%;
    height: auto;
    aspect-ratio: 0.49;
  }

  .cl-play[data-world="phonemes"] #cl-stage .bs-name {
    top: 82%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .bs-scroll:not(.reveal),
  .cl-play[data-world="phonemes"] #cl-stage .bs-flight {
    width: min(78%, 440px);
    min-height: 48px;
  }

  .cl-play[data-world="phonemes"] #cl-stage .bs-speech {
    top: 12%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .qb-canvas {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    background-size: cover;
    background-position: center bottom;
  }

  .cl-play[data-world="phonemes"] #cl-stage .qb-picture {
    object-position: center bottom;
  }

  .cl-play[data-world="phonemes"] #cl-stage .qolarba .qb-keeper {
    object-position: center bottom;
  }

  .cl-play[data-world="phonemes"] #cl-stage .qb-head :is(#cl-exit, #cl-mute, #cl-settings, .qb-pause) {
    flex: 0 0 44px;
    padding-inline: 6px;
  }

  .cl-play[data-world="phonemes"] #cl-stage .qb-letter {
    min-width: 44px;
    min-height: 44px;
    text-align: center;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.qb-cart, .qb-letter) {
    translate: 0 12cqh;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .cl-play[data-world-game="31"] .cl-viewport {
    box-sizing: border-box;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
    min-height: 0;
    padding: 4px max(52px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left));
  }

  .cl-play[data-world-game="31"] .cl-head {
    min-height: 42px;
    margin-bottom: 0;
  }

  .cl-play[data-world-game="31"] .cl-head h1 {
    margin-block: 3px;
  }

  .cl-play[data-world-game="31"] #cl-stage {
    min-height: 0;
  }

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

  .cl-play[data-world-game="31"] #cl-stage .banana-board {
    height: 100%;
    container-type: size;
  }

  .cl-play[data-world-game="31"] #cl-stage .banana-guest .banana-face {
    width: min(100%, 44cqh);
  }

  .cl-play[data-world-game="31"] #cl-stage .banana-game .ag-status {
    margin-block: .15em;
    font-size: clamp(14px, 4.1dvh, 20px);
  }

  .cl-play[data-world-game="13"] #cl-stage .eh-tray {
    height: max(146px, 62%);
    padding-block: 6px;
  }
}

@media (orientation: landscape) and (max-height: 520px),
       (orientation: landscape) and (pointer: coarse) {
  .cl-play:is([data-world-game="26"], [data-world-game="123"], [data-world-game="147"], [data-world-game="148"]) {
    --scene-left: max(8px, env(safe-area-inset-left));
    --scene-right: max(8px, env(safe-area-inset-right));
    --scene-top: max(6px, env(safe-area-inset-top));
    --scene-bottom: max(6px, env(safe-area-inset-bottom));
    --scene-toolbar: 44px;
    --scene-paper: #fff8e9f4;
    --scene-frame: 1px solid #a3804e52;
    --scene-shadow: 0 2px 9px #33261632;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-game, .qolarba, .tatti),
  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-field, .qb-field, .tt-field),
  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-world, .qb-canvas) {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-world, .qb-canvas) {
    background-size: cover;
    background-position: center 85%;
  }

  .cl-play[data-world="phonemes"] #cl-stage .qb-field::before { content: none; }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-head, .qb-head, .bs-foot, .qb-foot) {
    position: absolute;
    inset-inline: var(--scene-left) var(--scene-right);
    z-index: 2;
    min-height: 0;
    padding: 0;
    gap: 5px;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-head, .qb-head) {
    top: var(--scene-top);
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-foot, .qb-foot) {
    bottom: var(--scene-bottom);
    justify-content: space-between;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-head, .qb-head) :is(h1, .bs-count, .qb-number),
  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-instruction, .qb-caption) {
    flex: 0 1 auto;
    padding: .43em .72em;
    border: var(--scene-frame);
    border-radius: 14px;
    background: var(--scene-paper);
    box-shadow: var(--scene-shadow);
    font-size: clamp(14px, min(2.3vw, 5.4dvh), 29px);
    line-height: 1.16;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-count, .qb-number, .bs-foot .bs-hint, .qb-caption + .qb-listen) {
    margin-inline-start: auto;
  }

  .cl-play[data-world="phonemes"] #cl-stage :is(.bs-head, .qb-head, .bs-foot, .qb-foot) button {
    pointer-events: auto;
  }

  .cl-play[data-world-game="123"] #cl-stage .bs-head :is(#cl-mute, #cl-settings, #cl-exit),
  .cl-play[data-world-game="148"] #cl-stage .qb-head :is(#cl-exit, #cl-mute, #cl-settings, .qb-pause),
  .cl-play[data-world="phonemes"][data-world-game="147"] :is(#cl-exit, #cl-mute, #cl-settings) {
    width: var(--scene-toolbar);
    height: var(--scene-toolbar);
    padding: 0;
    border: var(--scene-frame);
    border-radius: 12px;
    background: var(--scene-paper);
    box-shadow: var(--scene-shadow);
  }

  .cl-play[data-world-game="123"] #cl-stage .bs-head #cl-exit { padding: 0; }
  .cl-play[data-world-game="123"] #cl-stage .bs-head #cl-exit span { display: none; }
  .cl-play[data-world-game="123"] #cl-stage .bs-head h1 { margin-inline-end: auto; }

  .cl-play[data-world-game="123"] #cl-stage .bs-game .bs-brother {
    top: 18%;
    height: 53%;
  }

  .cl-play[data-world-game="123"] #cl-stage .bs-person {
    width: min(133%, 38cqh);
  }

  .cl-play[data-world-game="123"] #cl-stage .bs-name {
    top: 82%;
    width: clamp(42px, 18.5cqh, 100px);
    font-size: clamp(12px, 4.6cqh, 25px);
  }

  .cl-play[data-world-game="123"] #cl-stage :is(.bs-scroll:not(.reveal), .bs-flight) {
    top: 77%;
    width: min(49%, 84cqh);
    min-height: 44px;
  }

  .cl-play[data-world-game="123"] #cl-stage .bs-speech {
    top: calc(var(--scene-top) + var(--scene-toolbar));
  }

  .cl-play[data-world-game="123"] #cl-stage .bs-performance[data-phase="wrong"] .bs-flight {
    animation-name: phonemes-scroll-return;
  }

  @keyframes phonemes-scroll-return {
    0%, 100% { left: 50%; top: 77%; transform: scale(1); }
    50% { left: var(--dest); top: 48%; transform: scale(.26); }
  }

  .cl-play[data-world-game="148"] #cl-stage :is(.qb-keeper, .qb-picture, .qb-spelling) {
    translate: 0 9cqh;
  }

  .cl-play[data-world-game="148"] #cl-stage :is(.qb-cart, .qb-letter) {
    translate: 0 -10cqh;
  }

  .cl-play[data-world-game="147"] .cl-viewport .cl-head {
    position: absolute;
    inset: var(--scene-top) 0 auto;
    height: var(--scene-toolbar);
    background: transparent;
    border: 0;
    pointer-events: none;
  }

  .cl-play[data-world-game="147"] .cl-viewport .cl-head h1 {
    padding: .33em .8em;
    border: var(--scene-frame);
    border-radius: 14px;
    background: var(--scene-paper);
    box-shadow: var(--scene-shadow);
    font-size: clamp(17px, 6dvh, 32px);
  }

  .cl-play[data-world-game="147"] .cl-viewport .cl-head > div {
    right: calc(var(--scene-right) + var(--scene-toolbar) + 5px);
    pointer-events: auto;
  }

  .cl-play[data-world="phonemes"][data-world-game="147"] :is(#cl-exit, #cl-settings) {
    top: var(--scene-top);
    transform: none;
  }

  .cl-play[data-world="phonemes"][data-world-game="147"] #cl-exit { left: var(--scene-left); }
  .cl-play[data-world="phonemes"][data-world-game="147"] #cl-settings { right: var(--scene-right); opacity: 1; }

  .cl-play[data-world-game="147"] .cl-viewport #cl-stage {
    position: absolute;
    inset: 0;
    height: 100%;
  }

  .cl-play[data-world-game="147"] #cl-stage :is(.tatti > .tt-instruction, .tt-build-footer) {
    position: absolute;
    z-index: 3;
    inset: auto auto var(--scene-bottom) 50%;
    width: max-content;
    max-width: calc(100% - var(--scene-left) - var(--scene-right));
    min-height: 0;
    padding: .4em .9em;
    border: var(--scene-frame);
    border-radius: 14px;
    translate: -50% 0;
    box-sizing: border-box;
    background: var(--scene-paper);
    box-shadow: var(--scene-shadow);
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-instruction {
    font-size: clamp(14px, 4.8cqh, 24px);
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-build-footer .tt-instruction { background: none; }
  .cl-play[data-world-game="147"] #cl-stage .tt-hear { width: 44px; height: 44px; }

  .cl-play[data-world-game="147"] #cl-stage .tt-choices {
    inset-block: calc(var(--scene-top) + var(--scene-toolbar)) calc(var(--scene-bottom) + 38px);
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-choice-label { font-size: clamp(15px, 5.1cqh, 25px); }

  .cl-play[data-world-game="147"] #cl-stage .tt-word {
    top: calc(var(--scene-top) + var(--scene-toolbar) + 5px);
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-sweets {
    inset-block: calc(var(--scene-top) + var(--scene-toolbar) + 3px) calc(var(--scene-bottom) + 35px);
    gap: 2px 2cqw;
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-field .tt-sweet {
    width: min(100%, max(44px, 19cqh));
    height: min(100%, max(44px, 19cqh));
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-field:is([data-phase="build"], [data-phase="won"]) {
    --home-size: min(40cqw, calc((100cqh - var(--scene-top) - var(--scene-bottom) - 100px) * var(--house-ratio)));
    --home-bottom: max(16%, calc(var(--scene-bottom) + 44px));
    --tray-bottom: var(--home-bottom);
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-field[data-phase="build"] .tt-cup {
    bottom: var(--home-bottom);
  }

  .cl-play[data-world-game="147"] #cl-stage .tt-field[data-phase="gather"] .tt-cup {
    bottom: max(12%, calc(var(--scene-bottom) + 34px));
  }

  .cl-running:has(.cl-play[data-world-game="147"]) dialog.tt-replay {
    inset: auto var(--scene-right, 8px) var(--scene-bottom, 8px);
    width: fit-content;
    max-width: calc(100% - 16px);
    min-height: 0;
    margin: 0 auto;
    border: 1px solid #d2b78a;
    border-radius: 14px;
    background: #fff8e9f4;
  }

  .cl-play[data-world-game="26"] #cl-stage .sp-pool {
    --sp-sky: clamp(0px, calc(50px - 8.7dvh), 26px);
    --sp-art-height: calc(100dvh - var(--sp-sky));
    background-size: 100% var(--sp-art-height);
    background-position: center bottom;
  }

  /* Fill the narrow extension behind the controls from the top edge of the artwork.
     The labels and card use the same coordinates as the signs and the raft. */
  .cl-play[data-world-game="26"] #cl-stage .sp-pool::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: var(--sp-sky);
    background-image: inherit;
    background-position: center top;
    background-size: 100% 16000%;
    pointer-events: none;
  }

  .cl-play[data-world-game="26"] #cl-stage .sp-signs {
    top: calc(var(--sp-sky) + var(--sp-art-height) * .087);
    height: max(44px, calc(var(--sp-art-height) * .188));
  }

  .cl-play[data-world-game="26"] #cl-stage .sp-lanes {
    top: calc(var(--sp-sky) + var(--sp-art-height) * .34);
  }

  .cl-play[data-world-game="26"] #cl-stage .sp-pool .sp-card {
    top: calc(var(--sp-sky) + var(--sp-art-height) * .437);
    height: calc(var(--sp-art-height) * .355);
  }

  .cl-play[data-world-game="26"] #cl-stage .sp-sign strong { font-size: clamp(16px, 8.4cqh, 52px); }
  .cl-play[data-world-game="26"] #cl-stage .sp-sign span { font-size: clamp(11px, 4.15cqh, 25px); }

  .cl-play[data-world-game="26"] #cl-stage .ag-top {
    top: var(--scene-top);
    left: var(--scene-left);
  }

  .cl-play[data-world-game="26"] .cl-head > div {
    top: var(--scene-top);
    right: calc(var(--scene-right) + 98px);
  }

  .cl-play[data-world-game="26"] :is(#cl-exit, #cl-settings) {
    top: var(--scene-top);
    transform: none;
  }

  .cl-play[data-world-game="26"] #cl-exit { right: var(--scene-right); }

  .cl-play[data-world-game="26"] #cl-settings {
    right: calc(var(--scene-right) + 49px);
    width: var(--scene-toolbar);
    height: var(--scene-toolbar);
    border-radius: 50%;
  }

  .cl-play[data-world-game="26"] #cl-stage .sp-listen {
    padding-inline: .9em;
    border: var(--scene-frame);
    border-radius: 14px;
    background: var(--scene-paper);
    color: #124b52;
    font-weight: 700;
    box-shadow: var(--scene-shadow);
  }
}
