/*!
 * theme.css — 心笺 / 前台与后台共用视觉基调
 * 深空底色 + 玻璃卡片 + 暖红辉光，字体优先中文衬线以获得"信笺"质感。
 */

:root {
  --heart-bg: #07050c;
  --heart-bg-accent: #140a1c;
  --heart-ink: #f4eef7;
  --heart-ink-dim: rgba(244, 238, 247, 0.66);
  --heart-ink-faint: rgba(244, 238, 247, 0.34);
  --heart-red: #ff2f5e;
  --heart-red-deep: #c0143c;
  --heart-gold: #ffd9a0;
  --heart-glass: rgba(28, 16, 34, 0.56);
  --heart-glass-line: rgba(255, 210, 225, 0.16);
  --heart-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --heart-font: "LXGW WenKai Screen", "Noto Serif SC", "Source Han Serif SC",
    "Songti SC", "PingFang SC", "Microsoft YaHei", Georgia, serif;
  --heart-font-ui: "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--heart-bg);
  color: var(--heart-ink);
  font-family: var(--heart-font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ------------------------------------------------------------- 前台舞台 */

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

#stage {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px 12vh;
  pointer-events: none; /* 空白处点击穿透给 canvas，控件单独开启 */
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

#stage.is-visible {
  opacity: 1;
  transform: translateY(0);
}

#stage > * { pointer-events: auto; }

/* 底部渐隐遮罩：保证文字在粒子光晕上始终可读。
   刻意从 52vh 才开始、下部最高仅 0.88 不透明度 —— 早期版本用 62vh / 0.92，
   会把爱心下半部分整体压黑，等于看不见心形。 */
#stage::before {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 52vh;
  background: linear-gradient(to top, rgba(7, 5, 12, 0.88) 4%, rgba(7, 5, 12, 0.5) 42%, transparent 100%);
  pointer-events: none;
  z-index: -1;
}

/* ------------------------------------------------------------- 通用文字 */

.sc-line {
  margin: 0 0 0.55em;
  font-size: clamp(17px, 2.5vw, 27px);
  line-height: 1.72;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--heart-ink);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.85), 0 0 42px rgba(255, 47, 94, 0.28);
  opacity: 0;
  transform: translateY(14px);
  animation: sc-line-in 1.05s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.sc-text-block { max-width: 34em; }

.sc-line-center { text-align: center; opacity: 0; animation: sc-line-in 1.05s ease forwards; }

@keyframes sc-line-in {
  to { opacity: 1; transform: translateY(0); }
}

.sc-question {
  margin: 0 0 1.1em;
  font-size: clamp(16px, 2.2vw, 23px);
  line-height: 1.7;
  text-align: center;
  letter-spacing: 0.03em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.8);
  animation: sc-line-in 0.9s ease forwards;
  opacity: 0;
}

/* ------------------------------------------------------------- 按钮 */

.sc-buttons {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.9em;
  opacity: 0;
  animation: sc-line-in 0.8s 0.3s ease forwards;
}

.sc-buttons-col { flex-direction: column; align-items: stretch; min-width: min(78vw, 320px); }

.sc-btn {
  appearance: none;
  border: 1px solid rgba(255, 138, 168, 0.5);
  background: linear-gradient(160deg, rgba(255, 47, 94, 0.26), rgba(120, 12, 44, 0.34));
  color: #fff2f6;
  font-family: var(--heart-font);
  font-size: clamp(14px, 1.7vw, 17px);
  letter-spacing: 0.08em;
  padding: 0.72em 1.9em;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 26px rgba(255, 47, 94, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease,
    background 0.22s ease, border-color 0.22s ease;
}

.sc-btn:hover {
  transform: translateY(-2px) scale(1.03);
  border-color: rgba(255, 190, 210, 0.9);
  box-shadow: 0 12px 38px rgba(255, 47, 94, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.sc-btn:active { transform: translateY(0) scale(0.99); }

.sc-btn:focus-visible { outline: 2px solid var(--heart-gold); outline-offset: 3px; }

.sc-btn:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }

.sc-btn-wide { width: 100%; }

.sc-btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow: none;
  color: var(--heart-ink-dim);
}

.sc-btn-ghost:hover { box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4); color: var(--heart-ink); }

