/* Source Han Sans 2.005R，版权与 SIL OFL 1.1 见 fonts/LICENSE.txt、fonts/NOTICE.txt。 */
@font-face {
  font-family: "Source Han Sans CN";
  src: url("./fonts/SourceHanSansCN-VF.ttf.woff2") format("woff2");
  font-style: normal;
  font-weight: 250 900;
  font-display: swap;
}

:root {
  --ink: #2B2D42;
  --ink-60: rgba(43, 45, 66, 0.60);
  --ink-45: rgba(43, 45, 66, 0.45);
  --ink-22: rgba(43, 45, 66, 0.22);
  --shadow: rgba(43, 45, 66, 0.14);
  --shadow-8: rgba(43, 45, 66, 0.08);
  --cream: #FFF7EC;
  --white: #FFFFFF;
  --coral: #FF6B6B;
  --yellow: #FFD166;
  --mint: #06D6A0;
  --purple: #7B4DFF;
  --sidebar-accent: #E8642C;
  --sky: #4CC9F0;
  --night: #3A4A86;
  --font-stack: "Source Han Sans CN", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--cream);
  font-family: var(--font-stack);
  color: var(--ink);
}

button { font-family: var(--font-stack); color: var(--ink); }

/* 宽屏背景：奶油白底 + 左上黄光晕 + 右下天蓝光晕（A§2.4） */
#app-wrapper {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 12% 15%, rgba(255, 209, 102, 0.35) 0%, rgba(255, 209, 102, 0) 48%),
    radial-gradient(circle at 88% 85%, rgba(76, 201, 240, 0.25) 0%, rgba(76, 201, 240, 0) 48%),
    var(--cream);
}

/* 舞台：画布铺满容器，绘制时按内容安全区等比放入 1080×1920 坐标并多铺背景；DOM 层同比缩放（见 app.js resize） */
#stage-frame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFE3CC;
}

@media (min-width: 900px) and (orientation: landscape) {
  #stage-frame {
    width: calc(100vh * 9 / 16);
    height: 100vh;
    border-left: 3px solid var(--ink);
    border-right: 3px solid var(--ink);
    box-shadow: 0 12px 36px rgba(43, 45, 66, 0.10);
    flex-shrink: 0;
  }
}

#stage-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

#dom-layer {
  position: absolute;
  width: 1080px;
  height: 1920px;
  flex-shrink: 0;
  transform-origin: center center;
  z-index: 2;
  pointer-events: none;
}

.interactive-el { pointer-events: auto; }

/* 主体和操作热区共用位移，顶栏、字幕和暂停层保持各自锚点。 */
#scene-layer {
  position: absolute;
  inset: 0;
  transform: translateY(var(--scene-dy, 0px));
  pointer-events: none;
}

/* 键盘焦点圈：只在键盘操作时显示（A§13.1） */
body.using-keyboard .focusable:focus-visible {
  outline: 6px dashed var(--purple) !important;
  outline-offset: 6px !important;
}
.focusable:focus { outline: none; }

/* 左上品牌条（顶栏各项随 --hud-dy 贴住可见顶边，由 app.js 设置） */
#brand-bar {
  position: absolute;
  left: 80px;
  top: calc(82px + var(--hud-dy, 0px));
  height: 70px;
  background: var(--cream);
  border: 3px solid var(--ink-22);
  border-radius: 35px;
  box-shadow: 0 5px 0 var(--shadow-8);
  display: flex;
  align-items: center;
  padding: 0 22px 0 13px;
  gap: 12px;
}
#brand-logo {
  width: 44px;
  height: 44px;
  display: block;
  object-fit: contain;
  flex-shrink: 0;
}
#brand-text {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
#top-subtitle {
  position: absolute;
  left: 400px;
  top: calc(99px + var(--hud-dy, 0px));
  font-size: 28px;
  font-weight: 500;
  color: var(--ink-60);
}

#mute-btn {
  position: absolute;
  right: 80px;
  top: calc(59px + var(--hud-dy, 0px));
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: var(--white);
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
#mute-btn:active { transform: translateY(5px); box-shadow: 0 4px 0 var(--shadow); }

