:root {
  --pink: #ff6b9d;
  --pink2: #ffc2d4;
  --text: #fff7fb;
  --muted: #c9a8b6;
  --snap: 44px;
  --board: min(70vw, 300px);
  --tray-min: 260px;
  --stage-w: min(94vw, 520px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  font-family: "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: #0a0610;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

.stage {
  position: relative; z-index: 1;
  min-height: 100vh;
  display: none; flex-direction: column;
}
.stage.active { display: flex; }
.page-roam .stage-roam.active {
  position: fixed;
  inset: 0;
  display: block;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.btn {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 10px 16px; font-size: 0.9rem; cursor: pointer; color: #fff;
  background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.2);
  backdrop-filter: blur(10px);
}
.btn.primary { background: linear-gradient(135deg, #ff6b9d, #ff8f70); color: #2a1018; font-weight: 650; border: 0; }
.btn.ghost { background: rgba(0,0,0,0.3); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* —— Cover / 多页跳转 —— */
body { opacity: 1; }
.page-cover { overflow: hidden; }
.page-puzzle { min-height: 100%; overflow: auto; }
.page-roam {
  height: 100%;
  overflow: hidden;
}

.cover-scene { position: fixed; inset: 0; overflow: hidden; z-index: 1; }
.cover-scene .layer {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  will-change: transform;
}
.cover-scene .bg { filter: blur(12px) brightness(0.55); }
.cover-scene .mid { filter: brightness(0.85); }

.start-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 100;
  padding: 24px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.main-title {
  margin: 0 0 10px;
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

.sub-title {
  margin: 0 0 12px;
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  color: var(--pink2);
}

.hint {
  margin: 0 0 30px;
  font-size: 0.95rem;
  color: rgba(255, 230, 240, 0.7);
  max-width: 22em;
  line-height: 1.5;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
  margin-bottom: 20px;
}

.demo-btn { margin-top: 4px; }

@media (max-width: 480px) {
  .main-title { font-size: 2rem; }
  .sub-title { font-size: 1.05rem; margin-bottom: 8px; }
  .hint { margin-bottom: 22px; font-size: 0.85rem; }
  .buttons { gap: 10px; }
}

/* —— Puzzle —— */
.stage-puzzle { padding: 12px 14px 20px; overflow: auto; }
.bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: flex-start; }
.bar h2 { margin: 0; font-size: 1.35rem; }
.bar p { margin: 4px 0 0; color: var(--muted); font-size: 0.88rem; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: rgba(0,0,0,0.28); border: 1px solid rgba(255,255,255,0.12); }
.seg-btn { border: 0; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 999px; cursor: pointer; }
.seg-btn.active { background: rgba(255,107,157,0.28); color: #fff; }
.progress { margin: 8px 0; color: var(--pink2); min-height: 1.3em; }
.stage-wrap { display: flex; justify-content: center; }

.p-stage {
  position: relative; width: var(--stage-w);
  height: calc(12px + var(--board) + 30px + var(--tray-min));
  border-radius: 18px; overflow: hidden;
  background: #120c14;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(255,194,212,0.22);
  touch-action: none;
}
.p-stage[data-n="3"] { --tray-min: 200px; --board: min(68vw, 290px); }
.p-stage[data-n="4"] { --tray-min: 260px; --board: min(66vw, 290px); }
.p-stage[data-n="5"] { --tray-min: 340px; --board: min(62vw, 270px); }

.p-grid {
  position: absolute; left: 50%; top: 12px; width: var(--board); height: var(--board);
  transform: translateX(-50%); display: grid; pointer-events: none; z-index: 1;
  border-radius: 12px; overflow: hidden; background: #1a1220;
  box-shadow: inset 0 0 0 2px rgba(255,194,212,0.4);
}
.p-grid::before {
  content: "把碎片拖到格子里"; position: absolute; inset: 0; display: grid; place-items: center;
  color: rgba(255,194,212,0.25); font-size: 13px; z-index: 0;
}
.slot {
  position: relative; z-index: 1; border: 1.5px dashed rgba(255,194,212,0.5);
  background: repeating-linear-gradient(-45deg, rgba(255,107,157,0.04), rgba(255,107,157,0.04) 6px, rgba(255,255,255,0.02) 6px, rgba(255,255,255,0.02) 12px);
}
.slot::after { content: attr(data-label); position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; color: rgba(255,194,212,0.28); }
.slot.ghosting {
  border-style: solid; border-color: rgba(255,194,212,0.85);
  background-size: cover !important; background-position: center !important;
  box-shadow: inset 0 0 0 999px rgba(20,10,18,0.45);
}
.slot.ghosting::after { content: ""; }
.slot.hot { border-color: #ffc2d4; box-shadow: inset 0 0 18px rgba(255,107,157,0.4); }

.p-tray-hint {
  position: absolute; left: 0; right: 0; top: calc(12px + var(--board)); height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,194,212,0.5); font-size: 12px; pointer-events: none; z-index: 1;
}
.p-tray {
  position: absolute; left: 8px; right: 8px; top: calc(12px + var(--board) + 30px); bottom: 8px;
  border-radius: 12px; border: 1px dashed rgba(255,194,212,0.2); pointer-events: none; z-index: 0;
}
.p-pieces { position: absolute; inset: 0; z-index: 2; }
.piece {
  position: absolute; left: 0; top: 0; border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.9); cursor: grab; touch-action: none;
  box-shadow: 0 8px 18px rgba(0,0,0,0.4); will-change: transform; background: #1a1018;
}
.piece canvas { display: block; width: 100%; height: 100%; border-radius: 4px; pointer-events: none; }
.piece.dragging {
  cursor: grabbing; z-index: 999 !important; opacity: 0.85;
  box-shadow: 0 22px 40px rgba(0,0,0,0.6), 0 0 0 2px rgba(255,194,212,0.9);
}
.piece.correct { border-color: transparent; border-radius: 0; box-shadow: none; pointer-events: none; }
.piece.merged { opacity: 0 !important; border: 0 !important; transition: opacity 0.45s ease; }
.piece.pop { animation: pop 0.42s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.piece.shake { animation: shake 0.38s ease; }
@keyframes pop { 0% { filter: brightness(2); } 100% { filter: brightness(1); } }
@keyframes shake {
  0%,100% { margin-left: 0; } 20% { margin-left: -7px; } 40% { margin-left: 7px; }
  60% { margin-left: -5px; } 80% { margin-left: 5px; }
}

.p-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1000; }
.p-full {
  position: absolute; left: 50%; top: 12px; width: var(--board); height: var(--board);
  transform: translateX(-50%) scale(0.98); border-radius: 12px; background-size: cover; background-position: center;
  opacity: 0; z-index: 4; pointer-events: none; transition: opacity 0.55s ease, transform 0.55s ease;
}
.p-full.show { opacity: 1; transform: translateX(-50%) scale(1); animation: breatheFull 2.8s ease-in-out 0.5s infinite; }
@keyframes breatheFull {
  0%,100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.03); }
}

.p-peek {
  position: absolute; left: 50%; top: 12px; width: var(--board); height: var(--board);
  transform: translateX(-50%); z-index: 8; border-radius: 12px; overflow: hidden; display: none;
}
.p-peek.show { display: block; }
.p-peek-photo { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0.75; }
.p-peek-timer {
  position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,0.45); display: grid; place-items: center; font-weight: 700;
}

.p-celebrate {
  position: absolute; inset: 0; z-index: 10; display: none; align-items: flex-end; justify-content: center;
  padding: 0 16px 18px; pointer-events: none;
}
.p-celebrate.show { display: flex; }
.p-banner {
  width: min(92%, 360px); text-align: center; padding: 16px 18px; border-radius: 16px;
  background: rgba(20,10,18,0.55); border: 1px solid rgba(255,194,212,0.35);
  backdrop-filter: blur(10px); opacity: 0; transform: translateY(20px) scale(0.9); pointer-events: auto;
}
.p-celebrate.show .p-banner.ready { animation: bannerIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
@keyframes bannerIn {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.done-title { margin: 0; font-size: 1.45rem; color: var(--pink2); }
.done-line { margin: 10px 0 14px; color: #ffe6ef; line-height: 1.5; }
.p-banner .row, .p-banner .btn { margin: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 999px; background: rgba(20,10,18,0.9);
  border: 1px solid rgba(255,107,157,0.45); z-index: 50; pointer-events: none;
}

/* —— Roam —— */
.stage-roam { display: none; }
.stage-roam.active { display: block; }
.roam-scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 56px 72px 72px;
  background: radial-gradient(ellipse at center, #1a1024 0%, #0a0610 70%);
}
.roam-scene .frame { z-index: 3; }

/* 方案一：极光 / 光晕铺满空隙 */
.ambient-glow {
  position: absolute;
  inset: -12%;
  z-index: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(56px) saturate(1.25) brightness(0.55);
  opacity: 0.9;
  transform: scale(1.15);
  pointer-events: none;
  transition: background-image 0.45s ease, opacity 0.45s ease;
}
.ambient-glow::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(255, 140, 100, 0.18), transparent 55%),
    radial-gradient(ellipse at 70% 60%, rgba(180, 120, 255, 0.12), transparent 50%),
    linear-gradient(180deg, rgba(8, 4, 12, 0.15), rgba(8, 4, 12, 0.55));
  pointer-events: none;
}

/* 方案三：两侧画廊留白 */
.gallery-side {
  position: absolute;
  top: 22%;
  bottom: 22%;
  z-index: 6;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  pointer-events: none;
  opacity: 0.72;
}
.gallery-left { left: 18px; }
.gallery-right { right: 18px; }
.gallery-vert {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.35em;
  font-size: 0.72rem;
  font-weight: 500;
  color: rgba(255, 230, 240, 0.55);
  text-transform: uppercase;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
.gallery-vert.soft { color: rgba(255, 194, 212, 0.38); letter-spacing: 0.42em; }
.gallery-rail {
  width: 2px;
  height: min(28vh, 220px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
  position: relative;
}
.gallery-rail-fill {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 30%;
  border-radius: inherit;
  background: linear-gradient(180deg, #ffc2d4, #ff6b9d);
  box-shadow: 0 0 12px rgba(255, 107, 157, 0.55);
  transition: height 0.35s ease;
}
.gallery-index {
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  color: rgba(255, 230, 240, 0.5);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.frame {
  position: relative;
  width: min(100%, 920px);
  height: 100%;
  max-height: calc(100vh - 140px);
  overflow: hidden;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 24px 60px rgba(0, 0, 0, 0.45);
  transition: width 0.3s ease, height 0.3s ease, max-height 0.3s ease, border-radius 0.3s ease;
}
.roam-scene.fit-cover .frame {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 128px);
  border-radius: 0;
  box-shadow: none;
}
.roam-scene.fit-cover .gallery-side { opacity: 0; }
.roam-scene.fit-cover .ambient-glow { opacity: 0.45; filter: blur(40px) saturate(1.1) brightness(0.4); }
.breathe {
  position: absolute; inset: 0; transform-origin: center;
  animation: breathe 6s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.025); } }
.roam-scene .layer {
  position: absolute; inset: 0;
  background-position: center;
  background-repeat: no-repeat;
  will-change: transform;
  transition: background-size 0.3s ease, filter 0.3s ease, opacity 0.3s ease;
}
/* 方法二：bg / mid / 人物 同一套 size + position，画布同尺寸才能严丝合缝 */
.roam-scene.fit-contain .layer.bg,
.roam-scene.fit-contain .layer.mid,
.roam-scene.fit-contain .person-float {
  background-size: contain;
  background-position: center center;
}
.roam-scene.fit-cover .layer.bg,
.roam-scene.fit-cover .layer.mid,
.roam-scene.fit-cover .person-float {
  background-size: cover;
  background-position: center center;
}
.roam-scene .bg { filter: blur(6px) brightness(0.8); z-index: 1; }
.roam-scene .mid { z-index: 2; }

/* 方法三：有人物但无干净背景时，适度模糊，不要过度放大，留出脚底地面 */
.roam-scene.has-person:not(.has-clean-bg) .bg {
  filter: blur(14px) brightness(0.58) saturate(0.88);
}
.roam-scene.has-person:not(.has-clean-bg) .mid {
  filter: blur(7px) brightness(0.68) saturate(0.92);
  opacity: 0.62;
}
.roam-scene.has-person.has-clean-bg .bg {
  filter: blur(6px) brightness(0.78);
}
.roam-scene.has-person.has-clean-bg .mid {
  filter: blur(0.5px) brightness(0.95);
  opacity: 1;
}

.roam-scene .person {
  z-index: 3;
  background: none;
  pointer-events: none;
  /* 整层略上提，脚不贴底，影子有落点 */
  --person-lift: -2.5%;
}
.roam-scene .person[hidden] { display: none !important; }

/* 方法一：脚底椭圆落地阴影 */
.ground-shadow {
  position: absolute;
  left: 50%;
  bottom: 9%;
  width: min(44%, 300px);
  height: clamp(20px, 3.8vw, 38px);
  translate: -50% 0;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.28) 38%,
    rgba(0, 0, 0, 0.08) 62%,
    transparent 78%
  );
  filter: blur(3px);
  pointer-events: none;
  z-index: 0;
  transform-origin: center center;
  animation: shadowBreath 5.5s ease-in-out infinite;
}
@keyframes shadowBreath {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(0.86); opacity: 0.62; }
}

.person-float {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-position: center center;
  background-repeat: no-repeat;
  /* 黑底抠图：亮部保留人物 */
  mix-blend-mode: lighten;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.28));
  animation: personFloat 5.5s ease-in-out infinite;
  transform-origin: center bottom;
  transition: background-size 0.3s ease, filter 0.3s ease, opacity 0.3s ease;
}
.roam-scene.has-clean-bg .person-float {
  mix-blend-mode: normal;
}
@keyframes personFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.veil {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(8,4,12,0.5) 100%);
}
.dust { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }

