/* === Custom Properties === */
:root {
    --obsidian: #0a0a0f;
    --cyan: #00f0ff;
    --magenta: #ff2d7b;
    --twilight: #0d1b2a;
    --dusk: #1a1025;
    --dusk-end: #2d1b3d;
    --parchment: #f5e6d3;
    --gold: #d4a574;
    --lavender: #b8a9c9;
    --white: #e8e8e8;
    --forest: #1a3a1a;
}

/* === Reset === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--obsidian);
    color: var(--white);
    font-family: 'Work Sans', sans-serif;
    font-weight: 300;
    overflow-x: hidden;
    cursor: crosshair;
}

/* === Scanlines === */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 3px,
        rgba(0, 240, 255, 0.025) 3px,
        rgba(0, 240, 255, 0.025) 4px
    );
    opacity: 0;
    transition: opacity 0.6s ease;
}

#scanlines.visible {
    opacity: 1;
}

/* === Progress Bar === */
#progress-bar {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 40vh;
    background: rgba(0, 240, 255, 0.1);
    z-index: 999;
    border-radius: 2px;
}

#progress-fill {
    width: 100%;
    height: 0%;
    background: var(--cyan);
    border-radius: 2px;
    transition: height 0.1s linear;
    box-shadow: 0 0 8px rgba(0, 240, 255, 0.5);
}

#progress-text {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.6rem;
    color: var(--cyan);
    opacity: 0.6;
    white-space: nowrap;
    letter-spacing: 0.06em;
}

/* === Section Base === */
.section {
    position: relative;
    width: 100%;
}

/* === The Approach === */
#approach {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--obsidian);
    overflow: hidden;
}

#wordmark {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0;
}

.letter {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(4rem, 15vw, 12rem);
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-shadow: 0 0 40px rgba(0, 240, 255, 0.3);
    opacity: 0;
    transition: text-shadow 0.3s ease;
    display: inline-block;
}

.letter.arrived {
    opacity: 1;
}

.letter.flash {
    text-shadow: 0 0 80px rgba(0, 240, 255, 0.8), 0 0 120px rgba(0, 240, 255, 0.4);
}

#scroll-chevron {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    color: var(--cyan);
    opacity: 0;
    animation: chevron-pulse 2s ease-in-out infinite;
    transition: opacity 0.5s ease;
}

#scroll-chevron.visible {
    opacity: 0.7;
}

@keyframes chevron-pulse {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.7; }
    50% { transform: translateX(-50%) translateY(8px); opacity: 0.3; }
}

/* === The Corridor === */
#corridor {
    min-height: 300vh;
}