#skip-btn {
  position: absolute;
  right: 80px;
  top: calc(220px + var(--hud-dy, 0px));
  height: 64px;
  padding: 0 28px;
  border-radius: 32px;
  background: var(--white);
  border: 4px solid var(--ink);
  box-shadow: 0 6px 0 var(--shadow);
  font-size: 34px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 3;
}
#skip-btn.visible { display: flex; animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
#skip-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--shadow); }

/* 封面 */
#cover-ui {
  position: absolute;
  left: 0;
  top: 1120px;
  width: 1080px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}
#start-btn {
  min-width: 440px;
  height: 128px;
  padding: 0 56px;
  border-radius: 64px;
  background: var(--coral);
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  color: var(--white);
  font-size: 60px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
#start-btn:disabled { background: #C9CED8; cursor: wait; }
#start-btn:not(:disabled):active { transform: translateY(5px); box-shadow: 0 4px 0 var(--shadow); }
.play-triangle {
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-left: 32px solid var(--white);
  display: inline-block;
}
#cover-sound-tip {
  font-size: 34px;
  font-weight: 500;
  color: var(--ink-60);
  background: rgba(255, 255, 255, 0.78);
  padding: 10px 28px;
  border-radius: 28px;
  border: 3px solid var(--ink-22);
}

/* 操作提示条 */
#prompt-pill {
  position: absolute;
  left: 50%;
  top: 1045px;
  transform: translateX(-50%);
  height: 68px;
  padding: 0 36px;
  background: var(--yellow);
  border: 4px solid var(--ink);
  border-radius: 34px;
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 38px;
  font-weight: 700;
  white-space: nowrap;
  display: none;
  align-items: center;
  z-index: 3;
}
#prompt-pill.visible { display: flex; animation: popInCenter 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }

/* 互动控件默认隐藏 */
.ctl { display: none; }
.ctl.visible { display: flex; }

/* 虚线热区：7px、墨色 45%，呼吸脉冲（A§7.5） */
.click-hotspot {
  position: absolute;
  border: 7px dashed var(--ink-45);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transform: translate(-50%, -50%);
}
.click-hotspot.visible { animation: hotspotPulse 1.3s infinite ease-in-out; }
@keyframes hotspotPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); border-color: rgba(43, 45, 66, 0.45); }
  50% { transform: translate(-50%, -50%) scale(1.06); border-color: var(--coral); }
}

/* ① 先猜：两张选项卡 */
#choice-group {
  position: absolute;
  left: 0;
  top: 1080px;
  width: 1080px;
  justify-content: center;
  gap: 40px;
}
.choice-btn {
  width: 440px;
  height: 200px;
  border-radius: 40px;
  background: var(--white);
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  font-size: 40px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, background 0.2s ease;
}
.choice-btn:active { transform: translateY(5px); box-shadow: 0 4px 0 var(--shadow); }
.choice-btn.is-picked { background: var(--mint); transform: translateY(-10px) scale(1.04); }

#scene-layer.guess-active #prompt-pill { top: 980px; }

/* ② 擦云区与按住按钮 */
#wipe-zone {
  position: absolute;
  left: 80px;
  top: 300px;
  width: 920px;
  height: 330px;
  border-radius: 40px 40px 0 0;
  border: 7px dashed rgba(255, 255, 255, 0.7);
  cursor: grab;
  touch-action: none;
}
#wipe-zone.visible { display: block; animation: zonePulse 1.3s infinite ease-in-out; }
@keyframes zonePulse {
  0%, 100% { border-color: rgba(255, 255, 255, 0.55); }
  50% { border-color: var(--yellow); }
}
#wipe-hand {
  position: absolute;
  left: 420px;
  top: 120px;
  width: 80px;
  height: 80px;
  animation: handSwipe 1.6s infinite ease-in-out;
  pointer-events: none;
}
@keyframes handSwipe {
  0%, 100% { transform: translateX(-160px) rotate(-8deg); }
  50% { transform: translateX(160px) rotate(8deg); }
}