.sc-btn.is-picked {
  background: linear-gradient(160deg, rgba(255, 47, 94, 0.6), rgba(160, 20, 60, 0.7));
  border-color: #ffd0dd;
}

/* ------------------------------------------------------------- 信封 */

.sc-gift { display: flex; flex-direction: column; align-items: center; }

.sc-gift-envelope {
  position: relative;
  width: clamp(132px, 20vw, 178px);
  height: clamp(88px, 13.5vw, 120px);
  margin-bottom: 1.5em;
  cursor: pointer;
  filter: drop-shadow(0 18px 40px rgba(255, 47, 94, 0.34));
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  animation: sc-float 3.6s ease-in-out infinite;
}

.sc-gift-envelope:hover { transform: scale(1.06) rotate(-1.5deg); }
.sc-gift-envelope:focus-visible { outline: 2px solid var(--heart-gold); outline-offset: 6px; }

.sc-gift-body {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(150deg, #fdf3e6, #f0d9c4 62%, #e2c3a8);
  box-shadow: inset 0 -6px 18px rgba(150, 90, 60, 0.22);
}

.sc-gift-flap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 62%;
  background: linear-gradient(150deg, #ffe9d6, #eccfb6);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-radius: 8px 8px 0 0;
  transform-origin: top center;
  transition: transform 0.7s cubic-bezier(0.34, 1.4, 0.5, 1);
  z-index: 3;
}

.sc-gift-envelope.is-open .sc-gift-flap { transform: rotateX(-172deg); }

.sc-gift-seal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2.1em;
  height: 2.1em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff6a8a, var(--heart-red-deep));
  color: #fff0f4;
  font-size: 17px;
  box-shadow: 0 0 22px rgba(255, 47, 94, 0.7);
  z-index: 4;
  transition: opacity 0.4s ease, transform 0.5s ease;
}

.sc-gift-envelope.is-open .sc-gift-seal { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }

.sc-gift-title {
  margin: 0 0 0.35em;
  font-size: clamp(18px, 2.4vw, 25px);
  letter-spacing: 0.12em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
  animation: sc-line-in 0.9s ease forwards;
  opacity: 0;
}

.sc-gift-prompt {
  margin: 0;
  color: var(--heart-ink-dim);
  font-size: clamp(14px, 1.8vw, 18px);
  letter-spacing: 0.06em;
  opacity: 0;
  animation: sc-line-in 0.9s 0.2s ease forwards;
}

@keyframes sc-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-11px); }
}

/* ------------------------------------------------------------- 输入 */

.sc-input { width: min(88vw, 460px); }

.sc-input-row { display: flex; gap: 10px; align-items: stretch; }

.sc-input-field {
  flex: 1;
  min-width: 0;
  padding: 0.72em 1.1em;
  border-radius: 999px;
  border: 1px solid var(--heart-glass-line);
  background: var(--heart-glass);
  color: var(--heart-ink);
  font-family: var(--heart-font);
  font-size: clamp(14px, 1.7vw, 17px);
  letter-spacing: 0.04em;
  backdrop-filter: blur(10px);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.sc-input-field::placeholder { color: var(--heart-ink-faint); }

.sc-input-field:focus {
  outline: none;
  border-color: rgba(255, 150, 180, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 47, 94, 0.16), 0 0 30px rgba(255, 47, 94, 0.2);
}

.sc-hint {
  min-height: 1.4em;
  margin: 0.6em 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--heart-gold);
  letter-spacing: 0.08em;
}

/* ------------------------------------------------------------- 结尾 */

.sc-finale { display: flex; flex-direction: column; align-items: center; position: relative; }

.sc-finale-glow {
  position: absolute;
  width: 60vw;
  height: 60vw;
  max-width: 560px;
  max-height: 560px;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 47, 94, 0.3), transparent 68%);
  pointer-events: none;
  animation: sc-pulse-glow 3.2s ease-in-out infinite;
  z-index: -1;
}

@keyframes sc-pulse-glow {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
}

.sc-line-final { font-size: clamp(19px, 2.9vw, 31px); letter-spacing: 0.1em; }

