:root {
  --art-w: 5337;
  --art-h: 3300;
  --viewport-h: 100svh;
  --stage-w: min(100vw, calc(var(--viewport-h) * var(--art-w) / var(--art-h)));
  --stage-h: calc(var(--stage-w) * var(--art-h) / var(--art-w));
  --scene-scale: 0.95; /* Increased from 0.82 to reduce border thickness */
}

* { box-sizing: border-box; }

.orientation-hint {
  display: none;
}

@media (orientation: portrait) {
  body.is-gated .orientation-hint {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    width: auto;
    max-width: none;
    padding: 32px;
    color: #fff;
    text-align: center;
    background: rgba(12, 13, 15, .72);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: none;
  }

  body.is-gated .gate-art {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .orientation-hint strong {
    display: block;
    font-size: clamp(25px, 7vw, 36px);
    line-height: 1.2;
    letter-spacing: .08em;
  }

  .orientation-hint-copy span {
    display: block;
    margin-top: 8px;
    color: rgba(255, 255, 255, .74);
    font-size: clamp(15px, 4vw, 19px);
    letter-spacing: .12em;
  }

  .orientation-phone {
    position: relative;
    flex: 0 0 auto;
    width: 56px;
    height: 96px;
    border: 5px solid #fff;
    border-radius: 13px;
    box-shadow: 0 0 0 8px rgba(255, 179, 49, .12), 0 16px 36px rgba(0, 0, 0, .35);
    transform-origin: center;
    animation: orientation-rotate 2.2s ease-in-out infinite;
  }

  .orientation-phone::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 6px;
    width: 17px;
    height: 4px;
    border-radius: 999px;
    background: #fff;
    transform: translateX(-50%);
  }

  .orientation-phone::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 6px;
    width: 7px;
    height: 7px;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translateX(-50%);
  }

  .orientation-phone-screen {
    position: absolute;
    left: 7px;
    right: 7px;
    top: 17px;
    bottom: 19px;
    border-radius: 4px;
    background: linear-gradient(145deg, #ffb531, #ef7100);
  }
}

@keyframes orientation-rotate {
  0%, 18% { transform: rotate(0deg); }
  45%, 72% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

html, body {
  width: 100%;
  height: var(--viewport-h);
  margin: 0;
  overflow: hidden;
  background: #d8cbb8;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.site-record {
  position: fixed;
  left: auto;
  right: max(6px, env(safe-area-inset-right));
  bottom: max(2px, env(safe-area-inset-bottom));
  z-index: 6000;
  padding: 2px 6px;
  font-size: 9px;
  line-height: 1.25;
  white-space: nowrap;
  opacity: .62;
  transform: none;
}

.site-record a {
  color: rgba(255, 255, 255, .9);
  text-decoration: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
}

.app, .stage-shell {
  position: relative;
  width: 100vw;
  height: var(--viewport-h);
  overflow: hidden;
}

.is-gated .app {
  pointer-events: none;
}

.experience-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  overflow: hidden;
  background: #f0c98e;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.experience-gate::before {
  content: "";
  position: absolute;
  inset: -28px;
  z-index: 0;
  background: url("./gate-background.jpg?v=1") center / cover no-repeat;
  filter: blur(7px) brightness(.76) saturate(.7);
  opacity: 1;
  transform: scale(1.035);
  transition: opacity 180ms ease;
  pointer-events: none;
}

.gate-art {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: min(94vw, calc(var(--viewport-h) * .9 * 5337 / 3300));
  aspect-ratio: 5337 / 3300;
  overflow: hidden;
  border-radius: clamp(8px, 1.2vw, 18px);
  box-shadow: 0 18px 55px rgba(38, 24, 10, .32);
  transform: translate(-50%, -50%);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.gate-art::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  pointer-events: none;
}

.gate-cover {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  filter: none;
  transform: none;
  user-select: none;
}