#hold-btn {
  position: absolute;
  left: 445px;
  top: 1122px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  background: conic-gradient(var(--mint) calc(var(--p, 0) * 360deg), var(--white) 0);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-touch-callout: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
#hold-btn .hold-core {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 5px solid var(--ink);
  background: var(--night);
  color: var(--white);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}
#hold-btn.is-holding { transform: translateY(5px) scale(0.97); box-shadow: 0 4px 0 var(--shadow); }
#hold-btn.visible:not(.is-holding) .hold-core { animation: holdBreath 1.3s infinite ease-in-out; }
@keyframes holdBreath { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* ③ 昼夜滑轨：左太阳、右月亮 */
#slider-widget {
  position: absolute;
  left: 100px;
  top: 1145px;
  width: 880px;
  height: 130px;
  align-items: center;
  touch-action: none;
  cursor: pointer;
}
#slider-track {
  position: absolute;
  left: 150px;
  top: 47px;
  width: 580px;
  height: 36px;
  border-radius: 18px;
  border: 5px solid var(--ink);
  box-shadow: 0 6px 0 var(--shadow);
  background: linear-gradient(90deg, #FFE9A8, #FFD166 30%, #7D8BC7 70%, var(--night));
}
.slider-end {
  position: absolute;
  top: 25px;
  width: 80px;
  height: 80px;
  pointer-events: none;
}
.slider-end-day { left: 18px; }
.slider-end-night { right: 18px; }
#slider-handle {
  position: absolute;
  top: 65px;
  left: 150px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--white);
  border: 6px solid var(--ink);
  box-shadow: 0 8px 0 var(--shadow);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#slider-handle.nudge-hint { animation: sliderNudge 1.1s infinite ease-in-out; }
@keyframes sliderNudge {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(calc(-50% + 26px), -50%); }
}
#slider-handle-dot { width: 34px; height: 34px; border-radius: 50%; background: var(--coral); border: 4px solid var(--ink); }
#slider-labels {
  position: absolute;
  left: 160px;
  top: 1282px;
  width: 760px;
  justify-content: space-between;
  font-size: 30px;
  font-weight: 700;
  color: var(--ink-60);
}

/* ④ 淀粉粒热区 */
.starch-spot { width: 160px; height: 160px; display: none; }
.starch-spot.visible { display: block; }

/* ⑤ 草帘与目标位（类名沿用 smoke） */
.drop-target {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 7px dashed rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.10);
  transform: translate(-50%, -50%);
  color: var(--white);
  font-size: 30px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}
.drop-target.visible { display: flex; animation: targetPulse 1.3s infinite ease-in-out; }
@keyframes targetPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); border-color: rgba(255, 255, 255, 0.7); }
  50% { transform: translate(-50%, -50%) scale(1.06); border-color: var(--yellow); }
}
.drop-target.is-armed { background: rgba(255, 209, 102, 0.30); }
.smoke-pile {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 40px;
  background: var(--white);
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 4;
}
.smoke-pile.visible { display: flex; }
.smoke-pile.is-selected { background: var(--yellow); }
.smoke-pile.dragging { transform: translate(-50%, -50%) scale(1.06); box-shadow: 0 16px 0 var(--shadow); cursor: grabbing; }
.smoke-pile.shake { animation: shake 0.36s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(calc(-50% - 14px), -50%); }
  75% { transform: translate(calc(-50% + 14px), -50%); }
}

/* 结尾 */
#ending-ui {
  position: absolute;
  left: 0;
  top: 1185px;
  width: 1080px;
  display: none;
  justify-content: center;
  align-items: center;
  gap: 48px;
}
#ending-ui.visible { display: flex; animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.end-btn {
  height: 112px;
  padding: 0 48px;
  border-radius: 56px;
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  font-size: 46px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.end-btn:active { transform: translateY(5px); box-shadow: 0 4px 0 var(--shadow); }
#btn-poster { background: var(--white); }
#btn-replay { background: var(--yellow); }

