/* 视口只负责取景，所有绘制与命中仍属于原有 scene。 */
.scene-viewport { position: absolute; inset: 0; z-index: -3; }
.scene-viewport .scene { z-index: 0; }
.hero:has(#water:focus-visible) .scene-objects-hint { opacity: 0; }
.hero:has(#scene-objects button:focus-visible) .scene-objects-hint { opacity: 1; }
.hero:has(#scene-objects button:focus-visible) .island-whisper { opacity: 0; transition: none; }
.view-toggle { left: auto; right: max(20px, env(safe-area-inset-right)); letter-spacing: .08em; }
body.is-exploring .site-header { display: none; }

@media (max-width: 1200px) {
  .scene-viewport { position: relative; inset: auto; aspect-ratio: 1.56; width: 100%; }
  /* 中屏也按文案实际占高，避免固定留白在手机断点突然收缩。 */
  .hero:not(.is-exploring), :lang(en) .hero:not(.is-exploring) {
    --hero-controls-space: 72px;
    display: flex;
    flex-direction: column;
    padding-top: 0;
    padding-bottom: var(--hero-controls-space);
  }
  .hero:not(.is-exploring) .hero-copy, :lang(en) .hero:not(.is-exploring) .hero-copy {
    position: relative;
    order: -1;
    inset: auto;
    margin: 32px 6% 30px;
  }
  .hero-copy h1, .hero-copy .hero-description {
    -webkit-text-stroke: 0;
    text-shadow: none;
    paint-order: normal;
  }
  .hero:not(.is-exploring) .scene-viewport { flex: none; }
  .hero:not(.is-exploring):has(.scene-noscript) { --hero-controls-space: 0px; padding-bottom: 0; }
  /* 失败说明可能包含多个原因，按文字实际高度排布，避免窄屏盖住场景或按钮。 */
  .hero:not(.is-exploring)[data-renderer="static"]:has(.water-hint:not([hidden])) { padding-bottom: 0; }
  .hero:not(.is-exploring)[data-renderer="static"] .hero-bottom:has(.water-hint:not([hidden])) {
    position: relative;
    inset: auto;
    min-height: var(--hero-controls-space);
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 20px;
    padding: 12px 16px;
    background: var(--panel);
  }
  .hero:not(.is-exploring)[data-renderer="static"] .water-hint { flex: 1 1 220px; max-width: none; font-size: 13px; line-height: 1.7; }
  body.is-exploring .hero {
    position: fixed;
    inset: 0;
    z-index: 11;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100svh;
    min-height: 0;
    max-height: none;
    border: 0;
  }
  .hero.is-exploring .scene-viewport {
    position: absolute;
    inset: 0;
    height: 100%;
    aspect-ratio: auto;
    overflow: hidden;
  }
  .hero.is-exploring .scene { position: relative; width: 100%; height: 100%; aspect-ratio: auto; }
  /* 静态镜头直接作用于原画和灯层，避免整层缩放产生额外滚动边界。 */
  .hero.is-exploring[data-renderer="static"] .scene { transform: none; }
  .hero.is-exploring[data-renderer="static"] :is(.scene-backdrop, .scene-lighting) { --scene-zoom: 1.1832; }
  .hero.is-exploring .hero-bottom { color: #f9f4dc; bottom: max(16px, env(safe-area-inset-bottom)); }
  .hero.is-exploring .scene-control:hover { color: #fff9e4; }
  .hero.is-exploring .scene-controls { background: rgb(40 37 35 / .68); padding-inline: 12px; }
  .hero.is-exploring .water-hint { color: #f9f4dc; text-shadow: 0 1px 4px #27242b; }
  .hero.is-exploring .island-whisper {
    bottom: 18%;
    color: #f5f2df;
    text-shadow: 0 1px 8px #27242b;
    font-size: clamp(16px, 2.8vw, 22px);
  }
  .hero.is-exploring .keyboard-hint { bottom: 72px; }
}

/* 深色底随真实场景取景露出；不改文案盒子，保留底部控件的纸色区域。 */
.hero:not(.is-exploring)::before {
  content: "";
  position: absolute;
  inset: 0 0 var(--hero-controls-space);
  z-index: -4;
  background: var(--hero-title-panel);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease-out;
}
@media (max-width: 1200px) {
  .hero:not(.is-exploring)::before { opacity: 1; }
}
.hero[data-layout-transition]:not(.is-exploring)::before { opacity: 1; }

/* 短暂固定到目标布局的真实盒子，再补间位置与高度；绘制层不做独立缩放。 */
:root.is-layout-transitioning { overflow-anchor: none; }
.is-layout-transitioning .site-header { min-height: 0; }
.hero[data-layout-transition] { min-height: 0; max-height: none; }
.hero[data-layout-transition] > .scene-viewport {
  position: absolute;
  inset: auto 0 auto;
  top: var(--layout-scene-top);
  height: var(--layout-scene-height);
  aspect-ratio: auto;
}
.hero[data-layout-transition] .scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}
:root .hero[data-layout-transition] .hero-copy {
  position: absolute;
  inset: auto;
  top: var(--layout-copy-top);
  left: var(--layout-copy-left);
  width: var(--layout-copy-width);
  margin: 0;
}
.hero-copy h1, .hero-copy .hero-description {
  transition: color .28s ease-out, text-shadow .28s ease-out,
    -webkit-text-stroke-color .28s ease-out, -webkit-text-stroke-width .28s ease-out;
}

@media (max-width: 1200px) and (orientation: portrait) {
  .hero[data-detail-view="true"] .scene-viewport {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    touch-action: pan-x pinch-zoom;
    scrollbar-width: thin;
    scrollbar-color: #a89888 #514b45;
  }
  .hero[data-detail-view="true"] .scene-viewport::-webkit-scrollbar { height: 4px; }
  .hero[data-detail-view="true"] .scene { width: calc(100svh * 1.56); min-width: 100%; height: 100%; }
  .hero[data-detail-view="true"] :is(#water, .window-light-button, .door-button, .pier-lamp-button) { touch-action: pan-x pinch-zoom; }
  .hero[data-overview="true"] .scene-viewport { display: flex; align-items: center; }
  .hero[data-overview="true"] .scene { flex: none; width: 100%; height: auto; aspect-ratio: 1.56; }
  .hero[data-overview="true"] .island-whisper { bottom: calc((100svh - 100vw / 1.56) / 2 + 16px); }
  .hero[data-overview="true"] .hero-bottom { color: var(--ink); }
  .hero[data-overview="true"] .water-hint { color: var(--ink); text-shadow: none; }
  .hero[data-overview="true"] .scene-controls { background: none; padding: 0; }
  .hero[data-overview="true"] .scene-control:hover { color: var(--ink); }
}

@media (max-width: 1200px) and (orientation: landscape) {
  .hero.is-exploring .scene-viewport { display: flex; justify-content: center; }
  .hero.is-exploring .scene { flex: none; width: min(100%, calc(100svh * 1.56)); height: 100%; }
}

@media (max-width: 640px) {
  /* 标题按实际内容占高，中英文都不再用大块固定上内边距垫出空白。 */
  .hero:not(.is-exploring), :lang(en) .hero:not(.is-exploring) { --hero-controls-space: 68px; display: flex; flex-direction: column; padding-top: 0; padding-bottom: var(--hero-controls-space); }
  .hero:not(.is-exploring) .hero-copy, :lang(en) .hero:not(.is-exploring) .hero-copy { position: relative; order: -1; inset: auto; margin: 24px 20px 30px; }
  .hero:not(.is-exploring) .scene-viewport { flex: none; }
  .hero:not(.is-exploring) .explore-button { position: static; margin-top: 22px; }
  :root:lang(zh) .hero:not(.is-exploring) .explore-button { position: absolute; margin-top: 0; right: 0; bottom: 0; }
  :root:lang(zh) .hero:not(.is-exploring) .hero-description { max-width: calc(100% - 148px); }
  :lang(en) .hero:not(.is-exploring) { --hero-controls-space: 84px; }
  :lang(en) .hero.is-exploring .hero-bottom { flex-direction: row; align-items: center; }
  .hero.is-exploring .return-button { top: max(16px, env(safe-area-inset-top)); }
  .hero.is-exploring .view-toggle { left: auto; right: max(16px, env(safe-area-inset-right)); }
}
