/* ============================================================
   continu.ax v2 -- Cinematic Kinetic Typography
   A mathematical proof of continuity, rendered in CSS.
   ============================================================ */

/* --- Custom Properties --- */
:root {
    --deep-slate: #1B1F3B;
    --chalk-white: #F0EDE5;
    --theorem-gold: #C9A84C;
    --asymptote-rose: #D4506B;
    --graph-teal: #2E8B8B;
    --margin-gray: #6B6B7B;
    --grid-subtle: #2A2E4A;
    --grid-line: #3D3D5C;

    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Source Serif 4', serif;
    --font-mono: 'JetBrains Mono', monospace;

    --hero-size: clamp(36px, 6vw, 88px);
    --section-heading-size: clamp(28px, 4vw, 56px);
    --body-size: clamp(16px, 1.2vw, 20px);

    --timing-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --timing-ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --timing-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--deep-slate);
    color: var(--chalk-white);
    font-family: var(--font-body);
    font-size: var(--body-size);
    font-weight: 400;
    line-height: 1.65;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Continuous Gold Line (spans entire page) --- */
#continuous-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

#gold-line-path {
    stroke-dasharray: var(--gold-line-length, 0);
    stroke-dashoffset: var(--gold-line-offset, 0);
    transition: stroke-dashoffset 0.05s linear;
}

/* --- Floating Typographic Fragments --- */
#typo-fragments {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    overflow: hidden;
}

.typo-fragment {
    position: absolute;
    font-family: var(--font-display);
    font-weight: 300;
    opacity: 0;
    color: var(--chalk-white);
    pointer-events: none;
    will-change: transform;
}

@keyframes fragment-drift-1 {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.1; }
    90% { opacity: 0.08; }
    100% { transform: translate(200px, -300px) rotate(15deg); opacity: 0; }
}

@keyframes fragment-drift-2 {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.12; }
    90% { opacity: 0.06; }
    100% { transform: translate(-250px, -400px) rotate(-12deg); opacity: 0; }
}

@keyframes fragment-drift-3 {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.08; }
    90% { opacity: 0.1; }
    100% { transform: translate(150px, -350px) rotate(8deg); opacity: 0; }
}

/* ============================================================
   HERO SECTION
   ============================================================ */
.hero {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--deep-slate);
    overflow: hidden;
}

/* Coordinate Grid Background */
.hero-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.hero-grid.visible {
    opacity: 0.05;
}

.hero-grid line {
    stroke: var(--grid-line);
    stroke-width: 0.5;
}

/* Coordinate Axes */
.hero-axes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
}

#x-axis, #y-axis {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 0.7s var(--timing-ease-out);
}

#x-axis.drawn {
    stroke-dashoffset: 0;
}

#y-axis.drawn {
    stroke-dashoffset: 0;
}

/* Hero Title */
.hero-title {
    position: relative;
    z-index: 4;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--hero-size);
    letter-spacing: -0.03em;
    display: flex;
    align-items: center;
    gap: 0;
}

.hero-letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.4s var(--timing-spring), transform 0.5s var(--timing-spring);
}

.hero-letter.visible {
    opacity: 1;
    transform: translateY(var(--sine-offset, 0px));
}

.hero-letter[data-index="7"] {
    color: var(--theorem-gold);
}

/* Sine Wave Curve */
.hero-curve {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

#sine-path {
    stroke-dasharray: var(--sine-length, 1000);
    stroke-dashoffset: var(--sine-length, 1000);
    transition: stroke-dashoffset 1s var(--timing-ease-out);
    filter: drop-shadow(0 0 4px rgba(46, 139, 139, 0.2));
}

#sine-path.drawn {
    stroke-dashoffset: 0;
}

