/*
 * Structure only.
 *
 * Every colour, font, radius and rule in this file is a custom property
 * defined by a theme file (theme-laura.css / theme-frederik.css). There
 * are deliberately NO literal colours or font-families below this
 * comment - that is what keeps the two identities honest and makes a
 * third one a single new file rather than an edit of every page.
 */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--body-size);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* The decorative page wash each theme paints behind everything. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: var(--page-wash, none);
    opacity: var(--page-wash-opacity, 1);
}

h1, h2, h3 {
    font-family: var(--font-head);
    font-weight: var(--head-weight);
    letter-spacing: var(--head-spacing);
    text-transform: var(--head-transform);
    color: var(--ink);
    line-height: 1.2;
    margin: 0 0 var(--space-3);
}

h1 { font-size: var(--h1-size); }
h2 { font-size: var(--h2-size); }
h3 { font-size: var(--h3-size); }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }

p { margin: 0 0 var(--space-3); }

hr {
    border: 0;
    border-top: var(--rule);
    margin: var(--space-4) 0;
}

/* ------------------------------------------------------------------ */
/* Admin chrome                                                        */
/* ------------------------------------------------------------------ */

.app-shell { max-width: var(--shell-width); margin: 0 auto; padding: 0 var(--space-3); }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-4) 0 var(--space-3);
    border-bottom: var(--rule);
    margin-bottom: var(--space-4);
}

.brand {
    font-family: var(--font-head);
    font-size: var(--brand-size);
    font-weight: var(--head-weight);
    letter-spacing: var(--brand-spacing);
    text-transform: var(--head-transform);
    color: var(--ink);
    text-decoration: none;
}
.brand .accent { color: var(--accent); }

.topbar nav { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.topbar nav a {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.active { color: var(--ink); border-bottom-color: var(--accent); }
.topbar nav a.muted { color: var(--ink-faint); }

.main { padding-bottom: var(--space-6); }

/* ------------------------------------------------------------------ */
/* Cards, sections                                                     */
/* ------------------------------------------------------------------ */

.card {
    background: var(--surface);
    border: var(--card-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}
.card-head h2, .card-head h3 { margin: 0; }

.section-label {
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-faint);
    margin-bottom: var(--space-2);
}

.muted { color: var(--ink-faint); }
.small { font-size: var(--small-size); }
.stack > * + * { margin-top: var(--space-3); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.row-end { margin-left: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--space-3); }

.empty {
    text-align: center;
    padding: var(--space-5) var(--space-3);
    color: var(--ink-faint);
}

/* ------------------------------------------------------------------ */
/* Forms                                                               */
/* ------------------------------------------------------------------ */

label, .field-label {
    display: block;
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-soft);
    margin-bottom: var(--space-1);
}

input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=date], input[type=datetime-local], input[type=number], input[type=url],
select, textarea {
    width: 100%;
    padding: 11px 12px;
    background: var(--input-bg);
    border: var(--input-border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 1rem;
}
textarea { min-height: 110px; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.field { margin-bottom: var(--space-3); }
.field-help { font-size: var(--small-size); color: var(--ink-faint); margin-top: var(--space-1); }
.field-error { font-size: var(--small-size); color: var(--danger-fg); margin-top: var(--space-1); }

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: normal;
    font-size: var(--body-size);
    color: var(--ink);
    margin: 0 var(--space-3) var(--space-2) 0;
}
.check input { width: auto; }

fieldset { border: 0; padding: 0; margin: 0 0 var(--space-3); }

details.collapsible summary {
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-soft);
    padding: var(--space-2) 0;
}
details.collapsible[open] summary { margin-bottom: var(--space-2); }

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
    display: inline-block;
    background: var(--accent);
    color: var(--accent-ink);
    border: var(--btn-border);
    border-radius: var(--btn-radius);
    padding: 11px 20px;
    font-family: var(--font-ui);
    font-size: var(--label-size);
    font-weight: 600;
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    text-decoration: none;
    cursor: pointer;
    transition: filter .15s ease;
}
.btn:hover { filter: brightness(1.08); color: var(--accent-ink); }

.btn-quiet {
    background: transparent;
    color: var(--ink-soft);
    border: var(--input-border);
}
.btn-quiet:hover { color: var(--ink); }

.btn-danger { background: var(--danger-bg); color: var(--danger-fg); border: 0; }

