/* ============================================
   economics.quest - Bauhaus Economics Timeline
   ============================================
   Typography: "Share Tech Mono" (Google Fonts), "IBM Plex Mono" (Google Fonts),
               "Space Grotesk" (Google Fonts)
   Palette: burnt-orange anchored
   Aesthetic: Bauhaus pedagogical, Interaction of Color" inspired
   Interactive Elements:** Card-flip, timeline spine, data-viz
   Observer: IntersectionObserver at 0.8 threshold for visualizations
   Card back text color: `#F5EDE3` on deep charcoal
   ============================================ */

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

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    background-color: #F5EDE3;
    color: #1A1A1A;
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    font-weight: 400;
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* --- Construction Grid (z-plane 0) --- */
#construction-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, #EDE5D9 1px, transparent 1px),
        linear-gradient(to bottom, #EDE5D9 1px, transparent 1px);
    background-size: 48px 48px;
    opacity: 0.3;
}

/* --- Central Spine --- */
.spine-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    overflow: visible;
}

#spine-line {
    stroke-dasharray: 10000;
    stroke-dashoffset: 10000;
    transition: none;
}

#spine-line.animate {
    animation: drawSpine 1.5s ease-out forwards;
}

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

/* --- Site Header --- */
#site-header {
    position: fixed;
    top: 24px;
    left: 32px;
    z-index: 100;
}

.site-title {
    font-family: 'Share Tech Mono', monospace;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #1A1A1A;
    opacity: 0;
    animation: fadeIn 0.5s ease-out 1.8s forwards;
}

.site-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #D4590A;
    margin-top: 4px;
    opacity: 0;
    animation: fadeIn 0.5s ease-out 2.0s forwards;
}

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

/* --- Minimap Navigation (Right Edge) --- */
#minimap {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    z-index: 100;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

#minimap:hover {
    opacity: 1;
}

.minimap-track {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 12px 0;
}

.minimap-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.5px solid #C4C0B8;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.minimap-dot:hover {
    border-color: #D4590A;
}

.minimap-dot.active {
    background: #D4590A;
    border-color: #D4590A;
}

/* --- Timeline Main --- */
#timeline {
    position: relative;
    z-index: 1;
    padding-top: 10vh;
    padding-bottom: 10vh;
}

/* --- Timeline Section --- */
.timeline-section {
    position: relative;
    min-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
    scroll-snap-align: start;
    padding: 40px 0;
}

/* --- Timeline Node --- */
.timeline-node {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.node-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #1A1A1A;
    background: #F5EDE3;
    position: relative;
    transition: border-color 0.3s ease;
}

.node-circle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #D4590A;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.3s ease;
}

.timeline-section.in-view .node-circle {
    border-color: #D4590A;
}

.timeline-section.in-view .node-circle::after {
    transform: translate(-50%, -50%) scale(1);
}

/* Visited nodes use deep orange #8B3A06 */
.timeline-section.visited .node-circle {
    border-color: #8B3A06;
}

.timeline-section.visited .node-circle::after {
    background: #8B3A06;
    transform: translate(-50%, -50%) scale(1);
}

/* Active overrides visited */
.timeline-section.in-view.visited .node-circle {
    border-color: #D4590A;
}

.timeline-section.in-view.visited .node-circle::after {
    background: #D4590A;
}

.node-year {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #D4590A;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    margin-top: 12px;
    white-space: nowrap;
}

/* --- Connector Line --- */
.connector-line {
    position: absolute;
    top: 50%;
    height: 1px;
    background: #C4C0B8;
    z-index: 3;
    transform: scaleX(0);
    transition: transform 0.2s ease-out;
}

.timeline-section.in-view .connector-line {
    transform: scaleX(1);
}

/* Left side: connector goes from spine (center) to left panel */
.timeline-section[data-side="left"] .connector-line {
    right: 50%;
    width: calc(50% - 280px);
    transform-origin: right center;
}

/* Right side: connector goes from spine (center) to right panel */
.timeline-section[data-side="right"] .connector-line {
    left: 50%;
    width: calc(50% - 280px);
    transform-origin: left center;
}

