/* ==========================================================================
   rational.business -- Styles
   Swiss Rationalism meets Mid-Century Academic Publishing
   ========================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
    /* Color Palette */
    --bg-primary: #FAFAF5;       /* Parchment White */
    --bg-secondary: #F0EDE4;     /* Warm Linen */
    --text-primary: #2B2D2F;     /* Graphite */
    --text-secondary: #5A6672;   /* Slate Gray */
    --accent-primary: #4A6FA5;   /* Rationalist Blue */
    --accent-secondary: #C4533A; /* Theorem Red */
    --accent-tertiary: #D4E4BC;  /* Decision Green */
    --structural: #B8C4D0;       /* Rule Gray */
    --bg-transition: #E8DFD0;    /* Warm transition for matrix */

    /* Typography Scale */
    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'Inter', 'Helvetica Neue', sans-serif;
    --font-mono: 'IBM Plex Mono', 'Menlo', monospace;

    /* Spacing */
    --grid-gutter: 24px;
    --section-spacing: 6rem;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
}

/* ---------- Bayesian Tree (Hero Background) ---------- */
#bayesian-tree {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0.4;
}

.tree-group {
    animation: treeRotate 30s linear infinite;
    transform-origin: 50% 50%;
}

@keyframes treeRotate {
    0%   { transform: rotate(0deg); }
    50%  { transform: rotate(0.5deg); }
    100% { transform: rotate(0deg); }
}

/* ---------- Diagonal Reading Lines ---------- */
.diagonal-lines-svg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

body:hover .diagonal-lines-svg {
    opacity: 1;
}

.reading-line {
    transform: rotate(7deg);
    transform-origin: center center;
}

/* ---------- Sections Common ---------- */
.section {
    position: relative;
    z-index: 1;
    padding: var(--section-spacing) var(--grid-gutter);
}

/* ---------- Section I: The Axiom (Hero) ---------- */
.section-hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background-color: var(--bg-primary);
}

.hero-content {
    position: relative;
    z-index: 2;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.8rem, 7vw, 6rem);
    letter-spacing: 0.01em;
    color: var(--text-primary);
    opacity: 0;
    animation: heroFadeIn 1.2s cubic-bezier(0.33, 1, 0.68, 1) 0.3s forwards;
}

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

.hero-axiom {
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-top: 2rem;
    min-height: 1.5em;
}

.axiom-label {
    color: var(--accent-primary);
    font-weight: 500;
}

.typewriter-text {
    border-right: none;
}

/* ---------- Inference Arrows ---------- */
.inference-arrow-container {
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem var(--grid-gutter);
}

.inference-arrow {
    width: 100%;
    height: 20px;
    display: block;
}

.arrow-shaft {
    stroke-dasharray: 760;
    stroke-dashoffset: 760;
    transition: stroke-dashoffset 800ms cubic-bezier(0.33, 1, 0.68, 1);
}

.arrow-head {
    opacity: 0;
    transition: opacity 300ms cubic-bezier(0.33, 1, 0.68, 1) 600ms;
}

.inference-arrow-container.animated .arrow-shaft {
    stroke-dashoffset: 0;
}

.inference-arrow-container.animated .arrow-head {
    opacity: 1;
}

/* ---------- Section Grid (Argument Corridor + Marginalia) ---------- */
.section-grid {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: calc(var(--grid-gutter) * 2);
    max-width: 1100px;
    margin: 0 auto;
}

.argument-corridor {
    max-width: 680px;
}

/* ---------- Marginalia Zone ---------- */
.marginalia-zone {
    padding-top: 3rem;
}

.marginal-annotation {
    border-left: 2px solid var(--accent-secondary);
    padding: 0.75rem 0 0.75rem 1rem;
    margin-bottom: 2.5rem;
}

.marginal-annotation p {
    font-family: var(--font-body);
    font-weight: 300;
    font-style: italic;
    font-size: clamp(0.8rem, 0.9vw, 0.9rem);
    line-height: 1.55;
    color: var(--text-secondary);
}

/* ---------- Section Numbers & Headings ---------- */
.section-number {
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.5rem, 2.5vw, 2.4rem);
    letter-spacing: 0.01em;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.section-heading-large {
    font-size: clamp(2rem, 4vw, 3.2rem);
}

.section-subheading {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 1.5vw, 1.4rem);
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ---------- Section Rule Lines ---------- */
.section-rule {
    width: 0;
    height: 1px;
    background-color: var(--structural);
    opacity: 0.3;
    margin-bottom: 2rem;
    transition: width 600ms cubic-bezier(0.33, 1, 0.68, 1);
}

.section-rule.animated {
    width: 100%;
}

/* ---------- Body Text ---------- */
.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    line-height: 1.75;
    color: var(--text-primary);
    margin-bottom: 1.75rem;
}

.body-text em {
    font-style: italic;
    font-weight: 500;
}

/* ---------- Truth Tables ---------- */
.truth-table-container {
    margin-bottom: 2.5rem;
}

.truth-table {
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    width: 100%;
    max-width: 180px;
}

.truth-table th,
.truth-table td {
    border: 1px solid var(--structural);
    padding: 6px 10px;
    text-align: center;
    color: var(--text-secondary);
}

.truth-table th {
    font-weight: 500;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
}

.truth-table .true-cell {
    background-color: var(--accent-tertiary);
    color: var(--text-primary);
    font-weight: 500;
}

