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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: radial-gradient(circle at top, #ffe8f2, #fdd0e3, #fbb7d5);
  color: #5c1846;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 420px;
  padding: 16px;
}

/* 初始时让卡片整体在视口中真正垂直居中 */
.app.center-mode {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
  padding-top: 0;
  padding-bottom: 0;
}

/* 导出模式：只为生成图片时使用，卡片居中、不显示提示和按钮 */
.app.export-mode {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
  padding: 16px;
}

.app.export-mode .card-wrapper {
  margin: 0 auto;
}

.app.export-mode .card-hint,
.app.export-mode #actionButtons,
.app.export-mode .result-section {
  display: none !important;
}

/* 导出时只保留背面，去掉翻转效果，避免正反两面一起被截进去 */
.app.export-mode #card {
  transform: none !important;
}

.app.export-mode .card-back {
  transform: none !important;
}

.app.export-mode .card-front {
  display: none !important;
}

/* 音乐开关按钮 */
.music-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 18px rgba(169, 46, 120, 0.45);
  color: #a61961;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s;
}

.music-toggle:active {
  transform: translateY(1px) scale(0.96);
  box-shadow: 0 4px 10px rgba(169, 46, 120, 0.35);
}

.music-toggle::before {
  content: "♪";
  font-size: 18px;
}