/* --- Content Panel (z-plane 1) --- */
.content-panel {
    max-width: 520px;
    width: 100%;
    background: #FFFFFF;
    border: 1px solid #C4C0B8;
    padding: 32px;
    position: relative;
    opacity: 0;
    transition: opacity 0.4s ease-out 0.2s, transform 0.4s ease-out 0.2s;
}

.timeline-section[data-side="left"] .content-panel {
    margin-right: calc(50% + 60px);
    transform: translateX(-30px);
}

.timeline-section[data-side="right"] .content-panel {
    margin-left: calc(50% + 60px);
    transform: translateX(30px);
}

.timeline-section.in-view .content-panel {
    opacity: 1;
    transform: translateX(0);
}

/* --- Panel Typography --- */
.panel-heading {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #1A1A1A;
    margin-bottom: 20px;
    line-height: 1.2;
}

.panel-body {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    font-weight: 400;
    line-height: 1.75;
    color: #1A1A1A;
    margin-bottom: 24px;
}

.panel-body strong,
.panel-body b {
    font-weight: 600;
}

/* --- Pull Quote / Key Concept (Space Grotesk) --- */
.key-concept {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    letter-spacing: 0.02em;
    color: #1A1A1A;
    border-left: 2px solid #D4590A;
    padding-left: 16px;
    margin: 20px 0;
    line-height: 1.5;
}

/* --- Data Visualizations --- */
.viz-container {
    margin: 24px 0;
    position: relative;
}

.chart-svg {
    width: 100%;
    height: auto;
    display: block;
}

.axis-line {
    stroke: #1A1A1A;
    stroke-width: 1.5;
}

.axis-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    fill: #D4590A;
}

.legend-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: #6B6560;
}

.bar-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    fill: #6B6560;
    letter-spacing: 0.1em;
}

.eq-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Supply/Demand curve animation */
.chart-line {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: none;
}

.chart-line.animate {
    animation: drawLine 1.2s ease-out forwards;
}

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

/* Equilibrium point */
.equilibrium-point {
    transform-origin: 210px 148px;
    transform: scale(0);
    transition: transform 0.3s ease-out;
}

.equilibrium-point.animate {
    transform: scale(1);
}

.equilibrium-pulse {
    opacity: 0;
}

.equilibrium-pulse.animate {
    animation: pulseRing 1s ease-out forwards;
}

@keyframes pulseRing {
    0% {
        opacity: 1;
        r: 6;
    }
    100% {
        opacity: 0;
        r: 20;
    }
}

