/* ==========================================================================
   bability.pro - Glassmorphism on Paper
   Colors: #F5E6C8, #D4C4A0, #FF2D78, #39FF14, #00F0FF, #BF00FF, #1C1C1E, #FFF8E7
   Fonts: Caveat, Nunito, Kalam, IBM Plex Mono
   IBM Plex Mono" (Google Fonts) used for technical callouts
   IntersectionObserver trigger. When the element enters the viewport
   ========================================================================== */

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

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

body {
    background-color: #F5E6C8;
    color: #1C1C1E;
    font-family: 'Nunito', sans-serif;
    font-weight: 400;
    line-height: 1.7;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* --- Paper Background Texture --- */
.paper-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    background:
        /* Paper grain noise via repeating gradients */
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(212, 196, 160, 0.05) 2px,
            rgba(212, 196, 160, 0.05) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 3px,
            rgba(212, 196, 160, 0.04) 3px,
            rgba(212, 196, 160, 0.04) 6px
        ),
        /* Fiber texture simulation */
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 8px,
            rgba(212, 196, 160, 0.03) 8px,
            rgba(212, 196, 160, 0.03) 9px
        ),
        repeating-linear-gradient(
            -30deg,
            transparent,
            transparent 12px,
            rgba(212, 196, 160, 0.02) 12px,
            rgba(212, 196, 160, 0.02) 13px
        );
    background-color: #F5E6C8;
}

/* Paper grain animation on scroll */
.paper-bg::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        repeating-linear-gradient(
            60deg,
            transparent,
            transparent 5px,
            rgba(212, 196, 160, 0.02) 5px,
            rgba(212, 196, 160, 0.02) 6px
        );
    animation: paperGrainShift 30s linear infinite;
}

@keyframes paperGrainShift {
    0% { transform: translate(0, 0); }
    100% { transform: translate(20px, 20px); }
}

/* Foxing marks (age spots) */
.paper-bg::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse 80px 60px at 15% 25%, rgba(180, 150, 100, 0.06) 0%, transparent 70%),
        radial-gradient(ellipse 60px 90px at 78% 45%, rgba(180, 150, 100, 0.05) 0%, transparent 70%),
        radial-gradient(ellipse 100px 70px at 45% 70%, rgba(180, 150, 100, 0.04) 0%, transparent 70%),
        radial-gradient(ellipse 50px 50px at 85% 85%, rgba(180, 150, 100, 0.05) 0%, transparent 70%);
}

/* Coffee rings */
.coffee-ring {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
}

.coffee-ring-1 {
    width: 120px;
    height: 120px;
    top: 12%;
    left: 8%;
    background: radial-gradient(
        circle,
        transparent 42%,
        rgba(160, 120, 70, 0.04) 44%,
        rgba(160, 120, 70, 0.06) 48%,
        rgba(160, 120, 70, 0.03) 52%,
        transparent 54%
    );
}

.coffee-ring-2 {
    width: 90px;
    height: 90px;
    top: 55%;
    right: 12%;
    background: radial-gradient(
        circle,
        transparent 40%,
        rgba(160, 120, 70, 0.05) 43%,
        rgba(160, 120, 70, 0.07) 47%,
        rgba(160, 120, 70, 0.04) 51%,
        transparent 53%
    );
}

.coffee-ring-3 {
    width: 100px;
    height: 100px;
    top: 80%;
    left: 20%;
    background: radial-gradient(
        circle,
        transparent 38%,
        rgba(160, 120, 70, 0.03) 41%,
        rgba(160, 120, 70, 0.05) 46%,
        rgba(160, 120, 70, 0.02) 50%,
        transparent 52%
    );
}

/* Fold lines */
.fold-line {
    position: fixed;
    pointer-events: none;
}

.fold-line-1 {
    width: 140%;
    height: 1px;
    top: 35%;
    left: -20%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(180, 150, 100, 0.08) 20%,
        rgba(180, 150, 100, 0.12) 50%,
        rgba(180, 150, 100, 0.08) 80%,
        transparent 100%
    );
    transform: rotate(-8deg);
}

