/* 新增互动组件样式：弹幕祝福 / 时间胶囊 / 接捧花小游戏 / 电子请柬。
   设计 token 复用 styles.css 的 :root 变量。 */

/* ===== 弹幕祝福 ===== */
.danmaku-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 24;
}

.danmaku-bullet {
  position: absolute;
  left: 100vw;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 60vw;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 250, 247, 0.88);
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: 0 6px 22px rgba(160, 82, 45, 0.12);
  color: var(--text);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  will-change: transform;
  animation: danmakuFly linear forwards;
}

.danmaku-bullet i {
  color: var(--wine);
  flex: none;
}

.danmaku-bullet strong {
  color: var(--wine-deep);
  flex: none;
}

.danmaku-bullet--fresh {
  background: linear-gradient(120deg, #fff3f5, #fdeacc);
  border-color: var(--gold);
}

@keyframes danmakuFly {
  to {
    transform: translateX(calc(-100vw - 100%));
  }
}

.danmaku-toggle {
  margin-left: auto;
}

.danmaku-toggle[aria-pressed="false"] {
  opacity: 0.55;
}

/* ===== 时间胶囊 ===== */
.capsule-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 24px;
  align-items: start;
}

.capsule-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.capsule-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
}

.capsule-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.capsule-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 42px 18px;
  color: var(--text-soft);
  border: 2px dashed rgba(160, 82, 45, 0.22);
  border-radius: var(--radius-md);
}

.capsule-empty i {
  font-size: 1.8rem;
  color: var(--gold);
  display: block;
  margin-bottom: 10px;
}

.capsule-card {
  position: relative;
  border-radius: var(--radius-md);
  padding: 22px;
  background: var(--pearl);
  border: 1px solid rgba(212, 175, 55, 0.28);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.capsule-card__tag {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
  margin: 0;
}

.capsule-card__icon {
  font-size: 1.6rem;
  color: var(--wine);
}

.capsule-card--ready {
  border-color: var(--gold);
  animation: capsuleGlow 2.2s ease-in-out infinite;
}

@keyframes capsuleGlow {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
  }
  50% {
    box-shadow: 0 0 26px rgba(212, 175, 55, 0.45);
  }
}

.capsule-card__countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--wine-deep);
  font-size: 1.05rem;
  margin: 0;
}

.capsule-card__meta {
  font-size: 0.8rem;
  color: var(--text-soft);
  margin: 0;
}

.capsule-card__letter {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.7;
  color: var(--text);
}

.capsule-card__actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.capsule-card--opened {
  background: linear-gradient(150deg, #fffaf3, #fff2f4);
}

/* ===== 接捧花小游戏 ===== */
.game-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-hud {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  font-size: 0.95rem;
  color: var(--text-soft);
}

.game-hud strong {
  color: var(--wine-deep);
  font-variant-numeric: tabular-nums;
}

.game-stage {
  position: relative;
  height: clamp(300px, 46vh, 420px);
  border-radius: var(--radius-md);
  background:
    radial-gradient(circle at 30% 18%, rgba(250, 218, 221, 0.55), transparent 42%),
    radial-gradient(circle at 78% 30%, rgba(200, 184, 232, 0.35), transparent 40%),
    linear-gradient(180deg, #fff7fa 0%, #fdeef0 100%);
  border: 1px solid rgba(212, 175, 55, 0.25);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: none;
}

.game-item {
  position: absolute;
  top: 0;
  font-size: 30px;
  line-height: 1;
  will-change: transform;
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(160, 82, 45, 0.18));
}

.game-item--caught {
  animation: itemPop 0.4s ease forwards;
}

@keyframes itemPop {
  40% {
    transform: scale(1.5);
    opacity: 1;
  }
  100% {
    transform: scale(0.2) translateY(-26px);
    opacity: 0;
  }
}

.game-basket {
  position: absolute;
  bottom: 8px;
  left: 50%;
  font-size: 44px;
  line-height: 1;
  transform: translateX(-50%);
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(160, 82, 45, 0.25));
  transition: none;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  background: rgba(255, 250, 247, 0.82);
  backdrop-filter: blur(6px);
  z-index: 2;
  cursor: auto;
}

