/* ==========================================================================
   CreateACard — Authentication pages (log in, sign up, signed-in page)
   Builds on the tokens in style.css. The envelope is layered HTML:

     .post                 entrance / exit / pointer tilt (GSAP)
       .post__drift        idle float (CSS)
         .post__body       stacking context for the layers below
           .env-back       z1   inside of the envelope
           .env-flap       z2   open → z6 once it folds past 90°
           .letter-slot    z3   the letter, clipped at the envelope's bottom edge
           .env-pocket     z4   front pocket the letter slides behind
           .env-seal       z7   wax seal pressed on the closed flap

   Without JavaScript (or if GSAP fails) the envelope renders open with the
   letter out, so the form always works.
   ========================================================================== */

/* 1. PAGE ================================================================== */
.auth-page { background: var(--paper); }

.authbar {
    position: absolute; inset: 0 0 auto; z-index: 50;
    width: min(100% - 2 * var(--gutter), var(--container)); margin-inline: auto; height: 76px;
    display: flex; align-items: center; justify-content: space-between;
}
.authbar__back {
    display: inline-flex; align-items: center; gap: .5rem; font-size: .92rem; font-weight: 600;
    padding-bottom: 2px; background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
    transition: background-size .5s var(--ease), color .3s;
}
.authbar__back:hover { color: var(--red); background-size: 100% 1px; }
.authbar__back svg { transition: transform .5s var(--ease); }
.authbar__back:hover svg { transform: translateX(-3px); }

.auth {
    position: relative; min-height: 100svh;
    width: min(100% - 2 * var(--gutter), var(--container)); margin-inline: auto;
    padding: 92px 0 clamp(2.5rem, 6vh, 4rem);
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
    column-gap: clamp(2rem, 6vw, 7rem);
}
/* Soft light behind the envelope */
.auth::before {
    content: ""; position: absolute; z-index: -1; pointer-events: none;
    right: -10%; top: 50%; width: min(1100px, 90vw); aspect-ratio: 1; transform: translateY(-50%);
    background: radial-gradient(closest-side, rgba(251, 248, 242, .95), rgba(251, 248, 242, .45) 45%, transparent);
}

.auth__intro { display: grid; gap: 1.6rem; align-content: center; max-width: 36rem; }
.auth__kicker { font-family: var(--mono); font-size: var(--fs-mono); color: var(--red); letter-spacing: .02em; }
.auth__statement {
    font-family: var(--serif); font-weight: 450; font-size: clamp(3rem, 6.2vw, 7rem);
    line-height: .92; letter-spacing: -.04em;
}
.auth__statement em { color: var(--red); }
.auth__lede { font-size: var(--fs-lede); color: var(--ink-soft); max-width: 30ch; line-height: 1.55; }

.auth__stage { display: grid; justify-items: center; padding: 1rem 0 calc(var(--gutter) * .5); }

/* 2. ENVELOPE GEOMETRY ===================================================== */
.post {
    --env-w: clamp(300px, 32vw, 460px);
    --env-h: calc(var(--env-w) * .54);    /* close to a DL envelope */
    --flap-h: calc(var(--env-h) * .56);   /* top flap reaches just past the pocket's V */
    --tuck: calc(var(--env-h) * .58);     /* how far the open letter stays inside the pocket */
    --seal: calc(var(--env-w) * .13);
    position: relative; width: var(--env-w);
    will-change: transform;
}
.post--signup { --env-w: clamp(320px, 36vw, 500px); }
.post--signup .sheet__body { gap: clamp(.85rem, 1.6vw, 1.1rem); }
.post--signup .form__fields { gap: clamp(.75rem, 1.3vw, .95rem); }

.post__drift { position: relative; }
.js .post__drift { animation: post-drift 8s var(--ease-io) infinite; }
.post.is-busy .post__drift { animation-play-state: paused; }
@keyframes post-drift {
    0%, 100% { transform: translate3d(0, 0, 0) rotate(-.4deg); }
    50% { transform: translate3d(0, -7px, 0) rotate(.35deg); }
}

.post__body {
    position: relative; z-index: 0;
    padding-bottom: calc(var(--env-h) - var(--tuck)); /* the envelope below the letter */
}

.post__shadow {
    position: absolute; left: 6%; right: 6%; bottom: calc(var(--env-h) * -.14); height: calc(var(--env-h) * .22);
    background: radial-gradient(closest-side, rgba(27, 24, 20, .28), transparent);
    pointer-events: none; transform-origin: 50% 50%;
}

