/* One layout owns the controls: the tool rail never shares the dock/player row.
   The canvas keeps its full viewport and the renderer's native aspect ratio. */
@media (max-width:1100px), (max-height:700px), (pointer:coarse) {
  #experience {
    --edge-left:max(16px,env(safe-area-inset-left));
    --edge-right:max(16px,env(safe-area-inset-right));
    display:grid;
    grid-template-columns:minmax(0,1fr) 64px;
    grid-template-rows:auto minmax(0,1fr) auto auto;
    column-gap:12px;
    row-gap:8px;
    padding:0 var(--edge-right) max(12px,env(safe-area-inset-bottom)) var(--edge-left);
    width:100%;height:100dvh;min-height:0;
    overflow:hidden;
  }
  #experience>.topbar {
    position:relative;inset:auto!important;grid-area:1/1/2/-1;
    width:100%;height:auto;min-height:64px;
    padding:calc(8px + env(safe-area-inset-top)) 0 8px!important;
    align-items:center!important;
  }
  .topbar .header-right { min-width:0;margin-left:auto;gap:4px!important; }
  .topbar .brand { margin-right:0; }
  #experience>.stage-tools {
    position:relative;inset:auto;transform:none;
    grid-area:2/2/3/3;align-self:center;justify-self:center;
    width:64px;max-width:100%;max-height:100%;min-height:0;
    display:flex;flex-direction:column;align-items:center;gap:2px;
    overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;
    padding:2px;
  }
  #experience>.world-story {
    top:calc(84px + env(safe-area-inset-top))!important;
    left:var(--edge-left);right:calc(var(--edge-right) + 80px);
    width:auto;max-width:none;
  }
  .world-story h1 {max-width:100%;white-space:normal;overflow-wrap:anywhere;}
  #experience>.world-dock {
    position:relative;inset:auto;grid-area:3/1/4/-1;
    width:100%;min-width:0;display:grid;
    grid-template-columns:44px minmax(0,1fr) auto;
    align-items:center;gap:8px 12px;
  }
  .world-dock>.library-entry {grid-area:1/1/2/2;margin:0;}
  .world-dock>.worlds {
    grid-area:1/2/2/3;width:100%;min-width:0;min-height:0;
    padding:4px 2px;gap:20px;
  }
  .world-dock>.scan-add {
    grid-area:1/3/2/4;justify-self:end;margin:0;min-height:44px;
    font-size:12px;padding:10px 14px;
  }
  #experience>.player {
    position:relative;inset:auto;grid-area:4/1/5/-1;
    width:100%;min-width:0;min-height:0;display:grid;
    grid-template-columns:minmax(0,1fr) minmax(180px,1.5fr) auto;
    gap:16px;align-items:center;
  }
  .player>.track-block {min-width:0;max-width:none;}
  .player>.transport {grid-area:auto;min-width:0;gap:12px;}
  .player .timeline {min-width:0;}
  .player>.source-actions {display:flex;min-width:0;gap:4px;}
  #experience>.stage-status {left:var(--edge-left);top:calc(68px + env(safe-area-inset-top));bottom:auto;max-width:calc(100% - 100px);}
  /* Old mobile min-width rules combined 44px width with 29–38px height. */
  #experience .icon-button:not(.settings-entry),#experience .play-button {
    box-sizing:border-box;flex:0 0 auto;
    width:44px;height:44px;min-width:44px;min-height:44px;
    max-width:44px;max-height:44px;aspect-ratio:1;border-radius:50%;
  }
  #experience .stage-tools .settings-entry {
    flex:0 0 auto;width:100%;min-width:44px;height:52px;min-height:52px;
    max-width:60px;max-height:none;padding:6px 2px;
  }
  .settings-entry span {line-height:1.2;}
  .panel-open #experience>.stage-tools {right:auto;z-index:8;}
  #experience>.inspector {
    z-index:30;inset:72px max(8px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) auto;
    width:min(390px,calc(100% - 16px));max-height:calc(100% - 80px);
  }
}

@media (max-width:700px) {
  #experience>.world-dock {grid-template-columns:44px minmax(0,1fr) auto;gap:0 12px;}
  .world-dock>.scan-add {grid-area:1/3/2/4;}
  .world-dock>.worlds {grid-area:2/1/3/-1;padding:0 2px 4px;}
  #experience>.player {grid-template-columns:minmax(0,1fr) auto;gap:8px 12px;}
  .player>.track-block {grid-area:1/1/2/2;}
  .player>.source-actions {grid-area:1/2/2/3;}
  .player>.transport {grid-area:2/1/3/-1;}
  .track-details strong,.track-details>span {overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%;}
}

/* Short windows / landscape: use the available width, without scaling the UI. */
@media (max-height:500px) and (min-width:540px) {
  #experience {grid-template-columns:minmax(0,1fr) minmax(0,auto);gap:4px 12px;}
  #experience>.topbar {min-height:52px;padding-block:4px!important;}
  #experience>.stage-tools {
    width:auto;max-width:min(440px,65vw);flex-direction:row;
    grid-area:2/2/3/3;justify-self:end;gap:2px;
    overflow-x:auto;overflow-y:hidden;
  }
  #experience .stage-tools .settings-entry {width:60px;min-width:60px;}
  #experience>.world-story {top:66px!important;right:68%;}
  .world-story h1 {font-size:20px;line-height:1.1;}
  #experience>.world-dock {grid-template-columns:44px minmax(0,1fr) auto;gap:10px;}
  .world-dock>.worlds {grid-area:1/2/2/3;padding:0 2px;}
  #experience>.player {grid-template-columns:minmax(90px,.6fr) minmax(100px,1.5fr) auto;gap:12px;}
  .player>.track-block {grid-area:1/1/2/2;}
  .player>.transport {grid-area:1/2/2/3;}
  .player>.source-actions {grid-area:1/3/2/4;}
  .player .source-actions>.import-button {width:44px;min-width:44px;padding:0;justify-content:center;}
  .player .source-actions>.import-button span {display:none;}
  #experience>.inspector {top:8px;max-height:calc(100% - 16px);}
}

/* Keep the live model visible while editing. */
@media(max-width:760px){body.panel-open #experience>.inspector{position:fixed;inset:40dvh 0 0;width:100%;height:60dvh;max-height:60dvh}body.panel-open #experience>.stage-tools{display:none}}
@media(max-width:1000px) and (max-height:520px){body.panel-open #experience>.inspector{position:fixed;inset:0 0 0 45vw;width:55vw;height:100dvh;max-height:100dvh}}
