/* =============================================
   adhoc.quest - Surrealist Cartography
   ============================================= */

/* CSS Custom Properties */
:root {
    --void: #0b0c2a;
    --deep-nav: #1a2744;
    --twilight: #2d1b3d;
    --carto-blue: #4a6fa5;
    --amber: #c4956a;
    --parchment: #e8e0d4;
    --annotation-red: #a34a3f;
    --contour: #2a2d5e;

    --font-headline: 'Syne', sans-serif;
    --font-body: 'Crimson Pro', serif;
    --font-annotation: 'Caveat', cursive;

    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--void);
    color: var(--parchment);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.8;
    font-weight: 400;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Grain overlay via SVG noise texture */
.grain-filter-svg {
    position: fixed;
    width: 0;
    height: 0;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    opacity: 0.04;
    pointer-events: none;
    z-index: 9999;
}

/* Section base */
.section {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* Section labels */
.section-label {
    position: absolute;
    top: 40px;
    left: 4%;
    z-index: 10;
}

/* Annotation style (Caveat handwriting) */
.annotation {
    font-family: var(--font-annotation);
    color: var(--annotation-red);
    font-size: 18px;
    font-weight: 400;
    display: inline-block;
}

/* =============================================
   Section 1: Opening Viewport
   ============================================= */
.section-opening {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--void);
    position: relative;
}

/* Topographic background container */
.topo-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.topo-bg svg {
    width: 100%;
    height: 100%;
}

/* Compass container */
.compass-container {
    position: relative;
    z-index: 2;
    width: clamp(150px, 25vw, 280px);
    height: clamp(150px, 25vw, 280px);
    margin-bottom: 2rem;
}

.compass-rose {
    width: 100%;
    height: 100%;
}

/* Compass draw animation - sequential path reveal */
.compass-draw {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: drawPath 3s ease-out forwards;
}

/* Stagger the draw animation for different elements */
.compass-draw:nth-child(1) { animation-delay: 0s; }
.compass-draw:nth-child(2) { animation-delay: 0.1s; }
.compass-draw:nth-child(3) { animation-delay: 0.15s; }
.compass-draw:nth-child(4) { animation-delay: 0.2s; }
.compass-draw:nth-child(5) { animation-delay: 0.3s; }
.compass-draw:nth-child(6) { animation-delay: 0.4s; }
.compass-draw:nth-child(7) { animation-delay: 0.5s; }
.compass-draw:nth-child(8) { animation-delay: 0.6s; }
.compass-draw:nth-child(9) { animation-delay: 0.7s; }
.compass-draw:nth-child(10) { animation-delay: 0.75s; }
.compass-draw:nth-child(11) { animation-delay: 0.8s; }
.compass-draw:nth-child(12) { animation-delay: 0.85s; }

@keyframes drawPath {
    to {
        stroke-dashoffset: 0;
    }
}

/* Compass needle spin then settle */
.compass-needle {
    transform-origin: 200px 200px;
    animation: needleSpin 2.2s var(--spring) forwards;
}

@keyframes needleSpin {
    0% { transform: rotate(0deg); opacity: 0; }
    15% { opacity: 1; }
    50% { transform: rotate(390deg); }
    75% { transform: rotate(352deg); }
    90% { transform: rotate(362deg); }
    100% { transform: rotate(360deg); }
}

/* Opening text */
.opening-text {
    position: relative;
    z-index: 3;
    text-align: center;
}

.site-title {
    font-family: var(--font-headline);
    font-weight: 800;
    font-size: clamp(14vw, 18vw, 200px);
    letter-spacing: -0.02em;
    color: var(--parchment);
    line-height: 0.9;
    opacity: 0;
    animation: fadeInUp 1.2s ease-out 1.5s forwards;
}

.site-subtitle {
    font-family: var(--font-annotation);
    font-size: clamp(20px, 3vw, 32px);
    color: var(--amber);
    margin-top: 1rem;
    opacity: 0;
    /* JS will override this to do letter-by-letter */
    animation: fadeInLetters 2s ease-out 2.5s forwards;
}

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

