:root {
  --bg: #5f7d96;
  --ink: #e8f0f7;
  --muted: #b4c7d8;
  --card: rgba(18, 28, 38, 0.72);
  --line: rgba(180, 210, 230, 0.28);
  --accent: #9ec7e8;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #4a657a;
  color: var(--ink);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  font-weight: 400;
  -webkit-text-size-adjust: 100%;
  touch-action: none;
}

body.is-locked { cursor: none; }
body.is-locked .back-link { opacity: 0; pointer-events: none; }
body.is-playing .back-link {
  opacity: 0.55;
}
body.is-touch.is-playing .back-link {
  opacity: 0.85;
  pointer-events: auto;
}

#gallery-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.back-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 30;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(12, 20, 28, 0.45);
  backdrop-filter: blur(8px);
  transition: opacity 0.25s ease, color 0.2s ease;
  touch-action: manipulation;
}
.back-link:hover { color: var(--ink); }

.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse at 50% 30%, rgba(130, 170, 200, 0.28), transparent 55%),
    rgba(28, 42, 55, 0.55);
  backdrop-filter: blur(10px);
  transition: opacity 0.45s ease, visibility 0.45s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.start-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.enter-card {
  width: min(440px, 100%);
  padding: 2rem 1.75rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 24px 60px rgba(8, 16, 24, 0.35);
  text-align: center;
}

.kicker {
  margin: 0 0 0.6rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--accent);
}

.overlay-title {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-weight: 600;
  font-size: clamp(1.85rem, 6vw, 2.6rem);
  letter-spacing: 0.12em;
}

.meta {
  margin: 0.85rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.overlay-sub {
  margin: 1rem auto 0;
  max-width: 28em;
  line-height: 1.7;
  color: #d5e3ef;
  font-size: 0.95rem;
}

.controls-hint {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  text-align: left;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.85;
}
.controls-hint li { padding-left: 0.1rem; }
.hint-mobile { display: none; }
body.is-touch .hint-desktop { display: none; }
body.is-touch .hint-mobile { display: block; }

kbd {
  display: inline-block;
  min-width: 1.35em;
  padding: 0.05em 0.35em;
  margin: 0 0.08em;
  border: 1px solid rgba(170, 200, 220, 0.35);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78em;
  text-align: center;
}

.enter-btn {
  margin-top: 1.4rem;
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  background: linear-gradient(180deg, #c5daf0, #9bb8d4);
  color: #1a2834;
  font: 500 0.95rem "Noto Sans SC", system-ui, sans-serif;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.enter-btn:hover { filter: brightness(1.05); }
.enter-btn:active { transform: scale(0.98); }

.fine {
  margin: 0.9rem 0 0;
  font-size: 0.78rem;
}
.fine a { color: var(--muted); touch-action: manipulation; }

.hud {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  max-width: calc(100vw - 2rem);
}
.hud.visible { opacity: 1; }
body.is-touch.is-playing .hud {
  bottom: max(168px, calc(env(safe-area-inset-bottom) + 148px));
}
.hud p {
  margin: 0;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background: rgba(12, 20, 28, 0.5);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 92vw;
  text-align: center;
}

/* Virtual joystick + look affordance */
.mobile-controls {
  display: none;
  pointer-events: none;
}
body.is-touch.is-playing .mobile-controls,
body.is-playing.force-mobile-controls .mobile-controls {
  display: block;
}
body.is-touch.is-playing.viewer-open .mobile-controls,
body.is-playing.viewer-open .mobile-controls {
  display: none;
}

/* 窄屏兜底：即使 JS 误判，进入展厅也显示轮盘 */
@media (max-width: 920px) {
  body.is-playing:not(.viewer-open) .mobile-controls {
    display: block;
  }
}

.joystick {
  position: fixed;
  left: max(18px, calc(env(safe-area-inset-left) + 8px));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 10px));
  z-index: 28;
  width: 132px;
  height: 132px;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(12, 20, 28, 0.55);
  border: 1.5px solid rgba(210, 230, 245, 0.55);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(6px);
}
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(210, 230, 245, 0.85), rgba(120, 160, 195, 0.55));
  border: 1px solid rgba(230, 242, 250, 0.45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  will-change: transform;
}

.look-affordance {
  position: fixed;
  right: max(22px, calc(env(safe-area-inset-right) + 10px));
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 36px));
  z-index: 27;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px dashed rgba(180, 210, 230, 0.28);
  background: rgba(12, 20, 28, 0.18);
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0.7;
  transition: opacity 0.6s ease;
}
.look-affordance span {
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: center;
  line-height: 1.3;
  padding: 0 0.3rem;
}
body.is-playing.look-active .look-affordance { opacity: 0; }

/* Inspect overlay — never exceeds viewport; object-fit contain */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  background: rgba(10, 16, 24, 0.82);
  backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  touch-action: manipulation;
}
.viewer.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.viewer-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  font-size: 1.65rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}

.viewer-frame {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: min(92vw, 1100px);
  max-height: min(90dvh, 90vh, 820px);
}

.viewer-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(92vw, 1100px);
  max-height: min(72dvh, 72vh, 720px);
  object-fit: contain;
  border-radius: 2px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  background: #111;
}

#viewer-caption {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.85rem;
  align-items: baseline;
  justify-content: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0 0.5rem;
}
#viewer-caption .num {
  font-family: "Cormorant Garamond", Georgia, serif;
  letter-spacing: 0.12em;
  color: var(--accent);
}
#viewer-caption strong {
  font-family: "Noto Serif SC", serif;
  font-weight: 600;
  color: var(--ink);
}
#viewer-caption .cap { font-weight: 300; }

@media (max-width: 480px) {
  .enter-card { padding: 1.5rem 1.2rem 1.25rem; }
  .joystick {
    width: 118px;
    height: 118px;
  }
  .joystick-knob {
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
  }
  .viewer-frame img {
    max-height: min(68dvh, 68vh);
  }
  #viewer-caption { font-size: 0.82rem; }
}

@media (prefers-reduced-motion: reduce) {
  .start-overlay,
  .hud,
  .viewer,
  .enter-btn,
  .look-affordance { transition: none; }
}
