:root {
  --bg1: #fff3f1;
  --bg2: #ffe0e6;
  --pink: #ff8fa3;
  --pink-d: #e8607d;
  --text: #5a3a40;
  --muted: #a07d84;
  --card: rgba(255, 255, 255, .82);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: linear-gradient(170deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  overflow-x: hidden;
}

main { position: relative; z-index: 1; max-width: 480px; margin: 0 auto; min-height: 100%; }

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 36px 22px calc(36px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  animation: fadeIn .45s ease;
}
.screen.active { display: flex; }

h1 { font-size: 26px; margin: 10px 0 6px; }
h2 { font-size: 22px; margin: 6px 0; }
h3 { font-size: 16px; margin: 0 0 10px; }
.sub { color: var(--muted); line-height: 1.7; margin: 4px 0 18px; }
.sub.small { font-size: 14px; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 13px; min-height: 18px; }

.mascot { font-size: 84px; line-height: 1; margin-top: 24px; filter: drop-shadow(0 6px 10px rgba(232, 96, 125, .25)); }
.bounce { animation: bounce 2.2s ease-in-out infinite; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }

.btn {
  font: inherit; font-size: 16px;
  border: 0; border-radius: 999px;
  padding: 12px 26px; margin: 6px;
  background: linear-gradient(135deg, var(--pink), var(--pink-d));
  color: #fff; font-weight: 600;
  box-shadow: 0 6px 16px rgba(232, 96, 125, .3);
  cursor: pointer; transition: transform .12s;
}
.btn:active { transform: scale(.95); }
.btn.ghost { background: #fff; color: var(--pink-d); box-shadow: 0 3px 10px rgba(232, 96, 125, .15); }

.actions { display: flex; flex-direction: column; align-items: center; margin-top: 18px; }
.actions.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }

#gate-form { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
#gate-input {
  font: inherit; font-size: 18px; text-align: center;
  width: 80%; max-width: 280px; padding: 12px 16px;
  border: 2px solid #ffc6d0; border-radius: 16px; outline: none; background: #fff; color: var(--text);
}
#gate-input:focus { border-color: var(--pink); }
.shake { animation: shake .35s; }

/* Story */
.story-text { width: 100%; margin-top: 22px; min-height: 160px; }
.line {
  background: var(--card); border-radius: 18px; padding: 12px 16px; margin: 10px 0;
  line-height: 1.7; font-size: 16px; text-align: left;
  box-shadow: 0 3px 12px rgba(232, 96, 125, .08);
  animation: rise .35s ease;
}
#story { cursor: pointer; }

/* Catch */
.hud { display: flex; justify-content: space-between; width: 100%; font-size: 18px; font-weight: 600; }
#catch-canvas {
  width: 100%; height: 62vh; height: 62dvh;
  background: linear-gradient(#fff9f8, #ffe9ee);
  border-radius: 22px; touch-action: none;
  box-shadow: inset 0 0 0 2px #ffd3db;
}

/* Memory */
.mem-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 340px; perspective: 800px; }
.card {
  position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: none;
  transform-style: preserve-3d; transition: transform .45s; cursor: pointer;
}
.card span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.card .back { background: linear-gradient(135deg, var(--pink), #ffb3c1); color: #fff; font-size: 30px; font-weight: 700; }
.card .front { background: #fff; font-size: 40px; transform: rotateY(180deg); box-shadow: inset 0 0 0 2px #ffd3db; }
.card.flip { transform: rotateY(180deg); }
.card.done .front { box-shadow: inset 0 0 0 3px var(--pink); animation: glow 1s; }

/* Scratch */
.coupon-wrap { position: relative; width: 100%; max-width: 320px; height: 190px; margin: 6px 0 18px; }
.coupon {
  position: absolute; inset: 0; border-radius: 18px; padding: 18px;
  background: repeating-linear-gradient(45deg, #fff, #fff 10px, #fff5f7 10px, #fff5f7 20px);
  border: 2px dashed var(--pink); display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.coupon-tag { color: var(--pink-d); font-size: 13px; letter-spacing: 4px; }
.coupon-main { font-size: 28px; font-weight: 700; }
.coupon-sub { font-size: 14px; color: var(--muted); }
.coupon-foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
#scratch-canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 18px; touch-action: none; cursor: grab; }

/* Letter */
.paper {
  width: 100%; margin-top: 30px; padding: 28px 22px;
  background: #fffdf9; border-radius: 6px;
  box-shadow: 0 10px 30px rgba(160, 90, 100, .18);
  background-image: repeating-linear-gradient(transparent, transparent 31px, #f5e3e6 32px);
  text-align: left;
}
.letter-text { white-space: pre-wrap; line-height: 32px; font-size: 16px; min-height: 260px; }
.caret::after { content: "▍"; color: var(--pink); animation: pulse 1s infinite; }

/* Hub */
.card-box { width: 100%; background: var(--card); border-radius: 20px; padding: 16px 18px; margin: 8px 0; text-align: left; box-shadow: 0 4px 14px rgba(232, 96, 125, .08); }
.card-box.center { text-align: center; }
.note { margin: 0; line-height: 1.7; white-space: pre-wrap; }
.fortune { text-align: center; }
.fortune .lv { font-size: 28px; font-weight: 700; color: var(--pink-d); margin: 4px 0; animation: pop .5s; }
.fortune .ft { line-height: 1.7; }
.big-btn {
  font: inherit; font-size: 18px; font-weight: 700; color: #fff;
  width: 140px; height: 140px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 35% 30%, #ffb3c1, var(--pink-d));
  box-shadow: 0 10px 0 #c94a66, 0 14px 24px rgba(201, 74, 102, .35);
  cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(8px); box-shadow: 0 2px 0 #c94a66, 0 4px 10px rgba(201, 74, 102, .3); }
.bubble { background: #fff; border-radius: 16px; padding: 12px 14px; margin: 18px 0 0; line-height: 1.7; box-shadow: 0 3px 10px rgba(232, 96, 125, .12); animation: pop .35s; text-align: left; }

/* Modal / toast */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(90, 58, 64, .35); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 24px; padding: 26px 20px 16px; max-width: 340px; width: 100%; text-align: center; animation: pop .35s; }
.modal-card .em { font-size: 54px; }
.modal-card p { line-height: 1.7; }
.toast {
  position: fixed; left: 50%; bottom: calc(40px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; background: rgba(90, 58, 64, .88); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 15px; max-width: 86vw; animation: rise .3s;
}
.toast[hidden] { display: none; }

/* Effects */
#petals, #fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#petals { z-index: 0; }
#fx { z-index: 40; }
.petal { position: absolute; top: -40px; font-size: 18px; opacity: .55; animation: fall linear infinite; }
.burst { position: absolute; font-size: 28px; animation: burst 1.4s ease-out forwards; }
.drop { position: absolute; top: -40px; font-size: 26px; animation: fall linear forwards; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }
@keyframes bounce { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-12px) rotate(3deg); } }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes glow { 50% { transform: rotateY(180deg) scale(1.08); } }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); } }
@keyframes burst { 0% { transform: translate(0, 0) scale(.6); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.2); opacity: 0; } }