.btn-small { padding: 6px 12px; font-size: var(--small-size); }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* ------------------------------------------------------------------ */
/* Alerts and badges                                                   */
/* ------------------------------------------------------------------ */

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-3);
    font-size: var(--small-size);
}
.alert.ok { background: var(--ok-bg); color: var(--ok-fg); }
.alert.error { background: var(--danger-bg); color: var(--danger-fg); }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: var(--badge-radius);
    font-family: var(--font-ui);
    font-size: var(--tiny-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    background: var(--badge-bg);
    color: var(--badge-fg);
    white-space: nowrap;
}
.badge.r-yes { background: var(--ok-bg); color: var(--ok-fg); }
.badge.r-no { background: var(--danger-bg); color: var(--danger-fg); }
.badge.r-maybe { background: var(--warn-bg); color: var(--warn-fg); }
.badge.r-none { background: var(--badge-bg); color: var(--ink-faint); }

/* ------------------------------------------------------------------ */
/* Tables                                                              */
/* ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: var(--rule);
    vertical-align: top;
}
th {
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-faint);
    font-weight: 600;
    white-space: nowrap;
}
tbody tr:hover { background: var(--row-hover); }
td.nowrap, th.nowrap { white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ */
/* Dashboard event rows                                                */
/* ------------------------------------------------------------------ */

.event-item { display: block; padding: var(--space-3) 0; border-bottom: var(--rule); text-decoration: none; color: inherit; }
.event-item:last-child { border-bottom: 0; }
.event-item:hover .event-title { color: var(--accent); }
.event-title { font-family: var(--font-head); font-size: var(--h3-size); font-weight: var(--head-weight); letter-spacing: var(--head-spacing); }
.event-when { font-size: var(--small-size); color: var(--ink-faint); margin-bottom: var(--space-2); }
.event-status { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; font-size: var(--small-size); }

.meter { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--badge-bg); min-width: 140px; flex: 1; }
.meter span { display: block; height: 100%; }
.meter .m-yes { background: var(--ok-fg); }
.meter .m-maybe { background: var(--warn-fg); }
.meter .m-no { background: var(--danger-fg); }

/* ------------------------------------------------------------------ */
/* Guest invitation page                                               */
/* ------------------------------------------------------------------ */

body.guest {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-4) var(--space-3);
}

.invite {
    width: 100%;
    max-width: var(--invite-width);
    background: var(--invite-surface);
    border: var(--invite-border);
    border-radius: var(--radius);
    box-shadow: var(--invite-shadow);
    padding: var(--invite-padding);
    position: relative;
    overflow: hidden;
}

/* Decorative frame/ornament layer - each theme fills these in. */
.invite::before {
    content: "";
    position: absolute;
    inset: var(--invite-frame-inset, 10px);
    border: var(--invite-frame, 0);
    border-radius: var(--invite-frame-radius, 0);
    pointer-events: none;
}

.invite-inner { position: relative; }

.invite-eyebrow {
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--eyebrow-spacing);
    text-transform: var(--label-transform);
    color: var(--accent);
    text-align: var(--invite-align);
    margin-bottom: var(--space-3);
}

.invite h1 {
    font-family: var(--font-display);
    font-size: var(--invite-title-size);
    font-weight: var(--display-weight);
    letter-spacing: var(--display-spacing);
    text-transform: var(--display-transform);
    text-align: var(--invite-align);
    margin-bottom: var(--space-3);
}

.invite-ornament { text-align: var(--invite-align); margin: var(--space-3) 0 var(--space-4); color: var(--accent); }
.invite-ornament svg { display: inline-block; }

.invite-details { margin: var(--space-4) 0; }
.invite-detail { margin-bottom: var(--space-3); text-align: var(--invite-align); }
.invite-detail .k {
    font-family: var(--font-ui);
    font-size: var(--tiny-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-faint);
    display: block;
    margin-bottom: 2px;
}
.invite-detail .v { font-size: var(--invite-detail-size); }

.invite-description { text-align: var(--invite-align); white-space: pre-wrap; }

.invite form { margin-top: var(--space-4); }

