/* Touch-only sizing. Laptop styles and number-line labels are intentionally independent. */
body.touch-device{--touch-text:20.8px;--touch-title:30.4px;--touch-equation:40px;--touch-guidance:24px;--touch-nav:20.8px;padding:12px}
body.touch-device.phone-layout{--touch-text:16px;--touch-title:21px;--touch-equation:30px;--touch-guidance:18px;--touch-nav:15px;padding:8px}
body.touch-device header,body.touch-device main{width:100%;max-width:100%}
body.touch-device main>.heading,body.touch-device .game#game #actionTitle,body.touch-device .game#game #instruction,body.touch-device .game#game #remaining,body.touch-device .game#game #hint{display:none!important}
body.touch-device .game#game{padding:12px;font-size:var(--touch-text)}
body.touch-device .game#game #levelTitle{font-size:var(--touch-title);line-height:1.15;margin:0}
body.touch-device .game#game button,body.touch-device .game#game label,body.touch-device .game#game select,body.touch-device .game#game #freeModes label,body.touch-device .game#game #freeModes select,body.touch-device .game#game #freeModes #undo,body.touch-device .game#game #freeModes #startNew,body.touch-device .game#game .question-tools button,body.touch-device .game#game #blockControls button{font-size:var(--touch-text);line-height:1.2;min-height:40px;padding:7px 10px}
body.touch-device .game#game .game-tools button,body.touch-device .game#game #bottomNavigation button,body.touch-device .game#game #questionActions #next{font-size:var(--touch-nav);line-height:1.2;min-height:40px;padding:7px 10px;width:auto;min-width:0}
body.touch-device .game#game .game-head{grid-template-columns:minmax(0,1fr) auto;gap:6px 10px;margin-bottom:6px}
body.touch-device .game#game .game-tools{gap:6px;flex-wrap:wrap}
body.touch-device .game#game #equationDock{grid-column:1/-1;grid-row:2;display:flex;justify-content:center}
body.touch-device .game#game #equation{font-size:var(--touch-equation);line-height:1.1;min-height:0;padding:4px 8px;gap:8px;max-width:100%;flex-wrap:wrap;background:#f4f5ee}
body.touch-device .game#game #equation .fraction{font-size:.8em}
body.touch-device .game#game #equation .blank{font-size:1em;min-height:1.2em;min-width:1em}
body.touch-device .game#game #activity,body.touch-device .game#game #activity.mistake-instruction,body.touch-device .game#game #activity.prediction-activity p{font-size:var(--touch-guidance);line-height:1.2;padding:6px 10px;margin:0;flex-shrink:0}
body.touch-device .game#game #activity.prediction-activity button{font-size:calc(var(--touch-guidance) * 1.5);min-height:40px;padding:5px 15px}
body.touch-device .game#game #feedback,body.touch-device .game#game #reviewLabel{font-size:var(--touch-text);line-height:1.25;padding:4px 0;margin:0}
body.touch-device .game#game .history-title,body.touch-device .game#game .history-title span{font-size:12px;line-height:1.2;margin-top:4px}
body.touch-device .game#game:fullscreen .history-title,body.touch-device .game#game.focus-mode .history-title{display:none}
body.touch-device .game#game #freeModes{padding:6px 8px;gap:6px;margin-bottom:5px;flex-wrap:wrap}
body.touch-device .game#game #gameControls{padding:4px 6px;gap:6px;margin:0;flex-shrink:0}
body.touch-device .game#game #gameControls #blockControls{gap:6px}
body.touch-device .game#game .question-tools{padding:0;min-height:0;flex-shrink:0}
body.touch-device .game#game #bottomNavigation{gap:8px;margin:3px 0;flex-shrink:0}
body.touch-device .game#game #clock{font-size:16px}
body.touch-device .game#game #dots{margin-top:4px;gap:5px;flex-shrink:0}
body.touch-device .game#game #dots span{height:14px;font-size:12px}
body.touch-device .game#game .stats{margin:0;font-size:16px}
body.touch-device .game#game:fullscreen,body.touch-device .game#game.focus-mode{padding:0;overflow-y:auto;overflow-x:hidden}
body.touch-device .game#game:fullscreen #gameSurface,body.touch-device .game#game.focus-mode #gameSurface{height:100dvh;min-height:0;padding:8px 12px;display:flex;flex-direction:column;width:100%}
body.touch-device .game#game:fullscreen .layout,body.touch-device .game#game.focus-mode .layout,body.touch-device .game#game:fullscreen .play,body.touch-device .game#game.focus-mode .play{display:flex;flex-direction:column;flex:1;min-height:0;gap:4px;width:100%}
body.touch-device .game#game:fullscreen #sceneWrap,body.touch-device .game#game.focus-mode #sceneWrap,body.touch-device .game#game:fullscreen #scene,body.touch-device .game#game.focus-mode #scene{display:flex;flex:1;min-height:120px;height:auto;padding:0}
body.touch-device .game#game:fullscreen .arm-scale,body.touch-device .game#game.focus-mode .arm-scale{height:100%;min-height:0;max-height:none;aspect-ratio:auto}
/* Leave phone balance width, tick digits and block geometry as they were. */
body.touch-device:not(.phone-layout) .game#game .arm-scale{width:100%;max-width:none}
body.touch-device.phone-layout nav button{font-size:14px;min-height:36px;padding:7px 10px}
body.touch-device:not(.phone-layout) nav button{font-size:20.8px}
body.touch-device.phone-layout #modalTitle{font-size:24px}
body.touch-device.phone-layout #modal button,body.touch-device.phone-layout #modal p,body.touch-device.phone-layout #modal li{font-size:16px}
body.touch-device.phone-layout #modalBody #demoCaption{font-size:18px}
body.touch-device.phone-layout #modalBody #demoProgress{font-size:14px}
body.touch-device #modalBody .levels button{font-size:var(--touch-text);min-height:70px;padding:12px}
@media(orientation:landscape){body.touch-device.phone-layout .game#game.focus-mode #gameSurface,body.touch-device.phone-layout .game#game:fullscreen #gameSurface{padding:5px 8px}body.touch-device.phone-layout .game#game .game-tools button,body.touch-device.phone-layout .game#game #bottomNavigation button{min-height:34px;padding:5px 8px}body.touch-device.phone-layout .game#game #equationDock{grid-column:1;grid-row:2;justify-content:flex-start}body.touch-device.phone-layout .game#game #equation{font-size:28px}body.touch-device.phone-layout .game#game #activity{padding:4px 8px}}
@media(orientation:portrait){body.touch-device .game#game.focus-mode #gameSurface{padding-top:8px}}

/* In short landscape windows the question uses the empty upper-left space above the arm. */
@media(orientation:landscape){body.touch-device.phone-layout .game#game.focus-mode:not(:has(#activity:not([hidden]))) #equationDock,body.touch-device.phone-layout .game#game:fullscreen:not(:has(#activity:not([hidden]))) #equationDock{position:absolute;top:42px;left:0;z-index:3;max-width:40%}body.touch-device.phone-layout .game#game #gameControls button{min-height:34px;padding:5px 8px}}

body.touch-device footer{font-size:16px}
body.touch-device:not(.phone-layout) #modal{font-size:20.8px}
body.touch-device:not(.phone-layout) #modalTitle{font-size:30.4px}
body.touch-device:not(.phone-layout) #modal button,body.touch-device:not(.phone-layout) #modal p,body.touch-device:not(.phone-layout) #modal li{font-size:20.8px}

/* Phone portrait: full-width balance, compact heading and controls. Tablet/laptop unaffected. */
@media(orientation:portrait){
body.touch-device.phone-layout{--touch-title:20px;--touch-equation:30px;--touch-guidance:17px;--touch-nav:14px}
body.touch-device.phone-layout .game#game .game-head{grid-template-columns:94px minmax(0,1fr);gap:8px;align-items:center;position:relative}
body.touch-device.phone-layout .game#game #levelTitle{font-size:20px;line-height:1.15;max-width:94px;overflow-wrap:normal}
body.touch-device.phone-layout .game#game .game-tools{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;width:100%;align-items:stretch}
body.touch-device.phone-layout .game#game .game-tools #choose{grid-column:1/-1}
body.touch-device.phone-layout .game#game .game-tools button{font-size:14px;line-height:1.15;padding:6px;min-height:42px;white-space:normal}
body.touch-device.phone-layout .game#game #equationDock{position:static;grid-column:1/-1;grid-row:2;max-width:100%;justify-content:center}
body.touch-device.phone-layout .game#game #equation{font-size:30px;padding:5px 7px;gap:6px;line-height:1.1}
body.touch-device.phone-layout .game#game #activity,body.touch-device.phone-layout .game#game #activity.mistake-instruction,body.touch-device.phone-layout .game#game #activity.prediction-activity p{font-size:17px;line-height:1.25;padding:7px 9px}
body.touch-device.phone-layout .game#game .arm-scale,body.touch-device.phone-layout .game#game.focus-mode .arm-scale,body.touch-device.phone-layout .game#game:fullscreen .arm-scale{width:100%;min-width:0;max-width:100%;height:auto;aspect-ratio:800 / 300;flex:none;margin:0}
body.touch-device.phone-layout .game#game #scene{align-items:center;justify-content:center;overflow:visible}
body.touch-device.phone-layout .game#game .comparison-badge{width:30px;height:27px;font-size:25px;line-height:1;border-width:1px;border-radius:5px;box-shadow:0 1px 0 #dce6d9}
body.touch-device.phone-layout .game#game #freeModes{padding:5px;gap:5px}
body.touch-device.phone-layout .game#game #freeModes label,body.touch-device.phone-layout .game#game #freeModes select,body.touch-device.phone-layout .game#game #freeModes #undo,body.touch-device.phone-layout .game#game #freeModes #startNew{font-size:14px;min-height:38px;padding:6px}
body.touch-device.phone-layout .game#game #bottomNavigation{justify-content:space-between;flex-wrap:wrap;gap:6px}
body.touch-device.phone-layout .game#game #bottomNavigation button,body.touch-device.phone-layout .game#game #blockControls button{font-size:14px;min-height:40px;padding:6px 8px}
body.touch-device.phone-layout .game#game #gameControls{padding:4px;margin:0}
body.touch-device.phone-layout .game#game #dots{width:100%;gap:4px}
body.touch-device.phone-layout .game#game #dots span{height:12px;font-size:11px}
body.touch-device.phone-layout .game#game #gameSurface{padding:6px 8px}
body.touch-device.phone-layout .game#game.focus-mode #sceneWrap,body.touch-device.phone-layout .game#game.focus-mode #scene,body.touch-device.phone-layout .game#game:fullscreen #sceneWrap,body.touch-device.phone-layout .game#game:fullscreen #scene{min-height:150px}
body.touch-device.phone-layout .game#game .success-tick{font-size:80px;top:24%}
body.touch-device.phone-layout #modal{max-height:94dvh;overflow-y:auto;padding:14px}
body.touch-device.phone-layout #modalBody .levels{grid-template-columns:1fr;gap:8px}
body.touch-device.phone-layout #modalBody .levels button{font-size:17px;min-height:64px;padding:10px}
}

@media(orientation:portrait){body.touch-device.phone-layout .game#game #predictionSlot{width:44px;min-width:44px;height:48px;min-height:48px;font-size:30px;padding:4px}body.touch-device.phone-layout .game#game #freeModes{display:grid;grid-template-columns:1fr 1fr}body.touch-device.phone-layout .game#game #freeModes #fractionRange{grid-column:1/-1}body.touch-device.phone-layout .game#game #freeModes #undo,body.touch-device.phone-layout .game#game #freeModes #startNew{width:100%}}

@media(orientation:portrait) and (max-height:600px){body.touch-device.phone-layout .game#game.focus-mode #sceneWrap,body.touch-device.phone-layout .game#game.focus-mode #scene,body.touch-device.phone-layout .game#game:fullscreen #sceneWrap,body.touch-device.phone-layout .game#game:fullscreen #scene{min-height:138px}}

/* Phone-only alignment: a solid fullscreen surface hides the page beneath it. */
body.phone-layout.game-focus-active{background:#fffefa;overflow-x:hidden}
body.phone-layout.game-focus-active>header,body.phone-layout.game-focus-active main>footer{visibility:hidden}
body.touch-device.phone-layout .game#game.focus-mode,body.touch-device.phone-layout .game#game:fullscreen{left:0;right:0;width:100%;max-width:100%;margin:0;border:0;outline:0;box-shadow:none;background:#fffefa;isolation:isolate}
@media(orientation:portrait){
body.touch-device.phone-layout .game#game #gameSurface{position:relative;left:-4px}
body.touch-device.phone-layout .game#game .arm-scale,body.touch-device.phone-layout .game#game.focus-mode .arm-scale,body.touch-device.phone-layout .game#game:fullscreen .arm-scale{width:110%;max-width:110%;flex-shrink:0}
}

/* Phone portrait: keep the heading clear of the browser edge and lift the balance into the spare gap. */
@media(orientation:portrait){
body.touch-device.phone-layout .game#game.focus-mode #gameSurface,body.touch-device.phone-layout .game#game:fullscreen #gameSurface{padding-top:max(22px,calc(env(safe-area-inset-top,0px) + 12px))}
body.touch-device.phone-layout .game#game .game-head{position:relative;top:auto}
body.touch-device.phone-layout .game#game.focus-mode #scene,body.touch-device.phone-layout .game#game:fullscreen #scene{padding-bottom:clamp(0px,calc(100dvh - 620px),120px)}
}
@media(orientation:portrait) and (max-height:600px){body.touch-device.phone-layout .game#game.focus-mode #sceneWrap,body.touch-device.phone-layout .game#game.focus-mode #scene,body.touch-device.phone-layout .game#game:fullscreen #sceneWrap,body.touch-device.phone-layout .game#game:fullscreen #scene{min-height:115px}}

/* Phone fullscreen balance: 5% narrower than the approved portrait width. */
@media(orientation:portrait){body.touch-device.phone-layout .game#game.focus-mode .arm-scale,body.touch-device.phone-layout .game#game:fullscreen .arm-scale{width:104.5%;max-width:104.5%}}

/* Tablet comparison sign: smaller box leaves the number-line labels clear. */
body.touch-device:not(.phone-layout) .game#game .comparison-badge{width:48px;height:36px;min-width:0;min-height:0;font-size:40px;line-height:1;border-radius:8px}

/* Tablet symbols use centred paths so font baselines cannot push them down. */
body.touch-device:not(.phone-layout) .game#game .comparison-badge{display:grid;place-items:center;padding:0}
body.touch-device:not(.phone-layout) .game#game .comparison-badge .tablet-comparison-symbol{display:block;width:32px;height:26px;overflow:visible}
