/*
 * Login, register and the other account screens (layouts.auth), loaded only there.
 * Every colour comes from the --auth-* tokens in ui-core.css, which switch between day and night
 * (and turn a dusky mauve and orange in the Halloween season); the Halloween dress itself lives in season-halloween.css.
 *   .auth-scene ...... the fixed landscape behind the page (x-shop.auth-scene): sky and stars, the sun setting as the moon
 *                      rises at the top right (.sky-orb, ui-core.css), the mountains (x-shop.scene-land, styled in ui-core.css) with the video
 *                      author's wolf (scene-wolf.js); day cross-fades into night with the page (shop-core.js); in the Halloween season his bats
 *                      and witch fly over it (x-shop.sky-flight, season-halloween.css)
 *   .auth-shell ...... the small glass card in the middle of the screen, holding only the form
 *   .auth-main ....... serif title, lead, glass fields and the glowing button
 *   flashlight ....... at night the eye of a password field lights a torch (.auth-stage.flashlight-on): the beam
 *                      (.flash-beam), the torch on the eye (.flashlight) and the letters the beam falls on (.password-reveal,
 *                      over the field, whose own text turns transparent); the owl (.auth-owl) wakes in its light
 * Anything that moves runs only under prefers-reduced-motion: no-preference.
 */

