/* ============================================
   conc.quest v2 -- Topographies of Concurrency
   Neomorphic Cartography Design System
   ============================================ */

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

:root {
    /* Palette from DESIGN.md */
    --base-surface: #F5F0E8;          /* warm parchment cream */
    --raised-surface: #FDFBF7;        /* near-white warm */
    --contour-terra-cotta: #C4836A;   /* muted brick-orange */
    --deep-gorge: #3B2F25;            /* dark loam brown */
    --river-channel: #6B9DAD;         /* muted teal-slate */
    --plateau-shadow: #E2D9CC;        /* warm taupe */
    --annotation-stone: #8A7E6D;      /* warm stone gray */
    --ridge-highlight: #FFFFFF;       /* pure white */

    /* Neomorphic shadows */
    --neo-raised: 6px 6px 12px rgba(0, 0, 0, 0.08), -6px -6px 12px rgba(255, 255, 255, 0.95);
    --neo-raised-hover: 8px 8px 14px rgba(0, 0, 0, 0.1), -8px -8px 14px rgba(255, 255, 255, 0.97);
    --neo-inset: inset 4px 4px 8px rgba(0, 0, 0, 0.06), inset -4px -4px 8px rgba(255, 255, 255, 0.9);

    /* Typography */
    --font-headline: 'Outfit', sans-serif;
    --font-body: 'Source Serif 4', serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--base-surface);
    color: var(--deep-gorge);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.7;
    font-weight: 400;
    overflow-x: hidden;
}

/* --- Opening Overlay --- */
#opening-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--base-surface);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease-out, visibility 0.6s ease-out;
}

#opening-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#opening-contours {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#opening-contours path {
    stroke: var(--contour-terra-cotta);
    stroke-width: 0.8;
    fill: none;
    opacity: 0.2;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

#opening-contours path.animate {
    transition: stroke-dashoffset 1.8s ease-out;
    stroke-dashoffset: 0;
}

#opening-title-group {
    position: relative;
    z-index: 1;
    text-align: center;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

#opening-title-group.visible {
    opacity: 1;
    transform: translateY(0);
}

#opening-title {
    font-family: var(--font-headline);
    font-weight: 600;
    font-size: clamp(36px, 6vw, 72px);
    letter-spacing: -0.02em;
    color: var(--deep-gorge);
    text-shadow: none;
    transition: text-shadow 0.8s ease-out;
}

#opening-title.neo-shadow {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.08), -2px -2px 4px rgba(255, 255, 255, 0.9);
}

#opening-subtitle-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    opacity: 0;
    transition: opacity 0.5s ease-out;
}

#opening-subtitle-line.visible {
    opacity: 1;
}

.subtitle-connector {
    display: inline-block;
    width: 32px;
    height: 1px;
    background-color: var(--contour-terra-cotta);
    opacity: 0.4;
}

#opening-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(14px, 2vw, 22px);
    color: var(--annotation-stone);
    letter-spacing: 0.02em;
}

/* --- Legend Panel (Desktop) --- */
#legend-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 30vw;
    height: 100vh;
    background-color: var(--base-surface);
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: clamp(20px, 3vw, 40px);
    transform: translateX(-100%);
    transition: transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
    overflow-y: auto;
}

#legend-panel.visible {
    transform: translateX(0);
}

.legend-header {
    margin-bottom: 32px;
}

.legend-title {
    font-family: var(--font-headline);
    font-weight: 600;
    font-size: clamp(18px, 2vw, 28px);
    letter-spacing: -0.02em;
    color: var(--deep-gorge);
    margin-bottom: 4px;
}

.legend-label {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.01em;
    color: var(--annotation-stone);
    text-transform: uppercase;
}

.legend-items {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 12px;
    cursor: pointer;
    background-color: var(--base-surface);
    box-shadow: none;
    transition: box-shadow 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
}

.legend-item:hover,
.legend-item.active,
.legend-item.highlighted {
    box-shadow: var(--neo-raised);
    background-color: var(--raised-surface);
    transform: translateY(-1px);
}

.legend-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 10px;
    background-color: var(--base-surface);
    box-shadow: var(--neo-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.legend-icon svg {
    width: 100%;
    height: 100%;
}

.legend-item-label {
    font-family: var(--font-headline);
    font-weight: 500;
    font-size: 15px;
    color: var(--deep-gorge);
    flex: 1;
}

.legend-elevation {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 400;
    color: var(--annotation-stone);
    letter-spacing: 0.01em;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--base-surface);
    box-shadow: var(--neo-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.legend-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--plateau-shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.legend-footer .legend-label {
    font-size: 11px;
}

/* --- Mobile Legend Ribbon --- */
#legend-ribbon {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: var(--base-surface);
    z-index: 100;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 8px 12px;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ribbon-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 10px;
    background-color: var(--base-surface);
    box-shadow: var(--neo-inset);
    cursor: pointer;
    scroll-snap-align: start;
    padding: 6px;
    margin-right: 8px;
    transition: box-shadow 0.3s ease;
}

.ribbon-item:hover,
.ribbon-item.active {
    box-shadow: var(--neo-raised);
}

.ribbon-item svg {
    width: 100%;
    height: 100%;
}

/* --- Content Terrain --- */
#content-terrain {
    margin-left: 30vw;
    width: 70vw;
    min-height: 100vh;
    position: relative;
    background-color: var(--base-surface);
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

#content-terrain.visible {
    opacity: 1;
}

