/* Foldable layout: use the live viewport, not a device name or an initial width.
   Scene dimensions remain owned by app.js / its existing ResizeObserver. */
.masthead > *, .control-desk > *, .tape-selection > *, .room-switches > * { min-width: 0; }
.masthead .brand { flex-shrink: 0; }
.masthead:before { left: -4.5vw; right: -4.5vw; }
.masthead nav { flex-wrap: wrap; justify-content: flex-end; }
.masthead nav a, .masthead nav button {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
}
.masthead nav .active:after { bottom: 0; }
.control-desk .tape-selection { flex-shrink: 1; min-width: 0; }
.tape-selection .tape { flex-shrink: 0; }
.tape-selection .tape-paper {
  grid-template-columns: minmax(0, 1fr) auto; min-width: 0; overflow: hidden;
}
.tape-selection .tape-paper b { line-height: 1.25; white-space: nowrap; }
.room-switches button { min-height: 44px; }
.room-switches .brightness-control { min-height: 30px; }
.room-tour-controls button { width: 44px; height: 44px; flex: 0 0 44px; }
.status { max-width: calc(100% - 32px); text-align: center; }

/* A narrow or almost square screen needs room and controls on separate rows.
   A minimum scene height also lets a short landscape screen scroll naturally. */
@media (max-width: 1100px), (max-width: 1360px) and (max-aspect-ratio: 4/3) {
  .masthead {
    position: relative; inset: auto; height: auto; min-height: 80px;
    margin: 0; padding: 12px max(4.5%, env(safe-area-inset-left)); gap: 16px;
    background: #15281f;
  }
  .masthead:before { display: none; }
  .masthead nav { gap: 4px 20px; font-size: 12px; }
  .masthead nav .active, .masthead nav button:last-child { display: inline-flex; }
  .preview-label { display: none; }
  .room { height: auto; min-height: 0; padding: 0; overflow: hidden; }
  .room-topline {
    position: relative; inset: auto; padding: 10px 4.5%; gap: 16px;
    min-height: 32px; align-items: center; font-size: 8px;
  }
  .room-topline > span { min-width: 0; }
  .room-topline > span:first-child { font-size: 8px; letter-spacing: 1px; }
  .room-topline > span:last-child { max-width: none; white-space: normal; text-align: right; }
  .scene-viewport {
    position: relative; inset: auto; width: 100%; margin: 0;
    height: clamp(300px, calc(100svh - 350px), 620px);
    height: clamp(300px, calc(100dvh - 350px), 620px);
    max-height: 110vw; aspect-ratio: auto;
  }
  .room-intro {
    display: block; top: 22px; left: 4.5%; right: auto;
    width: auto; max-width: calc(100% - 180px);
  }
  .room-intro .eyebrow { font-size: 9px; margin-bottom: 9px; letter-spacing: 1px; }
  .room-intro h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.35; letter-spacing: 1px; }
  .room-intro h1 br { display: block; }
  .room-intro .explore-note { display: none; }
  .scene-viewport > .intro-xiangyin {
    display: flex; top: 22px; right: 4.5%; width: 136px; min-height: 56px;
    padding: 4px 8px 4px 2px; gap: 2px;
  }
  .scene-viewport > .intro-xiangyin img { width: 56px; height: 44px; }
  .scene-viewport > .intro-xiangyin b { font-size: 21px; }
  .scene-viewport > .intro-xiangyin small { font-size: 7px; letter-spacing: 0; }
  .room-tour-controls { bottom: 12px; gap: 9px; font-size: 9px; padding: 2px 5px; max-width: 95%; }
  .control-desk {
    position: relative; inset: auto; width: auto; min-height: 0;
    display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px;
    margin: 0 4.5%; padding: 16px; border-radius: 5px;
    background: #14291f; box-shadow: 0 6px 25px #06150d40;
  }
  .control-desk .tape-caption { display: none; }
  .control-desk .tape-selection {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 12px; width: 100%; margin: 0;
  }
  .control-desk .tape-selection .tape { width: 100%; height: 60px; min-width: 0; padding: 5px 7px; }
  .control-desk .tape-selection .tape-paper {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; height: 35px; padding: 3px 8px;
  }
  .control-desk .tape-selection .tape-paper b {
    display: block; grid-column: 2; grid-row: 1 / 3; font-size: 25px; letter-spacing: 0;
  }
  .control-desk .tape-selection .tape-paper small {
    display: block; font-size: 8px; line-height: 1.4; letter-spacing: 0;
  }
  .control-desk .tape-selection .tape-paper em {
    display: block; font-size: 6px; line-height: 1.4; letter-spacing: 0;
    max-width: none; overflow: hidden; text-overflow: ellipsis;
  }
  .control-desk .tape-selection .tape-reels { display: none; }
  .control-desk .tape-selection .tape-edge { left: 30%; right: 30%; height: 7px; }
  .control-desk .tape.selected { transform: translateY(-2px); }
  .control-desk .tape:hover { transform: translateY(-2px); }
  .control-desk .room-switches {
    display: flex; flex-wrap: wrap; width: 100%; margin: 0; padding: 8px 0 0;
    align-items: center; justify-content: space-evenly; gap: 4px 16px;
    border-top: 1px solid #d1d5b42e; font-size: 11px;
  }
  .room-switches .light-controls { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0 12px; }
  .room-switches .brightness-control { font-size: 10px; gap: 5px; }
  .room-switches .brightness-control input { width: 76px; }
  .room-switches #explore3d { padding-left: 0; border-left: 0; font-size: 11px; }
  .room-bottomline {
    position: relative; inset: auto; height: auto; min-height: 48px;
    margin: 0 4.5%; padding: 9px 0; gap: 10px; flex-wrap: wrap; font-size: 9px;
  }
  .room-bottomline .local-note { display: none; }
  .room-bottomline a { display: inline-flex; align-items: center; min-height: 32px; }
  .archive-heading { flex-wrap: wrap; gap: 18px 28px; }
  .archive-desc { max-width: 100%; }
  .archive-stamp { flex-shrink: 0; }
}