/* Back (inside of the envelope) */
.env-back {
    position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; height: var(--env-h);
    border-radius: 5px;
    background:
        linear-gradient(180deg, rgba(27, 24, 20, .16), transparent 42%),
        linear-gradient(180deg, #E3D7C3, #D9CBB3);
    box-shadow: 0 1px 1px rgba(27, 24, 20, .08), 0 18px 34px -16px rgba(27, 24, 20, .35), 0 44px 70px -40px rgba(27, 24, 20, .45);
}

/* Flap — hinged on the envelope's top edge */
.env-flap {
    position: absolute; z-index: 2; left: 0; right: 0;
    bottom: calc(var(--env-h) - var(--flap-h)); height: var(--flap-h);
    transform-origin: 50% 0;
    transform: perspective(1100px) rotateX(180deg);   /* open by default */
    transform-style: preserve-3d;
    pointer-events: none;
}
.env-flap__face { position: absolute; inset: 0; -webkit-backface-visibility: hidden; backface-visibility: hidden; }
.env-flap__paper {
    position: absolute; inset: 0; display: block;
    clip-path: polygon(0 0, 100% 0, 54.5% 94%, 52.2% 98.6%, 50% 100%, 47.8% 98.6%, 45.5% 94%);
}
.env-flap__face--out { filter: drop-shadow(0 3px 3px rgba(27, 24, 20, .14)) drop-shadow(0 10px 12px rgba(27, 24, 20, .1)); }
.env-flap__face--out .env-flap__paper {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .5), transparent 30%),
        linear-gradient(176deg, #FAF5EC, #ECE2D1 70%, #E4D8C4);
}
.env-flap__face--in { transform: rotateX(180deg); }
.env-flap__face--in .env-flap__paper { /* Post Red liner — shape mirrored so it reads correctly once flipped */
    clip-path: polygon(0 100%, 100% 100%, 54.5% 6%, 52.2% 1.4%, 50% 0, 47.8% 1.4%, 45.5% 6%);
    background:
        linear-gradient(0deg, rgba(27, 24, 20, .22), transparent 40%),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .08) 0 2px, transparent 2px 9px),
        var(--red);
}

/* Letter slot — clipped at the envelope's bottom edge, open above */
.letter-slot {
    position: relative; z-index: 3;
    width: 88%; margin-inline: auto;
    clip-path: inset(-100vh -30% calc(var(--tuck) - var(--env-h) + 6px) -30%);
}

