/* ============ Story Calendar (Frame & Forever) ============ */
:root {
  --paper: #f6eee1;
  --paper-2: #efe3cf;
  --card: #fffaf1;
  --ink: #3a2029;
  --ink-soft: #6e5c51;
  --ink-faint: #a8968a;
  --rose: #B65A6E;
  --rose-deep: #5E1A33;
  --rose-soft: #ecc3c4;
  --gold: #C9A15A;
  --gold-soft: #dcc395;
  --shadow: 0 1px 2px rgba(60, 40, 25, .08), 0 8px 24px rgba(60, 40, 25, .12);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --script: "Pinyon Script", "Caveat", cursive;
  --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .15 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper) var(--paper-grain);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { text-align: center; padding: 40px 16px; }

.btn {
  border: 0; border-radius: 999px; padding: 12px 26px;
  font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: .04em;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.btn:active { transform: scale(.97); }
.btn-rose { background: var(--rose); color: #fff8f2; box-shadow: 0 6px 18px rgba(156, 70, 85, .28); }
.btn-rose:hover { background: var(--rose-deep); }
.btn-gold {
  background: linear-gradient(135deg, #c9a46a, #a87d45); color: #fffaf0;
  box-shadow: 0 6px 18px rgba(150, 110, 60, .3);
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-gold svg { width: 18px; height: 18px; fill: currentColor; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* ============ 1. Envelope gate ============ */
.gate {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255, 250, 240, .9), transparent 65%),
    var(--paper) var(--paper-grain);
  transition: opacity .9s ease, transform .9s ease;
}
.gate.leaving { opacity: 0; transform: scale(1.04); pointer-events: none; }
.gate-inner { width: 100%; max-width: 420px; text-align: center; }

.envelope {
  --w: min(84vw, 360px);
  position: relative; width: var(--w); height: calc(var(--w) / 1.45);
  margin: 0 auto 28px; perspective: 1200px;
  animation: env-float 6s ease-in-out infinite;
  filter: drop-shadow(0 18px 24px rgba(80, 50, 30, .18));
}
@keyframes env-float { 50% { transform: translateY(-6px); } }
.env-back, .env-front, .env-flap, .env-letter { position: absolute; inset: 0; border-radius: 6px; }
.env-back { background: #e3ccb0; z-index: 1; }
.env-letter {
  z-index: 2; inset: 8% 6% 6%;
  background: var(--card) var(--paper-grain); border-radius: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 10%;
  transition: transform 1.2s cubic-bezier(.2, .8, .2, 1);
}
.letter-script { font-family: var(--script); font-size: clamp(26px, 8vw, 36px); color: var(--rose-deep); }
.letter-line { width: 40%; height: 1px; background: var(--gold-soft); margin-top: 6px; }
.env-front {
  z-index: 3;
  background: linear-gradient(180deg, #f4e6d2, #eedcc3);
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 9%;
}
.env-name { font-family: var(--script); font-size: clamp(34px, 10vw, 46px); color: var(--ink); line-height: 1.1; }
.env-flap {
  z-index: 4; height: 60%;
  background: linear-gradient(180deg, #ecd8bd, #e2c8a8);
  clip-path: polygon(0 0, 100% 0, 50% 96%);
  transform-origin: 50% 0;
  transition: transform .9s cubic-bezier(.5, 0, .3, 1);
  border-radius: 6px 6px 0 0;
}
.env-seal {
  position: absolute; z-index: 5; left: 50%; top: 52%;
  width: 64px; height: 64px; margin: -32px 0 0 -32px; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d0717c, #a43c4c 55%, #7d2a38);
  box-shadow: inset 0 0 0 5px rgba(0, 0, 0, .08), inset 0 0 0 7px rgba(255, 255, 255, .12), 0 4px 10px rgba(90, 20, 30, .35);
  color: #f6dcc0; font-family: var(--script); font-size: 19px; letter-spacing: .02em;
  display: grid; place-items: center;
  transition: transform .5s ease, opacity .5s ease;
}
.env-seal:hover { transform: scale(1.05); }
.envelope.open { animation: none; }
.envelope.open .env-seal { transform: scale(1.4) rotate(-20deg); opacity: 0; pointer-events: none; }
.envelope.open .env-flap { transform: rotateX(180deg); }
.envelope.open.flap-back .env-flap { z-index: 1; }
.envelope.open.rise .env-letter { transform: translateY(-58%); }

.gate-note { font-style: italic; color: var(--ink-soft); margin: 0 0 18px; min-height: 1.5em; }
.gate-form { display: flex; gap: 10px; justify-content: center; }
.gate-form input {
  flex: 1; min-width: 0; max-width: 240px;
  border: 1px solid var(--gold-soft); background: rgba(255, 252, 246, .85);
  border-radius: 999px; padding: 12px 20px; font-family: var(--serif); font-size: 18px; color: var(--ink);
  text-align: center; letter-spacing: .15em;
}
.gate-form input::placeholder { letter-spacing: .02em; color: var(--ink-faint); font-style: italic; }
.gate-form input:focus { outline: none; border-color: var(--rose); box-shadow: 0 0 0 3px rgba(192, 106, 120, .15); }
.gate-form.shake { animation: shake .45s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.gate-hint { font-family: var(--hand); font-size: 19px; color: var(--ink-faint); margin: 14px 0 0; min-height: 1.4em; }
.gate-hint.error { color: var(--rose-deep); }

/* ============ 2. Calendar ============ */
.calendar { min-height: 100vh; padding: 0 16px calc(48px + env(safe-area-inset-bottom)); }
.calendar.unfold .cal-header { animation: rise-in 1s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes rise-in { from { opacity: 0; transform: translateY(24px); } }

.cal-header { text-align: center; padding: 48px 0 24px; max-width: 640px; margin: 0 auto; }
.cal-kicker { font-family: var(--script); font-size: 30px; color: var(--rose-deep); margin: 0; line-height: 1.2; }
.cal-title {
  font-weight: 500; font-size: clamp(40px, 11vw, 64px); letter-spacing: .06em; margin: 0;
  line-height: 1.05; text-transform: uppercase;
}
.cal-title::after {
  content: ""; display: block; width: 90px; height: 10px; margin: 14px auto 0;
  background: radial-gradient(circle, var(--gold) 2.5px, transparent 3px) center / 10px 10px no-repeat,
              linear-gradient(var(--gold-soft), var(--gold-soft)) left center / 38px 1px no-repeat,
              linear-gradient(var(--gold-soft), var(--gold-soft)) right center / 38px 1px no-repeat;
}
.counter { margin: 22px 0 26px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.counter-label { font-style: italic; color: var(--ink-soft); font-size: 17px; }
.counter-main { font-size: clamp(22px, 6vw, 30px); font-weight: 600; letter-spacing: .02em; }
.counter-main b { color: var(--rose-deep); font-weight: 600; }
.counter-sub { font-family: var(--hand); font-size: 20px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.timeline { max-width: 1060px; margin: 0 auto; }
.year { margin-top: 36px; }
.year-label {
  display: flex; align-items: center; gap: 16px; justify-content: center;
  font-size: 30px; font-weight: 500; letter-spacing: .2em; color: var(--gold); margin: 0 0 6px;
}
.year-label::before, .year-label::after { content: ""; flex: 1; max-width: 140px; height: 1px; background: var(--gold-soft); }
.month-label { font-family: var(--hand); font-size: 24px; line-height: 1.2; color: var(--ink-soft); margin: 0 4px 12px; min-height: 1.2em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; align-items: start; margin-top: 14px; }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 30px 24px; } }

/* A card = calendar page + polaroid */
.card {
  --tilt: 0deg; --rx: 0deg; --ry: 0deg; --glow: 0;
  position: relative; display: block; width: 100%; text-align: left;
  border: 0; padding: 0; background: none;
  perspective: 900px;
  opacity: 0; transform: translateY(30px) rotate(var(--tilt));
}
.card.in { opacity: 1; transform: rotate(var(--tilt)); transition: opacity .8s ease, transform .9s cubic-bezier(.2, .8, .2, 1); }
.card-body {
  position: relative; background: var(--card) var(--paper-grain);
  border-radius: 4px; padding: 0 9px 12px; box-shadow: var(--shadow);
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .25s ease, box-shadow .3s ease;
}
.card:hover .card-body, .card.touch .card-body {
  box-shadow: 0 2px 4px rgba(60, 40, 25, .08), 0 16px 34px rgba(60, 40, 25, .18), 0 0 0 1px rgba(220, 195, 149, .7), 0 0 28px rgba(232, 180, 140, .45);
}
.card-rings { position: absolute; top: -6px; left: 0; right: 0; display: flex; justify-content: center; gap: 46%; }
.card-rings i {
  width: 10px; height: 16px; border-radius: 6px; border: 2px solid var(--gold); border-bottom-color: transparent;
  background: transparent; display: block;
}
.card-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 14px 3px 8px; border-bottom: 1px dashed rgba(180, 138, 82, .45); margin-bottom: 9px;
}
.card-month { font-size: 13px; letter-spacing: .18em; text-transform: uppercase; color: var(--rose-deep); font-weight: 600; line-height: 1.2; }
.card-weekday { display: block; font-style: italic; letter-spacing: .02em; text-transform: none; color: var(--ink-faint); font-weight: 400; font-size: 14px; }
.card-day { font-size: 40px; line-height: .9; font-weight: 500; color: var(--ink); }
.card-art { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--paper-2); border-radius: 2px; }
.card-art img, .card-art canvas { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 1.2s ease; }
.card:hover .card-art img { transform: scale(1.06); }
.card-art.pencil img { filter: grayscale(1) contrast(1.1) sepia(.12); }
.card-title { font-family: var(--hand); font-size: 22px; line-height: 1.15; margin: 10px 2px 0; color: var(--ink); }
.card-seen {
  position: absolute; right: 8px; bottom: 10px; color: var(--rose); font-size: 14px; opacity: .8;
}

.card.locked .card-art img { filter: blur(6px) grayscale(.6) brightness(1.05); transform: scale(1.1); }
.card-lock {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: rgba(246, 238, 225, .55); text-align: center; color: var(--ink);
}
.card-lock svg { width: 26px; height: 26px; fill: none; stroke: var(--gold); stroke-width: 1.8; }
.card-lock span { font-family: var(--hand); font-size: 20px; line-height: 1.1; }
.card.locked.nudge .card-body { animation: shake .45s ease; }

.card.final .card-body {
  background: linear-gradient(160deg, #fff6ea, #f6e1d6);
  box-shadow: var(--shadow), 0 0 0 1px var(--gold-soft), 0 0 30px rgba(220, 160, 140, .5);
  animation: final-glow 3.5s ease-in-out infinite;
}
@keyframes final-glow { 50% { box-shadow: var(--shadow), 0 0 0 1px var(--gold), 0 0 44px rgba(220, 140, 130, .7); } }
.card.final .card-day { color: var(--rose); }
.final-art { display: grid; place-items: center; background: radial-gradient(circle at 50% 45%, #f7d9d3, #efd2bc 70%); }
.final-art svg { width: 46%; }

.final-section { margin-top: 44px; }
.cal-footer { text-align: center; margin-top: 56px; color: var(--rose-soft); font-size: 22px; }

/* ============ 3. Scene ============ */
.scene {
  position: fixed; inset: 0; z-index: 50;
  background: var(--paper) var(--paper-grain);
  overflow: hidden; opacity: 0; transition: opacity .6s ease;
}
.scene.show { opacity: 1; }
.scene-stage { position: absolute; left: 0; right: 0; top: 0; height: 52%; overflow: hidden; }
.scene-art { position: absolute; inset: 0; transform-origin: 50% 50%; will-change: transform; }
.scene-art svg, .scene-art canvas, .scene-art img { width: 100%; height: 100%; display: block; object-fit: cover; }
.scene-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scene-vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(60, 35, 20, .22) 100%),
              linear-gradient(180deg, transparent 70%, var(--paper) 100%);
}
.scene-text {
  position: absolute; left: 0; right: 0; bottom: 0; top: 46%;
  padding: 20px 24px calc(88px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(246, 238, 225, 0), var(--paper) 22px);
  overflow-y: auto; text-align: center;
}
.scene-text > * { max-width: 620px; margin-left: auto; margin-right: auto; }
.scene-date {
  font-size: 13px; letter-spacing: .28em; text-transform: uppercase; color: var(--rose-deep); font-weight: 600;
  opacity: 0; transform: translateY(8px); transition: opacity .8s ease, transform .8s ease;
}
.scene-title {
  font-weight: 500; font-size: clamp(28px, 7.5vw, 42px); line-height: 1.1; margin: 6px auto 12px;
  opacity: 0; transform: translateY(10px); transition: opacity 1s ease .15s, transform 1s ease .15s;
}
.scene.titled .scene-date, .scene.titled .scene-title { opacity: 1; transform: none; }
.scene-story { font-family: var(--hand); font-size: clamp(21px, 5.4vw, 28px); line-height: 1.35; color: var(--ink); margin-top: 0; }
.scene-story .w { opacity: 0; display: inline-block; transform: translateY(4px); transition: opacity .45s ease, transform .45s ease; }
.scene-story .w.on { opacity: 1; transform: none; }
.scene-sign { font-family: var(--script); font-size: 30px; color: var(--rose-deep); margin: 8px auto 0; opacity: 0; transition: opacity 1.2s ease; }
.scene-sign.on { opacity: 1; }

.scene-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 0;
}
.scene-progress { flex: 1; height: 3px; border-radius: 3px; background: rgba(255, 250, 240, .55); overflow: hidden; }
.scene-progress span { display: block; height: 100%; width: 0; background: var(--rose); }
.scene-controls {
  position: absolute; left: 0; right: 0; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 3;
  display: flex; justify-content: center; gap: 22px;
}
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(180, 138, 82, .35);
  background: rgba(255, 250, 242, .82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 0; box-shadow: 0 2px 10px rgba(60, 40, 25, .12);
  transition: transform .2s ease, background .2s ease;
}
.icon-btn:hover { background: #fff; }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--ink); stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path[fill="none"] { fill: none; }
.scene-top .icon-btn { width: 40px; height: 40px; }
#sceneMute .ico-off { display: none; }
#sceneMute.muted .ico-on { display: none; }
#sceneMute.muted .ico-off { display: block; }

/* Floating plane for trips */
.fx-plane { position: absolute; width: 64px; top: 14%; left: -80px; pointer-events: none; z-index: 2; }

/* Wide screens: picture left, words right */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .scene-stage { width: 62%; height: 100%; }
  .scene-vignette { background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(60, 35, 20, .22) 100%), linear-gradient(90deg, transparent 80%, var(--paper) 100%); }
  .scene-text {
    top: 0; left: 62%; padding: 80px 44px 110px; background: none;
    display: flex; flex-direction: column; justify-content: center; text-align: left;
  }
  .scene-text > * { margin-left: 0; }
  .scene-controls { left: 62%; }
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fbf3e8; padding: 10px 20px; border-radius: 999px;
  font-family: var(--hand); font-size: 20px; max-width: calc(100vw - 32px); text-align: center;
  transition: opacity .4s ease, transform .4s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Respect "reduce motion" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .2s !important; }
  .card { transform: none !important; }
  .card-body { transform: none !important; }
}

/* ============ Frame & Forever additions ============ */
.gate { position: relative; overflow: hidden; isolation: isolate; }
.gate-inner { position: relative; z-index: 2; }
.gate-backdrop {
  position: absolute; inset: -40px; z-index: 0; pointer-events: none; user-select: none;
  display: flex; flex-direction: column; align-items: center; padding: 70px 24px 0;
  filter: blur(9px) saturate(1.15); opacity: .9;
}
.gate-backdrop::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 45%, rgba(246, 238, 225, .75) 0%, rgba(246, 238, 225, .3) 50%, rgba(246, 238, 225, 0) 100%); }
.bd-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px; width: 100%; max-width: 980px; margin-top: 30px; }
.bd-card { aspect-ratio: 3 / 4; border-radius: 6px; background: var(--card); box-shadow: var(--shadow); overflow: hidden; transform: rotate(var(--r, 0deg)); }
.bd-card img { width: 100%; height: 70%; object-fit: cover; }
.is-private .bd-card { background: linear-gradient(160deg, #fffaf1 55%, var(--rose-soft)); }
.blur-text { filter: blur(7px); user-select: none; }
.gate-form.busy { opacity: .6; pointer-events: none; }
.gate-note a { color: var(--rose-deep); }
.ff-mark { position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 3; white-space: nowrap; text-decoration: none; font-family: "Bodoni Moda", var(--serif); font-size: 14px; letter-spacing: .26em; text-transform: uppercase; color: var(--rose-deep); opacity: .8; }
.ff-mark span { font-family: var(--script); font-size: 22px; letter-spacing: 0; text-transform: none; color: var(--gold); }
.ff-mark-foot { position: static; transform: none; display: block; margin-top: 10px; font-size: 12px; }

/* ---- Private story seen without the code: pictures visible, words blurred ---- */
.gate-peek { display: block; margin: 14px auto 0; border: 0; background: none; padding: 6px 10px; font-family: var(--serif); font-size: 17px; font-style: italic; color: var(--rose-deep); text-decoration: underline; text-underline-offset: 3px; }
.peek .card-title, .peek .scene-title, .peek .scene-story, .peek .scene-sign { filter: blur(7px); user-select: none; pointer-events: none; }
.peek .scene-story .w { filter: none; }
.peek-bar { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px; padding: 10px 16px; background: rgba(94, 26, 51, .96); color: #fff6ee; font-size: 16px; text-align: center; }
.peek-bar b { color: var(--gold); font-weight: 600; }
.peek-row { display: inline-flex; gap: 8px; }
.peek-bar input { width: 150px; border: 1px solid var(--gold); border-radius: 999px; padding: 8px 14px; font: inherit; background: #fffaf2; color: var(--ink); }
.peek-bar .btn { padding: 8px 18px; font-size: 16px; }
.peek-bar.shake { animation: shake .45s ease; }
.peek-bar.busy { opacity: .7; pointer-events: none; }

/* Home button on story pages */
.ff-home { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 12px; z-index: 40; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 250, 242, .9); border: 1px solid rgba(180, 138, 82, .35); color: var(--rose-deep); box-shadow: 0 2px 10px rgba(60, 40, 25, .12); }
.ff-home svg { width: 22px; height: 22px; }
.peek .ff-home { top: calc(64px + env(safe-area-inset-top)); }
