/* ===================================================
   ringworld.quest - Grainy Textured Timeline Vertical
   =================================================== */

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

:root {
    --bg-primary: #1e1e1a;
    --bg-secondary: #2a2926;
    --surface: #3d3b36;
    --text-primary: #e8dcc0;
    --text-secondary: #c8bda8;
    --text-tertiary: #9a9a8a;
    --accent-primary: #6d4c2e;
    --accent-secondary: #5a7a6a;
    --highlight: #b89a5a;
    --text-graphite: #3a3a34;
    --spine-position: 38.2%;
    --scroll-progress: 0;
}

html {
    scroll-behavior: auto;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.06;
    mix-blend-mode: overlay;
}

#grain-overlay svg {
    width: 100%;
    height: 100%;
}

/* --- Orbital Arcs --- */
#orbital-arcs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.orbital-arc {
    position: absolute;
    will-change: transform;
}

.arc-1 {
    width: 600px;
    height: 600px;
    top: 5%;
    left: 15%;
    transform: rotate(-15deg);
}

.arc-2 {
    width: 1040px;
    height: 1040px;
    top: 25%;
    right: -20%;
    transform: rotate(30deg);
}

.arc-3 {
    width: 1560px;
    height: 1560px;
    top: 50%;
    left: -30%;
    transform: rotate(10deg);
}

.arc-4 {
    width: 800px;
    height: 800px;
    top: 75%;
    right: 5%;
    transform: rotate(-25deg);
}

.arc-path {
    stroke-dasharray: 2500;
    stroke-dashoffset: 2500;
    transition: stroke-dashoffset 0.1s linear;
}

/* --- Central Spine --- */
#spine {
    position: fixed;
    left: var(--spine-position);
    top: 0;
    width: 2px;
    height: 100vh;
    z-index: 1;
    pointer-events: none;
}

#spine-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background-color: var(--text-tertiary);
    transform: scaleY(0);
    transform-origin: top;
    opacity: 0.5;
}

#spine-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(
        to bottom,
        var(--accent-primary) 0%,
        var(--accent-primary) calc(var(--scroll-progress) * 100%),
        transparent calc(var(--scroll-progress) * 100%)
    );
    opacity: 0.8;
}

/* --- Hero Section --- */
#hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    overflow: hidden;
}

.hero-grid {
    display: grid;
    grid-template-columns: 1fr 2px 1fr;
    width: 100%;
    max-width: 1200px;
    padding: 0 2rem;
    position: relative;
}

.hero-left {
    justify-self: end;
    text-align: right;
    padding-right: 3rem;
    max-width: 480px;
}

.hero-right {
    justify-self: start;
    padding-left: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

#hero-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(2.8rem, 7vw, 6rem);
    letter-spacing: 0.02em;
    color: var(--text-primary);
    line-height: 1.1;
    opacity: 0;
    transform: translateY(20px);
}

#hero-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-top: 1.5rem;
    opacity: 0;
    transform: translateY(10px);
}

/* --- Ring Cross-Section Diagram --- */
#ring-diagram {
    position: relative;
    width: 240px;
    height: 240px;
    opacity: 0;
    transform: scale(0.95);
    animation: spin 120s linear infinite;
    animation-play-state: paused;
}

#ring-diagram.active {
    animation-play-state: running;
}

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

.ring {
    position: absolute;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.ring-outer {
    width: 220px;
    height: 220px;
    border: 2px dashed var(--text-tertiary);
    border-spacing: 8px 4px;
    opacity: 0.7;
}

.ring-mid {
    width: 170px;
    height: 170px;
    border: 1px solid var(--accent-secondary);
    opacity: 0.6;
}

.ring-inner {
    width: 120px;
    height: 120px;
    border: 1.5px solid var(--accent-primary);
    opacity: 0.8;
}

.ring-core {
    width: 60px;
    height: 60px;
    border: 2px solid var(--text-tertiary);
}

/* --- Viewport Sections --- */
.viewport-section {
    position: relative;
    min-height: 100vh;
    z-index: 2;
}

/* --- Timeline Grid --- */
.timeline-grid {
    display: grid;
    grid-template-columns: 1fr 2px 1fr;
    min-height: 100vh;
    align-items: center;
    position: relative;
}

/* --- Gate Markers --- */
.gate {
    position: absolute;
    top: 0;
    left: calc(var(--spine-position) - 60px);
    width: 120px;
    height: 2px;
    background-color: var(--text-tertiary);
    opacity: 0;
    transition: opacity 200ms cubic-bezier(0.23, 1, 0.32, 1);
    z-index: 3;
}

.gate.active {
    opacity: 0.6;
}

/* --- Station Blocks --- */
.station {
    position: relative;
    padding: 2rem;
}

.station-left {
    grid-column: 1;
    justify-self: end;
    text-align: right;
    max-width: 480px;
    margin-right: 3rem;
}

.station-right {
    grid-column: 3;
    justify-self: start;
    text-align: left;
    max-width: 480px;
    margin-left: 3rem;
}

/* --- Station Content --- */
.station-content {
    opacity: 0;
    transform: translateY(30px);
}

.station-content.revealed {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 600ms cubic-bezier(0.23, 1, 0.32, 1) 300ms,
                transform 600ms cubic-bezier(0.23, 1, 0.32, 1) 300ms;
}

.station-epoch {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.65rem, 1.1vw, 0.8rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    display: block;
    margin-bottom: 0.75rem;
}

.station-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(1.6rem, 3.2vw, 2.4rem);
    letter-spacing: 0.02em;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 1rem;
}

