/* =============================================
   thefirst.quest - Styles
   Archaeological descent through analog circuitry
   ============================================= */

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

:root {
    --fired-clay: #C2703E;
    --burnt-sienna: #944A2B;
    --parchment-smoke: #F5EDE3;
    --weathered-hide: #E8D5C0;
    --obsidian-workshop: #1C1612;
    --solder-gold: #D4A843;
    --patina-verdigris: #5B8A72;
    --oxidized-copper: #8B7355;

    --font-display: 'Libre Baskerville', Georgia, serif;
    --font-body: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    --font-mono: 'Inconsolata', 'Courier New', monospace;

    --ease-main: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-ripple: cubic-bezier(0, 0, 0.2, 1);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.125rem);
    line-height: 1.7;
    color: var(--obsidian-workshop);
    background-color: var(--parchment-smoke);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Analog Noise Overlay --- */
#noise-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.025;
    background-image:
        radial-gradient(circle at 20% 30%, var(--obsidian-workshop) 0.5px, transparent 0.5px),
        radial-gradient(circle at 70% 80%, var(--obsidian-workshop) 0.4px, transparent 0.4px),
        radial-gradient(circle at 40% 60%, var(--obsidian-workshop) 0.6px, transparent 0.6px),
        radial-gradient(circle at 90% 20%, var(--obsidian-workshop) 0.3px, transparent 0.3px),
        radial-gradient(circle at 10% 90%, var(--obsidian-workshop) 0.5px, transparent 0.5px);
    background-size: 7px 7px, 11px 11px, 13px 13px, 9px 9px, 15px 15px;
    animation: noiseShift 0.15s steps(3) infinite;
}

@keyframes noiseShift {
    0% { transform: translate(0, 0); }
    33% { transform: translate(-2px, 1px); }
    66% { transform: translate(1px, -2px); }
    100% { transform: translate(0, 0); }
}

/* --- Leather Texture Mixin (applied via pseudo-elements) --- */
.leather-surface::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(28,22,18,0.05) 0%, transparent 70%),
        radial-gradient(ellipse at 80% 20%, rgba(28,22,18,0.04) 0%, transparent 60%),
        radial-gradient(ellipse at 50% 80%, rgba(28,22,18,0.06) 0%, transparent 65%),
        radial-gradient(circle at 30% 30%, rgba(139,115,85,0.04) 0%, transparent 40%),
        radial-gradient(circle at 70% 70%, rgba(139,115,85,0.03) 0%, transparent 45%);
    box-shadow: inset 0 0 60px rgba(28,22,18,0.1);
    z-index: 1;
}

/* --- Embossed Text Effect --- */
.embossed {
    text-shadow:
        1px 1px 1px rgba(28,22,18,0.3),
        -1px -1px 1px rgba(245,237,227,0.5);
}

/* --- Navigation Pill --- */
#nav-pill {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 1000;
    background: var(--weathered-hide);
    border-radius: 32px;
    padding: 12px 16px;
    box-shadow:
        0 4px 24px rgba(28,22,18,0.15),
        inset 0 0 20px rgba(28,22,18,0.05);
    cursor: pointer;
    transition: all 0.4s var(--ease-main);
    display: flex;
    align-items: center;
    gap: 0;
    overflow: hidden;
    max-width: 48px;
}

#nav-pill:hover {
    max-width: 400px;
    gap: 12px;
    padding: 12px 24px;
}

.nav-glyph {
    display: block;
    width: 16px;
    height: 16px;
    min-width: 16px;
    border: 2px solid var(--fired-clay);
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.nav-glyph::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    background: var(--solder-gold);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: nodePulseGlyph 4s ease-out infinite;
}

@keyframes nodePulseGlyph {
    0%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(2.5); }
}

.nav-links {
    display: flex;
    gap: 16px;
    opacity: 0;
    transition: opacity 0.3s var(--ease-main);
    white-space: nowrap;
}

#nav-pill:hover .nav-links {
    opacity: 1;
}

.nav-anchor {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--burnt-sienna);
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color 0.3s var(--ease-main);
    position: relative;
}

.nav-anchor::after {
    content: attr(data-label);
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--oxidized-copper);
    opacity: 0;
    transition: opacity 0.2s var(--ease-main);
    white-space: nowrap;
}

.nav-anchor:hover {
    color: var(--fired-clay);
}

.nav-anchor:hover::after {
    opacity: 1;
}