/* Background contour lines SVG */
#terrain-contours {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    transition: transform 0.1s linear;
}

/* Flow arrows SVG overlay */
#flow-arrows {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.flow-arrow {
    stroke-dasharray: 12 6;
    stroke-dashoffset: 0;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.flow-arrow.animate {
    opacity: 0.6;
    animation: flowDash 8s linear infinite;
}

@keyframes flowDash {
    to {
        stroke-dashoffset: -36;
    }
}

/* --- Terrain Sections --- */
.terrain-section {
    position: relative;
    z-index: 2;
    padding: 0;
}

.section-content {
    padding: clamp(32px, 5vw, 64px) clamp(24px, 4vw, 48px);
    position: relative;
}

/* Ridgeline transitions */
.ridgeline-top,
.ridgeline-bottom {
    height: 40px;
    position: relative;
    z-index: 3;
}

/* Each section gets a unique ridgeline clip-path */
#section-threads .ridgeline-bottom {
    clip-path: polygon(0% 0%, 8% 45%, 15% 20%, 25% 55%, 35% 15%, 45% 60%, 55% 25%, 65% 50%, 75% 10%, 85% 45%, 92% 20%, 100% 0%, 100% 100%, 0% 100%);
    background-color: var(--base-surface);
}

#section-mutexes .ridgeline-top {
    clip-path: polygon(0% 100%, 8% 55%, 15% 80%, 25% 45%, 35% 85%, 45% 40%, 55% 75%, 65% 50%, 75% 90%, 85% 55%, 92% 80%, 100% 100%, 100% 0%, 0% 0%);
    background-color: var(--base-surface);
}

#section-mutexes .ridgeline-bottom {
    clip-path: polygon(0% 0%, 10% 50%, 20% 20%, 30% 55%, 42% 10%, 52% 48%, 62% 18%, 72% 52%, 82% 15%, 90% 42%, 100% 0%, 100% 100%, 0% 100%);
    background-color: var(--base-surface);
}

#section-channels .ridgeline-top {
    clip-path: polygon(0% 100%, 10% 50%, 20% 80%, 30% 45%, 42% 90%, 52% 52%, 62% 82%, 72% 48%, 82% 85%, 90% 58%, 100% 100%, 100% 0%, 0% 0%);
    background-color: var(--base-surface);
}

#section-channels .ridgeline-bottom {
    clip-path: polygon(0% 0%, 7% 40%, 18% 15%, 28% 50%, 38% 8%, 48% 55%, 58% 20%, 68% 48%, 78% 12%, 88% 40%, 95% 18%, 100% 0%, 100% 100%, 0% 100%);
    background-color: var(--base-surface);
}

#section-deadlocks .ridgeline-top {
    clip-path: polygon(0% 100%, 7% 60%, 18% 85%, 28% 50%, 38% 92%, 48% 45%, 58% 80%, 68% 52%, 78% 88%, 88% 60%, 95% 82%, 100% 100%, 100% 0%, 0% 0%);
    background-color: var(--base-surface);
}

#section-deadlocks .ridgeline-bottom {
    clip-path: polygon(0% 0%, 12% 42%, 22% 12%, 32% 48%, 40% 8%, 50% 52%, 60% 15%, 70% 45%, 80% 10%, 88% 38%, 100% 0%, 100% 100%, 0% 100%);
    background-color: var(--base-surface);
}

#section-async .ridgeline-top {
    clip-path: polygon(0% 100%, 12% 58%, 22% 88%, 32% 52%, 40% 92%, 50% 48%, 60% 85%, 70% 55%, 80% 90%, 88% 62%, 100% 100%, 100% 0%, 0% 0%);
    background-color: var(--base-surface);
}

#section-async .ridgeline-bottom {
    clip-path: polygon(0% 0%, 9% 48%, 19% 18%, 30% 52%, 41% 12%, 51% 46%, 61% 22%, 71% 50%, 81% 8%, 91% 44%, 100% 0%, 100% 100%, 0% 100%);
    background-color: var(--base-surface);
}

#section-patterns .ridgeline-top {
    clip-path: polygon(0% 100%, 9% 52%, 19% 82%, 30% 48%, 41% 88%, 51% 54%, 61% 78%, 71% 50%, 81% 92%, 91% 56%, 100% 100%, 100% 0%, 0% 0%);
    background-color: var(--base-surface);
}

