/* ============================================
   continua.quest - Styles
   Triadic Palette | Ma-Negative-Space | Glassmorphism
   ============================================ */

/* ---- Color Reference ----
   Electric Violet:  #7B2FBE
   Searing Coral:    #BE522F
   Vivid Teal:       #2FBE8A
   Deep Space:       #0D0B14
   Muted Sage:       #3D5A4A
   Bone White:       #F0EDE5
   Hot Magenta:      #E8368F
   ---- */

/* CSS Custom Properties for @property Animation */
@property --border-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

@property --border-progress {
    syntax: '<percentage>';
    initial-value: 0%;
    inherits: false;
}

@property --font-weight {
    syntax: '<number>';
    initial-value: 700;
    inherits: false;
}

@property --font-casual {
    syntax: '<number>';
    initial-value: 1;
    inherits: false;
}

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

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #7B2FBE #0D0B14;
}

body {
    background-color: #0D0B14;
    color: #F0EDE5;
    font-family: 'DM Sans', sans-serif;
    font-size: clamp(1rem, 1.2vw, 1.25rem);
    line-height: 1.75;
    font-weight: 400;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- Typography ---- */

/* Headlines / Display: Recursive Casual=1, Mono=0 */
.hero-text {
    font-family: 'Recursive', sans-serif;
    font-variation-settings: 'MONO' 0, 'CASL' 1, 'wght' 900, 'slnt' 0;
    font-size: clamp(3rem, 7vw, 6rem);
    letter-spacing: -0.04em;
    color: #7B2FBE;
    cursor: default;
    transition: font-variation-settings 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hero-text:hover {
    font-variation-settings: 'MONO' 0, 'CASL' 0.7, 'wght' 900, 'slnt' 0;
}

.section-title {
    font-family: 'Recursive', sans-serif;
    font-variation-settings: 'MONO' 0, 'CASL' 1, 'wght' 700, 'slnt' 0;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    letter-spacing: -0.02em;
    color: #F0EDE5;
    margin-bottom: 1rem;
    transition: font-variation-settings 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.section-title:hover {
    font-variation-settings: 'MONO' 0, 'CASL' 0.7, 'wght' 900, 'slnt' 0;
}

/* Accent / Labels: Recursive Mono=1, Casual=0 */
.card-label {
    font-family: 'Recursive', monospace;
    font-variation-settings: 'MONO' 1, 'CASL' 0, 'wght' 500, 'slnt' 0;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #3D5A4A;
    display: block;
    margin-bottom: 1rem;
}

/* Body / Reading: DM Sans */
.card-body {
    font-family: 'DM Sans', sans-serif;
    font-size: clamp(1rem, 1.2vw, 1.25rem);
    line-height: 1.75;
    font-weight: 400;
    color: #F0EDE5;
    opacity: 0.85;
}

/* ---- Connective Line SVG ---- */
#connective-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
    z-index: 1;
}

/* ---- Navigation Pill ---- */
#nav-pill {
    position: fixed;
    bottom: 40px;
    left: 40px;
    z-index: 100;
    background: rgba(13, 11, 20, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(123, 47, 190, 0.3);
    border-radius: 100px;
    padding: 10px 24px;
    transition: all 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
    cursor: default;
}

#nav-pill:hover {
    background: #BE522F;
    border-color: #BE522F;
    transform: scale(1.05);
}

#nav-pill:hover #nav-pill-label {
    color: #F0EDE5;
}

#nav-pill-label {
    font-family: 'Recursive', monospace;
    font-variation-settings: 'MONO' 1, 'CASL' 0, 'wght' 500, 'slnt' 0;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #BE522F;
    transition: color 0.3s ease, opacity 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
    display: inline-block;
}

/* ---- Chapters (shared) ---- */
.chapter {
    min-height: 150vh;
    position: relative;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chapter-content {
    width: 100%;
    max-width: 1400px;
    padding: 0 5vw;
    position: relative;
}

/* ---- Chapter 1: Origin ---- */
#chapter-origin {
    min-height: 160vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chapter-origin-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(30px);
    animation: letterReveal 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
    animation-delay: calc(var(--delay) * 0.15s + 0.5s);
}

