:root {
  --ink: #241220;
  --wine: #3E0F2C;
  --wine-2: #5C1A3F;
  --rose: #F2B8C6;
  --rose-dim: #D998A9;
  --red: #D6365B;
  --paper: #FBF1E9;
  --paper-2: #F3E4D6;
  --gold: #D9A441;
  --ink-soft: rgba(251, 241, 233, 0.72);

  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', sans-serif;
  --font-script: 'Caveat', cursive;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
  color: var(--paper);
}

button {
  font-family: inherit;
  cursor: pointer;
}

img { -webkit-user-drag: none; user-select: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------- layout shell ---------------- */

.app {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  min-height: 100dvh;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px 48px;
  background: radial-gradient(120% 90% at 50% 0%, var(--wine-2) 0%, var(--ink) 62%);
}

.screen.active {
  display: flex;
  animation: screenIn 520ms cubic-bezier(.22,.8,.32,1);
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.eyebrow {
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--rose-dim);
  margin: 0 0 10px;
  text-align: center;
  font-weight: 600;
}

.eyebrow--light { color: rgba(255,255,255,0.75); }

.script-title {
  font-family: var(--font-script);
  font-size: 52px;
  line-height: 1;
  color: var(--rose);
  margin: 0 0 6px;
  text-align: center;
  font-weight: 700;
}

.script-title--light { color: #fff; }

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  text-align: center;
  margin: 0 0 8px;
  color: var(--paper);
}

.body-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
  text-align: center;
  max-width: 320px;
  margin: 0 auto 20px;
}

.btn-main {
  margin-top: auto;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 15px 40px;
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(214,54,91,0.35);
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.btn-main:active { transform: scale(0.96); box-shadow: 0 6px 14px rgba(214,54,91,0.3); }
.btn-main--dark {
  background: var(--wine-2);
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
  border: 1px solid rgba(242,184,198,0.35);
}

.btn-main:focus-visible, button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* ---------------- floating hearts (signature texture) ---------------- */

.hearts-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.heart-particle {
  position: absolute;
  bottom: -10%;
  font-size: 18px;
  color: rgba(242,184,198,0.18);
  animation-name: floatUp;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

@keyframes floatUp {
  0% { transform: translateY(0) translateX(0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(-110vh) translateX(var(--drift,20px)) rotate(25deg); opacity: 0; }
}

.app, .screen { position: relative; z-index: 1; }

/* ================= 1. lock screen ================= */

.lives {
  position: absolute;
  top: 20px;
  left: 24px;
  display: flex;
  gap: 6px;
  font-size: 18px;
  z-index: 2;
}
.life { color: var(--red); transition: opacity 200ms ease, transform 200ms ease; }
.life.spent { opacity: 0.25; transform: scale(0.85); color: rgba(255,255,255,0.3); }

.lock-wrap {
  margin-top: 56px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lock-sub {
  font-size: 13.5px;
  color: var(--ink-soft);
  text-align: center;
  margin: 0 0 26px;
}

.code-dots {
  display: flex;
  gap: 16px;
  margin-bottom: 30px;
}
.code-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--rose-dim);
  background: transparent;
  transition: background 150ms ease, transform 150ms ease;
}
.code-dots span.filled {
  background: var(--rose);
  transform: scale(1.1);
}
.code-dots.shake { animation: shake 420ms ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  gap: 14px;
  justify-content: center;
}

.key {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid rgba(242,184,198,0.28);
  background: rgba(255,255,255,0.04);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, transform 100ms ease;
}
.key:active { transform: scale(0.92); background: rgba(242,184,198,0.18); }
.key--ghost { visibility: hidden; }
.key--del { font-size: 15px; letter-spacing: 0.02em; color: var(--rose-dim); border-color: transparent; background: transparent; }

.lock-message {
  min-height: 20px;
  margin-top: 22px;
  font-size: 13.5px;
  color: var(--red);
  text-align: center;
  font-weight: 500;
}
.lock-message.info { color: var(--gold); }

.polaroid {
  border: 6px solid #fff;
  border-bottom-width: 22px;
  box-shadow: 0 12px 26px rgba(0,0,0,0.45);
  object-fit: cover;
  object-position: center;
  background: #fff;
}

.polaroid--lock {
  position: absolute;
  bottom: 22px;
  right: -14px;
  width: 108px;
  height: 130px;
  transform: rotate(9deg);
}

/* ================= 2. success screen ================= */

#screen-success { justify-content: center; text-align: center; padding-top: 64px; }
#screen-success .script-title { font-size: 38px; line-height: 1.15; margin-bottom: 12px; }
#screen-success .body-text { margin-bottom: 8px; }

.success-photos {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin: 34px 0;
}

.polaroid--success1 {
  width: 108px;
  height: 132px;
  transform: rotate(-8deg);
  margin-right: -10px;
  z-index: 1;
}
.polaroid--success2 {
  width: 112px;
  height: 138px;
  transform: rotate(7deg);
  z-index: 2;
}

/* ================= 3. gifts screen — tirage au sort ================= */

#screen-gifts { padding-top: 56px; }

.gift-grid {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

/* Chaque carte est un bouton "vide" (perspective 3D) qui contient un
   recto (mystère) et un verso (le cadeau réel), assemblés en flip-card
   pour que rien ne soit visible avant le tirage. */
.gift-card {
  position: relative;
  width: 100%;
  border: none;
  background: none;
  padding: 0;
  color: inherit;
  text-align: left;
  perspective: 1200px;
}
.gift-card.disabled {
  opacity: 0.35;
  filter: grayscale(0.5);
  pointer-events: none;
  transition: opacity 420ms ease, filter 420ms ease;
}

.gift-card-inner {
  position: relative;
  min-height: 100px;
  transform-style: preserve-3d;
  transition: transform 620ms cubic-bezier(.22,.8,.32,1);
  animation: giftIn 480ms cubic-bezier(.22,.8,.32,1) backwards;
}
.gift-card:nth-child(1) .gift-card-inner { animation-delay: 40ms; }
.gift-card:nth-child(2) .gift-card-inner { animation-delay: 120ms; }
.gift-card:nth-child(3) .gift-card-inner { animation-delay: 200ms; }
@keyframes giftIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.gift-card.revealed .gift-card-inner { transform: rotateY(180deg); }

.gift-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  border: 1px solid rgba(242,184,198,0.25);
  background: rgba(255,255,255,0.045);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  overflow: hidden;
}

.gift-face--front {
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 5px;
  transition: transform 140ms ease;
}
.gift-card:not(.disabled):active .gift-face--front { transform: scale(0.97); }

.gift-mystery-icon { font-size: 26px; }
.gift-mystery-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--paper);
}
.gift-mystery-hint {
  font-size: 11.5px;
  color: var(--rose-dim);
  letter-spacing: 0.02em;
}