.gate-button {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 3;
  width: clamp(170px, 26%, 340px);
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
  animation: gate-button-pulse 1.5s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

.gate-button img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

.gate-button:active {
  animation: none;
  transform: translate(-50%, -50%) scale(.96);
}

.gate-button.is-launching {
  animation: gate-button-launch 680ms ease forwards;
}

.start-firework {
  position: absolute;
  z-index: 3;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.start-firework-particle {
  position: absolute;
  left: 0;
  top: 0;
  width: clamp(5px, .65vw, 10px);
  height: clamp(10px, 1.25vw, 19px);
  border-radius: 999px;
  background: var(--particle-color);
  box-shadow: 0 0 8px var(--particle-color);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(var(--particle-rotation)) scale(.2);
  animation: start-firework-burst 920ms cubic-bezier(.12, .62, .18, 1) var(--particle-delay) forwards;
}

.pointer-trail-spark {
  position: absolute;
  z-index: 4;
  width: clamp(6px, .7vw, 11px);
  height: clamp(6px, .7vw, 11px);
  border-radius: 50%;
  background: var(--spark-color);
  box-shadow: 0 0 6px var(--spark-color), 0 0 13px var(--spark-color);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1);
  animation: pointer-trail-fade 620ms ease-out forwards;
}

@keyframes gate-button-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.04); }
}

@keyframes gate-button-launch {
  0% { transform: translate(-50%, -50%) scale(1); }
  22% { transform: translate(-50%, -50%) scale(.93); }
  52% { transform: translate(-50%, -50%) scale(1.08); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes start-firework-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--particle-rotation)) scale(.2);
  }
  14% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--particle-rotation)) scale(1);
  }
  76% {
    opacity: 1;
    transform: translate(calc(-50% + var(--particle-x)), calc(-50% + var(--particle-y))) rotate(var(--particle-rotation)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--particle-x)), calc(-50% + var(--particle-y))) rotate(var(--particle-rotation)) scale(.35);
  }
}

@keyframes pointer-trail-fade {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--spark-x)), calc(-50% + var(--spark-y))) scale(.1);
  }
}

body:not(.is-gated) .experience-gate {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app::before {
  content: "";
  position: fixed;
  inset: -24px;
  z-index: 0;
  background: url("./game-background.jpg?v=1") center / cover no-repeat;
  filter: blur(7px) brightness(.76) saturate(.7);
  opacity: 1;
  transform: scale(1.035);
  pointer-events: none;
}

.stage-shell {
  z-index: 1;
  overscroll-behavior: contain;
}

.clue-counter {
  position: absolute; /* Changed from fixed to absolute to position relative to .stage */
  top: 1%; /* Use percentage so it scales with the stage */
  right: 1%;
  z-index: 500;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 10px 20px; /* Reduced padding */
  border-radius: 30px; /* Reduced border radius */
  font-size: 20px; /* Significantly reduced font size */
  font-weight: 500;
  letter-spacing: 1px; /* Reduced letter spacing */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* Reduced shadow */
  pointer-events: none;
  transition: opacity 0.5s ease;
  transform: translateZ(0); /* Force hardware acceleration */
}

.clue-counter span {
  color: #ffd700;
  font-size: 24px; /* Significantly reduced font size */
  font-weight: bold;
  margin: 0 4px;
}

.btn-summary {
  position: absolute; /* Changed from fixed to absolute */
  top: calc(1% + 50px); /* Moved down by 50px */
  right: 1%;
  z-index: 500;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #ccc; /* Reduced border */
  border-radius: 50%;
  width: 64px; /* Reduced dimensions */
  height: 64px;
  font-size: 32px; /* Reduced font size */
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2); /* Reduced shadow */
  transition: transform 0.2s ease, opacity 0.5s ease;
  animation: breathe 1.5s ease-in-out infinite;
  pointer-events: auto; /* Ensure it can be clicked even if inside a non-interactive layer initially */
}

.btn-summary:active {
  transform: scale(0.9);
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--stage-w);
  height: var(--stage-h);
  transform: translate(-50%, -50%) scale(var(--scene-scale));
  transform-origin: center;
  will-change: transform;
  contain: layout paint;
}

