/* Fit the room into the actual browser viewport, including short Safari tabs. */
@media (max-width:900px), (any-pointer:coarse) and (max-width:1200px) {
  body[data-screen='play'],body[data-screen='runner'],body[data-screen='tower'] { overflow:hidden; }
  body[data-screen='play'] .app,body[data-screen='runner'] .app,body[data-screen='tower'] .app {
    height:100svh; height:100dvh; min-height:0; width:100%; max-width:none;
    padding:max(3px,env(safe-area-inset-top)) max(9px,env(safe-area-inset-right)) max(3px,env(safe-area-inset-bottom)) max(9px,env(safe-area-inset-left));
    display:grid; grid-template-rows:46px minmax(0,1fr) 20px;
  }
  .app header { min-height:0; height:46px; gap:6px; }
  .app .game-title.painted-title { height:42px; width:min(38vw,170px); }
  .app .settings { gap:4px; }
  .app .settings button { min-height:42px; padding:4px 9px; font-size:12px; }
  body[data-screen='play'] main,body[data-screen='runner'] main,body[data-screen='tower'] main {
    position:relative; min-height:0; height:100%; display:block;
  }
  body[data-screen='play'] .play { display:grid; grid-template-rows:auto 4px minmax(0,1fr); gap:5px; height:100%; padding:0; }
  .app .quest-bar { position:relative; inset:auto; min-height:0; flex-wrap:nowrap; align-items:center; gap:8px; }
  .app .quest-bar>div:first-child { flex:1; min-width:0; }
  .app .quest-bar .eyebrow { margin:0; max-width:none; font-size:9px; line-height:1.2; }
  .app .hearts { min-height:24px; margin:2px 0 0; gap:6px; }
  .app .heart { font-size:25px; line-height:1; }
  .app .layer-count strong { font-size:23px; }
  .app .layer-count span { font-size:11px; }
  .app .play>.progress { position:relative; inset:auto; margin:0; height:4px; }
  .app .play .table-stage,.app .play.sentence-stage .table-stage {
    position:relative; inset:auto; height:100%; min-height:0; width:100%; max-width:none; margin:0;
    padding:6px 1px 4px; overflow:visible;
  }
  .app .play .choices,.app .play.sentence-stage .choices { height:100%; gap:clamp(12px,8vw,100px); grid-template-columns:repeat(2,minmax(0,1fr)); }
  .app .choice { min-height:0; height:100%; display:grid; grid-template-rows:minmax(0,1fr) auto; gap:4px; }
  .app .doll-wrap { height:100%; width:auto; max-width:100%; min-height:0; aspect-ratio:2/3; }
  .app .answer,.app .play.sentence-stage .answer,body[data-world='3'] .app .answer {
    min-height:52px; width:100%; padding:8px; font-size:clamp(16px,2.6vw,21px); line-height:1.2;
    overflow-wrap:break-word; text-align:center; touch-action:manipulation;
  }
  .app .answer kbd { display:none; }
  body[data-screen='play'] .play .touch-choices { display:none!important; }
  .app .game-bottom { display:none; }
  body[data-screen='play'] .rotate-hint { display:none!important; }
  body[data-screen='play'] footer,body[data-screen='runner'] footer,body[data-screen='tower'] footer {
    min-height:0; height:20px; padding:0; margin:0; font-size:10px;
  }
  .app footer span:last-child { display:none; }
  .app #curseMeter { top:42px; font-size:14px; gap:2px; }
  .app #curseTime { width:110px; }
  .app .spell-notice { top:48px; font-size:13px; padding:4px 8px; }
  .app .answer .opening-plea { font-size:17px; padding:4px 8px; }
  .app .runner,.app .tower { height:100%; min-height:0; }
  .app .run-heading,.app .tower-heading { flex:none; padding:3px 0; font-size:12px; gap:6px; }
  .app .run-field,.app .tower-field { min-height:0; flex:1; }
  .app .run-hint { display:none; }
  .app .run-controls,.app .tower-controls { flex:none; display:flex; gap:6px; margin:4px 0 0; }
  .app .run-controls button,.app .tower-controls button { flex:1; min-height:44px; padding:5px; font-size:14px; touch-action:manipulation; }
  .app .run-controls kbd,.app .tower-controls kbd { display:none; }
  .app .tower-message { font-size:12px; margin:3px 0; }
  .app .tower-option { font-size:15px; padding:5px 5px 12px; min-height:44px; }
  .app .run-phrase { font-size:16px; padding:6px 9px; }
  .app .runner-girl { height:32%; max-height:100px; }
  dialog { max-height:85dvh; overflow:auto; }
}
@media (orientation:portrait) and (max-width:900px) {
  .app .play .choices { gap:12px; }
  .app .play .table-stage { padding-top:8dvh; }
  .app .answer,.app .play.sentence-stage .answer,body[data-world='3'] .app .answer { min-height:80px; font-size:18px; }
}
@media (orientation:landscape) and (max-height:400px) {
  body[data-screen='play'] .app,body[data-screen='runner'] .app,body[data-screen='tower'] .app { grid-template-rows:42px minmax(0,1fr) 16px; }
  .app header { height:42px; }
  .app .quest-bar>div:first-child { display:flex; align-items:center; gap:10px; }
  .app .quest-bar .eyebrow { max-width:48%; }
  .app .heart { font-size:22px; }
  .app .answer,.app .play.sentence-stage .answer,body[data-world='3'] .app .answer { min-height:44px; padding:5px 7px; font-size:16px; }
  body[data-screen='play'] footer,body[data-screen='runner'] footer,body[data-screen='tower'] footer { height:16px; font-size:9px; }
}
