/* Phones held sideways (short landscape screens). Upright phones, tablets and computers are unchanged.
   Every rule here sits inside this one media query. */
@media(orientation:landscape) and (max-height:500px){

/* Levels and Grandmaster: the top bar steps aside, and the touch buttons get their own strip under the course
   (level-view.js reads --pad-reserve), so they never cover the explorer, answer boxes or hazards. */
body.in-level .topbar{display:none}
body.in-level .level-view{height:100dvh;min-height:0;--pad-reserve:76px}
body.in-level .level-hud{top:max(8px,env(safe-area-inset-top));left:max(10px,env(safe-area-inset-left));right:max(10px,env(safe-area-inset-right));gap:8px}
body.in-level .level-leave{padding:7px 11px;font-size:12px}
body.in-level .level-name{padding:5px 12px}
body.in-level .level-name span{font-size:8px}
body.in-level .level-name strong{font-size:14px}
body.in-level .level-guide-button{width:34px;height:34px}
body.in-level .level-coins{padding:6px 12px}
body.in-level #toast{top:calc(env(safe-area-inset-top,0px) + 54px)}
.level-pad{bottom:max(6px,env(safe-area-inset-bottom));padding:0 max(16px,env(safe-area-inset-right)) 0 max(16px,env(safe-area-inset-left))}
.level-pad .pad-move{gap:12px}
.level-pad button{width:62px;height:62px;font-size:22px}
.level-pad .pad-jump{width:68px;height:68px;font-size:15px;margin-right:0}

/* Math questions (battle get-ready, rescues, wild Wonderkin, power-ups): the whole number pad fits, in two rows. */
.encounter-dialog:has(.math-area){width:100vw;max-width:none;height:100dvh;max-height:none;margin:0;border:0;border-radius:0;
 padding:max(6px,env(safe-area-inset-top)) max(14px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left));overflow:hidden auto}