.gift-face--back { transform: rotateY(180deg); }

.gift-icon { font-size: 26px; }
.gift-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  display: block;
  color: var(--paper);
}
.gift-desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  display: block;
  margin-top: 2px;
}

.gift-face--photo {
  background-image: linear-gradient(100deg, rgba(36,18,32,0.8) 30%, rgba(36,18,32,0.2) 100%), var(--gift-img);
  background-size: cover;
  background-position: center;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
}

.polaroid--gift {
  position: absolute;
  bottom: 16px;
  left: -10px;
  width: 88px;
  height: 108px;
  transform: rotate(-10deg);
  opacity: 0.9;
}

.gift-confirm {
  margin-top: 22px;
  font-size: 13.5px;
  color: var(--gold);
  text-align: center;
  min-height: 18px;
}

#giftNextBtn {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 320ms ease, transform 320ms ease;
}
#giftNextBtn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ================= 4. letter intro ================= */

#screen-letter-intro {
  padding: 0;
  justify-content: center;
  align-items: center;
}

.bg-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  filter: blur(2px) saturate(0.9);
  transform: scale(1.08);
}

.bg-photo-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(36,18,32,0.55) 0%, rgba(36,18,32,0.86) 100%);
}
.bg-photo-veil--strong { background: linear-gradient(180deg, rgba(20,8,16,0.72) 0%, rgba(20,8,16,0.93) 100%); }

.letter-intro-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.envelope-card {
  border: 1px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(6px);
  border-radius: 20px;
  padding: 26px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-family: var(--font-display);
  font-size: 15px;
  animation: pulseGlow 2.4s ease-in-out infinite;
}
.envelope-icon { font-size: 34px; }

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242,184,198,0.0); }
  50% { box-shadow: 0 0 0 10px rgba(242,184,198,0.06); }
}

/* ================= 5. letter ================= */

#screen-letter { align-items: center; padding-top: 44px; }

.letter-paper {
  position: relative;
  background: var(--paper);
  color: #3a2a30;
  border-radius: 6px;
  padding: 34px 26px 30px;
  width: 100%;
  box-shadow: 0 18px 40px rgba(0,0,0,0.45);
  margin-bottom: 26px;
}

.letter-greeting {
  font-family: var(--font-script);
  font-size: 30px;
  margin: 0 0 14px;
  color: var(--red);
}

.letter-body {
  font-family: var(--font-display);
  font-size: 14.5px;
  line-height: 1.65;
  margin: 0 0 14px;
  color: #4a3038;
}

.letter-signature {
  font-family: var(--font-script);
  font-size: 24px;
  color: var(--red);
  margin-top: 18px;
}

.polaroid--letter1 {
  position: absolute;
  top: -22px;
  right: -12px;
  width: 78px;
  height: 96px;
  transform: rotate(10deg);
}
.polaroid--letter2 {
  position: absolute;
  bottom: -20px;
  left: -14px;
  width: 82px;
  height: 100px;
  transform: rotate(-9deg);
}

/* ================= 6. gallery ================= */

#screen-gallery { padding-top: 56px; }

.gallery-grid {
  width: 100%;
  columns: 2;
  column-gap: 10px;
  margin: 14px 0 28px;
}
.gallery-grid img {
  width: 100%;
  display: block;
  margin-bottom: 10px;
  border-radius: 10px;
  break-inside: avoid;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}

/* ================= 7. music ================= */

#screen-music {
  padding: 0;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.bg-photo--music { filter: blur(3px) saturate(0.85) brightness(0.75); }

.music-content {
  position: relative;
  z-index: 2;
  width: 100%;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.video-frame {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 16px 36px rgba(0,0,0,0.5);
  margin: 8px 0 14px;
  border: 1px solid rgba(255,255,255,0.15);
}
.video-frame iframe { width: 100%; height: 100%; border: 0; }

.audio-frame {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 20px;
  border-radius: 20px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: 0 16px 36px rgba(0,0,0,0.5);
  margin: 8px 0 14px;
}
.audio-frame-icon {
  font-size: 30px;
}
.audio-frame audio {
  width: 100%;
  max-width: 320px;
}

.music-caption {
  font-family: var(--font-script);
  font-size: 22px;
  color: var(--rose);
  margin: 0 0 18px;
}

.music-final {
  font-size: 14px;
  color: rgba(255,255,255,0.85);
}

/* ================= small screens ================= */

@media (max-width: 360px) {
  .keypad { grid-template-columns: repeat(3, 60px); gap: 10px; }
  .key { width: 60px; height: 60px; font-size: 20px; }
  .script-title { font-size: 44px; }
}
