/* ========================================================================
   aiice.quest — a quest through artificial ice
   Scandinavian restraint meets Alice in a crystalline AI wonderland
   Interactive elements use IntersectionObserver for line-by-line stagger
   reveals from `translateY(20px while named faces reference (Google Fonts)
   only as font-family names with system fallbacks.
   ======================================================================== */

/* ---------- Tokens ---------- */
:root {
    --c-midnight-fjord: #0a0e1a;
    --c-frozen-slate: #1a1f35;
    --c-sapphire-fracture: #2563eb;
    --c-amethyst-shard: #7c3aed;
    --c-emerald-glacier: #059669;
    --c-ruby-facet: #dc2626;
    --c-frost-white: #e8ecf4;
    --c-glacier-gray: #94a3b8;

    --f-display: "Archivo Black", Impact, Haettenschweiler, "Arial Black", system-ui, sans-serif;
    --f-serif: "Cormorant Garamond", Garamond, Georgia, "Times New Roman", serif;
    --f-ui: "Space Grotesk", "Trebuchet MS", Arial, system-ui, sans-serif;

    --spring-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --spring-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
    background: var(--c-midnight-fjord);
    color: var(--c-frost-white);
    font-family: var(--f-serif);
    overflow-x: hidden;
    min-height: 100%;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: var(--c-sapphire-fracture);
    color: var(--c-frost-white);
}

/* ---------- Global layout ---------- */
.spreads {
    display: block;
    position: relative;
}

.spread {
    position: relative;
    width: 100%;
    min-height: 100vh;
    overflow: hidden;
    background: var(--c-midnight-fjord);
}

/* ---------- Shared label ---------- */
.label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--f-ui);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.22em;
    color: var(--c-glacier-gray);
    text-transform: uppercase;
}

.label-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--c-sapphire-fracture);
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

/* ---------- Fracture lines ---------- */
.fracture-line {
    position: absolute;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--c-sapphire-fracture), transparent);
    pointer-events: none;
    opacity: 0.55;
}

.fracture-line-1 {
    top: 28%;
    left: -10%;
    width: 60%;
    transform: rotate(12deg);
}

.fracture-line-2 {
    top: 72%;
    left: -5%;
    width: 80%;
    transform: rotate(-24deg);
    opacity: 0.3;
}

.fracture-line-3 {
    top: 20%;
    left: -5%;
    width: 110%;
    transform: rotate(12deg);
    opacity: 0.4;
}

.fracture-line-4 {
    bottom: 18%;
    left: -10%;
    width: 120%;
    transform: rotate(-12deg);
    opacity: 0.25;
}

/* ========================================================================
   SPREAD 1 — Through the Looking-Glass
   ======================================================================== */
.spread-1 {
    display: grid;
    grid-template-columns: 60fr 40fr;
    min-height: 100vh;
    position: relative;
}

.spread-1-left {
    position: relative;
    background: var(--c-frozen-slate);
    overflow: hidden;
}

.tessellation-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.diagonal-cut {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 60%;
    width: 200px;
    transform: translateX(-50%) rotate(12deg);
    transform-origin: center;
    background: linear-gradient(90deg,
        var(--c-frozen-slate) 0%,
        var(--c-frozen-slate) 49.5%,
        var(--c-sapphire-fracture) 50%,
        var(--c-midnight-fjord) 50.5%,
        var(--c-midnight-fjord) 100%);
    pointer-events: none;
    z-index: 2;
}

.spread-1-right {
    position: relative;
    background: var(--c-midnight-fjord);
    padding: 48px 64px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 3;
}

.label-top {
    align-self: flex-start;
}

.logotype {
    font-family: var(--f-display);
    font-weight: 400;
    font-size: clamp(4rem, 9vw, 7rem);
    line-height: 0.95;
    letter-spacing: -0.03em;
    color: var(--c-frost-white);
    text-transform: lowercase;
    margin-bottom: 24px;
}

.glyph-i {
    color: var(--c-sapphire-fracture);
    display: inline-block;
    animation: iGlyphBreath 6s var(--spring-bounce) infinite;
}

