:root {
  --bg: #1a1612;
  --panel: #242018;
  --ink: #f5efe6;
  --sub: #a89882;
  --gold: #c9a84c;
  --red: #a84838;
  --line: rgba(255, 255, 255, 0.08);
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "PingFang SC", "Heiti SC", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--gold); }

.gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.88);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate.hidden { display: none; }
.gate-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
}
.gate-card h2 { font-size: 22px; margin-bottom: 8px; }
.gate-card p { font-size: 14px; color: var(--sub); margin-bottom: 20px; }
.gate-card input {
  width: 100%; padding: 14px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-size: 18px; letter-spacing: 0.2em; text-align: center;
}
.gate-card .err { color: #ff8a7a; font-size: 13px; margin-top: 10px; min-height: 18px; }
.gate-card button {
  margin-top: 16px; width: 100%; padding: 14px;
  border: none; border-radius: 8px; background: var(--gold); color: #1a1208;
  font-size: 16px; font-weight: 700; cursor: pointer;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 48px; }
header.hero {
  text-align: center; padding: 28px 0 24px;
  border-bottom: 1px solid var(--line); margin-bottom: 24px;
}
.hero .tag {
  display: inline-block; font-size: 12px; letter-spacing: 0.2em;
  color: var(--gold); border: 1px solid rgba(201, 168, 76, 0.4);
  padding: 4px 12px; border-radius: 999px; margin-bottom: 12px;
}
.hero h1 { font-family: "Songti SC", "STSong", serif; font-size: clamp(26px, 5vw, 34px); font-weight: 700; }
.hero p { color: var(--sub); font-size: 14px; margin-top: 8px; }
.hero .price { color: var(--gold); font-weight: 700; }

section.block { margin-bottom: 28px; }
.block h2 {
  font-size: 15px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--gold); margin-bottom: 12px;
}
.block .hint { font-size: 12px; color: var(--sub); margin-bottom: 12px; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 14px; color: var(--sub); transition: 0.15s;
}
.pill:hover { border-color: rgba(201, 168, 76, 0.4); color: var(--ink); }
.pill.active { border-color: var(--gold); color: var(--gold); background: rgba(201, 168, 76, 0.1); }

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.tpl {
  aspect-ratio: 3/4; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent; overflow: hidden; position: relative;
}
.tpl.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.25); }
.tpl-inner { width: 100%; height: 100%; }
.tpl span {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: 11px; padding: 6px; background: rgba(0,0,0,0.55); text-align: center;
}

