/* ============================================================
   tokens.css — 变量、重置、通用组件
   ============================================================ */

:root {
  /* 颜色 */
  --cream: #fdf6e9;
  --paper: #f8ecd8;
  --paper-deep: #efdfc6;
  --ink: #4a3a30;
  --ink-soft: #8c7466;
  --ink-faint: #b9a696;

  --gold: #f6c46a;
  --gold-deep: #e8a93f;
  --gold-glow: #ffd98a;

  --rose: #f2a9a0;
  --rose-deep: #e0837a;
  --sage: #b8c9a8;
  --sage-deep: #93a984;

  --night: #1b1512;
  --night-2: #241b16;
  --night-3: #33251c;

  --line: rgba(74, 59, 47, 0.55);
  --line-soft: rgba(74, 59, 47, 0.32);
  --wood: #a9764f;
  --wood-deep: #8a5c3b;

  /* 圆角（手绘感：不规则的组合圆角） */
  --r-sm: 12px 14px 11px 15px / 14px 11px 15px 12px;
  --r-md: 18px 22px 16px 24px / 22px 16px 24px 18px;
  --r-lg: 26px 30px 24px 32px / 30px 24px 32px 26px;

  /* 字号 */
  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 26px;
  --fs-2xl: 34px;

  /* 安全区 */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* 缓动 */
  --ease-soft: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--night);
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  font-family: "Kaiti SC", "STKaiti", "Songti SC", "PingFang SC", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: absolute;
  inset: 0;
  height: 100%;
  overflow: hidden;
}

/* ---------- 场景容器 ---------- */
.scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.65s var(--ease-soft);
  will-change: opacity;
}

.scene.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- 纸纹 ---------- */
.grain::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/><feColorMatrix type='saturate' values='0'/></filter><rect width='140' height='140' filter='url(%23n)' opacity='0.35'/></svg>");
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: none;
  margin: 0;
  padding: 0 26px;
  min-height: 52px;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--fs-md);
  color: var(--ink);
  background: linear-gradient(180deg, #fffaf0, var(--paper));
  box-shadow:
    0 0 0 2px rgba(122, 90, 65, 0.22),
    0 6px 0 rgba(122, 90, 65, 0.18),
    0 12px 24px rgba(60, 30, 10, 0.16);
  cursor: pointer;
  transition: transform 0.16s var(--ease-pop), box-shadow 0.16s ease, filter 0.2s ease;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(4px) scale(0.985);
  box-shadow:
    0 0 0 2px rgba(122, 90, 65, 0.22),
    0 2px 0 rgba(122, 90, 65, 0.18),
    0 4px 10px rgba(60, 30, 10, 0.14);
}

.btn--gold {
  background: linear-gradient(180deg, #ffe6b0, var(--gold));
}

.btn--ghost {
  background: rgba(253, 246, 233, 0.14);
  color: var(--cream);
  box-shadow: 0 0 0 2px rgba(253, 246, 233, 0.35);
  min-height: 44px;
  font-size: var(--fs-sm);
  padding: 0 18px;
}

.btn--ghost:active {
  transform: scale(0.97);
  box-shadow: 0 0 0 2px rgba(253, 246, 233, 0.35);
}

/* ---------- 顶部小按钮 ---------- */
.corner-btn {
  position: absolute;
  top: calc(var(--sat) + 12px);
  right: calc(var(--sar) + 14px);
  z-index: 40;
  width: 42px;
  height: 42px;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: none;
  background: rgba(27, 21, 18, 0.35);
  color: var(--cream);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 0 0 1.5px rgba(253, 246, 233, 0.28);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.2s var(--ease-pop);
}

.corner-btn:active {
  transform: scale(0.9);
}

.corner-btn.is-off {
  opacity: 0.55;
}

/* ---------- 模态框 ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: calc(var(--sat) + 18px) 20px calc(var(--sab) + 18px);
  background: rgba(20, 14, 10, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.32s var(--ease-soft), visibility 0.32s;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal__card {
  position: relative;
  width: min(100%, 380px);
  max-height: 100%;
  overflow: auto;
  padding: 22px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #fffdf8, var(--paper));
  box-shadow:
    0 0 0 2px rgba(122, 90, 65, 0.16),
    0 26px 60px rgba(20, 10, 4, 0.45);
  transform: translateY(18px) scale(0.96);
  transition: transform 0.36s var(--ease-pop);
}

.modal.is-open .modal__card {
  transform: translateY(0) scale(1);
}

/* ---------- 黑幕转场 ---------- */
.fader {
  position: absolute;
  inset: 0;
  z-index: 90;
  background: #0d0907;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.55s ease;
  display: grid;
  place-items: center;
}

.fader.is-on {
  opacity: 1;
  pointer-events: auto;
}

.fader__line {
  color: var(--cream);
  font-size: var(--fs-lg);
  letter-spacing: 0.12em;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s ease 0.15s, transform 0.5s ease 0.15s;
}

.fader.is-on .fader__line {
  opacity: 0.9;
  transform: translateY(0);
}

/* ---------- 工具 ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

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

/* 启动失败的兜底提示 */
.boot-note {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sab) + 24px);
  transform: translateX(-50%);
  z-index: 120;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(253, 246, 233, 0.92);
  color: #4a3a30;
  font-size: 13px;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

/* ---------------- 开场加载 ---------------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: radial-gradient(90% 70% at 50% 45%, #221913 0%, #0b0705 70%);
  transition: opacity 0.7s ease;
}

.loader.is-done {
  opacity: 0;
  pointer-events: none;
}

.loader__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  transform: translateY(-3vh);
}

.loader__ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(246, 196, 106, 0.22);
  border-top-color: var(--gold);
  animation: loader-spin 1.1s linear infinite;
}

@keyframes loader-spin {
  to { transform: rotate(360deg); }
}

.loader__text {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: rgba(253, 246, 233, 0.6);
}

.loader__bar {
  width: 148px;
  height: 2px;
  border-radius: 2px;
  background: rgba(253, 246, 233, 0.14);
  overflow: hidden;
}

.loader__bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-glow));
  transition: width 0.3s ease;
}

/* 音乐按钮的提示脉冲 */
.corner-btn.is-hint::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 1.5px solid rgba(246, 196, 106, 0.75);
  animation: hint-pulse 1.7s ease-out infinite;
  pointer-events: none;
}

@keyframes hint-pulse {
  0% { transform: scale(0.86); opacity: 0.9; }
  100% { transform: scale(1.34); opacity: 0; }
}

.music-tip {
  position: absolute;
  top: calc(var(--sat) + 58px);
  right: calc(var(--sar) + 10px);
  z-index: 41;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(24, 16, 11, 0.82);
  color: var(--cream);
  font-size: 12px;
  letter-spacing: 0.08em;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
  white-space: nowrap;
}

.music-tip.is-shown {
  opacity: 1;
  transform: translateY(0);
}
