/*
 * Public pages: the write flow (/) and the wall (/soovid).
 * Measurements come from the Figma frames, which are 402 × 874 px phones.
 */

@font-face {
    font-family: 'Caveat';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/caveat-700-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Caveat';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/caveat-700-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Caveat';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/caveat-700-cyrillic.woff2') format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
    --green-light: #66a559;
    --green: #4e8443;
    --green-dark: #35622d;
    --yellow: #fcf246;
    --navy: #0f275c;
    --lime: #c9f373;
    --paper: #faf6eb;
    --paper-back: #d7d2bf;
    --ink: #204fa4;

    --font: 'Lidl Font Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    --hand: 'Caveat', 'Comic Sans MS', cursive;

    --frame: 402px;

    /* Text sizes. At 440 px wide and up they are the design's; below that
       (so on every phone) they shrink in a straight line to the minimum at
       320 px and stop there. Each one is
       min + (max - min) * (100vw - 320px) / 120px, written as a rem part
       plus a vw part. Because of the rem parts, text still follows the
       visitor's zoom and font-size settings. */
    --text-title: clamp(1.4375rem, -0.0625rem + 7.5vw, 2rem);         /* 23 → 32 px */
    --text-lead: clamp(1.125rem, 0.125rem + 5vw, 1.5rem);             /* 18 → 24 px */
    /* Buttons also shrink with the screen's height (the smaller size
       wins), so a short phone like the iPhone SE gets a compact button:
       23.25 px at 874 px tall down to 17.5 px at 667 px. */
    --text-button: min(
        clamp(1.125rem, 0.25rem + 4.375vw, 1.453125rem),              /* 18 → 23.25 px by width */
        clamp(1.09375rem, -0.0643rem + 2.7778svh, 1.453125rem)        /* 17.5 → 23.25 px by height */
    );
    --text-empty: clamp(1.0625rem, 0.2292rem + 4.1667vw, 1.375rem);   /* 17 → 22 px */
    --text-link: clamp(0.875rem, 0.375rem + 2.5vw, 1.0625rem);        /* 14 → 17 px */
    --text-status: clamp(0.84375rem, 0.4271rem + 2.0833vw, 1rem);     /* 13.5 → 16 px */

    /* The buttons' height shrinks the same way, by width and by height. */
    --button-height: min(
        clamp(3rem, 1.6667rem + 6.6667vw, 3.5rem),                     /* 48 → 56 px by width */
        clamp(2.75rem, 0.8625rem + 4.83svh, 3.5rem)                    /* 44 → 56 px by height */
    );
}

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

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