/* --- Sections Common --- */
.section {
    position: relative;
    min-height: 100vh;
}

.section-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 96px 48px;
    position: relative;
}

/* --- Hero Section --- */
#hero {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--parchment-smoke);
    position: relative;
    overflow: hidden;
    animation: heroDrift 20s ease-in-out infinite alternate;
}

/* Hero leather texture (stronger) */
#hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at 15% 45%, rgba(28,22,18,0.07) 0%, transparent 65%),
        radial-gradient(ellipse at 85% 25%, rgba(28,22,18,0.06) 0%, transparent 55%),
        radial-gradient(ellipse at 45% 85%, rgba(28,22,18,0.08) 0%, transparent 60%),
        radial-gradient(circle at 25% 25%, rgba(139,115,85,0.06) 0%, transparent 40%),
        radial-gradient(circle at 75% 65%, rgba(139,115,85,0.05) 0%, transparent 50%),
        radial-gradient(circle at 55% 35%, rgba(194,112,62,0.03) 0%, transparent 35%);
    box-shadow: inset 0 0 80px rgba(28,22,18,0.12);
    z-index: 1;
}

@keyframes heroDrift {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.03) translate(5px, -5px); }
}

.hero-circuit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.06;
    z-index: 2;
}

.hero-circuit-svg {
    width: 100%;
    height: 100%;
}

.circuit-trace-line {
    stroke: var(--fired-clay);
    stroke-width: 2;
    fill: none;
}

.circuit-node {
    fill: var(--fired-clay);
    stroke: var(--fired-clay);
    stroke-width: 2;
}

.hero-node {
    animation: nodePulseHero 4s ease-out infinite;
}

.hero-node:nth-child(odd) { animation-delay: 0s; }
.hero-node:nth-child(3n) { animation-delay: 1.2s; }
.hero-node:nth-child(5n) { animation-delay: 2.4s; }
.hero-node:nth-child(7n) { animation-delay: 0.8s; }
.hero-node:nth-child(4n) { animation-delay: 1.8s; }

@keyframes nodePulseHero {
    0%, 70% {
        r: 4;
        opacity: 0.8;
    }
    85% {
        r: 8;
        opacity: 0.4;
    }
    100% {
        r: 4;
        opacity: 0.8;
    }
}

.hero-content {
    position: relative;
    z-index: 3;
    text-align: center;
    max-width: 60vw;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.8rem, 7vw, 5.5rem);
    letter-spacing: 0.02em;
    line-height: 1.1;
    color: var(--fired-clay);
    margin-bottom: 24px;
}

.hero-inscription {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.25rem);
    color: var(--oxidized-copper);
    font-style: italic;
    max-width: 480px;
    margin: 0 auto;
    line-height: 1.6;
}

.hero-scroll-indicator {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    animation: scrollBob 2s ease-in-out infinite;
}

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

.scroll-node-pulse {
    animation: scrollNodePulse 2s ease-out infinite;
}

@keyframes scrollNodePulse {
    0%, 60% { r: 4; opacity: 1; }
    80% { r: 8; opacity: 0.3; }
    100% { r: 4; opacity: 1; }
}

/* --- Strata Dividers --- */
.strata-divider {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--parchment-smoke);
}

.strata-divider-narrow {
    height: 80px;
}

.strata-line {
    display: flex;
    align-items: center;
    width: 80%;
    max-width: 900px;
    height: 2px;
    background: var(--fired-clay);
    position: relative;
    justify-content: space-evenly;
}

.strata-node {
    display: block;
    width: 8px;
    height: 8px;
    background: var(--fired-clay);
    border: 2px solid var(--fired-clay);
    border-radius: 50%;
    position: relative;
    z-index: 1;
}

.strata-node::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid var(--solder-gold);
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
    animation: strataNodeRipple 4s var(--ease-ripple) infinite;
}

.strata-node:nth-child(1)::after { animation-delay: 0s; }
.strata-node:nth-child(2)::after { animation-delay: 0.6s; }
.strata-node:nth-child(3)::after { animation-delay: 1.2s; }
.strata-node:nth-child(4)::after { animation-delay: 1.8s; }
.strata-node:nth-child(5)::after { animation-delay: 2.4s; }