/* The three answer buttons */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-3); }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span {
    display: block;
    text-align: center;
    padding: 14px 10px;
    border: var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.choice input:checked + span {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}
.choice input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.invite .btn { width: 100%; padding: 14px; }

.invite-note {
    margin-top: var(--space-3);
    font-size: var(--small-size);
    color: var(--ink-faint);
    text-align: var(--invite-align);
}

.invite-answer {
    margin: var(--space-3) 0;
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--badge-bg);
    text-align: var(--invite-align);
}

/* ------------------------------------------------------------------ */
/* Copy-to-clipboard button state                                      */
/* ------------------------------------------------------------------ */

.copy-btn[data-copied="1"] { background: var(--ok-fg); color: var(--paper); }

/* ------------------------------------------------------------------ */
/* Import preview                                                      */
/* ------------------------------------------------------------------ */

tr.row-skip { opacity: .55; }
tr.row-error td { background: var(--danger-bg); }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 640px) {
    .topbar { flex-direction: column; align-items: flex-start; }
    .topbar nav { gap: var(--space-2) var(--space-3); }
    .card { padding: var(--space-3); }
    .invite { padding: var(--invite-padding-mobile); }
    /* Themes may set a smaller display size for narrow screens; the
       fallback keeps the desktop value if one does not. */
    .invite h1 { font-size: var(--invite-title-size-mobile, var(--invite-title-size)); }
    th, td { padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* ------------------------------------------------------------------ */
/* Kitchen sheet                                                       */
/* ------------------------------------------------------------------ */

.sheet-headline {
    font-size: 1.35rem;
    margin: var(--space-3) 0 var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: var(--rule);
}
.sheet-headline strong { font-size: 2.2rem; }

.sheet-section { margin-bottom: var(--space-4); }
.sheet-section h2 { font-size: var(--h3-size); margin-bottom: var(--space-2); }

.sheet-list { margin: 0; padding-left: 1.2em; }
.sheet-list li { margin-bottom: 6px; }

.sheet-printed { margin-top: var(--space-4); }

@media print {
    /* Everything that is a control rather than information. */
    .topbar, .btn, .btn-row, .no-print, .guest-tools { display: none; }

    body { background: none; }
    body::before { display: none; }

    /* A printed page has no viewport: let the card be a plain sheet. */
    .app-shell { max-width: none; padding: 0; }
    .card {
        border: 0;
        box-shadow: none;
        padding: 0;
        margin: 0;
        background: none;
    }

    .sheet-section { page-break-inside: avoid; }
    .sheet-headline strong { font-size: 2rem; }

    /*
     * The only literal HUE in this file, and a deliberate exception to
     * its token-only rule: this is not a theme decision but a physical
     * one. Sort slips is a dark theme, and printing it as designed would
     * put pale text on white paper - i.e. nothing at all.
     *
     * (The envelope also uses a few rgba(0,0,0,a) values. Those are
     * shading, not colour: a shadow is black everywhere, and darkening
     * is correct over cream and over midnight alike. A theme that wanted
     * a coloured shadow sets --envelope-shadow, which is a token.)
     */
    .sheet, .sheet * { color: #000 !important; }
}

/* Narrow single-purpose pages (login, password setup). */
.auth-narrow { max-width: 420px; margin: var(--space-4) auto 0; }

/* The hidden attribute must win over the display rules above it. */
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Inline admin edit (guest list "Ret svar")                           */
/* ------------------------------------------------------------------ */

.row-edit { margin-top: var(--space-2); }

.row-edit summary {
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: var(--tiny-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-faint);
}
.row-edit summary:hover { color: var(--accent); }
.row-edit[open] summary { margin-bottom: var(--space-2); }

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}
/* The two controls sit side by side rather than each filling the row. */
.inline-form select { width: auto; min-width: 108px; padding: 6px 8px; }
.inline-form input[type=number] { width: 74px; padding: 6px 8px; }

.history { margin: 0; padding-left: 1.1em; }
.history li { margin-bottom: 4px; }

/* Visible to screen readers only - labels for the compact inline form. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Date + 24-hour time, side by side. The time is a <select> we render
   ourselves rather than a datetime-local, whose popup would follow the
   browser's locale and show AM/PM on an English system. */
.datetime-row { display: flex; gap: var(--space-2); align-items: center; }
.datetime-row input[type=date] { flex: 1 1 auto; min-width: 0; }
.datetime-row select { width: auto; flex: 0 0 auto; min-width: 92px; }

/* ------------------------------------------------------------------ */
/* Guest self-service: "are these details still right?"                */
/* ------------------------------------------------------------------ */

.details-block {
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: var(--rule);
    text-align: var(--invite-align);
}

.details-person { margin-bottom: var(--space-3); }

.details-confirm { margin: var(--space-3) 0 var(--space-2); }
.details-confirm .btn { width: auto; padding: 10px 22px; }

.details-edit summary {
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: var(--small-size);
    color: var(--ink-faint);
    padding: var(--space-2) 0;
}
.details-edit summary:hover { color: var(--accent); }

/* The edit form is left-aligned even in the centred themes: labelled
   fields are unreadable centred. */
.details-edit form { text-align: left; margin-top: var(--space-3); }

.details-fields {
    border: 0;
    padding: 0;
    margin: 0 0 var(--space-4);
}
.details-fields legend {
    font-family: var(--font-ui);
    font-size: var(--label-size);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-soft);
    padding: 0 0 var(--space-2);
}

/* ------------------------------------------------------------------ */
/* Invitation image, rich text, script title                           */
/* ------------------------------------------------------------------ */

.invite-image {
    margin: var(--space-4) 0 var(--space-3);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.invite-image img {
    display: block;
    width: 100%;
    height: auto;
}

/* The description is rendered HTML from RichText, not a single string. */
.invite-description p { margin: 0 0 var(--space-3); }
.invite-description p:last-child { margin-bottom: 0; }
.invite-description u { text-decoration-thickness: 1px; text-underline-offset: 2px; }

.richtext-preview {
    margin-top: var(--space-2);
    padding: var(--space-3);
    border: var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: var(--small-size);
    min-height: 2.4em;
}
.richtext-preview:empty { display: none; }
.richtext-preview p { margin: 0 0 var(--space-2); }
.richtext-preview p:last-child { margin-bottom: 0; }

.image-current { margin-bottom: var(--space-2); }
.image-current img {
    display: block;
    max-width: 260px;
    height: auto;
    border-radius: var(--radius-sm);
    border: var(--card-border);
    margin-bottom: var(--space-2);
}

/* The one face declared outside a theme file: it is an opt-in per-event
   title style rather than part of any single design. */
@font-face {
    font-family: "Great Vibes";
    src: url("../fonts/great-vibes-400.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* Opt-in script face for the event title. Falls back to the theme's own
   display face if the woff2 is missing, rather than to something random. */
body.title-script .invite h1 {
    font-family: "Great Vibes", var(--font-display);
    font-weight: 400;
    font-style: normal;
    letter-spacing: 0;
    text-transform: none;
    font-size: calc(var(--invite-title-size) * 1.35);
    line-height: 1.15;
}

/* ------------------------------------------------------------------ */
/* The envelope                                                        */
/* ------------------------------------------------------------------ */

/*
 * Five beats, ~3.5s:
 *
 *   0.00  the envelope arrives, slightly turned, and settles
 *   0.70  the wax seal cracks in two and the halves fall
 *   1.20  the flap folds back over the top edge
 *   2.00  the letter rises out of the pocket
 *   2.70  everything drifts up and fades
 *
 * Drawn entirely from --envelope-* tokens, which every theme defines, so
 * an envelope belongs to its design rather than being one shape in five
 * colours. Nothing below is a literal colour except neutral shadows.
 *
 * The invitation is fully rendered underneath the whole time: this is
 * decoration over a page that is already complete.
 */
.envelope {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    background: var(--paper);
    animation: envelope-fade .7s ease 2.7s forwards;
}

.envelope::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--page-wash, none);
    opacity: var(--page-wash-opacity, 1);
    pointer-events: none;
}

/*
 * Two elements, deliberately: the scene ANIMATES (transform and opacity),
 * the stage HOLDS THE 3D CONTEXT and never animates at all.
 *
 * They cannot be the same element. An element that animates opacity gets
 * a stacking context, and a stacking context flattens transform-style:
 * preserve-3d - so the flap would have no depth to fold back into and
 * would paint flat on top of the envelope instead of going behind it.
 */
.envelope-scene {
    position: relative;
    width: min(78vw, 380px);
    aspect-ratio: 3 / 2;
    animation:
        envelope-arrive .75s cubic-bezier(.2, .9, .25, 1) both,
        envelope-depart .9s cubic-bezier(.4, 0, .7, .3) 2.7s forwards;
}

.envelope-stage {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    perspective: 900px;
}

/* Pocket back, and the lining glimpsed once the flap lifts. */
.envelope-back {
    position: absolute;
    inset: 0;
    background: var(--envelope-lining, var(--surface));
    border: var(--envelope-border, 1px solid var(--accent));
    border-radius: var(--envelope-radius, var(--radius-sm));
    box-shadow: var(--envelope-shadow, 0 22px 55px -32px rgba(0, 0, 0, .55));
}

/*
 * The letter carries the real title and date, so the reveal lands on the
 * thing it was hiding rather than on three decorative lines.
 */
.envelope-letter {
    position: absolute;
    left: 7%;
    right: 7%;
    bottom: 8%;
    height: 86%;
    padding: 13% 9% 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .4em;
    text-align: center;
    background: var(--envelope-letter-paper, var(--surface));
    border-radius: 2px;
    box-shadow: 0 -6px 18px -12px rgba(0, 0, 0, .45);
    transform: translateY(6%);
    animation: envelope-letter-rise 1.05s cubic-bezier(.22, 1.1, .3, 1) 2s both;
    overflow: hidden;
}

.envelope-letter-title {
    font-family: var(--font-display);
    font-weight: var(--display-weight);
    letter-spacing: var(--display-spacing);
    text-transform: var(--display-transform);
    color: var(--ink);
    font-size: clamp(1rem, 4.6vw, 1.5rem);
    line-height: 1.15;
    /* Two lines at most: the letter is a glimpse, not the invitation. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

body.title-script .envelope-letter-title {
    font-family: "Great Vibes", var(--font-display);
    font-size: clamp(1.2rem, 5.4vw, 1.9rem);
}

.envelope-letter-date {
    font-family: var(--font-ui);
    font-size: clamp(.6rem, 2.4vw, .75rem);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--ink-faint);
}

.envelope-letter-rule {
    width: 34%;
    height: 1px;
    background: var(--envelope-seal, var(--accent));
    opacity: .5;
    margin-top: .2em;
}

/*
 * Pocket front, so the letter slides out from behind something. The
 * inset shadow at the mouth is what makes it read as a pocket rather
 * than a rectangle sitting in front of the letter.
 */
.envelope-front {
    position: absolute;
    inset: 0;
    background: var(--envelope-paper, var(--surface));
    border: var(--envelope-border, 1px solid var(--accent));
    border-radius: var(--envelope-radius, var(--radius-sm));
    clip-path: polygon(0 32%, 50% 78%, 100% 32%, 100% 100%, 0 100%);
    box-shadow: inset 0 14px 18px -14px rgba(0, 0, 0, .55);
    z-index: 3;
}

/* Paper tooth, if the theme supplies one. */
.envelope-front::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--envelope-texture, none);
    opacity: var(--envelope-texture-opacity, 0);
    pointer-events: none;
}

/*
 * A shadow that sweeps down the face as the flap lifts. A moving
 * gradient on a pseudo-element, never an animated box-shadow, so the
 * compositor can handle it.
 */
.envelope-front::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    /* Transparent at BOTH ends: a travelling band of shade. With a hard
       edge at the top it stops being a sweep and becomes a grey slab
       covering everything it has already passed. */
    background: linear-gradient(180deg,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, .11) 50%,
        rgba(0, 0, 0, 0) 100%);
    transform: translateY(-100%);
    animation: envelope-sweep .9s ease 1.25s forwards;
    pointer-events: none;
}