/* ---------- Decision Matrix ---------- */
.decision-matrix-wrapper {
    margin: 2.5rem 0;
}

.matrix-label {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    text-align: center;
}

.matrix-label-top {
    margin-bottom: 0.5rem;
}

.matrix-with-label {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.matrix-label-side {
    writing-mode: vertical-lr;
    transform: rotate(180deg);
}

.decision-matrix {
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    letter-spacing: 0.04em;
    width: 100%;
    max-width: 420px;
}

.decision-matrix th,
.decision-matrix td {
    border: 1px solid var(--structural);
    padding: 12px 18px;
    text-align: center;
    transition: background-color 300ms cubic-bezier(0.33, 1, 0.68, 1);
}

.decision-matrix th {
    font-weight: 500;
    color: var(--accent-primary);
    background-color: var(--bg-secondary);
}

.decision-matrix td {
    color: var(--text-primary);
    cursor: default;
}

.decision-matrix td:hover {
    background-color: var(--bg-transition);
}

.decision-matrix .nash-equilibrium {
    background-color: var(--accent-tertiary);
    font-weight: 500;
}

.decision-matrix .nash-equilibrium:hover {
    background-color: var(--accent-tertiary);
}

.nash-pulse {
    animation: nashPulse 1.5s cubic-bezier(0.33, 1, 0.68, 1) forwards;
}

@keyframes nashPulse {
    0%   { box-shadow: 0 0 0 rgba(212, 228, 188, 0); }
    50%  { box-shadow: 0 0 20px rgba(212, 228, 188, 0.4); }
    100% { box-shadow: 0 0 0 rgba(212, 228, 188, 0); }
}

.matrix-caption {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.75rem;
    font-style: italic;
}

/* ---------- Theorem Statement (Pull-quote) ---------- */
.theorem-statement {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1.2rem, 1.8vw, 1.6rem);
    line-height: 1.6;
    color: var(--text-primary);
    padding: 2rem 0;
    margin: 2rem 0;
    border-top: 1px solid rgba(184, 196, 208, 0.3);
    border-bottom: 1px solid rgba(184, 196, 208, 0.3);
}

.theorem-statement p {
    margin: 0;
}

.theorem-statement em {
    font-weight: 600;
    color: var(--accent-secondary);
}

/* ---------- Network Graph ---------- */
.network-graph-container {
    margin-bottom: 2.5rem;
    display: flex;
    justify-content: center;
}

.network-graph {
    width: 160px;
    height: 160px;
}

.network-node {
    opacity: 0.7;
    transition: opacity 200ms ease, r 200ms ease;
}

.network-node.pulse {
    opacity: 1;
    r: 6;
}

/* ---------- Section V: Corollary ---------- */
.section-corollary {
    background-color: var(--bg-primary);
}

.corollary-content {
    max-width: 560px;
    margin: 0 auto;
}

.corollary-content .body-text {
    margin-bottom: 2rem;
}

/* ---------- Section VI: Q.E.D. ---------- */
.section-qed {
    text-align: center;
    padding-top: 4rem;
    padding-bottom: 0;
}

.qed-content {
    max-width: 800px;
    margin: 0 auto;
}

.qed-mark {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--accent-secondary);
    letter-spacing: 0.04em;
    margin-bottom: 2rem;
}

.qed-rule {
    width: 0;
    height: 1px;
    background-color: var(--structural);
    opacity: 0.3;
    margin: 0 auto 2rem;
    transition: width 600ms cubic-bezier(0.33, 1, 0.68, 1);
}

.qed-rule.animated {
    width: 100%;
}

.qed-domain {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.qed-space {
    height: 40vh;
}

/* ---------- Fade-in Animation ---------- */
[data-animate="fade"] {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 600ms cubic-bezier(0.33, 1, 0.68, 1),
                transform 600ms cubic-bezier(0.33, 1, 0.68, 1);
}

[data-animate="fade"].animated {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- Responsive: Tablet & Below ---------- */
@media (max-width: 900px) {
    .section-grid {
        grid-template-columns: 1fr;
        gap: var(--grid-gutter);
    }

    .marginalia-zone {
        padding-top: 0;
        padding-left: 1.5rem;
        border-left: 2px solid rgba(184, 196, 208, 0.2);
    }

    .marginal-annotation {
        border-left: none;
        padding-left: 0;
    }

    .truth-table-container {
        transform: none !important;
    }

    .argument-corridor {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    :root {
        --section-spacing: 4rem;
    }

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

    .marginalia-zone {
        padding-left: 1.5rem;
        border-left: 2px solid rgba(184, 196, 208, 0.2);
        margin-top: 1.5rem;
    }

    .inference-arrow-container {
        max-width: 80%;
    }

    .matrix-with-label {
        flex-direction: column;
    }

    .matrix-label-side {
        writing-mode: horizontal-tb;
        transform: none;
    }

    .decision-matrix th,
    .decision-matrix td {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .hero-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    #bayesian-tree {
        opacity: 0.2;
    }
}

@media (max-width: 480px) {
    .section {
        padding-left: 16px;
        padding-right: 16px;
    }

    .corollary-content {
        max-width: 100%;
    }

    .decision-matrix th,
    .decision-matrix td {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
}

/* ---------- Selection Styles ---------- */
::selection {
    background-color: rgba(74, 111, 165, 0.15);
    color: var(--text-primary);
}