.music-toggle.playing {
  background: linear-gradient(130deg, #ff7bac, #ff4a8a);
  color: #fff;
  animation: musicSpin 4s linear infinite;
}

.music-toggle.paused {
  opacity: 0.85;
}

@keyframes musicSpin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 加载页 */
.loader-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #ffe8f2, #fdd0e3, #fbb7d5);
  z-index: 999;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loader-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.loader-flower {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: conic-gradient(#ff7bac, #ffb3cd, #ffe1ef, #ff7bac);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: spin 3s linear infinite;
}

.loader-center {
  width: 36px;
  height: 36px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.5);
}

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

.loader-text {
  margin-top: 18px;
  font-size: 18px;
  letter-spacing: 2px;
  font-weight: 600;
}

.loader-sub {
  margin-top: 8px;
  font-size: 14px;
  opacity: 0.8;
}

/* 卡片整体布局 */
.card-wrapper {
  perspective: 1200px;
  margin-bottom: 16px;
}

.app.center-mode .card-wrapper {
  margin-bottom: 0;
}

/* 卡片下方提示：点击翻转添加祝福 */
.card-hint {
  margin-top: 20px;
  margin-bottom: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: rgba(166, 25, 97, 0.85);
  text-align: center;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  opacity: 0.95;
}

.app:not(.center-mode) .card-hint {
  display: none;
}

.card {
  position: relative;
  width: 100%;
  padding-top: 60%; /* 宽高比例 */
  transform-style: preserve-3d;
  transition: transform 0.8s ease;
  cursor: pointer;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(169, 46, 120, 0.35);
  backface-visibility: hidden;
  overflow: hidden;
}

/* 正面：卡片样式 + 正面图片 */
.card-front {
  background: #fef5f8;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
}

/* 正反面图片铺满整个卡片区域 */
.card-front-image,
.card-back-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 使用图片后，隐藏原有叠加元素避免遮挡 */
.card-front .tag-ribbon,
.card-front .front-header,
.card-front .flower-illustration,
.card-front .front-footer {
  display: none;
}

.tag-ribbon {
  position: absolute;
  top: 14px;
  left: -40px;
  background: linear-gradient(120deg, #ff7bac, #ff4a8a);
  color: #fff;
  padding: 6px 46px;
  font-size: 12px;
  transform: rotate(-12deg);
  letter-spacing: 2px;
  text-transform: uppercase;
  box-shadow: 0 8px 18px rgba(255, 74, 138, 0.4);
}

.front-header {
  margin-top: 0;
}

.front-subtitle {
  font-size: 14px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #b54a80;
  margin-bottom: 4px;
}

.front-title {
  font-size: 26px;
  font-weight: 800;
  color: #a61961;
  line-height: 1.3;
}

.front-title span.small {
  font-size: 18px;
  margin-left: 6px;
  font-weight: 600;
}

.flower-illustration {
  align-self: flex-end;
  margin-top: 8px;
  position: relative;
  width: 150px;
  height: 130px;
}

.stem {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 4px;
  height: 75px;
  background: linear-gradient(#0d9d68, #05734a);
  border-radius: 999px;
}

.leaf {
  position: absolute;
  width: 38px;
  height: 18px;
  background: #0ca568;
  border-radius: 30px 30px 0 30px;
}

.leaf.left {
  bottom: 26px;
  left: calc(50% - 32px);
  transform: rotate(-22deg);
}

.leaf.right {
  bottom: 42px;
  left: calc(50% - 6px);
  transform: rotate(18deg);
  border-radius: 30px 30px 30px 0;
}

.flower-head {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ffeef6, #ff7bac);
  box-shadow: 0 14px 26px rgba(194, 40, 118, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.flower-center {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ffe9b3, #ffb347);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.7);
}

.petal-ring {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 10px dotted rgba(255, 255, 255, 0.7);
  animation: petalPulse 3s ease-in-out infinite;
}

@keyframes petalPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.85; }
}

.front-footer {
  margin-top: 4px;
  font-size: 13px;
  color: #b54a80;
}

/* 背面：使用 card-back.png 作为底图，在中间白色书写区叠加可编辑文字 */
.card-back {
  padding: 0;
  transform: rotateY(180deg);
  background: #fff9fb;
  display: flex;
  flex-direction: column;
}

.back-header {
  display: none;
}

.back-title {
  font-size: 18px;
  font-weight: 700;
  color: #a61961;
}

.back-tip {
  font-size: 12px;
  color: #c26c96;
}

/* 寄语区域：叠在图片中央白色留言区，用百分比控制，便于不同屏幕适配 */
.message-card {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 15%;
  bottom: 23%;
  background: transparent;
  border-radius: 0;
  border: none;
  padding: 3% 4%;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.message-header {
  font-size: clamp(13px, 3.4vw, 16px);
  margin-bottom: 8px;
  color: #b54a80;
  font-style: italic;
}

.message-body {
  font-size: clamp(13px, 3.2vw, 15px);
  line-height: 1.8;
  white-space: pre-wrap;
  margin-bottom: 10px;
  color: #5c1846;
  flex: 1;
}

.message-footer {
  margin-top: auto;
  font-size: clamp(12px, 3vw, 14px);
  text-align: right;
  color: #8b335f;
}

/* 卡片内可编辑文字样式 */
.editable {
  cursor: text;
}

.editable:focus {
  outline: none;
  box-shadow: 0 0 0 1px rgba(255, 123, 172, 0.45);
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.7);
}

.message-footer .sign-line {
  margin-top: 2px;
}

.message-footer .date {
  font-size: 12px;
  opacity: 0.8;
}

.message-deco {
  display: none;
}

/* 按钮区域 */
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 9px 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-primary {
  background: linear-gradient(120deg, #ff7bac, #ff4a8a);
  color: #fff;
  box-shadow: 0 10px 20px rgba(255, 74, 138, 0.5);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.9);
  color: #b54a80;
  border: 1px solid rgba(214, 151, 178, 0.7);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: none;
}

/* 生成图片预览 */
.result-section {
  margin-top: 14px;
  font-size: 12px;
  color: #8b335f;
}

/* 初始只展示卡片时，不显示结果区域 */
.app.center-mode .result-section {
  display: none;
}

.result-image-wrapper {
  margin-top: 8px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 22px rgba(169, 46, 120, 0.3);
}

.result-image-wrapper img {
  display: block;
  width: 100%;
}

.hint {
  margin-top: 6px;
  font-size: 11px;
  color: #b54a80;
}

@media (min-width: 480px) {
  .card {
    padding-top: 58%;
  }
}