/* Phone covers and the narrow half of a foldable: give navigation its own row. */
@media (max-width: 700px) {
  .masthead { flex-wrap: wrap; justify-content: center; gap: 7px; padding-top: 12px; padding-bottom: 4px; }
  .masthead .brand { width: 100%; justify-content: center; }
  .masthead nav { width: 100%; justify-content: space-between; gap: 4px; font-size: 11px; }
  .masthead nav a, .masthead nav button { min-width: 44px; padding: 0 4px; }
  .room-topline { padding-top: 7px; padding-bottom: 7px; gap: 10px; }
  .room-topline > span:first-child { font-size: 7px; letter-spacing: .3px; }
  .room-topline > span:last-child { font-size: 7px; }
  .room-intro { top: 18px; max-width: calc(100% - 140px); }
  .room-intro .eyebrow { font-size: 8px; }
  .room-intro h1 { font-size: clamp(25px, 6.8vw, 33px); }
  .scene-viewport > .intro-xiangyin { top: 18px; width: 112px; min-height: 52px; padding: 3px 5px 3px 0; }
  .scene-viewport > .intro-xiangyin img { width: 46px; height: 40px; }
  .scene-viewport > .intro-xiangyin b { font-size: 20px; }
  .scene-viewport > .intro-xiangyin small { font-size: 6px; }
  .control-desk { padding: 12px; gap: 9px; }
  .control-desk .tape-selection { gap: 9px; }
  .control-desk .tape-selection .tape { height: 56px; padding: 4px; }
  .control-desk .tape-selection .tape-paper { display: flex; justify-content: center; height: 34px; padding: 2px; }
  .control-desk .tape-selection .tape-paper b { font-size: 25px; }
  .control-desk .tape-selection .tape-paper small,
  .control-desk .tape-selection .tape-paper em { display: none; }
  .control-desk .room-switches { gap: 2px 12px; padding-top: 5px; font-size: 10px; }
  .room-switches .light-controls { flex-direction: column; align-items: flex-start; gap: 0; }
  .room-switches .brightness-control input { width: 66px; }
  .room-switches #explore3d { font-size: 10px; }
  .room-bottomline { font-size: 8px; }
  .archive-stamp { right: 0; font-size: 15px; }
  .cassette-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .archive-cassette { min-width: 0; }
  .cassette-label { min-width: 0; }
  .television-tape-bar { flex-wrap: wrap; }
  .video-stage-toolbar { flex-wrap: wrap; }
}

/* On a short landscape screen there is width for one row of tapes.
   The page scrolls; controls never float across the television or tea table. */
@media (min-width: 600px) and (max-width: 1100px) and (max-height: 550px) and (min-aspect-ratio: 3/2) {
  .masthead { flex-wrap: nowrap; min-height: 70px; padding-top: 8px; padding-bottom: 8px; }
  .masthead .brand { width: auto; }
  .masthead nav { width: auto; gap: 8px; }
  .room-topline { display: flex; }
  .scene-viewport { height: 330px; max-height: none; }
  .room-intro { display: block; top: 18px; }
  .scene-viewport > .intro-xiangyin { display: flex; top: 18px; }
  .control-desk .tape-selection { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
  .control-desk .tape-selection .tape-paper { display: flex; justify-content: center; padding: 2px; }
  .control-desk .tape-selection .tape-paper small,
  .control-desk .tape-selection .tape-paper em { display: none; }
  .room-switches .light-controls { flex-direction: row; align-items: center; gap: 10px; }
}
@media (max-width: 380px) {
  .masthead nav { font-size: 10px; }
  .control-desk .room-switches { gap: 2px 8px; }
  .room-switches .brightness-control input { width: 54px; }
  .room-switches .brightness-control { font-size: 9px; }
  .archive { padding-left: 5%; padding-right: 5%; }
  .archive h2 { font-size: 28px; }
  .archive-stamp { font-size: 13px; letter-spacing: 3px; }
}