/* Front pocket */
.env-pocket {
    position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; height: var(--env-h);
    filter: drop-shadow(0 -1px 1.5px rgba(27, 24, 20, .16)); /* edge of the pocket casts onto the letter */
    pointer-events: none;
}
.env-pocket__sides, .env-pocket__bottom, .env-pocket__bottom > span, .env-pocket__shade { position: absolute; inset: 0; display: block; }
.env-pocket__sides {
    border-radius: 0 0 5px 5px;
    clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
    background:
        linear-gradient(90deg, rgba(27, 24, 20, .05), transparent 30% 70%, rgba(27, 24, 20, .05)),
        linear-gradient(180deg, #F4ECDF, #EADFCD);
}
.env-pocket__bottom { filter: drop-shadow(0 -1px 1px rgba(27, 24, 20, .1)) drop-shadow(0 -4px 6px rgba(27, 24, 20, .05)); }
.env-pocket__bottom > span {
    border-radius: 0 0 5px 5px;
    clip-path: polygon(0 100%, 0 99%, 47% 57%, 50% 55.5%, 53% 57%, 100% 99%, 100% 100%);
    background: linear-gradient(180deg, #FBF7EF, #F1E8D9);
}
.env-pocket__shade { /* shadow cast by the flap as it closes */
    clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
    background: linear-gradient(180deg, rgba(27, 24, 20, .32), rgba(27, 24, 20, .08) 45%, transparent 70%);
    opacity: 0;
}
.env-pocket__mark {
    position: absolute; left: 0; right: 0; bottom: 9%; text-align: center;
    font-family: var(--mono); font-size: clamp(.58rem, .9vw, .7rem); letter-spacing: .14em; text-transform: uppercase;
    color: rgba(27, 24, 20, .38);
}

/* Wax seal */
.env-seal {
    position: absolute; z-index: 7; left: 50%;
    bottom: calc(var(--env-h) - var(--flap-h) - var(--seal) * .5);
    width: var(--seal); height: var(--seal); margin-left: calc(var(--seal) * -.5);
    opacity: 0; transform: scale(.6); pointer-events: none;
}
.env-seal__wax {
    position: absolute; inset: 0; display: grid; place-items: center; border-radius: 50%;
    background: radial-gradient(circle at 34% 28%, #F27A63, var(--red) 42%, var(--red-deep) 78%, #9E2A16);
    box-shadow: 0 3px 6px rgba(120, 30, 15, .35), 0 10px 18px -6px rgba(120, 30, 15, .35), inset 0 -3px 5px rgba(0, 0, 0, .22), inset 0 2px 3px rgba(255, 255, 255, .25);
}
.env-seal__wax::before { /* uneven wax edge */
    content: ""; position: absolute; inset: -7%; z-index: -1; border-radius: 47% 53% 50% 50% / 52% 46% 54% 48%;
    background: var(--red-deep);
}
.env-seal__wax img { width: 50%; height: auto; filter: grayscale(1) brightness(3); opacity: .82; mix-blend-mode: screen; }
.env-seal__ring {
    position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid var(--red); opacity: 0;
}

/* 3. LETTER ================================================================ */
.sheet {
    position: relative; display: block;
    padding: clamp(1.3rem, 2.4vw, 2rem) clamp(1.25rem, 2.6vw, 2.2rem) calc(var(--tuck) + 1.6rem);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .6), transparent 18%),
        var(--stock);
    border-radius: 3px;
    box-shadow: 0 1px 1px rgba(27, 24, 20, .06), 0 14px 30px -18px rgba(27, 24, 20, .4);
    will-change: transform;
}
.sheet::before { /* faint deckle at the top edge */
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; border-radius: 3px 3px 0 0;
    background: linear-gradient(90deg, var(--red) 0 22%, transparent 22%);
}
.sheet__head {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding-bottom: .9rem; margin-bottom: clamp(1.1rem, 2.4vw, 1.6rem); border-bottom: 1px solid var(--line-soft);
    font-family: var(--mono); font-size: .7rem; color: var(--muted);
}
.sheet__brand { display: inline-flex; align-items: center; gap: .45rem; font-family: var(--sans); font-weight: 700; font-size: .85rem; letter-spacing: -.03em; font-variation-settings: "wdth" 88; color: var(--ink); }
.sheet__brand b { font-family: var(--serif); font-style: italic; font-weight: 500; color: var(--red); font-size: 1.15em; }
.sheet__brand img { width: 18px; height: 18px; }

.sheet__body { display: grid; gap: clamp(1rem, 2vw, 1.35rem); }
.sheet__intro { display: grid; gap: .35rem; }
.sheet__title { font-family: var(--serif); font-weight: 450; font-size: clamp(2rem, 3.2vw, 2.85rem); line-height: 1; letter-spacing: -.035em; }
.sheet__title em { color: var(--red); }
.sheet__lede { color: var(--ink-soft); font-size: .98rem; }
.sheet__switch { font-size: .92rem; color: var(--ink-soft); }
.sheet__switch a {
    font-weight: 600; color: var(--ink); white-space: nowrap;
    background: linear-gradient(var(--red), var(--red)) 0 100% / 100% 1px no-repeat; padding-bottom: 1px;
    transition: color .3s, background-size .5s var(--ease);
}
.sheet__switch a:hover { color: var(--red); }

.sheet__stack { position: relative; }

/* Notices */
.notice {
    position: relative; padding: .7rem .9rem .7rem 1rem; font-size: .88rem; line-height: 1.45;
    border-left: 2px solid var(--ink); background: rgba(27, 24, 20, .04);
}
.notice--error { border-color: var(--red); color: var(--red-deep); background: rgba(228, 71, 43, .07); }
.notice--demo { border-color: var(--gold); background: rgba(242, 217, 138, .28); }

/* 4. FORM ================================================================== */
.form__fields { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: clamp(.9rem, 1.6vw, 1.15rem); }
.form__fields:disabled { cursor: progress; }
.form__pair { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(.9rem, 1.6vw, 1.15rem) 1.1rem; }

.field { position: relative; display: grid; gap: .25rem; min-width: 0; align-content: start; }
.field__label { font-family: var(--mono); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); transition: color .3s; }
.field:focus-within .field__label { color: var(--ink); }
.field__control { position: relative; display: flex; align-items: center; }
.field__control::after { /* ruled line that inks in on focus */
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1.5px; background: var(--ink);
    transform: scaleX(0); transform-origin: left; transition: transform .55s var(--ease);
}
.field:focus-within .field__control::after { transform: scaleX(1); }
.field__input {
    width: 100%; min-width: 0; height: 46px; padding: 0 0 2px; border: 0; border-bottom: 1px solid var(--line);
    border-radius: 0; background: transparent; outline: none;
    font-family: var(--serif); font-size: 1.2rem; letter-spacing: -.01em; color: var(--ink);
    transition: border-color .3s;
}
.field__input:focus-visible { outline: none; } /* the inked line is the focus indicator */
.field__input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px var(--stock) inset; -webkit-text-fill-color: var(--ink); }
.field__control:has(.field__toggle) .field__input { padding-right: 44px; }