.station-body {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    color: var(--text-secondary);
    max-width: 42ch;
}

.station-left .station-body {
    margin-left: auto;
}

/* --- Connector Lines --- */
.connector {
    position: absolute;
    top: 50%;
    height: 1px;
    z-index: 3;
}

.connector-left {
    right: -3rem;
    width: calc(3rem + 2px);
    transform: translateY(-50%);
}

.connector-right {
    left: -3rem;
    width: calc(3rem + 2px);
    transform: translateY(-50%);
}

.connector-line {
    width: 100%;
    height: 1px;
    background-color: var(--text-tertiary);
    transform: scaleX(0);
    opacity: 0.5;
}

.connector-left .connector-line {
    transform-origin: right;
    border-top-right-radius: 12px;
}

.connector-right .connector-line {
    transform-origin: left;
    border-top-left-radius: 12px;
}

.connector-line.revealed {
    transform: scaleX(1);
    transition: transform 400ms cubic-bezier(0.23, 1, 0.32, 1) 200ms;
}

/* --- Waypoint Markers --- */
.waypoint-marker {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    z-index: 4;
}

.waypoint-marker[data-side="left"] {
    right: calc(-3rem - 8px);
}

.waypoint-marker[data-side="right"] {
    left: calc(-3rem - 8px);
}

.waypoint-glyph {
    width: 16px;
    height: 16px;
    opacity: 0;
    transform: scale(0.8);
}

.waypoint-glyph.revealed {
    opacity: 1;
    transform: scale(1);
    transition: opacity 300ms cubic-bezier(0.23, 1, 0.32, 1) 100ms,
                transform 300ms cubic-bezier(0.23, 1, 0.32, 1) 100ms;
}

/* --- Terminus Section --- */
#terminus {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
}

.terminus-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#terminus-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(2.8rem, 7vw, 6rem);
    letter-spacing: 0.02em;
    color: var(--text-primary);
    line-height: 1.1;
    opacity: 0;
    transform: translateY(30px);
}

#terminus-title.revealed {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 800ms cubic-bezier(0.23, 1, 0.32, 1),
                transform 800ms cubic-bezier(0.23, 1, 0.32, 1);
}

#terminus-marker {
    position: relative;
    margin-top: 3rem;
    width: 24px;
    height: 24px;
    opacity: 0;
}

#terminus-marker.revealed {
    opacity: 1;
    transition: opacity 400ms ease;
}

.terminus-dot {
    width: 8px;
    height: 8px;
    background-color: var(--highlight);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.terminus-dot.expanded {
    width: 24px;
    height: 24px;
    transition: width 400ms cubic-bezier(0.23, 1, 0.32, 1),
                height 400ms cubic-bezier(0.23, 1, 0.32, 1);
}

.terminus-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0;
    height: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 var(--highlight);
    opacity: 0;
}

.terminus-pulse.active {
    animation: terminus-pulse-anim 800ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes terminus-pulse-anim {
    0% {
        width: 0;
        height: 0;
        box-shadow: 0 0 0 0 var(--highlight);
        opacity: 0.6;
    }
    100% {
        width: 80px;
        height: 80px;
        box-shadow: 0 0 20px 2px var(--highlight);
        opacity: 0;
    }
}

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

    #spine-line {
        transform: scaleY(1) !important;
    }

    #hero-title,
    #hero-subtitle,
    #ring-diagram,
    .station-content,
    .connector-line,
    .waypoint-glyph,
    #terminus-title,
    #terminus-marker {
        opacity: 1 !important;
        transform: none !important;
    }

    .gate {
        opacity: 0.6 !important;
    }
}

/* --- Mobile Responsive (< 768px) --- */
@media (max-width: 767px) {
    :root {
        --spine-position: 12%;
    }

    .hero-grid {
        grid-template-columns: 1fr;
        padding: 0 1.5rem 0 calc(12% + 2rem);
    }

    .hero-left {
        text-align: left;
        padding-right: 0;
        justify-self: start;
    }

    .hero-right {
        padding-left: 0;
        justify-self: start;
        margin-top: 2rem;
    }

    .timeline-grid {
        grid-template-columns: 1fr;
        padding-left: calc(12% + 2rem);
    }

    .station-left,
    .station-right {
        grid-column: 1;
        justify-self: start;
        text-align: left;
        margin-left: 2rem;
        margin-right: 0;
        max-width: calc(100vw - 12% - 4rem);
    }

    .station-left .station-body {
        margin-left: 0;
    }

    .connector-left,
    .connector-right {
        left: -2rem;
        right: auto;
        width: 2rem;
    }

    .connector-left .connector-line,
    .connector-right .connector-line {
        transform-origin: left;
        border-top-left-radius: 12px;
        border-top-right-radius: 0;
    }

    .waypoint-marker[data-side="left"],
    .waypoint-marker[data-side="right"] {
        left: calc(-2rem - 8px);
        right: auto;
    }

    .gate {
        left: calc(12% - 60px);
    }

    #ring-diagram {
        width: 160px;
        height: 160px;
    }

    .ring-outer { width: 150px; height: 150px; }
    .ring-mid { width: 115px; height: 115px; }
    .ring-inner { width: 80px; height: 80px; }
    .ring-core { width: 40px; height: 40px; }
}
