/* ============================
   RESET & VARIABLES
   ============================ */

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

:root {
    --bg: #0c0e13;
    --bg-surface: #141720;
    --bg-elevated: #1a1e2a;
    --bg-code: #0d1117;
    --text: #d4d4d8;
    --text-muted: #71717a;
    --text-bright: #fafafa;
    --accent: #60a5fa;
    --accent-dim: #2563eb;
    --green: #4ade80;
    --amber: #fbbf24;
    --red: #f87171;
    --purple: #c084fc;
    --border: #27272a;
    --border-light: #3f3f46;
    --font-serif: 'Source Serif 4', Georgia, serif;
    --font-sans: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
    --max-width: 960px;
    --max-width-wide: 1100px;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--text-bright);
}

img {
    max-width: 100%;
    display: block;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 24px;
}

.container-wide {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    padding: 0 24px;
}

/* ============================
   NAVIGATION
   ============================ */

.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: rgba(12, 14, 19, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.nav-logo {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.nav-logo:hover {
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 32px;
}

.nav-links a {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    transition: color 0.2s;
    position: relative;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text-bright);
}

.nav-links a.active::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-direction: column;
    gap: 5px;
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-muted);
    transition: all 0.3s;
}

/* ============================
   HERO
   ============================ */

.hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 120px 24px 80px;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    opacity: 0.4;
}

.grid-overlay {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(96, 165, 250, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(96, 165, 250, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
}

.hero-content {
    position: relative;
    max-width: 720px;
    text-align: center;
}

.hero-eyebrow {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 24px;
    opacity: 0;
    animation: fadeUp 0.8s ease forwards;
}

.hero h1 {
    font-family: var(--font-serif);
    font-size: clamp(3rem, 8vw, 5.5rem);
    font-weight: 700;
    line-height: 1.05;
    color: var(--text-bright);
    margin-bottom: 24px;
    opacity: 0;
    animation: fadeUp 0.8s ease 0.15s forwards;
}

.hero-subtitle {
    font-size: 1.15rem;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 560px;
    margin: 0 auto 48px;
    opacity: 0;
    animation: fadeUp 0.8s ease 0.3s forwards;
}

.hero-code {
    margin-bottom: 48px;
    opacity: 0;
    animation: fadeUp 0.8s ease 0.45s forwards;
}

.code-window {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px 32px;
    display: inline-block;
    text-align: left;
    position: relative;
}

.code-dots {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}

.code-dots span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-light);
}

.code-dots span:first-child { background: #ef4444; }
.code-dots span:nth-child(2) { background: #f59e0b; }
.code-dots span:last-child { background: #22c55e; }

.code-window pre {
    margin: 0;
}

.code-window code {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    color: var(--text);
}

.hero-code-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 16px;
    font-family: var(--font-mono);
}

.hero-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
    opacity: 0;
    animation: fadeUp 0.8s ease 0.6s forwards;
}

.btn {
    padding: 14px 28px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font-sans);
    transition: all 0.2s;
    cursor: pointer;
    border: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg);
}

.btn-primary:hover {
    background: var(--text-bright);
    color: var(--bg);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover {
    border-color: var(--text-muted);
    color: var(--text-bright);
}

/* ============================
   OVERVIEW
   ============================ */

.overview {
    padding: 100px 0;
    border-top: 1px solid var(--border);
}

.overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 80px;
    align-items: start;
}

.overview-text h2 {
    font-family: var(--font-serif);
    font-size: 2rem;
    color: var(--text-bright);
    margin-bottom: 24px;
    font-weight: 600;
}

.overview-text p {
    margin-bottom: 16px;
    color: var(--text);
    line-height: 1.8;
}

.overview-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-num {
    font-family: var(--font-mono);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ============================
   CHAPTERS
   ============================ */

.chapters {
    padding: 80px 0 120px;
}

.chapters h2 {
    font-family: var(--font-serif);
    font-size: 2rem;
    color: var(--text-bright);
    margin-bottom: 48px;
    font-weight: 600;
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.chapter-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: all 0.3s ease;
    color: var(--text);
}

.chapter-card:hover {
    border-color: var(--accent-dim);
    transform: translateY(-4px);
    background: var(--bg-elevated);
}

.chapter-icon {
    width: 48px;
    height: 48px;
    color: var(--accent);
}

.chapter-card h3 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    color: var(--text-bright);
    font-weight: 600;
}

