/* sim-ai.org - Scandinavian Scholarly Simulation Design */
/* Fonts: Space Grotesk 500, Inter 300/400, JetBrains Mono 400, Cormorant Garamond 300i */

:root {
    --bg-primary: #f5f0e8;
    --bg-dark: #2c2620;
    --text-primary: #3b3028;
    --text-body: #4a4035;
    --text-secondary: #8a7d6e;
    --text-light: #e8ddd0;
    --accent-gold: #b78e56;
    --accent-birch: #c9b99a;
    --accent-resin: #6b5638;
    --accent-ember: #d4a35a;
    --shadow: #1e1a15;
    --accent-brass: #7a6548;
    --line-color: #a0896a;
    --scroll: 0;
}

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

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

body {
    background-color: var(--bg-primary);
    color: var(--text-body);
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
}

/* Top anchor line */
#top-line {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background-color: rgba(160, 137, 106, 0.3);
    z-index: 100;
}

/* Sticky header */
#sticky-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background-color: rgba(245, 240, 232, 0.95);
    backdrop-filter: blur(8px);
    z-index: 90;
    opacity: 0;
    transform: translateY(-100%);
    transition: opacity 0.5s ease, transform 0.5s ease;
    border-bottom: 1px solid rgba(201, 185, 154, 0.2);
}

#sticky-header.visible {
    opacity: 1;
    transform: translateY(0);
}

.header-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-primary);
}

#contents-toggle {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: 0.8rem;
    color: var(--accent-gold);
    background: none;
    border: none;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: color 0.3s ease;
}

#contents-toggle:hover {
    color: var(--accent-resin);
}

/* Table of contents panel */
#toc-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    max-width: 90vw;
    height: 100vh;
    background-color: var(--bg-primary);
    border-left: 1px solid var(--accent-birch);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

#toc-panel.open {
    transform: translateX(0);
}

.toc-inner {
    padding: 3rem 2.5rem;
}

#toc-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 1.5rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    transition: color 0.3s ease;
}

#toc-close:hover {
    color: var(--text-primary);
}

.toc-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 1.2rem;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 2rem;
}

.toc-list {
    list-style: none;
    counter-reset: toc-counter;
}

.toc-list li {
    margin-bottom: 1rem;
}

.toc-link {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
    line-height: 1.4;
}

.toc-link:hover {
    color: var(--accent-gold);
}

#toc-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(30, 26, 21, 0.3);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

#toc-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Bubble field */
#bubble-field {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* Section base */
section {
    position: relative;
    z-index: 2;
}

/* Hero section */
.section-hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.candle-glow {
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
}

.candle-glow--hero {
    width: 60vw;
    height: 45vh;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(ellipse at center, rgba(183, 142, 86, 0.08), transparent 70%);
    opacity: 0;
    animation: candleBloom 2s ease-out 1.8s forwards;
}

@keyframes candleBloom {
    to { opacity: 1; }
}

@keyframes candleflicker {
    0%, 100% { opacity: 0.06; }
    50% { opacity: 0.09; }
}

.hero-content {
    text-align: center;
    position: relative;
    z-index: 5;
    padding: 2rem;
}

.hero-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.05;
    margin-bottom: 2rem;
}

.letter {
    display: inline-block;
    opacity: 0;
    animation: letterFadeIn 120ms ease forwards;
    animation-delay: calc(800ms + var(--i) * 60ms);
}

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

.hero-subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    color: var(--accent-brass);
    max-width: 36em;
    margin: 0 auto;
    line-height: 1.5;
    opacity: 0;
    animation: subtitleFadeIn 800ms ease forwards;
    animation-delay: 1.5s;
}

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

/* Diagonal bridges */
.diagonal-bridge {
    background-color: var(--bg-dark);
    padding: 6vh 8vw;
    clip-path: polygon(0 15%, 100% 0, 100% 85%, 0 100%);
    position: relative;
    z-index: 3;
    min-height: 8vh;
}

.diagonal-bridge--reverse {
    clip-path: polygon(0 0, 100% 15%, 100% 100%, 0 85%);
}

.bridge-content {
    text-align: center;
    padding: 3rem 0;
}

.bridge-line {
    width: 60%;
    max-width: 500px;
    height: 10px;
    margin: 0 auto 1.5rem;
    display: block;
    overflow: visible;
}

.draw-line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 1.2s ease;
}

.draw-line--right {
    stroke-dashoffset: -400;
}

.draw-line.animated {
    stroke-dashoffset: 0;
}

.bridge-circle {
    opacity: 0;
    transition: opacity 0.4s ease 0.8s;
}

.bridge-circle.animated {
    opacity: 1;
}

.bridge-text {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: 0.95rem;
    color: var(--accent-birch);
    letter-spacing: 0.01em;
    line-height: 1.6;
    max-width: 40em;
    margin: 0 auto;
}

/* Annotation sections */
.section-annotation {
    background-color: var(--bg-primary);
    padding: 12vh 8vw;
    position: relative;
    overflow: hidden;
}

.sim-grid-bg {
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 39.5px, rgba(201, 185, 154, 0.1) 39.5px, rgba(201, 185, 154, 0.1) 40px),
        repeating-linear-gradient(90deg, transparent, transparent 39.5px, rgba(201, 185, 154, 0.1) 39.5px, rgba(201, 185, 154, 0.1) 40px);
    mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, transparent 20%, black 80%);
    -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, transparent 20%, black 80%);
    pointer-events: none;
}