@media (orientation: portrait) {
  :root {
    --stage-h: 100vw;
    --stage-w: calc(var(--stage-h) * var(--art-w) / var(--art-h));
    --scene-scale: 1;
  }

  .app {
    height: var(--viewport-h);
  }

  .stage-shell {
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--viewport-h);
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
    overflow-x: hidden;
    overflow-y: hidden;
    touch-action: manipulation;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stage-shell::-webkit-scrollbar {
    display: none;
  }

  .stage {
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--stage-w);
    min-width: var(--stage-w);
    height: var(--stage-h);
    transform: translate(-50%, -50%);
  }

  .clue-counter {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
    max-width: calc(100vw - 20px);
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    line-height: 1.35;
    letter-spacing: 0;
  }

  .clue-counter span {
    font-size: 15px;
    margin: 0 2px;
  }

  .btn-summary {
    position: fixed;
    top: calc(max(10px, env(safe-area-inset-top)) + 42px);
    right: 10px;
    width: 48px;
    height: 48px;
    border-width: 2px;
    font-size: 24px;
  }

  .hotspot::after {
    width: 27px;
    height: 34px;
  }
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.bg-layer {
  z-index: 10;
  filter: none;
  transform: none;
}
.base-panel { z-index: 15; }
.base-doodle { z-index: 116; }
.prop-calendar { z-index: 20; }
.prop-desks {
  z-index: 115;
  filter: none;
  opacity: 1;
}
.char-girl-sitting { z-index: 40; animation: side-sway 3.4s ease-in-out infinite; will-change: transform; transform-origin: bottom center; }
.char-boy-sitting { z-index: 50; animation: side-sway 3.0s ease-in-out infinite; will-change: transform; transform-origin: bottom center; }
.char-xiaohong { z-index: 60; animation: tiny-tremble 2.4s linear infinite; will-change: transform; transform-origin: bottom center; opacity: 1; transition: opacity 0.5s ease; }
.char-xiaohong-2 { z-index: 60; animation: tiny-tremble 2.4s linear infinite; will-change: transform; transform-origin: bottom center; opacity: 0; transition: opacity 0.5s ease; }
.char-girl-ponytail { z-index: 70; animation: tiny-tremble 3.0s linear infinite; animation-delay: -.7s; will-change: transform; transform-origin: bottom center; }
.char-girl-short-hair { z-index: 80; animation: side-sway 3.4s ease-in-out infinite; animation-delay: -.9s; will-change: transform; transform-origin: bottom center; }
.char-observer { z-index: 25; opacity: 0.68; animation: float 4.4s ease-in-out infinite; will-change: transform; transform-origin: bottom center; }
.prop-backpack-gray { z-index: 125; }
.ui-phone-chat, .ui-panel-question-text,
.reveal-new, .reveal-bag,
.bubble-xiaohong-bg, .bubble-xiaohong-seq,
.bubble-right-bg, .bubble-right-seq,
.bubble-boy-bg, .bubble-boy-seq,
.effect-mist, .effect-hands,
.summary-1 {
  opacity: 0;
  transition: opacity 260ms ease, transform 320ms ease;
}

.is-visible { opacity: 1 !important; }
.is-frozen { animation: none !important; }

.ui-phone-chat { z-index: 200; }
.reveal-bag { z-index: 200; }
.reveal-new { z-index: 200; }
.ui-panel-question-text {
  z-index: 200;
  transform: translateY(-10px) scaleY(0.88);
  transform-origin: top center;
}

.ui-panel-question-text.is-visible {
  transform: translateY(0) scaleY(1);
}
.bubble-xiaohong-bg { z-index: 35; }
.bubble-xiaohong-seq { z-index: 36; }
.bubble-boy-bg { z-index: 34; }
.bubble-boy-seq { z-index: 35; }
.bubble-right-bg { z-index: 33; }
.bubble-right-seq { z-index: 34; }
.effect-mist { z-index: 200; }
.effect-hands { z-index: 201; }
.summary-1 { z-index: 180; }

.summary-1, .ui-phone-chat, .ui-panel-question-text,
.bubble-xiaohong-bg, .bubble-xiaohong-seq,
.bubble-right-bg, .bubble-right-seq,
.bubble-boy-bg, .bubble-boy-seq,
.effect-mist, .effect-hands {
  object-fit: fill;
}

