/* ============ 基础 ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: #3d2f24;
  background: #171221;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

img {
  max-width: 100%;
}

/* ============ 验证页 ============ */
.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(30px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 90% at 50% 0%, #3d2a55 0%, #241837 48%, #14101f 100%);
  transition: opacity 0.45s ease;
  overflow-y: auto;
}

.gate.leaving {
  opacity: 0;
  pointer-events: none;
}

.gate-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  animation: float 7s ease-in-out infinite;
  pointer-events: none;
}

.gate-glow-a {
  width: 46vmin;
  height: 46vmin;
  left: -12vmin;
  top: 8vh;
  background: #8a3f6e;
}

.gate-glow-b {
  width: 40vmin;
  height: 40vmin;
  right: -10vmin;
  bottom: 6vh;
  background: #3f6e8a;
  animation-delay: -3.5s;
}

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

.gate-card {
  position: relative;
  width: min(94vw, 430px);
  background: linear-gradient(165deg, #fffdf7 0%, #f9ecd9 100%);
  border-radius: 26px;
  padding: 30px 22px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.08);
  text-align: center;
  animation: rise 0.6s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.gate-eyebrow {
  font-size: 13px;
  letter-spacing: 3px;
  color: #b08a5d;
  margin-bottom: 10px;
}

.gate-title {
  font-size: 19px;
  font-weight: 700;
  color: #4a3728;
  line-height: 1.5;
  margin-bottom: 22px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 10px 12px;
  background: #ffffff;
  border: 2px solid rgba(196, 158, 116, 0.25);
  border-radius: 18px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(120, 84, 48, 0.12);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  font: inherit;
}

.choice:active {
  transform: scale(0.95);
}

.choice-img {
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fdf9f0;
  border-radius: 16px;
  overflow: hidden;
}

.choice-img img {
  width: 94%;
  height: 94%;
  object-fit: contain;
  object-position: center;
}

.choice-label {
  font-size: 15px;
  font-weight: 600;
  color: #5a4634;
}

.choice.shake {
  animation: shake 0.45s ease;
  border-color: #e0646f;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.gate-msg {
  min-height: 20px;
  margin-top: 16px;
  font-size: 14px;
  color: #d05660;
}

.gate-foot {
  margin-top: 18px;
  font-size: 12px;
  letter-spacing: 2px;
  color: rgba(255, 255, 255, 0.45);
}

/* ============ 主界面：信纸为主体 ============ */
.main {
  position: fixed;
  inset: 0;
  z-index: 10;
  background:
    radial-gradient(90% 60% at 50% 0%, rgba(76, 54, 96, 0.3), transparent 70%),
    #151120;
  animation: fadeIn 0.7s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.letter-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
}

/* 牛皮纸信纸：不规则的边、微微倾斜，更像一张真实的纸 */
.letter {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 780px;
  display: flex;
  flex-direction: column;
  transform: rotate(-0.35deg);
  border-radius: 4px 24px 6px 20px / 20px 5px 26px 6px;
  background:
    radial-gradient(120% 100% at 18% 8%, rgba(255, 240, 210, 0.2), transparent 42%),
    radial-gradient(130% 120% at 88% 96%, rgba(70, 42, 18, 0.18), transparent 46%),
    linear-gradient(180deg, #dab486 0%, #cda273 55%, #c49a6c 100%);
  box-shadow:
    inset 0 0 46px rgba(80, 48, 20, 0.35),
    0 12px 34px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.letter::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(120, 80, 40, 0.05) 0px,
    rgba(120, 80, 40, 0.05) 2px,
    transparent 2px,
    transparent 7px
  );
  pointer-events: none;
}

.letter-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 150px 34px 36px;
  font-family: "Kaiti SC", "KaiTi", "STKaiti", "FangSong", "SimSun", serif;
  font-size: 16px;
  line-height: 2.05;
  color: #3b2c1c;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.letter-body p {
  margin-bottom: 10px;
  text-align: justify;
  text-indent: 2em;
}

.letter-body p.letter-date {
  text-indent: 0;
  text-align: right;
  font-size: 13px;
  letter-spacing: 2px;
  color: #7a5a38;
  margin-bottom: 16px;
}

.letter-body p.letter-greet {
  text-indent: 0;
  margin-bottom: 14px;
}

.letter-body p.letter-sign {
  text-indent: 0;
  text-align: right;
  letter-spacing: 4px;
  margin-top: 20px;
}

.letter-body::-webkit-scrollbar {
  width: 4px;
}

.letter-body::-webkit-scrollbar-thumb {
  background: rgba(90, 55, 25, 0.4);
  border-radius: 4px;
}

.letter-body::-webkit-scrollbar-track {
  background: transparent;
}

.letter-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0 10px;
}

.heart {
  color: #a4544f;
  font-size: 15px;
  animation: beat 1.6s ease-in-out infinite;
}