.hud { position: absolute; z-index: 10; pointer-events: none; }
.hud.top { left: 20px; top: 18px; text-shadow: 0 2px 16px rgba(0,0,0,0.5); }
.hud.top h1 { margin: 0; font-size: 1.5rem; }
.hud.top p { margin: 6px 0 0; color: var(--pink2); font-size: 0.88rem; }
.hud.controls {
  right: 14px; top: 14px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end;
  pointer-events: auto; max-width: 60vw;
}
.hud.dots {
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex; gap: 8px; pointer-events: auto;
  padding: 8px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  z-index: 20;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.35); cursor: pointer;
  flex-shrink: 0;
}
.dot.active { background: #ffc2d4; transform: scale(1.35); box-shadow: 0 0 10px rgba(255,194,212,0.7); }
.hud.hint {
  left: 50%;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  color: rgba(255,230,240,0.5);
  font-size: 0.8rem;
  transition: opacity 0.5s;
  z-index: 20;
}
.hud.hint.hide { opacity: 0; }

@media (max-width: 480px) {
  :root { --snap: 56px; }
  .p-stage[data-n="5"] { --tray-min: 240px; }
  .hud.controls { max-width: 58vw; }
  .btn { padding: 8px 11px; font-size: 0.78rem; }
}

/* 手机竖屏：两侧字会挤到照片上 → 隐藏；全身照用 contain 防切脸；空隙靠光晕填满 */
@media (max-width: 768px) {
  .roam-scene {
    padding: 0;
  }

  /* 1. 隐藏两侧英文 / 进度条，避免挤进照片 */
  .gallery-side {
    display: none !important;
  }

  /* 2. 相框铺满可视区 */
  .roam-scene.fit-contain .frame,
  .roam-scene.fit-cover .frame {
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
  }

  /* 3. 手机默认 contain：人完整；上下空隙由光晕填，不切脸 */
  .roam-scene.fit-contain .layer.bg,
  .roam-scene.fit-contain .layer.mid,
  .roam-scene.fit-contain .person-float,
  .roam-scene.fit-cover .layer.bg,
  .roam-scene.fit-cover .layer.mid,
  .roam-scene.fit-cover .person-float {
    background-size: contain;
    background-position: center center;
  }

  .ambient-glow {
    inset: -18%;
    opacity: 0.95;
    filter: blur(64px) saturate(1.35) brightness(0.62);
    transform: scale(1.25);
  }

  /* 4. 顶栏按钮更紧凑，允许换行 */
  .hud.top {
    left: 10px;
    top: 10px;
    max-width: 42vw;
  }
  .hud.top h1 { font-size: 1.05rem; }
  .hud.top p { display: none; }
  .hud.controls {
    right: 8px;
    top: 8px;
    max-width: 56vw;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .hud.controls .btn {
    padding: 7px 10px;
    font-size: 0.72rem;
  }
  .desktop-only {
    display: none !important;
  }
}