.fold-line-2 {
    width: 120%;
    height: 1px;
    top: 68%;
    left: -10%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(180, 150, 100, 0.06) 30%,
        rgba(180, 150, 100, 0.10) 55%,
        rgba(180, 150, 100, 0.06) 75%,
        transparent 100%
    );
    transform: rotate(5deg);
}

/* --- Floating Particles --- */
.particles-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0.15;
    animation: particleFloat linear infinite;
}

.particle-1 {
    width: 3px;
    height: 3px;
    background: #FF2D78;
    top: 20%;
    left: 30%;
    animation-duration: 12s;
    animation-delay: 0s;
}

.particle-2 {
    width: 2px;
    height: 2px;
    background: #39FF14;
    top: 40%;
    left: 60%;
    animation-duration: 15s;
    animation-delay: -3s;
}

.particle-3 {
    width: 3px;
    height: 3px;
    background: #00F0FF;
    top: 60%;
    left: 45%;
    animation-duration: 18s;
    animation-delay: -6s;
}

.particle-4 {
    width: 2px;
    height: 2px;
    background: #BF00FF;
    top: 15%;
    left: 70%;
    animation-duration: 14s;
    animation-delay: -2s;
}

.particle-5 {
    width: 3px;
    height: 3px;
    background: #FF2D78;
    top: 75%;
    left: 25%;
    animation-duration: 16s;
    animation-delay: -8s;
}

.particle-6 {
    width: 2px;
    height: 2px;
    background: #00F0FF;
    top: 50%;
    left: 80%;
    animation-duration: 13s;
    animation-delay: -4s;
}

.particle-7 {
    width: 3px;
    height: 3px;
    background: #39FF14;
    top: 85%;
    left: 55%;
    animation-duration: 17s;
    animation-delay: -10s;
}

.particle-8 {
    width: 2px;
    height: 2px;
    background: #BF00FF;
    top: 35%;
    left: 15%;
    animation-duration: 11s;
    animation-delay: -1s;
}

@keyframes particleFloat {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 0;
    }
    10% {
        opacity: 0.15;
    }
    50% {
        transform: translate(40px, -80px) scale(1.3);
        opacity: 0.2;
    }
    90% {
        opacity: 0.15;
    }
    100% {
        transform: translate(-20px, -160px) scale(0.8);
        opacity: 0;
    }
}

/* --- Narrative Column --- */
.narrative-column {
    position: relative;
    z-index: 2;
    max-width: 680px;
    margin: 0 auto;
    padding: 80px 24px 160px;
}

/* --- Title Section --- */
.title-section {
    text-align: center;
    padding: 120px 0 80px;
    position: relative;
}

.site-title {
    font-family: 'Caveat', cursive;
    font-size: 72px;
    font-weight: 700;
    color: #1C1C1E;
    text-shadow: 0 0 2px rgba(28, 28, 30, 0.1);
    line-height: 1.1;
    margin-bottom: 16px;
    position: relative;
    display: inline-block;
}

.site-title .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
}

.site-subtitle {
    font-size: 20px;
    color: #1C1C1E;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.8s ease 1.2s, transform 0.8s ease 1.2s;
}

.site-subtitle.visible {
    opacity: 0.7;
    transform: translateY(0);
}