@keyframes beat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.25); }
  24% { transform: scale(1); }
}

/* ---- 左上角的小唱片 ---- */
.record {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  z-index: 30;
  width: 112px;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  background:
    radial-gradient(
      circle,
      rgba(23, 23, 23, 0.78) 0%,
      rgba(38, 38, 38, 0.7) 34%,
      rgba(27, 27, 27, 0.66) 36%,
      rgba(5, 5, 5, 0.55) 78%,
      rgba(0, 0, 0, 0.62) 100%
    );
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.5),
    inset 0 0 10px rgba(255, 255, 255, 0.06);
  animation: spin 9s linear infinite;
  will-change: transform;
}

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

.record::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-radial-gradient(
    circle at 50% 50%,
    rgba(255, 255, 255, 0.03) 0px,
    rgba(255, 255, 255, 0.03) 1px,
    transparent 1px,
    transparent 4px
  );
  -webkit-mask: radial-gradient(circle, transparent 30%, #000 31%, #000 64%, transparent 65%);
  mask: radial-gradient(circle, transparent 30%, #000 31%, #000 64%, transparent 65%);
}

.record::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from 210deg,
    transparent 0deg,
    rgba(255, 255, 255, 0.1) 18deg,
    transparent 46deg,
    transparent 180deg,
    rgba(255, 255, 255, 0.04) 210deg,
    transparent 240deg
  );
  mix-blend-mode: screen;
}

.cover {
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: url("../assets/cover.jpg") center / cover no-repeat;
  border: 5px solid #f4efe6;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.9), 0 0 12px rgba(0, 0, 0, 0.6);
}

.spindle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #0a0a0a;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.22), 0 0 0 2px #3a3a3a;
}

.song-info {
  position: fixed;
  top: calc(134px + env(safe-area-inset-top));
  left: 22px;
  z-index: 30;
}

.song-artist {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #4f3a24;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* ---- 提示 / 弹窗 ---- */
.music-hint {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(30, 22, 45, 0.85);
  color: #f5eee2;
  font-size: 14px;
  letter-spacing: 1px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.92; }
  50% { opacity: 0.55; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  padding: 9px 18px;
  border-radius: 10px;
  background: rgba(30, 22, 45, 0.92);
  color: #ffe4e6;
  font-size: 14px;
  letter-spacing: 1px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.toast.show {
  animation: toastIn 0.25s ease both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============ 信纸边缘藤蔓花草（真实照片） ============ */
.letter-vine {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.vine {
  position: absolute;
  display: block;
  opacity: 0.62;
  background-repeat: repeat;
}

.vine-top {
  top: 0;
  left: 0;
  right: 0;
  height: 118px;
  background-image: url("../assets/flowers/ivy-h.png");
  background-position: top left;
  background-size: auto 100%;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 10%, #000 90%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0%, #000 10%, #000 90%, transparent 100%);
}

.vine-bottom {
  bottom: 0;
  left: 0;
  right: 0;
  height: 118px;
  background-image: url("../assets/flowers/ivy-h.png");
  background-position: bottom left;
  background-size: auto 100%;
  transform: rotate(180deg);
  opacity: 0.45;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 8%, #000 92%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0%, #000 8%, #000 92%, transparent 100%);
}

.vine-left {
  left: 0;
  top: 0;
  bottom: 0;
  width: 112px;
  background-image: url("../assets/flowers/ivy-v.png");
  background-position: top left;
  background-size: 100% auto;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
}

.vine-right {
  right: 0;
  top: 0;
  bottom: 0;
  width: 112px;
  background-image: url("../assets/flowers/ivy-v.png");
  background-position: top right;
  background-size: 100% auto;
  transform: scaleX(-1);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
}

.flower {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  object-fit: contain;
}

.flower-jasmine-tl {
  top: 8px;
  left: 6px;
  width: 132px;
  transform: rotate(-12deg);
  opacity: 0.95;
}

.flower-lily-tl {
  top: 66px;
  left: 96px;
  width: 84px;
  transform: rotate(24deg);
  opacity: 0.9;
}

.flower-lisianthus-tr {
  top: 6px;
  right: 8px;
  width: 120px;
  transform: scaleX(-1) rotate(8deg);
  opacity: 0.95;
}

.flower-lily-tr {
  top: 70px;
  right: 84px;
  width: 78px;
  transform: scaleX(-1) rotate(-22deg);
  opacity: 0.9;
}

.flower-jasmine-br {
  bottom: 10px;
  right: 6px;
  width: 118px;
  transform: scaleX(-1) rotate(148deg);
  opacity: 0.88;
}

.flower-lisianthus-br {
  bottom: 74px;
  right: 92px;
  width: 80px;
  transform: scaleX(-1) rotate(118deg);
  opacity: 0.85;
}

.flower-lily-bl {
  bottom: 8px;
  left: 4px;
  width: 96px;
  transform: rotate(150deg);
  opacity: 0.88;
}

.flower-lisianthus-bl {
  bottom: 66px;
  left: 84px;
  width: 78px;
  transform: rotate(126deg);
  opacity: 0.85;
}

/* ============ 歌曲介绍弹窗 ============ */
.song-popup {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 12, 24, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: popFade 0.25s ease both;
}

.song-popup-card {
  position: relative;
  width: min(86vw, 360px);
  max-height: 72vh;
  overflow-y: auto;
  background: linear-gradient(165deg, #fffdf7 0%, #f6e7cf 100%);
  border-radius: 20px;
  padding: 26px 22px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.song-popup-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(90, 55, 25, 0.12);
  color: #6b4a2a;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.song-popup-kicker {
  font-size: 12px;
  letter-spacing: 4px;
  color: #b08a5d;
  margin-bottom: 8px;
}

.song-popup-title {
  font-size: 22px;
  color: #4a3728;
  margin-bottom: 6px;
}

.song-popup-sub {
  font-size: 13px;
  color: #8a6a48;
  margin-bottom: 14px;
}

.song-popup-body {
  text-align: left;
  font-family: "Kaiti SC", "KaiTi", "STKaiti", "FangSong", "SimSun", serif;
  font-size: 15px;
  line-height: 1.9;
  color: #4a3625;
}

.song-popup-body p {
  margin-bottom: 10px;
  text-align: justify;
}

.song-popup-tip {
  margin-top: 14px;
  font-size: 11px;
  color: #a08a6a;
  letter-spacing: 1px;
}

@keyframes popFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============ 桌宠小狗（真实照片卡） ============ */
.pet {
  position: fixed;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 35;
  width: 112px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.pet-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  transform: rotate(-2.5deg);
  box-shadow:
    0 12px 26px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.1);
  background: #e9e2d5;
}

.pet-img {
  display: block;
  width: 100%;
  height: auto;
}

.pet-sleep-img {
  transform-origin: 50% 92%;
  animation: petBreathe 3.4s ease-in-out infinite;
}

.pet-cry-img {
  display: none;
}

.pet.crying .pet-sleep-img {
  display: none;
}

.pet.crying .pet-cry-img {
  display: block;
  animation: petShiver 0.42s ease-in-out 2;
}

@keyframes petShiver {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-2px, 1px) rotate(-1deg); }
  50% { transform: translate(2px, -1px) rotate(1deg); }
  75% { transform: translate(-1px, 0) rotate(0deg); }
}

.pet-shadow {
  position: absolute;
  left: 8%;
  right: 6%;
  bottom: -6px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.28) 0%, transparent 70%);
  pointer-events: none;
}

