/* ============================================
   p9r.dev - Crystalline Nordic Collage
   Scandinavian + Jewel-Tones + Parallax
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Palette */
    --snow-linen: #f5f2ed;
    --midnight-garnet: #1e1020;
    --graphite-ink: #2a2a2e;
    --worn-stone: #7a7670;
    --sapphire-night: #1a3a5c;
    --emerald-depth: #1a5c3a;
    --worn-garnet: #8c2f4a;
    --amethyst-dusk: #5c3a7a;
    --topaz-glow: #b8860b;
    --birch-thread: #c8c0b4;

    /* Typography */
    --font-display: 'Nunito', sans-serif;
    --font-body: 'Karla', sans-serif;
    --font-mono: 'Martian Mono', monospace;

    /* Parallax */
    --scroll-offset: 0;
    --scroll-shadow-y: 4px;
    --panel-progress: 0;

    /* Cursor */
    --cursor-x: -100px;
    --cursor-y: -100px;
    --cursor-ring-color: var(--sapphire-night);
}

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

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    cursor: none;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    color: var(--graphite-ink);
    background-color: var(--snow-linen);
    overflow-x: hidden;
    cursor: none;
    line-height: 1.7;
    letter-spacing: 0.01em;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
}

/* --- Grid Overlay --- */
.grid-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    background-image:
        repeating-linear-gradient(
            to right,
            rgba(200, 192, 180, 0.15) 0px,
            rgba(200, 192, 180, 0.15) 1px,
            transparent 1px,
            transparent calc(100% / 12)
        );
    clip-path: inset(0 0 100% 0);
    transition: opacity 0.3s ease;
}

.grid-overlay.visible {
    opacity: 1;
    animation: gridReveal 1200ms ease-out forwards;
}

@keyframes gridReveal {
    from { clip-path: inset(0 0 100% 0); }
    to { clip-path: inset(0 0 0% 0); }
}

/* --- Custom Cursor --- */
.cursor-dot {
    position: fixed;
    width: 8px;
    height: 8px;
    background-color: var(--topaz-glow);
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
    mix-blend-mode: difference;
    transform: translate(-50%, -50%) scale(0);
    left: var(--cursor-x);
    top: var(--cursor-y);
    transition: width 0.3s ease, height 0.3s ease;
}

.cursor-dot.active {
    transform: translate(-50%, -50%) scale(1);
}

.cursor-dot.hover {
    width: 12px;
    height: 12px;
}

.cursor-ring {
    position: fixed;
    width: 32px;
    height: 32px;
    border: 1px solid var(--cursor-ring-color);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%) scale(0);
    left: var(--cursor-x);
    top: var(--cursor-y);
    transition: width 0.3s ease, height 0.3s ease, border-color 0.4s ease, background-color 0.3s ease;
}

.cursor-ring.active {
    transform: translate(-50%, -50%) scale(1);
}

.cursor-ring.hover {
    width: 56px;
    height: 56px;
    background-color: rgba(26, 58, 92, 0.08);
}

.cursor-ring.hover[data-jewel="sapphire"] {
    background-color: rgba(26, 58, 92, 0.08);
}
.cursor-ring.hover[data-jewel="emerald"] {
    background-color: rgba(26, 92, 58, 0.08);
}
.cursor-ring.hover[data-jewel="garnet"] {
    background-color: rgba(140, 47, 74, 0.08);
}
.cursor-ring.hover[data-jewel="amethyst"] {
    background-color: rgba(92, 58, 122, 0.08);
}
.cursor-ring.hover[data-jewel="topaz"] {
    background-color: rgba(184, 134, 11, 0.08);
}

/* --- Intersection Markers --- */
#intersection-markers {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.crosshair {
    position: absolute;
    width: 16px;
    height: 16px;
    opacity: 0.2;
    animation: crosshairPulse 2s infinite ease-in-out;
    animation-play-state: running;
}

.crosshair::before,
.crosshair::after {
    content: '';
    position: absolute;
    background-color: var(--topaz-glow);
}

