/* ============================================================
   在线情书生成器 / Love Letter Generator
   ToolCMS V3.13 plugin stylesheet
   - all colour, radius and focus states follow the site theme vars
   - icons are inline SVG masks; no external requests
   - cards keep natural height; the preview card uses a fixed three-state stick, never position:sticky
   ============================================================ */

.love-letter-generator-container {
    --llg-fill: var(--primary, #10B981);
    --llg-fill-soft: var(--primary-light, rgba(16, 185, 129, .10));
    --llg-track: #E5E7EB;
    --llg-ink: var(--text, #333);
    --llg-muted: var(--text-secondary, #6b7280);
    --llg-line: var(--border, #e5e7eb);
    --llg-card: var(--bg-input, #fff);
    --llg-soft: var(--bg-btn, #f9fafb);
    --llg-radius: var(--radius, 10px);
    --llg-radius-sm: var(--radius-sm, 7px);
    --i-pen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E");
    --i-mail: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='2'/%3E%3Cpath d='m3 7 9 6 9-6'/%3E%3C/svg%3E");
    --i-wand: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 4 5 5L8 21H3v-5Z'/%3E%3Cpath d='M14 5 3 16'/%3E%3Cpath d='M18 2v4M16 4h4M21 13v3M19.5 14.5h3'/%3E%3C/svg%3E");
    --i-refresh: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a9 9 0 0 0-15-6.7L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3Cpath d='M3 12a9 9 0 0 0 15 6.7L21 16'/%3E%3Cpath d='M21 21v-5h-5'/%3E%3C/svg%3E");
    --i-reset: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E");
    --i-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
    --i-file: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E");
    --i-md: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 5h16v14H4z'/%3E%3Cpath d='M7 15V9l2 3 2-3v6M16 9v6M14.5 13.5 16 15l1.5-1.5'/%3E%3C/svg%3E");
    --i-code: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m8 9-3 3 3 3M16 9l3 3-3 3M13 6l-2 12'/%3E%3C/svg%3E");
    --i-print: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9V3h12v6M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='7'/%3E%3C/svg%3E");
    --i-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Ccircle cx='8.5' cy='9' r='1.5'/%3E%3Cpath d='m21 15-5-5L5 20'/%3E%3C/svg%3E");
    --i-heart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8L12 21l8.8-8.6a5.5 5.5 0 0 0 0-7.8Z'/%3E%3C/svg%3E");
    --i-lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E");
    --i-unlock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 7.5-2'/%3E%3C/svg%3E");
    --i-swap: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7h14l-3-3M21 17H7l3 3'/%3E%3C/svg%3E");
    --i-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    --i-warn: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h16.9a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
    --i-read: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10v4M7 6v12M11 8v8M15 5v14M19 9v6M22 11v2'/%3E%3C/svg%3E");
    --i-undo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 14 4 9l5-5'/%3E%3Cpath d='M4 9h10a6 6 0 0 1 0 12h-1'/%3E%3C/svg%3E");
    --i-redo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 14 5-5-5-5'/%3E%3Cpath d='M20 9H10a6 6 0 0 0 0 12h1'/%3E%3C/svg%3E");
}

.love-letter-generator-container,
.love-letter-generator-container *,
.love-letter-generator-container *::before,
.love-letter-generator-container *::after { box-sizing: border-box; }

.love-letter-generator-container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    color: var(--llg-ink);
    font-size: 14px;
    line-height: 1.6;
    font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---------- top ---------- */
.llg-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin: 0 0 14px;
}
.llg-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.llg-mark {
    position: relative;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    color: var(--llg-fill);
    display: grid;
    place-items: center;
    overflow: hidden;
}
.llg-mark::before { content: ""; position: absolute; inset: 0; background: currentColor; opacity: .13; }
.llg-mark::after {
    content: "";
    position: relative;
    width: 22px; height: 22px;
    background: currentColor;
    -webkit-mask: var(--i-mail) center / contain no-repeat;
    mask: var(--i-mail) center / contain no-repeat;
}
.llg-brand-txt { min-width: 0; }
.llg-title { margin: 0; font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.2px; }
.llg-sub { margin: 3px 0 0; color: var(--llg-muted); font-size: 12.5px; line-height: 1.5; }
.llg-tags { display: flex; gap: 7px; flex-wrap: wrap; padding-top: 2px; }
.llg-tag {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 26px; padding: 3px 9px;
    border: 1px solid var(--llg-line); border-radius: 999px;
    background: var(--llg-soft); color: var(--llg-muted);
    font-size: 11.5px; white-space: nowrap;
}
.llg-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--llg-fill); }
.llg-tag-soft { color: var(--llg-fill); border-color: color-mix(in srgb, var(--llg-fill) 28%, var(--llg-line)); background: var(--llg-fill-soft); }

/* ---------- layout ---------- */
.llg-grid {
    display: grid;
    grid-template-columns: minmax(340px, 410px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    width: 100%;
}
.llg-grid > * { min-width: 0; }
.llg-preview { grid-column: 2; align-self: start; width: 100%; height: auto; }
.llg-preview-ph { display: none; grid-column: 2; min-height: 0; }
.llg-preview.is-fixed { position: fixed; z-index: 30; margin: 0; max-width: none; will-change: top, left, width; }
.llg-card {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border: 1px solid var(--llg-line);
    border-radius: var(--llg-radius);
    background: var(--llg-card);
    padding: 16px;
    display: block;
}
.llg-settings { padding-bottom: 15px; }
.llg-preview { padding-bottom: 6px; }

.llg-card-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin: 0 0 14px; }
.llg-head-ico { position: relative; flex: 0 0 auto; width: 28px; height: 28px; border-radius: var(--llg-radius-sm); color: var(--llg-fill); display: grid; place-items: center; overflow: hidden; }
.llg-head-ico::before { content: ""; position: absolute; inset: 0; background: currentColor; opacity: .13; }
.llg-head-ico::after { content: ""; position: relative; width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.llg-ico-pen { --ico: var(--i-pen); }
.llg-ico-mail { --ico: var(--i-mail); }
.llg-head-txt { min-width: 0; }
.llg-head-t { margin: 0; font-size: 14px; font-weight: 650; line-height: 1.35; }
.llg-head-s { margin: 1px 0 0; color: var(--llg-muted); font-size: 11.5px; line-height: 1.45; }
.llg-badge {
    margin-left: auto;
    display: inline-flex; align-items: center; gap: 5px;
    max-width: 100%; padding: 3px 8px;
    border: 1px solid color-mix(in srgb, var(--llg-fill) 25%, var(--llg-line));
    border-radius: 999px; background: var(--llg-fill-soft); color: var(--llg-fill);
    font-size: 11px; line-height: 1.4; white-space: nowrap;
}
.llg-badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ---------- settings body ---------- */
.llg-body { display: flex; flex-direction: column; gap: 14px; }
.llg-group { padding-top: 12px; border-top: 1px solid var(--llg-line); }
.llg-group:first-child { padding-top: 0; border-top: 0; }
.llg-group-title {
    margin: 0 0 9px;
    padding-left: 8px;
    border-left: 3px solid var(--llg-fill);
    font-size: 12px; font-weight: 650; line-height: 1.4; color: var(--llg-ink);
}
.llg-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.llg-field { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.llg-span-2 { grid-column: 1 / -1; }
.llg-label {
    display: block;
    min-height: 16px;
    color: var(--llg-muted);
    font-size: 12px;
    line-height: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.llg-slider-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 16px; }
.llg-slider-head .llg-label { min-height: 0; }
.llg-output {
    flex: 0 0 auto;
    min-width: 42px; padding: 1px 6px;
    border: 1px solid var(--llg-line);
    border-radius: 5px;
    background: var(--llg-soft);
    color: var(--llg-fill);
    font-size: 11px; line-height: 16px;
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.llg-input, .llg-select, .llg-textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--llg-line);
    border-radius: var(--llg-radius-sm);
    background: var(--llg-card);
    color: var(--llg-ink);
    font: inherit;
    outline: none;
    transition: border-color .14s ease, box-shadow .14s ease;
}
.llg-input, .llg-select { height: 34px; padding: 6px 10px; font-size: 13px; }
.llg-textarea { min-height: 62px; padding: 8px 10px; font-size: 13px; line-height: 1.55; resize: vertical; }
.llg-input::placeholder, .llg-textarea::placeholder { color: color-mix(in srgb, var(--llg-muted) 62%, transparent); }
.llg-input:focus, .llg-select:focus, .llg-textarea:focus {
    border-color: var(--llg-fill);
    box-shadow: 0 0 0 3px var(--llg-fill-soft);
}
.llg-select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--llg-muted) 50%), linear-gradient(135deg, var(--llg-muted) 50%, transparent 50%); background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.llg-input-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; letter-spacing: .1px; }
.llg-hint { margin: 1px 0 0; color: var(--llg-muted); font-size: 11px; line-height: 1.5; }

/* ---------- range: deliberately heavier than a site input[type=range] ---------- */
.love-letter-generator-container input.love-letter-generator-range {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    height: 34px;
    margin: 0;
    padding: 9px 0;
    border: 0;
    background: transparent;
    outline: none;
    cursor: pointer;
}
.love-letter-generator-container .love-letter-generator-range::-webkit-slider-runnable-track {
    width: 100%;
    height: 5px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--llg-fill) 0 var(--fill, 50%), var(--llg-track) var(--fill, 50%) 100%);
}
.love-letter-generator-container .love-letter-generator-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -4.5px;
    border: 0;
    border-radius: 50%;
    background: var(--llg-fill);
    box-shadow: 0 1px 3px rgba(0,0,0,.22);
}
.love-letter-generator-container .love-letter-generator-range::-moz-range-track {
    height: 5px;
    border: 0;
    border-radius: 999px;
    background: var(--llg-track);
}
.love-letter-generator-container .love-letter-generator-range::-moz-range-progress {
    height: 5px;
    border: 0;
    border-radius: 999px;
    background: var(--llg-fill);
}
.love-letter-generator-container .love-letter-generator-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: var(--llg-fill);
    box-shadow: 0 1px 3px rgba(0,0,0,.22);
}
.love-letter-generator-container .love-letter-generator-range:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px var(--llg-fill-soft), 0 1px 3px rgba(0,0,0,.22);
}