.hotspot {
  position: absolute;
  z-index: 300;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hotspot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(26px, 2.2vw, 46px);
  height: clamp(33px, 2.75vw, 58px);
  border: 0;
  border-radius: 0;
  background: url("./hotspot-bulb.png?v=5") center / contain no-repeat;
  filter: drop-shadow(0 0 5px rgba(255, 196, 34, .7));
  transform: translate(-50%, -50%);
  animation: breathe 1.35s ease-in-out infinite;
}

.hotspot.is-pulsed::after {
  filter:
    drop-shadow(0 0 7px rgba(255, 255, 255, .95))
    drop-shadow(0 0 14px rgba(255, 196, 34, .85));
}

.hotspot.is-active::after {
  filter:
    drop-shadow(0 0 8px rgba(255, 255, 255, 1))
    drop-shadow(0 0 18px rgba(255, 137, 46, .95));
}

.hotspot-xiaohong { left: 61.85%; top: 76.84%; width: 7.5%; height: 9.0%; }
.hotspot-girl-short { left: 76.56%; top: 47.31%; width: 11.0%; height: 14.5%; }
.hotspot-girl-sitting { left: 20.43%; top: 67.84%; width: 7.5%; height: 8.8%; }
.hotspot-backpack { left: 39.8%; top: 83.22%; width: 8.2%; height: 12.5%; }
.hotspot-boy { left: 13.0%; top: 79.4%; width: 7.8%; height: 10.0%; }
.hotspot-table { left: 43.41%; top: 68.31%; width: 6.5%; height: 9.5%; }
.hotspot-new { left: 61.8%; top: 51.2%; width: 6.2%; height: 8.6%; }
.hotspot-scroll { left: 5.03%; top: 0.8%; width: 5.5%; height: 8.5%; }

/* 卷轴相关样式 */
.scroll-closed {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  font-size: 0;
  color: transparent;
  object-fit: contain;
}

.scroll-opened {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  object-fit: contain;
}

.app.scroll-shown .scroll-opened {
  opacity: 1;
  pointer-events: auto;
}

@keyframes breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(.85); }
  50% { transform: translate(-50%, -50%) scale(1.35); }
}
@keyframes sway {
  0%,100% { transform: rotate(0deg); }
  50% { transform: rotate(1deg); }
}
@keyframes side-sway {
  0%,100% { transform: rotate(0deg); }
  50% { transform: rotate(-1deg); }
}
@keyframes tiny-tremble {
  0%,100% { transform: rotate(0deg) translate3d(0, 0, 0); }
  25% { transform: rotate(0.5deg) translate3d(.04%, -.015%, 0); }
  50% { transform: rotate(0deg) translate3d(0, 0, 0); }
  75% { transform: rotate(-0.5deg) translate3d(-.04%, .015%, 0); }
}
@keyframes float {
  0%,100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-0.2%) rotate(0.5deg); }
}

@media (prefers-reduced-motion: reduce) {
  .char-girl-sitting,
  .char-boy-sitting,
  .char-xiaohong,
  .char-girl-ponytail,
  .char-girl-short-hair,
  .char-observer,
  .hotspot::after {
    animation: none;
  }
}

/* 手机微信 WebView 优先控制合成层与滤镜开销，避免点击热点时掉帧。 */
@media (pointer: coarse), (max-width: 1024px) {
  .experience-gate::before {
    filter: blur(7px) brightness(.72) saturate(.68);
    transform: scale(1.055);
  }

  .app::before {
    filter: blur(7px) brightness(.72) saturate(.68);
    transform: scale(1.055);
  }

  .orientation-hint,
  .clue-counter {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .stage {
    will-change: auto;
  }

  .layer {
    backface-visibility: visible;
    transform: none;
  }

  .bg-layer {
    filter: none;
    transform: none;
  }

  .char-girl-sitting,
  .char-boy-sitting,
  .char-xiaohong,
  .char-xiaohong-2,
  .char-girl-ponytail,
  .char-girl-short-hair,
  .char-observer {
    animation: none;
    will-change: auto;
  }

  .hotspot::after,
  .hotspot.is-pulsed::after,
  .hotspot.is-active::after {
    filter: none;
  }

  .hotspot::after {
    width: 27px;
    height: 34px;
  }
}

