/* ============ 设计令牌 ============ */
:root {
  --night: #160912;
  --plum: #3a1526;
  --rose: #ff6f9c;
  --blush: #ffb3c8;
  --gold: #f5c063;
  --leaf: #6ea87a;
  --milk: #fff1e8;
  --milk-dim: rgba(255, 241, 232, 0.55);
  --serif: "Noto Serif SC", "Songti SC", serif;
  --brush: "Ma Shan Zheng", "Noto Serif SC", "Songti SC", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--milk);
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(120% 90% at 50% 110%, var(--plum) 0%, transparent 60%),
    radial-gradient(90% 60% at 50% -10%, #241019 0%, transparent 55%),
    var(--night);
}

/* ============ 画布 ============ */
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ============ 加载遮罩 ============ */
#loader {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--night);
  transition: opacity 0.9s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
#loader p {
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--milk-dim);
  padding-left: 0.3em; /* 视觉居中补偿字间距 */
}
.loader-heart {
  width: 26px;
  height: 26px;
  position: relative;
  transform: rotate(45deg);
  background: var(--rose);
  animation: heartbeat 1.1s ease-in-out infinite;
}
.loader-heart::before,
.loader-heart::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--rose);
}
.loader-heart::before { left: -13px; }
.loader-heart::after { top: -13px; }
@keyframes heartbeat {
  0%, 100% { transform: rotate(45deg) scale(1); }
  30% { transform: rotate(45deg) scale(1.18); }
  45% { transform: rotate(45deg) scale(0.96); }
}

/* ============ 顶部栏 ============ */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 20px 0;
  pointer-events: none;
}
.dedication {
  font-family: var(--brush);
  font-size: 24px;
  color: var(--milk);
  text-shadow: 0 2px 18px rgba(255, 111, 156, 0.35);
  opacity: 0;
  animation: fadeDown 1.2s ease 0.6s forwards;
}
.dedication span { color: var(--blush); }
.icon-btn {
  pointer-events: auto;
  border: 1px solid rgba(255, 179, 200, 0.35);
  background: rgba(58, 21, 38, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--blush);
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.08em;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  animation: fadeDown 1.2s ease 0.9s forwards;
  transition: background 0.25s ease, transform 0.25s ease;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ============ 祝福卡片 ============ */
.card {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: calc(56px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: 420px;
  margin: 0 auto;
  padding: 20px 24px 18px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(58, 21, 38, 0.55), rgba(22, 9, 18, 0.45));
  border: 1px solid rgba(255, 179, 200, 0.22);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 241, 232, 0.08);
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 1s ease, transform 1s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.card.show { opacity: 1; transform: translateY(0); }
.message {
  font-size: 17px;
  font-weight: 300;
  line-height: 1.9;
  color: var(--milk);
  min-height: 1.9em;
}
.message .caret {
  display: inline-block;
  width: 1px;
  height: 1em;
  background: var(--gold);
  vertical-align: -0.12em;
  margin-left: 2px;
  animation: blink 0.85s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.from {
  margin-top: 12px;
  text-align: right;
  font-family: var(--brush);
  font-size: 18px;
  color: var(--gold);
  opacity: 0;
  transition: opacity 1.2s ease;
}
.from.show { opacity: 1; }

/* ============ 底部提示 ============ */
.hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 10;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.22em;
  padding-left: 0.22em;
  color: var(--milk-dim);
  opacity: 0;
  animation: fadeUp 1.4s ease 1.4s forwards;
  pointer-events: none;
}

/* ============ 卡片唤起按钮 ============ */
.card-toggle {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 10;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 179, 200, 0.35);
  background: rgba(58, 21, 38, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 19px;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.card-toggle.show { opacity: 1; transform: scale(1); }
.card-toggle:active { transform: scale(0.88); }
.card-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ============ 编辑弹层 ============ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 4, 8, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-width: 480px;
  margin: 0 auto;
  padding: 22px 22px calc(22px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: #21101a;
  border: 1px solid rgba(255, 179, 200, 0.18);
  border-bottom: none;
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}
.sheet.open { transform: translateY(0); }
.sheet h2 {
  font-family: var(--brush);
  font-size: 22px;
  font-weight: normal;
  color: var(--blush);
  margin-bottom: 16px;
}
.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 12px;
  letter-spacing: 0.15em;
  color: var(--milk-dim);
  margin-bottom: 6px;
}
.field input,
.field textarea {
  width: 100%;
  border: 1px solid rgba(255, 179, 200, 0.22);
  border-radius: 12px;
  background: rgba(255, 241, 232, 0.05);
  color: var(--milk);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.7;
  padding: 10px 14px;
  resize: none;
  outline: none;
  transition: border-color 0.25s ease;
}
.field input:focus,
.field textarea:focus { border-color: var(--rose); }
.field ::placeholder { color: rgba(255, 241, 232, 0.3); }
.sheet-actions { display: flex; gap: 12px; margin-top: 18px; }
.btn {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 13px 0;
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(135deg, var(--rose), #ff8f6b);
  color: #fff;
  box-shadow: 0 6px 20px rgba(255, 111, 156, 0.35);
}
.btn.ghost {
  background: transparent;
  border: 1px solid rgba(255, 179, 200, 0.4);
  color: var(--blush);
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  z-index: 30;
  background: rgba(33, 16, 26, 0.92);
  border: 1px solid rgba(245, 192, 99, 0.35);
  color: var(--milk);
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 10px 20px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 入场动画 ============ */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .dedication, .icon-btn, .hint { animation-duration: 0.01s; animation-delay: 0s; }
  .loader-heart { animation: none; }
}
