/* ============================================================
   conc.quest — Pop-Art Glassmorphic Concurrency Experience
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
    --midnight-violet: #1A0A2E;
    --electric-indigo: #4B0082;
    --pop-magenta: #FF2D6B;
    --panel-white: #F0E6FF;
    --deep-violet-text: #2D1B4E;
    --concurrent-green: #00E676;
    --lichtenstein-yellow: #FFD23F;
    --trace-copper: #E8913A;
    --frosted-violet: rgba(75, 0, 130, 0.15);
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);
    --spring-ease: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Source Serif 4', Georgia, serif;
    background: var(--midnight-violet);
    color: var(--panel-white);
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* ---------- Ben-Day Dot Background ---------- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, var(--pop-magenta) 1px, transparent 1px);
    background-size: 8px 8px;
    opacity: 0;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

body.dots-visible::before {
    opacity: 0.04;
}

/* ---------- Main Container ---------- */
body > section,
body > div.signal-card,
body > footer {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 clamp(1rem, 3vw, 2rem);
}

/* ---------- Glassmorphic Card Base ---------- */
.glass-card {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    position: relative;
    overflow: hidden;
    transition: transform 0.35s var(--spring-ease),
                box-shadow 0.35s var(--spring-ease),
                border-color 0.35s ease;
}

.glass-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 16px 48px rgba(75, 0, 130, 0.25),
                0 0 24px rgba(255, 45, 107, 0.15);
    border-color: rgba(255, 45, 107, 0.3);
}

/* Sympathetic glow on nearby cards */
.glass-card.sympathetic-glow {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12),
                0 0 12px rgba(75, 0, 130, 0.15);
}

/* ---------- Ben-Day Overlay on Cards ---------- */
.ben-day-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.ben-day-overlay.dots-magenta {
    background: radial-gradient(circle, var(--pop-magenta) 1px, transparent 1px);
    background-size: 8px 8px;
    opacity: 0.06;
}

.ben-day-overlay.dots-yellow {
    background: radial-gradient(circle, var(--lichtenstein-yellow) 1px, transparent 1px);
    background-size: 8px 8px;
    opacity: 0.07;
}

/* ---------- HERO SECTION ---------- */
.hero-section {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    position: relative;
}

.hero-card {
    width: 100%;
    max-width: 860px;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(2rem, 5vw, 4rem);
    transform: scale(0.85);
    opacity: 0;
    transition: transform 0.6s var(--spring-ease),
                opacity 0.6s ease;
}

.hero-card.revealed {
    transform: scale(1);
    opacity: 1;
}

.hero-card .ben-day-overlay {
    background: radial-gradient(circle, var(--pop-magenta) 1px, transparent 1px);
    background-size: 8px 8px;
    opacity: 0.06;
}

.hero-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 900;
    font-size: clamp(2.5rem, 7vw, 6rem);
    letter-spacing: -0.02em;
    color: #FFFFFF;
    text-align: center;
    position: relative;
    z-index: 2;
    line-height: 1.1;
}

.hero-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s var(--spring-ease);
}

.hero-title .letter.visible {
    opacity: 1;
    transform: translateY(0);
}

.hero-subtitle {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    color: rgba(255, 255, 255, 0.7);
    margin-top: 1.5rem;
    text-align: center;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease 0.8s, transform 0.5s var(--spring-ease) 0.8s;
    position: relative;
    z-index: 2;
}

.hero-card.revealed .hero-subtitle {
    opacity: 1;
    transform: translateY(0);
}

/* Hero circuit traces */
.hero-traces {
    width: 100%;
    max-width: 600px;
    height: auto;
    margin-top: 2rem;
    position: relative;
    z-index: 2;
}

/* ---------- Starburst Container ---------- */
.starburst-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.starburst {
    position: absolute;
    width: 40px;
    height: 40px;
    transform: scale(0);
    opacity: 0;
    animation: starburstPop 0.5s var(--spring-ease) forwards;
}