@keyframes letterReveal {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.origin-subtitle {
    font-family: 'DM Sans', sans-serif;
    font-size: clamp(0.9rem, 1.4vw, 1.3rem);
    font-weight: 400;
    color: #3D5A4A;
    letter-spacing: 0.08em;
    opacity: 0;
    animation: subtitleFade 1s ease forwards;
    animation-delay: 2s;
}

@keyframes subtitleFade {
    to {
        opacity: 0.7;
    }
}

/* ---- Chapter 2: Spectrum ---- */
#chapter-spectrum {
    min-height: 200vh;
    padding: 20vh 0;
}

.spectrum-layout {
    display: flex;
    flex-direction: column;
}

.spectrum-layout .dense-zone {
    display: flex;
    flex-direction: column;
    gap: 8vh;
    max-width: 65%;
}

/* ---- Chapter 3: Topology ---- */
#chapter-topology {
    min-height: 180vh;
    padding: 15vh 0;
}

.topology-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8vw;
    align-items: start;
}

.topology-layout .sparse-zone {
    padding-top: 10vh;
}

.motif-display {
    position: relative;
    padding-top: 25vh;
}

.cross-hatch-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.06;
    background:
        repeating-linear-gradient(
            45deg,
            #2FBE8A 0px,
            #2FBE8A 1px,
            transparent 1px,
            transparent 20px
        ),
        repeating-linear-gradient(
            135deg,
            #2FBE8A 0px,
            #2FBE8A 1px,
            transparent 1px,
            transparent 20px
        );
    pointer-events: none;
    border-radius: 16px;
}

/* ---- Chapter 4: Resonance ---- */
#chapter-resonance {
    min-height: 180vh;
    padding: 15vh 0;
}

.resonance-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 6vw;
    align-items: center;
}

.resonance-layout .dense-zone {
    display: flex;
    flex-direction: column;
    gap: 6vh;
}

.dot-matrix-display {
    display: flex;
    align-items: center;
    justify-content: center;
}

.dot-matrix-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 12px;
    padding: 2rem;
}

.dot-matrix-grid .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: dotPulse 3s ease-in-out infinite;
    animation-delay: calc(var(--dot-delay) * 0.15s);
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* ---- Chapter 5: Emergence ---- */
#chapter-emergence {
    min-height: 200vh;
    padding: 15vh 0;
}

.emergence-layout {
    display: flex;
    flex-direction: column;
    gap: 10vh;
}

.emergence-layout .sparse-zone {
    max-width: 55%;
    align-self: flex-end;
}

.emergence-dense {
    max-width: 50%;
    align-self: flex-start;
}

.chevron-display {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 6vh 0;
}

.chevron-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.chevron {
    width: 0;
    height: 0;
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-bottom: 20px solid #2FBE8A;
    animation: chevronFloat 2.5s ease-in-out infinite;
}