body {
    margin: 0;
    min-height: 100svh;
    color: #fff;
    font-family: var(--font);
    font-weight: 600;
    background-color: var(--green-dark);
    background-image: radial-gradient(closest-side, var(--green-light) 0%, var(--green) 50%, var(--green-dark) 100%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

img {
    display: block;
}

button {
    font: inherit;
    color: inherit;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 3px solid var(--yellow);
    outline-offset: 3px;
}

/* ---------- Shared pieces ---------- */

/* Falling snow on the wall (snow.js): fixed to the window, behind
   everything on the page, which sits on a layer above it. */
.snow {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.screen,
.wall {
    z-index: 1;
}

.screen {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: var(--frame);
    min-height: 100svh;
    margin: 0 auto;
    overflow-x: clip;
    animation: screen-in 0.5s ease backwards;
    /* For the trees' side fade (100cqw is this column's width). */
    container-type: inline-size;
}

/* Runs each time a screen is shown (it restarts when [hidden] comes off). */
@keyframes screen-in {
    from {
        opacity: 0;
    }
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(100% - 46px);
    max-width: 357px;
    height: var(--button-height);
    padding: 0 24px;
    border: 0;
    border-radius: 108px;
    background: var(--yellow);
    color: var(--navy);
    font-size: var(--text-button);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.btn:hover {
    filter: brightness(1.04);
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    cursor: progress;
    opacity: 0.8;
}

.title {
    margin: 0;
    font-size: var(--text-title);
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
}

.lead {
    position: relative;
    /* 287 px at the design's 24 px, narrower as the text shrinks, so the
       lines break where they do in the design. */
    width: 11.96em;
    max-width: calc(100% - 32px);
    margin: 0;
    font-size: var(--text-lead);
    line-height: 1.2;
    text-align: center;
}

/* Focused by script on the thank-you screen, for screen readers only. */
.lead:focus {
    outline: none;
}

.lead p {
    margin: 0;
}

.lead p + p {
    margin-top: 11px;
}

.lead .highlight {
    color: var(--lime);
}

.text-link {
    color: #fff;
    font-size: var(--text-link);
    text-underline-offset: 3px;
}

/* The logos are 85% of the design's size (186 × 31 and 59 × 59). */
.partners {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 25px;
    /* Clear of the iPhone home bar, but otherwise close to the bottom. */
    padding-bottom: max(30px, env(safe-area-inset-bottom) + 12px);
}

.partners .sos {
    width: 158px;
    height: 26.35px;
    margin-top: 8.5px;
}

.partners .lidl {
    width: 50px;
    height: 50px;
}

.privacy {
    margin-top: 16px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 400;
}

/* ---------- The trees (intro and thank-you) ---------- */

/* The tree shrinks on short phones so the text and button stay on screen;
   the box keeps the design's proportions. */
.hero {
    /* How far the sides fade: nothing while the tree is as wide as the
       screen (as in the design), and as much as it is narrower once a short
       screen shrinks it, so its picture never shows as a box. */
    --edge: 0px;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
    -webkit-mask-image: var(--fade), linear-gradient(to right, transparent, #000 var(--edge), #000 calc(100% - var(--edge)), transparent);
    mask-image: var(--fade), linear-gradient(to right, transparent, #000 var(--edge), #000 calc(100% - var(--edge)), transparent);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

@supports (width: 1cqw) {
    .hero {
        --edge: max(0px, (100cqw - 100%) * 0.5);
    }
}

.hero img {
    position: absolute;
    max-width: none;
    height: auto;
    pointer-events: none;
    user-select: none;
}

/* Intro: the film's first frame, the screen's full width. The box is the
   design's 568 px tall (less on short screens, so the text and button stay
   in view) and the tree's foot sits 86% down it. The whole tree is in view,
   as in the design. first.webp is the film's whole width (3840 px); the
   2080 px middle the other frames use spans 101% of the box, where the
   tree fills the screen with a few pixels to spare (it spans 3.8–96.9% of
   that middle, 28–93% of the height). Above it the film's own background
   fades into the page. */
.hero--fallen {
    --h: min(141.3vw, 568px, max(340px, 100svh - 306px));
    /* At least --h tall, and on a taller screen it grows to fill it; the
       picture stays on the box's bottom edge, right above the text. */
    flex: 1 0 auto;
    width: 100%;
    min-height: var(--h);
    --fade: linear-gradient(to bottom, transparent, #000 calc(var(--h) * 0.18), #000 calc(100% - var(--h) * 0.2), transparent);
    container-type: inline-size;
}

.hero--fallen img {
    /* The width the tree is sized for: the screen's, but no more than the
       height allows (1.18 × --h), so on a wide screen (a tablet) the whole
       tree still fits above the text. Phones are never that wide. */
    --w: min(100cqw, var(--h) * 1.18);
    left: calc(50% - var(--w) * 0.9586);
    bottom: calc(var(--h) * 0.14 - var(--w) * 0.0726);
    width: calc(var(--w) * 1.8646);
    /* On tall screens the frame is shorter than the box: its own edges
       melt into the page too (the sides only show on wide screens). */
    -webkit-mask-image:
        linear-gradient(to bottom, transparent, #000 14%, #000 88%, transparent),
        linear-gradient(to right, transparent, #000 10%, #000 90%, transparent);
    mask-image:
        linear-gradient(to bottom, transparent, #000 14%, #000 88%, transparent),
        linear-gradient(to right, transparent, #000 10%, #000 90%, transparent);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
}

/* Thank-you: visible area 400 × 696 starting 18 px above the top. */
/* Always the screen's full width. The height is the design's (696 px at
   400 px wide), less on short screens so the text stays in view; a wider
   box just shows more of the film's sides. */
.screen.thanks {
    --h: min(174vw, 696px, max(380px, 100svh - 178px));
}

.hero--upright {
    /* At least --h tall, growing into a taller screen like the intro's. */
    flex: 1 0 auto;
    width: 100%;
    min-height: var(--h);
    /* Fades out under the tree's foot (lower than mask-tree-upright.svg,
       because the tree is drawn bigger and lower than in the design). */
    --fade: linear-gradient(to bottom, #000 calc(100% - var(--h) * 0.18), transparent calc(100% - var(--h) * 0.05));
}

/* The tree film: the part of the film the tree ever touches (2080 × 2160
   of it, see scripts/tree-frames.sh). write.js moves it in from further back, around
   the foot of the tree, while it plays. */
.tree-film {
    position: absolute;
    /* Sized from the box's height, so the tree is the same however wide
       the box is: 12% bigger than the design's tree, its foot centred and
       85% down, which leaves the tip about 6% of the box below the top. */
    left: calc(50% - var(--h) * 0.4963);
    bottom: calc(var(--h) * 0.0485);
    width: calc(var(--h) * 1.0607);
    height: calc(var(--h) * 1.1015);
    transform-origin: 43.4% 90.6%;
    transition: opacity 0.6s ease;
    /* Its edges fade into the page: the top on tall screens, the sides on
       screens wider than the film (a tablet, a narrow desktop window). On
       other screens they're out of view anyway. The standing tree is in
       the middle 30–70%, clear of the fades. */
    -webkit-mask-image:
        linear-gradient(to bottom, transparent, #000 10%),
        linear-gradient(to right, transparent, #000 14%, #000 86%, transparent);
    mask-image:
        linear-gradient(to bottom, transparent, #000 10%),
        linear-gradient(to right, transparent, #000 14%, #000 86%, transparent);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
}

.tree-film img,
.tree-film canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* The canvas covers the picture while the film plays, then fades away to
   leave the sharp last frame. */
.tree-film canvas {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.tree-film.is-playing canvas {
    opacity: 1;
    transition: none;
}

.tree-film.is-playing img {
    visibility: hidden;
}

/* ---------- 01 Intro ---------- */

.intro .lead {
    margin-top: -42px;
}

/* The gap between the text and the button (intro) or logos (thank-you)
   is the design's on its 874 px phone, less on short ones. A taller screen
   doesn't widen it: the tree's box takes the extra height instead (see
   .hero--fallen and .hero--upright). */
.intro-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    /* 66 px on the design's 874 px tall phone, 28 px at 667 px (iPhone SE). */
    padding-top: clamp(28px, 18.36svh - 94.4px, 66px);
}

.intro .partners {
    margin-top: 20px;
}

/* ---------- 02 Write ---------- */

/* The letter fills the room the window has left: the design's 512 px
   when there's room, shorter (fewer ruled lines) on short screens, so the
   send button is in view. Below 300 px it stops shrinking; the screen grows
   past the window instead, and the page scrolls. */
.write .title {
    flex-shrink: 0;
    width: 339px;
    max-width: calc(100% - 32px);
    margin-top: clamp(28px, 8.7svh, 76px);
}

.letter-form {
    min-height: 0;
}

.letter-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex: 1;
}

.letter-wrap {
    position: relative;
    width: 337px;
    max-width: calc(100% - 44px);
    flex: 1 0 300px;
    max-height: 512px;
    margin-top: clamp(24px, 6.75svh, 59px);
}

/* The second sheet peeking out behind the letter. */
.letter-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 13px;
    background: var(--paper-back);
    transform: rotate(2.49deg);
}

.letter {
    position: relative;
    height: 100%;
    border-radius: 13px;
    background: var(--paper);
}

.letter .postmark {
    position: absolute;
    top: 51px;
    right: 86.56px;
    width: 121.438px;
    height: 90px;
    transform: rotate(-1.77deg);
}

.stamp {
    position: absolute;
    overflow: hidden;
    background: var(--paper);
    border: 1px dashed rgba(0, 0, 0, 0.5);
}

.letter .stamp {
    top: 31px;
    right: 26px;
    width: 95px;
    height: 125px;
    border-radius: 2px;
}

.letter .stamp-picture {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 86.685px;
    height: 116px;
    overflow: hidden;
}

.letter .stamp-picture img {
    position: absolute;
    top: -6.53%;
    left: -5.82%;
    width: 112.02%;
    max-width: none;
    height: auto;
}

/* Each line of writing sits on a ruled line (32 px apart, as in the
   design). The lines are the box's own background, attached to its content
   ("local"), so they scroll with the writing and go on as far as it does.
   .letter-text is the writing on the copy that gets sent (write.js). */
.letter textarea,
.letter .letter-text {
    position: absolute;
    top: 164px;
    bottom: 60px;
    left: 28px;
    width: calc(100% - 57px);
    margin: 0;
    padding: 0;
    border: 0;
    background: repeating-linear-gradient(to bottom, transparent 0 26px, rgba(0, 0, 0, 0.2) 26px 27px, transparent 27px 32px) local;
    color: var(--ink);
    font-family: var(--hand);
    font-size: 21px;
    font-weight: 700;
    line-height: 32px;
    resize: none;
    overflow-y: auto;
    scrollbar-width: none;
    outline: none;
}

.letter .letter-text {
    overflow: hidden;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.letter textarea::placeholder {
    color: rgba(32, 79, 164, 0.35);
}

.letter textarea::-webkit-scrollbar {
    display: none;
}

.counter {
    position: absolute;
    bottom: 40px;
    right: 29px;
    margin: 0;
    color: rgba(0, 0, 0, 0.4);
    font-size: 12px;
    font-weight: 400;
}

.counter.is-full {
    color: #b3261e;
}

.form-status {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(44px, 8.2svh, 72px);
    margin: 0;
    padding: 8px 24px;
    font-size: var(--text-status);
    line-height: 1.3;
    text-align: center;
}

.write .form-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-top: auto;
    padding-bottom: max(40px, env(safe-area-inset-bottom) + 20px);
}

/* Honeypot: off screen for people, still in the form for bots. */
.hp {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* The letter arrives a moment after the title. */
.write .title {
    animation: rise-in 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.write .letter-wrap {
    animation: letter-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 0.08s backwards;
}

.write .form-footer {
    animation: rise-in 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) 0.2s backwards;
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
}

@keyframes letter-in {
    from {
        opacity: 0;
        transform: translateY(46px) rotate(-3deg);
    }
}

/* ---------- Sending (write.js) ---------- */

/* While the copy of the letter is on its way, the page steps back. */
.write .title,
.write .form-footer {
    transition: opacity 0.4s ease;
}

.write.is-sending .title,
.write.is-sending .form-footer {
    opacity: 0;
    pointer-events: none;
}

.write.is-sending .letter-wrap {
    visibility: hidden;
}

.send-stage {
    position: fixed;
    inset: 0;
    z-index: 10;
    overflow: hidden;
    pointer-events: none;
}

.letter-ghost {
    position: absolute;
    max-width: none;
    margin: 0;
    animation: none !important;
}

/* The sheet behind straightens, so one tidy letter goes in. */
.letter-ghost::before {
    transition: transform 0.5s ease;
}

.letter-ghost.is-flat::before {
    transform: none;
}

.letter-ghost .letter {
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

/* The envelope has the wall card's shape, because its front is one. */
.envelope-rise {
    --envelope: min(300px, 100vw - 72px);
    position: absolute;
    top: 58%;
    left: 50%;
    width: var(--envelope);
    height: calc(var(--envelope) * 0.6844);
    margin: calc(var(--envelope) * -0.3422) 0 0 calc(var(--envelope) * -0.5);
    opacity: 0;
}

.envelope,
.envelope-turn,
.envelope-back,
.envelope-front {
    position: absolute;
    inset: 0;
}

.envelope {
    perspective: 900px;
}

.envelope-turn {
    transform-style: preserve-3d;
}

.envelope-back,
.envelope-front {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.envelope-body,
.envelope-pocket {
    position: absolute;
    inset: 0;
    border-radius: 10px;
}

.envelope-body {
    background: #e9e3d0;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
}

/* The front of the pocket: everything but the V the flap closes over. */
.envelope-pocket {
    background:
        linear-gradient(to top right, transparent calc(50% - 0.5px), rgba(0, 0, 0, 0.07) 50%, transparent calc(50% + 0.5px)) bottom left / 50% 50% no-repeat,
        linear-gradient(to top left, transparent calc(50% - 0.5px), rgba(0, 0, 0, 0.07) 50%, transparent calc(50% + 0.5px)) bottom right / 50% 50% no-repeat,
        var(--paper);
    -webkit-clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
    clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
}

/* Cuts the letter off at the envelope's bottom edge as it slides in. */
.envelope-slot {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 100vh;
    overflow: hidden;
}

.envelope-slot .letter-ghost .letter {
    box-shadow: none;
}

/* Open, the flap stands up behind the letter; closed, it lies on top. */
.envelope-flap {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 56%;
    transform: perspective(600px) rotateX(180deg);
    transform-origin: top;
}

/* A triangle with the envelope's round corners at the top and a soft tip,
   drawn at the flap's own size (300 × 115 on a 300 px envelope). */
.envelope-flap i {
    position: absolute;
    inset: 0;
    background: #ded7c2;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 115' preserveAspectRatio='none'%3E%3Cpath d='M10 0H290Q300 0 292.1 7.6L162.7 105.3Q150 115 137.3 105.3L7.9 7.6Q0 0 10 0Z'/%3E%3C/svg%3E") 0 0 / 100% 100% no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 115' preserveAspectRatio='none'%3E%3Cpath d='M10 0H290Q300 0 292.1 7.6L162.7 105.3Q150 115 137.3 105.3L7.9 7.6Q0 0 10 0Z'/%3E%3C/svg%3E") 0 0 / 100% 100% no-repeat;
}

.envelope-flap.is-closed {
    z-index: 1;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.16));
}

.envelope-flap.is-closed i {
    background: #f4efe1;
}

.envelope-seal {
    position: absolute;
    top: 56%;
    left: 50%;
    z-index: 2;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 50%;
    /* The heart's viewBox is its own outline, so it sits dead centre. */
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='2 2.175 20 20'%3E%3Cpath fill='%230f275c' d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E") center / 19px no-repeat,
        radial-gradient(circle, transparent 16.5px, rgba(15, 39, 92, 0.16) 17px, rgba(15, 39, 92, 0.16) 18px, transparent 18.5px),
        radial-gradient(circle at 35% 30%, #fffa9c, var(--yellow) 55%, #e6d82a);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22), inset 0 -2px 3px rgba(0, 0, 0, 0.08);
    transform: scale(0);
}

.send-stage .envelope-front {
    font-size: calc(var(--envelope) / 18.833);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
    transform: rotateY(180deg);
    /* Shown halfway through the turn (write.js), not before: Safari can
       draw it through the back otherwise. */
    opacity: 0;
}

/* ---------- 03 Thanks ---------- */

/* The column is the window's width here, so the tree reaches both edges
   on wide phones too; the text keeps its own width. */
.screen.thanks,
.screen.intro {
    max-width: none;
}

/* After sending, the words wait for the tree to stand up (write.js takes
   .is-arriving off), then come in one after the other. */
.thanks .lead,
.thanks .partners {
    transition: opacity 0.8s ease, transform 1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.thanks .partners {
    transition-delay: 0.25s;
}

.thanks.is-arriving .lead,
.thanks.is-arriving .partners {
    opacity: 0;
    transform: translateY(18px);
    transition: none;
}

/* Over the faded floor, as in the design, but never on the tree's stand
   (85% down the box): on short screens it keeps 24 px below it. */
.thanks .lead {
    margin-top: max(-62px, var(--h) * -0.15 + 24px);
}

.thanks .partners {
    padding-top: clamp(40px, 7.2svh, 63px);
}

/* ---------- Letter cards (04 wall, 05 open letter) ---------- */

/* Every measurement is in em, so the large card is the small one at a
   bigger font size: 10.812 px on the wall, 19.433 px when opened. */
.card {
    position: relative;
    display: block;
    width: 18.833em;
    height: 12.89em;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0.75em;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--hand);
    font-size: 10.812px;
    font-weight: 700;
    line-height: 1.19;
    text-align: left;
}

.card .postmark {
    position: absolute;
    top: 1.874em;
    left: 11.8em;
    width: 4.067em;
    height: 3.014em;
    transform: rotate(-1.77deg);
}

.card .stamp {
    top: 1.142em;
    right: 0.981em;
    width: 3.181em;
    height: 4.186em;
    border-width: 0.0335em;
    border-radius: 0.067em;
}

.card .stamp img {
    position: absolute;
    top: 0.1em;
    left: 0.1em;
    width: calc(100% - 0.2em);
    height: calc(100% - 0.2em);
    object-fit: cover;
    transform: rotate(-0.48deg);
}

.card .text {
    margin: 0;
    padding: 5.308em 4.409em 0 1.925em;
    overflow-wrap: anywhere;
}

/* On the wall: as many lines as fit the card, the rest when opened. */
.card--small .text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    overflow: hidden;
}

/* ---------- 04 Wall ---------- */

.wall {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100svh;
    overflow: hidden;
}

.wall .title {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    width: 352px;
    max-width: calc(100% - 32px);
    margin: 58px auto 0;
}

@media (min-width: 720px) {
    .wall .title {
        width: 680px;
    }
}

/* The rows of cards drift through this area (wall.js). It starts below the
   title, so a title on three lines doesn't cover it. Sideways swipes belong
   to the wall; up and down still scrolls the page. */
.wall-viewport {
    position: relative;
    flex: 1;
    min-height: 0;
    margin: 36px 0 max(20px, env(safe-area-inset-bottom));
    overflow: hidden;
    touch-action: pan-y;
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
}

.wall-viewport.is-dragging {
    cursor: grabbing;
}

/* On wide screens the cards fade into the page's dark green at the sides
   (on a phone they simply run off the edges; the three rows fit its
   height, so nothing fades at the bottom). A layer of green over them
   rather than a see-through mask: see-through cards would show the snow
   behind them (snow.js), as if it fell in front. The layer covers the
   whole page to its edges, so the snow fades out under it too instead of
   stopping at a line. */
@media (min-width: 720px) {
    .wall::after {
        content: '';
        position: absolute;
        inset: 0;
        z-index: 2;
        pointer-events: none;
        background: linear-gradient(to right, var(--green-dark), transparent 7%, transparent 93%, var(--green-dark));
    }
}

.wall-grid {
    position: absolute;
    inset: 0;
}

/* wall.js places every card with a transform, once per frame, and sets
   --card-scale so three rows fill the wall's height. */
.wall-grid .card {
    position: absolute;
    top: 0;
    left: 0;
    font-size: calc(10.812px * var(--card-scale, 1));
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: box-shadow 1.6s ease;
    will-change: transform;
    -webkit-tap-highlight-color: transparent;
}

.wall-viewport.is-dragging .card {
    cursor: grabbing;
}

.wall-grid .card:hover,
.wall-grid .card.is-fresh {
    z-index: 1;
}

.wall-grid .card:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    transition-duration: 0.25s;
}

/* A letter that has just arrived glows for a moment. */
.wall-grid .card.is-fresh {
    box-shadow: 0 0 0 0.25em var(--lime), 0 10px 26px rgba(0, 0, 0, 0.25);
    transition-duration: 0.3s;
}

.wall .title {
    animation: rise-in 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.wall-empty {
    position: absolute;
    top: 40%;
    left: 50%;
    width: 300px;
    max-width: calc(100% - 32px);
    margin: 0;
    transform: translate(-50%, -50%);
    font-size: var(--text-empty);
    line-height: 1.3;
    text-align: center;
}

.wall-empty .text-link {
    display: inline-block;
    margin-top: 16px;
}

/* ---------- 05 Open letter ---------- */

.letter-dialog {
    /* Sideways drags anywhere on it move between letters (wall.js). */
    touch-action: pan-y;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    /* Wider sides than the wall's, so the letters before and after show. */
    padding: 18px 30px;
    border: 0;
    background: transparent;
    overflow-x: hidden;
    overflow-y: auto;
}

.letter-dialog[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

.letter-dialog::backdrop {
    background: rgba(0, 0, 0, 0.2);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

/* The current letter and, behind it, the ones before and after. Sideways
   swipes belong to it (wall.js); up and down still scrolls a long letter. */
.letter-deck {
    position: relative;
    width: 100%;
    max-width: 18.833em;
    font-size: var(--letter-size);
    touch-action: pan-y;
    -webkit-user-select: none;
    user-select: none;
    --letter-size: min(19.433px, calc((100vw - 60px) / 18.833));
}

.letter-deck:focus {
    outline: none;
}

.letter-dialog .card {
    /* 342 px wide on the design's phone, scaled down on narrower ones. */
    font-size: var(--letter-size);
    /* A column, so a short letter's text sits at the bottom of the card,
       as on the wall; a long one still starts below the stamp. */
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 12.89em;
    padding-bottom: 1.6em;
}

.letter-deck {
    /* How far apart the cards are, in card widths (wall.js reads it). */
    --deck-spacing: 0.9;
}

/* The strip of cards (wall.js places each one from its offset): the middle
   one is the open letter, the others smaller and turned at the sides. */
.letter-dialog .letter-card {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    margin: 0;
    box-shadow: 0 6px 34px rgba(0, 0, 0, 0.5);
    will-change: transform, opacity;
}

.letter-dialog .letter-card.is-side {
    cursor: pointer;
}

/* The side letters are a shade darker: --dim goes from 0 in the middle to
   1 one place out, set by wall.js as the cards move, so it changes
   smoothly with them (no transition, which would restart mid-swipe). */
.letter-dialog .letter-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(0, 0, 0, 0.08);
    opacity: var(--dim, 0);
    pointer-events: none;
}

.letter-deck.is-swiping .letter-card {
    cursor: grabbing;
}

/* On a desktop the opened letter is bigger (up to 600 px wide, as tall as
   the window allows), with the side letters further out. */
@media (min-width: 720px) {
    .letter-deck {
        --letter-size: min(32px, calc((100vw - 120px) / 18.833), calc((100svh - 160px) / 14.5));
        /* Further apart, so the side letters show whole beside it. */
        --deck-spacing: 1.04;
        }

    .letter-dialog {
        cursor: grab;
    }
}

.letter-dialog .card .text {
    margin-top: auto;
    white-space: pre-line;
}

/* The letter comes up out of the wall as the wall blurs behind it. */
.letter-dialog[open] .letter-deck {
    animation: letter-open 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.15) backwards;
}

.letter-dialog[open]::backdrop {
    animation: screen-in 0.35s ease backwards;
}

/* Closing plays the opening backwards (wall.js closes it afterwards). */
.letter-dialog.is-closing .letter-deck {
    animation: letter-close 0.28s cubic-bezier(0.4, 0, 0.7, 0.2) forwards;
}

.letter-dialog.is-closing::backdrop {
    animation: fade-out 0.28s ease forwards;
}

@keyframes letter-close {
    to {
        opacity: 0;
        transform: scale(0.92);
    }
}

@keyframes fade-out {
    to {
        opacity: 0;
    }
}

/* A straight pop, no tilt: the letters at the sides open with it. */
@keyframes letter-open {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* Scales with the letter: 24 px at the design's size (19.433 px), up to
   about 40 px on a desktop, never under 24 px. */
.letter-dialog .close {
    position: absolute;
    top: 0.36em;
    left: 0.36em;
    width: max(24px, 1.235em);
    height: max(24px, 1.235em);
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}

.letter-dialog .close img {
    width: 100%;
    height: 100%;
}

/* ---------- Desktop ---------- */

/* Desktop: the trees would otherwise be hard-edged strips of a lighter
   green on the page. Every edge fades into the page instead, and the
   thank-you film shows its whole width (the tree stays the size it is on a
   phone). */
@media (min-width: 720px) and (min-height: 560px) {
    /* One soft oval, not four straight fades: those meet in straight
       edges and corners, and the studio's darker side walls showed along
       them. The oval just fits the box, so it has faded out completely
       before it reaches any of the box's edges (else they show as
       lines), and stays solid over the middle 75%, so the tree and its
       stand do too; only the tips of the fallen tree's branches soften. */
    .hero {
        -webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 75%, transparent 100%);
        mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 75%, transparent 100%);
    }

    /* The tree is the same size as before; the box is as wide as the
       film (1.77 × its height, or the window), so there's studio either
       side of the tree, fading into the page well clear of it. */
    .hero--fallen {
        --h: min(600px, max(340px, 100svh - 306px));
        flex: none;
        width: min(100%, var(--h) * 1.77);
        height: var(--h);
        min-height: 0;
    }

    .hero--fallen img {
        left: calc(50% - var(--h) * 0.9109);
        top: calc(var(--h) * -0.067);
        bottom: auto;
        width: calc(var(--h) * 1.7723);
    }

    /* The box is fitted around the standing tree: its tip 11% from the
       top, its foot 80% down, both inside the oval's solid part. Below
       the film there's room for the oval to fade out before the box's
       bottom edge. --tw is the box's width (its height is the window's
       height less 250 px, at most 771 px). */
    .screen.thanks {
        --tw: min(720px, max(440px, 100svh - 250px) * 0.9333);
    }

    .hero--upright {
        flex: none;
        width: var(--tw);
        height: auto;
        min-height: 0;
        aspect-ratio: 0.9333;
        margin-top: 0;
    }

    .hero--upright .tree-film {
        left: 0;
        top: -7.8%;
        bottom: auto;
        width: 100%;
        height: 96.9%;
        /* Its own bottom edge (the floor) fades out too, below the stand. */
        -webkit-mask-image: linear-gradient(to bottom, #000 93%, transparent);
        mask-image: linear-gradient(to bottom, #000 93%, transparent);
    }

    /* The content sits together in the middle, not spread to the edges.
       The column is as wide as the window, so the wider tree isn't cut
       off; everything in it keeps its own phone width. */
    .screen {
        justify-content: center;
        max-width: none;
    }

    .letter-form {
        flex: none;
    }

    .write .letter-wrap {
        flex: none;
        height: 512px;
    }

    .intro-actions {
        margin-top: 36px;
        padding-top: 0;
    }

    .write .form-footer {
        margin-top: 0;
        padding-bottom: 40px;
    }

    /* Up into the room under the tree, 18 px below its stand (which is
       20% of the box's height, 0.2143 × its width, above the box's end). */
    .thanks .lead {
        margin-top: calc(var(--tw) * -0.2143 + 18px);
    }

    .thanks .partners {
        margin-top: 48px;
        padding-top: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }
}