.corridor-panel {
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.panel-image {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.urban-1 {
    background:
        radial-gradient(ellipse at 30% 70%, rgba(0, 240, 255, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(255, 45, 123, 0.05) 0%, transparent 40%),
        linear-gradient(180deg, #0a0a0f 0%, #0f0f1a 30%, #141420 60%, #0a0a0f 100%);
    background-size: 200% 200%;
}

.urban-2 {
    background:
        radial-gradient(ellipse at 70% 60%, rgba(0, 240, 255, 0.1) 0%, transparent 45%),
        radial-gradient(circle at 20% 30%, rgba(212, 165, 116, 0.06) 0%, transparent 35%),
        linear-gradient(200deg, #0a0a0f 0%, #0d1020 40%, #0a0a18 70%, #0a0a0f 100%);
    background-size: 200% 200%;
}

.urban-3 {
    background:
        radial-gradient(ellipse at 50% 40%, rgba(0, 240, 255, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 60% 80%, rgba(255, 45, 123, 0.04) 0%, transparent 30%),
        linear-gradient(160deg, #0d1b2a 0%, #0a0a0f 50%, #0f0a15 100%);
    background-size: 200% 200%;
}

/* HUD Brackets */
.hud-brackets {
    position: absolute;
    top: 15%;
    left: 15%;
    width: 70%;
    height: 70%;
    pointer-events: none;
}

.bracket {
    position: absolute;
    width: 30px;
    height: 30px;
    border-color: var(--cyan);
    border-style: solid;
    border-width: 0;
    opacity: 0;
    transition: opacity 0.8s ease, transform 0.4s ease, border-color 1s ease;
}

.bracket.tl { top: 0; left: 0; border-top-width: 2px; border-left-width: 2px; transform: translate(-20px, -20px); }
.bracket.tr { top: 0; right: 0; border-top-width: 2px; border-right-width: 2px; transform: translate(20px, -20px); }
.bracket.bl { bottom: 0; left: 0; border-bottom-width: 2px; border-left-width: 2px; transform: translate(-20px, 20px); }
.bracket.br { bottom: 0; right: 0; border-bottom-width: 2px; border-right-width: 2px; transform: translate(20px, 20px); }

.hud-brackets.active .bracket {
    opacity: 0.8;
    transform: translate(0, 0);
    animation: bracket-pulse 3s ease-in-out infinite;
}

.hud-brackets.warm .bracket {
    border-color: var(--gold);
}

@keyframes bracket-pulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 0.5; }
}

.coord-readout {
    position: absolute;
    bottom: 12%;
    right: 15%;
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(0.65rem, 1vw, 0.8rem);
    color: var(--cyan);
    opacity: 0;
    letter-spacing: 0.06em;
    transition: opacity 0.5s ease;
    overflow: hidden;
    white-space: nowrap;
}

.coord-readout.warm {
    color: var(--gold);
}

.coord-readout.typing {
    opacity: 0.6;
    animation: typewriter 1.5s steps(35) forwards;
}

@keyframes typewriter {
    from { max-width: 0; }
    to { max-width: 100%; }
}

/* Corridor gaps */
.corridor-gap {
    height: 20vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--obsidian);
}

.clue-text {
    font-family: 'Work Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.5vw, 1.15rem);
    color: var(--lavender);
    letter-spacing: 0.02em;
    line-height: 1.85;
    opacity: 0;
    transition: opacity 0.8s ease;
    font-style: italic;
}

.clue-text.visible {
    opacity: 0.8;
}

/* === The Threshold === */
#threshold {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: var(--twilight);
    transition: background-color 0.3s ease;
}

#magnetic-text {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    max-width: 90vw;
    gap: 0;
}

.mag-char {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2rem, 8vw, 6rem);
    color: var(--parchment);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: inline-block;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: transform;
}

.hud-arc {
    position: absolute;
    bottom: 60px;
    right: 60px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0.6;
}

.arc-circle {
    stroke: var(--cyan);
    animation: arc-spin 6s linear infinite;
}

@keyframes arc-spin {
    from { transform-origin: center; transform: rotate(0deg); }
    to { transform-origin: center; transform: rotate(360deg); }
}

.arc-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.7rem;
    color: var(--cyan);
    letter-spacing: 0.06em;
}

/* === The Meadow === */
#meadow {
    min-height: 150vh;
    padding: 10vh 5vw;
    background: linear-gradient(180deg, var(--dusk) 0%, var(--dusk-end) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 60px;
}

.puzzle-piece {
    position: relative;
    max-width: 600px;
    width: 90%;
    padding: 40px;
    background: rgba(26, 16, 37, 0.6);
    border: 1px solid rgba(212, 165, 116, 0.15);
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 1.2s ease, transform 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.puzzle-piece.visible {
    opacity: 1;
    transform: translateY(0);
}

.piece-1 {
    clip-path: polygon(0 0, 100% 0, 100% 75%, 85% 75%, 85% 85%, 75% 85%, 75% 75%, 60% 75%, 60% 100%, 0 100%);
    align-self: flex-start;
    margin-left: 10%;
}

.piece-2 {
    clip-path: polygon(0 0, 40% 0, 40% 25%, 50% 25%, 50% 15%, 60% 15%, 60% 25%, 75% 25%, 75% 0, 100% 0, 100% 100%, 0 100%);
    align-self: flex-end;
    margin-right: 10%;
}

.piece-3 {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 65% 100%, 65% 85%, 55% 85%, 55% 90%, 45% 90%, 45% 100%, 0 100%);
    align-self: flex-start;
    margin-left: 15%;
}

