@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=Caveat:wght@500;700&family=Outfit:wght@300;400;500;600&display=swap');

/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --ink-900: #161320;
  --ink-800: #211c30;
  --ink-700: #2c2640;
  --paper:   #f2e8d9;
  --paper-2: #e9dcc4;
  --wine:       #7c2f3e;
  --wine-light: #a4485a;
  --gold:  #c9a06a;
  --sage:  #7d8968;
  --kraft: #a9895f;
  --ash:     #c9c3d6;
  --ash-dim: #8a84a0;
  font-size: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 90% 60% at 20% -10%, #3a3050 0%, transparent 60%),
    radial-gradient(ellipse 70% 50% at 90% 100%, #241f38 0%, transparent 60%),
    linear-gradient(180deg, var(--ink-900), var(--ink-800) 40%, var(--ink-900));
  color: var(--ash);
  font-family: 'Outfit', sans-serif;
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed; inset: 0;
  background-image:
    radial-gradient(circle at 15% 30%, rgba(201,160,106,.05), transparent 40%),
    radial-gradient(circle at 85% 70%, rgba(124,47,62,.08),  transparent 40%);
  pointer-events: none;
  z-index: 0;
}

/* ============================================================
   HEADER
   ============================================================ */
header {
  position: relative; z-index: 1;
  max-width: 920px; margin: 0 auto;
  padding: 64px 24px 32px;
  text-align: center;
}

.eyebrow {
  font-family: 'Caveat', cursive;
  font-size: 1.4rem;
  color: var(--gold);
  letter-spacing: .02em;
  margin: 0 0 4px;
}

h1 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  margin: 0 0 12px;
  color: #f7f0e4;
  letter-spacing: .01em;
}

header p {
  font-size: .95rem;
  color: var(--ash-dim);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ============================================================
   PROGRESS STRIP
   ============================================================ */
.progress-wrap {
  position: relative; z-index: 1;
  max-width: 640px; margin: 0 auto 56px;
  padding: 18px 26px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 16px;
  display: flex; align-items: center; gap: 18px;
}

.progress-label { font-size: .8rem; color: var(--ash-dim); white-space: nowrap; }

.progress-track {
  flex: 1; height: 6px; border-radius: 99px;
  background: rgba(255,255,255,.08);
  position: relative; overflow: hidden;
}

.progress-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--wine), var(--gold));
  border-radius: 99px;
  transition: width .8s cubic-bezier(.4,0,.2,1);
}

.progress-frags { display: flex; gap: 6px; }

.frag {
  width: 14px; height: 14px; border-radius: 3px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  transition: all .4s;
}
.frag.on {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(201,160,106,.6);
}

/* ============================================================
   ENVELOPE GRID
   ============================================================ */
.grid {
  position: relative; z-index: 1;
  max-width: 960px; margin: 0 auto;
  padding: 0 24px 100px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 26px;
}

.env-card {
  position: relative;
  aspect-ratio: 3 / 3.6;
  border-radius: 6px;
  cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 16px;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1), box-shadow .35s;
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
  border: 1px solid rgba(0,0,0,.15);
}
.env-card:hover { transform: translateY(-6px) rotate(-.6deg); box-shadow: 0 16px 36px rgba(0,0,0,.45); }

/* envelope flap triangle */
.env-card::after {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 46%;
  background: inherit;
  filter: brightness(.88);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-bottom: 1px solid rgba(0,0,0,.15);
}

.env-num {
  font-family: 'Outfit', sans-serif;
  font-size: .65rem; letter-spacing: .12em;
  color: rgba(0,0,0,.35);
  z-index: 1; position: relative;
}

.env-title {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.08rem;
  line-height: 1.35;
  color: rgba(0,0,0,.72);
  z-index: 1; position: relative;
}

.env-meta {
  display: flex; align-items: center; justify-content: space-between;
  z-index: 1; position: relative;
}

.env-tag {
  font-size: .62rem; letter-spacing: .08em; text-transform: uppercase;
  color: rgba(0,0,0,.4);
}