/* Elevation marker */
.elevation-marker {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--base-surface);
    box-shadow: var(--neo-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.elevation-marker span {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    color: var(--annotation-stone);
    letter-spacing: 0.01em;
}

/* Section titles */
.section-title {
    font-family: var(--font-headline);
    font-weight: 600;
    font-size: clamp(24px, 3.5vw, 48px);
    letter-spacing: -0.02em;
    color: var(--deep-gorge);
    margin-bottom: 4px;
}

.section-subtitle {
    font-family: var(--font-headline);
    font-weight: 500;
    font-size: clamp(14px, 1.5vw, 20px);
    color: var(--contour-terra-cotta);
    letter-spacing: -0.01em;
    margin-bottom: 28px;
}

/* Content plateaus -- neomorphic raised blocks */
.content-plateau {
    background-color: var(--raised-surface);
    border-radius: 16px;
    padding: clamp(24px, 4vw, 48px);
    margin-bottom: 24px;
    box-shadow: 0 0 0 rgba(0, 0, 0, 0), 0 0 0 rgba(255, 255, 255, 0);
    opacity: 0.7;
    transform: translateY(0);
    transition: box-shadow 0.5s ease, opacity 0.5s ease, transform 0.3s ease;
}

.content-plateau.in-view {
    box-shadow: var(--neo-raised);
    opacity: 1;
}

.content-plateau:hover {
    box-shadow: var(--neo-raised-hover);
    transform: translateY(-1px);
}

.content-plateau.linked {
    box-shadow: var(--neo-raised-hover);
}

.content-plateau p {
    margin-bottom: 16px;
    color: var(--deep-gorge);
}

.content-plateau p:last-child {
    margin-bottom: 0;
}

/* Annotations (code snippets) */
.annotation {
    margin-bottom: 20px;
    padding: 14px 18px;
    background-color: var(--base-surface);
    border-radius: 10px;
    box-shadow: var(--neo-inset);
}

.annotation code {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 400;
    color: var(--annotation-stone);
    letter-spacing: 0.01em;
    line-height: 1.6;
}

/* Strong text inside body */
strong {
    font-weight: 600;
    color: var(--deep-gorge);
}

/* --- Selection Color --- */
::selection {
    background-color: var(--contour-terra-cotta);
    color: var(--ridge-highlight);
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--base-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--plateau-shadow);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--annotation-stone);
}

/* --- Responsive: Mobile --- */
@media (max-width: 768px) {
    #legend-panel {
        display: none;
    }

    #legend-ribbon {
        display: flex;
    }

    #content-terrain {
        margin-left: 0;
        width: 100%;
        padding-top: 68px;
    }

    .content-plateau {
        box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.06), -3px -3px 6px rgba(255, 255, 255, 0.9);
    }

    .content-plateau.in-view {
        box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.08), -3px -3px 6px rgba(255, 255, 255, 0.95);
    }

    .content-plateau:hover,
    .content-plateau.linked {
        box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1), -4px -4px 8px rgba(255, 255, 255, 0.97);
    }

    /* Simplify ridgeline clip-paths to fewer points on mobile */
    #section-threads .ridgeline-bottom {
        clip-path: polygon(0% 0%, 25% 45%, 50% 15%, 75% 50%, 100% 0%, 100% 100%, 0% 100%);
    }
    #section-mutexes .ridgeline-top {
        clip-path: polygon(0% 100%, 25% 55%, 50% 85%, 75% 50%, 100% 100%, 100% 0%, 0% 0%);
    }
    #section-mutexes .ridgeline-bottom {
        clip-path: polygon(0% 0%, 25% 50%, 50% 10%, 75% 48%, 100% 0%, 100% 100%, 0% 100%);
    }
    #section-channels .ridgeline-top {
        clip-path: polygon(0% 100%, 25% 50%, 50% 90%, 75% 48%, 100% 100%, 100% 0%, 0% 0%);
    }
    #section-channels .ridgeline-bottom {
        clip-path: polygon(0% 0%, 25% 40%, 50% 8%, 75% 48%, 100% 0%, 100% 100%, 0% 100%);
    }
    #section-deadlocks .ridgeline-top {
        clip-path: polygon(0% 100%, 25% 60%, 50% 92%, 75% 52%, 100% 100%, 100% 0%, 0% 0%);
    }
    #section-deadlocks .ridgeline-bottom {
        clip-path: polygon(0% 0%, 25% 42%, 50% 8%, 75% 45%, 100% 0%, 100% 100%, 0% 100%);
    }
    #section-async .ridgeline-top {
        clip-path: polygon(0% 100%, 25% 58%, 50% 92%, 75% 55%, 100% 100%, 100% 0%, 0% 0%);
    }
    #section-async .ridgeline-bottom {
        clip-path: polygon(0% 0%, 25% 48%, 50% 12%, 75% 50%, 100% 0%, 100% 100%, 0% 100%);
    }
    #section-patterns .ridgeline-top {
        clip-path: polygon(0% 100%, 25% 52%, 50% 88%, 75% 50%, 100% 100%, 100% 0%, 0% 0%);
    }

    .ridgeline-top,
    .ridgeline-bottom {
        height: 24px;
    }

    .section-content {
        padding: 24px 16px;
    }

    /* Reduce contour density */
    #terrain-contours path:nth-child(n+9) {
        display: none;
    }
}
