/* ================= 1. 全局变量与重置 ================= */
:root {
  /* 调色板：更深沉的夜色，更辉煌的金光 */
  --red: #c02c20;
  --gold: #f5d68e;
  --gold-glow: #ffecb3;
  --night-bg: #0f0b18;
  --lantern-core: #ff9966;
  --lantern-rim: #592317;
  --status-error: #ff4d4f;
  --status-success: #52c41a;
  --status-loading: #1890ff;
  --status-warning: #faad14;
  
  /* 动态变量默认值 (会被 JS 覆盖) */
  --glow: 1;
  --scale: 1;
  --blur: 0px;
  --brightness: 1;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  background: var(--night-bg);
  color: var(--gold);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ================= 2. 背景氛围层 ================= */
.screen #bg-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  filter: brightness(0.6) contrast(1.1) saturate(1.2); /* 压暗背景，突出灯笼 */
}

/* 兜底背景图：增加噪点质感 */
.screen #bg-fallback {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image: url("/assets/bg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#lantern-layer,
#message-layer {
  position: fixed;
  inset: 0;
  pointer-events: none; /* 确保不阻挡交互 */
  z-index: 10;
}

/* 粒子层优化：减少混合模式开销，使用透明度动画 */
#sparkle-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  background-image: 
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(2px 2px at 40% 70%, #fff, transparent),
    radial-gradient(2px 2px at 60% 40%, #fff, transparent),
    radial-gradient(1px 1px at 80% 80%, #fff, transparent);
  background-size: 550px 550px;
  opacity: 0.3;
  animation: sparkle-anim 10s linear infinite;
}

@keyframes sparkle-anim {
  from { transform: translateY(0); }
  to { transform: translateY(-550px); }
}

/* ================= 3. 孔明灯 (核心优化) ================= */
.lantern {
  position: absolute;
  /* 基础尺寸 */
  width: 80px; 
  height: 110px;
  
  /* 材质透光感：光从底部向上扩散 */
  background: radial-gradient(
    circle at 50% 60%,
    rgba(255, 246, 230, 0.95) 5%,
    rgba(255, 200, 100, 0.85) 40%,
    rgba(224, 86, 58, 0.8) 85%,
    rgba(140, 40, 20, 0.7) 100%
  );
  
  /* 形状微调：让它看起来像充了气 */
  border-radius: 30px 30px 20px 20px;
  
  /* 核心光晕：使用 drop-shadow 获得更好性能和边缘融合 */
  filter: 
    blur(var(--blur)) 
    brightness(var(--brightness)) 
    drop-shadow(0 0 calc(12px + var(--glow) * 10px) rgba(255, 160, 50, calc(0.15 + var(--glow) * 0.6)));
    
  transform-origin: top center; /* 摇摆支点在上部 */
  will-change: transform, opacity; /* GPU 加速提示 */
  
  /* 初始不可见，防止闪烁 */
  opacity: 0; 
}

/* 顶部盖子 */
.lantern::before {
  content: "";
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 8px;
  background: linear-gradient(90deg, #3e160e, #6b2b1a, #3e160e); /* 金属质感 */
  border-radius: 4px 4px 0 0;
}

/* 底部底座 + 火焰暗示 */
.lantern::after {
  content: "";
  position: absolute;
  bottom: -8px; left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 10px;
  border: 2px solid #5a2d1e;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 20%, transparent 60%);
  box-shadow: 0 5px 10px rgba(255, 153, 0, 0.7); /* 火苗照亮下方空气 */
}

/* 动态类：由 JS 添加 */
.lantern.floating {
  /* 复合动画：同时向上飘 + 左右摇摆 */
  animation: 
    float-up var(--float-duration, 20s) linear forwards,
    sway-tilt var(--sway-duration, 4s) ease-in-out infinite alternate,
    breathe var(--breathe-duration, 4s) ease-in-out infinite;
  
  /* 应用 JS 计算的大小 */
  transform: scale(var(--scale));
  opacity: 1; /* 动画开始时显示 */
}

/* 文字样式优化 */
.lantern .wish-text {
  width: 100%;
  padding: 0 10px;
  text-align: center;
  color: #592317; /* 墨字颜色 */
  font-weight: bold;
  font-size: 16px;
  line-height: 1.3;
  writing-mode: vertical-rl; /* 竖排文字，更有古风 */
  text-orientation: upright;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.5);
  opacity: 0.85;
}

/* 特殊高亮灯笼 */
.lantern.special {
  z-index: 100 !important;
  filter: drop-shadow(0 0 30px rgba(255, 215, 0, 0.8)) !important; /* 金光护体 */
  background: radial-gradient(circle at 50% 50%, #fff7e6 0%, #ffcc80 60%, #ff6f00 100%);
}

/* 关键帧：向上飘 */
@keyframes float-up {
  0% { top: 110%; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 0.9; }
  100% { top: -20%; opacity: 0; }
}

/* 关键帧：左右摇摆 (S形运动) */
@keyframes sway-tilt {
  0% { margin-left: -25px; transform: scale(var(--scale)) rotate(-3deg); }
  100% { margin-left: 25px; transform: scale(var(--scale)) rotate(3deg); }
}

@keyframes breathe {
  0%, 100% { 
    filter: blur(var(--blur)) brightness(var(--brightness)) drop-shadow(0 0 calc(12px + var(--glow) * 10px) rgba(255, 160, 50, calc(0.15 + var(--glow) * 0.6))); 
  }
  50% { 
    filter: blur(var(--blur)) brightness(calc(var(--brightness) * 1.12)) drop-shadow(0 0 calc(14px + var(--glow) * 12px) rgba(255, 170, 60, calc(0.2 + var(--glow) * 0.7))); 
  }
}

/* ================= 4. 祈福卷轴 UI ================= */
#message-layer {
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1000px;
}

.scroll {
  /* 玻璃拟态 + 古风卷轴 */
  background: rgba(30, 10, 15, 0.85);
  backdrop-filter: blur(12px); /* 毛玻璃 */
  border: 1px solid rgba(245, 214, 142, 0.3);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), inset 0 0 30px rgba(179, 19, 18, 0.2);
  
  padding: 40px;
  border-radius: 8px;
  text-align: center;
  position: relative;
  min-width: 400px;
  transform: rotateX(10deg); /* 3D 倾斜感 */
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 卷轴两侧的轴杆 */
.scroll::before, .scroll::after {
  content: "";
  position: absolute;
  top: 10px; bottom: 10px;
  width: 12px;
  background: linear-gradient(to right, #6b2b1a, #8a3a24, #6b2b1a);
  border-radius: 4px;
  box-shadow: 2px 0 5px rgba(0,0,0,0.5);
}
.scroll::before { left: 10px; }
.scroll::after { right: 10px; }

/* 进场动画类 */
.scroll.animate-in {
  opacity: 1;
  transform: rotateX(0deg) scale(1);
}
.scroll.hidden {
  display: none;
}

.scroll-text {
  font-size: 36px;
  background: linear-gradient(to bottom, #fff1cf, #f5d68e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; /* 文字渐变 */
  margin: 20px 0;
  font-weight: bold;
  text-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.scroll-count {
  font-size: 14px;
  color: rgba(245, 214, 142, 0.6);
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ================= 5. 闪光特效 ================= */
#flash {
  position: fixed;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 999;
}
#flash.active {
  animation: flash-burst 0.8s ease-out;
}
@keyframes flash-burst {
  0% { opacity: 0.6; }
  100% { opacity: 0; }
}

/* ================= 6. 移动端 UI (简单美化) ================= */
.mobile {
  background: #1a0f18;
  color: var(--gold);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.mobile-card {
  width: 100%;
  max-width: 400px;
  background: rgba(40, 20, 30, 0.9);
  border: 1px solid rgba(245, 214, 142, 0.2);
  padding: 24px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.mobile-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  color: #f8e6b7;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.mobile-buttons,
.mobile-style {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.mobile-subtitle {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(245, 214, 142, 0.7);
  margin: 4px 0 10px;
}

.mobile-buttons button,
.mobile-style button {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #f8e6b7;
  border: 1px solid rgba(245, 214, 142, 0.35);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
}

.mobile-buttons button.is-selected,
.mobile-style button.is-selected {
  background: rgba(245, 214, 142, 0.18);
  border-color: rgba(245, 214, 142, 0.7);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.25);
}

.mobile-buttons button:active,
.mobile-style button:active {
  transform: scale(0.98);
  box-shadow: 0 6px 14px rgba(0,0,0,0.2);
}

.mobile-input {
  width: 100%;
  padding: 15px;
  background: rgba(0,0,0,0.3);
  border: 1px solid #592317;
  color: #fff;
  border-radius: 8px;
  margin-bottom: 15px;
  font-size: 16px;
}

.mobile-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.mobile-input:focus {
  outline: 2px solid rgba(245, 214, 142, 0.4);
  border-color: rgba(245, 214, 142, 0.6);
}

.mobile-send {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #b31312, #e0563a);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 5px 15px rgba(179, 19, 18, 0.4);
  transition: transform 0.1s;
}

.mobile-send:active {
  transform: scale(0.98);
}

.mobile-status {
  margin-top: 12px;
  text-align: center;
  font-size: 14px;
  min-height: 18px;
  color: rgba(245, 214, 142, 0.7);
  transition: color 0.2s ease, opacity 0.2s ease;
}

#status.error { color: var(--status-error); }
#status.success { color: var(--status-success); }
#status.loading { color: var(--status-loading); }
#status.warning { color: var(--status-warning); }

/* 按钮禁用/加载状态 */
button:disabled,
button.loading {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(0.6);
}

button.loading {
  position: relative;
}

button.loading::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-top-color: transparent;
  border-radius: 50%;
  display: inline-block;
  margin-left: 8px;
  vertical-align: -2px;
  animation: btn-spin 0.8s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}
/* 建议添加到 styles.css 末尾 */
.qr-container {
    position: fixed;
    right: 30px;
    bottom: 30px;
    z-index: 999;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #b81c22; /* 红色边框，呼应主题 */
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
}

.qr-container:hover {
    transform: scale(1.05); /* 鼠标悬停微放大 */
}

#qrcode img {
    display: block;
    margin: 0 auto;
}

.qr-tips {
    margin-top: 8px;
    color: #b81c22;
    font-size: 14px;
    font-weight: bold;
    font-family: 'Noto Serif SC', serif;
}