@keyframes fadeInLetters {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =============================================
   Section 2: The Departure (broken grid)
   ============================================= */
.section-departure {
    min-height: 150vh;
    background: linear-gradient(180deg,
        var(--void) 0%,
        var(--deep-nav) 30%,
        var(--deep-nav) 60%,
        var(--void) 100%
    );
    padding: 10vh 0;
    position: relative;
}

.departure-grid {
    position: relative;
    width: 100%;
    min-height: 130vh;
}

/* Expedition cards - broken grid, tilted, pinned look */
.expedition-card {
    position: absolute;
    width: clamp(280px, 28vw, 420px);
    padding: 2.5rem 2rem;
    background: rgba(26, 39, 68, 0.45);
    border: 1px solid rgba(74, 111, 165, 0.2);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.8s ease, transform 0.8s var(--spring), border-color 0.4s ease;
}

.expedition-card.revealed {
    opacity: 1;
}

/* Card positions: deliberately misaligned per design */
.card-left {
    left: 8%;
    top: 10%;
    transform: rotate(-3deg) translateX(-80px);
}
.card-left.revealed {
    transform: rotate(-3deg) translateX(0);
}

.card-center {
    left: 45%;
    top: 35%;
    transform: rotate(1deg) translateY(60px) translateX(-50%);
}
.card-center.revealed {
    transform: rotate(1deg) translateY(0) translateX(-50%);
}

.card-right {
    left: 72%;
    top: 60%;
    transform: rotate(2deg) translateX(80px);
}
.card-right.revealed {
    transform: rotate(2deg) translateX(0);
}

.card-date {
    font-family: var(--font-annotation);
    color: var(--amber);
    font-size: 16px;
    margin-bottom: 0.25rem;
}

.card-heading {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: clamp(22px, 3vw, 36px);
    letter-spacing: -0.02em;
    color: var(--parchment);
    margin-bottom: 1rem;
}

.card-body {
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.75;
    color: rgba(232, 224, 212, 0.85);
}

.card-annotation {
    display: block;
    font-family: var(--font-annotation);
    color: var(--annotation-red);
    font-size: 16px;
    margin-top: 1rem;
}

/* Tilt 3D on card hover */
.expedition-card:hover {
    border-color: rgba(196, 149, 106, 0.3);
}

/* Margin notes */
.margin-note {
    position: absolute;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.margin-note.revealed {
    opacity: 1;
}

.margin-note-left {
    left: 2%;
    top: 75%;
}

.margin-note-right {
    right: 2%;
    top: 40%;
}

.margin-note-departure-right {
    top: 18%;
}

.margin-note .annotation {
    font-size: 16px;
    line-height: 1.6;
    opacity: 0.7;
}

/* =============================================
   Section 3: The Territory (generative map)
   ============================================= */
.section-territory {
    min-height: 200vh;
    background: linear-gradient(180deg,
        var(--void) 0%,
        var(--deep-nav) 25%,
        var(--twilight) 55%,
        var(--deep-nav) 80%,
        var(--void) 100%
    );
    position: relative;
    padding: 10vh 0;
}

.territory-map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.territory-map line {
    transition: opacity 0.5s ease;
}

.territory-map circle {
    transition: opacity 0.4s ease, r 0.3s var(--spring);
}

.map-annotations {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

.map-label {
    position: absolute;
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s ease;
    pointer-events: none;
    transform: translateY(10px);
}

.map-label.visible {
    opacity: 1;
    transform: translateY(0);
}

.map-label .annotation {
    font-size: 17px;
    color: var(--amber);
    text-shadow: 0 0 24px rgba(11, 12, 42, 0.95), 0 0 48px rgba(11, 12, 42, 0.7);
}

/* Pin markers at map nodes */
.pin-markers {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

.pin-marker {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid var(--amber);
    background: var(--void);
    transform: translate(-50%, -50%);
    transition: width 0.3s var(--spring), height 0.3s var(--spring), box-shadow 0.3s ease;
    pointer-events: auto;
    cursor: pointer;
    opacity: 0;
}

.pin-marker.visible {
    opacity: 1;
}

.pin-marker:hover {
    width: 16px;
    height: 16px;
    box-shadow: 0 0 32px rgba(196, 149, 106, 0.2);
}

/* =============================================
   Section 4: Field Notes (timeline-vertical)
   ============================================= */
.section-fieldnotes {
    min-height: 180vh;
    position: relative;
    padding: 10vh 0;
}

/* Left two-thirds gradient field */
.fieldnotes-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 66.66%;
    height: 100%;
    background: linear-gradient(180deg,
        var(--void) 0%,
        var(--deep-nav) 25%,
        var(--twilight) 50%,
        var(--deep-nav) 75%,
        var(--void) 100%
    );
    z-index: 0;
}

/* Timeline on the right third */
.fieldnotes-timeline {
    position: relative;
    width: 50%;
    margin-left: auto;
    margin-right: 6%;
    z-index: 2;
    padding: 5vh 0;
}

.timeline-line {
    position: absolute;
    left: 0;
    top: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg,
        transparent 0%,
        var(--carto-blue) 10%,
        var(--carto-blue) 90%,
        transparent 100%
    );
    opacity: 0.3;
}

/* Timeline entries slide in from right with spring easing */
.timeline-entry {
    position: relative;
    padding-left: 40px;
    margin-bottom: 8vh;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.6s ease, transform 0.8s var(--spring);
}

.timeline-entry.revealed {
    opacity: 1;
    transform: translateX(0);
}

.entry-marker {
    position: absolute;
    left: -5px;
    top: 8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--amber);
    background: var(--void);
    z-index: 3;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.timeline-entry:hover .entry-marker {
    background: var(--amber);
    box-shadow: 0 0 12px rgba(196, 149, 106, 0.3);
}

.entry-time {
    font-family: var(--font-annotation);
    color: var(--amber);
    font-size: 18px;
    display: block;
    margin-bottom: 0.25rem;
}

.entry-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: clamp(20px, 3vw, 32px);
    letter-spacing: -0.02em;
    color: var(--parchment);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: color 0.3s ease;
    user-select: none;
}

.entry-title:hover {
    color: var(--amber);
}

/* Expandable content - progressive disclosure */
.entry-expandable {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease, opacity 0.4s ease;
    opacity: 0;
}

.entry-expandable.expanded {
    max-height: 300px;
    opacity: 1;
}

.entry-expandable p {
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.75;
    color: rgba(232, 224, 212, 0.8);
    padding-top: 0.5rem;
}

/* =============================================
   Section 5: The Return
   ============================================= */
.section-return {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--void);
    position: relative;
}