.glyph-i:nth-of-type(2) {
    animation-delay: 0.6s;
    color: var(--c-sapphire-fracture);
}

@keyframes iGlyphBreath {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.invitation {
    font-family: var(--f-serif);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.1rem, 1.6vw, 1.4rem);
    color: var(--c-glacier-gray);
    letter-spacing: 0.01em;
    opacity: 0;
    animation: fadeInDelay 2s var(--spring-ease) 2s forwards;
    max-width: 32ch;
}

@keyframes fadeInDelay {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.meta-block {
    font-family: var(--f-ui);
    font-size: 11px;
    letter-spacing: 0.3em;
    color: var(--c-glacier-gray);
    opacity: 0.6;
    text-transform: uppercase;
    padding-top: 16px;
    border-top: 1px solid rgba(232, 236, 244, 0.1);
}

.chevron-wrap {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.chevron-label {
    font-family: var(--f-ui);
    font-size: 10px;
    letter-spacing: 0.4em;
    color: var(--c-glacier-gray);
    text-transform: uppercase;
}

.chevron {
    position: relative;
    width: 22px;
    height: 12px;
    animation: chevronPulse 2.4s var(--spring-bounce) infinite;
}

.chevron-arm {
    position: absolute;
    top: 0;
    width: 14px;
    height: 1px;
    background: var(--c-frost-white);
    transform-origin: 0 0;
}

.chevron-arm-left {
    left: 50%;
    transform: translateX(-100%) rotate(45deg);
}

.chevron-arm-right {
    left: 50%;
    transform: translateX(0) rotate(135deg);
}

@keyframes chevronPulse {
    0%, 100% { transform: translateY(0); opacity: 0.7; }
    50% { transform: translateY(6px); opacity: 1; }
}

/* Polygon crystallization */
.tessellation-svg polygon {
    transform-origin: center;
    transform-box: fill-box;
    transform: scale(0);
    animation: crystallize 0.6s var(--spring-bounce) forwards;
    stroke: var(--c-frost-white);
    stroke-width: 1;
    stroke-opacity: 0.08;
}

@keyframes crystallize {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.06); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ========================================================================
   Alice Falling Silhouette Transition
   ======================================================================== */
.alice-transition {
    position: relative;
    width: 100%;
    height: 0;
    overflow: visible;
    z-index: 5;
    pointer-events: none;
}

.alice-silhouette {
    position: absolute;
    left: 50%;
    top: -48px;
    width: 48px;
    height: 96px;
    transform: translateX(-50%) translateY(-120vh);
    opacity: 0;
    transition: none;
}

.alice-silhouette.is-falling {
    animation: aliceFall 1.6s var(--spring-bounce) forwards;
}

@keyframes aliceFall {
    0% { transform: translateX(-50%) translateY(-120vh) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    80% { opacity: 1; }
    100% { transform: translateX(-50%) translateY(0vh) rotate(12deg); opacity: 0.8; }
}

.alice-tri {
    fill: var(--c-frost-white);
    fill-opacity: 0.9;
    stroke: var(--c-sapphire-fracture);
    stroke-width: 0.8;
}

.alice-tri:nth-child(odd) {
    fill: var(--c-sapphire-fracture);
    fill-opacity: 0.75;
    stroke: var(--c-frost-white);
}

/* ========================================================================
   SPREAD 2 — The Descent
   ======================================================================== */
.spread-2 {
    display: grid;
    grid-template-columns: 25fr 75fr;
    background: var(--c-midnight-fjord);
    position: relative;
    padding: 80px 0;
}

.spread-2-left {
    position: relative;
    padding: 64px 24px 64px 48px;
    display: flex;
    flex-direction: column;
    gap: 120px;
    align-items: flex-start;
}

.big-number {
    font-family: var(--f-display);
    font-size: clamp(5rem, 10vw, 9rem);
    line-height: 1;
    letter-spacing: -0.04em;
    color: rgba(148, 163, 184, 0.3);
    transition: color 0.8s var(--spring-ease), transform 0.8s var(--spring-bounce);
}

.big-number.is-lit {
    color: rgba(37, 99, 235, 0.65);
    transform: translateX(12px);
}

.spread-2-right {
    position: relative;
    background: var(--c-frozen-slate);
    padding: 80px 64px 80px 80px;
    display: flex;
    flex-direction: column;
    gap: 56px;
    justify-content: center;
    border-left: 1px solid rgba(37, 99, 235, 0.2);
}

.label-descent {
    margin-bottom: 16px;
}

.descent-text {
    display: flex;
    flex-direction: column;
    gap: 48px;
}

.descent-paragraph {
    font-family: var(--f-serif);
    font-weight: 400;
    font-size: clamp(1.25rem, 1.6vw, 1.55rem);
    line-height: 1.7;
    color: var(--c-frost-white);
    position: relative;
    padding-left: 28px;
}

.descent-paragraph::before {
    content: attr(data-number);
    position: absolute;
    left: 0;
    top: 12px;
    font-family: var(--f-ui);
    font-size: 10px;
    letter-spacing: 0.3em;
    color: var(--c-sapphire-fracture);
}

.descent-paragraph .line {
    display: block;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.9s var(--spring-ease), transform 0.9s var(--spring-bounce);
}

.descent-paragraph .line.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================================================
   SPREAD 3 — The Tessellation Chamber
   ======================================================================== */
.spread-3 {
    background: var(--c-midnight-fjord);
    padding: 0;
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.chamber-label {
    position: absolute;
    top: 32px;
    left: 48px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--f-ui);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.22em;
    color: var(--c-glacier-gray);
    text-transform: uppercase;
    z-index: 10;
    mix-blend-mode: difference;
}

.tessellation-chamber {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 100vh;
    overflow: hidden;
}

.chamber-cell {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    transition:
        transform 0.55s var(--spring-bounce),
        filter 0.55s var(--spring-ease),
        z-index 0s 0.55s;
    will-change: transform;
    border: 1px solid rgba(232, 236, 244, 0.05);
}

.chamber-cell .cell-word {
    font-family: var(--f-ui);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--c-frost-white);
    text-align: center;
    padding: 0 12px;
    transition: opacity 0.4s var(--spring-ease), transform 0.4s var(--spring-ease);
    z-index: 2;
    position: relative;
    mix-blend-mode: normal;
}

.chamber-cell .cell-reveal {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    font-family: var(--f-serif);
    font-style: italic;
    font-size: clamp(0.9rem, 1.1vw, 1.1rem);
    color: var(--c-frost-white);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.4s var(--spring-ease) 0.1s, transform 0.4s var(--spring-bounce) 0.1s;
    pointer-events: none;
    text-align: center;
    line-height: 1.4;
    background: rgba(10, 14, 26, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 3;
}

.chamber-cell:hover {
    transform: scale(1.08);
    z-index: 20;
    filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.55));
    transition:
        transform 0.55s var(--spring-bounce),
        filter 0.55s var(--spring-ease),
        z-index 0s;
}

.chamber-cell:hover .cell-word {
    opacity: 0;
    transform: translateY(-6px);
}

.chamber-cell:hover .cell-reveal {
    opacity: 1;
    transform: translateY(0);
}

/* Fill variants */
.chamber-cell.fill-sapphire { background: var(--c-sapphire-fracture); }
.chamber-cell.fill-amethyst { background: var(--c-amethyst-shard); }
.chamber-cell.fill-emerald { background: var(--c-emerald-glacier); }
.chamber-cell.fill-slate { background: var(--c-frozen-slate); }
.chamber-cell.fill-ruby { background: var(--c-ruby-facet); }

/* ========================================================================
   SPREAD 4 — The Mirror
   ======================================================================== */
.spread-4 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: relative;
    background: var(--c-midnight-fjord);
    min-height: 100vh;
    padding: 96px 0;
}

