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

:root {
    --bg-primary: #0c0a1a;
    --bg-card: rgba(28,22,50,0.72);
    --grid: #2a2a4a;
    --text-primary: #e8e4f0;
    --text-secondary: #8a86a0;
    --magenta: #ff2d7b;
    --cyan: #2dd4ff;
    --violet: #7b2dff;
    --green: #2dff8a;
    --halo: rgba(255,45,123,0.15);
    --wonk: 1;
    --opsz: clamp(9, calc(9 + 135 * ((100vw - 320px) / 1120)), 144);
}

/* Design terms retained: IntersectionObserver threshold IntersectionObserver` `requestAnimationFrame` (Google. The badge border color indicates the theorem's "school". */

html,
body {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: "Literata", serif;
    font-size: clamp(1rem, 1.15vw, 1.2rem);
    font-weight: 350;
    line-height: 1.72;
    letter-spacing: 0.01em;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 18% 22%, rgba(123,45,255,0.25), transparent 26vw),
        radial-gradient(circle at 82% 72%, rgba(45,212,255,0.16), transparent 24vw),
        radial-gradient(circle at 50% 50%, rgba(255,45,123,0.09), transparent 36vw),
        var(--bg-primary);
}

.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 9999;
    background: rgba(42,42,74,0.45);
    box-shadow: 0 0 28px rgba(123,45,255,0.35);
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #ff2d7b, #7b2dff, #2dd4ff);
    box-shadow: 0 0 18px rgba(45,212,255,0.65);
}

