/* === Fonts & Variables === */
:root {
  --bg: #FDF6EC;
  --paper: #FFFAF0;
  --ink: #5D4037;
  --ink-light: #8D6E63;
  --accent: #D84315;
  --yellow: #FFF9C4;
  --pink: #FCE4EC;
  --blue: #E3F2FD;
  --orange: #FFF3E0;
  --tape: #E8D5B7;
  --tape-warm: #F5C6AA;
  --shadow: rgba(93, 64, 55, 0.1);
  --font-hand: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', 'Apple LiGothic', cursive;
  --font-body: 'Songti SC', 'SimSun', Georgia, serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
}

/* === Stage common === */
.stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 60px 0;
}

/* === Stage 1: Intro === */
.intro-title {
  font-family: var(--font-hand);
  font-size: 32px;
  color: var(--ink);
  text-align: center;
  margin-bottom: 48px;
  opacity: 0;
  animation: fadeInDown 0.8s ease forwards;
}

.sticky-wall {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  align-items: center;
}

.sticky-note {
  font-family: var(--font-hand);
  font-size: 22px;
  padding: 16px 24px;
  border-radius: 2px;
  box-shadow: 2px 3px 8px var(--shadow), 0 1px 2px rgba(0,0,0,0.06);
  transform: rotate(var(--rotate, 0deg));
  max-width: 320px;
  width: fit-content;
  text-align: center;
  opacity: 0;
  animation: stickyIn 0.5s ease forwards;
  animation-delay: var(--delay, 0s);
}

.sticky-note.yellow { background: var(--yellow); }
.sticky-note.pink { background: var(--pink); }
.sticky-note.blue { background: var(--blue); }
.sticky-note.orange { background: var(--orange); }

.intro-cta {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink-light);
  text-align: center;
  margin-top: 48px;
  opacity: 0;
  animation: fadeIn 0.6s ease forwards;
  animation-delay: 1.8s;
}

.arrow-down {
  display: block;
  font-size: 28px;
  margin-top: 12px;
  animation: bounce 1.5s ease infinite;
}

/* === Stage 2: Input === */
.big-note {
  width: 85%;
  max-width: 400px;
  background: var(--yellow);
  padding: 32px 24px 24px;
  border-radius: 2px;
  box-shadow: 3px 4px 12px var(--shadow), 0 1px 3px rgba(0,0,0,0.08);
  position: relative;
}

.note-lines {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: repeating-linear-gradient(
    transparent 0, transparent 31px,
    rgba(213, 75, 75, 0.12) 31px, rgba(213, 75, 75, 0.12) 32px
  );
  background-position: 0 28px;
  pointer-events: none;
  border-radius: 2px;
}

.big-note textarea {
  width: 100%;
  min-height: 120px;
  border: none;
  background: transparent;
  font-family: var(--font-hand);
  font-size: 24px;
  color: var(--ink);
  line-height: 32px;
  resize: none;
  outline: none;
  position: relative;
  z-index: 1;
}

.big-note textarea::placeholder {
  color: var(--ink-light);
  opacity: 0.5;
}

/* === Stage 2a: 年龄（可选）=== */
.stage-ages .ages-lead {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink);
  text-align: center;
  margin-bottom: 24px;
  max-width: 340px;
  line-height: 1.5;
}

.stage-ages .ages-hint {
  display: block;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-light);
  margin-top: 8px;
  font-weight: normal;
}

.stage-ages .ages-form {
  width: 85%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 12px;
}

.stage-ages .ages-field {
  display: grid;
  grid-template-columns: 5.5em 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  padding: 14px 16px;
  border-radius: 8px;
  box-shadow: 2px 3px 8px var(--shadow);
}

.stage-ages .ages-label {
  font-size: 15px;
  color: var(--ink);
}

.stage-ages .ages-field input {
  min-width: 0;
  width: 100%;
  border: none;
  border-bottom: 1px dashed var(--ink-light);
  background: transparent;
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--ink);
  text-align: center;
  outline: none;
  padding: 4px 0;
}