@keyframes starburstPop {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* ---------- Circuit Traces ---------- */
.circuit-trace {
    stroke: var(--trace-copper);
    stroke-width: 1.5;
    opacity: 0.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: opacity 0.35s ease, stroke 0.35s ease;
}

.circuit-trace.trace-active {
    opacity: 1;
    stroke: var(--trace-copper);
}

.junction-dot {
    fill: var(--trace-copper);
    opacity: 0.4;
    transition: fill 0.35s ease, opacity 0.35s ease;
}

.junction-dot.dot-active {
    fill: var(--concurrent-green);
    opacity: 1;
}

/* Junction final pulse */
.junction-final {
    fill: var(--concurrent-green);
    opacity: 0;
}

.junction-final.pulsing {
    opacity: 1;
    animation: junctionPulse 1.5s ease-in-out infinite;
}

@keyframes junctionPulse {
    0%, 100% {
        r: 6;
        opacity: 0.6;
    }
    50% {
        r: 9;
        opacity: 1;
    }
}

/* Stroke dashoffset animation for draw-in */
.circuit-trace.draw-in {
    stroke-dasharray: var(--dash-length, 500);
    stroke-dashoffset: var(--dash-length, 500);
    animation: drawTrace 1.2s ease-out forwards;
}

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

/* ---------- Signal Cards (Connectors) ---------- */
.signal-card {
    height: 120px;
    width: 60%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.connector-trace {
    width: 100%;
    height: 80px;
}

/* ---------- Chapter Sections ---------- */
.chapter {
    margin-bottom: clamp(2rem, 5vh, 4rem);
}

/* ---------- Narrative Cards ---------- */
.narrative-card {
    padding: clamp(2rem, 4vw, 3.5rem);
    position: relative;
}

/* ---------- Section Headings ---------- */
.section-heading {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3.5vw, 2.8rem);
    letter-spacing: -0.02em;
    color: #FFFFFF;
    margin-bottom: 1.25rem;
    position: relative;
    z-index: 2;
}

/* ---------- Body Text ---------- */
.body-text {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    color: rgba(255, 255, 255, 0.88);
    margin-bottom: 1.25rem;
    position: relative;
    z-index: 2;
}

/* ---------- Code Labels ---------- */
.code-label {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--lichtenstein-yellow);
    position: relative;
    z-index: 2;
    margin-top: 0.75rem;
}

/* ---------- Speech Bubbles ---------- */
.speech-bubble {
    position: absolute;
    top: -18px;
    background: var(--pop-magenta);
    border: 2px solid var(--midnight-violet);
    border-radius: 12px;
    padding: 6px 16px;
    z-index: 5;
    transform: rotate(-3deg) scale(0);
    opacity: 0;
    transition: transform 0.3s var(--spring-ease), opacity 0.3s ease;
}

.speech-bubble.bubble-visible {
    transform: rotate(-3deg) scale(1);
    opacity: 1;
}

.speech-bubble-left {
    left: 20px;
}

.speech-bubble-right {
    right: 20px;
}

.speech-bubble-danger {
    background: var(--pop-magenta);
    animation: dangerPulse 2s ease-in-out infinite;
}

@keyframes dangerPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 45, 107, 0.4);
    }
    50% {
        box-shadow: 0 0 12px 4px rgba(255, 45, 107, 0.3);
    }
}

/* Speech bubble tail */
.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 12px solid var(--pop-magenta);
}

.speech-bubble-right::after {
    left: auto;
    right: 20px;
}

.bubble-text {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--panel-white);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

/* ---------- Thread Visualization Strips ---------- */
.thread-strip-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 1.5rem 0;
    position: relative;
    z-index: 2;
}

.thread-strip {
    height: 4px;
    border-radius: 2px;
    width: 0%;
    transition: none;
}

.thread-strip.animating {
    animation: threadFill 2s ease-out forwards;
}

.thread-strip.thread-green {
    background: var(--concurrent-green);
}

.thread-strip.thread-yellow {
    background: var(--lichtenstein-yellow);
}

.thread-strip.thread-magenta {
    background: var(--pop-magenta);
}

/* Staggered delays for parallel effect */
.thread-strip:nth-child(2).animating {
    animation-delay: 0.3s;
    animation-duration: 1.7s;
}

.thread-strip:nth-child(3).animating {
    animation-delay: 0.5s;
    animation-duration: 2.2s;
}

.thread-strip:nth-child(4).animating {
    animation-delay: 0.8s;
    animation-duration: 1.5s;
}

/* Mutex pause effect */
.thread-strip.thread-pause.animating {
    animation: threadFillPause 3s ease-out forwards;
}

.thread-strip.thread-pause-delayed.animating {
    animation: threadFillPauseDelayed 3s ease-out forwards;
    animation-delay: 0.2s;
}

@keyframes threadFill {
    0% { width: 0%; }
    100% { width: 100%; }
}

@keyframes threadFillPause {
    0% { width: 0%; }
    40% { width: 50%; }
    55% { width: 50%; }
    100% { width: 100%; }
}

@keyframes threadFillPauseDelayed {
    0% { width: 0%; }
    30% { width: 35%; }
    60% { width: 35%; }
    100% { width: 100%; }
}

/* Race collision effect */
.thread-race .thread-strip.animating {
    animation-duration: 1.5s;
}

.thread-race .thread-race-collide.animating {
    animation: threadRaceCollide 1.5s ease-out forwards;
    animation-delay: 0.1s;
}