.pet.dragging {
  cursor: grabbing;
  opacity: 0.9;
}

@keyframes petBreathe {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.015); }
}

.pet-zzz {
  position: absolute;
  right: 10px;
  color: #f7efe0;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: zzzFloat 2.6s ease-in-out infinite;
}

.pet-zzz-1 { top: -8px; }
.pet-zzz-2 { top: -18px; right: 24px; font-size: 10px; animation-delay: 0.6s; }
.pet-zzz-3 { top: -28px; right: 38px; font-size: 8px; animation-delay: 1.2s; }

@keyframes zzzFloat {
  0% { opacity: 0; transform: translateY(6px); }
  35% { opacity: 0.9; }
  100% { opacity: 0; transform: translateY(-16px); }
}

.pet-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  max-width: 160px;
  padding: 7px 12px;
  border-radius: 12px;
  background: #fffdf4;
  color: #6b4a2a;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  z-index: 5;
}

.pet-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%) rotate(45deg);
  width: 12px;
  height: 12px;
  background: #fffdf4;
}

.pet-bubble.show {
  opacity: 1;
}

.pet.hit {
  animation: petHit 0.4s ease;
}

@keyframes petHit {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-7px, 2px); }
  50% { transform: translate(6px, -3px); }
  75% { transform: translate(-3px, -2px); }
}

.pet-fist {
  position: fixed;
  z-index: 80;
  font-size: 30px;
  pointer-events: none;
  transition: transform 0.36s cubic-bezier(0.2, 0.8, 0.3, 1);
  will-change: transform;
}

.pet-burst {
  position: fixed;
  z-index: 80;
  font-size: 26px;
  pointer-events: none;
  animation: burstPop 0.5s ease both;
}

@keyframes burstPop {
  0% { opacity: 0; transform: scale(0.3); }
  40% { opacity: 1; transform: scale(1.25); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* ============ 小屏 / 大屏适配 ============ */
@media (max-height: 600px) {
  .record {
    width: 96px;
  }
  .song-info {
    top: calc(116px + env(safe-area-inset-top));
  }
  .letter-body {
    padding-top: 130px;
  }
  .pet {
    width: 100px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .record {
    animation-duration: 18s;
  }
}
