/* ============================================================
   A Christmas Card — for her
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --night: #121a2c;
  --ink: #f6efe6;
  --ink-2: rgba(246, 239, 230, 0.66);
  --gold: #f2c477;
  --paper: #f7f1e8;
  --paper-2: #efe6d9;
  --pen: #3b2a33;
  --ease: cubic-bezier(0.22, 0.68, 0.16, 1);
  /* the card's width; everything on it is measured in --u, a hundredth of that */
  --cw: min(410px, 76vw, calc((100svh - 190px) * 0.714));
  --u: calc(var(--cw) / 100);
}

html, body { margin: 0; height: 100%; }
body {
  min-height: 100svh;
  overflow: hidden;
  color: var(--ink);
  font-family: "Inter", system-ui, sans-serif;
  background:
    radial-gradient(70% 55% at 50% 42%, rgba(255, 196, 120, 0.13), transparent 70%),
    radial-gradient(120% 90% at 50% 0%, #22304d 0%, #141c30 55%, #0b101c 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

/* snow over the whole night, behind the card */
.sky { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------------- the stage ---------------- */
.stage {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding-bottom: 76px;
  perspective: 1600px;
}
/* .slide carries the card sideways as it opens; .tilt leans it towards the pointer */
.slide { transition: transform 1.1s var(--ease); transform-style: preserve-3d; }
.tilt { transform-style: preserve-3d; transition: transform 0.5s var(--ease); will-change: transform; }

.card {
  position: relative;
  width: var(--cw);
  aspect-ratio: 5 / 7;
  transform-style: preserve-3d;
  cursor: pointer;
  outline: none;
  animation: arrive 1.3s var(--ease) both;
}
.card:focus-visible::after { content: ""; position: absolute; inset: -10px; border-radius: 10px; outline: 2px solid var(--gold); }
@keyframes arrive { from { opacity: 0; transform: translateY(26px) rotateX(10deg); } to { opacity: 1; transform: none; } }

/* the shadow it casts on the table, which follows it open */
.card::before {
  content: ""; position: absolute; left: 4%; right: 2%; bottom: -5%; height: 14%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.5), transparent);
  filter: blur(8px); transform: translateZ(-2px);
  transition: left 1.1s var(--ease);
}
.card.is-open::before { left: -96%; }

.page, .face {
  position: absolute; inset: 0;
  border-radius: calc(var(--u) * 1.2);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 calc(var(--u) * 3) calc(var(--u) * 8) rgba(0, 0, 0, 0.35);
}
/* paper: a warm white, with the tooth of cold-pressed paper over it */
.paper {
  position: absolute; inset: 0;
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.38 0 0 0 0 0.3 0 0 0 0.16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(120% 90% at 30% 20%, rgba(255, 255, 255, 0.55), transparent 60%),
    linear-gradient(160deg, var(--paper), var(--paper-2));
}

/* ---------------- the cover ---------------- */
.cover {
  position: absolute; inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 1.15s var(--ease);
}
.card.is-open .cover { transform: rotateY(-178deg); }
/* swapping to another design: shut at once, no turn, and the new card arrives */
.card.no-turn .cover, .card.no-turn::before, .slide.no-turn { transition: none !important; }
.card.again { animation: arrive2 0.9s var(--ease) both; }
@keyframes arrive2 { from { opacity: 0; transform: translateY(18px) scale(0.97); } to { opacity: 1; transform: none; } }
.face { -webkit-backface-visibility: hidden; backface-visibility: hidden; }
.face--back { transform: rotateY(180deg); }

.art {
  position: absolute;
  left: 7%; right: 7%; top: 6%;
  aspect-ratio: 400 / 480;
}
.art__paint, .art__fx, .art__snow { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.art__snow { pointer-events: none; }

.front__greet {
  position: absolute; left: 5%; right: 5%; top: 81.5%; white-space: nowrap;
  margin: 0; text-align: center;
  font-family: "Fraunces", Georgia, serif; font-style: italic; font-weight: 400;
  font-size: calc(var(--u) * 8.6); line-height: 1;
  color: #7a2a2a; letter-spacing: -0.01em;
}
.front__for {
  position: absolute; left: 0; right: 0; top: 91%;
  margin: 0; text-align: center;
  font-size: calc(var(--u) * 2.9); letter-spacing: 0.28em; text-transform: uppercase;
  color: #8d7a6a;
}
/* the light catching the card as it turns */
.sheen {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(60% 45% at var(--sx, 30%) var(--sy, 20%), rgba(255, 255, 255, 0.32), transparent 70%);
  mix-blend-mode: soft-light;
  transition: opacity 0.4s;
}

/* ---------------- the inside ---------------- */
/* the left half inside: a printed verse under a small painting, like a shop card */
.inside { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 14% 14% 12%; text-align: center; }
.inside__frame { position: absolute; inset: 6%; border: 1.5px solid var(--accent, #b0452f); border-radius: calc(var(--u) * 1); opacity: 0.35; pointer-events: none; }
.inside__frame::after { content: ""; position: absolute; inset: calc(var(--u) * 1.4); border: 1px solid var(--accent, #b0452f); border-radius: calc(var(--u) * 0.6); opacity: 0.6; }
.inside__pic { height: calc(var(--u) * 34); width: auto; max-width: 84%; display: block; }
.inside__verse {
  margin: calc(var(--u) * 6) 0 0; max-width: 15em;
  font-family: "Fraunces", Georgia, serif; font-style: italic; font-weight: 400;
  font-size: calc(var(--u) * 5.6); line-height: 1.3; color: #5a3f3a; text-wrap: balance;
}
.inside__sprig { width: 24%; margin-top: calc(var(--u) * 6); opacity: 0.85; }
.inside__sprig svg { display: block; width: 100%; height: auto; }
.inside__year { margin: calc(var(--u) * 1) 0 0; font-family: "Caveat", cursive; font-size: calc(var(--u) * 5.4); color: #8d7a6a; }
.face--back .paper { background-color: var(--paper-2); }
/* the fold: a soft shadow down the spine on both halves */
.face--back::after, .page--right::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 8%; pointer-events: none;
}
.face--back::after { right: 0; background: linear-gradient(to left, rgba(80, 60, 40, 0.16), transparent); }
.page--right::after { left: 0; background: linear-gradient(to right, rgba(80, 60, 40, 0.18), transparent); }

.note {
  position: absolute; inset: 9% 10% 9% 12%;
  display: flex; flex-direction: column; justify-content: center;
  font-family: "Caveat", "Segoe Print", cursive;
  color: var(--pen);
  font-size: var(--fs, calc(var(--u) * 7));
  line-height: 1.22;
}
.note p { margin: 0; overflow-wrap: anywhere; }
.note__to { margin-bottom: 0.45em !important; font-weight: 600; }
.note__msg { white-space: normal; }
.note__from { margin-top: 0.55em !important; text-align: right; font-weight: 600; }
/* written in, word by word, once it's open */
.note .w { opacity: 0; filter: blur(2px); transition: opacity 0.45s ease, filter 0.45s ease; transition-delay: var(--d, 0s); }
.card.is-open .note .w { opacity: 1; filter: none; }

/* ---------------- moving bits of the paintings ---------------- */
.art__fx * { transform-box: fill-box; }
.fx-flick { animation: flick 3.2s ease-in-out infinite; }
@keyframes flick { 0%, 100% { opacity: 0.85; } 37% { opacity: 1; } 52% { opacity: 0.7; } 70% { opacity: 0.95; } }
.fx-puff { transform-origin: center; animation: puff 4.8s ease-out infinite; opacity: 0; }
@keyframes puff { 0% { opacity: 0; transform: translate(0, 0) scale(0.5); } 18% { opacity: 1; } 100% { opacity: 0; transform: translate(30px, -96px) scale(2.6); } }
.fx-d2 { animation-delay: -1.6s; } .fx-d3 { animation-delay: -3.2s; } .fx-d4 { animation-delay: -2.4s; }
.fx-tw { transform-origin: center; animation: tw 2.4s ease-in-out infinite; }
@keyframes tw { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.25; transform: scale(0.7); } }
.fx-t0 { animation-delay: 0s; } .fx-t1 { animation-delay: -0.5s; } .fx-t2 { animation-delay: -1s; } .fx-t3 { animation-delay: -1.5s; } .fx-t4 { animation-delay: -1.9s; }
.fx-pulse { transform-origin: center; animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.6; transform: scale(0.9); } 50% { opacity: 1; transform: scale(1.15); } }
.fx-steam { animation: steam 4.2s ease-in-out infinite; }
@keyframes steam { 0% { opacity: 0; transform: translateY(10px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(-26px); } }
.fx-heart { stroke-dasharray: 190; stroke-dashoffset: 190; animation: heart 7s ease-in-out infinite; }
@keyframes heart { 0%, 20% { stroke-dashoffset: 190; opacity: 0; } 30% { opacity: 0.75; } 60% { stroke-dashoffset: 0; opacity: 0.75; } 85%, 100% { stroke-dashoffset: 0; opacity: 0; } }
.fx-swing { transform-box: view-box; transform-origin: 200px 0; animation: swing 5s ease-in-out infinite; }
@keyframes swing { 0%, 100% { transform: rotate(-3.2deg); } 50% { transform: rotate(3.2deg); } }

/* ---------------- the strip ---------------- */
.hint {
  position: fixed; left: 0; right: 0; bottom: calc(88px + env(safe-area-inset-bottom));
  margin: 0; text-align: center; pointer-events: none;
  font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-2);
  transition: opacity 0.6s;
}
.hint.is-gone { opacity: 0; }
.bar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.bar__designs { display: flex; gap: 6px; }
.bar__designs[hidden], .bar__rule[hidden] { display: none; }
.thumb {
  width: 40px; height: 50px; padding: 0; border: 0; border-radius: 7px; cursor: pointer;
  background: var(--paper); overflow: hidden; position: relative;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: transform 0.25s var(--ease), box-shadow 0.25s;
}
.thumb svg { position: absolute; left: 7%; top: 6%; width: 86%; height: auto; }
.thumb:hover { transform: translateY(-2px); }
.thumb svg * { animation: none !important; }
.thumb[aria-checked="true"] { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(242, 196, 119, 0.45); }
.thumb:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.bar__rule { width: 1px; height: 30px; background: rgba(255, 255, 255, 0.18); margin: 0 2px; }
.bar__btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: var(--ink); color: #2a1d24;
  transition: transform 0.2s var(--ease), background 0.2s;
}
.bar__btn svg { width: 22px; height: 22px; }
.bar__btn:hover { transform: scale(1.06); }
.bar__btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.fab {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: 14px; z-index: 20;
  padding: 10px 16px; border-radius: 999px; cursor: pointer;
  background: rgba(10, 14, 26, 0.55); border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 13px; letter-spacing: 0.02em;
}
.fab[hidden] { display: none; }
.fab:hover { background: rgba(242, 196, 119, 0.22); }

/* ---------------- the editor ---------------- */
.ed, .share {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto;
  background: rgba(6, 9, 16, 0.72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ed[hidden], .share[hidden] { display: none; }
.ed__box, .share__box {
  position: relative; width: min(520px, 100%); margin: auto;
  padding: 28px 24px 24px; border-radius: 22px;
  background: linear-gradient(180deg, #1c2539, #141b2b);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
.share__box { width: min(440px, 100%); }
.ed__x {
  position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(255, 255, 255, 0.05); cursor: pointer;
}
.ed__kicker { margin: 0; font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase; color: var(--gold); }
.ed__title { margin: 6px 0 0; font-family: "Fraunces", Georgia, serif; font-weight: 400; font-size: 30px; line-height: 1.1; }
.ed__sub { margin: 8px 0 16px; font-size: 14px; line-height: 1.6; color: var(--ink-2); }
.ed__label, .ed__field > span { display: block; margin: 0 0 7px; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(246, 239, 230, 0.55); }
.ed__designs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.ed__designs .thumb { width: 100%; height: auto; aspect-ratio: 5 / 7; border-radius: 9px; }
.ed__designs .thumb span {
  position: absolute; left: 0; right: 0; bottom: 6%; font-size: 10px; line-height: 1.15; color: #7a5f52; text-align: center; padding: 0 3px;
}
.ed__field { display: block; position: relative; margin-bottom: 12px; }
.ed__field input, .ed__field textarea {
  width: 100%; padding: 11px 13px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12); background: rgba(0, 0, 0, 0.25);
  color: var(--ink); font: inherit; font-size: 16px; outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.ed__field textarea { resize: vertical; min-height: 96px; font-family: "Caveat", cursive; font-size: 22px; line-height: 1.25; }
.ed__field input:focus, .ed__field textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242, 196, 119, 0.16); }
.ed__field input::placeholder, .ed__field textarea::placeholder { color: rgba(246, 239, 230, 0.3); }
.ed__count { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: rgba(246, 239, 230, 0.4); }
.ed__note { min-height: 1.4em; margin: 2px 0 10px; font-size: 13px; color: #ffb4a8; }
.ed__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.ed__btn {
  flex: 1 1 140px; display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--ink); color: #241820; font-weight: 600; font-size: 15px; text-decoration: none;
}
.ed__btn--ghost { background: transparent; color: var(--ink); border: 1px solid rgba(255, 255, 255, 0.22); font-weight: 500; }
.ed__btn[hidden] { display: none; }
.share__link {
  width: 100%; margin-bottom: 14px; padding: 11px 13px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12); background: rgba(0, 0, 0, 0.25); color: var(--gold);
  font: 13px ui-monospace, Menlo, monospace; text-overflow: ellipsis;
}

/* ---------------- a link that arrived broken ---------------- */
.broken { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 28px; text-align: center; background: #0e1424; }
.broken[hidden] { display: none; }
.broken div { max-width: 30em; }
.broken h2 { margin: 0 0 12px; font-family: "Fraunces", Georgia, serif; font-weight: 400; font-size: clamp(22px, 5vw, 30px); }
.broken p { margin: 0; color: var(--ink-2); line-height: 1.7; }

/* ---------------- phones ---------------- */
@media (max-width: 700px) {
  /* there's no room for both halves side by side: the open card keeps the
     written half in the middle, and the left half folds away off-screen */
  .ed__title { font-size: 26px; }
  .ed__designs { gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .fx-flick, .fx-puff, .fx-tw, .fx-pulse, .fx-steam, .fx-heart, .fx-swing { animation: none !important; }
  .fx-puff, .fx-steam { opacity: 0.4; }
  .fx-heart { stroke-dashoffset: 0; opacity: 0.6; }
  .slide, .tilt, .cover, .card::before { transition-duration: 0.01s; }
  .note .w { transition: none; }
}