@keyframes threadRaceCollide {
    0% { width: 0%; }
    60% { width: 70%; }
    65% { width: 70%; background: var(--pop-magenta); }
    70% { width: 75%; background: #FF0000; }
    100% { width: 100%; background: var(--lichtenstein-yellow); }
}

/* Converge effect */
.thread-strip.thread-converge.animating {
    animation: threadConverge 2s ease-out forwards;
    animation-delay: 0.4s;
}

.thread-strip.thread-converge-delayed.animating {
    animation: threadConverge 2.5s ease-out forwards;
    animation-delay: 0.7s;
}

@keyframes threadConverge {
    0% { width: 0%; }
    70% { width: 80%; }
    100% { width: 100%; }
}

/* Delayed thread */
.thread-strip.thread-delayed.animating {
    animation-delay: 1s;
    animation-duration: 1.2s;
}

/* ---------- Mutex Visualization ---------- */
.mutex-visualization {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.5rem 0;
    position: relative;
    z-index: 2;
}

.mutex-lock {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Fork-Join Layout ---------- */
.fork-join-section {
    padding: 0;
}

.fork-join-grid {
    display: grid;
    grid-template-columns: 1fr 20px 1fr;
    gap: 0;
    align-items: start;
}

.parallel-card {
    padding: clamp(1.5rem, 3vw, 2.5rem);
}

.parallel-left {
    justify-self: end;
}

.parallel-right {
    justify-self: start;
}

.fork-join-divider {
    display: flex;
    align-items: stretch;
    justify-content: center;
    min-height: 100%;
}

.divider-line {
    width: 20px;
    height: 100%;
    min-height: 300px;
}

.divider-line line {
    stroke: var(--electric-indigo);
    stroke-width: 1.5;
    opacity: 0.5;
}

/* ---------- Danger Card (Race Condition) ---------- */
.card-danger {
    border-color: rgba(255, 45, 107, 0.3);
}

.card-danger:hover {
    border-color: rgba(255, 45, 107, 0.6);
    box-shadow: 0 16px 48px rgba(255, 45, 107, 0.2),
                0 0 32px rgba(255, 45, 107, 0.15);
}

/* ---------- Final Card ---------- */
.card-final {
    border-color: rgba(0, 230, 118, 0.2);
}

.card-final:hover {
    border-color: rgba(0, 230, 118, 0.4);
    box-shadow: 0 16px 48px rgba(0, 230, 118, 0.15),
                0 0 24px rgba(0, 230, 118, 0.1);
}

/* ---------- Convergence Junction ---------- */
.convergence-junction {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2rem;
    position: relative;
    z-index: 2;
}

.convergence-svg {
    width: 200px;
    height: 100px;
}

/* ---------- Footer ---------- */
.footer-section {
    padding: 4rem 0 6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.final-glow-dot {
    width: 16px;
    height: 16px;
    background: var(--concurrent-green);
    border-radius: 50%;
    box-shadow: 0 0 20px var(--concurrent-green),
                0 0 40px rgba(0, 230, 118, 0.4),
                0 0 60px rgba(0, 230, 118, 0.2);
    animation: finalGlow 2s ease-in-out infinite;
}

@keyframes finalGlow {
    0%, 100% {
        box-shadow: 0 0 20px var(--concurrent-green),
                    0 0 40px rgba(0, 230, 118, 0.4),
                    0 0 60px rgba(0, 230, 118, 0.2);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 30px var(--concurrent-green),
                    0 0 60px rgba(0, 230, 118, 0.5),
                    0 0 90px rgba(0, 230, 118, 0.3);
        transform: scale(1.2);
    }
}

.footer-text {
    opacity: 0.5;
    text-align: center;
}

/* ---------- Scroll Reveal (initial state) ---------- */
.scroll-reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.5s ease, transform 0.6s var(--spring-ease);
}

.scroll-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Fork-join specific reveal */
.fork-join-section.scroll-reveal .parallel-left {
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.5s ease, transform 0.6s var(--spring-ease);
}

.fork-join-section.scroll-reveal .parallel-right {
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.5s ease, transform 0.6s var(--spring-ease);
}

.fork-join-section.revealed .parallel-left {
    opacity: 1;
    transform: translateX(0);
}

.fork-join-section.revealed .parallel-right {
    opacity: 1;
    transform: translateX(0);
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hero-card {
        transform: scale(1);
        opacity: 1;
    }

    .hero-title .letter {
        opacity: 1;
        transform: translateY(0);
    }

    .scroll-reveal {
        opacity: 1;
        transform: translateY(0);
    }

    .speech-bubble {
        transform: rotate(-3deg) scale(1);
        opacity: 1;
    }

    body::before {
        opacity: 0.04;
    }

    .thread-strip {
        width: 100%;
    }

    .fork-join-section.scroll-reveal .parallel-left,
    .fork-join-section.scroll-reveal .parallel-right {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ---------- Mobile Responsive ---------- */
@media (max-width: 768px) {
    .fork-join-grid {
        grid-template-columns: 1fr;
        gap: clamp(1rem, 3vw, 2rem);
    }

    .fork-join-divider {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: auto;
        height: 40px;
        width: 100%;
    }

    .divider-line {
        width: 100%;
        height: 20px;
        min-height: 20px;
    }

    /* Horizontal divider on mobile */
    .fork-join-divider svg {
        transform: rotate(90deg);
        width: 300px;
        height: 20px;
    }

    .parallel-left,
    .parallel-right {
        justify-self: stretch;
    }

    .signal-card {
        width: 80%;
    }

    .hero-card {
        min-height: 50vh;
    }

    .speech-bubble {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        display: inline-block;
        margin-bottom: 1rem;
    }

    .speech-bubble::after {
        display: none;
    }
}

@media (max-width: 480px) {
    .signal-card {
        width: 90%;
    }

    .hero-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }
}
