/* =============================================
   LOADER - "The Slate"
   A clapperboard fills in while the page loads,
   snaps shut, gets pulled out of frame and the
   screen opens like a shutter onto the hero.
   ============================================= */

.loader {
    display: none;
}

.js .loader {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10000;
    overflow: hidden;
    cursor: pointer;
    /* Failsafe: never trap the visitor if a script fails */
    animation: loaderFailsafe 0.5s 7s forwards;
}

@keyframes loaderFailsafe {
    to { opacity: 0; visibility: hidden; pointer-events: none; }
}

/* Two halves = the shutter that opens at the end */
.loader-half {
    position: absolute;
    left: 0;
    width: 100%;
    height: 50.5%;
    background: var(--bg-deep);
    transition: transform 0.95s var(--ease-in-out);
}

.loader-half.top {
    top: 0;
    background:
        radial-gradient(ellipse 60% 90% at 50% 100%, rgba(255, 240, 180, 0.18), transparent 70%),
        conic-gradient(#3a7a2a 0 25%, #357226 0 50%, #3a7a2a 0 75%, #357226 0);
    background-size: 100% 100%, 180px 180px;
}

.loader-half.bottom {
    bottom: 0;
    background:
        radial-gradient(ellipse 60% 90% at 50% 0%, rgba(255, 240, 180, 0.18), transparent 70%),
        conic-gradient(#3a7a2a 0 25%, #357226 0 50%, #3a7a2a 0 75%, #357226 0);
    background-size: 100% 100%, 180px 180px;
}

.loader-half::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary-color);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.loader-half.top::after { bottom: 0; }
.loader-half.bottom::after { top: 0; }

/* ---------- Camera HUD ---------- */
.loader-hud {
    position: absolute;
    inset: 22px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.16em;
    color: rgba(255, 251, 234, 0.85);
    text-shadow: 0 1px 3px rgba(10, 30, 5, 0.55);
    text-transform: uppercase;
    transition: opacity 0.35s ease;
    pointer-events: none;
}

.loader-hud .vf-corner {
    width: 34px;
    height: 34px;
    animation: hudCornerIn 0.7s var(--ease-out) both;
}

.loader-hud .vf-corner.tl { --fx: -30px; --fy: -30px; }
.loader-hud .vf-corner.tr { --fx: 30px; --fy: -30px; }
.loader-hud .vf-corner.bl { --fx: -30px; --fy: 30px; }
.loader-hud .vf-corner.br { --fx: 30px; --fy: 30px; }

@keyframes hudCornerIn {
    from { transform: translate(var(--fx), var(--fy)); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.loader-hud-item {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.loader-hud-item.tl { top: 14px; left: 48px; color: var(--text-light); }
.loader-hud-item.tr { top: 14px; right: 48px; font-variant-numeric: tabular-nums; }
.loader-hud-item.bl { bottom: 14px; left: 48px; }
.loader-hud-item.br { bottom: 14px; right: 48px; font-variant-numeric: tabular-nums; }

.loader-hud-item b {
    color: var(--primary-color);
    font-weight: 500;
}

/* ---------- The slate ---------- */
.slate {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(460px, 84vw);
    margin-left: calc(min(460px, 84vw) / -2);
    transform: translateY(-50%);
    animation: slateIn 0.8s var(--ease-out) both;
}

@keyframes slateIn {
    from { opacity: 0; transform: translateY(-38%) rotate(-4deg) scale(0.92); }
    to { opacity: 1; transform: translateY(-50%); }
}

.slate-sticks {
    position: relative;
    height: calc(min(460px, 84vw) * 0.125);
}

.slate-stick {
    position: absolute;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid #0b0b0b;
    border-radius: 4px;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.5);
}

.slate-stick--base {
    top: 0;
    background: repeating-linear-gradient(56deg, var(--primary-color) 0 26px, #0b0b0b 26px 52px);
}

/* The arm: hinged on its bottom-left corner, starts open */
.slate-stick--top {
    top: -100%;
    transform-origin: 2% 100%;
    transform: rotate(-24deg);
    background: repeating-linear-gradient(-56deg, var(--primary-color) 0 26px, #0b0b0b 26px 52px);
    animation: armIdle 1.6s ease-in-out infinite alternate;
}

/* Hinge pin */
.slate-sticks::after {
    content: '';
    position: absolute;
    left: 6px;
    top: -5px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #1c1c1c;
    border: 2px solid #3a3a3a;
    z-index: 2;
}

@keyframes armIdle {
    from { transform: rotate(-24deg); }
    to { transform: rotate(-29deg); }
}

.slate-board {
    background:
        radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.05), transparent 60%),
        #0e0e0e;
    border: 3px solid #1b1b1b;
    border-top: 0;
    border-radius: 0 0 8px 8px;
    padding: 4px 18px 14px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(240, 168, 48, 0.12);
}

.slate-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0 8px;
    border-bottom: 1.5px solid rgba(241, 236, 227, 0.22);
    clip-path: inset(0 100% 0 0);
    animation: chalkWrite 0.55s var(--ease-out) forwards;
}

.slate-row:nth-child(1) { animation-delay: 0.25s; }
.slate-row:nth-child(2) { animation-delay: 0.4s; }
.slate-row:nth-child(3) { animation-delay: 0.55s; }
.slate-row:nth-child(4) { animation-delay: 0.7s; }
.slate-row:nth-child(5) { animation-delay: 0.85s; border-bottom: 0; }

@keyframes chalkWrite {
    to { clip-path: inset(0 0 0 0); }
}

.slate-k {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.18em;
    color: rgba(241, 236, 227, 0.5);
    text-transform: uppercase;
    white-space: nowrap;
}

.slate-k b {
    color: var(--text-light);
    font-weight: 500;
    margin-left: 6px;
}

.slate-v {
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 5.4vw, 1.9rem);
    line-height: 1;
    color: #f4efe6;
    letter-spacing: 0.02em;
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.12);
    text-transform: uppercase;
    white-space: nowrap;
}