.sc-reply-card {
  margin: 1.4em 0 0.4em;
  padding: 1.1em 1.7em;
  border-radius: 18px;
  border: 1px solid var(--heart-glass-line);
  background: var(--heart-glass);
  backdrop-filter: blur(14px);
  box-shadow: var(--heart-shadow);
  text-align: center;
  max-width: min(88vw, 460px);
  opacity: 0;
  animation: sc-line-in 1s 0.9s ease forwards;
}

.sc-reply-label {
  margin: 0 0 0.5em;
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--heart-ink-faint);
  text-transform: uppercase;
}

.sc-reply-text {
  margin: 0.2em 0;
  font-size: clamp(15px, 2vw, 20px);
  color: var(--heart-gold);
  letter-spacing: 0.05em;
  word-break: break-word;
}

/* ------------------------------------------------------------- 加载与降级 */

#boot {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  background: var(--heart-bg);
  color: var(--heart-ink-faint);
  letter-spacing: 0.3em;
  font-size: 13px;
  transition: opacity 0.8s ease;
}

#boot.is-hidden { opacity: 0; pointer-events: none; }

#boot-msg { animation: sc-breathe 2.2s ease-in-out infinite; }

@keyframes sc-breathe {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* 小屏适配 */
@media (max-width: 560px) {
  #stage { padding: 0 18px 9vh; justify-content: flex-end; }
  .sc-input-row { flex-direction: column; }
  .sc-input-row .sc-btn { width: 100%; }
  /* 输入框字号必须 ≥16px：iOS Safari 在更小字号下会于聚焦时自动放大整页 */
  .sc-input-field { font-size: 16px; padding: 0.78em 1.1em; }
  /* 触控目标高度：Apple 人机界面指南建议 ≥44px */
  .sc-btn { padding: 0.82em 1.7em; }
  .sc-buttons { gap: 12px; }
}

/* 全面屏安全区：避免控件被刘海或手势条遮挡 */
@supports (padding: max(0px)) {
  #stage {
    padding-bottom: max(9vh, calc(20px + env(safe-area-inset-bottom)));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }
}

/*
 * 手机横屏：垂直空间很矮（约 390px）而心形接近正方，若仍按"底部堆叠"排版，
 * 信封会正好压在心形中央、标题穿过心形下半部分 —— 实测视觉效果很乱。
 * 改为左右布局：爱心居中，剧情内容靠右自适应宽度。
 */
@media (orientation: landscape) and (max-height: 560px) {
  #stage {
    justify-content: center;
    align-items: flex-end;
    padding: 0 max(18px, env(safe-area-inset-right)) 0 0;
  }
  #stage::before {
    /* 竖屏用的底部渐隐在横屏会横切画面，改为右侧渐隐 */
    top: 0;
    bottom: 0;
    left: auto;
    width: 58vw;
    height: auto;
    background: linear-gradient(to right, transparent 0%, rgba(7, 5, 12, 0.62) 46%, rgba(7, 5, 12, 0.9) 100%);
  }
  .sc-text-block,
  .sc-input,
  .sc-gift,
  .sc-finale,
  .sc-choice {
    max-width: 48vw;
  }
  .sc-line { font-size: clamp(14px, 2.1vw, 18px); margin-bottom: 0.4em; }
  .sc-line-final { font-size: clamp(15px, 2.5vw, 20px); }
  .sc-question { font-size: clamp(13px, 1.9vw, 17px); margin-bottom: 0.7em; }
  .sc-gift-envelope {
    width: clamp(96px, 12vw, 130px);
    height: clamp(64px, 8vw, 88px);
    margin-bottom: 0.9em;
  }
  .sc-gift-title { font-size: clamp(15px, 2.1vw, 19px); }
  .sc-gift-prompt { font-size: clamp(12px, 1.7vw, 15px); }
  /* 横屏高度紧张，但触控目标仍须 ≥44px：用 min-height 而不是缩小内边距 */
  .sc-btn {
    padding: 0.6em 1.5em;
    font-size: clamp(13px, 1.6vw, 16px);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .sc-btn-wide { width: auto; }
  .sc-reply-card { padding: 0.8em 1.2em; margin-top: 0.9em; }
}

/* 尊重系统的"减少动态效果"偏好 */
@media (prefers-reduced-motion: reduce) {
  .sc-gift-envelope { animation: none; }
  .sc-finale-glow { animation: none; }
  #boot-msg { animation: none; }
}