.annotation-layout {
    display: grid;
    grid-template-columns: 1fr 0.65fr;
    gap: 4rem;
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

.annotation-layout--reversed {
    grid-template-columns: 0.65fr 1fr;
}

.annotation-main {
    position: relative;
}

.annotation-margin {
    margin-top: 3rem;
    position: relative;
}

.section-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(2.4rem, 5.5vw, 4.8rem);
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.05;
    margin-bottom: 2rem;
}

.body-text {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.1vw, 1.2rem);
    color: var(--text-body);
    line-height: 1.72;
    letter-spacing: 0.005em;
    max-width: 38em;
    margin-bottom: 1.5rem;
}

.code-term {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 0.9em;
    background: rgba(183, 142, 86, 0.1);
    border-radius: 3px;
    padding: 0.15em 0.4em;
}

/* Margin notes */
.margin-note {
    margin-bottom: 2.5rem;
    padding-left: 1rem;
    border-left: 2px solid var(--accent-birch);
}

.margin-glyph {
    display: block;
    margin-bottom: 0.5rem;
}

.margin-text {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.55;
}

/* Candle Pool sections */
.section-candle-pool {
    background-color: var(--bg-dark);
    padding: 12vh 8vw;
    position: relative;
    overflow: hidden;
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.candle-glow--pool {
    width: 60%;
    height: 45%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(ellipse 60% 45% at 50% 40%, rgba(183, 142, 86, 0.08), transparent);
    animation: candleflicker 6s ease-in-out infinite;
}

.candle-glow--left {
    left: 35%;
    transform: translate(-50%, -50%);
}

.candle-glow--right {
    left: 65%;
    transform: translate(-50%, -50%);
}

.candle-pool-content {
    position: relative;
    z-index: 5;
    text-align: center;
    max-width: 48em;
    margin: 0 auto;
}

.pool-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    color: var(--text-light);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.pool-bubbles {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.bubble-dark {
    fill: none;
    stroke: var(--accent-birch);
    stroke-width: 0.5;
    opacity: 0.15;
}

.bubble-dark[style*="--depth:1"] { opacity: 0.25; }
.bubble-dark[style*="--depth:2"] { opacity: 0.2; }
.bubble-dark[style*="--depth:3"] { opacity: 0.15; }
.bubble-dark[style*="--depth:4"] { opacity: 0.1; }
.bubble-dark[style*="--depth:5"] { opacity: 0.06; }

/* Zoom focus animation */
.zoom-focus {
    opacity: 0;
    transform: scale(0.97);
    filter: blur(2px);
    transition: opacity 600ms ease, transform 600ms ease, filter 600ms ease;
}

.zoom-focus.visible {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
}

.zoom-focus--reverse {
    transform: scale(1.03);
}

.zoom-focus--reverse.visible {
    transform: scale(1);
}

/* Colophon */
.section-colophon {
    background-color: var(--bg-primary);
    padding: 16vh 8vw;
    text-align: center;
    position: relative;
    overflow: hidden;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.candle-glow--colophon {
    width: 50vw;
    height: 40vh;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(ellipse at center, rgba(183, 142, 86, 0.06), transparent 70%);
    animation: candleflicker 6s ease-in-out infinite;
}

.colophon-content {
    position: relative;
    z-index: 5;
    max-width: 36em;
    margin: 0 auto;
}

.colophon-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    color: var(--accent-brass);
    line-height: 1.5;
    margin-bottom: 3rem;
}

.colophon-attribution {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    text-transform: lowercase;
}

.final-bubble {
    position: absolute;
    bottom: 20%;
    left: 50%;
    width: 60px;
    height: 60px;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 3;
}

.bubble-ascending {
    animation: bubbleRise 8s ease-in-out infinite;
}

@keyframes bubbleRise {
    0% { transform: translateY(0); opacity: 0.3; }
    100% { transform: translateY(-200px); opacity: 0; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .letter {
        opacity: 1;
        animation: none;
    }
    .hero-subtitle {
        opacity: 1;
        animation: none;
    }
    .candle-glow--hero {
        opacity: 1;
        animation: none;
    }
    .candle-glow--pool,
    .candle-glow--colophon {
        animation: none;
    }
    .zoom-focus {
        opacity: 1;
        transform: none;
        filter: none;
        transition: none;
    }
    .draw-line {
        stroke-dasharray: none;
        stroke-dashoffset: 0;
    }
    .bridge-circle {
        opacity: 1;
    }
    .bubble-ascending {
        animation: none;
        opacity: 0.3;
    }
    #bubble-field {
        display: none;
    }
}

/* Mobile responsive */
@media (max-width: 768px) {
    .annotation-layout,
    .annotation-layout--reversed {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .annotation-margin {
        margin-top: 0;
    }

    .section-annotation {
        padding: 8vh 5vw;
    }

    .section-candle-pool {
        padding: 8vh 5vw;
    }

    .diagonal-bridge {
        padding: 5vh 5vw;
    }

    #toc-panel {
        width: 100vw;
    }

    .section-heading {
        font-size: clamp(1.8rem, 6vw, 2.8rem);
    }

    .pool-heading {
        font-size: clamp(1.4rem, 5vw, 2.2rem);
    }
}