/* Epsilon-Delta Circles */
.epsilon-delta-group {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.epsilon-delta-group.visible {
    opacity: 1;
}

.ed-circles {
    position: absolute;
    width: 140px;
    height: 140px;
}

.ed-circles:first-child {
    top: 30%;
    right: 25%;
}

.ed-circles-2 {
    bottom: 25%;
    left: 20%;
    top: auto;
}

@keyframes epsilon-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.epsilon-circle, .delta-circle {
    animation: epsilon-pulse 2s ease-in-out infinite;
}

.delta-circle {
    animation-delay: 0.5s;
}

/* Scroll Indicator */
.scroll-indicator {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.scroll-indicator.visible {
    opacity: 0.6;
}

@keyframes bounce-parabola {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

.scroll-indicator.visible {
    animation: bounce-parabola 2s ease-in-out infinite;
}

/* ============================================================
   PROOF SECTIONS
   ============================================================ */
.proof-section {
    position: relative;
    min-height: 80vh;
    padding: 120px 0 80px;
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 15% 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 0 40px;
}

/* Timeline Spine */
.proof-section::before {
    content: '';
    position: absolute;
    left: 15%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(
        to bottom,
        transparent,
        var(--grid-line) 20%,
        var(--grid-line) 80%,
        transparent
    );
    opacity: 0.4;
}

/* Proof Marker (Lemma 1:, Theorem:, etc.) */
.proof-marker-container {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    display: flex;
    justify-content: flex-end;
    padding-right: 24px;
    padding-top: 8px;
}

.proof-marker {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: clamp(14px, 1.1vw, 18px);
    color: var(--theorem-gold);
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.proof-marker::after {
    content: '|';
    animation: cursor-blink 0.8s step-end infinite;
    color: var(--theorem-gold);
    opacity: 0;
}

.proof-marker.typing::after {
    opacity: 1;
}

.proof-marker.typed::after {
    display: none;
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Proof Content */
.proof-content {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
    max-width: 680px;
    padding: 0 24px;
}

.proof-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--section-heading-size);
    letter-spacing: -0.03em;
    color: var(--chalk-white);
    margin-bottom: 32px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s var(--timing-ease-out);
}

.proof-heading.visible {
    opacity: 1;
    transform: translateY(0);
}

.proof-content p {
    margin-bottom: 24px;
    color: rgba(240, 237, 229, 0.88);
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.5s ease, transform 0.5s var(--timing-ease-out);
}

.proof-content p.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Math Notation */
.math-notation {
    font-family: var(--font-mono);
    font-size: 0.92em;
    color: var(--graph-teal);
    padding: 0 2px;
    cursor: default;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.math-notation:hover {
    color: var(--asymptote-rose);
    text-shadow: 0 0 8px rgba(212, 80, 107, 0.3);
}

/* --- Diagonal Annotation Panels --- */
.diagonal-panel {
    position: relative;
    grid-column: 1 / -1;
    grid-row: 3 / 4;
    margin: 40px 0 0;
    padding: 28px 36px;
    background: rgba(212, 80, 107, 0.06);
    border-left: 2px solid var(--asymptote-rose);
    transform: rotate(-2deg) translateX(30px);
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s var(--timing-ease-out);
    max-width: 520px;
}

.diagonal-panel.visible {
    opacity: 1;
    transform: rotate(-2deg) translateX(0);
}

.diagonal-panel-right {
    margin-left: auto;
    margin-right: 60px;
    transform: rotate(2deg) translateX(-30px);
}

.diagonal-panel-right.visible {
    transform: rotate(2deg) translateX(0);
}

.diagonal-panel-left {
    margin-left: 18%;
    transform: rotate(-2deg) translateX(30px);
}

.diagonal-panel-left.visible {
    transform: rotate(-2deg) translateX(0);
}

.annotation-text {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(14px, 1vw, 16px);
    line-height: 1.6;
    color: var(--margin-gray);
}

.annotation-text em {
    color: var(--asymptote-rose);
    font-style: italic;
}

.annotation-text .math-notation {
    font-style: normal;
    color: var(--theorem-gold);
}

/* --- Curve Dividers --- */
.curve-divider {
    grid-column: 1 / -1;
    width: 100%;
    height: 80px;
    margin-top: 60px;
    overflow: visible;
}

.divider-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    filter: drop-shadow(0 0 4px rgba(46, 139, 139, 0.2));
    transition: stroke-dashoffset 1.2s var(--timing-ease-out);
}

.divider-path.drawn {
    stroke-dashoffset: 0;
}

/* ============================================================
   LIMIT SECTION
   ============================================================ */
.limit-section {
    position: relative;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--deep-slate);
    overflow: hidden;
    padding: 60px 24px;
}

.limit-container {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 1000px;
    width: 100%;
    gap: var(--limit-gap, 200px);
}

.limit-text {
    flex: 1;
    max-width: 380px;
}

.limit-text p {
    font-family: var(--font-body);
    font-size: var(--body-size);
    line-height: 1.65;
    color: rgba(240, 237, 229, 0.85);
}

.limit-text-left {
    text-align: right;
}

.limit-text-right {
    text-align: left;
}

.limit-gap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    flex-shrink: 0;
}

.limit-symbol {
    font-family: var(--font-mono);
    font-size: clamp(24px, 3vw, 48px);
    color: var(--theorem-gold);
    opacity: 0.8;
}

.limit-formula {
    margin-top: 48px;
    text-align: center;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s var(--timing-ease-out);
}

.limit-formula.visible {
    opacity: 1;
    transform: translateY(0);
}

.limit-formula .math-notation {
    font-size: clamp(20px, 2.5vw, 36px);
    color: var(--chalk-white);
}

/* Limit Epsilon-Delta Circles */
.limit-ed-circles {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
}

.limit-ed-circles.visible {
    opacity: 0.4;
}

.ed-circles-limit {
    width: 300px;
    height: 300px;
}

/* ============================================================
   QED FOOTER
   ============================================================ */
.qed-footer {
    position: relative;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--deep-slate);
    padding: 80px 24px;
}

