/* ==========================================================================
   Cultural Evolution - Shared Styles
   ========================================================================== */

/* CSS Variables - Theme Configuration */
:root {
    --bg: #0a0a0f;
    --bg-card: rgba(0,0,0,0.4);
    --bg-input: rgba(255,255,255,0.2);
    --text: #fff;
    --text-muted: rgba(255,255,255,0.5);
    --border: rgba(255,255,255,0.06);
    --border-strong: rgba(255,255,255,0.2);
    --border-hover: rgba(255,255,255,0.5);
    --nav-bg: rgba(10,10,15,0.95);
    --chart-bg: #0d0d12;
    --node-color: rgba(255,255,255,0.6);
    --line-color: 255,255,255;
}

[data-theme="light"] {
    --bg: #f5f5f7;
    --bg-card: rgba(255,255,255,0.7);
    --bg-input: rgba(0,0,0,0.1);
    --text: #1d1d1f;
    --text-muted: rgba(0,0,0,0.5);
    --border: rgba(0,0,0,0.08);
    --border-strong: rgba(0,0,0,0.2);
    --border-hover: rgba(0,0,0,0.3);
    --nav-bg: rgba(245,245,247,0.95);
    --chart-bg: #fafafa;
    --node-color: rgba(0,0,0,0.5);
    --line-color: 0,0,0;
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* ==========================================================================
   Background Canvas
   ========================================================================== */

#bg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: var(--bg);
}

/* ==========================================================================
   Theme Toggle
   ========================================================================== */

.theme-toggle {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 101;
    background: var(--border);
    border: 1px solid var(--border-strong);
    width: 44px;
    height: 24px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    border-color: var(--text-muted);
}

.theme-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text);
    transition: transform 0.3s;
}

[data-theme="light"] .theme-toggle::after {
    transform: translateX(20px);
}

/* ==========================================================================
   Navigation
   ========================================================================== */

nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 1.5rem 3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, var(--nav-bg), transparent);
}

.logo {
    font-size: 0.75rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    opacity: 0.6;
    text-decoration: none;
    color: var(--text);
    cursor: pointer;
}

.logo:hover {
    opacity: 0.8;
}

.nav-links {
    display: flex;
    gap: 2rem;
    margin-right: 3.5rem;
}

.nav-links a {
    color: var(--text);
    text-decoration: none;
    font-size: 0.8rem;
    opacity: 0.6;
    transition: opacity 0.3s;
    cursor: pointer;
}

.nav-links a:hover,
.nav-links a.active {
    opacity: 1;
}

/* ==========================================================================
   Sections
   ========================================================================== */

section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6rem 3rem;
    position: relative;
    z-index: 1;
}

/* ==========================================================================
   Hero Section
   ========================================================================== */

#hero {
    text-align: center;
    position: relative;
    overflow: hidden;
}

#hero h1 {
    font-size: clamp(2.5rem, 8vw, 5rem);
    font-weight: 200;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
    position: relative;
    z-index: 2;
}

#hero .subtitle {
    font-size: 1.1rem;
    opacity: 0.5;
    font-weight: 300;
    max-width: 520px;
    line-height: 1.6;
    position: relative;
    z-index: 2;
}

/* ==========================================================================
   Scroll Indicator
   ========================================================================== */

.scroll-indicator {
    position: absolute;
    bottom: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.4;
    animation: pulse 2s ease-in-out infinite;
    z-index: 2;
    cursor: pointer;
    transition: opacity 0.3s;
}

.scroll-indicator:hover {
    opacity: 0.7;
}

.scroll-indicator span {
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.scroll-indicator .arrow {
    width: 1px;
    height: 40px;
    background: linear-gradient(to bottom, var(--text), transparent);
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.7; }
}

/* ==========================================================================
   Cinematic Entrance Animations
   ========================================================================== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

#hero h1 {
    animation: fadeInUp 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
}

#hero .subtitle {
    animation: fadeInUp 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.5s both;
}

.scroll-indicator {
    animation: fadeIn 1s ease-out 1.2s both;
}

#concept h2,
#insights h2 {
    animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.concept-intro {
    animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
}

.concept-card {
    animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.concept-card:nth-child(1) { animation-delay: 0.2s; }
.concept-card:nth-child(2) { animation-delay: 0.35s; }
.concept-card:nth-child(3) { animation-delay: 0.5s; }

.insight {
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.insight:nth-child(1) { animation-delay: 0.1s; }
.insight:nth-child(2) { animation-delay: 0.2s; }
.insight:nth-child(3) { animation-delay: 0.3s; }

.chapter-link {
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.chapter-link:nth-child(1) { animation-delay: 0.1s; }
.chapter-link:nth-child(2) { animation-delay: 0.2s; }
.chapter-link:nth-child(3) { animation-delay: 0.3s; }
.chapter-link:nth-child(4) { animation-delay: 0.4s; }
.chapter-link:nth-child(5) { animation-delay: 0.5s; }

.sim-container {
    animation: scaleIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Scroll-triggered animation class */
.scroll-animate {
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* ==========================================================================
   Concept Section
   ========================================================================== */

#concept {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

#concept h2 {
    font-size: 2.5rem;
    font-weight: 200;
    margin-bottom: 2rem;
}

.concept-intro {
    opacity: 0.5;
    max-width: 550px;
    line-height: 1.7;
}