.field__toggle {
    position: absolute; right: -6px; bottom: 2px; width: 42px; height: 42px; display: grid; place-items: center;
    color: var(--muted); border-radius: var(--radius); transition: color .3s;
}
.field__toggle:hover { color: var(--ink); }
.field__toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.field__toggle .icon-eye-off, .field__toggle[aria-pressed="true"] .icon-eye { display: none; }
.field__toggle[aria-pressed="true"] .icon-eye-off { display: block; }

.field__hint { font-size: .75rem; color: var(--muted); }
.field__error { font-size: .78rem; color: var(--red-deep); line-height: 1.35; }
.field__error:empty { display: none; }
.field.is-invalid .field__input { border-bottom-color: var(--red); }
.field.is-invalid .field__control::after { background: var(--red); }
.field.is-invalid .field__label { color: var(--red-deep); }

.form__row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: -.1rem; }
.check { display: inline-flex; align-items: center; gap: .6rem; font-size: .9rem; cursor: pointer; user-select: none; min-height: 32px; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check__box {
    width: 18px; height: 18px; flex-shrink: 0; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 2px;
    transition: background .3s var(--ease), border-color .3s;
}
.check__box svg { width: 13px; height: 13px; fill: none; stroke: var(--stock); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 22; stroke-dashoffset: 22; transition: stroke-dashoffset .4s var(--ease); }
.check input:checked + .check__box { background: var(--ink); }
.check input:checked + .check__box svg { stroke-dashoffset: 0; }
.check input:focus-visible + .check__box { outline: 2px solid var(--red); outline-offset: 3px; }

.form__error {
    display: flex; gap: .55rem; align-items: flex-start;
    font-family: var(--serif); font-style: italic; font-size: 1.02rem; line-height: 1.35; color: var(--red-deep);
}
.form__error::before { content: ""; flex: 0 0 auto; width: 6px; height: 6px; margin-top: .55em; border-radius: 50%; background: var(--red); }
.form__error:empty { display: none; }

.form__submit { width: 100%; margin-top: .2rem; overflow: hidden; }
.form__submit-arrow { transition: transform .5s var(--ease); }
.form__submit:hover .form__submit-arrow { transform: translateX(4px); }
.form__submit-check { display: none; }
.form__submit[aria-busy="true"] { cursor: progress; }
.form__submit[aria-busy="true"] .form__submit-arrow { animation: nudge 1s var(--ease-io) infinite; }
@keyframes nudge { 50% { transform: translateX(5px); opacity: .5; } }
.form__submit.is-done, .form__submit.is-done:hover { background: var(--moss); color: var(--stock); }
.form__submit.is-done .form__submit-arrow { display: none; }
.form__submit.is-done .form__submit-check { display: block; }
.form__submit.is-done .form__submit-check path { stroke-dasharray: 22; stroke-dashoffset: 22; animation: draw .5s var(--ease) .05s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Sign-up demo panel — overlays the form so the letter doesn't change size */
.demo-panel {
    position: absolute; inset: 0; display: grid; align-content: center; justify-items: start; gap: 1rem;
    padding: 1rem 0;
}
.demo-panel[hidden] { display: none; }
.demo-panel__stamp {
    font-family: var(--mono); font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; color: var(--red);
    border: 1.5px solid var(--red); padding: .3rem .6rem .25rem; transform: rotate(-4deg); border-radius: 2px;
}
.demo-panel__title { font-family: var(--serif); font-weight: 450; font-size: clamp(1.6rem, 2.6vw, 2.2rem); line-height: 1.05; letter-spacing: -.03em; outline: none; }
.demo-panel__title em { color: var(--red); }
.demo-panel__text { color: var(--ink-soft); max-width: 34ch; }
.demo-panel .btn { width: 100%; margin-top: .4rem; }
.form[inert] { pointer-events: none; }

/* 5. SIGNED-IN PAGE ======================================================== */
.auth--dash { grid-template-columns: 1fr; justify-items: center; }
.auth--dash::before { right: auto; left: 50%; transform: translate(-50%, -50%); }
.welcome {
    position: relative; width: min(100%, 620px);
    padding: clamp(2rem, 5vw, 3.5rem); background: var(--stock); border-radius: 3px;
    box-shadow: var(--shadow-paper); display: grid; gap: 1rem;
}
.welcome::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; border-radius: 3px 3px 0 0; background: linear-gradient(90deg, var(--red) 0 22%, transparent 22%); }
.welcome__postmark { position: absolute; right: clamp(-2.5rem, -3vw, -1rem); top: clamp(-3rem, -4vw, -1.5rem); width: clamp(110px, 16vw, 150px); color: var(--red); opacity: .85; transform: rotate(-12deg); }
.welcome__kicker { font-family: var(--mono); font-size: var(--fs-mono); color: var(--red); }
.welcome__title { font-family: var(--serif); font-weight: 450; font-size: clamp(2.8rem, 6vw, 4.4rem); line-height: .95; letter-spacing: -.04em; }
.welcome__title em { color: var(--red); }
.welcome__text { font-size: var(--fs-lede); color: var(--ink-soft); }
.welcome__text strong { color: var(--ink); font-weight: 600; }
.welcome__note { font-size: .9rem; color: var(--muted); padding-top: 1rem; border-top: 1px solid var(--line-soft); margin-top: .5rem; }
.welcome__actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .75rem; }
.welcome__actions form { display: contents; }