.qed-symbol {
    font-size: clamp(48px, 8vw, 120px);
    color: var(--chalk-white);
    line-height: 1;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 1s ease, transform 1s var(--timing-spring);
}

.qed-symbol.visible {
    opacity: 1;
    transform: scale(1);
}

.qed-nav {
    margin-top: 60px;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.8s ease 0.4s;
}

.qed-nav.visible {
    opacity: 1;
}

.qed-nav-item {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--margin-gray);
    letter-spacing: 0.05em;
    text-transform: lowercase;
}

.qed-nav-separator {
    color: var(--grid-line);
    font-size: 14px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .proof-section {
        grid-template-columns: 1fr;
        padding: 80px 24px 60px;
        gap: 0;
    }

    .proof-section::before {
        left: 24px;
    }

    .proof-marker-container {
        justify-content: flex-start;
        padding-right: 0;
        padding-left: 0;
        margin-bottom: 16px;
    }

    .proof-content {
        padding: 0;
    }

    .diagonal-panel {
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100%;
    }

    .limit-container {
        flex-direction: column;
        gap: 24px;
    }

    .limit-text-left,
    .limit-text-right {
        text-align: center;
    }

    .limit-gap {
        min-width: auto;
    }

    .ed-circles:first-child {
        right: 10%;
    }

    .ed-circles-2 {
        left: 10%;
    }
}

/* ============================================================
   COORDINATE GRID PATTERN (generated in JS, styled here)
   ============================================================ */
.grid-line-major {
    stroke: var(--grid-line);
    stroke-width: 0.5;
    stroke-opacity: 0.3;
}

.grid-line-minor {
    stroke: var(--grid-subtle);
    stroke-width: 0.25;
    stroke-opacity: 0.15;
}

/* ============================================================
   SCROLL-DRIVEN UTILITY CLASSES
   ============================================================ */
.fade-in-up {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s var(--timing-ease-out);
}

.fade-in-up.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Subtle background noise texture via CSS */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.015;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
}

/* Selection color */
::selection {
    background: var(--asymptote-rose);
    color: var(--chalk-white);
}