.stage-ages .ages-field input::placeholder {
  color: var(--ink-light);
  opacity: 0.4;
}

.stage-ages .ages-unit {
  font-size: 15px;
  color: var(--ink-light);
}

.stage-ages .ages-tip {
  font-size: 13px;
  color: var(--accent);
  max-width: 340px;
  text-align: center;
  margin-bottom: 8px;
}

.stage-ages .ages-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.btn-tape {
  display: block;
  margin: 16px auto 0;
  padding: 10px 32px;
  background: var(--tape);
  border: none;
  border-radius: 2px;
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 1px 2px 4px var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  z-index: 1;
}

.btn-tape:hover {
  transform: translateY(-1px);
  box-shadow: 2px 3px 8px var(--shadow);
}

.btn-tape:active {
  transform: translateY(0);
}

.btn-tape-warm {
  background: var(--tape-warm);
}

.btn-tape-light {
  background: transparent;
  border: 1px dashed var(--ink-light);
  box-shadow: none;
}

/* === Stage 2b: 解读风格 === */
.stage-style .style-stage-lead {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink);
  text-align: center;
  margin-bottom: 20px;
  max-width: 340px;
  line-height: 1.5;
}

.stage-style .style-grid {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
}

.stage-style .style-option {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 2px 3px 8px var(--shadow);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--ink);
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.stage-style .style-option .style-emoji {
  grid-row: 1 / span 2;
  font-size: 28px;
  line-height: 1;
}

.stage-style .style-option .style-title {
  grid-column: 2;
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--ink);
}

.stage-style .style-option .style-sub {
  grid-column: 2;
  font-size: 13px;
  color: var(--ink-light);
  line-height: 1.35;
}

.stage-style .style-option:hover {
  transform: translateY(-1px);
  box-shadow: 2px 5px 12px var(--shadow);
}

.stage-style .style-option[aria-pressed="true"] {
  border-color: var(--accent);
  border-left-width: 4px;
  border-left-color: var(--accent);
  background: linear-gradient(135deg, #fff5f0 0%, #fffaf7 100%);
  box-shadow:
    inset 0 0 0 1px rgba(216, 67, 21, 0.25),
    2px 4px 14px var(--shadow);
}

.stage-style .style-option[aria-pressed="true"] .style-title {
  color: var(--accent);
}

.stage-style .style-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.stage-style #btn-confirm-style {
  margin-top: 4px;
}

/* === Stage 3: AI Interpret === */
.interpret-card {
  width: 85%;
  max-width: 400px;
  background: var(--blue);
  padding: 24px;
  border-radius: 2px;
  box-shadow: 2px 3px 8px var(--shadow);
  transform: rotate(-0.5deg);
  opacity: 0;
  animation: stickyIn 0.6s ease forwards;
}

.interpret-label {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-light);
  margin-bottom: 12px;
}

.interpret-text {
  font-family: var(--font-hand);
  font-size: 20px;
  line-height: 1.85;
  color: var(--ink);
  min-height: 60px;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-break: break-word;
}

.counter-text {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink-light);
  margin-top: 16px;
  text-align: right;
  transition: opacity 0.6s ease;
}

.counter-text .count-number {
  font-family: var(--font-hand);
  font-size: 24px;
  color: var(--accent);
}

/* === Stage 3b: 时间反差 === */
.time-card {
  width: 85%;
  max-width: 400px;
  background: var(--orange);
  padding: 28px 22px 22px;
  border-radius: 2px;
  box-shadow: 2px 3px 8px var(--shadow);
  transform: rotate(0.4deg);
  opacity: 0;
  animation: stickyIn 0.55s ease forwards;
}

.time-kicker {
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--ink-light);
  text-transform: none;
  margin-bottom: 12px;
}

.time-headline {
  font-family: var(--font-hand);
  font-size: 26px;
  line-height: 1.35;
  color: var(--ink);
  margin-bottom: 14px;
}

.time-sub {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  margin-bottom: 18px;
  opacity: 0.92;
}

.time-count {
  font-family: var(--font-hand);
  font-size: 22px;
  line-height: 1.55;
  color: var(--accent);
  margin-bottom: 20px;
  text-align: center;
}

