/* =====================================================================
   resar.one — Neomorphic Reasoning Engine
   Colors: #f0f0f3 (substrate), #d1d1d6 (depth), #ffffff (highlight),
           #2d2d3a (ink), #4a6fa5 (logic blue), #5a8a6a (affirm green),
           #b8863e (doubt amber)
   Fonts: Space Grotesk (headings), Inter (body), JetBrains Mono (notation)
===================================================================== */

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: #f0f0f3;
    color: #2d2d3a;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    line-height: 1.75;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Typography ───────────────────────────────────────────────────── */
h1, h2, h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    color: #2d2d3a;
    line-height: 1.2;
}

.module-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    margin-bottom: 0.75rem;
    color: #2d2d3a;
}

code, .notation-badge, .pill-label, .step-badge, .pill-item {
    font-family: 'JetBrains Mono', monospace;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
}

/* ── Header ───────────────────────────────────────────────────────── */
#site-header {
    background-color: #f0f0f3;
    padding: 1.5rem 2rem;
    box-shadow: 0 4px 12px #d1d1d6, 0 -2px 6px #ffffff;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-identity {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.site-name {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: #2d2d3a;
    letter-spacing: -0.02em;
}

.logic-dot {
    color: #4a6fa5;
}

.site-tagline {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 400;
    color: #2d2d3a;
    opacity: 0.65;
    max-width: 480px;
}

.header-notation {
    flex-shrink: 0;
}

.notation-badge {
    display: inline-block;
    font-size: 0.8rem;
    color: #5a8a6a;
    background: #f0f0f3;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    box-shadow: 4px 4px 8px #d1d1d6, -4px -4px 8px #ffffff;
    letter-spacing: 0.03em;
}

/* ── Main Layout ──────────────────────────────────────────────────── */
#proof-tree {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 2rem 6rem;
}

#connector-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}

.proof-layout {
    display: grid;
    grid-template-columns: 65fr 35fr;
    gap: 2.5rem;
    align-items: start;
    position: relative;
    z-index: 1;
}

/* ── Primary Column ───────────────────────────────────────────────── */
.primary-column {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ── Reasoning Modules ────────────────────────────────────────────── */
.reasoning-module {
    position: relative;
}

.module-inner {
    background: #f0f0f3;
    border-radius: 16px;
    padding: 1.75rem 1.75rem 1.5rem;
    box-shadow: 8px 8px 16px #d1d1d6, -8px -8px 16px #ffffff;
    transition: box-shadow 200ms ease;
    position: relative;
    overflow: visible;
}

.module-inner:hover {
    box-shadow: 12px 12px 20px #d1d1d6, -12px -12px 20px #ffffff;
}

/* Conclusion glow (applied by JS via IntersectionObserver) */
.reasoning-module.conclusion .module-inner.in-view {
    box-shadow: 0 0 20px rgba(74, 111, 165, 0.15),
                8px 8px 16px #d1d1d6, -8px -8px 16px #ffffff;
}

/* ── Step Badges ──────────────────────────────────────────────────── */
.step-badge {
    position: absolute;
    top: -0.85rem;
    left: 1.5rem;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    background: #f0f0f3;
    box-shadow: 4px 4px 8px #d1d1d6, -4px -4px 8px #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 500;
    color: #4a6fa5;
    letter-spacing: 0;
    animation: badgePulse 3s ease-in-out infinite;
    z-index: 2;
}

.step-badge.amber {
    color: #b8863e;
}

.step-badge.blue {
    color: #4a6fa5;
    font-size: 0.75rem;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1.0); }
    50% { transform: scale(1.05); }
}

/* Conclusion badge scales up when in view */
.reasoning-module.conclusion.in-view .step-badge {
    animation: conclusionBadge 400ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes conclusionBadge {
    from { transform: scale(1.0); }
    to { transform: scale(1.2); }
}

/* ── Module Content ───────────────────────────────────────────────── */
.module-content {
    padding-top: 0.5rem;
}

.module-body {
    font-size: 0.95rem;
    font-weight: 400;
    color: #2d2d3a;
    line-height: 1.75;
    margin-bottom: 1rem;
}

.module-body strong {
    font-weight: 600;
    color: #4a6fa5;
}

/* ── Derivation Toggle ────────────────────────────────────────────── */
.derivation-toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 0;
    user-select: none;
}

.toggle-text {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a6fa5;
    position: relative;
    letter-spacing: 0.02em;
}

.toggle-text::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 0;
    height: 1px;
    background: #4a6fa5;
    transition: width 300ms ease;
}

.derivation-toggle:hover .toggle-text::after,
.derivation-toggle.active .toggle-text::after {
    width: 100%;
}

.derivation-toggle.active .toggle-text::before {
    content: 'hide ';
}

.derivation-toggle.active .toggle-text {
    /* handled via JS text swap */
}

/* ── Derivation Body ──────────────────────────────────────────────── */
.derivation-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height 300ms ease;
    margin-top: 0;
}

.derivation-body.expanded {
    max-height: 300px;
    margin-top: 1rem;
}

.derivation-body[hidden] {
    display: block;
    visibility: visible;
}

.notation-block {
    background: #f0f0f3;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    box-shadow: inset 4px 4px 8px #d1d1d6, inset -4px -4px 8px #ffffff;
    font-size: 0.8rem;
    line-height: 1.8;
    color: #2d2d3a;
    white-space: pre;
    overflow-x: auto;
}

.notation-block code {
    font-size: 0.8rem;
    color: #2d2d3a;
    background: none;
    display: block;
}

