/* ==========================================================
   Sealed — stylesheet
   ========================================================== */

/* ---------- themes (shared by stage, cards, previews) ---------- */
:root {
  /* v8 design system: warm neutral wall, ink black, one red accent */
  --wall: #f3f2ee; --well: #f6f5f1; --rule: #e3e1db; --ink-ui: #16161a; --ink-hover: #2c2c33; --mute: #6b6a64; --dot: #d23a2c;
  --app-bg: var(--wall);
  --app-ink: var(--ink-ui);
  --muted: var(--mute);
  --line: var(--rule);
  --card: #ffffff;
  --wine: #16161a;
  --wine-2: #2c2c33;
  --wine-soft: #ecebe6;
  --serif: 'Cormorant Garamond', 'Times New Roman', serif;
  --sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 18px; --r: 12px; --r-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 20, 25, .05), 0 8px 28px -12px rgba(20, 20, 25, .18);
  --shadow-float: 0 1px 2px rgba(20, 20, 25, .05), 0 18px 48px -18px rgba(20, 20, 25, .28);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

[data-theme="romantic"] {
  --bg1: #fdeef0; --bg2: #f4c3cc;
  --env: #f3bcc5; --env-2: #eaa6b2; --env-3: #f8cfd6; --env-in: #d98d9b; --env-ink: #7a2a3c;
  --paper: #fffaf7; --ink: #5e2232; --accent: #c2405a;
  --seal: #a3162f; --seal-hi: #e0566d; --seal-lo: #6d0d1e;
  --stage-ink: #5e2232;
}
[data-theme="vintage"] {
  --bg1: #f3e8d2; --bg2: #d6be95;
  --env: #c9a679; --env-2: #b8915e; --env-3: #d6b88e; --env-in: #9c7445; --env-ink: #3d2a17;
  --paper: #f6ecd4; --ink: #3b2a1a; --accent: #8a3b2a;
  --seal: #7a1f1f; --seal-hi: #b0463c; --seal-lo: #4a0f10;
  --stage-ink: #3b2a1a;
}
[data-theme="minimal"] {
  --bg1: #fbfaf7; --bg2: #e7e4dc;
  --env: #ffffff; --env-2: #efede7; --env-3: #f8f7f3; --env-in: #dcd9d0; --env-ink: #26262a;
  --paper: #ffffff; --ink: #26262a; --accent: #26262a;
  --seal: #26262a; --seal-hi: #5b5b62; --seal-lo: #0e0e10;
  --stage-ink: #26262a;
}
[data-theme="midnight"] {
  --bg1: #24305a; --bg2: #090d22;
  --env: #2e3d71; --env-2: #23315f; --env-3: #3a4c88; --env-in: #182246; --env-ink: #f1e6c4;
  --paper: #fbf6e8; --ink: #1d2a55; --accent: #c99a3c;
  --seal: #b8862a; --seal-hi: #f3d27a; --seal-lo: #7a5612;
  --stage-ink: #ece8f6;
}