@layer components {
    /* ---------- Landscape behind the page ---------- */
    .auth-scene { --orb-size: 54px; --orb-right: 9%; --orb-top: calc(var(--sticky-top) + 22px);
        position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; background: linear-gradient(180deg, var(--auth-sky-top), var(--auth-sky-high) 44%, var(--auth-sky-low) 78%, var(--auth-sky-foot)); }
    .auth-scene-stars { position: absolute; inset: 0 0 45%;
        background:
            radial-gradient(1.6px 1.6px at 6% 18%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 14% 42%, var(--auth-star) 98%, transparent),
            radial-gradient(1.3px 1.3px at 22% 10%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 31% 30%, var(--auth-star) 98%, transparent),
            radial-gradient(1.8px 1.8px at 39% 14%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 47% 48%, var(--auth-star) 98%, transparent),
            radial-gradient(1.4px 1.4px at 56% 22%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 63% 8%, var(--auth-star) 98%, transparent),
            radial-gradient(1.6px 1.6px at 71% 36%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 79% 16%, var(--auth-star) 98%, transparent),
            radial-gradient(1.3px 1.3px at 86% 44%, var(--auth-star) 98%, transparent),
            radial-gradient(1.8px 1.8px at 93% 12%, var(--auth-star) 98%, transparent);
    }
    .auth-scene-stars::after { content: ''; position: absolute; inset: 0;
        background:
            radial-gradient(1.2px 1.2px at 10% 28%, var(--auth-star) 98%, transparent),
            radial-gradient(1.5px 1.5px at 27% 52%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 44% 6%, var(--auth-star) 98%, transparent),
            radial-gradient(1.5px 1.5px at 60% 40%, var(--auth-star) 98%, transparent),
            radial-gradient(1.2px 1.2px at 75% 26%, var(--auth-star) 98%, transparent),
            radial-gradient(1px 1px at 97% 32%, var(--auth-star) 98%, transparent);
    }
    /* The sun and the moon (.sky-orb, ui-core.css) sit where these say; the witch circles the moon there. */
    .auth-scene .sky-flight { --moon-right: var(--orb-right); --moon-top: calc(var(--orb-top) - var(--sticky-top)); --moon-size: var(--orb-size); }

    .auth-scene-flies > i { position: absolute; left: var(--x); top: var(--y); width: 4px; height: 4px; border-radius: 50%; background: var(--auth-firefly); box-shadow: 0 0 8px 2px var(--auth-firefly); }
    .auth-scene-leaves > svg { position: absolute; left: var(--x); top: -30px; width: 18px; height: 18px; scale: var(--s); fill: var(--hw-orange); opacity: 0; }
    .auth-scene-leaves > svg.is-red { fill: var(--hw-orange-deep); }
    .auth-scene-leaves > svg.is-gold { fill: var(--hw-ember); }
    :root[data-theme="light"] .auth-scene-leaves > svg:nth-child(2n) { display: none; }

    /* ---------- The glass card ---------- */
    main.container:has(> .auth-stage) { padding-top: 0; padding-bottom: 0; }
    /* On a phone the card sits near the top (room for the pumpkins on its frame), the moon behind its glass, so the whole
       form shows above the bottom bar; on a larger screen it sits in the middle. */
    .auth-stage { display: grid; place-items: start center; min-height: calc(100svh - var(--sticky-top)); padding: 40px 14px 32px; }
    .auth-shell { position: relative; width: 100%; max-width: 420px; padding: 6px; border: 1px solid var(--auth-glass-line); border-radius: 24px; background: var(--auth-glass); box-shadow: var(--auth-glass-shadow); -webkit-backdrop-filter: blur(18px) saturate(1.25); backdrop-filter: blur(18px) saturate(1.25); }

    /* ---------- The form ---------- */
    .auth-main { position: relative; padding: 22px 16px 18px; }
    .auth-main h1 { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 700; line-height: 1.15; text-align: center; color: var(--ink); }
    .auth-lead { max-width: 320px; margin: 6px auto 20px; color: var(--muted); font-size: 13.5px; line-height: 1.5; text-align: center; }
    .auth-main h1:last-child, .auth-main h1 + :not(.auth-lead) { margin-bottom: 20px; }
    .auth-main a:not(.btn) { color: var(--auth-accent); }
    .auth-main .auth-invite a { color: inherit; font-weight: 700; }
    .auth-main h1 + .auth-invite { margin-top: 14px; }
    .auth-main h1 + form { margin-top: 20px; }
    .auth-main .auth-submit + .auth-invite { margin-top: 12px; }
    .auth-main .auth-invite > .bxs-gift { background: var(--auth-btn); color: #fff; box-shadow: 0 8px 18px -10px var(--auth-btn-glow); }
    /* The page's own line under the title ("Vui lòng đăng nhập để bắt đầu."), in the page's accent rather than green. */
    .auth-main .auth-invite.is-hint { border-color: color-mix(in srgb, var(--auth-accent) 28%, transparent); background: color-mix(in srgb, var(--auth-accent) 10%, var(--auth-field)); color: var(--text); }
    .auth-main .auth-invite.is-hint > i { background: var(--auth-btn); color: var(--photo-ink); box-shadow: 0 8px 18px -10px var(--auth-btn-glow); }
    /* A wrong password or any other error (and the green "status" line) in the same joined box as the hint, with the icon in a round badge. */
    .auth-main .alert { align-items: center; gap: var(--sp-3); margin: var(--sp-4) 0; padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-2); border-radius: var(--radius); font-size: var(--fs-sm); font-weight: 600; line-height: 1.4; }
    .auth-main .alert > i { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--photo-ink); font-size: var(--fs-lg); }
    .auth-main .alert > div { flex: 1; min-width: 0; text-wrap: balance; }
    .auth-main .alert > div > div + div { margin-top: var(--sp-1); }
    .auth-main .alert-error { border-color: color-mix(in srgb, var(--bad) 34%, transparent); background: color-mix(in srgb, var(--bad) 12%, var(--auth-field)); }
    .auth-main .alert-error > i { background: var(--bad); box-shadow: 0 8px 18px -10px var(--bad); }
    .auth-main .alert-success { border-color: color-mix(in srgb, var(--ok) 34%, transparent); background: color-mix(in srgb, var(--ok) 12%, var(--auth-field)); }
    .auth-main .alert-success > i { background: var(--ok); box-shadow: 0 8px 18px -10px var(--ok); }
    /* Register page once this phone or connection has made all its accounts (DeviceSignupLimit): an amber card with the
       way back in (sign in, or chat with the shop) above the form. */
    .auth-main .auth-limit { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-3); margin: var(--sp-4) 0 var(--sp-5); padding: var(--sp-4); border: 1px solid color-mix(in srgb, var(--warn) 34%, transparent); border-radius: var(--radius-lg); background: linear-gradient(160deg, color-mix(in srgb, var(--warn) 22%, var(--auth-field)), var(--warn-soft)); box-shadow: 0 14px 30px -22px var(--warn); }
    .auth-limit-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--warn); color: var(--photo-ink); font-size: var(--fs-xl); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warn) 18%, transparent); }
    .auth-limit-body { min-width: 0; align-self: center; }
    .auth-limit-body > strong { display: block; color: var(--ink); font-size: var(--fs-md); line-height: 1.35; text-wrap: balance; }
    .auth-limit-body > p { margin: var(--sp-1) 0 0; color: var(--text); font-size: var(--fs-sm); line-height: 1.5; }
    .auth-limit-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
    .auth-limit-actions > .btn { min-height: var(--control-h); gap: var(--sp-1); font-size: var(--fs-sm); }
    .auth-main .auth-input > input { min-height: 48px; border-color: color-mix(in srgb, var(--auth-glass-line) 45%, var(--field-border)); border-radius: 14px; background: var(--auth-field); transition: border-color .2s, box-shadow .2s, background-color .2s; }
    .auth-main .auth-input > input:focus { border-color: var(--auth-accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--auth-accent) 18%, transparent); }
    .auth-main .auth-input:focus-within > i { color: var(--auth-accent); }
    .auth-main .auth-input.is-invalid > input { border-color: var(--bad); }
    .auth-main input[type=checkbox] { accent-color: var(--auth-accent); }
    .auth-main .auth-submit { border: 0; border-radius: 14px; background: var(--auth-btn); color: #fff; box-shadow: 0 12px 26px -12px var(--auth-btn-glow); transition: box-shadow .25s, translate .25s, filter .25s; }
    .auth-main .auth-submit:hover { translate: 0 -1px; filter: brightness(1.06); box-shadow: 0 16px 34px -10px var(--auth-btn-glow), 0 0 0 4px color-mix(in srgb, var(--auth-btn-glow) 30%, transparent); }
    .auth-main .auth-submit:active { translate: 0 1px; }
    .auth-main .auth-submit[aria-busy] { cursor: progress; opacity: .75; translate: none; }

    /* ---------- The flashlight (night) ---------- */
    .flash-beam, .password-reveal, .flashlight { position: fixed; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .7s ease, visibility 0s linear .7s; }
    .flash-beam { z-index: 991; filter: blur(12px); transform-origin: 0 50%; }
    .flash-beam::before { content: ''; position: absolute; inset: 0; background: var(--auth-beam); -webkit-mask: url(season/beam-mask.svg) 0 0 / 100% 100% no-repeat; mask: url(season/beam-mask.svg) 0 0 / 100% 100% no-repeat; }
    .password-reveal { z-index: 992; overflow: hidden; color: var(--auth-reveal-ink); }
    .password-reveal > span { position: absolute; inset: 0 auto 0 0; display: flex; white-space: pre; }
    .password-reveal .reveal-char { --lit: 0; position: relative; flex: none; width: var(--reveal-cell, 1ch); height: 100%; }
    .reveal-char > span { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity 90ms linear; }
    .reveal-char .masked-char { opacity: calc(1 - var(--lit)); color: var(--auth-reveal-mask); }
    .reveal-char .plain-char { opacity: var(--lit); }
    .flashlight { z-index: 993; display: grid; width: 34px; height: 34px; place-items: center; filter: drop-shadow(0 0 8px var(--auth-flash-glow)); }
    .flashlight img { width: 33px; height: 33px; }
    .auth-stage.flashlight-on :is(.flash-beam, .password-reveal, .flashlight) { opacity: 1; visibility: visible; transition-delay: 0s; }
    /* The lit field keeps its caret but hides its own dots under the revealed letters (spaced to the same cells). */
    .auth-main .auth-input.is-torch-lit > input { color: transparent; -webkit-text-fill-color: transparent; caret-color: var(--auth-caret); letter-spacing: var(--reveal-gap, 0); }
    .auth-main .auth-input.is-torch-lit > input::placeholder { -webkit-text-fill-color: var(--auth-placeholder-lit); letter-spacing: normal; }
    .auth-input.is-torch-lit .auth-eye > i { opacity: 0; }

    /* The owl perched on the field above the lit one, seen only in the beam: it starts, then watches the torch and blinks. */
    .auth-owl { position: absolute; z-index: 2; left: 12px; bottom: calc(100% - 3.5px); width: 50.4px; height: 58.8px; opacity: 0; pointer-events: none; filter: drop-shadow(0 2.8px 4.2px var(--auth-owl-shadow)); transition: opacity .22s ease; }
    .auth-owl .owl-vector { display: block; width: 100%; height: 100%; overflow: visible; }
    .auth-owl .owl-breath { transform-origin: 1500px 3100px; }
    .auth-owl .owl-head { transform-origin: 1500px 1850px; transform: translate(var(--owl-head-x, 0px), var(--owl-head-y, 0px)) rotate(var(--owl-tilt, 0deg)); transition: transform .5s cubic-bezier(.2, .8, .2, 1); }
    .auth-owl .owl-gaze { transform: translate(var(--owl-gaze-x, 0px), var(--owl-gaze-y, 0px)); transition: transform .26s ease-out; }
    .auth-owl .owl-eyes { transform-box: fill-box; transform-origin: center; }

    @media (min-width: 600px) {
        .auth-scene { --orb-size: 76px; --orb-top: calc(var(--sticky-top) + 4vh); }
        .auth-stage { place-items: center; padding: 56px 24px; }
        .auth-main { padding: 28px 30px 24px; }
        .auth-main h1 { font-size: 34px; }
    }
    @media (min-width: 1100px) {
        .auth-scene { --orb-size: 100px; --orb-right: 12%; --orb-top: calc(var(--sticky-top) + 6vh); }
    }

    @media (prefers-reduced-motion: no-preference) {
        /* The glass box is there from the first frame and only settles; its rows follow within half a second. */
        .auth-shell { animation: auth-settle .45s cubic-bezier(.2, .8, .2, 1) both; }
        .auth-main > * { animation: auth-rise .4s cubic-bezier(.2, .8, .2, 1) both; }
        .auth-main > :nth-child(2) { animation-delay: .04s; }
        .auth-main > :nth-child(3) { animation-delay: .08s; }
        .auth-main > :nth-child(n+4) { animation-delay: .12s; }
        .auth-scene-stars { animation: auth-twinkle 3.4s ease-in-out infinite alternate; }
        .auth-scene-stars::after { animation: auth-twinkle 2.6s ease-in-out -1.3s infinite alternate-reverse; }
        .auth-scene-flies > i { animation: auth-fly 7s ease-in-out var(--d) infinite alternate, auth-blink 2.2s ease-in-out var(--d) infinite alternate; }
        .auth-scene-leaves > svg { animation: auth-fall var(--t) linear var(--d) infinite; }
        .auth-owl.is-lit .owl-breath { animation: owl-breathe 3.6s ease-in-out infinite; }
        .auth-owl.is-lit .owl-eyes { animation: owl-blink 4.8s ease-in-out infinite; }
        .auth-owl.just-lit .owl-vector { animation: owl-startle .65s cubic-bezier(.2, .8, .2, 1); }
        .auth-limit-icon { animation: auth-limit-pulse 2.8s ease-in-out infinite; }
        .auth-main > .alert-error { animation: auth-rise .4s cubic-bezier(.2, .8, .2, 1) .04s both, auth-shake .5s ease-in-out .3s; }
        .auth-main .auth-invite > .bxs-gift { position: relative; overflow: hidden; animation: auth-gift-glow 3.2s ease-in-out infinite; }
        .auth-main .auth-invite > .bxs-gift::before { animation: auth-gift-wiggle 3.2s ease-in-out infinite; }
        .auth-main .auth-invite > .bxs-gift::after { content: ""; position: absolute; inset: 0; background: linear-gradient(115deg, transparent 30%, color-mix(in srgb, var(--photo-ink) 55%, transparent) 50%, transparent 70%); translate: -110% 0; animation: auth-gift-shine 3.2s ease-in-out infinite; }
    }
    @media (prefers-reduced-motion: reduce) {
        :is(.flash-beam, .password-reveal, .flashlight, .auth-owl, .reveal-char > span) { transition-duration: .01ms; transition-delay: 0s; }
    }
}