.chapter-card p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.chapter-link {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent);
    margin-top: auto;
}

/* ============================
   QUOTE
   ============================ */

.quote-section {
    padding: 100px 0;
    border-top: 1px solid var(--border);
}

.quote-section blockquote {
    max-width: 640px;
    margin: 0 auto;
    text-align: center;
}

.quote-section blockquote p {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    font-weight: 400;
    font-style: italic;
    color: var(--text-bright);
    line-height: 1.6;
    margin-bottom: 20px;
}

.quote-section cite {
    font-style: normal;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ============================
   PAGE HEADERS (inner pages)
   ============================ */

.page-header {
    padding: 140px 0 60px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.page-header h1 {
    font-family: var(--font-serif);
    font-size: clamp(2.2rem, 5vw, 3.5rem);
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 16px;
}

.page-header .lead {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 560px;
    margin: 0 auto;
    line-height: 1.7;
}

/* ============================
   CONTENT SECTIONS
   ============================ */

.content-section {
    padding: 80px 0;
    border-bottom: 1px solid var(--border);
}

.content-section:last-of-type {
    border-bottom: none;
}

.content-section h2 {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    color: var(--text-bright);
    margin-bottom: 24px;
    font-weight: 600;
}

.content-section h3 {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    color: var(--text-bright);
    margin-bottom: 16px;
    font-weight: 600;
}

.content-section p {
    margin-bottom: 16px;
    line-height: 1.8;
}

.content-section p:last-child {
    margin-bottom: 0;
}

/* ============================
   LAYER CARDS (stack page)
   ============================ */

.layer {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 24px;
    overflow: hidden;
    transition: border-color 0.3s;
}

.layer:hover {
    border-color: var(--border-light);
}

.layer-header {
    display: flex;
    align-items: center;
    padding: 24px 28px;
    cursor: pointer;
    gap: 20px;
    user-select: none;
}

.layer-num {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
    color: var(--bg);
}

.layer-num.l1 { background: var(--accent); }
.layer-num.l2 { background: #34d399; }
.layer-num.l3 { background: var(--green); }
.layer-num.l4 { background: var(--amber); }
.layer-num.l5 { background: #fb923c; }
.layer-num.l6 { background: var(--red); }
.layer-num.l7 { background: var(--purple); }

.layer-info {
    flex-grow: 1;
}

.layer-title {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 2px;
}

.layer-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.layer-badge {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent);
    background: rgba(96, 165, 250, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
}

.layer-toggle {
    color: var(--text-muted);
    transition: transform 0.3s;
    font-size: 0.8rem;
}

.layer.open .layer-toggle {
    transform: rotate(180deg);
}

.layer-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease;
}

.layer.open .layer-body {
    max-height: 800px;
}

.layer-content {
    padding: 0 28px 28px 92px;
}

.layer-content p {
    color: var(--text);
    line-height: 1.8;
    margin-bottom: 20px;
}

/* ============================
   CODE BLOCKS
   ============================ */

.code-block {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 20px;
    position: relative;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.code-block pre {
    padding: 20px;
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.65;
    color: var(--text);
    overflow-x: auto;
}

.code-block .kw { color: #ff7b72; }
.code-block .fn { color: #d2a8ff; }
.code-block .str { color: #a5d6ff; }
.code-block .num { color: #79c0ff; }
.code-block .type { color: #7ee787; }
.code-block .cmt { color: #6e7681; font-style: italic; }

/* Also for hero */
.kw { color: #ff7b72; }
.str { color: #a5d6ff; }
.fn { color: #d2a8ff; }

/* ============================
   TIMELINE (history page)
   ============================ */

.timeline {
    position: relative;
    padding: 40px 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 28px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-left: 72px;
    margin-bottom: 56px;
}

.timeline-item:last-child {
    margin-bottom: 0;
}

.timeline-dot {
    position: absolute;
    left: 18px;
    top: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--accent);
    z-index: 1;
}

.timeline-dot.highlight {
    background: var(--accent);
    box-shadow: 0 0 12px rgba(96, 165, 250, 0.4);
}

.timeline-year {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.timeline-item h3 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 12px;
}

.timeline-item p {
    color: var(--text);
    line-height: 1.8;
}

/* ============================
   ERROR CARDS (errors page)
   ============================ */

.error-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    margin-bottom: 32px;
    position: relative;
    overflow: hidden;
}

.error-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.error-card.moth::before { background: var(--green); }
.error-card.pentium::before { background: var(--amber); }
.error-card.cosmic::before { background: var(--purple); }
.error-card.mario::before { background: var(--red); }

.error-card .error-layer {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 12px;
}

.error-card.moth .error-layer { color: var(--green); }
.error-card.pentium .error-layer { color: var(--amber); }
.error-card.cosmic .error-layer { color: var(--purple); }
.error-card.mario .error-layer { color: var(--red); }

.error-card h3 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    color: var(--text-bright);
    margin-bottom: 16px;
    font-weight: 600;
}

.error-card p {
    line-height: 1.8;
    margin-bottom: 12px;
}

.error-card .error-detail {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin-top: 20px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.error-card .error-cost {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--accent);
    margin-top: 12px;
}

/* ============================
   BIT FLIP DEMO
   ============================ */

.bitflip-demo {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    margin: 32px 0;
}

.bitflip-demo h3 {
    font-family: var(--font-serif);
    color: var(--text-bright);
    margin-bottom: 8px;
}

.bitflip-demo .demo-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.bit-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.bit-cell {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: all 0.3s;
    cursor: default;
}

.bit-cell.flipped {
    background: rgba(248, 113, 113, 0.15);
    border-color: var(--red);
    color: var(--red);
    animation: bitPulse 0.6s ease;
}

.bit-label {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.demo-btn {
    padding: 10px 24px;
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.demo-btn:hover {
    background: var(--accent);
    color: var(--bg);
}

/* ============================
   ARGUMENT SECTION (probability)
   ============================ */

.argument-block {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    margin: 32px 0;
}

.argument-block h3 {
    font-family: var(--font-serif);
    color: var(--text-bright);
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 1.3rem;
}

.argument-block p {
    line-height: 1.8;
    margin-bottom: 12px;
}

.argument-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 16px;
    display: inline-block;
    padding: 4px 12px;
    border-radius: 4px;
}

.argument-label.critique {
    color: var(--red);
    background: rgba(248, 113, 113, 0.1);
}

.argument-label.response {
    color: var(--green);
    background: rgba(74, 222, 128, 0.1);
}

.argument-label.note {
    color: var(--amber);
    background: rgba(251, 191, 36, 0.1);
}

/* ============================
   FOOTER
   ============================ */

.site-footer {
    border-top: 1px solid var(--border);
    padding: 48px 0;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 40px;
}

.footer-brand {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.footer-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer-right p {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: right;
}

/* ============================
   ANIMATIONS
   ============================ */

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

@keyframes bitPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ============================
   SCROLL REVEAL
   ============================ */

.reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: all 0.6s ease;
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================
   RESPONSIVE
   ============================ */

@media (max-width: 768px) {
    .site-nav {
        padding: 14px 20px;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: 16px 20px;
        gap: 16px;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-toggle {
        display: flex;
    }

    .hero {
        padding: 120px 20px 60px;
    }

    .hero h1 {
        font-size: 2.8rem;
    }

    .code-window code {
        font-size: 1rem;
    }

    .overview-grid {
        grid-template-columns: 1fr;
        gap: 48px;
    }

    .overview-stats {
        grid-template-columns: 1fr 1fr;
    }

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

    .footer-content {
        flex-direction: column;
    }

    .footer-right p {
        text-align: left;
    }

    .layer-content {
        padding-left: 28px;
    }

    .layer-badge {
        display: none;
    }

    .timeline::before {
        left: 14px;
    }

    .timeline-item {
        padding-left: 48px;
    }

    .timeline-dot {
        left: 5px;
        width: 18px;
        height: 18px;
    }

    .bit-cell {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .overview-stats {
        grid-template-columns: 1fr;
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .stat-num {
        font-size: 1.4rem;
    }
}