.slate-head .slate-v {
    color: var(--primary-color);
    font-size: clamp(1.6rem, 7vw, 2.6rem);
    flex: 1;
    text-align: right;
}

.slate-head svg {
    width: 38px;
    height: 30px;
    flex-shrink: 0;
    align-self: center;
}

.slate-cells {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
    gap: 0;
    padding: 0;
}

.slate-cell {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px 8px;
    border-left: 1.5px solid rgba(241, 236, 227, 0.22);
}

.slate-cell:first-child {
    border-left: 0;
    padding-left: 0;
}

.slate-cell .slate-v {
    font-size: clamp(1.6rem, 7vw, 2.4rem);
}

.slate-foot .slate-k {
    font-size: 10px;
}

/* Progress line under the slate */
.slate-progress {
    margin-top: 18px;
    height: 2px;
    background: rgba(241, 236, 227, 0.12);
    overflow: hidden;
    border-radius: 2px;
}

.slate-progress span {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--primary-color);
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.25s linear;
}

/* Big word that punches in on the clap */
.loader-action {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    text-align: center;
    font-family: var(--font-display);
    font-size: clamp(5rem, 24vw, 22rem);
    line-height: 1;
    color: transparent;
    -webkit-text-stroke: 2px rgba(240, 168, 48, 0.85);
    transform: translateY(-50%) scale(0.7);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
}

.loader-flash {
    position: absolute;
    inset: 0;
    background: #fff8e8;
    opacity: 0;
    pointer-events: none;
}

/* ---------- Sequence states (set by js/loader.js) ---------- */

/* 1. Clap - the arm slams shut */
.loader.is-clap .slate-stick--top {
    animation: none;
    transform: rotate(0deg);
    transition: transform 0.16s var(--ease-snap);
}

/* 2. Impact - jolt, flash, ACTION! */
.loader.is-clapped .slate-sticks,
.loader.is-clapped .slate-board {
    animation: slateJolt 0.32s var(--ease-out);
}

@keyframes slateJolt {
    0% { transform: translateY(7px) rotate(0.6deg); }
    45% { transform: translateY(-3px) rotate(-0.3deg); }
    100% { transform: none; }
}

.loader.is-clapped .loader-flash {
    animation: flash 0.42s ease-out;
}

@keyframes flash {
    0% { opacity: 0.55; }
    100% { opacity: 0; }
}

.loader.is-clapped .loader-action {
    animation: actionPunch 0.9s var(--ease-out) forwards;
}

@keyframes actionPunch {
    0% { opacity: 0; transform: translateY(-50%) scale(0.75); }
    25% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-50%) scale(1.12); }
}

.loader.is-clapped .loader-half::after {
    opacity: 1;
}

/* 3. Out - slate pulled out of frame, shutter opens */
.loader.is-out {
    pointer-events: none;
}

.loader.is-out .slate {
    animation: slateOut 0.6s cubic-bezier(0.55, 0, 0.75, 0.2) forwards;
}

@keyframes slateOut {
    from { transform: translateY(-50%); }
    to { transform: translateY(85vh) rotate(9deg); }
}

.loader.is-out .loader-hud {
    opacity: 0;
}

.loader.is-out .loader-half.top {
    transform: translateY(-101%);
    transition-delay: 0.12s;
}

.loader.is-out .loader-half.bottom {
    transform: translateY(101%);
    transition-delay: 0.12s;
}

/* Quick mode: arriving from another page of the site */
.loader.is-quick .slate,
.loader.is-quick .loader-hud {
    display: none;
}

@media (max-width: 600px) {
    .loader-hud {
        inset: 14px;
        font-size: 9.5px;
    }
    .loader-hud .vf-corner { width: 24px; height: 24px; }
    .loader-hud-item.tl, .loader-hud-item.bl { left: 34px; }
    .loader-hud-item.tr, .loader-hud-item.br { right: 34px; }
    .loader-hud-item.tl, .loader-hud-item.tr { top: 6px; }
    .loader-hud-item.bl, .loader-hud-item.br { bottom: 6px; }
    .loader-hud-item.bl { display: none; }
    .slate-board { padding: 2px 12px 10px; }
    .slate-cell { padding: 8px 8px 6px; }
}

@media (prefers-reduced-motion: reduce) {
    .js .loader { display: none; }
}