/* Construction lines to equilibrium */
.construction-eq {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

.construction-eq.animate {
    animation: drawLine 0.6s ease-out forwards;
}

/* Bar chart animations */
.bar {
    transition: height 0.5s ease-out, y 0.5s ease-out;
}

/* Treemap animations */
.treemap-rect {
    transform-origin: center;
    transform: scale(0);
    transition: transform 0.4s ease-out;
}

.treemap-rect.animate {
    transform: scale(1);
}

.treemap-label,
.treemap-value {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    letter-spacing: 0.08em;
}

.treemap-label {
    font-size: 12px;
}

.treemap-value {
    font-size: 11px;
}

/* Game theory matrix */
.matrix-player {
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.matrix-strategy {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: #6B6560;
}

.payoff {
    font-family: 'Share Tech Mono', monospace;
    font-size: 18px;
    font-weight: 400;
}

.nash-eq {
    opacity: 0;
    transition: opacity 0.5s ease-out;
}

.nash-eq.animate {
    opacity: 1;
}

/* Agent-based model */
.agent-node {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.agent-node.animate {
    opacity: 1;
}

.agent-connection {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

.agent-connection.animate {
    animation: drawLine 0.8s ease-out forwards;
}

.data-particle {
    opacity: 0;
}

.data-particle.animate {
    opacity: 1;
}

/* --- Card Flip Interactive Elements --- */
.card-flip {
    perspective: 1000px;
    margin: 24px 0 0;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    padding-top: 66.66%; /* 3:2 aspect ratio */
    transform-style: preserve-3d;
    transition: transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

.card-flip.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.card-front {
    background: #FFFFFF;
    border: 1px solid #C4C0B8;
}

.card-back {
    background: #2A2520;
    transform: rotateY(180deg);
    padding: 24px;
    align-items: flex-start;
    overflow-y: auto;
}

/* Card corner indicator (triangle, 8px) signaling interactivity */
.card-corner-indicator {
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-top: 8px solid #D4590A;
}

.card-title {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(1rem, 2vw, 1.4rem);
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #1A1A1A;
    margin-bottom: 12px;
    text-align: center;
}

.card-diagram {
    width: 70%;
    max-width: 200px;
    height: auto;
}

.card-flip-hint {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #D4590A;
    margin-top: 8px;
}

.card-back-title {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #F5EDE3;
    margin-bottom: 12px;
}

.card-back-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.65;
    color: #F5EDE3;
}

.card-back-viz {
    width: 100%;
    max-width: 200px;
    height: auto;
    margin-top: 12px;
}

/* Mid-flip edge effect: 2px #D4590A line visible during rotation */
.card-inner::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: #D4590A;
    transform: translateX(-50%);
    opacity: 0;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.1s;
}

/* --- Bauhaus Geometric Accents --- */
.bauhaus-accent {
    position: fixed;
    z-index: 1;
    pointer-events: none;
    opacity: 0.15;
    animation: rotateAccent 30s linear infinite;
}

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

.accent-circle {
    width: 48px;
    height: 48px;
    border: 1.5px solid #1A1A1A;
    border-radius: 50%;
}

.accent-square {
    width: 36px;
    height: 36px;
    border: 1.5px solid #1A1A1A;
}

.accent-triangle {
    width: 44px;
    height: 38px;
    position: relative;
}

.accent-triangle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    background: #1A1A1A;
}

.accent-triangle::after {
    content: '';
    position: absolute;
    top: 1.5px;
    left: 1.5px;
    width: calc(100% - 3px);
    height: calc(100% - 3px);
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    background: #F5EDE3;
}

/* Node pulse on scroll intersection */
@keyframes nodePulse {
    0% { box-shadow: 0 0 0 0 rgba(212, 89, 10, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(212, 89, 10, 0); }
    100% { box-shadow: 0 0 0 0 rgba(212, 89, 10, 0); }
}

.timeline-section.in-view .node-circle {
    animation: nodePulse 1s ease-out;
}

/* --- Data Viz Color Classes --- */
.viz-primary {
    fill: #D4590A;
}

.viz-secondary {
    fill: #0A7A6D;
}

.viz-deep-orange {
    fill: #8B3A06;
}

.viz-peach {
    fill: #F5C9A8;
}

/* --- Selection color --- */
::selection {
    background: #D4590A;
    color: #FFFFFF;
}

/* --- Responsive: Below 768px --- */
@media (max-width: 768px) {
    #construction-grid {
        background-size: 24px 24px;
    }

    .timeline-node {
        left: 12px;
        transform: translate(0, -50%);
    }

    .node-circle {
        width: 24px;
        height: 24px;
    }

    .connector-line {
        left: 24px !important;
        right: auto !important;
        width: 30px !important;
        transform-origin: left center !important;
    }

    .content-panel {
        margin-left: 60px !important;
        margin-right: 16px !important;
        max-width: calc(100% - 76px);
        padding: 20px;
    }

    .timeline-section[data-side="left"] .content-panel,
    .timeline-section[data-side="right"] .content-panel {
        margin-left: 60px;
        margin-right: 16px;
        transform: translateX(20px);
    }

    .timeline-section.in-view .content-panel {
        transform: translateX(0);
    }

    .panel-heading {
        font-size: clamp(1.4rem, 3vw, 2rem);
    }

    #site-header {
        left: 16px;
        top: 16px;
    }

    #minimap {
        display: none;
    }

    .timeline-section {
        min-height: auto;
        padding: 40px 0;
    }

    .card-diagram {
        width: 60%;
    }
}

/* --- Responsive: Below 480px --- */
@media (max-width: 480px) {
    .card-inner {
        transition: none;
        transform-style: flat;
    }

    .card-flip.flipped .card-inner {
        transform: none;
    }

    .card-front {
        transition: opacity 0.3s ease;
    }

    .card-flip.flipped .card-front {
        opacity: 0;
        pointer-events: none;
    }

    .card-back {
        transform: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .card-flip.flipped .card-back {
        opacity: 1;
    }

    .content-panel {
        padding: 16px;
    }

    .panel-heading {
        font-size: 1.3rem;
    }

    .key-concept {
        font-size: 1.1rem;
    }
}