/* 暂停层：奶油白 72%；超出舞台四周，盖住屏幕更长时露出的背景和上移的顶栏 */
#pause-overlay {
  position: absolute;
  inset: -480px -240px;
  background: rgba(255, 247, 236, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  z-index: 20;
  pointer-events: auto;
}
#pause-overlay.visible { display: flex; }
#pause-title { font-size: 52px; font-weight: 700; }
#resume-btn {
  height: 116px;
  padding: 0 56px;
  border-radius: 58px;
  background: var(--coral);
  border: 5px solid var(--ink);
  box-shadow: 0 9px 0 var(--shadow);
  color: var(--white);
  font-size: 48px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 20px;
}

#toast {
  position: absolute;
  left: 50%;
  top: 1610px;
  transform: translateX(-50%);
  max-width: 900px;
  padding: 14px 28px;
  border-radius: 28px;
  background: var(--white);
  border: 3px solid var(--ink-22);
  font-size: 30px;
  font-weight: 500;
  color: var(--ink-60);
  display: none;
  white-space: nowrap;
}
#toast.visible { display: block; }

/* 纪念卡弹层：墨色 55% 遮罩 */
#poster-modal {
  position: fixed;
  inset: 0;
  background: rgba(43, 45, 66, 0.55);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
#poster-modal.visible { display: flex; }
#poster-card-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; max-height: 94vh; }
#poster-img {
  max-height: 74vh;
  max-width: 88vw;
  border-radius: 18px;
  border: 4px solid var(--ink);
  box-shadow: 0 10px 0 var(--shadow);
  background: var(--cream);
  -webkit-touch-callout: default;
  user-select: auto;
  -webkit-user-select: auto;
}
#poster-img[hidden] { display: none; }
#poster-tip {
  color: var(--white);
  font-size: 15px;
  font-weight: 500;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.poster-actions { display: flex; gap: 16px; }
.poster-modal-btn {
  height: 46px;
  padding: 0 26px;
  border-radius: 23px;
  border: 3px solid var(--ink);
  box-shadow: 0 5px 0 var(--shadow);
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--white);
  cursor: pointer;
}
.poster-modal-btn.primary { background: var(--yellow); }
.poster-modal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.poster-modal-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--shadow); }

/* 宽屏右侧栏 */
#widescreen-sidebar {
  display: none;
  width: 400px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 32px 28px;
  margin-left: 36px;
  background: rgba(255, 255, 255, 0.88);
  border: 4px solid var(--ink);
  border-radius: 32px;
  box-shadow: 0 8px 0 var(--shadow);
  flex-direction: column;
  gap: 20px;
  z-index: 5;
}
@media (min-width: 900px) and (orientation: landscape) {
  #widescreen-sidebar { display: flex; }
}
.sb-title-line1 { font-size: 24px; font-weight: 800; line-height: 1.3; }
.sb-title-line2 { font-size: 28px; font-weight: 800; color: var(--sidebar-accent); line-height: 1.3; margin-top: 2px; }
.sb-lead { font-size: 14px; font-weight: 500; color: var(--ink-60); line-height: 1.65; }
.sb-section-label { font-size: 13px; font-weight: 700; letter-spacing: 1px; margin-bottom: 8px; }
#sb-chapter-list { display: flex; flex-direction: column; gap: 8px; }
.sb-chap-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.sb-chap-item:hover { background: rgba(255, 209, 102, 0.28); }
.sb-chap-item.active { background: rgba(255, 107, 107, 0.14); font-weight: 700; }
.sb-chap-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.sb-chap-item.active .sb-chap-num { background: var(--coral); color: var(--white); }
.sb-controls-box {
  background: var(--cream);
  border: 2.5px solid var(--ink-22);
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--ink-60);
  line-height: 1.6;
}

/* 加载页 */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 100;
  transition: opacity 0.4s ease;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-title { font-size: clamp(26px, 4vw, 38px); font-weight: 800; text-align: center; line-height: 1.35; }
.loading-title span { color: var(--sidebar-accent); }
#loading-status { font-size: 18px; font-weight: 500; color: var(--ink-60); margin-top: 8px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  80% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes popInCenter {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  80% { transform: translateX(-50%) scale(1.08); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