.chevron.c1 { opacity: 1; animation-delay: 0s; border-bottom-color: #7B2FBE; }
.chevron.c2 { opacity: 0.8; animation-delay: 0.15s; border-bottom-color: #BE522F; }
.chevron.c3 { opacity: 0.6; animation-delay: 0.3s; border-bottom-color: #2FBE8A; }
.chevron.c4 { opacity: 0.4; animation-delay: 0.45s; border-bottom-color: #7B2FBE; }
.chevron.c5 { opacity: 0.2; animation-delay: 0.6s; border-bottom-color: #BE522F; }

@keyframes chevronFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* ---- Chapter 6: Infinite ---- */
#chapter-infinite {
    min-height: 160vh;
    padding: 10vh 0;
}

.infinite-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10vh;
}

.infinite-spiral {
    display: flex;
    justify-content: center;
    align-items: center;
}

.spiral-svg {
    width: clamp(250px, 35vw, 400px);
    height: clamp(250px, 35vw, 400px);
}

.spiral-ring {
    transform-origin: 200px 200px;
    animation: spiralRotate 20s linear infinite;
}

.spiral-ring.r1 { animation-duration: 30s; }
.spiral-ring.r2 { animation-duration: 25s; animation-direction: reverse; }
.spiral-ring.r3 { animation-duration: 22s; }
.spiral-ring.r4 { animation-duration: 18s; animation-direction: reverse; }
.spiral-ring.r5 { animation-duration: 15s; }
.spiral-ring.r6 { animation-duration: 12s; animation-direction: reverse; }
.spiral-ring.r7 { animation-duration: 8s; }

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

.spiral-center {
    animation: spiralPulse 3s ease-in-out infinite;
}

@keyframes spiralPulse {
    0%, 100% { r: 8; opacity: 0.9; }
    50% { r: 12; opacity: 1; }
}

.infinite-text {
    max-width: 600px;
    width: 100%;
}

.restart-prompt {
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.6s ease;
    padding: 1rem 0;
}

.restart-prompt.visible {
    opacity: 1;
}

.restart-text {
    font-family: 'Recursive', monospace;
    font-variation-settings: 'MONO' 1, 'CASL' 0.5, 'wght' 400, 'slnt' 0;
    font-size: clamp(0.8rem, 1vw, 1rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #E8368F;
    transition: color 0.3s ease, letter-spacing 0.3s ease;
}

.restart-prompt:hover .restart-text {
    color: #F0EDE5;
    letter-spacing: 0.3em;
}

/* ---- Glassmorphic Cards ---- */
.glass-card {
    position: relative;
    padding: 48px;
    border-radius: 16px;
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border: 1px solid rgba(255, 255, 255, 0.12);
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.glass-card.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Card Tints - Triadic color backgrounds at 6-10% opacity */
.violet-tint {
    background: rgba(123, 47, 190, 0.08);
    box-shadow:
        0 4px 8px rgba(123, 47, 190, 0.15),
        0 16px 32px rgba(13, 11, 20, 0.3),
        0 48px 64px rgba(123, 47, 190, 0.05);
}

.coral-tint {
    background: rgba(190, 82, 47, 0.08);
    box-shadow:
        0 4px 8px rgba(190, 82, 47, 0.15),
        0 16px 32px rgba(13, 11, 20, 0.3),
        0 48px 64px rgba(190, 82, 47, 0.05);
}

.teal-tint {
    background: rgba(47, 190, 138, 0.08);
    box-shadow:
        0 4px 8px rgba(47, 190, 138, 0.15),
        0 16px 32px rgba(13, 11, 20, 0.3),
        0 48px 64px rgba(47, 190, 138, 0.05);
}

/* Card Sizes */
.continental {
    width: 100%;
}

.island {
    width: 80%;
}

/* Card Offsets - scattered-but-intentional composition */
.offset-right {
    margin-left: 15%;
}

.offset-left {
    margin-left: -5%;
}

.float-offset {
    margin-left: 10%;
    margin-top: -5vh;
}

/* ---- Border Animation (conic gradient draw) ---- */
.glass-card::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 17px;
    padding: 1px;
    background: conic-gradient(
        from var(--border-angle),
        transparent 0%,
        transparent calc(100% - var(--border-progress, 0%)),
        #7B2FBE calc(100% - var(--border-progress, 0%)),
        #2FBE8A 100%
    );
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.glass-card.border-animating::before {
    opacity: 1;
    animation: borderDraw 1.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

@keyframes borderDraw {
    from {
        --border-angle: 0deg;
        --border-progress: 0%;
    }
    to {
        --border-angle: 360deg;
        --border-progress: 100%;
    }
}

/* Reward flash in Hot Magenta */
.glass-card.border-complete::before {
    animation: rewardFlash 150ms ease-out forwards;
}

@keyframes rewardFlash {
    0% {
        background: conic-gradient(from 360deg, #E8368F, #E8368F);
        opacity: 1;
    }
    100% {
        background: conic-gradient(from 360deg, rgba(232, 54, 143, 0.15), rgba(232, 54, 143, 0.15));
        opacity: 0.4;
    }
}

/* Post-flash settled state */
.glass-card.border-settled::before {
    opacity: 0.3;
    background: conic-gradient(
        from 0deg,
        #7B2FBE,
        #2FBE8A,
        #BE522F,
        #7B2FBE
    );
    transition: opacity 1s ease;
}

/* ---- Particle Cards (floating decorative) ---- */
#particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    overflow: hidden;
}

.particle-card {
    position: absolute;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(123, 47, 190, 0.04);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    opacity: 0;
    transition: opacity 1.5s ease;
}

.particle-card.active {
    opacity: 0.7;
}

/* Particle positions in the negative space corridor (right third) */
.particle-1 {
    right: 12%;
    top: 20%;
    animation: particleDrift1 20s ease-in-out infinite;
}

.particle-2 {
    right: 18%;
    top: 45%;
    animation: particleDrift2 25s ease-in-out infinite;
}

.particle-3 {
    right: 8%;
    top: 65%;
    animation: particleDrift3 22s ease-in-out infinite;
}

.particle-4 {
    right: 22%;
    top: 30%;
    animation: particleDrift4 18s ease-in-out infinite;
}

.particle-5 {
    right: 5%;
    top: 55%;
    animation: particleDrift1 24s ease-in-out infinite reverse;
}

.particle-6 {
    right: 15%;
    top: 80%;
    animation: particleDrift2 20s ease-in-out infinite reverse;
}

/* Sinusoidal drift paths for particle cards */
@keyframes particleDrift1 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(20px, -30px) rotate(5deg); }
    50% { transform: translate(-10px, -50px) rotate(-3deg); }
    75% { transform: translate(15px, -20px) rotate(2deg); }
}

@keyframes particleDrift2 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-25px, 20px) rotate(-4deg); }
    50% { transform: translate(15px, 40px) rotate(6deg); }
    75% { transform: translate(-10px, 15px) rotate(-2deg); }
}

@keyframes particleDrift3 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(30px, 15px) rotate(3deg); }
    50% { transform: translate(-20px, -25px) rotate(-5deg); }
    75% { transform: translate(10px, 30px) rotate(1deg); }
}

