body { overflow: hidden; }
.screen { position: relative; width: 100%; height: 100vh; height: 100dvh; overflow: hidden; }
.stage { display: flex; align-items: center; width: 100%; height: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.stage::-webkit-scrollbar { display: none; }
.room { flex: none; width: max(100%, 150vh); width: max(100%, 150dvh); border: 0; border-radius: 0; box-shadow: none; }
.screen-header { position: absolute; z-index: 4; inset: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 15px 22px; background: linear-gradient(#201321a6, transparent); pointer-events: none; }
.screen-header h1 { color: #fff2e1; padding: 7px 11px; border-radius: 8px; background: #261827d9; font-size: clamp(15px, 2vw, 22px); }
.screen-header button, .screen-controls button { pointer-events: auto; }
.screen-controls { position: absolute; z-index: 4; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 620px); padding: 0 10px max(10px, env(safe-area-inset-bottom)); pointer-events: none; }
.actions { margin: 0; }
.actions button { background-color: #312131ec; border-color: #b27b79; }
.actions button[aria-label="打开相册"] { min-width: 42px; }
.status:not(:empty) { width: max-content; max-width: 100%; margin: 0 auto 7px; padding: 4px 9px; border-radius: 6px; background: #251924e8; }
.photo-frame { left: 84%; top: 22%; width: 18.8%; height: 22%; transform: translate(-50%, -50%); padding: 0; overflow: hidden; border-radius: .55cqw; background: #67324b; box-shadow: 0 0 0 1px #ffe3a66b; }
.photo-frame img { width: 100%; height: 100%; object-position: 50% 35%; }
.photo-frame:hover { filter: brightness(1.1); }
#gallery { width: min(94vw, 1040px); max-height: 96dvh; padding: 48px 12px 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.photo-grid img { width: 100%; height: min(34dvh, 315px); display: block; object-fit: cover; object-position: 50% 36%; border-radius: 6px; background: #4c3443; }

/* On phones and portrait tablets, fit the scene before positioning its controls. */
@media (orientation: portrait) and (max-width: 1100px), (orientation: landscape) and (max-width: 1100px) and (max-height: 550px) {
  body { overflow: auto; }
  .screen {
    display: grid;
    grid-template-rows: auto minmax(min-content, 1fr) auto;
    height: auto;
    min-height: 100dvh;
    isolation: isolate;
  }
  .screen::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: -24px;
    background: linear-gradient(168deg, #211823a6, #211823ef), url("loft.png") center / cover;
    filter: blur(20px);
    pointer-events: none;
  }
  .screen-header {
    position: relative;
    grid-row: 1;
    padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
    background: #211823df;
    border-bottom: 1px solid #92636580;
  }
  .screen-header h1 { padding: 0; background: transparent; font-size: clamp(16px, 4.4vw, 24px); }
  .stage {
    grid-row: 2;
    height: auto;
    align-self: center;
    justify-content: center;
    overflow: visible;
  }
  .room { width: 100%; }
  .art { object-fit: contain; }
  .marker { width: clamp(24px, 6.5cqw, 42px); }
  .screen-controls {
    position: relative;
    grid-row: 3;
    left: auto;
    transform: none;
    justify-self: center;
    width: min(100%, 540px);
    padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    border: 1px solid #96637080;
    border-radius: 13px;
    background: #211823e8;
  }
  .actions button { min-height: 46px; font-size: 14px; }
  .actions button[aria-label="打开相册"] span { margin-right: .45em; }
  .actions button[aria-label="打开相册"]::after { content: "相册"; }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 550px) {
  .screen-header { padding-top: max(3px, env(safe-area-inset-top)); padding-bottom: 3px; }
  .screen-header h1 { font-size: 16px; }
  .screen-header .records-button { min-height: 36px; }
  .room { width: min(100%, max(290px, calc((100dvh - 120px) * 1.5))); }
  .screen-controls { padding-top: 4px; padding-bottom: max(5px, env(safe-area-inset-bottom)); }
  .screen-controls .status:not(:empty) { position: absolute; z-index: 1; bottom: 100%; left: 50%; transform: translateX(-50%); }
  .actions { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 4px; gap: 5px; }
  .actions button { min-height: 42px; padding-inline: 5px; font-size: 12px; }
}

@media (max-width: 640px) {
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-grid img { height: min(24dvh, 225px); }
}

@media (orientation: portrait) and (max-width: 1100px) {
  .screen { grid-template-rows: repeat(3, auto); align-content: start; }
  .stage { margin-top: clamp(10px, 2.8dvh, 22px); }
  .screen-controls { padding-top: 14px; }
  .screen::before {
    background: linear-gradient(165deg, #2118237a, #211823e8 76%), url("loft.png") center 60% / cover;
    filter: blur(27px);
  }
}