.crosshair::before {
    width: 0.5px;
    height: 16px;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.crosshair::after {
    width: 16px;
    height: 0.5px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.crosshair.paused {
    animation-play-state: paused;
}

@keyframes crosshairPulse {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.6; }
}

/* --- Parallax Panels --- */
.parallax-panel {
    position: relative;
    min-height: 100vh;
    width: 100%;
    overflow: hidden;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-bg {
    position: absolute;
    top: -20%;
    left: 0;
    width: 100%;
    height: 140%;
    z-index: 0;
    transition: background-color 0.2s ease-out;
}

.panel-hero .panel-bg {
    background-color: var(--snow-linen);
}

.panel-chapter[data-panel="1"] .panel-bg {
    background-color: var(--snow-linen);
}

.panel-chapter[data-panel="2"] .panel-bg {
    background-color: #f3f0ea;
}

.panel-chapter[data-panel="3"] .panel-bg {
    background-color: #f0ede6;
}

.panel-chapter[data-panel="4"] .panel-bg {
    background-color: #edeae3;
}

.panel-bg-dark {
    background-color: var(--midnight-garnet);
}

/* --- Section Dividers --- */
.section-divider {
    position: absolute;
    top: 0;
    left: calc(100% / 12);
    right: calc(100% / 12);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 3;
    padding-top: 2rem;
}

.section-label {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sapphire-night);
    white-space: nowrap;
}

.divider-line {
    flex: 1;
    height: 0.5px;
    opacity: 0.6;
}

/* --- Hero Panel --- */
.panel-hero {
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.parallax-bg-plane {
    position: absolute;
    z-index: 1;
}

.sapphire-plane {
    width: 45vw;
    height: 55vh;
    background-color: rgba(26, 58, 92, 0.12);
    top: 15%;
    left: 25%;
}

.hero-title-wrap {
    position: absolute;
    top: 18%;
    left: calc(100% / 12 * 2);
    z-index: 5;
}

.hero-title {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sapphire-night);
}

.hero-title .char {
    display: inline-block;
    opacity: 0;
}

.hero-title .char.visible {
    opacity: 1;
}

/* --- Collage System --- */
.collage-container {
    position: relative;
    width: clamp(300px, 50vw, 600px);
    height: clamp(300px, 50vh, 500px);
    z-index: 3;
}

.collage-piece {
    position: absolute;
    transition: transform 0.15s ease-out;
}

.collage-large {
    width: 50%;
    height: 60%;
    top: 10%;
    left: 5%;
}

.collage-medium-1 {
    width: 35%;
    height: 40%;
    top: 25%;
    right: 10%;
}

.collage-medium-2 {
    width: 30%;
    height: 35%;
    bottom: 10%;
    left: 25%;
}

.collage-rect {
    width: 100%;
    height: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.3s ease;
}

/* Jewel tone fills */
.sapphire-fill { background-color: rgba(26, 58, 92, 0.85); }
.emerald-fill { background-color: rgba(26, 92, 58, 0.85); }
.garnet-fill { background-color: rgba(140, 47, 74, 0.85); }
.amethyst-fill { background-color: rgba(92, 58, 122, 0.85); }
.topaz-fill { background-color: rgba(184, 134, 11, 0.85); }

/* Multiply blends */
.sapphire-multiply { background-color: rgba(26, 58, 92, 0.65); mix-blend-mode: multiply; }
.emerald-multiply { background-color: rgba(26, 92, 58, 0.65); mix-blend-mode: multiply; }
.garnet-multiply { background-color: rgba(140, 47, 74, 0.65); mix-blend-mode: multiply; }
.amethyst-multiply { background-color: rgba(92, 58, 122, 0.65); mix-blend-mode: multiply; }
.topaz-multiply { background-color: rgba(184, 134, 11, 0.65); mix-blend-mode: multiply; }

/* Collage rules */
.collage-rule {
    position: absolute;
    background-color: var(--graphite-ink);
}

.collage-rule-h {
    width: 120%;
    height: 1px;
    top: 55%;
    left: -10%;
}

.collage-rule-v {
    width: 1px;
    height: 120%;
    left: 60%;
    top: -10%;
}

/* Collage text */
.collage-text-fragment {
    position: absolute;
    right: -20px;
    top: 20%;
    z-index: 4;
}

.mono-label {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sapphire-night);
}

.rotated {
    display: block;
    transform: rotate(-90deg);
    transform-origin: right top;
    white-space: nowrap;
}