[data-theme="noel"] {
  --bg1: #fbf3e8; --bg2: #ead8c1;
  --env: #1f4d36; --env-2: #183f2c; --env-3: #285d42; --env-in: #11301f; --env-ink: #d8b35c;
  --paper: #fcf8ef; --ink: #1d3a2a; --accent: #b98a2c;
  --seal: #c4952f; --seal-hi: #f8dc86; --seal-lo: #735112;
  --stage-ink: #3d2c1c;
}
[data-theme="birthday"] {
  --bg1: #fff8ec; --bg2: #f4dbbd;
  --env: #f3e0c0; --env-2: #e8cfa5; --env-3: #f8ead2; --env-in: #d9b987; --env-ink: #9b5a1c;
  --paper: #fffdf8; --ink: #5a3416; --accent: #e07b39;
  --seal: #c0682b; --seal-hi: #f2ab6c; --seal-lo: #6a330c;
  --stage-ink: #5a3416;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--app-bg);
  color: var(--app-ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll, body.has-stage { overflow: hidden; }
img { max-width: 100%; }
a { color: var(--wine); }
h1, h2, h3 { line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--wine); outline-offset: 2px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: .95rem; font-weight: 500;
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--app-ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .15s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { border-color: #d6c7b8; box-shadow: 0 2px 8px rgba(60, 30, 20, .08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn-primary:hover { background: var(--wine-2); border-color: var(--wine-2); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0, 0, 0, .04); box-shadow: none; }
.btn-danger { background: #b3261e; border-color: #b3261e; color: #fff; }
.btn.danger { color: #b3261e; }
.btn-sm { padding: 6px 13px; font-size: .85rem; }
.btn-lg { padding: 14px 26px; font-size: 1.02rem; }

.input {
  width: 100%; font: inherit; color: var(--app-ink);
  padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #fffdfa;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--wine-2); box-shadow: 0 0 0 3px rgba(142, 47, 69, .12); }
textarea.input { resize: vertical; line-height: 1.7; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: .9rem; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--app-ink); cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: #d6c7b8; }
.chip.on { border-color: var(--wine); background: var(--wine-soft); color: var(--wine); }
.chip span { opacity: .6; font-size: .8em; margin-left: 2px; }
.font-chip { font-size: 1.05rem; }

.note { font-size: .85rem; color: var(--muted); background: #f6f0e9; border-radius: 10px; padding: 9px 12px; margin: 8px 0 0; }
.warn { font-size: .88rem; background: #fff3e0; color: #7a4a00; border-radius: 10px; padding: 10px 12px; }
.warn-inline { color: #9a5b00; }
.err { color: #b3261e; font-size: .88rem; margin: 8px 0 0; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgba(250, 246, 241, .86);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(233, 223, 213, .7);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 1.65rem;
  color: var(--app-ink); text-decoration: none; letter-spacing: .01em;
}
/* the logo: your own wax seal, rendered from the 3D seal (icons/seal*.png) */
.brand-seal { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(60, 20, 20, .25)); transition: transform .3s ease; }
.brand:hover .brand-seal { transform: rotate(-8deg) scale(1.05); }
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a {
  color: var(--app-ink); text-decoration: none; padding: 7px 12px; border-radius: 999px; font-size: .95rem;
}
.topbar nav a:hover { background: rgba(0, 0, 0, .04); }
.topbar nav a.on { background: var(--wine-soft); color: var(--wine); }
body[data-page="l"] .topbar, body[data-page="view"] .topbar { display: none; }

/* ---------- sections ---------- */
#app { min-height: calc(100vh - 64px); }
.section { max-width: 1120px; margin: 0 auto; padding: clamp(36px, 6vw, 72px) clamp(16px, 4vw, 40px); }
.sec-title, .page-title { font-family: var(--serif); font-weight: 500; font-size: clamp(1.9rem, 4vw, 2.6rem); margin: 0 0 8px; }
.sec-sub { color: var(--muted); margin: 0 0 26px; max-width: 60ch; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 40px 16px 56px; }

/* hero */
.hero {
  max-width: 1120px; margin: 0 auto;
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center;
  padding: clamp(40px, 8vw, 96px) clamp(16px, 4vw, 40px) clamp(24px, 4vw, 48px);
}
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .75rem; color: var(--wine); font-weight: 600; margin: 0 0 14px; }
.hero h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(2.3rem, 5.6vw, 4rem); line-height: 1.08; margin: 0 0 18px; }
.hero h1 em { color: var(--wine); }
.lead { font-size: 1.08rem; color: #5b4d47; max-width: 52ch; margin: 0 0 28px; }
.cta { display: flex; flex-wrap: wrap; gap: 12px; }
.hero-art { position: relative; height: 340px; }
.ha { position: absolute; width: min(300px, 72%); filter: drop-shadow(0 18px 30px rgba(80, 30, 40, .18)); }
.ha1 { right: 0; top: 0; transform: rotate(9deg); animation: float 7s ease-in-out infinite; }
.ha2 { left: 0; top: 70px; transform: rotate(-8deg); animation: float 8s ease-in-out -2s infinite; }
.ha3 { left: 18%; top: 150px; transform: rotate(2deg); animation: float 6s ease-in-out -4s infinite; }
@keyframes float { 50% { translate: 0 -10px; } }

/* theme cards */
.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.theme-card {
  border-radius: var(--radius); padding: 22px 20px 20px;
  background: radial-gradient(ellipse at 50% 0%, var(--bg1), var(--bg2));
  color: var(--stage-ink);
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 10px 30px -18px rgba(40, 20, 20, .5);
}
.theme-card .mini-env { margin: 6px 0 14px; transform: rotate(-2deg); }
.theme-card h3 { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; margin: 0; }
.theme-card p { margin: 0 0 12px; font-size: .9rem; opacity: .85; flex: 1; }
.theme-card .btn { align-self: flex-start; }

/* steps & features */
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; counter-reset: s; }
.steps li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; counter-increment: s; }
.steps li::before { content: counter(s); font-family: var(--serif); font-style: italic; font-size: 2.2rem; color: var(--wine); line-height: 1; display: block; margin-bottom: 8px; }
.steps b { display: block; font-size: 1.05rem; margin-bottom: 4px; }
.steps span { color: var(--muted); font-size: .93rem; }
.features { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.features > div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.features h3 { margin: 0 0 6px; font-size: 1.05rem; }
.features p { margin: 0; color: var(--muted); font-size: .93rem; }

/* ---------- mini envelope (static, CSS only) ---------- */
.mini-env {
  position: relative; width: 100%; aspect-ratio: 1.55; border-radius: 7px; overflow: hidden;
  background: var(--env);
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(0, 0, 0, .04);
}
.mini-env i { position: absolute; inset: 0; }
.mini-env .f1 { background: var(--env-2); clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%); }
.mini-env .f2 { background: linear-gradient(to top, var(--env), var(--env-3)); clip-path: polygon(0 100%, 50% 46%, 100% 100%); }
.mini-env .f3 { background: linear-gradient(to bottom, var(--env-3), var(--env)); clip-path: polygon(0 0, 100% 0, 50% 60%); filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .15)); }
.mini-seal {
  position: absolute; left: 50%; top: 60%; width: 22%; aspect-ratio: 1; translate: -50% -50%;
  display: grid; place-items: center; border-radius: 50%;
  font: 400 clamp(.8rem, 2.4vw, 1.3rem) / 1 Georgia, serif; color: rgba(0, 0, 0, .3);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .25);
  background: radial-gradient(circle at 35% 30%, var(--seal-hi), var(--seal) 58%, var(--seal-lo));
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3), inset 0 -2px 4px rgba(0, 0, 0, .25);
}

/* ==========================================================
   Stage (letter viewer)
   ========================================================== */
.stage {
  position: fixed; inset: 0; z-index: 30;
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 15%, var(--bg1), var(--bg2) 75%);
  color: var(--stage-ink);
  font-family: var(--sans);
}
.preview-overlay { position: fixed; inset: 0; z-index: 60; }
.preview-overlay .stage { z-index: 60; }
.scene {
  position: relative; z-index: 1;
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 76px 16px 48px;
}
.stage.reading .scene { justify-content: flex-start; }
.stage-home {
  position: fixed; top: 16px; left: 18px; z-index: 5;
  font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 1.35rem;
  color: var(--stage-ink); text-decoration: none; opacity: .8;
}
.stage-tools { position: fixed; top: 12px; right: 14px; z-index: 5; display: flex; gap: 8px; align-items: center; }
.music-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 1.1rem; color: #2a211e; background: rgba(255, 255, 255, .78);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .15); backdrop-filter: blur(6px);
  animation: spin 6s linear infinite;
}
.music-btn.off { animation: none; opacity: .6; text-decoration: line-through; }
@keyframes spin { to { rotate: 360deg; } }
.stage .btn { background: rgba(255, 255, 255, .82); border-color: rgba(255, 255, 255, .5); color: #2a211e; backdrop-filter: blur(6px); }
.stage .btn-primary { background: var(--seal); border-color: var(--seal); color: #fff; }
[data-theme="midnight"] .stage .btn-primary, .stage[data-theme="midnight"] .btn-primary { color: #1b1405; }

.stage-hint { margin-top: 36px; text-align: center; min-height: 3em; transition: opacity .4s; }
.stage-hint p { margin: 0; font-size: .95rem; letter-spacing: .02em; opacity: .85; animation: breathe 2.6s ease-in-out infinite; }
.stage-hint.gone { opacity: 0; }
.countdown { font-family: var(--serif); font-size: clamp(1.8rem, 6vw, 2.6rem); font-variant-numeric: tabular-nums; margin-top: 6px; letter-spacing: .03em; }
@keyframes breathe { 50% { opacity: .45; } }

.broken { max-width: 440px; text-align: center; background: #fff; border-radius: var(--radius); padding: 28px; box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .3); }
.broken h2 { font-family: var(--serif); font-weight: 500; font-size: 1.8rem; margin: 0 0 10px; }
.broken p { color: var(--muted); }

/* ---------- particles ---------- */
.particles { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.p-petal {
  position: absolute; top: -6vh; width: var(--s); height: calc(var(--s) * .72);
  background: radial-gradient(ellipse at 30% 30%, #ffe0e6, #f29aae);
  border-radius: 80% 0 80% 0; opacity: .85;
  animation: fall var(--dur) linear var(--delay) infinite;
}
@keyframes fall {
  from { transform: translate3d(0, 0, 0) rotate(0); }
  to { transform: translate3d(var(--drift), 112vh, 0) rotate(560deg); }
}
.p-star {
  position: absolute; width: var(--s); height: var(--s); border-radius: 50%;
  background: #fff; box-shadow: 0 0 6px 1px rgba(255, 255, 255, .7);
  animation: twinkle var(--dur) ease-in-out var(--delay) infinite;
}
@keyframes twinkle { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }
.p-dust {
  position: absolute; width: var(--s); height: var(--s); border-radius: 50%;
  background: rgba(255, 248, 230, .8); filter: blur(.5px);
  animation: dust var(--dur) ease-in-out var(--delay) infinite;
}
@keyframes dust {
  0%, 100% { transform: translate(0, 0); opacity: 0; }
  20%, 80% { opacity: .55; }
  50% { transform: translate(var(--drift), -60px); }
}
.p-snow {
  position: absolute; top: -6vh; width: var(--s); height: var(--s); border-radius: 50%;
  background: #fff; opacity: .85; box-shadow: 0 0 4px rgba(170, 150, 120, .35);
  animation: fall var(--dur) linear var(--delay) infinite;
}
.p-snow.flake {
  background: none; box-shadow: none; width: auto; height: auto; border-radius: 0;
  font-size: var(--s); line-height: 1; color: #fff; opacity: .75;
  text-shadow: 0 0 6px rgba(160, 140, 110, .35);
}
.p-confetti {
  position: absolute; top: -6vh; width: var(--s); height: calc(var(--s) * .45);
  background: var(--c); border-radius: 1px; opacity: .9;
  animation: fall var(--dur) linear var(--delay) infinite;
}
.stage[data-theme="midnight"] .particles::before, .studio-stage[data-theme="midnight"] .particles::before {
  content: ""; position: absolute; top: 9%; right: 12%; width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fffbe8, #f1dfa6 70%);
  box-shadow: 0 0 40px 10px rgba(255, 240, 190, .25), 0 0 120px 40px rgba(255, 240, 190, .08);
}

/* ---------- seal (wax / sticker / glue) with real thickness ---------- */
.seal {
  --size: var(--seal-size, 88px);
  position: absolute; left: 50%; top: 60%; z-index: 6;
  width: var(--size); height: var(--size); margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  padding: 0; border: 0; background: none; cursor: default;
  transform-style: preserve-3d;
  -webkit-tap-highlight-color: transparent;
}
.seal3d { position: absolute; inset: 0; transform-style: preserve-3d; transition: opacity .15s; }
.seal-edge, .seal-top { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.seal-top { display: block; }
.seal-shadow { position: absolute; inset: 9%; border-radius: 50%; background: rgba(0, 0, 0, .55); filter: blur(5px); transform: translate(5%, 8%); }
.wax { display: block; width: 100%; height: 100%; overflow: visible; }
.seal-half { position: absolute; inset: 0; display: block; transition: transform .9s cubic-bezier(.3, .6, .3, 1), opacity .9s ease; }
/* the seal breaks across: the top piece leaves with the flap, the bottom piece stays on the envelope */
.seal { --crack-bottom: polygon(0 50%, 10% 46%, 22% 54%, 34% 47%, 46% 55%, 58% 46%, 70% 54%, 82% 47%, 92% 53%, 100% 49%, 100% 100%, 0 100%); }
.seal-half.t { transform: translateZ(13px); clip-path: polygon(0 0, 100% 0, 100% 49%, 92% 53%, 82% 47%, 70% 54%, 58% 46%, 46% 55%, 34% 47%, 22% 54%, 10% 46%, 0 50%); }
.seal.crack .seal3d, .env3d.open .seal .seal3d { clip-path: var(--crack-bottom); }
.seal.crack .seal-half.t { transform: translate(6px, -64px) rotate(-22deg); opacity: 0; transition-delay: .3s; }
.seal.crack.resting { animation: none; }
.seal.press { animation: press .55s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes press { from { scale: 1.35; opacity: .4; } }
.seal-lock { position: absolute; right: -6px; top: -8px; font-size: 18px; opacity: 0; transition: opacity .3s; }
.locked .seal-lock { opacity: 1; }
.seal-glow { position: absolute; inset: -16%; border-radius: 50%; pointer-events: none; opacity: 0; background: radial-gradient(circle, rgba(255, 228, 170, .6), transparent 66%); }
.seal.ready { cursor: pointer; }
.seal.ready .seal-glow { animation: glow 2s ease-in-out infinite; }
@keyframes glow { 50% { opacity: 1; } }
.seal.crack { animation: wiggle .4s ease; pointer-events: none; }
@keyframes wiggle { 20% { rotate: -6deg; } 40% { rotate: 5deg; } 60% { rotate: -3deg; } 80% { rotate: 2deg; } }
.seal.is-sticker .seal-shadow { inset: 6%; filter: blur(3px); background: rgba(0, 0, 0, .35); transform: translate(3%, 5%); }
.seal.is-glue { width: 34%; height: 16%; margin: -8% 0 0 -17%; border-radius: 40%; }
.seal.is-glue .seal-glow { inset: -40%; }

/* ---------- 3D envelope ---------- */
.env3d {
  --w: min(86vw, 460px);
  --seal-size: calc(var(--w) * .21);
  --flap-h: 61%; --fold-y: 56%; --seal-top: 60%;
  --liner: linear-gradient(var(--env-in), var(--env-in));
  position: relative; width: var(--w); height: calc(var(--w) / 1.55);
  perspective: 1500px;
  animation: arrive .9s cubic-bezier(.2, .7, .2, 1) both;
}
.env3d.cover-round { --flap-h: 58%; --fold-y: 54%; --seal-top: 57%; }
.env3d.cover-square, .env3d.cover-straight { --flap-h: 42%; --fold-y: 38%; --seal-top: 40.5%; }
.env3d.cover-wavy { --flap-h: 55%; --fold-y: 50%; --seal-top: 54.5%; }
.env3d.cover-scalloped { --flap-h: 57%; --fold-y: 52%; --seal-top: 56.5%; }
.env3d.static, .env3d.noarrive { animation: none; }
/* pointer-driven 3D tilt (reader) */
.scene, .studio-scene { perspective: 1400px; }
.tilt {
  transform: rotateX(var(--rx, 5deg)) rotateY(var(--ry, -7deg));
  transition: transform .5s cubic-bezier(.2, .7, .3, 1);
  will-change: transform;
}
@keyframes arrive { from { opacity: 0; transform: translateY(30px) scale(.94); } }
.env3d.tappable { cursor: pointer; }
.env3d.tappable .env-card { animation: hover 3.2s ease-in-out infinite; }
@keyframes hover { 50% { transform: translateY(-8px) rotateX(4deg) rotateY(-4deg); } }
.env-card { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 1s cubic-bezier(.6, .05, .3, 1); }
.env3d.flipped .env-card { transform: rotateY(180deg); animation: none; }
.env-face {
  position: absolute; inset: 0; border-radius: 4px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 26px 50px -18px rgba(0, 0, 0, .45);
}
/* the back is a real 3D stack: inside → letter → folds → flap → seal, each a hair above the last */
.env-back { transform: rotateY(180deg) translateZ(var(--half-t)); transform-style: preserve-3d; }
.env-back > .env-inside, .env-back > .env-paper, .env-back > .env-fold { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.env-back::after { transform: translateZ(2.3px); }

.env-front {
  transform: translateZ(var(--half-t));
  background: var(--env-tex, none), var(--env);
  background-blend-mode: var(--env-blend, normal);
  overflow: hidden;
  container-type: inline-size;
}
/* foil edge */
.env3d.edge-gold .env-face::after, .env3d.edge-silver .env-face::after {
  content: ""; position: absolute; inset: 5px; z-index: 8; pointer-events: none; border-radius: 5px;
  border: 2.5px solid transparent;
  background: linear-gradient(135deg, #9c7020, #f6dc8c, #b8862a, #fff1c2, #a77b25) border-box;
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.env3d.edge-silver .env-face::after { background: linear-gradient(135deg, #8b95a3, #f4f7fb, #a7b1bf, #ffffff, #7e8896) border-box; }
/* airmail edge: red / blue diagonal bands */
.env3d.edge-airmail .env-front::after {
  content: ""; position: absolute; inset: 0; z-index: 8; pointer-events: none; border-radius: inherit;
  border: clamp(6px, 2.6cqw, 14px) solid transparent;
  background: repeating-linear-gradient(-45deg, #c8362b 0 10px, #fbf8f2 10px 17px, #26458f 17px 27px, #fbf8f2 27px 34px) border-box;
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.env3d.edge-xmas .env-front::after {
  content: ""; position: absolute; inset: 0; z-index: 8; pointer-events: none; border-radius: inherit;
  border: clamp(6px, 2.6cqw, 14px) solid transparent;
  background: repeating-linear-gradient(-45deg, #b8322a 0 10px, #fbf8f2 10px 17px, #2f6b45 17px 27px, #fbf8f2 27px 34px) border-box;
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.edge-pv.edge-airmail { border: 4px solid transparent; background: repeating-linear-gradient(-45deg, #c8362b 0 4px, #fbf8f2 4px 6px, #26458f 6px 10px, #fbf8f2 10px 12px) border-box; -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
.env-stamp small { text-transform: uppercase; }

.env-from {
  position: absolute; top: calc(8% + var(--ny, 0%)); left: calc(6% + var(--nx, 0%)); max-width: 45%; z-index: 3;
  font-size: calc(clamp(.8rem, 4.6cqw, 1.4rem) * var(--ns, 1)); font-weight: 600; line-height: 1.1;
  color: var(--env-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.env-postmark {
  position: absolute; top: calc(7% + var(--ny, 0%)); right: calc(8% - var(--nx, 0%)); width: 42%; height: auto; z-index: 3;
  color: color-mix(in srgb, var(--env-ink) 62%, transparent);
  transform: rotate(-9deg); transform-origin: 30% 50%;
}
.env-postmark.pm-waves { width: 38%; right: calc(2% - var(--nx, 0%)); }
.env-stamp-wrap {
  position: absolute; top: calc(6% + var(--ny, 0%)); right: calc(5.5% - var(--nx, 0%)); width: 17%; z-index: 2;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .3));
  transform: rotate(2deg);
}
.env-stamp {
  --r: 3.2px;
  aspect-ratio: .84; padding: 7%;
  background: #fffaf0;
  display: flex; flex-direction: column;
  /* perforated edges */
  -webkit-mask: linear-gradient(#000 0 0) content-box, radial-gradient(circle, #0000 calc(var(--r) - .5px), #000 var(--r)) calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3);
  mask: linear-gradient(#000 0 0) content-box, radial-gradient(circle, #0000 calc(var(--r) - .5px), #000 var(--r)) calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3);
}
.env-stamp-wrap.round .env-stamp { aspect-ratio: 1; border-radius: 50%; padding: 9%; -webkit-mask: none; mask: none; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .08); }
.env-stamp-wrap.round .stamp-art { border-radius: 50%; }
.env-stamp-wrap.round small { display: none; }
.stamp-art { flex: 1; position: relative; overflow: hidden; min-height: 0; background: #e9dcc4; }
.stamp-art svg, .stamp-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; max-width: none; }
.stamp-art::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(rgba(0, 0, 0, .06) .6px, transparent .8px) 0 0 / 3px 3px; mix-blend-mode: multiply; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.env-stamp small { display: flex; align-items: center; justify-content: center; text-align: center; font: 600 clamp(4px, 1.5cqw, 7px)/1 Georgia, serif; letter-spacing: .12em; color: #6b5a40; height: 1.9em; margin-bottom: -3%; white-space: nowrap; overflow: hidden; }
.env-address {
  position: absolute; left: calc(30% + var(--nx, 0%)); width: 58%; top: calc(48% + var(--ny, 0%)); z-index: 3;
  color: var(--env-ink);
}
.env-address i { display: block; height: 0; border-top: 1px solid color-mix(in srgb, var(--env-ink) var(--ar-a, 35%), transparent); margin-top: 9%; }
.env-address i.ar-dashed { border-top-style: dashed; }
.env-address i.ar-dotted { border-top: 2px dotted color-mix(in srgb, var(--env-ink) var(--ar-a, 35%), transparent); }
.env-address i.ar-wave { border: 0; height: 5px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='5'%3E%3Cpath d='M0 2.5Q3.5 0 7 2.5T14 2.5' fill='none' stroke='black' stroke-width='1'/%3E%3C/svg%3E") repeat-x; opacity: var(--ar-a, 35%); filter: none; }
.hand { font-family: 'Dancing Script', cursive; font-size: clamp(1.6rem, 6vw, 2.3rem); line-height: 1.15; overflow-wrap: anywhere; }
.env-address .hand {
  font-family: inherit; font-style: inherit;
  font-size: calc(clamp(1.2rem, 8.5cqw, 2.6rem) * var(--ns, 1)); line-height: 1.15;
  border-bottom: 1px solid color-mix(in srgb, var(--env-ink) 35%, transparent); padding: 0 0 3% 3%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* stickers (cover & letter) */
.stk {
  position: absolute; z-index: 4; translate: -50% -50%;
  transform: rotate(var(--rot, 0deg)) scale(var(--sc, 1));
  font-size: clamp(1.5rem, 9cqw, 2.4rem); line-height: 1;
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .2));
  user-select: none; -webkit-user-select: none;
}
.stk img { display: block; width: 1.6em; height: 1.6em; max-width: none; object-fit: contain; pointer-events: none; }
.paper .stk { font-size: clamp(1.7rem, 6vw, 2.3rem); }

.env-inside { position: absolute; inset: 0; border-radius: 8px; background: linear-gradient(rgba(0, 0, 0, .28), rgba(0, 0, 0, .45)), var(--env-in); transform: translateZ(.05px); }
.env-paper {
  position: absolute; left: 7%; right: 7%; top: 6%; height: 86%;
  background: var(--paper); border-radius: 3px; padding: 9% 10%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
  transform: translateZ(.6px);
  transition: transform 1.2s cubic-bezier(.3, .7, .3, 1);
}
.env-paper i { display: block; height: 2px; margin: 0 0 9%; border-radius: 2px; background: color-mix(in srgb, var(--ink) 18%, transparent); }
.env-paper i:nth-child(2) { width: 82%; }
.env-paper i:nth-child(3) { width: 90%; }
.env-paper i:nth-child(4) { width: 55%; }
.env3d.empty .env-paper { visibility: hidden; }
.env-fold { position: absolute; inset: 0; border-radius: 8px; }
.env-fold-lr { background: var(--env-tex, none), var(--env-2); background-blend-mode: var(--env-blend, normal); clip-path: polygon(0 0, 50% var(--fold-y), 100% 0, 100% 100%, 0 100%); transform: translateZ(1.1px); }
.env-fold-b { background: var(--env-tex, none), linear-gradient(to top, var(--env), var(--env-3)); background-blend-mode: var(--env-blend, normal); clip-path: polygon(0 100%, 50% 45%, 100% 100%); transform: translateZ(1.5px); }
/* two-sided flap: outside in envelope colour, inside with the liner */
.env3d { --flap-clip: polygon(0 0, 100% 0, 50% 100%); --liner-clip: polygon(4% 3%, 96% 3%, 50% 90%); }
.env3d.cover-round { --flap-clip: ellipse(64% 100% at 50% 0); --liner-clip: ellipse(58% 88% at 50% 0); }
.env3d.cover-square, .env3d.cover-straight { --flap-clip: polygon(0 0, 100% 0, 99.2% 90%, 96.5% 100%, 3.5% 100%, 0.8% 90%); --liner-clip: polygon(4% 3%, 96% 3%, 95.4% 83%, 93% 92%, 7% 92%, 4.6% 83%); }
.env3d.cover-wavy { --flap-clip: polygon(99.9% -0.0%, 99.9% 4.9%, 99.9% 9.8%, 99.8% 14.7%, 99.5% 19.6%, 98.9% 24.2%, 98.1% 28.7%, 97.2% 32.9%, 96.3% 37.1%, 95.5% 41.1%, 94.7% 45.2%, 93.9% 49.3%, 93.1% 53.5%, 92.4% 57.7%, 91.5% 62.0%, 90.6% 66.3%, 89.5% 70.4%, 88.3% 74.3%, 87.0% 77.8%, 85.6% 80.8%, 84.0% 83.4%, 82.4% 85.3%, 80.7% 86.8%, 78.9% 87.7%, 77.1% 88.3%, 75.3% 88.6%, 73.5% 88.7%, 71.8% 88.8%, 70.1% 89.0%, 68.3% 89.4%, 66.7% 90.1%, 65.0% 91.0%, 63.3% 92.2%, 61.6% 93.6%, 59.9% 95.1%, 58.2% 96.6%, 56.5% 98.0%, 54.8% 99.3%, 53.1% 100.2%, 51.3% 100.7%, 49.6% 100.8%, 47.8% 100.5%, 46.1% 99.8%, 44.3% 98.7%, 42.6% 97.3%, 40.9% 95.8%, 39.2% 94.3%, 37.5% 92.9%, 35.9% 91.6%, 34.2% 90.5%, 32.5% 89.7%, 30.8% 89.2%, 29.1% 88.9%, 27.3% 88.8%, 25.6% 88.7%, 23.8% 88.5%, 22.0% 88.1%, 20.2% 87.3%, 18.5% 86.1%, 16.8% 84.4%, 15.2% 82.2%, 13.7% 79.4%, 12.3% 76.1%, 11.0% 72.4%, 9.9% 68.3%, 8.9% 64.1%, 8.1% 59.9%, 7.2% 55.6%, 6.5% 51.4%, 5.7% 47.2%, 4.9% 43.2%, 4.1% 39.1%, 3.2% 35.0%, 2.3% 30.8%, 1.5% 26.5%, 0.8% 21.9%, 0.3% 17.2%, 0.1% 12.3%, 0.1% 7.4%, 0.1% 2.4%, 0.1% -0.0%); --liner-clip: polygon(95.9% -0.0%, 95.9% 4.5%, 95.9% 9.0%, 95.8% 13.6%, 95.5% 18.0%, 95.0% 22.3%, 94.3% 26.4%, 93.4% 30.3%, 92.6% 34.1%, 91.9% 37.8%, 91.1% 41.6%, 90.4% 45.4%, 89.7% 49.2%, 89.0% 53.1%, 88.2% 57.0%, 87.3% 61.0%, 86.4% 64.7%, 85.3% 68.3%, 84.1% 71.5%, 82.7% 74.4%, 81.3% 76.7%, 79.8% 78.5%, 78.2% 79.8%, 76.6% 80.7%, 74.9% 81.2%, 73.3% 81.5%, 71.7% 81.6%, 70.0% 81.7%, 68.5% 81.9%, 66.9% 82.3%, 65.3% 82.9%, 63.8% 83.7%, 62.2% 84.8%, 60.7% 86.1%, 59.1% 87.5%, 57.6% 88.9%, 56.0% 90.2%, 54.4% 91.3%, 52.8% 92.2%, 51.2% 92.6%, 49.6% 92.7%, 48.0% 92.4%, 46.4% 91.8%, 44.8% 90.8%, 43.2% 89.5%, 41.6% 88.2%, 40.1% 86.8%, 38.5% 85.4%, 37.0% 84.2%, 35.4% 83.3%, 33.9% 82.5%, 32.3% 82.1%, 30.8% 81.8%, 29.2% 81.7%, 27.5% 81.6%, 25.9% 81.4%, 24.2% 81.0%, 22.6% 80.3%, 21.0% 79.2%, 19.4% 77.7%, 18.0% 75.6%, 16.6% 73.0%, 15.3% 70.0%, 14.2% 66.6%, 13.1% 62.9%, 12.2% 59.0%, 11.4% 55.1%, 10.7% 51.1%, 9.9% 47.3%, 9.2% 43.5%, 8.5% 39.7%, 7.7% 36.0%, 7.0% 32.2%, 6.2% 28.3%, 5.4% 24.4%, 4.7% 20.2%, 4.3% 15.8%, 4.1% 11.3%, 4.1% 6.8%, 4.1% 2.2%, 4.1% -0.0%); }
.env3d.cover-scalloped { --flap-clip: polygon(99.9% -0.0%, 99.9% 4.8%, 99.8% 9.6%, 99.8% 14.4%, 99.7% 19.2%, 99.2% 23.9%, 97.9% 27.9%, 98.2% 33.1%, 98.0% 38.1%, 97.5% 42.7%, 96.6% 47.0%, 95.5% 50.9%, 93.9% 53.7%, 93.3% 58.4%, 92.5% 62.9%, 91.4% 66.8%, 90.0% 70.0%, 88.4% 72.5%, 86.6% 73.8%, 85.3% 77.0%, 84.0% 80.7%, 82.5% 83.4%, 80.9% 85.3%, 79.1% 86.5%, 77.3% 86.6%, 75.6% 88.2%, 74.1% 91.1%, 72.4% 92.9%, 70.7% 93.9%, 68.9% 94.3%, 67.1% 93.6%, 65.3% 93.9%, 63.7% 96.2%, 61.9% 97.4%, 60.2% 97.9%, 58.4% 97.8%, 56.6% 96.7%, 54.8% 95.8%, 53.1% 98.0%, 51.3% 98.8%, 49.6% 99.0%, 47.8% 98.5%, 46.0% 97.2%, 44.3% 95.3%, 42.5% 97.4%, 40.7% 97.9%, 39.0% 97.8%, 37.2% 96.9%, 35.5% 95.3%, 33.9% 92.1%, 32.0% 94.1%, 30.2% 94.2%, 28.4% 93.5%, 26.7% 92.1%, 25.1% 89.8%, 23.8% 85.5%, 21.8% 86.8%, 20.0% 86.1%, 18.3% 84.4%, 16.7% 82.1%, 15.3% 79.0%, 14.3% 74.4%, 12.4% 73.4%, 10.7% 71.4%, 9.3% 68.5%, 8.0% 64.9%, 7.1% 60.8%, 6.6% 55.7%, 5.2% 52.5%, 3.9% 49.0%, 2.9% 44.9%, 2.2% 40.4%, 1.8% 35.6%, 1.9% 30.5%, 1.3% 26.0%, 0.5% 21.6%, 0.2% 16.8%, 0.2% 12.0%, 0.2% 7.2%, 0.1% 2.4%, 0.1% -0.0%); --liner-clip: polygon(95.9% -0.0%, 95.9% 4.4%, 95.9% 8.8%, 95.8% 13.2%, 95.7% 17.7%, 95.2% 22.0%, 94.1% 25.7%, 94.4% 30.5%, 94.2% 35.0%, 93.7% 39.3%, 92.9% 43.3%, 91.9% 46.8%, 90.3% 49.4%, 89.8% 53.7%, 89.1% 57.9%, 88.1% 61.4%, 86.8% 64.4%, 85.4% 66.7%, 83.7% 67.9%, 82.5% 70.9%, 81.3% 74.2%, 79.9% 76.7%, 78.4% 78.5%, 76.8% 79.6%, 75.1% 79.7%, 73.6% 81.2%, 72.2% 83.8%, 70.6% 85.4%, 69.0% 86.4%, 67.4% 86.7%, 65.7% 86.1%, 64.1% 86.4%, 62.6% 88.5%, 61.0% 89.6%, 59.3% 90.1%, 57.7% 89.9%, 56.1% 88.9%, 54.4% 88.2%, 52.8% 90.1%, 51.2% 90.9%, 49.6% 91.1%, 48.0% 90.6%, 46.4% 89.4%, 44.8% 87.6%, 43.1% 89.6%, 41.5% 90.1%, 39.8% 89.9%, 38.2% 89.2%, 36.7% 87.6%, 35.2% 84.7%, 33.4% 86.6%, 31.8% 86.7%, 30.2% 86.0%, 28.6% 84.7%, 27.1% 82.7%, 25.9% 78.6%, 24.0% 79.8%, 22.4% 79.2%, 20.8% 77.7%, 19.4% 75.6%, 18.1% 72.7%, 17.1% 68.5%, 15.4% 67.5%, 13.9% 65.7%, 12.5% 63.0%, 11.4% 59.7%, 10.5% 55.9%, 10.1% 51.2%, 8.8% 48.3%, 7.6% 45.1%, 6.7% 41.3%, 6.0% 37.2%, 5.7% 32.8%, 5.8% 28.1%, 5.2% 24.0%, 4.5% 19.8%, 4.2% 15.5%, 4.1% 11.0%, 4.1% 6.6%, 4.1% 2.2%, 4.1% -0.0%); }
.env-flap {
  position: absolute; left: 0; top: 0; width: 100%; height: var(--flap-h);
  transform-origin: 50% 0; transform-style: preserve-3d;
  transform: translateZ(2px);
  transition: transform .9s cubic-bezier(.5, .1, .3, 1);
}
.flap-out, .flap-in { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flap-out { filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .18)); }
.flap-out > div, .flap-in > div { width: 100%; height: 100%; clip-path: var(--flap-clip); }
.flap-out > div { background: var(--env-tex, none), linear-gradient(to bottom, var(--env-3), var(--env)); background-blend-mode: var(--env-blend, normal); }
.flap-in { transform: rotateY(180deg); }
.flap-in > div { position: relative; background: linear-gradient(rgba(0, 0, 0, .12), rgba(0, 0, 0, .12)), var(--env-3); }
.flap-in > div::after {
  content: ""; position: absolute; inset: 0; clip-path: var(--liner-clip);
  background: linear-gradient(to bottom, rgba(0, 0, 0, .18), transparent 30%, rgba(255, 255, 255, .06)), var(--liner);
}
.env3d .seal { top: var(--seal-top); transform: translateZ(2.6px); }
.env3d.open .env-flap { transform: translateZ(.3px) rotateX(180deg); }
.env3d.rise .env-paper { transform: translateZ(.6px) translateY(-58%); }
.env3d.leave { animation: leave .55s ease-in forwards; }
@keyframes leave { to { opacity: 0; transform: translateY(40px) scale(.92); } }
.env3d.locked .env-front { filter: saturate(.85); }
.env3d.unlocked { animation: arrive .6s ease both; }

/* ---------- 2D folded note ---------- */
.note2d { animation: arrive .9s cubic-bezier(.2, .7, .2, 1) both; }
.note-paper {
  position: relative; width: min(82vw, 380px); aspect-ratio: 4 / 3;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, .035), transparent 48%, rgba(0, 0, 0, .05) 50%, transparent 52%),
    var(--paper);
  border-radius: 4px; color: var(--ink);
  box-shadow: 0 26px 50px -18px rgba(0, 0, 0, .45), 0 1px 0 rgba(255, 255, 255, .5) inset;
  --seal-size: clamp(70px, 22vw, 92px);
}
.note-fold { position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .14), transparent); }
.note-to { position: absolute; left: 0; right: 0; top: 13%; text-align: center; padding: 0 10%; }
.note-to small { text-transform: uppercase; letter-spacing: .22em; font-size: .62rem; opacity: .6; }
.note-to .hand { font-size: clamp(1.5rem, 5.5vw, 2rem); }
.note-paper .seal { top: 50%; }
.note2d.leave { animation: noteOut .6s ease-in forwards; }
@keyframes noteOut { to { opacity: 0; transform: scale(1.08) rotateX(25deg); } }
.note2d.locked .note-paper { filter: saturate(.85); }

/* ---------- paper (reading view & studio) ---------- */
.reader { width: 100%; max-width: 680px; margin: 0 auto; padding-bottom: 40px; }
.paper {
  position: relative; color: var(--ink);
  aspect-ratio: 1 / var(--ratio, 1.35);
  padding: clamp(30px, 7vw, 60px) clamp(24px, 7vw, 64px);
  font-family: var(--hand); font-style: var(--hand-style, normal);
  font-size: calc(clamp(1.12rem, 3.6vw, 1.36rem) * var(--hand-scale, 1)); line-height: var(--lh, 1.75);
  font-weight: var(--weight, 400); letter-spacing: var(--ls, 0);
  overflow-wrap: anywhere;
}
.paper > * { position: relative; z-index: 1; }
.paper > .paper-bg {
  position: absolute; inset: 0; z-index: 0; border-radius: 3px;
  /* printed ruling · soft directional light · the sheet colour; the material texture sits in ::before */
  background: var(--ruling-tex, linear-gradient(transparent, transparent)), var(--paper-light, linear-gradient(transparent, transparent)), var(--paper);
  /* paper thickness: a hair of edge below/right, then the cast shadow */
  box-shadow: 0 var(--paper-thick, 1px) 0 color-mix(in srgb, var(--paper) 80%, #000), 0 calc(var(--paper-thick, 1px) * 2) 1px rgba(0, 0, 0, .06), 0 34px 60px -24px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .08);
}
.paper > .paper-bg::before { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; background: var(--pbr-img, none) 0 0 / var(--pbr-size, 512px 512px), var(--paper-tex, none); opacity: calc(.35 + var(--grain, .6) * .65); mix-blend-mode: var(--paper-blend, normal); }
.paper.deckled > .paper-bg { -webkit-mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; border-radius: 0; box-shadow: none; }
.paper.deckled::before { content: ""; position: absolute; inset: 5px; z-index: 0; pointer-events: none; box-shadow: 0 34px 60px -24px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .1); }
.paper.fold-half > .paper-bg::after, .paper.fold-thirds > .paper-bg::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  --crease: transparent calc(var(--p) - 18px), rgba(0, 0, 0, .04) calc(var(--p) - 1px), rgba(255, 255, 255, .6) var(--p), rgba(0, 0, 0, .06) calc(var(--p) + 1px), transparent calc(var(--p) + 18px);
}
.paper.fold-half > .paper-bg::after { --p: 50%; background: linear-gradient(to bottom, var(--crease)); }
.paper.fold-thirds > .paper-bg::after {
  background:
    linear-gradient(to bottom, transparent calc(33.33% - 18px), rgba(0, 0, 0, .04) calc(33.33% - 1px), rgba(255, 255, 255, .6) 33.33%, rgba(0, 0, 0, .06) calc(33.33% + 1px), transparent calc(33.33% + 18px)),
    linear-gradient(to bottom, transparent calc(66.66% - 18px), rgba(0, 0, 0, .04) calc(66.66% - 1px), rgba(255, 255, 255, .6) 66.66%, rgba(0, 0, 0, .06) calc(66.66% + 1px), transparent calc(66.66% + 18px));
}
.paper-date { text-align: right; font-size: .78em; opacity: .7; margin-bottom: .9em; }
.paper-to { margin-bottom: .5em; font-weight: 600; }
.paper-body { text-align: var(--align, left); }
.paper-body p { margin: 0; }
.paper-body p + p { margin-top: var(--para, .5em); }
.paper-body p.gap { height: .9em; }
.paper-body .placeholder { opacity: .4; }
.paper-from { text-align: right; margin-top: 1.2em; }
.paper-from b { font-weight: 600; font-size: 1.12em; }
.paper-stickers { position: absolute !important; inset: 0; z-index: 2 !important; pointer-events: none; container-type: inline-size; }
.paper-stickers .stk { pointer-events: auto; }

/* theme paper frames */
[data-theme="romantic"] .paper > .paper-bg { box-shadow: 0 34px 60px -24px rgba(120, 20, 40, .4); }

[data-theme="noel"] .paper > .paper-bg { box-shadow: 0 34px 70px -24px rgba(20, 50, 30, .5); }
[data-theme="birthday"] .paper > .paper-bg { border-top: 6px solid transparent; border-image: repeating-linear-gradient(90deg, #f4a261 0 14px, #2a9d8f 14px 28px, #e9c46a 28px 42px, #f28482 42px 56px) 6; }
[data-theme="minimal"] .paper > .paper-bg { border-radius: 2px; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .35), 0 0 0 1px rgba(0, 0, 0, .05); }
[data-theme="minimal"] .paper-to { font-weight: 500; }
[data-theme="midnight"] .paper > .paper-bg { box-shadow: 0 34px 70px -20px rgba(0, 0, 0, .7); }

/* paper textures that need layout-aware patterns */
/* the rules are drawn once under the greeting and the body together, so "Gửi …," sits on the first one */
.paper[data-ruling="lined"] .paper-text { background: repeating-linear-gradient(transparent 0 calc(var(--lh, 1.75) * 1em - 1px), color-mix(in srgb, var(--ink) 17%, transparent) calc(var(--lh, 1.75) * 1em - 1px) calc(var(--lh, 1.75) * 1em)); }
.paper[data-ruling="lined"] .paper-body p.gap, .paper[data-ruling="ruled"] .paper-body p.gap { height: calc(var(--lh, 1.75) * 1em); }
/* school notebook: blue rules on the text lines + red margin */
.paper[data-ruling="ruled"] .paper-text { background: repeating-linear-gradient(transparent 0 calc(var(--lh, 1.75) * 1em - 1px), rgba(70, 120, 190, .38) calc(var(--lh, 1.75) * 1em - 1px) calc(var(--lh, 1.75) * 1em)); }
.paper[data-ruling="ruled"] > .paper-bg { background: linear-gradient(90deg, transparent 5.5cqi, rgba(214, 72, 72, .55) 5.5cqi calc(5.5cqi + 1.5px), transparent 0), var(--paper); }

/* writing animation: each word is revealed left→right like ink from a pen */
/* backwards, not both: once it has slid out nothing holds the transform, so the sheet is re-rendered sharp
   (a held end-state keeps the text rasterised at the small starting scale) */
.paper.animate { transform-origin: 50% 100%; animation: pullOut 1.2s cubic-bezier(.2, .7, .2, 1) backwards; }
@keyframes pullOut { from { opacity: 0; transform: translateY(42%) scale(.7); } 35% { opacity: 1; } }
@keyframes unfold { from { opacity: 0; transform: perspective(1400px) rotateX(-70deg) translateY(-24px); } }
/* the date, greeting and closing are handwritten word by word like the body (see .w) */
.paper.animate .w { display: inline-block; clip-path: inset(-40% 100% -40% 0); animation: write var(--wd) linear var(--d) forwards, wet 2.6s ease-out var(--d) both; }
/* fresh ink: darker and glossy, then dries */
@keyframes wet {
  0% { text-shadow: -.4px -.4px .6px rgba(255, 255, 255, calc(var(--wet, .6) * .9)), 0 .6px 1.4px rgba(0, 0, 0, calc(var(--wet, .6) * .35)); filter: brightness(calc(1 - var(--wet, .6) * .4)) saturate(calc(1 + var(--wet, .6) * .7)); }
  100% { text-shadow: none; filter: none; }
}
@keyframes write { to { clip-path: inset(-40% -8% -40% -8%); } }
.paper.animate .stk { animation: pop .5s cubic-bezier(.3, 1.6, .5, 1) var(--d) both; }
@keyframes ink { from { opacity: 0; filter: blur(3px); transform: translateY(5px); } }
@keyframes pop { from { opacity: 0; scale: .2; } }
.paper.done .w { animation: none; clip-path: none; }
.paper.done .paper-from, .paper.done .paper-date, .paper.done .paper-to, .paper.done .stk { animation: none; }

/* polaroids */
.polaroids { display: flex; flex-wrap: wrap; justify-content: center; gap: 22px 18px; margin-top: 40px; }
.polaroid {
  margin: 0; width: min(40vw, 180px); background: #fff; padding: 10px 10px 0; cursor: zoom-in;
  box-shadow: 0 14px 28px -12px rgba(0, 0, 0, .45);
  transform: rotate(var(--r)); transition: transform .35s cubic-bezier(.3, .7, .3, 1), box-shadow .35s;
  position: relative;
}
.polaroid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #eee; }
.polaroid figcaption { font-family: 'Patrick Hand', cursive; font-style: normal; color: #3a3330; text-align: center; padding: 8px 4px 12px; min-height: 2.6em; font-size: 1.05rem; line-height: 1.2; }
.polaroid:hover { transform: rotate(0) translateY(-4px); }
.polaroid.lift { transform: rotate(0) scale(1.45); z-index: 10; cursor: zoom-out; box-shadow: 0 30px 60px -10px rgba(0, 0, 0, .5); }
.polaroids.animate .polaroid { animation: drop .8s cubic-bezier(.2, .8, .3, 1.2) calc(var(--end, 2s) + .6s + var(--k) * .25s) both; }
@keyframes drop { from { opacity: 0; transform: translateY(-40px) rotate(calc(var(--r) * -3)); } }

.reader-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 40px; animation: ink .8s ease calc(var(--end, 2s) + 1s) both; }

/* extra effects */
.p-heart { position: absolute; bottom: -6vh; font-size: var(--s); line-height: 1; color: #e8657f; opacity: .7; animation: rise var(--dur) linear var(--delay) infinite; }
@keyframes rise { from { transform: translate(0, 0) rotate(-10deg); } to { transform: translate(var(--drift), -115vh) rotate(15deg); } }
.p-firefly { position: absolute; width: var(--s); height: var(--s); border-radius: 50%; background: #fff3b0; box-shadow: 0 0 10px 3px rgba(255, 228, 120, .7); animation: wander var(--dur) ease-in-out var(--delay) infinite alternate; }
@keyframes wander { 0% { transform: translate(0, 0); opacity: .2; } 50% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)); opacity: .3; } }
.fx-candle { position: absolute; inset: 0; background: radial-gradient(ellipse 80% 60% at 50% 105%, rgba(255, 180, 80, .35), transparent 70%), radial-gradient(ellipse 120% 90% at 50% 50%, transparent 60%, rgba(60, 30, 0, .18)); animation: flicker 3.2s ease-in-out infinite; }
@keyframes flicker { 0%, 100% { opacity: .85; } 30% { opacity: 1; } 55% { opacity: .75; } 70% { opacity: .95; } }

/* ---------- modal & toast ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: rgba(30, 18, 16, .45); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .2s;
  font-family: var(--sans); color: var(--app-ink);
}
.modal-back.in { opacity: 1; }
.modal-back.out { opacity: 0; }
.modal {
  width: min(100%, 480px); max-height: calc(100vh - 32px); overflow: auto;
  background: #fffdfa; border-radius: 20px; padding: 24px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5);
  transform: translateY(10px); transition: transform .25s;
}
.modal-back.in .modal { transform: none; }
.modal h3 { font-family: var(--serif); font-weight: 600; font-size: 1.6rem; margin: 0 0 10px; }
.modal-body p { margin: 0 0 12px; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { translate: -8px 0; } 40%, 80% { translate: 8px 0; } }
.share-row { display: flex; gap: 8px; margin-bottom: 8px; }
.share-row .input { font-size: .85rem; }
.share-grid { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: start; margin-top: 12px; }
.qr { background: #fff; border-radius: 12px; padding: 6px; border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: auto; }
.share-lines { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.share-lines p { width: 100%; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 110;
  translate: -50% 20px; opacity: 0; transition: all .3s;
  background: #2a211e; color: #fff; padding: 11px 18px; border-radius: 999px;
  font: 500 .9rem/1.4 var(--sans); max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.toast.in { translate: -50% 0; opacity: 1; }

/* ==========================================================
   Editor
   ========================================================== */
.write-head { max-width: 1200px; margin: 0 auto; padding: 32px clamp(16px, 4vw, 40px) 0; }
.write-head .sec-sub { margin-bottom: 10px; }
.write-grid {
  max-width: 1200px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px;
  padding: 16px clamp(16px, 4vw, 40px) 130px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; }
.card h2 { font-family: var(--serif); font-weight: 600; font-size: 1.45rem; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; }
.card h2 span { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--wine-soft); color: var(--wine); font: 600 .9rem var(--sans); }
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; font-size: .85rem; font-weight: 500; color: #5b4d47; margin-bottom: 7px; }
.field > label.btn { display: inline-flex; color: var(--app-ink); margin: 0; }
.field small { font-weight: 400; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.body-input { min-height: 240px; font-size: 1.25rem; }
.hint-row { text-align: right; font-size: .8rem; color: var(--muted); min-height: 1.2em; margin-top: 4px; }

.theme-pick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tp { font: inherit; font-size: .85rem; border: 2px solid transparent; border-radius: 14px; padding: 8px 8px 6px; background: #f7f2ec; cursor: pointer; display: flex; flex-direction: column; gap: 6px; align-items: center; color: var(--app-ink); }
.tp.on { border-color: var(--wine); background: var(--wine-soft); }
.seal-pick { display: flex; flex-wrap: wrap; gap: 10px; }
.seal-chip {
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  font: 400 1.2rem/1 Georgia, serif; color: rgba(0, 0, 0, .32); text-shadow: 0 1px 0 rgba(255, 255, 255, .25);
  background: radial-gradient(circle at 34% 28%, var(--seal-hi), var(--seal) 56%, var(--seal-lo));
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, .3), 0 2px 4px rgba(0, 0, 0, .2);
  transition: transform .15s;
}
.seal-chip.on { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--wine), inset 0 -3px 5px rgba(0, 0, 0, .3); transform: scale(1.06); }
.sticker-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.st { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 1.4rem; cursor: pointer; transition: all .15s; }
.st.on { border-color: var(--wine); background: var(--wine-soft); transform: scale(1.06); }
.photo-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.photo-list:empty { display: none; }
.photo-row { display: flex; gap: 10px; align-items: center; }
.photo-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .15); }
.file-btn { cursor: pointer; }
.music-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }

.preview-col { position: sticky; top: 84px; align-self: start; }
.preview-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-bottom: 8px; }
.live-preview {
  border-radius: var(--radius); padding: 28px 26px;
  max-height: calc(100vh - 220px); overflow: auto;
  background: radial-gradient(ellipse at 50% 0%, var(--bg1), var(--bg2));
}
.live-preview .paper { padding: 32px 30px; }
.live-preview .polaroids { margin-top: 26px; }
.live-preview .polaroid { width: 120px; }
.live-preview .polaroid figcaption { font-size: .9rem; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(250, 246, 241, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}

/* ==========================================================
   Letter box
   ========================================================== */
.box-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.filter { margin-bottom: 24px; }
.box-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.letter-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.lc-top { position: relative; display: block; padding: 24px 16% 22px; background: radial-gradient(ellipse at 50% 0%, var(--bg1), var(--bg2)); }
.lc-top .mini-env { transition: transform .3s; }
.lc-top:hover .mini-env { transform: translateY(-4px) rotate(-1.5deg); }
.lc-lock { position: absolute; top: 10px; right: 12px; font-size: 1rem; }
.lc-body { padding: 14px 16px 4px; }
.lc-body h3 { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; margin: 6px 0 2px; overflow-wrap: anywhere; }
.lc-body p { margin: 0; }
.lc-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 16px; margin-top: auto; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; letter-spacing: .03em; }
.badge-private { background: #efe9f7; color: #5b3f8a; }
.badge-sent { background: var(--wine-soft); color: var(--wine); }
.badge-received { background: #e6f2ea; color: #2f6b45; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .mini-env { width: 180px; margin: 0 auto 16px; transform: rotate(-3deg); }

/* ==========================================================
   Standalone exported file
   ========================================================== */
body.standalone { background: #000; }

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 960px) {
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .write-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-col { display: none; }
}
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; gap: 10px; }
  .hero-art { height: 240px; order: -1; max-width: 420px; width: 100%; margin: 0 auto; }
  .ha { width: 58%; }
  .ha2 { top: 50px; }
  .ha3 { top: 100px; }
  .steps, .features { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .theme-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .share-grid { grid-template-columns: 1fr; }
  .qr { max-width: 180px; }
  .actionbar .btn { padding: 9px 12px; font-size: .86rem; flex: 1 1 calc(50% - 10px); }
  .topbar nav a { padding: 6px 9px; font-size: .9rem; }
  .brand { font-size: 1.45rem; }
}
@media (max-width: 420px) {
  .theme-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .particles { display: none; }
  .ha, .music-btn, .seal.ready, .env3d.tappable .env-card, .stage-hint p { animation: none !important; }
  .paper.animate .w { animation-duration: .01s; }
}

/* ==========================================================
   Studio editor (live 3D preview + tabbed panel)
   ========================================================== */
body[data-page="write"] { overflow: hidden; }
.studio {
  display: grid; grid-template-columns: minmax(0, 1fr) 440px;
  height: calc(100vh - 65px); height: calc(100dvh - 65px);
}
.studio-stage {
  position: relative; overflow: hidden; min-height: 0;
  background: radial-gradient(ellipse at 50% 20%, var(--bg1), var(--bg2) 80%);
  color: var(--stage-ink);
}
.studio-scene {
  position: absolute; inset: 0 0 72px 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; container-type: size;
}
.studio-scene .env3d { --w: min(78cqw, 120cqh, 640px); }
.studio-scene.is-inside .env3d { --w: min(70cqw, 86cqh, 560px); translate: 0 22%; }
.studio-stage .particles { position: absolute; }
.studio-scene.is-letter { align-items: flex-start; overflow-y: auto; container-type: normal; }
.studio-letter { width: min(100%, 640px); margin: 8px auto 24px; }
.studio-letter .paper { cursor: default; }
.studio-bar {
  position: absolute; left: 50%; bottom: 18px; translate: -50% 0; z-index: 3;
  display: flex; gap: 8px; align-items: center; max-width: calc(100% - 24px);
}
.seg {
  display: flex; padding: 4px; border-radius: 999px; overflow-x: auto; scrollbar-width: none;
  background: rgba(255, 255, 255, .86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .25);
}
.seg button {
  border: 0; background: none; cursor: pointer; white-space: nowrap;
  padding: 7px 14px; border-radius: 999px; font: 500 .88rem var(--sans); color: #776963;
}
.seg button.on { background: #fff; color: #2a211e; box-shadow: 0 1px 4px rgba(0, 0, 0, .14); }
.studio-bar .try { background: rgba(255, 255, 255, .9); box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .25); border-color: transparent; }

.studio-panel { display: flex; flex-direction: column; min-height: 0; background: #fff; border-left: 1px solid var(--line); }
.studio-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); flex: none; }
.studio-tabs button {
  border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 13px 4px 11px; font: 500 .82rem var(--sans); color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.studio-tabs button svg { width: 20px; height: 20px; }
.studio-tabs button.on { color: var(--app-ink); border-bottom-color: var(--app-ink); }
.studio-body { flex: 1; overflow-y: auto; padding: 20px 20px 28px; }
.studio-note { font-size: .82rem; color: var(--muted); margin: 0 0 16px; }
.studio-actions { flex: none; display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.studio-actions .btn { flex: 1; padding: 10px 8px; font-size: .88rem; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 7px; }
.label-row label { font-size: .85rem; font-weight: 500; color: #5b4d47; }
.label-row span { font-size: .78rem; color: var(--muted); }
.studio .body-input { min-height: 200px; font-size: 1.2rem; }
.sub-h { font: 600 .72rem var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 26px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.sub-h:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.quick .btn { background: #f5f0ea; border-color: transparent; }

/* template carousel */
.tpl-row { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 2px 10px; margin: 0 -2px; scrollbar-width: thin; }
.tpl {
  flex: 0 0 112px; scroll-snap-align: start; position: relative;
  border: 0; background: none; padding: 0; cursor: pointer; text-align: left;
  font: 500 .8rem var(--sans); color: var(--app-ink);
}
.tpl .mini-env { border-radius: 9px; outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s; }
.tpl span { display: block; margin-top: 7px; }
.tpl.on .mini-env { outline-color: var(--app-ink); }
.tpl.on::after {
  content: "✓"; position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: .7rem; color: #fff; background: rgba(20, 20, 20, .55); border: 1.5px solid #fff;
}

/* wax / seal / stamp / ink pickers */
.wax-row { display: flex; flex-wrap: wrap; gap: 10px; }
.wax-sw {
  width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, var(--h), var(--b) 55%, var(--d));
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.wax-sw.on { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--app-ink); transform: scale(1.06); }
.seal-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.seal-opt {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 14px; background: #f7f3ee; cursor: pointer; padding: 6px;
  filter: none; transition: all .15s;
}
.seal-opt .wax { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .25)); }
.seal-opt.on { border-color: var(--app-ink); background: #fff; }
.seal-custom { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.seal-custom .input { max-width: 120px; text-align: center; font-weight: 600; }
.stamp-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.ink-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ink-sw { display: inline-flex; align-items: center; gap: 6px; }
.ink-sw i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.switch { display: flex; align-items: center; gap: 10px; font-size: .9rem; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--wine); }

@media (max-width: 900px) {
  body[data-page="write"] { overflow: auto; }
  .studio { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; height: auto; }
  .studio-panel, .studio-body, .pane, .acc-b { min-width: 0; }
  .studio-stage { height: 46vh; min-height: 300px; }
  .studio-scene { bottom: 64px; padding: 12px; }
  .studio-scene .env3d { --w: min(84cqw, 125cqh, 520px); }
  .studio-panel { border-left: 0; }
  .studio-tabs { position: sticky; top: 57px; z-index: 6; background: #fff; }
  .studio-body { overflow: visible; }
  .studio-actions { position: sticky; bottom: 0; z-index: 6; }
  .seg button { padding: 7px 10px; font-size: .82rem; }
}
@media (max-width: 440px) {
  .seg button { padding: 6px 8px; font-size: .78rem; }
  .studio-bar .try { padding: 6px 10px; font-size: .78rem; }
}

/* ==========================================================
   Studio v3 — rotation, part picking, accordion controls
   ========================================================== */
.studio-scene .env3d { scale: var(--zoom, 1); transition: scale .25s ease; }
.studio-scene .env3d .env-card { will-change: transform; }
.studio-scene { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.studio-scene.is-letter { cursor: default; touch-action: pan-y; }
.studio-stage.grabbing .studio-scene { cursor: grabbing; }
.studio-scene [data-drag] { cursor: move; }
.studio-scene [data-part]:not(.env-front):not(.paper-bg):hover { filter: brightness(1.04); }
.studio-letter { scale: var(--zoom, 1); transform-origin: 50% 0; }
.part-flash { animation: partFlash .7s ease; }
@keyframes partFlash { 0% { outline: 2px solid rgba(255, 255, 255, 0); } 30% { outline: 3px solid rgba(255, 255, 255, .95); outline-offset: 3px; } 100% { outline: 2px solid rgba(255, 255, 255, 0); outline-offset: 8px; } }
.stage-help {
  position: absolute; top: 14px; left: 16px; z-index: 3; pointer-events: none;
  font-size: .78rem; color: var(--stage-ink); opacity: .65;
  background: rgba(255, 255, 255, .35); padding: 5px 10px; border-radius: 999px; backdrop-filter: blur(6px);
}
.zoom-ctl {
  position: absolute; right: 16px; bottom: 18px; z-index: 3;
  display: flex; flex-direction: column; overflow: hidden; border-radius: 12px;
  background: rgba(255, 255, 255, .88); box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .25);
}
.zoom-ctl button { width: 36px; height: 34px; border: 0; background: none; cursor: pointer; font: 500 1.05rem var(--sans); color: #4a3f3a; }
.zoom-ctl button:hover { background: rgba(0, 0, 0, .05); }

/* accordion */
.acc { border-bottom: 1px solid var(--line); }
.acc-h {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 17px 2px; border: 0; background: none; cursor: pointer; text-align: left;
  font: 600 .98rem var(--sans); color: var(--app-ink);
}
.acc-h b { font-weight: 600; flex: none; }
.acc-v { flex: 1; text-align: right; font-weight: 400; font-size: .84rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.acc-v .dot, .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); flex: none; }
.chev { width: 16px; height: 16px; flex: none; color: var(--muted); transition: transform .2s; }
.acc.open .chev { transform: rotate(180deg); }
.acc-b { display: none; padding: 0 2px 20px; }
.acc.open .acc-b { display: block; animation: accIn .25s ease; }
@keyframes accIn { from { opacity: 0; transform: translateY(-4px); } }
.lbl { font-size: .82rem; color: #6b5f59; margin: 16px 0 8px; display: flex; align-items: center; gap: 8px; }
.lbl:first-child { margin-top: 0; }
.link-btn { border: 0; background: none; color: var(--wine); font: 500 .8rem var(--sans); cursor: pointer; padding: 0; margin-left: auto; }

/* option cards & carousels */
.car-wrap { position: relative; }
.car { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 3px 3px 8px; scrollbar-width: thin; }
.car-btn {
  position: absolute; top: 34%; z-index: 2; width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
  font-size: 1.1rem; line-height: 1; cursor: pointer; color: #444;
}
.car-btn.prev { left: -8px; } .car-btn.next { right: -8px; }
.opt-row { display: flex; flex-wrap: wrap; gap: 10px; }
.opt {
  flex: 0 0 auto; width: 104px; scroll-snap-align: start; position: relative;
  border: 0; background: none; padding: 0; cursor: pointer; text-align: left; color: var(--app-ink);
}
.opt-img {
  display: grid; place-items: center; height: 70px; border-radius: 10px; overflow: hidden;
  background: #f6f1eb; outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s;
}
.opt-l { display: block; font: 500 .8rem var(--sans); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt.on .opt-img { outline-color: var(--app-ink); }
.opt.on::after {
  content: "✓"; position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: .7rem; color: #fff; background: rgba(20, 20, 20, .6); border: 1.5px solid #fff;
}
.opt-img svg { width: 80%; height: auto; }
.mat-pv, .liner-pv, .tex-pv { display: block; width: 100%; height: 100%; }
.tex-pv { background: var(--pv-paper); }
.tex-pv.tex-lined { background: repeating-linear-gradient(transparent 0 9px, rgba(0, 0, 0, .14) 9px 10px), var(--pv-paper); }
.tex-pv.tex-grid { background: linear-gradient(rgba(0, 0, 0, .1) 1px, transparent 1px) 0 0 / 10px 10px, linear-gradient(90deg, rgba(0, 0, 0, .1) 1px, transparent 1px) 0 0 / 10px 10px, var(--pv-paper); }
.tex-pv.tex-dots { background: radial-gradient(rgba(0, 0, 0, .22) 1.2px, transparent 1.6px) 0 0 / 10px 10px, var(--pv-paper); }
.sheet-pv { display: block; height: 78%; max-width: 70%; background: var(--pv-paper); box-shadow: 0 2px 6px rgba(0, 0, 0, .15); border-radius: 2px; }
.edge-pv { display: block; width: 70%; height: 66%; border-radius: 4px; background: var(--pv-env); }
.edge-pv.edge-gold { box-shadow: inset 0 0 0 3px #fff0, inset 0 0 0 5px #d8b45a; }
.edge-pv.edge-silver { box-shadow: inset 0 0 0 5px #c9d0da; }
.script-pv { color: #2a211e; white-space: nowrap; }
.pens { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.pens .opt { width: auto; }
.pens .opt-img { height: 84px; background: #f7f6f3; border: 1px solid rgba(0, 0, 0, .06); }
.pen-ico { display: grid; place-items: center; width: 100%; height: 100%; }
.pen-ico svg { width: 86%; height: auto; }
.pen-pv { display: block; height: 62px; transform: rotate(35deg); }
.pen-pv svg { height: 100%; width: auto; }

/* segmented (2-4 options) */
.seg2 { display: flex; background: #f3eee8; border-radius: 999px; padding: 4px; gap: 2px; }
.seg2 button { flex: 1; border: 0; background: none; cursor: pointer; padding: 8px 10px; border-radius: 999px; font: 500 .86rem var(--sans); color: #776963; white-space: nowrap; }
.seg2 button.on { background: #fff; color: var(--app-ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.seg2.wide { margin-bottom: 8px; }
.range-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.range-row input { flex: 1; accent-color: var(--app-ink); }
.range-row span { font-size: .82rem; color: var(--muted); width: 42px; text-align: right; }

/* swatches */
.sw-row { display: flex; flex-wrap: wrap; gap: 9px; }
.sw {
  position: relative; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 0; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14);
  transition: transform .12s; font: 600 .9rem var(--sans); color: #6b5f59;
}
.sw.wax-sw { background: radial-gradient(circle at 35% 30%, var(--h), var(--c) 55%, var(--d)); box-shadow: inset 0 -2px 4px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .25); }
.sw.sw-default { background: #fff; border: 1px dashed #c9bcb0; }
.sw.rainbow { background: conic-gradient(red, #ff0, lime, cyan, blue, #f0f, red); overflow: hidden; display: inline-block; }
.sw.rainbow input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.sw.on { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--app-ink); transform: scale(1.05); }

/* stickers placed */
.sticker-pick.lib:empty { display: none; }
.sticker-pick.lib { margin-top: 8px; }
.st.img { padding: 4px; }
.st.img img { width: 100%; height: 100%; object-fit: contain; }
.placed { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.placed .lbl { width: 100%; margin: 4px 0 2px; }
.placed-chip { display: inline-flex; align-items: center; gap: 4px; background: #f5f0ea; border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 1.1rem; }
.placed-chip img { width: 22px; height: 22px; object-fit: contain; }
.placed-chip button { border: 0; background: #fff; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-size: .7rem; color: #776963; }

/* library */
.lib-lbl { margin-top: 18px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.lib-item { aspect-ratio: 1; border: 0; padding: 0; border-radius: 10px; overflow: hidden; cursor: pointer; background: #eee; }
.lib-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.lib-item:hover img { transform: scale(1.06); }
.lib-empty { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); background: #f8f4ef; border-radius: 10px; padding: 10px 12px; margin: 0; }
.lib-empty code, .note code { font-size: .78rem; background: #efe7de; padding: 1px 5px; border-radius: 4px; }

/* music tracks */
.tracks { display: flex; flex-direction: column; gap: 8px; }
.track { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px 8px 8px; background: #fff; transition: border-color .15s; }
.track.on { border-color: var(--app-ink); box-shadow: inset 0 0 0 1px var(--app-ink); }
.track .play { width: 34px; height: 34px; border-radius: 50%; border: 0; background: #f3eee8; cursor: pointer; font-size: .8rem; flex: none; color: var(--app-ink); }
.track-main { flex: 1; min-width: 0; border: 0; background: none; text-align: left; cursor: pointer; padding: 0; color: var(--app-ink); }
.track-main b { display: block; font: 600 .9rem var(--sans); }
.track-main small { display: block; font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .tag { font-size: .7rem; background: #f3eee8; color: #6b5f59; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.upload { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1.5px dashed #d8ccbf; border-radius: 14px; cursor: pointer; background: #fbf8f4; }
.upload b { display: block; font-size: .9rem; }
.upload small { display: block; font-size: .76rem; color: var(--muted); }
.up-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); font-size: 1.2rem; flex: none; }
.switch { margin-top: 14px; }

@media (max-width: 900px) {
  .stage-help { display: none; }
  .zoom-ctl { bottom: 70px; right: 10px; }
  .pen.rest { display: none; }
}

/* ==========================================================
   Reader v4 — hold to open, drag to rotate, tap the letter
   ========================================================== */
.orbit { position: relative; animation: arrive .9s cubic-bezier(.2, .7, .2, 1) both; }
.orbit .env3d { animation: none; }
.stage .scene { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage.reading .scene { cursor: default; touch-action: auto; user-select: text; -webkit-user-select: text; }
.stage-pill {
  position: fixed; top: 18px; left: 50%; translate: -50% 0; z-index: 6;
  display: flex; align-items: center; gap: 8px; overflow: hidden;
  padding: 7px 14px; border-radius: 999px; font: 500 .85rem var(--sans);
  background: rgba(255, 255, 255, .78); color: #3b302b; backdrop-filter: blur(8px); box-shadow: 0 6px 20px -10px rgba(0, 0, 0, .3);
}
.stage-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #d23b3b; animation: breathe 1.6s infinite; }
.stage-pill .hold-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--wine); }
.stage.holding .stage-pill .hold-bar { width: 100%; transition: width .75s linear; }
.stage.holding .orbit { scale: .98; transition: scale .75s ease; }
.sound-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer; font-size: 1rem;
  background: rgba(255, 255, 255, .82); box-shadow: 0 4px 14px rgba(0, 0, 0, .15); backdrop-filter: blur(6px);
}
.countdown-box { margin-top: 30px; text-align: center; color: var(--stage-ink); }
.countdown-box p { margin: 0; opacity: .85; }
.paper-wrap { position: relative; }
.paper-wrap > .paper { z-index: 1; }
.paper-wrap.has-tuck { margin-bottom: 120px; }
.env-tuck {
  position: absolute; left: 50%; top: calc(100% - 190px); z-index: 0; translate: -50% 0; rotate: -3deg;
  perspective: 1400px; pointer-events: none; animation: tuckIn 1.1s cubic-bezier(.2, .7, .2, 1) both;
}
.env-tuck .env3d { --w: min(80vw, 430px); }
@keyframes tuckIn { from { translate: -50% -30%; } }
.reader .polaroids { position: relative; z-index: 1; }
/* studio v4 controls */
.stamp-pv {
  display: block; position: relative; width: 52px; height: 62px; padding: 5px; background: #fffaf0;
  --r: 2.4px;
  -webkit-mask: linear-gradient(#000 0 0) content-box, radial-gradient(circle, #0000 calc(var(--r) - .5px), #000 var(--r)) calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3);
  mask: linear-gradient(#000 0 0) content-box, radial-gradient(circle, #0000 calc(var(--r) - .5px), #000 var(--r)) calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .2));
}
.stamp-pv svg, .stamp-pv img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pm-pv { width: 92%; height: auto; color: #6b5a48; }
.seal-pv { display: block; width: 62px; height: 62px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3)); }
.seal-pv svg { width: 100%; height: 100%; }
#seal-pick .opt-img { background: color-mix(in srgb, var(--pv-env) 85%, #fff); }
details.adv { margin-top: 14px; }
details.adv summary { cursor: pointer; font-size: .84rem; color: #6b5f59; list-style: none; display: inline-flex; align-items: center; gap: 4px; }
details.adv summary::after { content: "⌄"; font-size: .9rem; transition: transform .2s; }
details.adv[open] summary::after { transform: rotate(180deg); }
details.adv summary::-webkit-details-marker { display: none; }
.range-row.labeled { flex-wrap: wrap; gap: 4px 12px; }
.range-row.labeled .rl { width: 100%; font-size: .82rem; color: #6b5f59; }
.lib-grid.mini { grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); margin-top: 10px; }
.lib-grid.mini:empty { display: none; }

/* ==========================================================
   v5 — realistic envelope, stickers, pens, editors
   ========================================================== */
/* paper thickness: the card is a thin box (front, back and four edges) */
.env3d { --thick: 3.2px; --half-t: 1.6px; }
.env-edge { position: absolute; display: block; background: linear-gradient(var(--env-3), var(--env-2)); }
.env-edge.et { left: 0; top: 0; width: 100%; height: var(--thick); transform-origin: 50% 0; transform: translateZ(var(--half-t)) rotateX(-90deg); }
.env-edge.eb { left: 0; bottom: 0; width: 100%; height: var(--thick); transform-origin: 50% 100%; transform: translateZ(var(--half-t)) rotateX(90deg); filter: brightness(.82); }
.env-edge.el { left: 0; top: 0; width: var(--thick); height: 100%; transform-origin: 0 50%; transform: translateZ(var(--half-t)) rotateY(90deg); filter: brightness(.9); }
.env-edge.er { right: 0; top: 0; width: var(--thick); height: 100%; transform-origin: 100% 50%; transform: translateZ(var(--half-t)) rotateY(-90deg); filter: brightness(.9); }
/* light that slides across the paper as you rotate */
.env-face::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 7;
  background:
    linear-gradient(112deg, transparent 30%, rgba(255, 255, 255, .22) 46%, rgba(255, 255, 255, .05) 54%, transparent 66%) var(--sheen, 50%) 0 / 260% 100% no-repeat,
    linear-gradient(rgba(0, 0, 0, var(--shade, .06)), rgba(0, 0, 0, var(--shade, .06)));
  mix-blend-mode: soft-light;
}
.env-back::before { transform: translateZ(2.4px); mix-blend-mode: normal; background: linear-gradient(112deg, transparent 30%, rgba(255, 255, 255, .1) 46%, transparent 66%) var(--sheen, 50%) 0 / 260% 100% no-repeat; }
/* the folds on the back press faintly through the front */
.env-ghost { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.env-ghost path { fill: none; stroke: rgba(0, 0, 0, .07); stroke-width: 1px; vector-effect: non-scaling-stroke; filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .12)); }
/* soft contact shadow on the ground */
.env3d::before {
  content: ""; position: absolute; left: 10%; right: 10%; bottom: -9%; height: 14%; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .28), transparent 70%); filter: blur(8px);
}
.env-tuck .env3d::before, .studio-scene.is-inside .env3d::before { display: none; }

/* own-image postmark: the picture is used as an ink mask */
.env-postmark.pm-image { aspect-ratio: 172 / 100; background: currentColor; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: center; mask-position: center; }

/* stickers: die-cut vinyl / round badge / stamp / plain */
.stk { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .22)); }
.stk-in { display: block; line-height: 1; }
.stk.st-diecut .stk-in { filter: url(#sealed-diecut); padding: 4px; }
.stk.st-round .stk-in {
  display: grid; place-items: center; width: 1.75em; height: 1.75em; border-radius: 50%; overflow: hidden;
  background: #fffdf8; box-shadow: 0 0 0 3px #fff, inset 0 0 0 1px rgba(0, 0, 0, .08); font-size: .85em;
}
.stk.st-round .stk-in img { width: 100%; height: 100%; object-fit: cover; }
.stk.st-square .stk-in {
  --r: 2.4px; display: grid; place-items: center; width: 1.6em; height: 1.85em; padding: .16em; background: #fffaf0; font-size: .85em;
  -webkit-mask: linear-gradient(#000 0 0) content-box, radial-gradient(circle, #0000 calc(var(--r) - .5px), #000 var(--r)) calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3);
  mask: linear-gradient(#000 0 0) content-box, radial-gradient(circle, #0000 calc(var(--r) - .5px), #000 var(--r)) calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3);
}
.stk.st-square .stk-in img { width: 100%; height: 100%; object-fit: cover; }

/* pens: a real-size pen held like a right hand writes — nib on the word, barrel to the right,
   lying almost flat with its shadow falling down-left; it rests beside the letter when done */
.pen {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none;
  --pl: clamp(150px, 64cqi, 460px);
  width: calc(var(--pl) * .18); height: var(--pl); margin: calc(var(--pl) * -1) 0 0 calc(var(--pl) * -.09);
}
.pen-body {
  position: absolute; inset: 0; transform-origin: 50% 100%;
  transform: translate(calc(var(--lift, 0px) * .4), calc(var(--lift, 0px) * -1)) rotate(var(--tz, 100deg));
  transition: transform .12s linear;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .18));
}
.pen-body svg, .pen-body img { display: block; width: 100%; height: 100%; object-fit: contain; }
.pen-shadow {
  position: absolute; left: 50%; bottom: 0; width: 46%; height: 96%; margin-left: -23%; transform-origin: 50% 100%;
  transform: translate(calc(var(--lift, 0px) * -.6), calc(var(--lift, 0px) * 1.3)) rotate(calc(var(--tz, 100deg) + 9deg));
  background: linear-gradient(to top, rgba(25, 18, 10, .34), rgba(25, 18, 10, .16) 55%, rgba(25, 18, 10, 0));
  border-radius: 45%; filter: blur(5px);
  transition: transform .12s linear;
}
.pen.rest {
  position: absolute; left: calc(100% + 3cqi); top: 4%; margin: 0; z-index: 3;
  --pl: clamp(140px, 72cqi, 440px); --tz: -9deg; --lift: 5px;
  pointer-events: auto; cursor: pointer;
}
.pen.rest .pen-shadow { transform: translate(-10px, 12px) rotate(-6deg); }
.pen.settle { animation: penSettle .9s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes penSettle { from { opacity: 0; translate: -40px -30px; rotate: 25deg; } }
.pen.away { opacity: 0; transition: opacity .5s; }
/* image editor */
.modal.modal-wide { width: min(100%, 760px); }
.ie { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.ie-stage {
  position: relative; flex: none; max-width: 100%; border-radius: 10px; overflow: hidden; cursor: grab; touch-action: none;
  background: repeating-conic-gradient(#e9e4dc 0 25%, #fbf8f3 0 50%) 0 0 / 18px 18px;
  box-shadow: 0 0 0 1px var(--line);
}
.ie-stage canvas { width: 100%; height: 100%; display: block; }
.ie-stage.shape-circle { border-radius: 50%; }
.ie-stage.shape-stamp { outline: 6px dotted #fffaf0; outline-offset: -3px; }
.ie-ctl { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 10px; }
.ie-sl { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: #6b5f59; flex: 1; }
.ie-sl input { accent-color: var(--wine); }
.ie-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

/* audio trim */
.at { display: flex; flex-direction: column; gap: 12px; }
.at-wave { position: relative; height: 120px; border-radius: 12px; background: #f6f1eb; overflow: hidden; touch-action: none; cursor: pointer; }
.at-wave canvas { width: 100%; height: 100%; display: block; }
.at-sel { position: absolute; top: 0; bottom: 0; background: rgba(142, 47, 69, .1); border-left: 2px solid var(--wine); border-right: 2px solid var(--wine); cursor: grab; }
.at-h { position: absolute; top: 50%; width: 14px; height: 34px; margin-top: -17px; border-radius: 7px; background: var(--wine); cursor: ew-resize; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.at-h.l { left: -8px; } .at-h.r { right: -8px; }
.at-head { position: absolute; top: 0; bottom: 0; width: 2px; background: #2a211e; opacity: 0; pointer-events: none; }
.at-times { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* custom option cards */
.opt-edit { position: absolute; top: 5px; left: 5px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .92); box-shadow: 0 1px 4px rgba(0, 0, 0, .2); font-size: .72rem; cursor: pointer; z-index: 2; }
.opt-add .opt-img { border: 1.5px dashed #cdbfb1; background: #fbf8f4; font-size: 1.4rem; color: #8a7b72; }
.custom-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.custom-row .thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; box-shadow: 0 0 0 1px var(--line); background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
.pm-colors { margin-top: 10px; }.font-sample { font-size: 1.6rem; line-height: 1.2; color: #2b1d14; }
.trim-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font: 500 .76rem var(--sans); cursor: pointer; color: var(--app-ink); white-space: nowrap; }
.trim-btn:hover { border-color: var(--wine); color: var(--wine); }
.my-stk { position: relative; display: inline-block; }
.my-stk .opt-edit { top: -6px; left: -6px; width: 20px; height: 20px; font-size: .6rem; position: absolute; }
.opt-del { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); font-size: .6rem; cursor: pointer; color: #b3261e; }
.sticker-pick.lib .lbl { margin: 6px 0 2px; }
.photo-row .btn-ghost { padding: 6px 9px; }
/* ==========================================================
   v6 — real letter inside, 3D letter, fit-to-page
   ========================================================== */
.env-paper { padding: 0; overflow: hidden; }
.mini-paper {
  position: absolute; inset: 0; color: var(--ink);
  font-family: var(--hand, 'Charm', cursive); font-style: var(--hand-style, normal);
  font-size: calc(var(--w, 400px) * .026 * var(--hand-scale, 1)); line-height: var(--lh, 1.7);
  padding: 7% 8%; overflow: hidden;
}
.mp-bg { position: absolute; inset: 0; background: var(--paper); }
.mp-bg::before { content: ""; position: absolute; inset: 0; background: var(--paper-tex, none); opacity: var(--grain, .6); }
.mini-paper.deckled .mp-bg { -webkit-mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; }
.mini-paper:not([style]) { background: var(--paper); }
.mp-txt { position: relative; }
.mp-date { display: block; text-align: right; font-size: .78em; opacity: .7; }
.mini-paper:not([style]) .mp-txt { height: 100%; background: repeating-linear-gradient(transparent 0 18%, color-mix(in srgb, var(--ink) 14%, transparent) 18% 19.5%); }

/* the letter is a thin 3D sheet with a back side */
.letter3d {
  position: relative; transform-style: preserve-3d;
  transform: rotateX(var(--lrx, 4deg)) rotateY(var(--lry, -3deg));
  transition: transform .5s cubic-bezier(.2, .7, .3, 1);
}
.letter3d > .paper { backface-visibility: hidden; -webkit-backface-visibility: hidden; transform: translateZ(1px); }
.paper-back {
  position: absolute; inset: 0; border-radius: 3px; background: var(--paper);
  transform: rotateY(180deg) translateZ(1px); backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 30px 60px -24px rgba(0, 0, 0, .4);
}
.paper-back::before { content: ""; position: absolute; inset: 0; background: var(--pbr-img, none) 0 0 / var(--pbr-size, 512px 512px), var(--paper-tex, none); opacity: calc(.35 + var(--grain, .6) * .65); mix-blend-mode: var(--paper-blend, normal); }
.paper-wrap { perspective: 1800px; container-type: inline-size; }
/* at rest the sheet is flat and not a 3D layer: no resampling, so text and paper stay pin-sharp.
   3D (tilt / turning it over) only while you move it */
.letter3d:not(.tilt) { transform: none; transform-style: flat; }
.letter3d:not(.tilt) > .paper { transform: none; }
.letter3d:not(.tilt) > .paper-back { visibility: hidden; }
.paper { font-size: calc(clamp(.85rem, 2.75cqi, 1.36rem) * var(--hand-scale, 1)); padding: 8cqi 9cqi; }
/* reading: the whole sheet fits the screen */
.reader .paper-wrap { width: min(100%, calc((100vh - 130px) / var(--ratio, 1.35))); margin: 0 auto; }
.env-tuck { left: 64%; top: calc(100% - 200px); rotate: 7deg; }
.reader .paper-wrap.has-tuck { margin-bottom: 130px; }

/* studio: letter fits the stage, rotates like the envelope */
.studio-scene { container-type: size; }
.studio-scene.is-letter { container-type: size; overflow-y: auto; align-items: center; }
.studio-letter { width: min(92cqw, calc((100cqh - 56px) / var(--ratio, 1.35)), 680px); margin: auto; scale: var(--zoom, 1); }
.studio-letter .paper-wrap { width: 100%; }
.studio-letter .pen.rest { left: calc(100% + 24px); }.studio-scene.is-letter { cursor: grab; touch-action: none; }
.studio-scene.is-letter .studio-letter { padding: 18px 0; }
.studio-polaroids { display: none; }

/* WebGL envelope */
.gl-host { position: absolute; inset: 0; }
.gl-host .gl-canvas { display: block; width: 100%; height: 100%; }
.orbit.gl { position: relative; width: min(100%, 980px); height: min(72vh, 680px); }
.stage .orbit.gl { width: min(96vw, 980px); height: min(78vh, 720px); }
/* the opened envelope lies behind the letter, lower right, like on a desk */
.env-tuck.gl { width: 104%; aspect-ratio: 1.12; left: 74%; top: 46%; rotate: 8deg; }

/* your own fonts */
.font-ctl { flex-direction: column; align-items: stretch; }
.font-cur, .font-act { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.font-list { display: flex; flex-wrap: wrap; gap: 6px; }
.font-list .chip { font-size: .82rem; padding: 5px 10px; }
.font-act code { font-size: .78em; }
.own-font-opt[hidden] { display: none; }
.tex-pv.tex-ruled { background: linear-gradient(90deg, transparent 9px, rgba(214, 72, 72, .6) 9px 10px, transparent 0), repeating-linear-gradient(transparent 0 9px, rgba(70, 120, 190, .4) 9px 10px), #fdfdfb; }
.tex-pv.tex-squared { background-color: #fcfdfd; background-size: 25px 25px, 25px 25px, 5px 5px, 5px 5px; }
.tex-pv.tex-dotgrid { background: radial-gradient(rgba(60, 60, 70, .4) 1px, transparent 1.4px) 4px 4px / 8px 8px, #fbfbf8; }
.tex-pv.tex-cotton { background-color: #fbfaf6; }
.tex-pv.tex-watercolor { background-color: #fbf8f1; }
.tex-pv.tex-parchment { background-color: #efe1c3; }
.tex-pv.tex-kraftpaper { background-color: #d9be93; }
/* ruled papers: the rules run down the whole sheet, the signature sits at the bottom */
.paper[data-ruling="ruled"], .paper[data-ruling="lined"] { display: flex; flex-direction: column; }
.paper[data-ruling="ruled"] .paper-text, .paper[data-ruling="lined"] .paper-text { flex: 1 0 auto; }
/* your name stamp (mộc) */
.moc-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(0, 0, 0, .07); }
.moc-add { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.moc-list { display: grid; gap: 6px; margin-top: 10px; }
.moc-row { display: flex; align-items: center; gap: 4px; font-size: .85rem; }
.moc-row span { flex: 1; }
/* reading: a flat, sharp sheet (no lingering scale/3D rasterisation) */
.reader .letter3d { --lrx: 0deg; --lry: 0deg; }
.reader .paper.settled { animation: none; }
.reader .paper { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
/* ruled sheets keep every line on the printed rules */
.paper[data-ruling="lined"] .paper-body p + p, .paper[data-ruling="ruled"] .paper-body p + p { margin-top: 0; }
/* "Gửi …," sits on the first rule, the body carries on from the next one (no half-line gap between them) */
.paper[data-ruling="lined"] .paper-to, .paper[data-ruling="ruled"] .paper-to { margin-bottom: 0; }

/* ===== stages for the template library ===== */
[data-theme="balloonparty"] {
  --bg1: #f2f7fb; --bg2: #cfdcea;
  --env: #cfe3f3; --env-2: #b9d2e8; --env-3: #dcebf7; --env-in: #e2567a; --env-ink: #2a4f8f;
  --paper: #fdfbf6; --ink: #2a4f8f; --accent: #e2567a;
  --seal: #cf6a83; --seal-hi: #f6b3c3; --seal-lo: #86304a; --stage-ink: #23345a;
}
[data-theme="giftbox"] {
  --bg1: #fbf1ea; --bg2: #ecd2c2;
  --env: #f3d6c6; --env-2: #e6c2ae; --env-3: #f8e2d4; --env-in: #c8362b; --env-ink: #8e2f45;
  --paper: #fbf6ee; --ink: #8e2f45; --accent: #c8362b;
  --seal: #b8172f; --seal-hi: #ee6378; --seal-lo: #5e0817; --stage-ink: #4a2a2a;
}
[data-theme="firstnote"] {
  --bg1: #fcf1f2; --bg2: #efd2d6;
  --env: #f6d6da; --env-2: #ecc1c7; --env-3: #fae3e6; --env-in: #c0466a; --env-ink: #8e1f3a;
  --paper: #fdf9f6; --ink: #8e1f3a; --accent: #c0466a;
  --seal: #b8172f; --seal-hi: #ee6378; --seal-lo: #5e0817; --stage-ink: #5a2333;
}
[data-theme="redrose"] {
  --bg1: #f7f1e8; --bg2: #e3d3c2;
  --env: #f4ece0; --env-2: #e5d9c7; --env-3: #f8f2e8; --env-in: #7c1528; --env-ink: #5e0f1f;
  --paper: #fbf6ec; --ink: #5e0f1f; --accent: #7c1528;
  --seal: #7c1528; --seal-hi: #b9465a; --seal-lo: #3a0510; --stage-ink: #3a1a1a;
}
[data-theme="secretnote"] {
  --bg1: #f2eef8; --bg2: #d6cce6;
  --env: #d9cfe9; --env-2: #c6b9dd; --env-3: #e5ddf1; --env-in: #8a72b8; --env-ink: #4a3775;
  --paper: #fbf9fd; --ink: #4a3775; --accent: #8a72b8;
  --seal: #8a72b8; --seal-hi: #c7b6e6; --seal-lo: #4a3775; --stage-ink: #2e2445;
}
[data-theme="teatime"] {
  --bg1: #f0f3ea; --bg2: #c9d4bd;
  --env: #b9c9ad; --env-2: #a6b899; --env-3: #c8d5bd; --env-in: #5f7d4f; --env-ink: #2f3f24;
  --paper: #f4f0e4; --ink: #3b4a2e; --accent: #5f7d4f;
  --seal: #2f6040; --seal-hi: #69a67a; --seal-lo: #13301f; --stage-ink: #2a3622;
}
[data-theme="rainyday"] {
  --bg1: #eef2f6; --bg2: #c3cfdb;
  --env: #aebfcf; --env-2: #9aaec1; --env-3: #bfcddb; --env-in: #3a5a7a; --env-ink: #1f3550;
  --paper: #f6f4ee; --ink: #26405f; --accent: #3a5a7a;
  --seal: #28407a; --seal-hi: #6582c4; --seal-lo: #0f1c40; --stage-ink: #1f2d3d;
}
[data-theme="oldfriend"] {
  --bg1: #f3ece2; --bg2: #d9c6ab;
  --env: #c49a6c; --env-2: #ad8457; --env-3: #d3ad83; --env-in: #8a5a2b; --env-ink: #3b2414;
  --paper: #efe2c8; --ink: #3b2a1f; --accent: #8a5a2b;
  --seal: #c0682b; --seal-hi: #f2ab6c; --seal-lo: #6a330c; --stage-ink: #3b2a1f;
}
[data-theme="northpole"] {
  --bg1: #f3efe6; --bg2: #dcd3c2;
  --env: #f3ece0; --env-2: #e2d8c6; --env-3: #f8f2e8; --env-in: #c8362b; --env-ink: #26458f;
  --paper: #fbf8f2; --ink: #26458f; --accent: #c8362b;
  --seal: #b8172f; --seal-hi: #ee6378; --seal-lo: #5e0817; --stage-ink: #26304a;
}
[data-theme="reindeer"] {
  --bg1: #f2ebe0; --bg2: #d6c4a8;
  --env: #c49a6c; --env-2: #ad8457; --env-3: #d3ad83; --env-in: #8a5a2b; --env-ink: #3b2414;
  --paper: #f4ecdd; --ink: #5a2a1c; --accent: #c8362b;
  --seal: #b8172f; --seal-hi: #ee6378; --seal-lo: #5e0817; --stage-ink: #3b2a1f;
}
[data-theme="holynight"] {
  --bg1: #f6ece6; --bg2: #e2c8c0;
  --env: #a51f24; --env-2: #8c181d; --env-3: #b8332f; --env-in: #6a0f12; --env-ink: #f4dc9a;
  --paper: #fcf8ef; --ink: #7a1420; --accent: #2f6040;
  --seal: #2f6040; --seal-hi: #69a67a; --seal-lo: #13301f; --stage-ink: #3a1a1a;
}
[data-theme="pinegold"] {
  --bg1: #eef0e8; --bg2: #c7cfbf;
  --env: #1f4d36; --env-2: #183f2c; --env-3: #285d42; --env-in: #11301f; --env-ink: #e2c071;
  --paper: #fbf8ef; --ink: #1f4a32; --accent: #b8913a;
  --seal: #c4952f; --seal-hi: #f8dc86; --seal-lo: #735112; --stage-ink: #1f2d22;
}
[data-theme="classic"] {
  --bg1: #f4efe4; --bg2: #d9cdb4;
  --env: #efe3cc; --env-2: #dccaa9; --env-3: #f6ecd9; --env-in: #b9a27c; --env-ink: #1f3a68;
  --paper: #f7f3ea; --ink: #1f3f8f; --accent: #1f3a68;
  --seal: #8e1f2a; --seal-hi: #c2485a; --seal-lo: #4d0b14; --stage-ink: #1f2d4a;
}
[data-theme="botanical"] {
  --bg1: #eef1e6; --bg2: #b9c7a5;
  --env: #9fb08f; --env-2: #8a9c79; --env-3: #b2c1a3; --env-in: #6b7d5c; --env-ink: #22381f;
  --paper: #ebe5d8; --ink: #2d5a3d; --accent: #3f6b48;
  --seal: #2f6040; --seal-hi: #69a67a; --seal-lo: #13301f; --stage-ink: #22381f;
}
[data-theme="japanese"] {
  --bg1: #f6f1e7; --bg2: #e2d6c3;
  --env: #ece6da; --env-2: #d9d0bf; --env-3: #f4efe5; --env-in: #b8ab93; --env-ink: #1a1a1a;
  --paper: #fbf8ef; --ink: #1a1a1a; --accent: #b3261e;
  --seal: #b3261e; --seal-hi: #e0594f; --seal-lo: #6a0f0a; --stage-ink: #2a2522;
}
[data-theme="postcard"] {
  --bg1: #eef4f8; --bg2: #bcd3e3;
  --env: #f4f1ea; --env-2: #e2ddd2; --env-3: #faf8f3; --env-in: #c1b8a6; --env-ink: #1f4f9a;
  --paper: #fbf8f1; --ink: #1f4f9a; --accent: #c0392b;
  --seal: #28407a; --seal-hi: #6582c4; --seal-lo: #0f1c40; --stage-ink: #1d3557;
}
[data-theme="luxury"] {
  --bg1: #2b2a2e; --bg2: #121214;
  --env: #1d1d22; --env-2: #141418; --env-3: #26262c; --env-in: #0c0c0f; --env-ink: #e5c77c;
  --paper: #fbf8ef; --ink: #1a1a2e; --accent: #b8913a;
  --seal: #c4952f; --seal-hi: #f8dc86; --seal-lo: #735112; --stage-ink: #efe2bd;
}
[data-theme="handmade"] {
  --bg1: #f5ede0; --bg2: #d9c4a4;
  --env: #c9a679; --env-2: #b8915e; --env-3: #d6b88e; --env-in: #9c7445; --env-ink: #3b2a1f;
  --paper: #f6f3ee; --ink: #3b2a1f; --accent: #8a5a2b;
  --seal: #c0682b; --seal-hi: #f2ab6c; --seal-lo: #6a330c; --stage-ink: #3b2a1f;
}
[data-theme="modern"] {
  --bg1: #eef1f4; --bg2: #c4ced6;
  --env: #5b7a8c; --env-2: #4c697a; --env-3: #6c8b9c; --env-in: #3a5363; --env-ink: #f4f1ea;
  --paper: #fbfaf6; --ink: #2a3f9a; --accent: #3f5d7d;
  --seal: #28407a; --seal-hi: #6582c4; --seal-lo: #0f1c40; --stage-ink: #1f2d3a;
}
[data-theme="luxury"] .paper > .paper-bg { box-shadow: 0 34px 70px -20px rgba(0, 0, 0, .7); }

/* ===== editor v7: seven tabs, template gallery, pen designer ===== */
.studio-tabs { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.studio-tabs button { font-size: .72rem; padding-inline: 2px; }
.studio-tabs button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tpl-cat { margin-bottom: 14px; }
.tpl-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tpl-card { display: flex; flex-direction: column; gap: 3px; min-width: 0; text-align: left; padding: 7px 7px 9px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; font: inherit; color: inherit; transition: border-color .15s, box-shadow .15s; }
.tpl-card:hover { border-color: color-mix(in srgb, var(--app-ink, #2b1d14) 25%, var(--line)); }
.tpl-card .env-thumb { border-radius: 8px; background: var(--well, #f6f5f1); padding: 6px 4px; margin-bottom: 4px; }
.tpl-card .mini-env { width: 100%; height: auto; aspect-ratio: 1.55; margin: 0; }
.tpl-card b { font-size: .8rem; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-card small { font-size: .68rem; color: var(--muted, #8a7f78); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tpl-card.on { border-color: var(--app-ink, #2b1d14); box-shadow: 0 0 0 2px rgba(0, 0, 0, .06); }
.font-cats { margin-bottom: 10px; }
.font-cats .chip { font-size: .78rem; padding: 4px 10px; }
.pen-suggest { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 12px; border-radius: 14px; background: rgba(0, 0, 0, .03); }
.pen-suggest .ps-pen { width: 18px; height: 96px; flex: none; transform: rotate(18deg); }
.pen-suggest .ps-pen svg { width: 100%; height: 100%; }
.pen-suggest .ps-txt { flex: 1; display: grid; gap: 2px; font-size: .86rem; }
.pen-suggest .ps-txt small { color: var(--muted, #8a7f78); font-size: .74rem; }
.pen-suggest .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; }
.tex-pv.rule-none { background: #fdfbf6; }
.tex-pv.rule-lined { background: repeating-linear-gradient(transparent 0 9px, rgba(0, 0, 0, .16) 9px 10px), #fdfbf6; }
.tex-pv.rule-ruled { background: linear-gradient(90deg, transparent 9px, rgba(214, 72, 72, .6) 9px 10px, transparent 0), repeating-linear-gradient(transparent 0 9px, rgba(70, 120, 190, .4) 9px 10px), #fdfdfb; }
.tex-pv.rule-squared { background: linear-gradient(rgba(70, 120, 190, .3) 1px, transparent 1px) 0 0 / 8px 8px, linear-gradient(90deg, rgba(70, 120, 190, .3) 1px, transparent 1px) 0 0 / 8px 8px, #fcfdfd; }
.tex-pv.rule-grid { background: linear-gradient(rgba(0, 0, 0, .12) 1px, transparent 1px) 0 0 / 10px 10px, linear-gradient(90deg, rgba(0, 0, 0, .12) 1px, transparent 1px) 0 0 / 10px 10px, #fdfbf6; }
.tex-pv.rule-dotgrid { background: radial-gradient(rgba(60, 60, 70, .4) 1px, transparent 1.4px) 4px 4px / 8px 8px, #fbfbf8; }
.tex-pv.rule-dots { background: radial-gradient(rgba(194, 64, 90, .35) 1.3px, transparent 1.8px) 0 0 / 10px 10px, #fdfbf6; }
/* nib contact shadow: the pen touches the paper */
.pen.writing::after { content: ""; position: absolute; left: 50%; bottom: -2px; width: 12px; height: 5px; margin-left: -6px; border-radius: 50%; background: radial-gradient(rgba(0, 0, 0, .38), transparent 70%); }
@media (max-width: 860px) { .studio-tabs { overflow-x: auto; grid-template-columns: repeat(7, minmax(64px, 1fr)); } }

/* ===== continuous 3D ⇄ letter hand-over ===== */
.gl-layer { position: fixed; inset: 0; z-index: 0; pointer-events: none; transition: scale .75s ease; }
.stage > .scene { position: relative; z-index: 1; }
.stage.holding .gl-layer { scale: .985; }
.stage .orbit.gl { pointer-events: none; }
.paper-wrap.flying { transition: transform 1.15s cubic-bezier(.25, .75, .2, 1); }
/* the folding rig and the sheet swap in one frame (no cross-fade: a half-faded sheet under the rig shows as a ghost) */
.paper-wrap .letter3d { transition: transform .5s cubic-bezier(.2, .7, .3, 1); }
.paper-wrap.rigged .letter3d { opacity: 0; }
.paper.waiting .pen { display: none; }
.paper.animate.no-pull { animation: none; }
.reader .polaroids, .reader .reader-actions { transition: opacity .5s ease .2s; }
.reader.handoff .polaroids, .reader.handoff .reader-actions { opacity: 0; pointer-events: none; }
.fold-rig { position: absolute; inset: 0; z-index: 3; pointer-events: none; filter: drop-shadow(0 18px 22px rgba(0, 0, 0, .22)); }
/* one full-size sheet, revealed down to one panel when folded and to the whole page when open */
.fold-sheet { position: absolute; inset: 0; border-radius: 2px; clip-path: inset(0 0 calc(100% - 100% / var(--n, 2)) 0);
  transition: clip-path .95s cubic-bezier(.3, .7, .2, 1) .1s; }
.fold-rig.open .fold-sheet { clip-path: inset(0 0 0 0); }
.fold-full { position: absolute; inset: 0; border-radius: inherit; background: var(--paper-light, linear-gradient(transparent, transparent)), var(--paper); }
.fold-full::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--pbr-img, none) 0 0 / var(--pbr-size, 512px 512px), var(--paper-tex, none); opacity: calc(.35 + var(--grain, .6) * .65); mix-blend-mode: var(--paper-blend, normal); }
.fold-crease { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, .05); box-shadow: 0 1px 0 rgba(255, 255, 255, .5); opacity: 0; transition: opacity .4s ease .7s; }
.fold-rig.open .fold-crease { opacity: 1; }

/* template cards: the real 3D envelope picture replaces the drawn preview when it is ready */
.env-thumb { position: relative; }
.env-thumb .env-shot { position: absolute; left: -7%; top: -10%; width: 114%; height: 120%; object-fit: contain; opacity: 0; transition: opacity .5s ease; pointer-events: none; }
.env-thumb.has-shot .env-shot { opacity: 1; }
.env-thumb.has-shot .mini-env { opacity: 0; transition: opacity .4s ease; }

/* ==========================================================
   v8 — calm product UI: neutral wall, compact type, floating cards
   ========================================================== */
body { font-size: 14px; line-height: 1.5; }
::selection { background: rgba(210, 58, 44, .18); }
:focus-visible { outline: 2px solid var(--ink-ui); outline-offset: 2px; }

/* buttons */
.btn { font-size: 14px; font-weight: 500; padding: 9px 16px; border-color: var(--rule); box-shadow: 0 1px 1px rgba(20, 20, 25, .03); transition: background .15s, border-color .15s, box-shadow .15s, transform .1s; }
.btn:hover { border-color: #cfccc4; box-shadow: 0 1px 2px rgba(20, 20, 25, .06); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--ink-ui); border-color: var(--ink-ui); color: #fff; }
.btn-primary:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-quiet { background: var(--well); border-color: transparent; box-shadow: none; }
.btn-quiet:hover { background: #ecebe6; border-color: transparent; }
.link { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.input { font-size: 14px; padding: 10px 12px; border-radius: 10px; background: #fff; border-color: var(--rule); }
.input:focus { border-color: var(--ink-ui); box-shadow: 0 0 0 3px rgba(22, 22, 26, .08); }
.input::placeholder { color: #a3a19a; }
.chip { font-size: 13px; padding: 6px 12px; border-color: var(--rule); }
.chip:hover { border-color: #cfccc4; }
.chip.on { border-color: var(--ink-ui); background: var(--ink-ui); color: #fff; }
.note { background: var(--well); font-size: 12.5px; border-radius: 10px; }
.warn { font-size: 13px; }
a { color: var(--ink-ui); }

/* top bar: floating over the home stage, a hairline bar elsewhere */
.topbar { padding: 0 clamp(14px, 3vw, 28px); height: 56px; background: rgba(255, 255, 255, .86); border-bottom: 1px solid var(--rule); gap: 16px; }
body[data-page="home"] .topbar { position: fixed; left: 0; right: 0; background: transparent; border-bottom-color: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.brand { gap: 8px; font-size: 1.55rem; }
.brand-name { font-family: var(--serif); font-style: italic; font-weight: 600; letter-spacing: .01em; }
.brand-seal { width: 30px; height: 30px; }
.topbar nav { gap: 6px; }
.topbar nav a { font-size: 14px; padding: 7px 12px; color: var(--mute); }
.topbar nav a:hover { color: var(--ink-ui); background: rgba(22, 22, 26, .04); }
.topbar nav a.on { background: rgba(22, 22, 26, .06); color: var(--ink-ui); }
body[data-page="home"] .topbar nav a { background: rgba(255, 255, 255, .7); color: var(--ink-ui); box-shadow: 0 1px 2px rgba(20, 20, 25, .05); }
.lang-seg { display: inline-flex; padding: 3px; border-radius: 999px; background: rgba(255, 255, 255, .8); border: 1px solid var(--rule); margin-left: 4px; }
.lang-seg button { border: 0; background: none; cursor: pointer; font: 600 12px var(--sans); color: var(--mute); padding: 5px 10px; border-radius: 999px; letter-spacing: .02em; }
.lang-seg button.on { background: var(--ink-ui); color: #fff; }
.save-state { margin-right: auto; display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--mute); }
.save-state i { width: 7px; height: 7px; border-radius: 50%; background: #3f8f5b; box-shadow: 0 0 0 3px rgba(63, 143, 91, .15); }
.save-state.pulse i { animation: savePulse .9s ease; }
@keyframes savePulse { 30% { transform: scale(1.6); } }

/* ---------- home ---------- */
#app { min-height: calc(100vh - 56px); }
.home-stage {
  position: relative; height: 100vh; height: 100dvh; min-height: 560px; overflow: hidden;
  background: radial-gradient(ellipse 70% 60% at 50% 42%, color-mix(in srgb, var(--bg1) 55%, var(--wall)), var(--wall) 72%);
  transition: background .6s var(--ease);
}
.home-stage[data-theme="midnight"] { background: radial-gradient(ellipse 70% 60% at 50% 42%, #3a4573, #1b2240 75%); }
.home-stage .particles { position: absolute; }
.home-gl { position: absolute; inset: 56px 0 0; z-index: 1; cursor: grab; touch-action: none; display: grid; place-items: center; }
.home-stage.grabbing .home-gl { cursor: grabbing; }
.home-gl .gl-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.home-gl .env3d { --w: min(56vw, 640px); }
.home-hint { position: absolute; left: 50%; top: 76px; translate: -50% 0; z-index: 2; margin: 0; font-size: 12.5px; color: var(--mute); background: rgba(255, 255, 255, .6); padding: 5px 12px; border-radius: 999px; backdrop-filter: blur(6px); pointer-events: none; transition: opacity .5s; }
.home-stage.touched .home-hint { opacity: 0; }
.home-stage[data-theme="midnight"] .home-hint { color: #e8eefc; background: rgba(255, 255, 255, .12); }

.float-card { position: absolute; z-index: 3; background: rgba(255, 255, 255, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid rgba(227, 225, 219, .8); border-radius: var(--radius); box-shadow: var(--shadow-float); }
.hero-card { left: clamp(16px, 3vw, 40px); bottom: clamp(16px, 5vh, 48px); width: min(420px, calc(100vw - 32px)); padding: 24px 24px 22px; }
.hero-card h1 { font: 600 clamp(24px, 2.4vw, 30px) / 1.2 var(--sans); letter-spacing: -.015em; margin: 0 0 10px; }
.hero-card p { margin: 0 0 20px; color: var(--mute); font-size: 14px; line-height: 1.6; }
.hero-card .cta { gap: 8px; }
.coll-card { right: clamp(16px, 3vw, 40px); bottom: clamp(16px, 5vh, 48px); width: 280px; padding: 14px 10px 10px; display: flex; flex-direction: column; max-height: calc(100dvh - 140px); }
.coll-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 8px 8px; font-size: 13px; }
.coll-head span { color: var(--mute); font-size: 12px; }
.coll-list { overflow-y: auto; display: flex; flex-direction: column; gap: 1px; scrollbar-width: thin; min-height: 0; }
.coll-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 0; border-radius: 10px; background: none; cursor: pointer; text-align: left; color: var(--ink-ui); font: inherit; transition: background .15s; }
.coll-item:hover { background: var(--well); }
.coll-item.on { background: #ecebe6; }
.coll-ic { width: 34px; flex: none; }
.coll-ic .mini-env { border-radius: 4px; box-shadow: 0 2px 5px -2px rgba(0, 0, 0, .3); }
.coll-ic .mini-seal { font-size: 6px; }
.coll-txt { display: flex; flex-direction: column; min-width: 0; }
.coll-txt b { font-weight: 500; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coll-txt small { color: var(--mute); font-size: 11.5px; }
.coll-all { display: block; margin-top: 6px; padding: 9px 8px 4px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-ui); text-decoration: none; }
.coll-all::after { content: " ›"; color: var(--mute); }
.coll-all:hover { text-decoration: underline; }

.home-more { max-width: 1120px; margin: 0 auto; padding: 64px clamp(16px, 4vw, 40px) 24px; }
.hm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.hm-grid > div { background: #fff; border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px; }
.hm-ic { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--well); font-size: 16px; margin-bottom: 12px; }
.hm-grid h3 { font-size: 14px; font-weight: 600; margin: 0 0 6px; }
.hm-grid p { margin: 0; color: var(--mute); font-size: 13px; line-height: 1.55; }
.site-foot { max-width: 1120px; margin: 0 auto; padding: 40px clamp(16px, 4vw, 40px) 48px; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; font-size: 13px; color: var(--mute); }
.sf-logo { display: flex; align-items: center; gap: 8px; color: var(--ink-ui); font-size: 1.4rem; }
.sf-brand p { margin: 8px 0 0; max-width: 34ch; }
.sf-col { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.sf-col b { color: var(--ink-ui); font-weight: 600; margin-bottom: 2px; }
.sf-col a, .sf-col .link { color: var(--mute); text-decoration: none; }
.sf-col a:hover, .sf-col .link:hover { color: var(--ink-ui); }
.sf-note { grid-column: 1 / -1; margin: 8px 0 0; padding-top: 20px; border-top: 1px solid var(--rule); font-size: 12px; }

/* ---------- pages, letterbox ---------- */
.section { padding-top: 40px; }
.sec-title, .page-title { font: 600 26px / 1.25 var(--sans); letter-spacing: -.01em; }
.sec-sub { font-size: 14px; }
.box-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.letter-card { border-color: var(--rule); box-shadow: 0 1px 2px rgba(20, 20, 25, .03); transition: box-shadow .2s, transform .2s; }
.letter-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.lc-top { background: radial-gradient(ellipse at 50% 30%, color-mix(in srgb, var(--bg1) 60%, var(--wall)), var(--wall)); }
.lc-body h3 { font: 600 15px / 1.35 var(--sans); }
.badge { font-size: 11px; }
.badge-sent { background: #fdf1ef; color: #b3261e; }
.filter .chip span { opacity: .55; }
.empty { background: #fff; border: 1px dashed var(--rule); border-radius: var(--radius); }

/* ---------- modal & toast ---------- */
.modal-back { background: rgba(22, 22, 26, .32); backdrop-filter: blur(4px); }
.modal { background: #fff; border-radius: var(--radius); padding: 22px; box-shadow: 0 30px 80px -24px rgba(20, 20, 25, .4); }
.modal h3 { font: 600 18px / 1.3 var(--sans); margin-bottom: 12px; }
.modal-body { font-size: 14px; }
.modal-actions .btn-ghost { background: var(--well); }
.toast { background: var(--ink-ui); font: 500 13px / 1.4 var(--sans); padding: 10px 16px; border-radius: 12px; }
.qr { border-color: var(--rule); }

/* ---------- studio ---------- */
.studio { height: calc(100vh - 56px); height: calc(100dvh - 56px); grid-template-columns: minmax(0, 1fr) 420px; }
.studio-stage { background: radial-gradient(ellipse 70% 60% at 50% 40%, color-mix(in srgb, var(--bg1) 45%, var(--wall)), var(--wall) 75%); }
.studio-stage[data-theme="midnight"] { background: radial-gradient(ellipse 70% 60% at 50% 40%, #3a4573, #1b2240 78%); }
.stage-help { background: rgba(255, 255, 255, .7); color: var(--mute); opacity: 1; font-size: 12px; }
.seg { background: rgba(255, 255, 255, .92); border: 1px solid var(--rule); box-shadow: var(--shadow); padding: 3px; }
.seg button { font-size: 13px; color: var(--mute); padding: 6px 13px; }
.seg button.on { background: var(--ink-ui); color: #fff; box-shadow: none; }
.studio-bar .try { background: #fff; border: 1px solid var(--rule); box-shadow: var(--shadow); font-size: 13px; }
.zoom-ctl { background: #fff; border: 1px solid var(--rule); box-shadow: var(--shadow); border-radius: 10px; }
.zoom-ctl button { color: var(--ink-ui); }

.studio-panel { border-left-color: var(--rule); }
.studio-tabs { grid-template-columns: repeat(4, 1fr); padding: 0 12px; border-bottom-color: var(--rule); }
.studio-tabs button { padding: 12px 4px 10px; font-size: 12.5px; color: var(--mute); gap: 5px; }
.studio-tabs button svg { width: 18px; height: 18px; }
.studio-tabs button.on { color: var(--ink-ui); font-weight: 600; border-bottom-color: var(--ink-ui); }
.studio-body { padding: 16px 18px 24px; }
.studio-note { font-size: 12.5px; }
.back-btn { display: inline-block; margin: 0 0 10px; font-size: 13px; }
.pane-title { font: 600 11px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--mute); margin: 4px 0 2px; }
.pane + .pane .pane-title { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--rule); }
.field > label, .label-row label { font-size: 13px; font-weight: 600; color: var(--ink-ui); }
.label-row span { font-size: 12px; }
.studio .body-input { font-size: 1.15rem; min-height: 190px; border-radius: 12px; }
.quick { align-items: center; gap: 6px; }
.quick-l { font-size: 12.5px; color: var(--mute); margin-right: 2px; }
.quick .btn { background: #fff; border: 1px solid var(--rule); border-radius: 999px; font-size: 12.5px; padding: 6px 12px; }
.tpl .mini-env, .opt-img { border-radius: 10px; }
.opt-img { background: var(--well); }
.tpl.on .mini-env, .opt.on .opt-img { outline-color: var(--ink-ui); }
.acc { border-bottom-color: var(--rule); }
.acc-h { padding: 15px 2px; font-size: 14px; }
.acc-v { font-size: 12.5px; }
.lbl { font-size: 12.5px; color: var(--mute); }
.link-btn { color: var(--ink-ui); font-size: 12.5px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: #cfccc4; }
.seg2 { background: var(--well); }
.seg2 button { font-size: 13px; color: var(--mute); padding: 7px 10px; }
.seg2 button.on { color: var(--ink-ui); box-shadow: 0 1px 3px rgba(20, 20, 25, .12); }
.sw.on, .wax-sw.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink-ui); }
.studio-actions { gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top-color: var(--rule); }
.studio-actions .btn { flex: none; padding: 11px 12px; font-size: 13px; }
.studio-actions .btn-send { flex: 1; font-size: 14.5px; padding: 12px 16px; border-radius: 12px; }
.studio-actions .btn-quiet { border-radius: 12px; }

/* ---------- reader chrome ---------- */
.stage .btn { background: rgba(255, 255, 255, .9); border-color: rgba(227, 225, 219, .9); color: var(--ink-ui); box-shadow: var(--shadow); }
.stage .btn-primary { background: var(--ink-ui); border-color: var(--ink-ui); color: #fff; }
[data-theme="midnight"] .stage .btn-primary, .stage[data-theme="midnight"] .btn-primary { color: #fff; }
.stage-home { font-size: 1.3rem; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .hm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .studio { height: auto; grid-template-columns: minmax(0, 1fr); }
  .studio-tabs { top: 56px; }
  .save-state { display: none; }
}
@media (max-width: 760px) {
  .topbar { height: 52px; gap: 8px; }
  .topbar nav a { padding: 6px 8px; font-size: 13px; }
  .brand { font-size: 1.35rem; }
  .home-stage { height: auto; min-height: 0; padding: 52px 0 16px; display: flex; flex-direction: column; }
  .home-gl { position: relative; inset: auto; height: 46vh; min-height: 280px; }
  .home-gl .env3d { --w: 82vw; }
  .home-hint { top: 60px; }
  .float-card { position: relative; left: auto; right: auto; bottom: auto; margin: 0 12px; width: auto; }
  .hero-card { padding: 20px; }
  .coll-card { margin-top: 10px; max-height: none; padding: 12px 8px 8px; }
  .coll-list { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .coll-item { flex-direction: column; align-items: flex-start; flex: 0 0 104px; }
  .coll-ic { width: 88px; }
  .coll-txt small { display: none; }
  .hm-grid { grid-template-columns: 1fr; }
  .home-more { padding-top: 32px; }
  .site-foot { grid-template-columns: 1fr 1fr; }
  .sf-brand { grid-column: 1 / -1; }
  .studio-actions .btn-quiet span { display: none; }
}
@media (max-width: 420px) { .lang-seg button { padding: 4px 7px; } .topbar nav a[data-nav="box"] { display: none; } }
@media (max-width: 760px) {
  .home-stage > * { min-width: 0; }
  .float-card { max-width: calc(100vw - 24px); }
  body[data-page="home"] .topbar nav a[data-nav="write"] { display: none; }
  #install { display: none; }
}

/* editing frame over the pieces on the envelope */
.giz { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.giz[hidden] { display: none; }
.giz-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.giz-line polygon { fill: none; stroke: #d23a2c; stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.giz-h { position: absolute; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; background: #fff; border: 1.4px solid #d23a2c; border-radius: 1.5px; pointer-events: auto; cursor: nwse-resize; touch-action: none; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.giz-h[data-gh="ne"], .giz-h[data-gh="sw"] { cursor: nesw-resize; }
.giz-h[data-gh="n"], .giz-h[data-gh="s"] { cursor: ns-resize; }
.giz-h[data-gh="e"], .giz-h[data-gh="w"] { cursor: ew-resize; }
.giz-rot { position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; padding: 0; border-radius: 50%; background: #fff; border: 1.4px solid #d23a2c; color: #d23a2c; display: grid; place-items: center; pointer-events: auto; cursor: grab; touch-action: none; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.giz.busy .giz-rot, .giz.busy .giz-h { cursor: grabbing; }
.giz-bar { position: absolute; transform: translate(-50%, -100%); display: flex; gap: 2px; padding: 4px 6px; background: rgba(38, 38, 42, .92); border-radius: 999px; pointer-events: auto; box-shadow: 0 6px 18px -6px rgba(0,0,0,.4); }
.giz.busy .giz-bar { opacity: 0; pointer-events: none; }
.giz-bar[hidden], .giz-bar button[hidden] { display: none; }
.giz-bar button { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer; }
.giz-bar button:hover { background: rgba(255,255,255,.14); }
.giz-bar button.del { color: #ff7a6e; }
.giz-bar button[hidden] { display: none; }

/* ---------- sub-tabs: each panel tab's sections in one row (one section at a time) ---------- */
.subtabs { position: relative; display: flex; gap: 26px; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex: none; background: #fff; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs[hidden] { display: none; }
.subtabs button { flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 15px 0 13px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; font: 500 14.5px var(--sans); color: var(--muted, #8a7f78); white-space: nowrap; cursor: pointer; transition: color .15s; }
.subtabs button:hover { color: var(--app-ink, #1d1d1f); }
.subtabs button.on { color: var(--app-ink, #1d1d1f); font-weight: 600; border-bottom-color: var(--app-ink, #1d1d1f); }
.subtabs .st-dot:empty { display: none; }
.subtabs .st-dot { display: inline-flex; }
.subtabs .st-dot .dot { width: 11px; height: 11px; }
.studio-panel.tabbed .acc { display: none; border-bottom: 0; }
.studio-panel.tabbed .acc.open { display: block; }
.studio-panel.tabbed .acc-h { display: none; }
.studio-panel.tabbed .acc.open .acc-b { display: block; padding-top: 2px; animation: none; }
.studio-panel.tabbed .pane-title { display: none; }
@media (max-width: 920px) { .subtabs { position: sticky; top: calc(57px + 62px); z-index: 5; } }
/* cover styles: three big cards a row, the front as it will look */
.opt-row.faces { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 12px; }
.faces .opt { width: auto; }
.faces .opt-img { height: auto; aspect-ratio: 1.38; padding: 7px; background: #fff; border: 1px solid rgba(0, 0, 0, .08); border-radius: 12px; }
.faces .opt-img svg.face-pv { width: 100%; height: 100%; }
.faces .opt-l { white-space: normal; line-height: 1.25; }
.face-pv { display: block; width: 100%; height: 100%; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.face-pv .pv-name { font-size: 13px; fill: #9b2a2a; }
.face-pv .pv-name.script { font-family: 'Dancing Script', cursive; font-size: 14px; }
.face-pv .pv-name.blue { fill: #26458f; }
.face-pv .pv-name.sans { font-family: 'Be Vietnam Pro', sans-serif; font-weight: 500; font-size: 10px; fill: #3a3a3c; }
.face-pv .pv-name.small { font-size: 8px; }
.face-pv .pv-name.mono { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 7.5px; fill: #1d1d1f; }
.face-pv .pv-name.bold { font-family: 'Be Vietnam Pro', sans-serif; font-weight: 600; font-size: 15px; fill: #1d1d1f; }
.face-pv .pv-tag { font: 600 6px 'Be Vietnam Pro', sans-serif; fill: #26458f; letter-spacing: .04em; }
.face-pv .pv-mini { font: 600 4.6px 'Be Vietnam Pro', sans-serif; letter-spacing: .03em; }
/* real material scans and patterns: three to a row, grouped */
.grp-h { font: 600 .74rem var(--sans); letter-spacing: .04em; text-transform: uppercase; color: #8a7f78; margin: 14px 0 8px; }
.grp-h:first-child { margin-top: 4px; }
.opt-row.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; }
.grid3 .opt { width: auto; align-self: start; }
.grid3 .opt-img { height: auto; aspect-ratio: 1.25; }
.grid3 .opt-l { white-space: normal; line-height: 1.25; }
.scan-pv { display: block; width: 100%; height: 100%; background: center / cover no-repeat; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.pat-pv { display: block; width: 100%; height: 100%; background-color: var(--pv-env); background-position: center; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.pat-pv.none { background-image: linear-gradient(to top right, transparent calc(50% - .75px), rgba(0, 0, 0, .25) calc(50% - .75px) calc(50% + .75px), transparent calc(50% + .75px)); }
/* hand-torn edges: the same mask on the sheet's back and on the fold/unfold rig as on the sheet itself */
.paper-back.deckled, .fold-rig.deckled .fold-full { -webkit-mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; border-radius: 0; }
.fold-rig.deckled .fold-sheet { border-radius: 0; }
.deckle-switch { margin-top: 14px; }
/* the fold rig carrying the written letter: the letter's own sheet paints the paper (and its torn edge) */
.fold-rig.with-paper .fold-full { background: none; -webkit-mask: none; mask: none; }
.fold-rig.with-paper .fold-full::before { display: none; }
.fold-rig.with-paper .fold-full > .paper { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; box-shadow: none; }
.fold-rig.with-paper .fold-full > .paper::before { display: none; }
.fold-rig.with-paper .fold-crease { z-index: 2; }
/* the fold rig as a real folded sheet: panels hinged at their creases (see foldRig) */
.fold-rig.panels { filter: none; transform-style: preserve-3d; }
.fold-rig.panels .fp { position: absolute; left: 0; right: 0; transform-style: preserve-3d; }
.fold-rig.panels .fp-0 { top: 0; height: calc(100% / var(--n, 2)); }
.fold-rig.panels .fp:not(.fp-0) { top: 100%; height: 100%; transform-origin: 50% 0;
  /* folded: turned up over the panel above (odd) or back under it (even), a hair apart so they never fight */
  transform: rotateX(180deg) translateZ(-.6px);
  transition: transform 1.05s cubic-bezier(.5, .05, .25, 1) calc(.12s + (var(--n) - 1 - var(--i)) * .22s); }
.fold-rig.panels .fp-2 { transform: rotateX(-180deg) translateZ(.6px); }
.fold-rig.panels.open .fp:not(.fp-0) { transform: rotateX(0deg); transition-delay: calc(.12s + (var(--i) - 1) * .22s); }
.fp-face { position: absolute; inset: 0; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.fp-back { transform: rotateX(180deg); }
.fp-sheet { position: absolute; left: 0; width: 100%; }
.fp-sheet > .paper { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; box-shadow: none; }
.fp-sheet > .paper::before { display: none; }
.fp-sheet > .paper > .paper-bg { box-shadow: none; }
/* unfolding out of the envelope the sheet is still blank: the pen writes it once it is open */
.fold-rig.blank .fp-sheet .paper [data-part="script"], .fold-rig.blank .fp-sheet .paper-stickers, .fold-rig.blank .fp-sheet .pen { visibility: hidden; }
/* the back of the paper, upside down as it is once turned over its crease */
.fp-backsheet { transform: scaleY(-1); background: var(--paper-light, linear-gradient(transparent, transparent)), var(--paper); }
.fp-backsheet::before { content: ""; position: absolute; inset: 0; background: var(--pbr-img, none) 0 0 / var(--pbr-size, 512px 512px), var(--paper-tex, none); opacity: calc(.35 + var(--grain, .6) * .65); mix-blend-mode: var(--paper-blend, normal); }
.fp-backsheet.deckled { -webkit-mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; mask: var(--deckle-mask) 0 0 / 100% 100% no-repeat; }
/* a soft shade on a panel while it turns (paper catching less light edge-on) */
.fold-rig.panels .fp:not(.fp-0) > .fp-face::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(0, 0, 0, .1), rgba(0, 0, 0, 0)); opacity: 0; transition: opacity .5s ease .3s; pointer-events: none; }