@keyframes strataNodeRipple {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    50% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

/* --- Section 2: The Discovery --- */
.section-discovery {
    background: var(--weathered-hide);
    position: relative;
}

.section-discovery::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(28,22,18,0.04) 0%, transparent 65%),
        radial-gradient(ellipse at 80% 30%, rgba(28,22,18,0.03) 0%, transparent 55%),
        radial-gradient(circle at 40% 70%, rgba(139,115,85,0.04) 0%, transparent 50%);
    box-shadow: inset 0 0 60px rgba(28,22,18,0.08);
    z-index: 0;
}

.section-discovery .section-inner {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 32px;
    padding-left: calc(48px + 2vw);
    padding-right: calc(48px + 2vw);
    position: relative;
}

.section-content-left {
    grid-column: 2 / 6;
    position: relative;
    z-index: 2;
}

.section-content-right {
    grid-column: 6 / 8;
    display: flex;
    align-items: center;
    position: relative;
    z-index: 2;
}

.section-circuit-border {
    position: absolute;
    left: 24px;
    top: 0;
    height: 100%;
    width: 40px;
    z-index: 2;
}

.circuit-border-svg {
    width: 100%;
    height: 100%;
}

.border-node {
    animation: borderNodePulse 4s ease-out infinite;
}

.border-node:nth-child(odd) { animation-delay: 0.3s; }
.border-node:nth-child(even) { animation-delay: 1.5s; }

@keyframes borderNodePulse {
    0%, 70% { r: 4; fill-opacity: 1; }
    85% { r: 7; fill-opacity: 0.5; }
    100% { r: 4; fill-opacity: 1; }
}

.section-number {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(3rem, 5vw, 5rem);
    color: var(--fired-clay);
    opacity: 0.15;
    display: block;
    margin-bottom: 16px;
    line-height: 1;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.8rem, 3vw, 2.5rem);
    color: var(--obsidian-workshop);
    letter-spacing: 0.02em;
    line-height: 1.2;
    margin-bottom: 32px;
}

.section-heading-center {
    text-align: center;
}

.section-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.125rem);
    line-height: 1.7;
    color: var(--obsidian-workshop);
    margin-bottom: 24px;
}

.pull-quote {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    color: var(--burnt-sienna);
    line-height: 1.5;
    border-left: 3px solid var(--fired-clay);
    padding-left: 24px;
}

/* --- Section 3: The Mechanism --- */
.section-mechanism {
    background: var(--parchment-smoke);
    position: relative;
}

.section-mechanism::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at 50% 50%, rgba(28,22,18,0.03) 0%, transparent 70%),
        radial-gradient(circle at 30% 40%, rgba(139,115,85,0.03) 0%, transparent 45%);
    box-shadow: inset 0 0 50px rgba(28,22,18,0.06);
    z-index: 0;
}

.section-mechanism .section-inner {
    padding-left: calc(48px + 4vw);
    padding-right: calc(48px + 4vw);
    text-align: center;
    position: relative;
    z-index: 1;
}

.mechanism-diagram {
    width: 100%;
    max-width: 800px;
    margin: 48px auto;
    position: relative;
}

.mechanism-svg {
    width: 100%;
    height: auto;
}

.mechanism-node {
    fill: var(--fired-clay);
    stroke: var(--fired-clay);
    stroke-width: 2;
}

.mechanism-center {
    fill: var(--solder-gold);
    stroke: var(--solder-gold);
    animation: centerNodeGlow 3s ease-in-out infinite alternate;
}

@keyframes centerNodeGlow {
    0% { fill: var(--solder-gold); filter: drop-shadow(0 0 0px var(--solder-gold)); }
    100% { fill: var(--solder-gold); filter: drop-shadow(0 0 8px var(--solder-gold)); }
}

.component-label {
    font-family: var(--font-mono);
    font-size: 11px;
    fill: var(--oxidized-copper);
    letter-spacing: 0.06em;
    text-anchor: middle;
}

.mechanism-text-blocks {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    margin-top: 48px;
    text-align: left;
}

.mechanism-text-left {
    padding-right: 16px;
}

.mechanism-text-right {
    padding-left: 16px;
}

/* --- Section 4: The Signal --- */
.section-signal {
    background: var(--parchment-smoke);
    position: relative;
}

.section-signal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at 50% 50%, rgba(212,168,67,0.04) 0%, transparent 60%),
        radial-gradient(circle at 70% 30%, rgba(194,112,62,0.03) 0%, transparent 50%);
    box-shadow: inset 0 0 50px rgba(28,22,18,0.06);
    z-index: 0;
}

.section-signal .section-inner {
    padding-left: calc(48px + 6vw);
    padding-right: calc(48px + 6vw);
    position: relative;
    z-index: 1;
}