/* ── Annotation Indicator ─────────────────────────────────────────── */
.annotation-indicator {
    margin-bottom: 0.75rem;
}

.annotation-ref {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #b8863e;
    opacity: 0.8;
    letter-spacing: 0.01em;
}

/* ── Conclusion Affirmation ───────────────────────────────────────── */
.conclusion-affirmation {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 0.5px solid #d1d1d6;
}

.affirmation-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #5a8a6a;
    font-weight: 500;
    background: #f0f0f3;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    box-shadow: 3px 3px 6px #d1d1d6, -3px -3px 6px #ffffff;
}

.affirmation-text {
    font-size: 0.78rem;
    color: #2d2d3a;
    opacity: 0.6;
    font-style: italic;
}

/* ── Annotation Sidebar ───────────────────────────────────────────── */
.annotation-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 5.5rem;
}

.annotation-card {
    background: #f0f0f3;
    border-radius: 12px;
    padding: 1rem 1.1rem 1rem 1.25rem;
    box-shadow: 6px 6px 12px #d1d1d6, -6px -6px 12px #ffffff;
    border-left: 3px solid #5a8a6a;
    position: relative;
}

.annotation-card.assumption-ann {
    border-left-color: #b8863e;
}

.ann-header {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    color: #2d2d3a;
    margin-bottom: 0.4rem;
    letter-spacing: 0.01em;
}

.ann-text {
    font-size: 0.8rem;
    line-height: 1.6;
    color: #2d2d3a;
    opacity: 0.8;
}

.ann-ref {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: #4a6fa5;
    margin-top: 0.5rem;
    opacity: 0.75;
}

/* Connector line from annotation to main content */
.annotation-card::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -2rem;
    width: 1.5rem;
    height: 0.5px;
    background: #d1d1d6;
    transform: translateY(-50%);
}

/* ── Navigation Pill ──────────────────────────────────────────────── */
.nav-pill {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 200;
}

.pill-trigger {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #f0f0f3;
    box-shadow: 6px 6px 12px #d1d1d6, -6px -6px 12px #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 200ms ease;
    position: relative;
    z-index: 201;
}

.pill-trigger:active {
    box-shadow: inset 4px 4px 8px #d1d1d6, inset -4px -4px 8px #ffffff;
}

.pill-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: #4a6fa5;
    letter-spacing: 0;
}

/* ── Pill Menu ────────────────────────────────────────────────────── */
.pill-menu {
    position: absolute;
    bottom: 56px;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease;
}

.pill-menu.open {
    pointer-events: auto;
    opacity: 1;
}

.pill-item {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f3;
    box-shadow: 4px 4px 8px #d1d1d6, -4px -4px 8px #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #4a6fa5;
    text-decoration: none;
    transform: translateY(20px) scale(0.8);
    opacity: 0;
    transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 300ms ease,
                box-shadow 150ms ease;
}

.pill-menu.open .pill-item {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.pill-menu.open .pill-item:nth-child(1) { transition-delay: 0ms; }
.pill-menu.open .pill-item:nth-child(2) { transition-delay: 50ms; }
.pill-menu.open .pill-item:nth-child(3) { transition-delay: 100ms; }
.pill-menu.open .pill-item:nth-child(4) { transition-delay: 150ms; }
.pill-menu.open .pill-item:nth-child(5) { transition-delay: 200ms; }
.pill-menu.open .pill-item:nth-child(6) { transition-delay: 250ms; }

.pill-item:hover {
    box-shadow: 6px 6px 10px #d1d1d6, -6px -6px 10px #ffffff;
}

.pill-item:active {
    box-shadow: inset 3px 3px 6px #d1d1d6, inset -3px -3px 6px #ffffff;
}

.pill-item.active-section {
    color: #ffffff;
    background: #4a6fa5;
    box-shadow: 4px 4px 8px rgba(74, 111, 165, 0.4), -2px -2px 6px #ffffff;
}

/* ── SVG Connectors ───────────────────────────────────────────────── */
.connector-path {
    fill: none;
    stroke: #4a6fa5;
    stroke-width: 1;
    stroke-dasharray: 4 8;
    opacity: 0.5;
    stroke-dashoffset: 0;
}

.connector-path.animating {
    animation: dashFlow 3s linear infinite;
}

@keyframes dashFlow {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -36; }
}

.connector-path.draw-in {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    opacity: 0;
    transition: opacity 300ms ease;
}

.connector-path.draw-in.visible {
    opacity: 0.5;
}

/* ── Module Type Accents ──────────────────────────────────────────── */
.reasoning-module.conclusion .module-inner {
    position: relative;
}

.reasoning-module.conclusion .module-inner::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    box-shadow: 0 0 0 1px rgba(74, 111, 165, 0.12);
    pointer-events: none;
}

/* ── Reduced Motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .step-badge {
        animation: none;
    }

    .connector-path.animating {
        animation: none;
    }

    .reasoning-module.conclusion.in-view .step-badge {
        animation: none;
        transform: scale(1.2);
    }

    .derivation-body {
        transition: none;
    }

    .pill-item {
        transition: none;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .proof-layout {
        grid-template-columns: 1fr;
    }

    .annotation-sidebar {
        position: static;
        gap: 1rem;
    }

    .annotation-card::before {
        display: none;
    }

    #proof-tree {
        padding: 2rem 1rem 5rem;
    }

    .header-inner {
        flex-wrap: wrap;
    }
}

@media (max-width: 560px) {
    #site-header {
        padding: 1rem 1rem;
    }

    .module-inner {
        padding: 1.5rem 1.25rem 1.25rem;
    }

    .notation-block {
        font-size: 0.72rem;
    }
}