/* 6. PAGE TRANSITIONS ====================================================== */
.auth-veil { position: fixed; inset: 0; z-index: 9000; background: var(--paper); pointer-events: none; opacity: 0; }

/* Hide the envelope until the script has set its starting pose (falls back to visible after 2.5s) */
.js .post { opacity: 0; animation: post-fallback 0s linear 2.5s forwards; }
.js .post.is-live, .js .post.is-static { opacity: 1; animation: none; }
@keyframes post-fallback { to { opacity: 1; } }

/* 7. RESPONSIVE ============================================================ */
@media (max-width: 1100px) {
    .auth { grid-template-columns: 1fr; justify-items: center; row-gap: 1.5rem; padding-top: 96px; }
    .auth::before { right: auto; left: 50%; transform: translate(-50%, -40%); }
    .auth__intro { justify-items: center; text-align: center; max-width: 40rem; gap: .9rem; }
    .auth__statement { font-size: clamp(2.6rem, 7vw, 4.4rem); }
    .auth__statement br { display: none; }
    .post, .post--signup { --env-w: min(100vw - 2 * var(--gutter), 520px); }
}

@media (max-width: 640px) {
    .authbar { height: 64px; }
    .authbar__back span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .authbar__back { width: 44px; height: 44px; justify-content: center; background: none; border: 1px solid var(--line); border-radius: 50%; }
    .auth { padding-top: 80px; row-gap: 1rem; }
    .auth__statement, .auth__lede { display: none; }
    .post, .post--signup { --env-w: calc(100vw - 2 * var(--gutter)); --env-h: calc(var(--env-w) * .58); }
    .letter-slot { width: 92%; }
    .form__pair { grid-template-columns: 1fr; }
    .field__input { font-size: 1.15rem; height: 48px; } /* ≥16px keeps iOS from zooming */
    .env-pocket__mark { letter-spacing: .1em; }
    .welcome__postmark { right: .5rem; top: -2.2rem; width: 96px; }
    .welcome__actions .btn { flex: 1 1 100%; }
}

/* Shorter laptop screens: tighten the letter so the envelope stays in view */
@media (min-width: 1101px) and (max-height: 960px) {
    .auth { padding-top: 80px; padding-bottom: 2rem; }
    .auth__stage { padding-top: 0; }
    .sheet { padding-top: 1.2rem; padding-bottom: calc(var(--tuck) + 1.1rem); }
    .sheet__head { padding-bottom: .7rem; margin-bottom: 1rem; }
    .sheet__title { font-size: clamp(2rem, 2.8vw, 2.5rem); }
    .field__input { height: 42px; }
    .post--signup { --env-h: calc(var(--env-w) * .5); }
}

/* 8. MOTION ================================================================ */
@media (prefers-reduced-motion: reduce) {
    .js .post__drift { animation: none; }
}
