/**
 * ADGO-style preloader — brand overlay + flip bars + diagonal wipe
 */

[data-theme='brand'] {
    --color-background: #00f2ff;
    --color-foreground: #141314;
    --color-brand: #00f2ff;
    --color-brand-muted: #fd8d68;
    --color-surface: #fd8d68;
}

/* Scramble on brand overlay — use dark ink (brand === background) */
[data-theme='brand'] .preloader__text .scramble-brand {
    color: var(--color-foreground);
}

.preloader,
.preloader-minimal {
    --ease-power3-in-out: cubic-bezier(0.76, 0, 0.24, 1);
    --ease-power3-out: cubic-bezier(0.25, 1, 0.5, 1);
}

/* ── Layer 2: Minimal solid background (fallback only) ── */
.preloader-minimal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    z-index: 9998;
    margin: 0;
    padding: 0;
    background: var(--color-background, #fb460d);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms var(--ease-power3-out);
}

.preloader-minimal.is-active {
    visibility: visible;
    opacity: 1;
}

.preloader-minimal.is-exiting {
    opacity: 0;
    pointer-events: none;
}

/* ── Layer 3: Main preloader ── */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    z-index: 10000;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-background);
    pointer-events: auto;
    will-change: clip-path;
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
    overflow: hidden;
}

.preloader.is-exiting {
    pointer-events: none;
}

.preloader.is-complete {
    pointer-events: none;
}

.preloader.is-hidden {
    visibility: hidden;
    pointer-events: none;
}

.preloader__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-shrink: 0;
    will-change: opacity;
}

/* ── Flip bar indicator (4 squares) ── */
.preloader__logo {
    position: relative;
    width: 70px;
    height: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.preloader__square {
    position: absolute;
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    background: var(--color-foreground);
    transform: translateX(-16px);
    transform-origin: bottom right;
    will-change: transform;
}

.preloader__square:nth-child(1) { z-index: 4; }
.preloader__square:nth-child(2) { z-index: 3; }
.preloader__square:nth-child(3) { z-index: 2; }
.preloader__square:nth-child(4) { z-index: 1; }

/* ── Scramble text (3-layer: sr-only / ghost / absolute scramble) ── */
.preloader__text {
    flex-shrink: 0;
    font-family: var(--font-ui);
    font-size: clamp(14px, 2.5vw, 16px);
    font-weight: 400;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    line-height: 1;
    min-height: 1em;
}

.preloader__text-inner {
    position: relative;
    display: inline-block;
    white-space: nowrap;
    vertical-align: top;
}

.preloader__text-ghost {
    visibility: hidden;
    white-space: nowrap;
    display: block;
}

.preloader__text-scramble,
#preloader-scramble {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    min-height: 1em;
    white-space: nowrap;
    line-height: 1;
}

.preloader__text .scramble-char {
    display: inline-block;
    position: relative;
    width: 1ch;
    height: 1em;
    vertical-align: top;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.preloader__text .scramble-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 1ch;
    height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.preloader__text .scramble-layer--old {
    z-index: 1;
}

.preloader__text .scramble-layer--new {
    z-index: 2;
}

.preloader__text .scramble-brand {
    color: var(--color-brand);
}

.preloader__text .scramble-foreground {
    color: var(--color-foreground);
}

.preloader__text .scramble-char.is-revealed .scramble-layer--old {
    opacity: 0;
}

.preloader__text .scramble-char.is-revealed .scramble-layer--new {
    opacity: 1;
    color: var(--color-foreground);
}

.preloader__text .scramble-layer--old,
.preloader__text .scramble-layer--new {
    opacity: 1;
    transition: opacity 0.08s linear;
}

/* Screen reader only */
.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;
}

/* Scroll lock while preloader active */
html.preloader-active,
html.preloader-active body {
    overflow: hidden !important;
    height: 100%;
    max-height: 100%;
    width: 100%;
    scrollbar-width: none;
}

html.preloader-active body {
    position: fixed;
    inset: 0;
}

html.preloader-active::-webkit-scrollbar {
    display: none;
}

/* Post-preloader — header hidden until page enter priority 0 */
#navbar.header-hidden {
    pointer-events: none;
}

/* Hero stays hidden until page-ready + GSAP entrance (matches index.php markup) */
html:not(.page-ready) .hero-media,
html:not(.page-ready) .hero-headline [data-line-inner],
html:not(.page-ready) .hero-subtext,
html:not(.page-ready) .hero-cta-group,
html:not(.page-ready) .hero-trust-label,
html:not(.page-ready) .hero-logo {
    visibility: hidden;
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .preloader {
        transition: opacity 300ms var(--ease-power3-out);
    }

    .preloader.is-exiting {
        opacity: 0;
    }
}
