/* =========================================================================
   Auth pages: animated habi loom background
   Faint vertical warp lines, crossed by woven bands running horizontally,
   vertically, and diagonally. On load a shuttle pulls each band across
   (alternating direction, like a real loom), then the threads drift slowly.

   CSS only. Every animation is transform/opacity, so it runs on the
   compositor and never triggers layout or repaint of the page. Each band is
   built along its own x-axis and the band itself is rotated into place, so
   vertical and diagonal bands reuse the horizontal animations.
   ========================================================================= */

.auth-page {
    --auth-ground: #161b3d;
    --auth-shuttle: #ffffff;
    --auth-ease: cubic-bezier(0.65, 0, 0.35, 1);
    --auth-pass: 1.6s;

    /* Thread colors from the logo, plus habi gold */
    --auth-teal: #0f9a8d;
    --auth-coral: #f0604d;
    --auth-gold: #e3a21a;
    --auth-indigo: #8796f2;

    position: relative;
    isolation: isolate;
    min-height: 100vh;
    display: flex;
    align-items: center;
    background: var(--auth-ground);
}

[data-bs-theme="dark"] .auth-page {
    --auth-ground: #0a0d24;
    --auth-shuttle: #e9ebf7;
}

.auth-page > .container {
    position: relative;
    z-index: 1;
}

/* ── Loom: fixed decorative layer with the static warp ── */
.auth-loom {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    contain: strict;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect x='7' width='2' height='16' fill='%23ffffff' fill-opacity='0.07'/%3E%3C/svg%3E");
}

/* One band = three threads in plain weave (over one, under one) */
.auth-loom-pick {
    position: absolute;
    height: 24px;
    overflow: hidden;
}

.auth-loom-pick.is-h {
    left: 0;
    width: 100%;
}

.auth-loom-pick.is-v {
    top: 0;
    width: 100vh;
    transform: rotate(90deg);
    transform-origin: 0 0;
}

.auth-loom-pick.is-d {
    left: 50%;
    width: 160vmax;
    margin-left: -80vmax;
    margin-top: -12px;
    transform: rotate(var(--auth-angle));
    transform-origin: center;
}

.auth-loom-weft {
    position: absolute;
    inset: 0;
    will-change: transform;
}

.auth-loom-track {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -32px;
    width: calc(100% + 64px);
    opacity: 0.75;
    background-color: var(--auth-weft);
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='24'%3E%3Crect x='1' y='1' width='14' height='6' rx='3'/%3E%3Crect x='17' y='9' width='14' height='6' rx='3'/%3E%3Crect x='1' y='17' width='14' height='6' rx='3'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='24'%3E%3Crect x='1' y='1' width='14' height='6' rx='3'/%3E%3Crect x='17' y='9' width='14' height='6' rx='3'/%3E%3Crect x='1' y='17' width='14' height='6' rx='3'/%3E%3C/svg%3E");
    will-change: transform;
}

/* The shuttle rides the leading edge of its band, then fades out */
.auth-loom-shuttle {
    position: absolute;
    top: 7px;
    right: 0;
    width: 40px;
    height: 10px;
    border-radius: 5px;
    background: var(--auth-shuttle);
    will-change: opacity;
}

.auth-loom-pick.is-rev .auth-loom-shuttle { right: auto; left: 0; }

/* Placement, thread color, and start time per band */
.auth-loom-h1 { top: 8%;  --auth-weft: var(--auth-teal);   --auth-delay: 0.10s; }
.auth-loom-v1 { left: calc(9% + 24px);  --auth-weft: var(--auth-coral);  --auth-delay: 0.26s; }
.auth-loom-d1 { top: 34%; --auth-weft: var(--auth-gold);   --auth-delay: 0.42s; --auth-angle: -24deg; }
.auth-loom-h2 { top: 27%; --auth-weft: var(--auth-coral);  --auth-delay: 0.58s; }
.auth-loom-v2 { left: calc(31% + 24px); --auth-weft: var(--auth-indigo); --auth-delay: 0.74s; }
.auth-loom-h3 { top: 52%; --auth-weft: var(--auth-gold);   --auth-delay: 0.90s; }
.auth-loom-v3 { left: calc(67% + 24px); --auth-weft: var(--auth-teal);   --auth-delay: 1.06s; }
.auth-loom-d2 { top: 68%; --auth-weft: var(--auth-indigo); --auth-delay: 1.22s; --auth-angle: 28deg; }
.auth-loom-h4 { top: 74%; --auth-weft: var(--auth-indigo); --auth-delay: 1.38s; }
.auth-loom-v4 { left: calc(90% + 24px); --auth-weft: var(--auth-gold);   --auth-delay: 1.54s; }
.auth-loom-h5 { top: 92%; --auth-weft: var(--auth-teal);   --auth-delay: 1.70s; }

@keyframes auth-loom-pass-fwd {
    from { transform: translateX(-100%); }
    to { transform: none; }
}

@keyframes auth-loom-pass-rev {
    from { transform: translateX(100%); }
    to { transform: none; }
}

@keyframes auth-loom-shuttle-fade {
    0%, 85% { opacity: 1; }
    100% { opacity: 0; }
}

/* Drift by exactly one weave repeat (32px) so the loop is seamless */
@keyframes auth-loom-drift-fwd {
    to { transform: translateX(32px); }
}

@keyframes auth-loom-drift-rev {
    to { transform: translateX(-32px); }
}

/* Motion only for viewers who haven't asked to reduce it; otherwise the
   finished weave is shown still. */
@media (prefers-reduced-motion: no-preference) {
    .auth-loom-weft {
        animation: auth-loom-pass-fwd var(--auth-pass) var(--auth-ease) var(--auth-delay) both;
    }

    .auth-loom-track {
        animation: auth-loom-drift-fwd 9s linear infinite;
    }

    .auth-loom-shuttle {
        animation: auth-loom-shuttle-fade var(--auth-pass) linear var(--auth-delay) both;
    }

    /* Reversed bands travel the other way along their axis */
    .auth-loom-pick.is-rev .auth-loom-weft { animation-name: auth-loom-pass-rev; }
    .auth-loom-pick.is-rev .auth-loom-track { animation-name: auth-loom-drift-rev; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-loom-shuttle {
        display: none;
    }
}