.waypoint {
    position: absolute;
    top: 7px;
    width: 9px;
    height: 9px;
    border: 1px solid rgba(232,228,240,0.22);
    border-radius: 999px;
    background: #2a2a4a;
    opacity: 0.65;
    transform: translateX(-50%);
    cursor: pointer;
    transition: opacity 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.waypoint::after {
    content: attr(data-label);
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%) translateY(-3px);
    opacity: 0;
    white-space: nowrap;
    font-family: "Space Grotesk", "Inter", sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8a86a0;
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

.waypoint:hover,
.waypoint.is-active {
    opacity: 1;
    border-color: #2dd4ff;
    background: #ff2d7b;
    box-shadow: 0 0 16px rgba(255,45,123,0.7);
}

.waypoint:hover::after,
.waypoint.is-active::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.page-container {
    position: relative;
    z-index: 1;
}

.parallax-section {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 100vh;
    overflow: hidden;
    padding: clamp(32px, 6vw, 80px);
    isolation: isolate;
}

.layer {
    position: absolute;
    inset: -15vh -8vw;
    will-change: transform;
    pointer-events: none;
}

.layer-0 {
    z-index: 0;
    background-color: #0c0a1a;
    background-image:
        repeating-linear-gradient(0deg, rgba(42,42,74,0.3) 0 1px, transparent 1px 60px),
        repeating-linear-gradient(90deg, rgba(42,42,74,0.3) 0 1px, transparent 1px 7.4vw),
        radial-gradient(circle at 50% 50%, rgba(123,45,255,0.15), transparent 38%);
    background-size: auto, auto, 100% 100%;
}

.layer-0::after {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0.42;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%232a2a4a' stroke-width='1' opacity='.9'%3E%3Ccircle cx='60' cy='60' r='4'/%3E%3Cpath d='M60 50v20M50 60h20'/%3E%3Cpath d='M20 20l5 5-5 5-5-5zM100 20l6 10h-12zM20 100l6 10h-12zM100 100l5 5-5 5-5-5z'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 240px 240px;
    animation: sigilPulse 14s ease-in-out infinite;
}

.layer-1 {
    z-index: 1;
    opacity: 0.9;
    transform-origin: center;
}

.layer-3 {
    position: fixed;
    inset: 0;
    z-index: 20;
    background-image:
        repeating-linear-gradient(0deg, rgba(0,0,0,0.14) 0 1px, transparent 1px 3px),
        radial-gradient(circle at 30% 10%, rgba(255,255,255,0.035), transparent 22%);
    mix-blend-mode: screen;
    opacity: 0.48;
}

.sigil {
    position: absolute;
    display: block;
    width: 22px;
    height: 22px;
    opacity: 0.42;
    filter: drop-shadow(0 0 10px rgba(123,45,255,0.55));
    animation: sigilSpin 120s linear infinite, sigilFlicker 7s ease-in-out infinite;
}

.sigil-circle { border: 2px solid #7b2dff; border-radius: 50%; left: 15%; top: 24%; }
.sigil-cross { left: 74%; top: 19%; }
.sigil-cross::before,
.sigil-cross::after { content: ""; position: absolute; background: #2a2a4a; }
.sigil-cross::before { width: 100%; height: 2px; top: 10px; left: 0; }
.sigil-cross::after { width: 2px; height: 100%; top: 0; left: 10px; }
.sigil-diamond { left: 22%; top: 75%; border: 2px solid #2a2a4a; transform: rotate(45deg); }
.sigil-triangle { left: 82%; top: 68%; width: 0; height: 0; border-left: 13px solid transparent; border-right: 13px solid transparent; border-bottom: 23px solid rgba(42,42,74,0.8); }

.section-1 .sigil-circle,
.section-3 .sigil-diamond { left: 67%; top: 27%; }
.section-1 .sigil-cross,
.section-4 .sigil-cross { left: 18%; top: 62%; }
.section-2 .sigil-triangle { left: 12%; top: 18%; }
.section-2 .sigil-diamond { left: 78%; top: 73%; }
.section-5 .sigil-circle { left: 50%; top: 15%; }

.floating-fragment {
    position: absolute;
    z-index: 2;
    font-family: "JetBrains Mono", monospace;
    font-size: clamp(1rem, 2vw, 1.55rem);
    color: #7b2dff;
    opacity: 0.1;
    pointer-events: none;
    text-shadow: 0 0 20px rgba(123,45,255,0.55);
    animation: floatDrift 18s ease-in-out infinite;
}

.theorem-card {
    position: relative;
    z-index: 5;
    width: min(90vw, 560px);
    padding: clamp(30px, 4vw, 54px);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    backdrop-filter: blur(24px) saturate(1.4);
    background: rgba(28,22,50,0.72);
    box-shadow:
        inset 0 0 60px rgba(123,45,255,0.05),
        0 24px 80px rgba(0,0,0,0.38),
        0 0 45px rgba(255,45,123,0.08);
    opacity: 0;
    transform: translate3d(0, 26px, 0) scale(0.985);
    transition: opacity 800ms cubic-bezier(0.16, 1, 0.3, 1), transform 800ms cubic-bezier(0.16, 1, 0.3, 1);
}

.theorem-card.is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
}

.theorem-card-wide {
    width: min(92vw, 640px);
}

.section-0,
.section-2,
.section-4 { justify-content: flex-end; }
.section-1,
.section-3 { justify-content: flex-start; }
.section-5 { justify-content: center; }

@media (min-width: 1024px) {
    .section-0 .theorem-card,
    .section-2 .theorem-card,
    .section-4 .theorem-card { margin-right: 8.2vw; margin-top: -12vh; }
    .section-1 .theorem-card,
    .section-3 .theorem-card { margin-left: 8.2vw; margin-top: 10vh; }
    .section-5 .theorem-card { margin-top: -2vh; }
}

.card-top-border {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 2px;
    border-radius: 10px 0 0 0;
    box-shadow: 0 0 18px currentColor;
}

.theorem-card.is-visible .card-top-border { animation: borderDraw 200ms ease-out forwards; }
.section-0 .card-top-border,
.section-1 .card-top-border { background: #ff2d7b; color: #ff2d7b; }
.section-2 .card-top-border { background: #2dd4ff; color: #2dd4ff; }
.section-3 .card-top-border { background: #7b2dff; color: #7b2dff; }
.section-4 .card-top-border,
.section-5 .card-top-border { background: #2dff8a; color: #2dff8a; }

.classification-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 6px 16px;
    border: 1px solid #ff2d7b;
    border-radius: 999px;
    backdrop-filter: blur(8px);
    background: rgba(28,22,50,0.8);
    color: #ff2d7b;
    font-family: "Space Grotesk", "Inter", sans-serif;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    line-height: 1;
    text-transform: uppercase;
    opacity: 0;
    transform: scale(0.8);
}

.theorem-card.is-visible .classification-badge { animation: badgeFadeScale 150ms cubic-bezier(0.34, 1.56, 0.64, 1) 50ms forwards; }
.badge-invocation { border-color: #ff2d7b; color: #ff2d7b; }
.badge-divination { border-color: #2dd4ff; color: #2dd4ff; }
.badge-transmutation { border-color: #7b2dff; color: #7b2dff; }
.badge-verification { border-color: #2dff8a; color: #2dff8a; }

.card-kicker {
    margin: 0 90px 12px 0;
    color: #8a86a0;
    font-family: "Space Grotesk", "Inter", sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    line-height: 1.3;
    text-transform: uppercase;
    opacity: 0;
    transform: translateY(12px);
}

.theorem-card.is-visible .card-kicker { animation: textFadeUp 320ms cubic-bezier(0.16, 1, 0.3, 1) 120ms forwards; }

.theorem-title {
    margin: 0 0 20px;
    color: #ff2d7b;
    font-family: "Fraunces", serif;
    font-size: clamp(2.4rem, 5.5vw, 4.8rem);
    font-weight: 900;
    font-variation-settings: "opsz" var(--opsz), "WONK" var(--wonk);
    letter-spacing: -0.03em;
    line-height: 1.05;
    min-height: 1.05em;
    text-shadow: 0 0 28px rgba(255,45,123,0.22);
}

.section-2 .theorem-title { color: #2dd4ff; text-shadow: 0 0 28px rgba(45,212,255,0.2); }
.section-3 .theorem-title { color: #7b2dff; text-shadow: 0 0 28px rgba(123,45,255,0.22); }
.section-4 .theorem-title,
.section-5 .theorem-title { color: #2dff8a; text-shadow: 0 0 28px rgba(45,255,138,0.16); }

.theorem-text {
    margin-bottom: 24px;
    color: #e8e4f0;
    opacity: 0;
    transform: translateY(20px);
}

.theorem-card.is-visible .theorem-text { animation: textFadeUp 400ms cubic-bezier(0.16, 1, 0.3, 1) var(--text-delay, 760ms) forwards; }

.spell-notation {
    display: inline-block;
    max-width: 100%;
    overflow-wrap: anywhere;
    border: 1px solid rgba(45,212,255,0.16);
    border-radius: 3px;
    padding: 0.15em 0.4em;
    background: rgba(45,212,255,0.08);
    color: #2dd4ff;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    opacity: 0;
    transform: translateX(30px);
}

.theorem-card.is-visible .spell-notation { animation: spellSlideIn 300ms cubic-bezier(0.34, 1.56, 0.64, 1) var(--spell-delay, 980ms) forwards; }

@keyframes borderDraw { to { width: 100%; } }
@keyframes badgeFadeScale { to { opacity: 1; transform: scale(1); } }
@keyframes textFadeUp { to { opacity: 1; transform: translateY(0); } }
@keyframes spellSlideIn { to { opacity: 1; transform: translateX(0); } }
@keyframes sigilSpin { to { rotate: 360deg; } }
@keyframes sigilPulse { 0%, 100% { opacity: 0.22; } 50% { opacity: 0.7; } }
@keyframes sigilFlicker { 0%, 100% { opacity: 0.28; } 48% { opacity: 0.42; } 50% { opacity: 0.78; } 52% { opacity: 0.35; } }
@keyframes floatDrift { 0%, 100% { transform: translate3d(0,0,0); } 50% { transform: translate3d(28px,-42px,0); } }

@media (max-width: 760px) {
    :root { --wonk: 0; }
    .parallax-section { justify-content: center; padding: 24px; }
    .theorem-card { width: 100%; padding: 28px; }
    .classification-badge { top: 16px; right: 16px; padding: 5px 12px; font-size: 0.65rem; }
    .card-kicker { margin-right: 70px; }
    .waypoint::after { display: none; }
}

@media (max-width: 460px) {
    .theorem-card { padding: 24px 20px; }
    .theorem-title { font-size: clamp(2.1rem, 13vw, 3.35rem); }
    .spell-notation { font-size: 0.74rem; }
}