.encounter-dialog:has(.math-area) .dialog-top{margin-bottom:4px;align-items:center}
.encounter-dialog:has(.math-area) .dialog-top .eyebrow{font-size:8px;letter-spacing:1.5px}
.encounter-dialog:has(.math-area) .dialog-top h2{font-size:18px;margin:0}
.encounter-dialog:has(.math-area) .dialog-top button{width:34px;height:34px;min-width:34px}
.encounter-dialog .encounter-layout:has(.math-area){grid-template-columns:minmax(0,.72fr) minmax(0,1.28fr);gap:12px;align-items:stretch;height:calc(100dvh - 58px)}
.encounter-dialog .encounter-layout:has(.math-area)>div:first-child{min-height:0;display:flex;flex-direction:column}
.encounter-dialog .encounter-layout:has(.math-area) .battle-scene,
.encounter-dialog .encounter-layout:has(.math-area) .face-off{height:auto;flex:1;min-height:0}
.encounter-dialog .encounter-layout:has(.math-area) .scene-caption{display:none}
.encounter-dialog .math-area{display:flex;flex-direction:column;justify-content:center;min-height:0;gap:4px}
.encounter-dialog .math-area .math-instruction{margin:0;font-size:12px}
.encounter-dialog .math-area .equation{font-size:30px;margin:0;min-height:0}
.encounter-dialog .math-area .answer-box{height:44px;min-width:70px}
.encounter-dialog .math-area .math-feedback{min-height:18px;margin:0;padding:0;font-size:13px}
.encounter-dialog .math-area .keypad{grid-template-columns:repeat(6,minmax(0,1fr));gap:6px;margin:0}
.encounter-dialog .math-area .keypad button{min-height:44px;font-size:21px;padding:0}
.encounter-dialog .math-area .keypad button.utility{font-size:13px}
.encounter-dialog .math-area .submit-answer{min-height:42px;margin:2px 0 0}
.encounter-dialog .math-area .helper-button{margin:0;padding:2px;font-size:12px}
/* Wild Wonderkin: a shorter scene, so the name and NEW banner stay on screen. */
.encounter-dialog .encounter-layout.wild-layout .wild-scene{min-height:0;flex:1}
.encounter-dialog .wild-layout .wild-scene .wild-heading{margin-top:8px;font-size:24px}
.encounter-dialog .wild-layout .wild-pack{margin:6px 10px 6px}
.encounter-dialog .wild-layout .wild-art{height:clamp(64px,26dvh,130px)}
.encounter-dialog .wild-layout .wild-scene .wild-name{font-size:22px;margin-bottom:3px}
.encounter-dialog .wild-layout .wild-banner{margin-bottom:4px}
.encounter-dialog .wild-layout .wild-banner>span{min-height:30px;padding:3px 5px}
/* The 60-second quiz's start card: rules and Start button on one screen. */
.encounter-dialog:has(.quiz-rules){width:100vw;max-width:none;height:100dvh;max-height:none;margin:0;border:0;border-radius:0;padding:max(6px,env(safe-area-inset-top)) max(14px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left))}
.encounter-dialog:has(.quiz-rules) .dialog-top{margin-bottom:4px}
.encounter-dialog:has(.quiz-rules) .dialog-top h2{font-size:18px;margin:0}
.encounter-dialog .quiz-layout:has(.quiz-rules){grid-template-columns:minmax(0,.72fr) minmax(0,1.28fr);gap:12px;align-items:center}
.encounter-dialog .quiz-layout:has(.quiz-rules) .quiz-scene{padding:8px 10px}
.encounter-dialog:has(.quiz-rules){overflow:hidden auto}
.encounter-dialog .quiz-rules{font-size:12px;line-height:1.3}
.encounter-dialog .quiz-rules .intro{margin:0 0 4px;font-size:13px;line-height:1.35}
.encounter-dialog .quiz-rule-list{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px;margin:0 0 4px}
.encounter-dialog .quiz-rule-list li{margin:0;padding:4px 6px;gap:5px;font-size:11px;line-height:1.25}
.encounter-dialog .quiz-rule-list li>span{width:20px;height:20px;min-width:20px;font-size:11px}
.encounter-dialog .quiz-bonus-table{margin:0 0 4px;gap:5px}
.encounter-dialog .quiz-bonus-table>div{padding:3px 6px}
.encounter-dialog .quiz-rules .small-caption{margin:2px 0 4px;font-size:10px}
.encounter-dialog .quiz-actions{margin:0}
.encounter-dialog .quiz-actions button{min-height:38px;padding-block:6px}
.encounter-dialog .quiz-layout:has(.quiz-rules) .quiz-stage{margin:4px 0;gap:8px}
.encounter-dialog .quiz-layout:has(.quiz-rules) .quiz-clock{width:clamp(60px,22dvh,96px);height:clamp(60px,22dvh,96px)}
.encounter-dialog .quiz-layout:has(.quiz-rules) .quiz-pet .pet-art{width:clamp(56px,22dvh,96px);height:clamp(56px,22dvh,96px)}
.encounter-dialog .quiz-bonus-table>div{display:flex;justify-content:center;align-items:baseline;gap:6px}
.encounter-dialog .quiz-bonus-table strong{font-size:14px}
.encounter-dialog .quiz-bonus-table :is(span,b){font-size:11px}
}
/* Narrow sideways phones (the first iPhone SE): the quiz start card drops its picture so the rules and Start button fit. */
@media(orientation:landscape) and (max-height:500px) and (max-width:700px){
.encounter-dialog .quiz-layout:has(.quiz-rules){grid-template-columns:1fr}
.encounter-dialog .quiz-layout:has(.quiz-rules) .quiz-scene{display:none}
/* A story problem takes the picture's place on the left; the answer side keeps the full number pad. */
.encounter-dialog .encounter-layout:has(.math-area #kinder-picture:not([hidden]))>div:first-child{display:none}
.encounter-dialog .encounter-layout:has(.math-area #kinder-picture:not([hidden])){grid-template-columns:1fr}
.encounter-dialog .math-area:has(#kinder-picture:not([hidden])){display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-auto-flow:dense;column-gap:14px;align-content:center}
.encounter-dialog .math-area:has(#kinder-picture:not([hidden]))>*{grid-column:2}
.encounter-dialog .math-area:has(#kinder-picture:not([hidden])) #kinder-picture{grid-column:1;grid-row:1 / span 8;align-self:center;max-height:calc(100dvh - 60px);overflow:auto;margin:0}
/* Story cards shrink their words and pictures with the screen height, so the whole story and question fit. */
.encounter-dialog .math-area{--sp-thing:clamp(14px,5.6dvh,26px)}
.encounter-dialog .math-area .sp-card{margin:0 auto;padding:7px 10px;max-width:none}
.encounter-dialog .math-area .sp-tag{font-size:8px;padding:2px 6px;margin-bottom:3px}
.encounter-dialog .math-area .sp-story{font-size:clamp(13px,4.6dvh,17px);line-height:1.3;margin:0 0 4px}
.encounter-dialog .math-area .sp-ask{font-size:clamp(13px,4.6dvh,17px);line-height:1.25;padding:5px 8px;margin:4px 0 0}
.encounter-dialog .math-area .sp-speaker{width:18px;height:18px;font-size:9px}
.encounter-dialog .math-area .sp-thing,.encounter-dialog .math-area .sp-box .sp-thing{width:var(--sp-thing);height:var(--sp-thing)}
.encounter-dialog .math-area .sp-row .sp-thing{width:calc(var(--sp-thing) * .8);height:calc(var(--sp-thing) * .8)}
.encounter-dialog .math-area .sp-box{grid-template-columns:repeat(var(--cols),var(--sp-thing));padding:3px 5px 5px;border-width:2px}
.encounter-dialog .math-area .sp-array{grid-template-columns:repeat(var(--cols),var(--sp-thing));gap:2px;margin:4px 0 2px}
.encounter-dialog .math-area :is(.sp-boxes,.sp-loose,.sp-compare){margin:4px auto 2px;gap:4px 6px}
.encounter-dialog .math-area .sp-who{font-size:12px;flex-basis:54px}

/* Battles: moves sit in one row, so the arena has room to show every Wonderkin above its card. */
#encounter-dialog .battle-layout .combat-desk{max-height:none;overflow:visible;padding:5px 8px 6px}
#encounter-dialog .battle-layout .boss-power-reminder{padding:3px 10px;margin-bottom:4px}
#encounter-dialog .battle-layout .boss-power-reminder>div{display:inline-flex}
#encounter-dialog .battle-layout .boss-power-reminder p{display:inline;margin-left:8px;font-size:11px}
#encounter-dialog .battle-layout .combat-meta{padding:3px 9px;min-height:0}
#encounter-dialog .battle-layout .battle-moves{grid-template-columns:repeat(auto-fit,minmax(0,1fr));grid-auto-flow:column;gap:6px}
#encounter-dialog .battle-layout .battle-move{min-height:44px;padding:4px 8px}
#encounter-dialog .battle-layout .battle-menu{min-height:0;margin-top:3px}
#encounter-dialog .battle-layout .elements-book-button{min-height:26px;padding:2px 8px}
#encounter-dialog .battle-layout .arena-heading small,#encounter-dialog .battle-layout .arena-heading .island-trick{display:none}
#encounter-dialog .battle-layout .team-arena{flex:1;min-height:0}
#encounter-dialog .battle-layout .arena-heading{top:max(6px,env(safe-area-inset-top))}
#encounter-dialog .battle-layout .arena-heading>strong{font-size:14px;padding:4px 14px}
#encounter-dialog .battle-layout .squad{top:38px;bottom:2px}
#encounter-dialog .battle-layout .squad[data-count] .squad-fighter{top:0;bottom:auto;height:100%;transform:none;gap:2px;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) auto auto;padding:0 2px}
#encounter-dialog .battle-layout .squad .squad-fighter>.squad-art{grid-column:1;grid-row:1}
#encounter-dialog .battle-layout .squad .squad-fighter>.squad-info{grid-column:1;grid-row:2;align-self:end}
#encounter-dialog .battle-layout .squad .squad-fighter>.squad-status{grid-column:1;grid-row:3}
#encounter-dialog .battle-layout .squad .squad-fighter>.squad-tag{left:50%;right:auto;transform:translateX(-50%)}
#encounter-dialog .battle-layout .squad-info>strong{overflow:hidden;justify-content:safe center}
#encounter-dialog .battle-layout .squad[data-count="3"] .squad-fighter{width:33.333%}
#encounter-dialog .battle-layout .squad[data-count="3"] .squad-fighter:nth-child(1){left:0}
#encounter-dialog .battle-layout .squad[data-count="3"] .squad-fighter:nth-child(2){left:33.333%}
#encounter-dialog .battle-layout .squad[data-count="3"] .squad-fighter:nth-child(3){left:66.666%}
#encounter-dialog .battle-layout .squad[data-count="2"] .squad-fighter{width:50%}
#encounter-dialog .battle-layout .squad[data-count="2"] .squad-fighter:nth-child(1){left:0}
#encounter-dialog .battle-layout .squad[data-count="2"] .squad-fighter:nth-child(2){left:50%}
#encounter-dialog .battle-layout .squad-tag{top:auto;bottom:calc(100% - 14px);padding:1px 5px;font-size:8px}
#encounter-dialog .battle-layout .squad-tag .type-chip{font-size:8px;padding:1px 3px}
#encounter-dialog .battle-layout .squad-art{padding-top:12px}
#encounter-dialog .battle-layout .squad-info{gap:1px 3px;padding:3px 6px;max-width:150px;margin:0 auto}
#encounter-dialog .battle-layout .squad-info>strong{flex-wrap:nowrap;white-space:nowrap;font-size:11px}
#encounter-dialog .battle-layout .squad-info>.kin-species,#encounter-dialog .battle-layout .squad-info .rarity-label,#encounter-dialog .battle-layout .squad-info>small:not(.kin-species){display:none}
#encounter-dialog .battle-layout .combat-hp{height:5px}
#encounter-dialog .battle-layout .squad-status{font-size:9px;padding:1px 5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;justify-self:center}

#encounter-dialog:has(.battle-layout) .dialog-top{padding-top:max(4px,env(safe-area-inset-top))}
#encounter-dialog:has(.battle-layout) .dialog-top button{width:32px;height:32px;min-width:32px;min-height:32px}

/* Clocktower Climb cards: a smaller card that starts at the top (a centred card taller than the screen cut its top off). */
.climb-overlay{display:flex;flex-direction:column;align-items:center;padding:8px}
.climb-card{margin:auto 0;width:min(100%,560px);padding:10px 22px 12px}
.climb-card h2{font-size:26px;margin:2px 0 4px}
.climb-card p{margin:4px auto 6px;font-size:14px;line-height:1.3}
.climb-portrait{width:76px;height:64px;margin:0 auto}
.climb-portrait svg{width:58px;height:62px}
.climb-summary{margin:6px 0}
.climb-summary span{padding:5px 3px}

/* Jackpot Drop: prizes and buttons on the left, the whole board on the right, all on one screen. */
.jackpot-shell{grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto auto 1fr auto auto;
 grid-template-areas:"header machine" "inventory machine" "prizes machine" "controls machine" "result machine";
 gap:5px 14px;max-width:none;height:100dvh;align-items:stretch;
 padding:max(6px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left))}
.jackpot-header{padding:0 2px 4px}
.jackpot-header p{font-size:.6rem;margin:0}
.jackpot-header h2{font-size:1.35rem}
.jackpot-close{width:36px;flex-basis:36px}
#jackpot-dialog button,#jackpot-dialog select{min-height:36px}
.jackpot-prizes{gap:5px}
.jackpot-card{min-height:0;padding:3px 2px}
.jackpot-card-art .pet-art{max-height:44px;width:52px}
.jackpot-token{font-size:1.5rem}
.jackpot-machine{align-self:center;width:calc((100dvh - 46px) * 600 / 410 + 14px);max-width:62vw}
.jackpot-machine-label{min-height:16px}
.jackpot-controls small{font-size:.66rem}
}