.game-overlay h3 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--wine-deep);
}

.game-overlay p {
  margin: 0;
  color: var(--text-soft);
  max-width: 360px;
}

.game-overlay.is-hidden {
  display: none;
}

/* ===== 电子请柬 ===== */
.invitation-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}

.invitation-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.invitation-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
}

.invitation-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.invitation-actions button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.invitation-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.invitation-preview-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.invitation-canvas-wrap {
  width: min(100%, 340px);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(212, 175, 55, 0.3);
}

.invitation-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ===== 网页桌宠 Yuehai ===== */
.web-pet {
  --pet-scale: 0.5;
  position: fixed;
  left: 0;
  bottom: 12px;
  z-index: 26;
  width: calc(192px * var(--pet-scale));
  height: calc(208px * var(--pet-scale));
  will-change: transform;
}

.web-pet__sprite {
  width: 100%;
  height: 100%;
  background-image: url("assets/pet-spritesheet.webp");
  background-repeat: no-repeat;
  background-size: calc(1536px * var(--pet-scale)) calc(1872px * var(--pet-scale));
  image-rendering: pixelated;
  cursor: grab;
  filter: drop-shadow(0 6px 8px rgba(160, 82, 45, 0.22));
}

.web-pet__sprite:active {
  cursor: grabbing;
}

.web-pet__bubble {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 240px;
  width: max-content;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(255, 250, 247, 0.95);
  border: 1px solid rgba(212, 175, 55, 0.45);
  box-shadow: 0 8px 24px rgba(160, 82, 45, 0.16);
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.web-pet__bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(255, 250, 247, 0.95);
}

.web-pet__tool {
  position: absolute;
  top: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(160, 82, 45, 0.78);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.web-pet__close {
  right: -6px;
  font-size: 12px;
}

.web-pet__sound {
  left: -6px;
  background: rgba(212, 175, 55, 0.85);
}

.web-pet:hover .web-pet__tool,
.web-pet:focus-within .web-pet__tool {
  opacity: 1;
}

.web-pet__sprite:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 8px;
}

.web-pet__chat {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  width: max-content;
  max-width: 72vw;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 250, 247, 0.96);
  border: 1px solid rgba(212, 175, 55, 0.45);
  box-shadow: 0 8px 24px rgba(160, 82, 45, 0.18);
  z-index: 1;
}

.web-pet__chat input {
  width: 168px;
  max-width: 46vw;
  border: 1px solid rgba(160, 82, 45, 0.25);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

.web-pet__chat button {
  border: none;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--wine);
  color: #fff;
  cursor: pointer;
}

/* 聊天框打开时气泡上移，互不遮挡 */
.web-pet__chat:not([hidden]) ~ .web-pet__bubble,
.web-pet__chat:not([hidden]) + .web-pet__bubble {
  bottom: calc(100% + 58px);
}

.web-pet-summon {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 26;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(212, 175, 55, 0.45);
  background: rgba(255, 250, 247, 0.92);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(160, 82, 45, 0.2);
  opacity: 0.85;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.web-pet-summon:hover,
.web-pet-summon:focus-visible {
  opacity: 1;
  transform: scale(1.12);
}

.web-pet-heart {
  position: fixed;
  z-index: 27;
  font-size: 18px;
  pointer-events: none;
  animation: petHeartFloat 1.6s ease-out forwards;
}

@keyframes petHeartFloat {
  0% {
    transform: translateY(0) scale(0.7);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(-90px) scale(1.2);
    opacity: 0;
  }
}

/* ===== 响应式 ===== */
@media (max-width: 880px) {
  .capsule-grid,
  .invitation-grid {
    grid-template-columns: 1fr;
  }

  .danmaku-bullet {
    max-width: 82vw;
    font-size: 0.84rem;
  }

  .game-stage {
    cursor: auto;
  }

  /* 移动端缩小桌宠并抬到底部 dock 之上 */
  .web-pet {
    --pet-scale: 0.38;
    bottom: 86px;
  }

  .web-pet-summon {
    bottom: 90px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .danmaku-layer {
    display: none;
  }

  .capsule-card--ready {
    animation: none;
  }
}