/* --- Chapter Grid --- */
.chapter-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: clamp(1.5rem, 3vw, 4rem);
    width: 100%;
    padding: 0 calc(100% / 12);
    z-index: 3;
    align-items: center;
    min-height: 80vh;
}

.chapter-content {
    grid-column: span 5;
    padding: 2rem 0;
}

.chapter-collage {
    grid-column: span 7;
    position: relative;
    width: 100%;
    height: clamp(280px, 45vh, 450px);
}

/* --- Typography --- */
.section-heading {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--graphite-ink);
    margin-bottom: 1.5rem;
}

.section-heading .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.section-heading .char.visible {
    opacity: 1;
    transform: translateY(0);
}

.section-heading .char-space {
    display: inline-block;
    width: 0.3em;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.7;
    letter-spacing: 0.01em;
    color: var(--graphite-ink);
    max-width: 48ch;
}

/* --- Closing Panel --- */
.panel-closing {
    background-color: var(--midnight-garnet);
    flex-direction: column;
    gap: 1.5rem;
}

.closing-content {
    text-align: center;
    z-index: 3;
}

.closing-heading {
    color: var(--snow-linen);
    font-size: clamp(2.8rem, 7vw, 6rem);
    margin-bottom: 1rem;
}

.closing-label {
    color: var(--topaz-glow);
    opacity: 0.7;
}

/* Panel-specific label colors */
[data-panel="1"] .section-label { color: var(--emerald-depth); }
[data-panel="2"] .section-label { color: var(--worn-garnet); }
[data-panel="3"] .section-label { color: var(--amethyst-dusk); }
[data-panel="4"] .section-label { color: var(--topaz-glow); }

[data-panel="2"] .collage-text-fragment .mono-label { color: var(--worn-garnet); }
[data-panel="3"] .collage-text-fragment .mono-label { color: var(--amethyst-dusk); }
[data-panel="4"] .collage-text-fragment .mono-label { color: var(--topaz-glow); }

/* --- Entry Animation --- */
.panel-hero .collage-piece,
.panel-hero .collage-rule,
.panel-hero .collage-text-fragment,
.panel-hero .parallax-bg-plane {
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.panel-hero .collage-piece.entered { opacity: 1; }
.panel-hero .collage-rule.entered { opacity: 1; }
.panel-hero .collage-text-fragment.entered { opacity: 1; }
.panel-hero .parallax-bg-plane.entered { opacity: 1; }

.panel-hero .collage-large { transform: translateX(-40px); }
.panel-hero .collage-large.entered { transform: translateX(0); }

.panel-hero .collage-medium-1,
.panel-hero .collage-medium-2 { transform: translateY(30px); }
.panel-hero .collage-medium-1.entered,
.panel-hero .collage-medium-2.entered { transform: translateY(0); }

.panel-hero .collage-text-fragment { transform: translateX(20px); }
.panel-hero .collage-text-fragment.entered { transform: translateX(0); }

.panel-hero .collage-rule { transform: scaleX(0); }
.panel-hero .collage-rule.entered { transform: scaleX(1); }

.panel-hero .collage-rule-v { transform: scaleY(0); }
.panel-hero .collage-rule-v.entered { transform: scaleY(1); }

/* --- Mobile Adaptation --- */
@media (max-width: 768px) {
    .grid-overlay {
        background-image:
            repeating-linear-gradient(
                to right,
                rgba(200, 192, 180, 0.15) 0px,
                rgba(200, 192, 180, 0.15) 1px,
                transparent 1px,
                transparent calc(100% / 4)
            );
    }

    .chapter-grid {
        grid-template-columns: 1fr;
        padding: 2rem calc(100% / 6);
        gap: 2rem;
    }

    .chapter-content {
        grid-column: 1;
        order: 1;
    }

    .chapter-collage {
        grid-column: 1;
        order: 2;
        height: 300px;
    }

    .collage-container {
        width: 90vw;
        height: 300px;
    }

    .sapphire-plane {
        width: 70vw;
        height: 40vh;
    }

    .cursor-dot,
    .cursor-ring {
        display: none;
    }

    html, body {
        cursor: auto;
    }

    .section-divider {
        left: calc(100% / 6);
        right: calc(100% / 6);
    }
}