.ink-droplet {
    position: absolute;
    bottom: 60px;
    right: calc(50% - 80px);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.ink-droplet.visible path {
    opacity: 0.6;
    animation: inkDrip 0.8s ease-out forwards;
}

@keyframes inkDrip {
    0% {
        opacity: 0;
        d: path("M10 0 C10 0 8 5 8 8 C8 11 9 12 10 12 C11 12 12 11 12 8 C12 5 10 0 10 0Z");
    }
    50% {
        opacity: 0.6;
    }
    100% {
        opacity: 0.3;
        d: path("M10 0 C10 0 0 15 0 20 C0 25.5 4.5 30 10 30 C15.5 30 20 25.5 20 20 C20 15 10 0 10 0Z");
    }
}

/* --- Glass Panels --- */
.glass-panel {
    position: relative;
    background: rgba(255, 255, 255, 0.20);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255, 45, 120, 0.3);
    border-radius: 16px;
    padding: 48px 40px;
    margin-bottom: 120px;
    transform-style: preserve-3d;
    transform: perspective(1200px) rotateX(var(--tiltX, 0deg)) rotateY(var(--tiltY, 0deg));
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.6s ease;
    box-shadow:
        0 0 20px rgba(255, 45, 120, 0.15),
        0 8px 32px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    animation: glowPulse 8s ease-in-out infinite;
}

.glass-panel.panel-left {
    transform: perspective(1200px) rotateX(var(--tiltX, 0deg)) rotateY(var(--tiltY, 1.5deg)) translateX(-24px);
}

.glass-panel.panel-right {
    transform: perspective(1200px) rotateX(var(--tiltX, 0deg)) rotateY(var(--tiltY, -1.5deg)) translateX(24px);
}

/* Neon glow pulse cycling through accent colors */
@keyframes glowPulse {
    0%, 100% {
        box-shadow:
            0 0 15px rgba(255, 45, 120, 0.2),
            0 8px 32px rgba(0, 0, 0, 0.08);
        border-color: rgba(255, 45, 120, 0.4);
    }
    25% {
        box-shadow:
            0 0 25px rgba(57, 255, 20, 0.2),
            0 8px 32px rgba(0, 0, 0, 0.08);
        border-color: rgba(57, 255, 20, 0.4);
    }
    50% {
        box-shadow:
            0 0 15px rgba(0, 240, 255, 0.2),
            0 8px 32px rgba(0, 0, 0, 0.08);
        border-color: rgba(0, 240, 255, 0.4);
    }
    75% {
        box-shadow:
            0 0 25px rgba(191, 0, 255, 0.2),
            0 8px 32px rgba(0, 0, 0, 0.08);
        border-color: rgba(191, 0, 255, 0.4);
    }
}