.form-grid { display: grid; gap: 12px; }
label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
input[type="text"], textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 15px; font-family: inherit;
}
textarea { min-height: 88px; resize: vertical; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0; }
.preview-actions {
  display: flex; flex-direction: column; gap: 10px; margin-top: 16px;
}
.preview-actions-row {
  display: grid; gap: 10px;
}
.preview-actions-primary { grid-template-columns: 1fr 1fr; }
.preview-actions-secondary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.preview-actions .btn { width: 100%; flex: none; min-width: 0; padding: 12px 14px; font-size: 14px; }
@media (max-width: 520px) {
  .preview-actions-primary { grid-template-columns: 1fr; }
  .preview-actions-secondary { grid-template-columns: 1fr 1fr; }
  .preview-actions-secondary .btn:last-child { grid-column: 1 / -1; }
}
.btn {
  padding: 12px 20px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 15px; font-weight: 600; font-family: inherit;
}
.btn-primary { background: var(--gold); color: #1a1208; flex: 1; min-width: 140px; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

.status { font-size: 13px; color: var(--sub); min-height: 20px; margin-bottom: 8px; }
.status.err { color: #ff8a7a; }
.status.ok { color: #8fd4a0; }

.preview-wrap {
  background: #2a241c; border-radius: var(--radius);
  padding: 20px; border: 1px solid var(--line);
}
.preview-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 16px; font-size: 13px; color: var(--sub);
}
.preview-toolbar select { width: auto; min-width: 110px; padding: 8px 10px; font-size: 13px; }
.preview-toolbar label + select { margin-right: 12px; }

.letter-measure {
  position: fixed; left: -9999px; top: 0; z-index: -1;
  width: min(100%, 595px); aspect-ratio: 210/297;
  visibility: hidden; pointer-events: none;
}
.letter-measure .letter { width: 100%; height: 100%; box-shadow: none; }
.is-export-hidden { display: none !important; }

.letter-pages { width: 100%; max-width: 595px; margin: 0 auto; }
.letter-page {
  width: 100%; aspect-ratio: 210/297; position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  margin-bottom: 0;
}
.letter-page + .letter-page { margin-top: 16px; }
.letter-page.is-active-only { display: block; }
.letter-pages.is-paged .letter-page { display: none; }
.letter-pages.is-paged .letter-page.is-active { display: block; }

.page-nav {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  max-width: 595px; margin: 12px auto 0;
}
.page-nav.hidden { display: none; }
.page-indicator { font-size: 13px; color: var(--sub); min-width: 4.5em; text-align: center; }
.btn-page {
  width: 36px; height: 36px; padding: 0; font-size: 20px; line-height: 1;
  border-radius: 50%;
}
.btn-page:disabled { opacity: 0.35; cursor: not-allowed; }

.letter-page-badge {
  position: absolute; bottom: 20px; left: 44px; z-index: 1;
  font-size: 11px; opacity: 0.45; letter-spacing: 0.05em;
  pointer-events: none;
}
.letter-sign .letter-date {
  display: block; margin-top: 4px; font-size: 13px; opacity: 0.75;
}
.letter-meta.has-continued .letter-meta-to::after { content: "（续）"; }

.letter {
  width: 100%; height: 100%; padding: 48px 44px 56px;
  position: relative; overflow: hidden;
  font-family: "Songti SC", "STSong", "KaiTi", serif;
  --letter-rule: 32px;
  --letter-body-size: 16px;
}
.letter-content {
  position: relative; z-index: 1;
  height: 100%;
  display: flex; flex-direction: column;
}
.letter-body {
  font-size: 16px; line-height: 2;
  white-space: pre-wrap; word-break: break-word;
  flex: 1 1 auto; min-height: 0;
  overflow: hidden;
}
/* 横线信纸：行高与背景线 32px 对齐 */
.letter.has-rules .letter-meta {
  font-size: 13px;
  line-height: 16px;
  margin-bottom: 16px;
}
.letter.has-rules .letter-body {
  font-size: var(--letter-body-size);
  line-height: var(--letter-rule);
  letter-spacing: 0.02em;
}
.letter.has-rules .letter-sign {
  padding-top: var(--letter-rule);
  line-height: var(--letter-rule);
  font-size: 15px;
}
.letter.has-rules .font-brush,
.letter.has-rules .font-pen,
.letter.has-rules .font-lite {
  font-size: var(--letter-body-size);
}
.letter-meta {
  font-size: 13px; margin-bottom: 20px; opacity: 0.75;
  flex-shrink: 0;
}
.letter-sign { margin-top: auto; padding-top: 24px; text-align: right; font-size: 15px; flex-shrink: 0; }

/* —— 字体 —— */
.font-song { font-family: "Noto Serif SC", "Songti SC", "STSong", serif; }
.font-kai { font-family: "KaiTi", "STKaiti", "楷体", serif; }
.font-brush { font-family: "Ma Shan Zheng", "KaiTi", cursive; font-size: 1.05em; }
.font-pen { font-family: "Long Cang", "KaiTi", cursive; font-size: 1.08em; letter-spacing: 0.02em; }
.font-lite { font-family: "ZCOOL XiaoWei", "PingFang SC", sans-serif; font-size: 1.02em; }

/* —— 火漆邮戳 —— */
.stamp-deco {
  position: absolute; z-index: 2;
  width: 78px; height: 78px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0.92;
}
.stamp-deco.pos-tr { top: 36px; right: 36px; transform: rotate(6deg); }
.stamp-deco.pos-tl { top: 36px; left: 36px; transform: rotate(-5deg); }
.stamp-deco.pos-br { bottom: 48px; right: 36px; transform: rotate(4deg); }
.stamp-deco.pos-bl { bottom: 48px; left: 36px; transform: rotate(-6deg); }
.stamp-deco.pos-cr { top: 50%; right: 24px; transform: translateY(-50%) rotate(3deg); }

.wax-body {
  width: 72px; height: 72px; position: relative;
  border-radius: 48% 52% 55% 45% / 52% 48% 52% 48%;
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    inset 0 2px 8px rgba(255,255,255,0.35),
    inset 0 -4px 12px rgba(0,0,0,0.15),
    0 6px 18px rgba(0,0,0,0.22);
}
.wax-shimmer {
  position: absolute; top: 10%; left: 15%; width: 55%; height: 55%;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.5), transparent 60%);
  pointer-events: none;
}
.wax-ring {
  position: absolute; inset: 6px;
  border-radius: 48% 52% 50% 50% / 50% 48% 52% 50%;
  border: 1.5px solid rgba(255,255,255,0.28);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.wax-center {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; line-height: 1.15;
}
.wax-main {
  font-family: "Ma Shan Zheng", "KaiTi", serif;
  font-size: 22px; font-weight: 400;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
.wax-icon { font-size: 18px; margin-bottom: 2px; opacity: 0.9; }
.wax-caption { display: none; }

.wax-crimson .wax-body { background: radial-gradient(circle at 35% 30%, rgba(220,80,70,0.88), rgba(140,35,35,0.78)); color: #fff8f0; }
.wax-wine .wax-body { background: radial-gradient(circle at 35% 30%, rgba(120,40,55,0.85), rgba(70,20,35,0.8)); color: #fce8e8; }
.wax-gold .wax-body { background: radial-gradient(circle at 35% 30%, rgba(210,170,80,0.9), rgba(140,100,40,0.82)); color: #2a1808; }
.wax-rose .wax-body { background: radial-gradient(circle at 35% 30%, rgba(200,90,110,0.86), rgba(130,50,70,0.78)); color: #fff5f7; }
.wax-amber .wax-body { background: radial-gradient(circle at 35% 30%, rgba(210,130,60,0.88), rgba(140,80,30,0.8)); color: #fff8ee; }
.wax-plum .wax-body { background: radial-gradient(circle at 35% 30%, rgba(120,70,120,0.84), rgba(70,40,80,0.78)); color: #f5eef8; }
.wax-cocoa .wax-body { background: radial-gradient(circle at 35% 30%, rgba(120,80,55,0.86), rgba(70,45,30,0.8)); color: #f8efe6; }
.wax-slate .wax-body { background: radial-gradient(circle at 35% 30%, rgba(90,100,120,0.82), rgba(50,55,70,0.78)); color: #eef2f8; }
.wax-vermillion .wax-body { background: radial-gradient(circle at 35% 30%, rgba(200,50,45,0.9), rgba(120,25,25,0.82)); color: #fff5e8; }
.wax-burgundy .wax-body { background: radial-gradient(circle at 35% 30%, rgba(100,30,45,0.86), rgba(55,15,30,0.8)); color: #fce8ec; }
.wax-teal .wax-body { background: radial-gradient(circle at 35% 30%, rgba(50,110,105,0.84), rgba(30,70,68,0.78)); color: #e8f8f6; }
.wax-coral .wax-body { background: radial-gradient(circle at 35% 30%, rgba(230,110,90,0.86), rgba(160,60,50,0.78)); color: #fff8f5; }

.letter.tpl-night .wax-caption { color: #e8dfd0; }
.letter.tpl-night .wax-body { box-shadow: inset 0 2px 8px rgba(255,255,255,0.2), 0 6px 16px rgba(0,0,0,0.45); }
.stamp-deco.hidden { display: none; }

.letter-content.pad-pr { padding-right: 92px; }
.letter-content.pad-pl { padding-left: 92px; }
.letter-content.pad-pt { padding-top: 100px; }
.letter-content.pad-pb { padding-bottom: 100px; }

.letter.tpl-cream { background: #f4e8d4; color: #2a2018; }
.letter.tpl-cream .lines {
  position: absolute; inset: 48px 44px 56px;
  background: repeating-linear-gradient(transparent, transparent 31px, rgba(80,60,40,0.12) 31px, rgba(80,60,40,0.12) 32px);
  pointer-events: none;
}
.letter.tpl-qiaopi {
  background: #faf3e8; color: #1f140e;
  border: 3px double #8b3a2a;
  box-shadow: inset 0 0 0 8px rgba(139,58,42,0.08);
}
.letter.tpl-qiaopi::before {
  content: "侨批 · 银信";
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: 11px; letter-spacing: 0.35em; color: #8b3a2a; opacity: 0.6;
}
.letter.tpl-kapok { background: linear-gradient(165deg, #f8ead8 0%, #edd5bc 100%); color: #3d2818; }
.letter.tpl-night { background: #1e1a16; color: #e8dfd0; border: 1px solid #3d3528; }
.letter.tpl-vertical { background: #f0e6d6; color: #2a1810; }
.letter.tpl-vertical .letter-content { writing-mode: vertical-rl; text-orientation: mixed; max-height: 100%; }
.letter.tpl-vertical .letter-body { max-height: none; }

.letter.tpl-blue { background: #f8fbff; color: #1a2838; }
.letter.tpl-blue .lines {
  position: absolute; inset: 48px 44px 56px;
  background:
    repeating-linear-gradient(transparent, transparent 31px, rgba(60,100,160,0.14) 31px, rgba(60,100,160,0.14) 32px),
    linear-gradient(90deg, transparent 39px, rgba(60,100,160,0.22) 40px, rgba(60,100,160,0.22) 41px, transparent 42px);
  pointer-events: none;
}

.letter.tpl-kraft {
  background: #c9a86c linear-gradient(135deg, rgba(255,255,255,0.08), transparent 40%, rgba(0,0,0,0.06));
  color: #2a1e10;
  box-shadow: inset 0 0 80px rgba(80,50,20,0.12);
}

.letter.tpl-ink {
  background: #f7f5f0;
  color: #1a1814;
}
.letter.tpl-ink::after {
  content: "";
  position: absolute; bottom: 12%; right: 8%; width: 38%; height: 28%;
  background: radial-gradient(ellipse, rgba(40,40,40,0.06), transparent 70%);
  pointer-events: none;
}
.letter.tpl-ink::before {
  content: "留白";
  position: absolute; top: 20px; right: 28px;
  font-family: "Ma Shan Zheng", serif; font-size: 28px;
  color: rgba(40,40,40,0.08); writing-mode: vertical-rl;
}

.letter.tpl-postcard {
  background: #fffef8;
  color: #2a2018;
  border: 1px solid #d8d0c0;
  box-shadow: inset 0 0 0 6px #fffef8, inset 0 0 0 7px #c8b898;
}
.letter.tpl-postcard::before {
  content: "";
  position: absolute; top: 48px; right: 44px; bottom: 56px; width: 42%;
  border-left: 1px dashed rgba(120,100,70,0.35);
  pointer-events: none;
}
.letter.tpl-postcard::after {
  content: "POST CARD";
  position: absolute; top: 52px; left: 48px;
  font-size: 9px; letter-spacing: 0.35em; color: rgba(120,90,50,0.45);
}

.letter.tpl-airmail {
  background: #f4f0e8;
  color: #1a2830;
  border-top: 12px solid transparent;
  border-image: repeating-linear-gradient(90deg, #c44 0, #c44 8px, #fff 8px, #fff 16px, #248 16px, #248 24px, #fff 24px, #fff 32px) 12;
}

.letter.tpl-rose {
  background: linear-gradient(180deg, #fff5f8 0%, #fce8ef 100%);
  color: #3d2030;
}
.letter.tpl-rose::before {
  content: "✿";
  position: absolute; bottom: 40px; right: 36px;
  font-size: 48px; opacity: 0.12;
}

.letter.tpl-goldedge {
  background: #1a1612;
  color: #e8dfd0;
  box-shadow: inset 0 0 0 3px #c9a84c, inset 0 0 0 6px #1a1612, inset 0 0 0 8px rgba(201,168,76,0.35);
}

.letter.tpl-grid { background: #faf8f4; color: #2a2018; }
.letter.tpl-grid .lines {
  position: absolute; inset: 48px 44px 56px;
  background:
    repeating-linear-gradient(transparent, transparent 31px, rgba(80,60,40,0.1) 31px, rgba(80,60,40,0.1) 32px),
    repeating-linear-gradient(90deg, transparent, transparent 31px, rgba(80,60,40,0.08) 31px, rgba(80,60,40,0.08) 32px);
  pointer-events: none;
}

.letter.tpl-bamboo {
  background: linear-gradient(180deg, #eef6ee 0%, #dce8dc 100%);
  color: #1a3020;
  border-left: 4px solid rgba(60,100,60,0.25);
}

.letter.tpl-minimal {
  background: #ffffff;
  color: #111;
  border: 1px solid #e0e0e0;
}
.letter.tpl-minimal .letter-meta { opacity: 0.5; font-family: "PingFang SC", sans-serif; letter-spacing: 0.05em; }

.letter.tpl-zhu {
  background:
    radial-gradient(circle at 12% 18%, rgba(168, 32, 32, 0.05), transparent 38%),
    radial-gradient(circle at 88% 82%, rgba(120, 80, 40, 0.04), transparent 42%),
    #f6efe3;
  color: #2a1810;
  box-shadow: inset 4px 0 0 #a82020, inset 7px 0 0 rgba(168, 32, 32, 0.12);
}
.letter.tpl-zhu::before {
  content: "";
  position: absolute; left: 28px; top: 48px; bottom: 56px; width: 1px;
  background: linear-gradient(180deg, transparent, rgba(168, 32, 32, 0.28) 12%, rgba(168, 32, 32, 0.28) 88%, transparent);
  pointer-events: none;
}
.letter.tpl-zhu::after {
  content: "敬";
  position: absolute; top: 52px; right: 40px;
  font-family: "Ma Shan Zheng", "KaiTi", serif; font-size: 36px;
  color: rgba(168, 32, 32, 0.09); writing-mode: vertical-rl; letter-spacing: 0.2em;
  pointer-events: none;
}

/* —— 信封（15 款）—— */
.envelope-preview {
  max-width: 595px; margin: 16px auto 0; aspect-ratio: 220/110;
  position: relative; border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  overflow: hidden;
  background: var(--env-bg, #e8dcc8);
  border: 1px solid var(--env-border, #b8a888);
}
.envelope-preview::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 55%;
  background: var(--env-flap, linear-gradient(135deg, transparent 49.5%, #c9b898 50%, #d8ccb0 100%));
  border-bottom: 1px dashed var(--env-flap-line, #a89070);
  pointer-events: none;
}
.envelope-preview::after {
  content: var(--env-deco, none);
}
.env-stamp {
  position: absolute; top: 18px; right: 24px; z-index: 1;
  width: 56px; height: 68px; border: 2px dashed var(--env-stamp-border, #8b6914);
  background: var(--env-stamp-bg, rgba(255,255,255,0.35)); font-size: 9px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--env-stamp-text, #5a4020);
}
.env-to {
  position: absolute; bottom: 16px; left: 20px; right: 20px; z-index: 1;
  font-size: 12px; color: var(--env-text, #4a3828); font-family: "Songti SC", serif;
}

.env-classic {
  --env-bg: #e8dcc8; --env-border: #b8a888;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #c9b898 50%, #d8ccb0 100%);
  --env-flap-line: #a89070; --env-text: #4a3828;
}
.env-kraft {
  --env-bg: #c4a574; --env-border: #8a6840;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #a88858 50%, #b89868 100%);
  --env-flap-line: #705830; --env-text: #2a1808;
  --env-stamp-border: #5a4020; --env-stamp-bg: rgba(255,248,230,0.25);
}
.env-white {
  --env-bg: #fafafa; --env-border: #d0d0d0;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #f0f0f0 50%, #ffffff 100%);
  --env-flap-line: #c8c8c8; --env-text: #333;
  --env-stamp-border: #999; --env-stamp-bg: rgba(240,240,240,0.8);
}
.env-cream {
  --env-bg: #f5ead8; --env-border: #d4c4a8;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #ead8c0 50%, #f0e4d0 100%);
  --env-flap-line: #c0a880; --env-text: #3d3020;
}
.env-qiaopi {
  --env-bg: #faf3e8; --env-border: #8b3a2a;
  border-width: 2px;
  box-shadow: inset 0 0 0 4px rgba(139,58,42,0.12);
  --env-flap: linear-gradient(135deg, transparent 49.5%, rgba(139,58,42,0.08) 50%, #f5ebe0 100%);
  --env-flap-line: rgba(139,58,42,0.35); --env-text: #5a2018;
  --env-stamp-border: #8b3a2a;
}
.env-night {
  --env-bg: #1e1a16; --env-border: #c9a84c;
  box-shadow: inset 0 0 0 1px rgba(201,168,76,0.35), 0 8px 24px rgba(0,0,0,0.45);
  --env-flap: linear-gradient(135deg, transparent 49.5%, #2a2418 50%, #252018 100%);
  --env-flap-line: rgba(201,168,76,0.4); --env-text: #e8dfd0;
  --env-stamp-border: #c9a84c; --env-stamp-bg: rgba(30,26,22,0.6); --env-stamp-text: #e8dfd0;
}
.env-rose {
  --env-bg: linear-gradient(180deg, #fff5f8, #fce8ef);
  --env-border: #e8b8c8;
  --env-flap: linear-gradient(135deg, transparent 49.5%, rgba(232,160,180,0.25) 50%, #fce8ef 100%);
  --env-flap-line: #e0a0b0; --env-text: #5a2838;
  --env-stamp-border: #c87898;
}
.env-bamboo {
  --env-bg: linear-gradient(180deg, #eef6ee, #dce8dc);
  --env-border: #88a888;
  --env-flap: linear-gradient(135deg, transparent 49.5%, rgba(100,140,100,0.2) 50%, #dce8dc 100%);
  --env-flap-line: #98b898; --env-text: #1a3020;
  --env-stamp-border: #508050;
}
.env-airmail {
  --env-bg: #f4f0e8; --env-border: #888;
  border-top: 10px solid transparent;
  border-image: repeating-linear-gradient(90deg, #c44 0, #c44 7px, #fff 7px, #fff 14px, #248 14px, #248 21px, #fff 21px, #fff 28px) 10;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #e8e4dc 50%, #f0ece4 100%);
  --env-flap-line: #888; --env-text: #1a2830;
}
.env-vintage {
  --env-bg: #e8dcc8;
  --env-border: #a89070;
  background-image: radial-gradient(circle at 20% 80%, rgba(120,80,40,0.06) 0, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(120,80,40,0.05) 0, transparent 40%);
  --env-flap: linear-gradient(135deg, transparent 49.5%, rgba(160,120,80,0.15) 50%, #ddd0b8 100%);
  --env-flap-line: #988060; --env-text: #3a2818;
}
.env-blue {
  --env-bg: #e8eef4; --env-border: #7898b8;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #d0dce8 50%, #e0e8f0 100%);
  --env-flap-line: #7898b8; --env-text: #1a2838;
  --env-stamp-border: #5070a0;
}
.env-festive {
  --env-bg: #c83838; --env-border: #a82020;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #b03030 50%, #c83838 100%);
  --env-flap-line: rgba(255,220,180,0.5); --env-text: #fff8e8;
  --env-stamp-border: #ffd080; --env-stamp-bg: rgba(255,255,255,0.2); --env-stamp-text: #fff8e8;
}
.env-minimal {
  --env-bg: #fff; --env-border: #e0e0e0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  --env-flap: linear-gradient(135deg, transparent 49.5%, #f8f8f8 50%, #fff 100%);
  --env-flap-line: #e8e8e8; --env-text: #222;
  --env-stamp-border: #ccc; --env-stamp-bg: #fafafa;
}
.env-kapok {
  --env-bg: linear-gradient(165deg, #f8ead8, #edd5bc);
  --env-border: #c8a878;
  --env-flap: linear-gradient(135deg, transparent 49.5%, #e0c8a0 50%, #edd5bc 100%);
  --env-flap-line: #b89868; --env-text: #3d2818;
}
.env-gold {
  --env-bg: #1a1612; --env-border: #c9a84c;
  box-shadow: inset 0 0 0 2px #c9a84c, inset 0 0 0 4px #1a1612, inset 0 0 0 5px rgba(201,168,76,0.4);
  --env-flap: linear-gradient(135deg, transparent 49.5%, #2a2418 50%, #221c14 100%);
  --env-flap-line: rgba(201,168,76,0.55); --env-text: #f0e8d8;
  --env-stamp-border: #c9a84c; --env-stamp-bg: rgba(201,168,76,0.12); --env-stamp-text: #c9a84c;
}

.disclaimer {
  margin-top: 32px; padding: 16px; border-radius: 8px;
  background: rgba(255,255,255,0.04); font-size: 12px; color: var(--sub); line-height: 1.7;
}

.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.75);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(480px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 22px;
}
.modal-card h3 { font-size: 18px; margin-bottom: 8px; }
.modal-desc { font-size: 13px; color: var(--sub); margin-bottom: 14px; line-height: 1.6; }
.modal-card input {
  width: 100%; padding: 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-size: 13px; margin-bottom: 8px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 12px; }
.modal-actions .btn { flex: 1; }

@media print {
  body { background: #fff; color: #000; }
  .gate, header.hero, section.block:not(.print-area), .disclaimer, .preview-toolbar, .preview-actions, .page-nav, .actions, .modal { display: none !important; }
  .preview-wrap { padding: 0; border: none; background: none; }
  .letter-measure { display: none !important; }
  .letter-pages.is-paged .letter-page { display: block !important; }
  .letter-page, .envelope-preview { box-shadow: none; max-width: 100%; page-break-inside: avoid; }
  .letter-page { page-break-after: always; margin-top: 0; }
  .letter-page:last-child { page-break-after: auto; }
}

@media (min-width: 768px) {
  .layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
  .layout .preview-wrap { grid-column: 2; position: sticky; top: 16px; }
}