@keyframes auth-gift-wiggle { 0%, 30%, 100% { transform: rotate(0) scale(1); } 6% { transform: rotate(-14deg) scale(1.12); } 12% { transform: rotate(12deg) scale(1.12); } 18% { transform: rotate(-8deg) scale(1.06); } 24% { transform: rotate(4deg) scale(1.02); } }
@keyframes auth-gift-shine { 0%, 32% { translate: -110% 0; } 58%, 100% { translate: 110% 0; } }
@keyframes auth-gift-glow { 0%, 100% { box-shadow: 0 8px 18px -10px var(--auth-btn-glow); } 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--auth-accent) 22%, transparent), 0 8px 22px -8px var(--auth-btn-glow); } }
@keyframes auth-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes auth-limit-pulse { 0%, 100% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--warn) 18%, transparent); } 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--warn) 6%, transparent); } }
@keyframes auth-settle { from { translate: 0 12px; } to { translate: 0 0; } }
@keyframes auth-rise { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
@keyframes auth-twinkle { from { opacity: .45; } to { opacity: 1; } }
@keyframes auth-fly { 0% { transform: translate(0, 0); } 50% { transform: translate(26px, -18px); } 100% { transform: translate(-14px, -34px); } }
@keyframes auth-blink { from { opacity: .15; } to { opacity: 1; } }
@keyframes auth-fall {
    0% { opacity: 0; transform: translate(0, 0) rotate(0); }
    8% { opacity: .9; }
    50% { transform: translate(60px, 52vh) rotate(220deg); }
    90% { opacity: .8; }
    100% { opacity: 0; transform: translate(-20px, 105vh) rotate(480deg); }
}
@keyframes owl-breathe { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-16px) scale(1.014, 1.018); } }
@keyframes owl-blink { 0%, 5%, 11%, 55%, 61%, 100% { transform: scaleY(1); } 8%, 58% { transform: scaleY(.06); } }
@keyframes owl-startle { 0%, 100% { transform: translateY(0); } 35% { transform: translateY(-4px) rotate(-3deg); } 65% { transform: translateY(-1px) rotate(2deg); } }