/* Circuit trace patterns on panel edges */
.panel-circuit {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.08;
    background:
        linear-gradient(0deg, #00F0FF 1px, transparent 1px) 0 0 / 100% 40px,
        linear-gradient(90deg, #00F0FF 1px, transparent 1px) 0 0 / 40px 100%;
    mask-image: linear-gradient(
        135deg,
        transparent 0%,
        transparent 85%,
        rgba(0,0,0,0.5) 90%,
        rgba(0,0,0,1) 95%,
        rgba(0,0,0,1) 100%
    );
    -webkit-mask-image: linear-gradient(
        135deg,
        transparent 0%,
        transparent 85%,
        rgba(0,0,0,0.5) 90%,
        rgba(0,0,0,1) 95%,
        rgba(0,0,0,1) 100%
    );
    border-radius: 16px;
}

/* Holographic refraction overlay */
.panel-holographic {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.03;
    background: conic-gradient(
        from 0deg at 50% 50%,
        #FF2D78,
        #39FF14,
        #00F0FF,
        #BF00FF,
        #FF2D78
    );
    border-radius: 16px;
    mix-blend-mode: screen;
}

/* Motes inside panels */
.panel-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    border-radius: 16px;
}

.mote {
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    opacity: 0;
}

.mote-1 {
    background: #FF2D78;
    top: 30%;
    left: 20%;
    animation: moteFloat 6s ease-in-out infinite;
}

.mote-2 {
    background: #00F0FF;
    top: 60%;
    left: 70%;
    animation: moteFloat 8s ease-in-out infinite 2s;
}

.mote-3 {
    background: #39FF14;
    top: 45%;
    left: 50%;
    animation: moteFloat 7s ease-in-out infinite 4s;
}

@keyframes moteFloat {
    0%, 100% {
        transform: translate(0, 0);
        opacity: 0;
    }
    25% {
        opacity: 0.15;
    }
    50% {
        transform: translate(15px, -20px);
        opacity: 0.2;
    }
    75% {
        opacity: 0.15;
    }
}

/* --- Typography --- */
.section-title {
    font-family: 'Caveat', cursive;
    font-size: 48px;
    font-weight: 700;
    color: #1C1C1E;
    margin-bottom: 24px;
    line-height: 1.2;
    text-shadow: 0 0 2px rgba(28, 28, 30, 0.1);
}

.glass-panel p {
    margin-bottom: 18px;
    text-shadow: 0 0 2px rgba(28, 28, 30, 0.05);
}

.glass-panel p:last-child {
    margin-bottom: 0;
}

.glass-panel em {
    font-style: italic;
}

.glass-panel strong {
    font-weight: 700;
}

.kalam-text {
    font-family: 'Kalam', cursive;
}

.margin-note {
    font-size: 15px;
    color: #1C1C1E;
    opacity: 0.6;
    margin-top: 24px;
    padding-left: 16px;
    border-left: 2px solid rgba(191, 0, 255, 0.3);
}

.closing-note {
    text-align: center;
    border-left: none;
    padding-left: 0;
    font-size: 16px;
    margin-top: 32px;
}

/* --- Highlight Text Effect --- */
.highlight-text {
    position: relative;
    display: inline;
    background: linear-gradient(
        to right,
        rgba(255, 240, 0, 0.40) 0%,
        rgba(255, 240, 0, 0.40) 100%
    );
    background-size: 0% 100%;
    background-repeat: no-repeat;
    background-position: left center;
    transition: background-size 0.8s ease;
    padding: 2px 0;
}

.highlight-text.highlighted {
    background-size: 100% 100%;
}

/* --- Code Blocks --- */
.code-block {
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 20px 24px;
    margin: 20px 0;
    border: 1px solid rgba(0, 240, 255, 0.2);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.1);
}

.code-block code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14px;
    font-weight: 400;
    color: #FFF8E7;
    display: block;
    line-height: 1.8;
    letter-spacing: 0;
}

/* --- Margin Doodles --- */
.margin-doodle {
    position: relative;
    height: 0;
    z-index: 3;
    pointer-events: none;
}

.doodle-right {
    text-align: right;
    transform: translateX(calc(50% + 360px));
}

.doodle-left {
    text-align: left;
    transform: translateX(calc(-50% - 20px));
}