.concept-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3rem;
    margin-top: 2.5rem;
    text-align: left;
}

.concept-card {
    padding: 0;
}

.concept-card h4 {
    font-size: 0.9rem;
    font-weight: 400;
    margin-bottom: 0.6rem;
    opacity: 0.9;
}

.concept-card p {
    font-size: 0.8rem;
    line-height: 1.6;
    opacity: 0.4;
}

/* ==========================================================================
   Simulation Section
   ========================================================================== */

#simulation {
    min-height: 100vh;
}

.sim-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    width: 100%;
    max-width: 1200px;
}

/* Chart */
.chart-wrapper {
    padding: 0;
}

#chart {
    width: 100%;
    height: 450px;
    background: var(--chart-bg);
    border-radius: 4px;
}

/* Legend */
.legend {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    opacity: 0.6;
}

.legend-line {
    width: 20px;
    height: 2px;
}

/* ==========================================================================
   Controls Panel
   ========================================================================== */

.controls {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.4;
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    opacity: 0.5;
    display: flex;
    justify-content: space-between;
}

.control-group label span {
    opacity: 1;
    font-variant-numeric: tabular-nums;
}

.control-group.highlight label {
    opacity: 0.6;
}

/* Range Inputs */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 2px;
    background: var(--bg-input);
    border-radius: 1px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--text);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--text);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
}

/* Parameter Row (for side-by-side controls) */
.param-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Toggle Group */
.toggle-group {
    display: flex;
    gap: 0;
    background: var(--border);
    border-radius: 6px;
    padding: 3px;
}

.toggle-btn {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0.5;
}

.toggle-btn.active {
    background: var(--border-strong);
    opacity: 1;
}

/* Selection Indicator (for biased transmission) */
.selection-indicator {
    padding: 0.75rem 0;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.selection-indicator .label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.4;
    margin-bottom: 0.3rem;
}

.selection-indicator .value {
    font-size: 1.1rem;
    font-weight: 300;
    opacity: 0.9;
    font-variant-numeric: tabular-nums;
}

.selection-indicator .desc {
    font-size: 0.65rem;
    opacity: 0.4;
    margin-top: 0.3rem;
}

/* Buttons */
.buttons {
    display: flex;
    gap: 0.5rem;
}

button {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s;
    border-radius: 4px;
}

button:hover {
    background: var(--border);
    border-color: var(--text-muted);
}

button.primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

button.primary:hover {
    opacity: 0.9;
}

/* Info Panel */
.info-panel {
    padding: 0;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.info-panel h3 {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    opacity: 0.3;
    margin-bottom: 0.5rem;
}

.info-panel p {
    font-size: 0.8rem;
    line-height: 1.5;
    opacity: 0.5;
}

/* ==========================================================================
   Insights Section
   ========================================================================== */

#insights {
    max-width: 600px;
    margin: 0 auto;
}

#insights h2 {
    font-size: 2rem;
    font-weight: 200;
    margin-bottom: 2rem;
    text-align: center;
}

.insight {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border);
}

.insight:last-child {
    border-bottom: none;
}

.insight h3 {
    font-size: 1.1rem;
    font-weight: 300;
    margin-bottom: 0.5rem;
}

.insight p {
    font-size: 0.85rem;
    line-height: 1.6;
    opacity: 0.5;
}

/* ==========================================================================
   Chapter Links (Index Page)
   ========================================================================== */

#chapters {
    min-height: auto;
    padding: 4rem 3rem 6rem;
}

.chapters-container {
    max-width: 700px;
    width: 100%;
}

.chapter-link {
    display: block;
    padding: 2.5rem 0;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: all 0.3s ease;
}

.chapter-link:first-child {
    border-top: 1px solid var(--border);
}

.chapter-link:hover {
    padding-left: 1rem;
}

.chapter-link:hover .chapter-title {
    opacity: 1;
}

.chapter-link:hover .chapter-arrow {
    opacity: 0.6;
    transform: translateX(0.5rem);
}

.chapter-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.chapter-number {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    opacity: 0.3;
}

.chapter-arrow {
    font-size: 1.2rem;
    opacity: 0;
    transition: all 0.3s;
    font-weight: 200;
}

.chapter-title {
    font-size: 1.8rem;
    font-weight: 200;
    margin-bottom: 0.75rem;
    opacity: 0.9;
    transition: opacity 0.3s;
}

.chapter-desc {
    font-size: 0.85rem;
    opacity: 0.4;
    line-height: 1.6;
    max-width: 500px;
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
    padding: 2rem;
    text-align: center;
    opacity: 0.3;
    font-size: 0.7rem;
    position: relative;
    z-index: 1;
    line-height: 1.8;
}

footer a {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.3s;
}

footer a:hover {
    border-color: var(--border-hover);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 1024px) {
    .sim-container {
        grid-template-columns: 1fr;
    }

    .concept-grid {
        grid-template-columns: 1fr;
    }

    .param-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    nav {
        padding: 1rem 1.5rem;
    }

    section {
        padding: 4rem 1.5rem;
    }

    #chapters {
        padding: 2rem 1.5rem 4rem;
    }

    .chapter-link {
        padding: 2rem 0;
    }

    .chapter-title {
        font-size: 1.4rem;
    }
}