@keyframes particleDrift4 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-15px, -40px) rotate(-6deg); }
    50% { transform: translate(25px, -15px) rotate(4deg); }
    75% { transform: translate(-20px, 25px) rotate(-3deg); }
}

/* ---- Breathing Column Line (visual metaphor for continuity) ---- */
.chapter::after {
    content: '';
    position: absolute;
    right: 33.33%;
    top: 10%;
    bottom: 10%;
    width: 1px;
    background: linear-gradient(
        to bottom,
        transparent,
        rgba(47, 190, 138, 0.15) 20%,
        rgba(47, 190, 138, 0.15) 80%,
        transparent
    );
    pointer-events: none;
}

#chapter-origin::after {
    display: none;
}

/* ---- Custom Scrollbar ---- */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: #0D0B14;
}

::-webkit-scrollbar-thumb {
    background: #7B2FBE;
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: #E8368F;
}

/* ---- Selection ---- */
::selection {
    background: rgba(123, 47, 190, 0.3);
    color: #F0EDE5;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .chapter-content {
        padding: 0 6vw;
    }

    .spectrum-layout .dense-zone {
        max-width: 100%;
    }

    .topology-layout {
        grid-template-columns: 1fr;
        gap: 6vh;
    }

    .resonance-layout {
        grid-template-columns: 1fr;
        gap: 6vh;
    }

    .emergence-layout .sparse-zone,
    .emergence-dense {
        max-width: 100%;
        align-self: center;
    }

    .glass-card {
        padding: 32px;
    }

    .island {
        width: 100%;
    }

    .offset-right {
        margin-left: 0;
    }

    .offset-left {
        margin-left: 0;
    }

    .float-offset {
        margin-left: 0;
        margin-top: 0;
    }

    .chapter::after {
        display: none;
    }

    .particle-card {
        display: none;
    }

    #nav-pill {
        bottom: 20px;
        left: 20px;
        padding: 8px 16px;
    }
}

@media (max-width: 600px) {
    .hero-text {
        font-size: clamp(2.5rem, 12vw, 4rem);
    }

    .section-title {
        font-size: clamp(1.4rem, 6vw, 2rem);
    }

    .glass-card {
        padding: 24px;
    }

    .spiral-svg {
        width: 220px;
        height: 220px;
    }

    .chapter {
        min-height: 120vh;
    }

    #chapter-origin {
        min-height: 130vh;
    }

    #chapter-spectrum {
        min-height: 160vh;
    }
}