.topo-bg-converge svg {
    width: 100%;
    height: 100%;
}

.compass-return {
    width: clamp(120px, 20vw, 240px);
    height: clamp(120px, 20vw, 240px);
    margin-bottom: 3rem;
}

/* Slow continuous spin at 0.5 rpm = 120s per rotation */
.compass-rose-final {
    animation: slowSpin 120s linear infinite;
}

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

.return-text {
    position: relative;
    z-index: 3;
    font-family: var(--font-annotation);
    font-size: clamp(24px, 4vw, 48px);
    color: var(--amber);
    opacity: 0;
    transition: opacity 1.2s ease;
}

.return-text.visible {
    opacity: 1;
}

/* =============================================
   Link styling (for any links that might appear)
   ============================================= */
a {
    color: var(--carto-blue);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:visited {
    color: var(--annotation-red);
}

a:hover {
    color: var(--amber);
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 900px) {
    .expedition-card {
        position: relative;
        left: auto !important;
        top: auto !important;
        width: 90%;
        margin: 3vh auto;
        transform: none !important;
    }
    .expedition-card.revealed {
        transform: none !important;
    }

    .departure-grid {
        min-height: auto;
        display: flex;
        flex-direction: column;
        padding: 5vh 0;
    }

    .fieldnotes-gradient {
        width: 100%;
    }

    .fieldnotes-timeline {
        width: 85%;
        margin: 0 auto;
    }

    .margin-note {
        display: none;
    }

    .card-center {
        transform: none !important;
    }
    .card-center.revealed {
        transform: none !important;
    }
}

@media (max-width: 600px) {
    .site-title {
        font-size: clamp(48px, 14vw, 120px);
    }

    .compass-container {
        width: 120px;
        height: 120px;
    }

    .compass-return {
        width: 100px;
        height: 100px;
    }

    .fieldnotes-timeline {
        width: 90%;
        margin-right: 5%;
    }
}