.env-seal {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--wine-light), var(--wine) 70%);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; color: #f3e4c8;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.3);
}
.env-seal.opened { background: radial-gradient(circle at 35% 30%, #b8b0c9, #8a84a0 70%); opacity: .55; }

/* colour themes */
.env-card.kraft { background: #c9a877; }
.env-card.rose  { background: #e3b9c4; }
.env-card.sage  { background: #a9b394; }
.env-card.dark  { background: #a89bb0; }
.env-card.gold  { background: #e8cf9c; }

/* states */
.env-card.opened        { opacity: .62; filter: saturate(.6); }
.env-card.locked-future { filter: brightness(.7); }

.env-lock-badge {
  position: absolute; bottom: 16px; right: 16px; z-index: 2;
  font-size: .6rem; color: rgba(0,0,0,.55);
  background: rgba(255,255,255,.35);
  padding: 3px 8px; border-radius: 20px;
  backdrop-filter: blur(2px);
}

/* empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 24px;
  color: var(--ash-dim);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { font-family: 'Cormorant Garamond', serif; font-style: italic; font-size: 1.2rem; }

/* ============================================================
   FOOTER
   ============================================================ */
footer.note {
  position: relative; z-index: 1;
  text-align: center; padding: 0 24px 60px;
  font-size: .78rem; color: var(--ash-dim);
  max-width: 520px; margin: 0 auto;
  line-height: 1.7;
}
footer.note b { color: var(--gold); font-weight: 500; }

/* ============================================================
   OVERLAY
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10,8,16,.88);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .4s;
  padding: 24px;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.close-x {
  position: absolute; top: 24px; right: 28px;
  background: none; border: none; color: var(--ash);
  font-size: 1.6rem; cursor: pointer; opacity: .6;
  font-family: 'Outfit', sans-serif;
  transition: opacity .2s;
}
.close-x:hover { opacity: 1; }

.stage {
  width: 100%; max-width: 460px;
  perspective: 1400px;
}

/* envelope opening animation */
.env-anim {
  position: relative;
  width: 100%; aspect-ratio: 3 / 2;
  margin-bottom: 0;
}
.env-body {
  position: absolute; inset: 0;
  background: var(--paper-2);
  border-radius: 4px;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.env-flap {
  position: absolute; top: 0; left: 0; right: 0; height: 55%;
  background: linear-gradient(160deg, #e0d0b3, #c9b48f);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 1s cubic-bezier(.6,.05,.3,1);
  z-index: 3;
}
.env-anim.open .env-flap { transform: rotateX(180deg); }

.seal-big {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%);
  width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--wine-light), var(--wine) 75%);
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.35), 0 4px 10px rgba(0,0,0,.4);
  z-index: 4;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Cormorant Garamond', serif; font-style: italic; color: #f3e4c8; font-size: 1.1rem;
  transition: opacity .5s, transform .5s;
}
.env-anim.open .seal-big { opacity: 0; transform: translate(-50%,-50%) scale(.4) rotate(25deg); }

/* ============================================================
   LETTER PANEL
   ============================================================ */
.letter-panel {
  margin-top: 22px;
  background: var(--paper);
  border-radius: 6px;
  padding: 34px 30px 28px;
  max-height: 64vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  opacity: 0; transform: translateY(14px);
  transition: opacity .5s ease .1s, transform .5s ease .1s;
  color: #3a2f22;
}
.letter-panel.show { opacity: 1; transform: translateY(0); }

/* scrollbar */
.letter-panel::-webkit-scrollbar { width: 4px; }
.letter-panel::-webkit-scrollbar-track { background: transparent; }
.letter-panel::-webkit-scrollbar-thumb { background: rgba(124,47,62,.3); border-radius: 99px; }

/* lock screen */
.lock-screen { text-align: center; }
.lock-icon { font-size: 1.8rem; margin-bottom: 8px; }
.lock-riddle {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 1.15rem; line-height: 1.5; margin: 10px 0 20px;
  color: #4a3c2b;
}
.lock-input {
  width: 100%; padding: 12px 14px;
  border: 1px solid #cbb896; border-radius: 6px;
  background: #fbf6ec;
  font-family: 'Outfit', sans-serif; font-size: .9rem;
  color: #3a2f22;
  margin-bottom: 12px;
  text-align: center;
}
.lock-input:focus { outline: 2px solid var(--wine-light); outline-offset: 1px; }
.lock-btn {
  padding: 10px 22px;
  border: none; border-radius: 99px;
  background: var(--wine);
  color: #f6e9d4;
  font-family: 'Outfit', sans-serif; font-size: .85rem;
  cursor: pointer;
  transition: background .2s, transform .2s;
}
.lock-btn:hover { background: var(--wine-light); transform: translateY(-1px); }
.lock-hint { font-size: .72rem; color: #9a8a6f; margin-top: 10px; }
.lock-error { font-size: .8rem; color: var(--wine); margin-top: 8px; min-height: 20px; }

.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

/* letter body */
.letter-body {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.18rem; line-height: 1.75; color: #3a2f22;
}
.letter-sign {
  font-family: 'Caveat', cursive; font-size: 1.6rem;
  color: var(--wine); margin-top: 18px; display: block;
}
.cursor {
  display: inline-block; width: 2px; background: #3a2f22;
  margin-left: 1px; animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* audio row */
.audio-row {
  display: flex; align-items: center; gap: 10px;
  margin: 20px 0 6px;
  padding: 10px 14px;
  background: #e9dcc4;
  border-radius: 99px;
  width: fit-content;
  cursor: pointer;
  font-size: .78rem; color: #5a4a34;
  border: 1px solid #d7c39c;
  transition: background .2s;
}
.audio-row:hover { background: #dfd0b0; }
.audio-row.hidden { display: none; }

.wave { display: flex; align-items: center; gap: 2px; height: 14px; }
.wave span { width: 2px; background: var(--wine); border-radius: 2px; animation: wv 1s ease-in-out infinite; }
.wave span:nth-child(1) { height: 6px;  animation-delay: 0s; }
.wave span:nth-child(2) { height: 12px; animation-delay: .1s; }
.wave span:nth-child(3) { height: 8px;  animation-delay: .2s; }
.wave span:nth-child(4) { height: 14px; animation-delay: .3s; }
.wave span:nth-child(5) { height: 5px;  animation-delay: .4s; }
@keyframes wv { 0%,100% { transform: scaleY(.4); } 50% { transform: scaleY(1); } }
.audio-row.paused .wave span { animation-play-state: paused; }

/* finish row */
.finish-row { margin-top: 26px; text-align: center; }
.finish-btn {
  padding: 13px 26px;
  border: none; border-radius: 99px;
  background: linear-gradient(90deg, var(--wine), var(--wine-light));
  color: #f6e9d4; font-family: 'Outfit', sans-serif; font-size: .85rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(124,47,62,.4);
  transition: transform .2s, box-shadow .2s;
}
.finish-btn:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 12px 28px rgba(124,47,62,.5); }
.finish-btn:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
.finish-msg {
  font-family: 'Caveat', cursive; font-size: 1.2rem; color: var(--wine);
  margin-top: 12px; opacity: 0; transition: opacity .5s;
}
.finish-msg.show { opacity: 1; }

/* countdown */
.countdown-box { text-align: center; padding: 10px 0; }
.countdown-box .num {
  font-family: 'Cormorant Garamond', serif; font-size: 2.8rem; color: var(--wine);
  display: block; margin: 8px 0;
}
.countdown-box .cd-label {
  font-size: .85rem; color: #6a5840; line-height: 1.5;
}

/* ============================================================
   CONFETTI HEARTS
   ============================================================ */
.heart {
  position: fixed; top: -30px; z-index: 60;
  font-size: 1.2rem; pointer-events: none;
  animation: fall linear forwards;
  color: var(--wine-light);
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(360deg); opacity: 0; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  header { padding: 40px 20px 24px; }
  .grid  { grid-template-columns: repeat(2, 1fr); gap: 16px; padding: 0 16px 80px; }
  .progress-wrap { margin: 0 16px 40px; padding: 14px 18px; }
  .letter-panel { padding: 24px 20px 20px; }
  .stage { max-width: 100%; }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr; }
}