.signal-typography {
    display: flex;
    justify-content: center;
    gap: 2px;
    margin: 48px 0 64px;
    flex-wrap: wrap;
}

.signal-letter {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--solder-gold);
    line-height: 1;
    display: inline-block;
    transform: translateY(var(--offset, 0px));
    text-shadow:
        2px 2px 2px rgba(28,22,18,0.2),
        -1px -1px 1px rgba(245,237,227,0.4);
}

.signal-content {
    max-width: 680px;
    margin: 0 auto;
}

.signal-accent {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1.1rem, 1.4vw, 1.25rem);
    color: var(--fired-clay);
    margin-top: 16px;
}

/* --- Footer --- */
.section-footer {
    min-height: 50vh;
    background: var(--obsidian-workshop);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.section-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at 50% 50%, rgba(139,115,85,0.06) 0%, transparent 60%);
    z-index: 0;
}

.footer-inner {
    text-align: center;
    position: relative;
    z-index: 1;
    padding: 64px 48px;
    max-width: 600px;
}

.footer-circuit-terminal {
    width: 24px;
    margin: 0 auto 40px;
    height: 200px;
}

.terminal-svg {
    width: 100%;
    height: 100%;
}

.terminal-node {
    fill: var(--solder-gold);
    stroke: var(--solder-gold);
    animation: terminalGlow 3s ease-in-out infinite;
}

@keyframes terminalGlow {
    0%, 100% {
        filter: drop-shadow(0 0 4px var(--solder-gold));
        opacity: 0.8;
    }
    50% {
        filter: drop-shadow(0 0 16px var(--solder-gold));
        opacity: 1;
    }
}

.footer-label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.component-id {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--oxidized-copper);
}

.component-meta {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(139,115,85,0.5);
}

/* --- Section Reveal Animations --- */
.section-reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s var(--ease-main), transform 0.6s var(--ease-main);
}

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

/* --- Mechanism Node Cascade (scroll-triggered) --- */
.mechanism-node-active {
    animation: mechanismActivate 0.5s var(--ease-ripple) forwards;
}

@keyframes mechanismActivate {
    0% { r: 4; fill: var(--fired-clay); }
    50% { r: 10; fill: var(--solder-gold); }
    100% { r: 5; fill: var(--solder-gold); }
}

/* --- Click Ripple --- */
.click-ripple {
    position: absolute;
    border-radius: 50%;
    background: var(--solder-gold);
    opacity: 0.3;
    pointer-events: none;
    transform: scale(0);
    animation: clickRippleExpand 0.6s var(--ease-ripple) forwards;
    z-index: 9998;
}

@keyframes clickRippleExpand {
    0% {
        transform: scale(0);
        opacity: 0.3;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* --- Section Boundary Ripple --- */
.section-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    margin-top: -100px;
    margin-left: -100px;
    border-radius: 50%;
    border: 2px solid var(--solder-gold);
    opacity: 0;
    pointer-events: none;
    z-index: 5;
    animation: sectionRippleExpand 1.2s var(--ease-ripple) forwards;
}

@keyframes sectionRippleExpand {
    0% {
        transform: scale(0);
        opacity: 0.4;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* --- Responsive Adjustments --- */
@media (max-width: 1024px) {
    .section-discovery .section-inner {
        grid-template-columns: 1fr;
        padding-left: 48px;
        padding-right: 48px;
    }

    .section-content-left {
        grid-column: 1 / -1;
    }

    .section-content-right {
        grid-column: 1 / -1;
    }

    .section-circuit-border {
        display: none;
    }

    .mechanism-text-blocks {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .mechanism-text-left,
    .mechanism-text-right {
        padding: 0;
    }
}

@media (max-width: 768px) {
    .section-inner {
        padding: 64px 24px;
    }

    .section-discovery .section-inner,
    .section-mechanism .section-inner,
    .section-signal .section-inner {
        padding-left: 24px;
        padding-right: 24px;
    }

    .hero-content {
        max-width: 85vw;
    }

    .signal-typography {
        gap: 0;
    }

    .signal-letter {
        font-size: clamp(2rem, 8vw, 4rem);
    }

    #nav-pill {
        bottom: 16px;
        right: 16px;
    }

    .strata-line {
        width: 90%;
    }

    .footer-inner {
        padding: 48px 24px;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    .section-number {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .pull-quote {
        font-size: clamp(1rem, 4vw, 1.3rem);
    }
}