.piece-4 {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 70%, 15% 70%, 15% 60%, 25% 60%, 25% 70%, 40% 70%, 40% 55%, 0 55%);
    align-self: flex-end;
    margin-right: 5%;
}

.piece-content h3 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(1.5rem, 3vw, 2.2rem);
    color: var(--gold);
    letter-spacing: 0.08em;
    margin-bottom: 12px;
    text-shadow: 0 0 20px rgba(212, 165, 116, 0.2);
}

.piece-content p {
    font-family: 'Work Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.5vw, 1.15rem);
    color: var(--parchment);
    letter-spacing: 0.02em;
    line-height: 1.85;
}

.puzzle-piece .hud-brackets {
    top: 5%;
    left: 5%;
    width: 90%;
    height: 90%;
}

.puzzle-piece .coord-readout {
    bottom: 8%;
    right: 8%;
}

/* === The Win === */
#win {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: var(--dusk-end);
    position: relative;
    overflow: hidden;
    animation: win-breathe 4s ease-in-out infinite;
}

@keyframes win-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.005); }
}

#win-assembly {
    position: absolute;
    width: 200px;
    height: 200px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 4px;
    opacity: 0;
    transition: opacity 1.5s ease;
}

#win-assembly.visible {
    opacity: 0.4;
}

.win-thumb {
    border-radius: 2px;
}

.win-thumb.t1 {
    background: linear-gradient(135deg, var(--twilight), var(--forest));
    transform: translate(-80px, -60px);
    transition: transform 1.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.win-thumb.t2 {
    background: linear-gradient(225deg, var(--dusk), var(--gold));
    transform: translate(80px, -40px);
    transition: transform 1.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s;
}

.win-thumb.t3 {
    background: linear-gradient(45deg, var(--forest), var(--dusk-end));
    transform: translate(-60px, 60px);
    transition: transform 1.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s;
}

.win-thumb.t4 {
    background: linear-gradient(315deg, var(--gold), var(--twilight));
    transform: translate(60px, 80px);
    transition: transform 1.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s;
}

#win-assembly.assembled .win-thumb {
    transform: translate(0, 0);
}

#win-word {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(5rem, 20vw, 15rem);
    color: var(--cyan);
    letter-spacing: 0.08em;
    text-shadow: 0 0 60px rgba(0, 240, 255, 0.4);
    opacity: 0;
    transition: opacity 1.5s ease, color 3s ease, text-shadow 3s ease;
    z-index: 2;
    position: relative;
}

#win-word.visible {
    opacity: 1;
}

#win-word.golden {
    color: var(--gold);
    text-shadow: 0 0 60px rgba(212, 165, 116, 0.4), 0 0 120px rgba(212, 165, 116, 0.2);
}

#win-hud-frame {
    position: absolute;
    top: 20%;
    left: 20%;
    width: 60%;
    height: 60%;
    pointer-events: none;
}

#win-hud-frame .bracket {
    width: 40px;
    height: 40px;
    border-color: var(--cyan);
    transition: border-color 0.5s ease, opacity 0.8s ease;
}

#win-hud-frame.active .bracket {
    opacity: 0.7;
    transform: translate(0, 0);
    animation: win-flicker 2s ease-in-out infinite;
}

#win-hud-frame.golden .bracket {
    border-color: var(--gold);
    animation: none;
    opacity: 0.6;
}

@keyframes win-flicker {
    0%, 90%, 100% { border-color: var(--cyan); }
    45% { border-color: var(--gold); }
    50% { border-color: var(--cyan); }
    55% { border-color: var(--gold); }
}

#win-readout {
    position: absolute;
    bottom: 12%;
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(0.65rem, 1vw, 0.8rem);
    color: var(--gold);
    letter-spacing: 0.06em;
    opacity: 0;
    transition: opacity 1s ease 2s;
}

#win-readout.visible {
    opacity: 0.7;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .puzzle-piece {
        opacity: 1;
        transform: none;
    }

    .letter {
        opacity: 1;
    }
}