.time-count-est {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-light);
  letter-spacing: 0.08em;
  margin-right: 6px;
  vertical-align: baseline;
}

.time-count-body {
  color: var(--accent);
  vertical-align: baseline;
}

.time-card .btn-tape {
  margin: 0 auto;
}

/* === Stage 4: Reply === */
.reply-label {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink-light);
  margin-bottom: 20px;
  opacity: 0;
  animation: fadeIn 0.6s ease forwards;
}

.reply-note {
  width: 85%;
  max-width: 400px;
  background: var(--pink);
  padding: 24px;
  border-radius: 2px;
  box-shadow: 2px 3px 8px var(--shadow);
  transform: rotate(1deg);
  opacity: 0;
  animation: stickyIn 0.5s ease forwards;
  animation-delay: 0.2s;
}

.reply-note textarea {
  width: 100%;
  min-height: 80px;
  border: none;
  background: transparent;
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--ink);
  line-height: 1.6;
  resize: none;
  outline: none;
}

.reply-note textarea::placeholder {
  color: var(--ink-light);
  opacity: 0.5;
}

/* === Stage 3: Loading === */
.interpret-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--ink-light);
  margin-bottom: 12px;
}

.interpret-loading .dots {
  display: inline-flex;
  gap: 4px;
}

.interpret-loading .dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-light);
  animation: dotPulse 1.2s ease infinite;
}

.interpret-loading .dots span:nth-child(2) { animation-delay: 0.2s; }
.interpret-loading .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* === Stage 5: Poster === */
.stage-poster {
  min-height: auto;
  padding: 40px 0 max(32px, env(safe-area-inset-bottom, 0px));
}

.btn-generate {
  padding: 14px 40px;
  background: var(--tape-warm);
  border: none;
  border-radius: 4px;
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 3px 10px var(--shadow);
  transition: transform 0.15s;
}

.btn-generate:hover { transform: translateY(-2px); }
.btn-generate:active { transform: translateY(0); }

.poster-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  scroll-margin-top: 16px;
  scroll-margin-bottom: 24px;
}

.poster-container {
  width: 100%;
  max-width: 400px;
  margin-inline: auto;
  border-radius: 8px;
  box-shadow: 4px 6px 20px var(--shadow);
  overflow: hidden;
  aspect-ratio: 9 / 16;
  background: var(--paper);
  scroll-margin-top: 16px;
}

.poster-container img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* 与其它阶段一致放在内容流里，不用 fixed，避免盖住海报底部蒲云 AI 文案 */
.poster-actions {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin: 4px auto 0;
  padding: 16px 8px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-radius: 12px;
  box-shadow: 0 2px 12px var(--shadow);
}

/* 保存提示：不用系统 alert，避免挡全屏 */
#save-tip-toast.save-tip-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  max-width: 400px;
  margin: 0 auto;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  border-radius: 10px;
  box-shadow: 0 4px 24px var(--shadow), 0 0 0 1px rgba(93, 64, 55, 0.08);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  text-align: center;
}

#save-tip-toast.save-tip-toast--show {
  opacity: 1;
  transform: translateY(0);
}

/* === Animations === */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes stickyIn {
  from { opacity: 0; transform: rotate(var(--rotate, 0deg)) translateY(12px); }
  to { opacity: 1; transform: rotate(var(--rotate, 0deg)) translateY(0); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(8px); }
}

@keyframes shake {
  0%, 100% { transform: rotate(var(--rotate, 0deg)); }
  25% { transform: rotate(calc(var(--rotate, 0deg) - 2deg)); }
  75% { transform: rotate(calc(var(--rotate, 0deg) + 2deg)); }
}

/* === Utility === */
.shake {
  animation: shake 0.3s ease;
}

.locked textarea {
  pointer-events: none;
  opacity: 0.9;
}

.locked .btn-tape {
  display: none;
}

/* === Responsive === */
@media (min-width: 768px) {
  .app { max-width: 480px; }
  .stage { padding: 80px 0; }
}