/* ---------- paper picker + switches ---------- */
.llg-paper-pick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 0 0 10px; }
.llg-paper-btn {
    display: flex; align-items: center; gap: 7px;
    min-height: 34px; padding: 4px 8px;
    border: 1px solid var(--llg-line); border-radius: var(--llg-radius-sm);
    background: var(--llg-soft); color: var(--llg-ink);
    font: inherit; font-size: 12px; text-align: left;
    cursor: pointer; transition: border-color .14s ease, background-color .14s ease;
}
.llg-paper-btn:hover { border-color: var(--llg-fill); }
.llg-paper-btn[aria-pressed="true"] { border-color: var(--llg-fill); background: var(--llg-fill-soft); color: var(--llg-fill); }
.llg-paper-btn:focus-visible { outline: 2px solid var(--llg-fill); outline-offset: 2px; }
.llg-swatch { flex: 0 0 auto; width: 20px; height: 20px; border: 1px solid rgba(0,0,0,.10); border-radius: 4px; }
.llg-swatch-cream { background: #FFFBF2; }
.llg-swatch-rose { background: #FFF5F7; }
.llg-swatch-sage { background: #F4F8F2; }
.llg-swatch-kraft { background: #E8D9C0; }
.llg-swatch-midnight { background: #1C2733; }
.llg-swatch-grid { background: #fff; background-image: linear-gradient(#dbe3ea 1px, transparent 1px), linear-gradient(90deg, #dbe3ea 1px, transparent 1px); background-size: 6px 6px; }
.llg-swatch-lavender { background: #F7F2FF; }
.llg-swatch-ocean { background: #F0F7FB; }
.llg-swatch-peach { background: #FFF4EE; }
.llg-swatch-linen { background: #FAF7F0; background-image: repeating-linear-gradient(115deg, rgba(160,145,120,.08) 0 1px, transparent 1px 4px); }
.llg-swatch-botanical { background: #FBF8EE; background-image: radial-gradient(ellipse 4px 2px at 5px 6px, rgba(95,125,75,.35), transparent 60%), radial-gradient(ellipse 2px 4px at 14px 15px, rgba(125,95,55,.25), transparent 60%); background-size: 20px 20px, 20px 20px; }
.llg-swatch-starry { background: #151C30; background-image: radial-gradient(circle at 5px 5px, rgba(255,228,168,.9) 0 1px, transparent 1.5px), radial-gradient(circle at 15px 14px, rgba(255,228,168,.55) 0 .8px, transparent 1.2px); background-size: 20px 20px, 20px 20px; }
.llg-swatch-parchment { background: #F3E7CF; background-image: repeating-linear-gradient(115deg, rgba(120,80,40,.10) 0 1px, transparent 1px 4px); }
.llg-swatch-blossom { background: #FFF0F3; background-image: radial-gradient(ellipse 5px 2px at 6px 7px, rgba(205,115,145,.32), transparent 60%), radial-gradient(ellipse 2px 5px at 15px 15px, rgba(205,115,145,.22), transparent 60%); background-size: 22px 22px, 22px 22px; }
.llg-fields-paper { margin-top: 0; }

.llg-switch { display: flex; align-items: center; gap: 8px; min-height: 34px; cursor: pointer; }
.llg-switch input {
    position: absolute;
    width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.llg-switch-track {
    position: relative; flex: 0 0 auto;
    width: 36px; height: 20px; border-radius: 999px;
    background: var(--llg-track); transition: background-color .16s ease;
}
.llg-switch-knob {
    position: absolute; top: 3px; left: 3px;
    width: 14px; height: 14px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,.18); transition: transform .16s ease;
}
.llg-switch input:checked + .llg-switch-track { background: var(--llg-fill); }
.llg-switch input:checked + .llg-switch-track .llg-switch-knob { transform: translateX(16px); }
.llg-switch input:focus-visible + .llg-switch-track { outline: 2px solid var(--llg-fill); outline-offset: 2px; }
.llg-switch-txt { color: var(--llg-muted); font-size: 12px; }

/* ---------- buttons ---------- */
.llg-btn-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.llg-btn-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.llg-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; min-width: 0; min-height: 34px; padding: 6px 11px;
    border: 1px solid var(--llg-line); border-radius: var(--llg-radius-sm);
    background: var(--llg-soft); color: var(--llg-ink);
    font: inherit; font-size: 12.5px; line-height: 1.3; text-align: center;
    cursor: pointer; transition: border-color .14s ease, background-color .14s ease, transform .1s ease;
}
.llg-btn > span { min-width: 0; }
.llg-btn:hover { border-color: var(--llg-fill); }
.llg-btn:active { transform: translateY(1px); }
.llg-btn:focus-visible { outline: 2px solid var(--llg-fill); outline-offset: 2px; }
.llg-btn-primary {
    border-color: transparent;
    background: var(--primary, #2563eb);
    color: var(--text-on-accent, #fff);
}
.llg-btn-primary:hover { border-color: transparent; filter: brightness(1.03); }
.llg-btn-sm { min-height: 30px; padding: 4px 8px; font-size: 11.5px; }
.llg-btn-ico { width: 14px; height: 14px; flex: 0 0 auto; background: currentColor; -webkit-mask: var(--btn-ico) center / contain no-repeat; mask: var(--btn-ico) center / contain no-repeat; }
.llg-ico-wand { --btn-ico: var(--i-wand); }
.llg-ico-refresh { --btn-ico: var(--i-refresh); }
.llg-ico-reset { --btn-ico: var(--i-reset); }
.llg-ico-copy { --btn-ico: var(--i-copy); }
.llg-ico-file { --btn-ico: var(--i-file); }
.llg-ico-md { --btn-ico: var(--i-md); }
.llg-ico-code { --btn-ico: var(--i-code); }
.llg-ico-print { --btn-ico: var(--i-print); }
.llg-ico-image { --btn-ico: var(--i-image); }
.llg-ico-heart { --btn-ico: var(--i-heart); }
.llg-ico-read { --btn-ico: var(--i-read); }
.llg-ico-undo { --btn-ico: var(--i-undo); }
.llg-ico-redo { --btn-ico: var(--i-redo); }

.llg-config { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--llg-line); }
.llg-config-sum { cursor: pointer; color: var(--llg-muted); font-size: 11.5px; font-weight: 600; list-style: none; }
.llg-config-sum::-webkit-details-marker { display: none; }
.llg-config-sum::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: -2px; background: currentColor; -webkit-mask: var(--i-code) center / contain no-repeat; mask: var(--i-code) center / contain no-repeat; }
.llg-config[open] .llg-config-sum { margin-bottom: 6px; }
.llg-config-area { margin-top: 6px; min-height: 68px; }

/* ---------- preview actions ---------- */
.llg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 11px; }
.llg-actions .llg-btn { flex: 0 1 auto; }

.llg-paper-shell { position: relative; width: 100%; min-width: 0; }
.llg-paper {
    position: relative;
    width: 100%;
    max-width: 780px;
    min-height: 520px;
    margin: 0 auto;
    --paper-line: 31px;
    padding: 24px 44px 28px;
    border-radius: 8px;
    background-color: var(--paper-bg, #fffbf2);
    background-image:
        repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line) - 1px), var(--paper-rule, rgba(120,90,50,.12)) calc(var(--paper-line) - 1px) var(--paper-line));
    background-position: 0 30px;
    color: var(--paper-ink, #3b3021);
    box-shadow: 0 8px 30px rgba(15, 23, 42, .12), 0 1px 0 rgba(255,255,255,.8) inset;
    overflow: hidden;
    transition: background-color .18s ease, color .18s ease;
}
.llg-paper::before {
    content: "";
    position: absolute; inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 15% 0, rgba(255,255,255,.55), transparent 45%);
    opacity: .6;
}
.llg-paper::after {
    content: "";
    position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: var(--paper-edge, rgba(160,120,70,.35));
    opacity: .55;
}
.llg-paper-rose { --paper-bg: #FFF5F7; --paper-ink: #43252e; --paper-rule: rgba(180, 90, 120, .12); --paper-edge: rgba(190, 95, 130, .28); }
.llg-paper-sage { --paper-bg: #F4F8F2; --paper-ink: #27382c; --paper-rule: rgba(70, 120, 85, .11); --paper-edge: rgba(70, 120, 85, .25); }
.llg-paper-kraft { --paper-bg: #E8D9C0; --paper-ink: #3d2d1b; --paper-rule: rgba(90, 60, 30, .10); --paper-edge: rgba(90, 60, 30, .25); background-image: repeating-linear-gradient(115deg, rgba(255,255,255,.05) 0 1px, transparent 1px 4px), repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(90,60,30,.10) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px)); }
.llg-paper-midnight { --paper-bg: #1C2733; --paper-ink: #F3F6F9; --paper-rule: rgba(190, 210, 230, .13); --paper-edge: rgba(120, 170, 210, .45); background-image: repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(190,210,230,.10) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px)); }
.llg-paper-midnight .llg-dateline, .llg-paper-midnight .llg-sign, .llg-paper-midnight .llg-para-tools { color: rgba(243,246,249,.68); }
.llg-paper-midnight .llg-para-tools .llg-para-btn { border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.08); color: rgba(255,255,255,.72); }
.llg-paper-grid { --paper-bg: #FFFFFF; --paper-ink: #26323d; --paper-rule: rgba(70, 105, 130, .13); --paper-edge: rgba(70, 105, 130, .22); background-image: linear-gradient(var(--paper-rule) 1px, transparent 1px), linear-gradient(90deg, var(--paper-rule) 1px, transparent 1px); background-size: 31px 31px; }
.llg-paper-grid::before { background: none; }
.llg-paper-lavender { --paper-bg: #F7F2FF; --paper-ink: #33264f; --paper-rule: rgba(110, 80, 150, .12); --paper-edge: rgba(120, 90, 170, .28); }
.llg-paper-ocean { --paper-bg: #F0F7FB; --paper-ink: #173747; --paper-rule: rgba(40, 110, 140, .12); --paper-edge: rgba(40, 110, 140, .27); }
.llg-paper-peach { --paper-bg: #FFF4EE; --paper-ink: #47281f; --paper-rule: rgba(190, 100, 60, .11); --paper-edge: rgba(190, 100, 60, .26); }
.llg-paper-linen { --paper-bg: #FAF7F0; --paper-ink: #34302a; --paper-rule: rgba(120, 105, 85, .10); --paper-edge: rgba(120, 105, 85, .24); background-image: repeating-linear-gradient(115deg, rgba(160,145,120,.055) 0 1px, transparent 1px 4px), repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(120,105,85,.09) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px)); }
.llg-paper-botanical {
    --paper-bg: #FBF8EE; --paper-ink: #35402F; --paper-rule: rgba(95, 120, 80, .14); --paper-edge: rgba(125, 148, 104, .34);
    background-image:
        radial-gradient(ellipse 7px 3px at 12px 18px, rgba(95,125,75,.13) 0 60%, transparent 62%),
        radial-gradient(ellipse 3px 7px at 44px 46px, rgba(125,95,55,.10) 0 60%, transparent 62%),
        repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(95,120,80,.14) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px));
    background-size: 64px 64px, 64px 64px, auto;
    background-position: 0 0, 34px 18px, 0 30px;
}
.llg-paper-starry {
    --paper-bg: #151C30; --paper-ink: #F5F1E6; --paper-rule: rgba(218, 190, 120, .22); --paper-edge: rgba(201, 168, 92, .58);
    background-image:
        radial-gradient(circle at 8px 9px, rgba(255,228,168,.78) 0 1px, transparent 1.8px),
        radial-gradient(circle at 34px 39px, rgba(255,228,168,.50) 0 .8px, transparent 1.4px),
        repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(218,190,120,.22) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px));
    background-size: 46px 46px, 46px 46px, auto;
    background-position: 0 0, 22px 20px, 0 30px;
}
.llg-paper-starry .llg-dateline, .llg-paper-starry .llg-sign, .llg-paper-starry .llg-para-tools { color: rgba(245,241,230,.70); }
.llg-paper-starry .llg-para-tools .llg-para-btn { border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.08); color: rgba(255,255,255,.74); }
.llg-paper-starry .llg-envelope { border-color: rgba(218,190,120,.34); }
.llg-paper-parchment {
    --paper-bg: #F3E7CF; --paper-ink: #4A3521; --paper-rule: rgba(120, 80, 40, .15); --paper-edge: rgba(168, 129, 75, .38);
    background-image:
        repeating-linear-gradient(115deg, rgba(120,80,40,.045) 0 1px, transparent 1px 6px),
        radial-gradient(ellipse 120px 60px at 80% 12%, rgba(150,105,55,.06), transparent 70%),
        repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(120,80,40,.15) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px));
    background-size: auto, auto, auto;
    background-position: 0 0, 0 0, 0 30px;
}
.llg-paper-blossom {
    --paper-bg: #FFF0F3; --paper-ink: #4A2733; --paper-rule: rgba(190, 100, 130, .13); --paper-edge: rgba(210, 138, 160, .34);
    background-image:
        radial-gradient(ellipse 10px 4px at 16px 14px, rgba(205,115,145,.11) 0 60%, transparent 62%),
        radial-gradient(ellipse 4px 9px at 50px 50px, rgba(205,115,145,.09) 0 60%, transparent 62%),
        repeating-linear-gradient(to bottom, transparent 0 calc(var(--paper-line, 31px) - 1px), rgba(190,100,130,.13) calc(var(--paper-line, 31px) - 1px) var(--paper-line, 31px));
    background-size: 72px 72px, 72px 72px, auto;
    background-position: 0 0, 32px 24px, 0 30px;
}

.llg-font-serif .llg-letter { font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, Georgia, "Times New Roman", serif; }
.llg-font-sans .llg-letter { font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif; }
.llg-font-hand .llg-letter { font-family: "Kaiti SC", "KaiTi", "Segoe Script", "Bradley Hand", "Comic Sans MS", cursive; }

/* envelope header */
.llg-envelope {
    position: relative;
    display: flex; align-items: center; justify-content: space-between;
    min-height: 58px;
    margin: -10px -10px 25px;
    padding: 0 10px 8px;
    border-bottom: 1px dashed var(--paper-rule, rgba(120,90,50,.25));
    transition: opacity .15s ease;
}
.llg-no-envelope .llg-envelope { display: none; }
.llg-stamp {
    width: 44px; height: 50px;
    display: grid; place-items: center;
    border: 2px dashed var(--paper-ink, #3b3021);
    color: var(--paper-ink, #3b3021);
    font-size: 8px; letter-spacing: 1px; text-transform: uppercase;
    transform: rotate(-3deg);
    opacity: .8;
}
.llg-postmark {
    display: grid; place-items: center;
    width: 54px; height: 54px;
    border: 1px dashed var(--paper-rule, rgba(120,90,50,.35));
    border-radius: 50%;
    color: var(--paper-ink, #3b3021);
    font-size: 8px; line-height: 1.2;
    text-align: center;
    opacity: .68;
    transform: rotate(6deg);
}
.llg-envelope-line { position: absolute; left: 62px; right: 68px; top: 28px; border-top: 1px solid var(--paper-rule, rgba(120,90,50,.18)); }

/* letter text */
.llg-letter { position: relative; z-index: 1; }
.llg-dateline { margin: 0 0 31px; text-align: right; color: color-mix(in srgb, var(--paper-ink, #3b3021) 62%, transparent); font-size: 12px; line-height: 31px; letter-spacing: .2px; }
.llg-paras { display: block; }
.llg-para {
    position: relative;
    margin: 0;
    padding: 0 30px 0 0;
    font-size: 16px;
    line-height: 31px;
    text-align: justify;
    text-justify: inter-ideograph;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
.llg-para-addr { margin-bottom: 31px; }
.llg-para + .llg-para { text-indent: 2em; }
.llg-para .llg-para-tools {
    position: absolute;
    right: 0;
    top: 2px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transition: opacity .12s ease;
}
.llg-para:hover .llg-para-tools,
.llg-para:focus-within .llg-para-tools { opacity: 1; }
@media (hover: none) { .llg-para .llg-para-tools { opacity: .75; } }
.llg-para-tools .llg-para-btn {
    width: 24px; height: 24px;
    display: grid; place-items: center;
    padding: 0;
    border: 1px solid var(--paper-rule, rgba(120,90,50,.25));
    border-radius: 5px;
    background: color-mix(in srgb, var(--paper-bg, #fffbf2) 82%, transparent);
    color: color-mix(in srgb, var(--paper-ink, #3b3021) 66%, transparent);
    cursor: pointer;
}
.llg-para-tools .llg-para-btn:hover { border-color: var(--llg-fill); color: var(--llg-fill); }
.llg-para-tools .llg-para-btn:focus-visible { outline: 2px solid var(--llg-fill); outline-offset: 1px; opacity: 1; }
.llg-para-btn .llg-para-ico { width: 12px; height: 12px; background: currentColor; -webkit-mask: var(--btn-ico) center / contain no-repeat; mask: var(--btn-ico) center / contain no-repeat; }
.llg-para-lock { --btn-ico: var(--i-unlock); }
.llg-para-locked .llg-para-lock { --btn-ico: var(--i-lock); color: var(--llg-fill); }
.llg-para-locked { background: color-mix(in srgb, var(--llg-fill) 4%, transparent); border-radius: 4px; padding-left: 6px; margin-left: -6px; }
.llg-para-swap { --btn-ico: var(--i-swap); }
.llg-sign { margin: 31px 0 0; text-align: right; font-size: 16px; line-height: 31px; white-space: pre-wrap; }
.llg-sign .llg-sign-name { color: color-mix(in srgb, var(--paper-ink, #3b3021) 84%, transparent); }

.llg-paper-shell .llg-paper + .llg-paper { margin-top: 0; }

/* ---------- stats ---------- */
.llg-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin: 10px 0 0; }
.llg-stat { min-width: 0; padding: 7px 8px; border: 1px solid var(--llg-line); border-radius: var(--llg-radius-sm); background: var(--llg-soft); text-align: center; }
.llg-stat-v { display: block; font-size: 15px; font-weight: 700; line-height: 1.25; color: var(--llg-fill); font-variant-numeric: tabular-nums; white-space: nowrap; }
.llg-stat-l { display: block; margin-top: 1px; color: var(--llg-muted); font-size: 10.5px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- history ---------- */
.llg-history { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--llg-line); }
.llg-history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.llg-history-panel { margin-top: 8px; }
.llg-history-list { display: flex; flex-direction: column; gap: 5px; }
.llg-hist-item {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; gap: 8px;
    width: 100%; padding: 6px 8px;
    border: 1px solid var(--llg-line); border-radius: var(--llg-radius-sm);
    background: var(--llg-card); color: var(--llg-ink);
    font: inherit; text-align: left; cursor: pointer;
}
.llg-hist-item:hover { border-color: var(--llg-fill); }
.llg-hist-item:focus-visible { outline: 2px solid var(--llg-fill); outline-offset: 1px; }
.llg-hist-main { min-width: 0; }
.llg-hist-title { display: block; font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.llg-hist-meta { display: block; margin-top: 1px; color: var(--llg-muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.llg-hist-tag { padding: 2px 5px; border-radius: 4px; background: var(--llg-fill-soft); color: var(--llg-fill); font-size: 10px; white-space: nowrap; }
.llg-favs { margin-top: 9px; padding-top: 7px; border-top: 1px dashed var(--llg-line); }
.llg-favs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; color: var(--llg-muted); font-size: 10.5px; }
.llg-favs-count { min-width: 18px; padding: 1px 5px; border-radius: 4px; background: var(--llg-fill-soft); color: var(--llg-fill); text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- notes / toast ---------- */
.llg-note { margin: 10px 0 0; color: var(--llg-muted); font-size: 10.5px; line-height: 1.55; }
.llg-note-soft { margin-top: 3px; opacity: .78; }
.llg-toast { min-height: 17px; margin: 6px 0 0; color: var(--llg-fill); font-size: 11.5px; line-height: 1.45; }
.llg-toast-err { color: var(--danger, #dc2626); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .llg-grid { grid-template-columns: minmax(0, 1fr); }
    .llg-settings { order: 1; }
    .llg-preview { order: 2; grid-column: 1; align-self: start; position: static !important; width: 100% !important; left: auto !important; top: auto !important; z-index: auto; height: auto !important; }
    .llg-preview-ph { display: none !important; }
}
@media (max-width: 560px) {
    .llg-top { gap: 10px; }
    .llg-title { font-size: 18px; }
    .llg-tags { padding-top: 0; }
    .llg-card { padding: 13px; }
    .llg-fields { grid-template-columns: minmax(0, 1fr); }
    .llg-span-2 { grid-column: auto; }
    .llg-paper-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .llg-paper { --paper-line: 28px; min-height: 460px; padding: 26px 22px 28px; background-position: 0 27px; }
    .llg-dateline { margin-bottom: 28px; line-height: 28px; }
    .llg-para { padding-right: 26px; font-size: 15px; line-height: 28px; }
    .llg-para-addr { margin-bottom: 28px; }
    .llg-sign { margin-top: 28px; line-height: 28px; }
    .llg-envelope { margin: -4px -4px 20px; }
    .llg-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .llg-btn-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .llg-btn-row .llg-btn-primary { grid-column: 1 / -1; }
    .llg-actions .llg-btn { flex: 1 1 calc(50% - 6px); }
}

/* the print stage is a body-level clone: screen never sees it */
.llg-print-stage { display: none; }
.llg-print-stage, .llg-print-stage * { box-sizing: border-box; }

/* print: only the letter paper, including its full background and rules */
@media print {
    @page { size: A4; margin: 0; }
    html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; width: auto !important; height: auto !important; min-height: 0 !important; }
    /* Remove the host site chrome entirely. The stage is the only direct body child kept. */
    body > * { display: none !important; }
    #love-letter-generator-print-stage {
        display: block !important;
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 10mm 0 0 !important;
        left: auto !important;
        top: auto !important;
    }
    #love-letter-generator-print-stage .llg-paper {
        display: block !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        box-sizing: border-box;
        box-shadow: none !important;
        max-width: none !important;
        min-height: 287mm !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 24px 9mm 10mm !important;
        border-radius: 0 !important;
        overflow: hidden !important;
    }
    #love-letter-generator-print-stage .llg-para-tools { display: none !important; }
    #love-letter-generator-print-stage .llg-para { padding-right: 0; }
    #love-letter-generator-print-stage .llg-paper-shell { width: 100%; }
}

/* address line sits left like a real salutation */
.llg-para-addr { text-align: left; text-justify: auto; font-weight: 600; }
