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

html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #2a2144; color: #3A2E5C;
  font-family: 'Baloo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none;
}

#stage {
  position: fixed; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; overflow: hidden; background: #FFD6E0;
}
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; z-index: 30; }

.hidden { display: none !important; }
.invisible { visibility: hidden; opacity: 0; }
.grow { flex: 1; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; z-index: 5; display: flex; align-items: center; gap: 5px;
  top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 62px;
}
.pill {
  background: rgba(255,255,255,.85); border-radius: 999px; padding: 5px 10px;
  font-weight: 700; font-size: 15px; line-height: 1.25; white-space: nowrap;
}
.pill small { font-weight: 500; font-size: 12px; opacity: .75; margin-right: 4px; }
#lives { color: #FF4D6D; letter-spacing: 2px; font-size: 17px; }
.icon-btn {
  width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%; padding: 0;
  background: rgba(255,255,255,.85); font-size: 20px; line-height: 1; cursor: pointer;
}
#btn-mute {
  position: absolute; z-index: 40; right: 8px; top: calc(8px + env(safe-area-inset-top));
}

#slots {
  position: absolute; z-index: 5; left: 0; right: 0; pointer-events: none;
  top: calc(66px + env(safe-area-inset-top));
  display: flex; justify-content: center; gap: 5px;
}
.slot {
  width: 32px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  background: rgba(255,255,255,.55); border: 2px dashed rgba(58,46,92,.35);
  font-weight: 800; font-size: 22px; line-height: 1;
}
.slot.on { background: #FFC93C; border: 2px solid #fff; }
.slot.new { animation: pop .45s; }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px;
  padding: calc(64px + env(safe-area-inset-top)) 24px calc(28px + env(safe-area-inset-bottom));
  background: rgba(255,214,224,.92);
}
.screen.show { display: flex; animation: fade .35s; }
.screen.dark { background: rgba(58,46,92,.78); color: #fff; }
.screen.night { background: linear-gradient(#3A2E5C, #7b4b8a 62%, #ff8fa3); color: #fff; }

h1 { margin: 0; font-size: 48px; font-weight: 800; line-height: 1.05; color: #FF4D6D;
     text-shadow: 0 3px 0 #fff; }
h2 { margin: 0; font-size: 32px; font-weight: 800; line-height: 1.15; }
.lead { margin: 0; font-size: 20px; font-weight: 500; line-height: 1.35; max-width: 320px; }
.logo-heart { font-size: 96px; line-height: 1; color: #FF4D6D; animation: beat 1.1s infinite; }

.btn {
  min-height: 58px; min-width: 210px; margin-top: 14px; padding: 10px 32px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: #FF4D6D; color: #fff; box-shadow: 0 6px 0 #c9184a;
  font: 800 23px/1 'Baloo 2', system-ui, sans-serif;
  transition: transform .08s, box-shadow .08s, opacity .5s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9184a; }

.legend { list-style: none; margin: 4px 0 0; padding: 14px 16px; width: 100%; max-width: 330px;
          background: rgba(255,255,255,.75); border-radius: 18px; text-align: start; }
.legend li { display: flex; align-items: center; gap: 12px; font-size: 16px; font-weight: 500;
             line-height: 1.25; padding: 5px 0; }
.legend .ico { width: 30px; flex: none; text-align: center; font-size: 26px; line-height: 1; }

.big-word { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 6px 0; }
.big-word span {
  width: 44px; height: 54px; border-radius: 12px; display: grid; place-items: center;
  background: #FFC93C; border: 3px solid #fff; box-shadow: 0 4px 0 rgba(58,46,92,.18);
  font-weight: 800; font-size: 32px; line-height: 1;
  opacity: 0; animation: drop .5s forwards;
}
.big-word.small span { width: 32px; height: 42px; font-size: 23px; border-radius: 9px; gap: 4px; }
.progress { font-size: 20px; font-weight: 700; letter-spacing: 1px; opacity: .8; }

/* ---------- Surprise ---------- */
.final-sentence { min-height: 96px; font-size: 38px; font-weight: 800; line-height: 1.2;
                  text-shadow: 0 2px 12px rgba(255,77,109,.8); }
.final-sentence::after { content: '|'; opacity: .7; animation: blink .8s infinite; }
.final-sentence.done::after { content: ''; }

.envelope { position: relative; width: 220px; height: 146px; margin: 78px 0 6px; perspective: 600px; }
.envelope > div { position: absolute; }
.env-back  { inset: 0; background: #e85d7c; border-radius: 10px; }
.env-paper { left: 8%; right: 8%; top: 8%; height: 84%; background: #fff8fa; border-radius: 6px;
             display: grid; place-items: start center; padding-top: 12px; color: #FF4D6D; font-size: 34px;
             transition: transform .8s .45s; }
.env-front { inset: 0; background: #ffb3c1; border-radius: 10px;
             clip-path: polygon(0 0, 50% 58%, 100% 0, 100% 100%, 0 100%); }
.env-flap  { left: 0; top: 0; width: 100%; height: 62%; background: #FF4D6D; border-radius: 10px 10px 0 0;
             clip-path: polygon(0 0, 100% 0, 50% 100%); transform-origin: top;
             transition: transform .6s; z-index: 3; }
.envelope.open .env-flap  { transform: rotateX(180deg); z-index: 0; }
.envelope.open .env-paper { transform: translateY(-58%); }

.letter-card {
  width: 100%; max-height: 72%; overflow-y: auto; touch-action: pan-y;
  -webkit-overflow-scrolling: touch; text-align: start;
  background: #fff8fa; color: #3A2E5C; border-radius: 22px; padding: 22px 22px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3); animation: rise .7s;
}
.letter-card h2 { font-size: 27px; color: #FF4D6D; margin-bottom: 8px; }
.letter-card p { margin: 0 0 12px; font-size: 18px; font-weight: 500; line-height: 1.5; white-space: pre-line; }
.letter-card img { width: 100%; border-radius: 14px; margin: 6px 0 12px; display: block; }
.letter-card .extra { font-weight: 700; color: #c9184a; }
.letter-card .date { font-size: 15px; opacity: .7; }
.letter-card .sign { font-weight: 700; text-align: end; margin-bottom: 0; }
.letter-card p:empty { display: none; }

/* ---------- Rotate hint ---------- */
#rotate { display: none; position: fixed; inset: 0; z-index: 99; background: #3A2E5C; color: #fff;
          flex-direction: column; align-items: center; justify-content: center; font-size: 20px; gap: 8px; }
#rotate div { font-size: 54px; }
#rotate p { margin: 0; }
@media (orientation: landscape) and (max-height: 480px) and (pointer: coarse) { #rotate { display: flex; } }

@keyframes fade  { from { opacity: 0; } }
@keyframes pop   { 0% { transform: scale(.4); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes beat  { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.14); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }
@keyframes drop  { from { opacity: 0; transform: translateY(-40px) scale(.5) rotate(-12deg); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes rise  { from { opacity: 0; transform: translateY(60px) scale(.9); } }