/*
 * The flap: a gradient rather than a flat fill, so the fold catches
 * light along its top edge and reads as a fold.
 */
.envelope-flap {
    position: absolute;
    inset: -1px -1px auto -1px;
    height: 64%;
    transform-origin: top center;
    transform: rotateX(0deg);
    transform-style: preserve-3d;
    animation: envelope-open .85s cubic-bezier(.5, 0, .3, 1) 1.2s forwards;
}

/*
 * A flap has two sides. Rotating one panel past 90 degrees with
 * backface-visibility: hidden makes it VANISH at the halfway point rather
 * than open - the bug this replaces. So: paper on the outside, lining on
 * the inside, each hiding its own back, and the fold shows the lining as
 * a real one does.
 *
 * No z-index anywhere here. Once the stage keeps its 3D context, depth
 * decides what covers what, and the folded flap goes behind the envelope
 * because that is where it physically is.
 */
.flap-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
}

.flap-outside {
    background: var(--envelope-flap, linear-gradient(var(--accent), var(--accent)));
    clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/*
 * The inside face is pre-flipped so it faces backwards, and rotateX(180)
 * MIRRORS IT VERTICALLY. So its triangle has to be mirrored too, or the
 * two faces do not share a silhouette: clipped apex-down like the front,
 * it flips to apex-up and the mismatched half juts out above the
 * envelope as a detached floating triangle. Mirrored here, the two faces
 * coincide exactly and the flap reads as one piece of paper.
 */
.flap-inside {
    background: var(--envelope-lining, var(--surface));
    transform: rotateX(180deg);
    clip-path: polygon(0 100%, 100% 100%, 50% 0);
}

.envelope-seal {
    position: absolute;
    top: 54%;
    left: 50%;
    width: 58px;
    height: 58px;
    margin: -29px 0 0 -29px;
    z-index: 5;
    pointer-events: none;
}

/* The two halves break apart along the line between the L and the F. */
.envelope-seal svg { width: 100%; height: 100%; overflow: visible; }

/*
 * The wax colour arrives through `color`, so the blob can use plain
 * currentColor in its attribute; the monogram takes its fill from CSS.
 * Both avoid var() inside an SVG presentation attribute, which Safari
 * ignores - there it would fall back to black wax with white letters.
 */
.envelope-seal { color: var(--envelope-seal, var(--accent)); }
.envelope-seal .seal-monogram {
    fill: var(--envelope-seal-ink, var(--surface));
    font-family: var(--font-display);
}
.envelope-seal .seal-half { transform-origin: 50% 50%; }
.envelope-seal .seal-left {
    animation: envelope-seal-left .75s cubic-bezier(.5, -0.3, .7, 1) .7s forwards;
}
.envelope-seal .seal-right {
    animation: envelope-seal-right .75s cubic-bezier(.5, -0.3, .7, 1) .74s forwards;
}

.envelope-skip {
    position: absolute;
    bottom: 8vh;
    left: 0;
    right: 0;
    text-align: center;
    font-family: var(--font-ui);
    font-size: var(--small-size);
    letter-spacing: var(--label-spacing);
    color: var(--ink-faint);
    opacity: 0;
    animation: envelope-skip-in .4s ease 1.2s forwards;
}

@keyframes envelope-arrive {
    from { transform: translateY(14%) rotate(-4deg) scale(.9); opacity: 0; }
    to   { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
}

@keyframes envelope-seal-left {
    30%  { transform: translate(-2px, -2px) rotate(-6deg); }
    to   { transform: translate(-26px, 96px) rotate(-52deg); opacity: 0; }
}

@keyframes envelope-seal-right {
    30%  { transform: translate(2px, -2px) rotate(5deg); }
    to   { transform: translate(24px, 104px) rotate(44deg); opacity: 0; }
}

@keyframes envelope-open {
    to { transform: rotateX(-168deg); }
}

@keyframes envelope-sweep {
    from { transform: translateY(-100%); opacity: 0; }
    25%  { opacity: 1; }
    to   { transform: translateY(100%); opacity: 0; }
}

/* A touch of overshoot, so the letter settles rather than stopping dead. */
@keyframes envelope-letter-rise {
    to { transform: translateY(-48%) rotate(-.6deg); }
}

@keyframes envelope-depart {
    to { transform: translateY(-16vh) scale(1.06); opacity: 0; }
}

@keyframes envelope-fade {
    to { opacity: 0; visibility: hidden; }
}

@keyframes envelope-skip-in {
    to { opacity: 1; }
}

/* Someone who has asked their system for less motion gets none of it:
   the overlay is simply never shown. */
@media (prefers-reduced-motion: reduce) {
    .envelope { display: none; }
}

/* A short screen has no room for the skip hint to sit clear of the card. */
@media (max-height: 520px) {
    .envelope-skip { display: none; }
}

/* The calendar link sits quietly under the details - useful, not a
   competing call to action next to the RSVP buttons. */
.invite-calendar {
    text-align: var(--invite-align);
    font-size: var(--small-size);
    margin: calc(var(--space-3) * -1) 0 var(--space-4);
}