.mirror-divider {
    position: absolute;
    top: 64px;
    bottom: 64px;
    left: 50%;
    width: 1px;
    background: var(--c-sapphire-fracture);
    transform: translateX(-50%);
    z-index: 5;
    animation: mirrorPulse 4s var(--spring-ease) infinite;
}

@keyframes mirrorPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.mirror-left, .mirror-right {
    padding: 48px 64px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    justify-content: center;
}

.mirror-left {
    align-items: flex-start;
    text-align: left;
}

.mirror-right {
    align-items: flex-end;
    text-align: right;
}

.label-mirror {
    color: var(--c-glacier-gray);
}

.label-mirror-right {
    flex-direction: row-reverse;
}

.mirror-text {
    font-family: var(--f-serif);
    font-size: clamp(1.1rem, 1.4vw, 1.4rem);
    line-height: 1.7;
    max-width: 42ch;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.mirror-text em {
    color: var(--c-sapphire-fracture);
    font-style: italic;
}

.mirror-text-original {
    color: var(--c-frost-white);
    font-weight: 400;
}

.mirror-text-reflection {
    color: var(--c-glacier-gray);
    font-weight: 300;
    transition: letter-spacing 0.1s linear, color 0.8s var(--spring-ease);
}

.mirror-text-reflection em {
    color: var(--c-amethyst-shard);
}

/* ========================================================================
   SPREAD 5 — The Return
   ======================================================================== */
.spread-5 {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    padding: 64px 32px;
    background: var(--c-midnight-fjord);
    position: relative;
    gap: 80px;
}

.final-mark {
    width: 32px;
    height: 32px;
    animation: markRotate 12s linear infinite;
}

@keyframes markRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.final-statement {
    font-family: var(--f-display);
    font-weight: 400;
    font-size: clamp(4rem, 12vw, 10rem);
    line-height: 0.95;
    letter-spacing: -0.03em;
    color: var(--c-frost-white);
    text-transform: uppercase;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.final-word {
    display: block;
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.9s var(--spring-ease), transform 0.9s var(--spring-bounce);
}

.final-word.is-in {
    opacity: 1;
    transform: translateY(0);
}

.final-word-accent {
    color: var(--c-sapphire-fracture);
}

.final-footer {
    font-family: var(--f-ui);
    font-size: 14px;
    letter-spacing: 0.3em;
    color: var(--c-glacier-gray);
    text-transform: uppercase;
    margin-top: 40px;
}

/* ========================================================================
   Breath Hex (global loading/breath indicator)
   ======================================================================== */
.breath-hex {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 16px;
    height: 16px;
    z-index: 50;
    animation: hexBreath 3s var(--spring-bounce) infinite;
    opacity: 0.8;
}

.breath-hex svg {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes hexBreath {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ========================================================================
   Responsive
   ======================================================================== */
@media (max-width: 900px) {
    .spread-1 {
        grid-template-columns: 1fr;
        min-height: auto;
    }
    .spread-1-left {
        min-height: 60vh;
    }
    .spread-1-right {
        padding: 48px 32px;
        gap: 40px;
    }
    .diagonal-cut { display: none; }

    .spread-2 {
        grid-template-columns: 1fr;
        padding: 40px 0;
    }
    .spread-2-left {
        flex-direction: row;
        gap: 32px;
        padding: 32px 24px;
        justify-content: flex-start;
        overflow-x: auto;
    }
    .big-number { font-size: 4rem; }
    .spread-2-right {
        padding: 48px 32px;
    }

    .spread-4 {
        grid-template-columns: 1fr;
        padding: 48px 0;
    }
    .mirror-divider {
        display: none;
    }
    .mirror-left, .mirror-right {
        padding: 32px 24px;
        align-items: flex-start;
        text-align: left;
    }
    .mirror-text-reflection {
        direction: ltr;
    }

    .chamber-label {
        left: 24px;
        top: 24px;
    }
}

/* ========================================================================
   Reduced Motion
   ======================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001s !important;
    }
    .tessellation-svg polygon {
        transform: scale(1);
        opacity: 1;
    }
    .descent-paragraph .line {
        opacity: 1;
        transform: none;
    }
    .invitation {
        opacity: 1;
    }
    .final-word {
        opacity: 1;
        transform: none;
    }
}