.doodle-svg {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.doodle-svg.revealed {
    opacity: 1;
}

.doodle-svg.revealed * {
    animation: drawStroke 1.2s ease-out forwards;
}

@keyframes drawStroke {
    to {
        stroke-dashoffset: 0;
    }
}

/* Staggered delays for individual SVG elements */
.doodle-svg.revealed *:nth-child(1) { animation-delay: 0ms; }
.doodle-svg.revealed *:nth-child(2) { animation-delay: 100ms; }
.doodle-svg.revealed *:nth-child(3) { animation-delay: 180ms; }
.doodle-svg.revealed *:nth-child(4) { animation-delay: 250ms; }
.doodle-svg.revealed *:nth-child(5) { animation-delay: 320ms; }
.doodle-svg.revealed *:nth-child(6) { animation-delay: 380ms; }
.doodle-svg.revealed *:nth-child(7) { animation-delay: 400ms; }

/* --- Navigation Pill --- */
.nav-pill {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255, 45, 120, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
    box-shadow: 0 0 15px rgba(255, 45, 120, 0.2);
}

.nav-pill:hover {
    transform: scale(1.1);
    box-shadow: 0 0 25px rgba(255, 45, 120, 0.35);
}

.nav-pill.active {
    background: rgba(255, 45, 120, 0.3);
    transform: scale(1.1) rotate(45deg);
}

.nav-pill-icon {
    font-size: 24px;
    color: #1C1C1E;
    font-weight: 700;
    user-select: none;
    transition: transform 0.3s ease;
}

/* --- Radial Navigation --- */
.radial-nav {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    z-index: 99;
    pointer-events: none;
}

.radial-link {
    position: absolute;
    bottom: 28px;
    right: 28px;
    font-size: 15px;
    color: #1C1C1E;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 45, 120, 0.25);
    white-space: nowrap;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.radial-nav.open .radial-link {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.radial-link:hover {
    background: rgba(255, 45, 120, 0.15);
}

/* Radial positions - spread upward in an arc */
.radial-nav.open .radial-link[data-angle="0"] {
    transform: translate(-70px, -80px) scale(1);
    transition-delay: 0.03s;
}

.radial-nav.open .radial-link[data-angle="1"] {
    transform: translate(-120px, -140px) scale(1);
    transition-delay: 0.06s;
}

.radial-nav.open .radial-link[data-angle="2"] {
    transform: translate(-160px, -200px) scale(1);
    transition-delay: 0.09s;
}

.radial-nav.open .radial-link[data-angle="3"] {
    transform: translate(-140px, -260px) scale(1);
    transition-delay: 0.12s;
}

.radial-nav.open .radial-link[data-angle="4"] {
    transform: translate(-90px, -320px) scale(1);
    transition-delay: 0.15s;
}

.radial-nav.open .radial-link[data-angle="5"] {
    transform: translate(-30px, -370px) scale(1);
    transition-delay: 0.18s;
}

.radial-nav.open .radial-link[data-angle="6"] {
    transform: translate(20px, -410px) scale(1);
    transition-delay: 0.21s;
}

/* --- Page Turn Overlay --- */
.page-turn-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 90;
    pointer-events: none;
    background: #F5E6C8;
    clip-path: polygon(100% 0, 100% 0, 100% 100%, 100% 100%);
    transition: clip-path 0.6s cubic-bezier(0.77, 0, 0.175, 1);
}

.page-turn-overlay.turning {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

.page-turn-overlay.turning-out {
    clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    .narrative-column {
        padding: 60px 20px 120px;
    }

    .title-section {
        padding: 80px 0 60px;
    }

    .site-title {
        font-size: 48px;
    }

    .section-title {
        font-size: 36px;
    }

    .glass-panel {
        padding: 32px 24px;
        margin-bottom: 80px;
    }

    .glass-panel.panel-left,
    .glass-panel.panel-right {
        transform: perspective(1200px) rotateX(var(--tiltX, 0deg)) rotateY(var(--tiltY, 0deg)) translateX(0);
    }

    .margin-doodle {
        display: none;
    }

    .nav-pill {
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
    }

    .radial-nav {
        bottom: 20px;
        right: 20px;
    }

    .radial-nav.open .radial-link[data-angle="0"] { transform: translate(-60px, -70px) scale(0.9); }
    .radial-nav.open .radial-link[data-angle="1"] { transform: translate(-100px, -120px) scale(0.9); }
    .radial-nav.open .radial-link[data-angle="2"] { transform: translate(-130px, -170px) scale(0.9); }
    .radial-nav.open .radial-link[data-angle="3"] { transform: translate(-120px, -220px) scale(0.9); }
    .radial-nav.open .radial-link[data-angle="4"] { transform: translate(-80px, -270px) scale(0.9); }
    .radial-nav.open .radial-link[data-angle="5"] { transform: translate(-30px, -310px) scale(0.9); }
    .radial-nav.open .radial-link[data-angle="6"] { transform: translate(10px, -350px) scale(0.9); }
}

@media (max-width: 480px) {
    .site-title {
        font-size: 40px;
    }

    .section-title {
        font-size: 30px;
    }

    .glass-panel {
        padding: 24px 20px;
        margin-bottom: 60px;
    }

    .code-block {
        padding: 16px 16px;
    }

    .code-block code {
        font-size: 12px;
    }
}

/* --- Utility --- */
::selection {
    background: rgba(255, 240, 0, 0.40);
    color: #1C1C1E;
}
