/* ============================================
   kakuritsu.com - Probability Design Language
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --deep-indigo: #1B1040;
    --deep-indigo-warm: #231752;
    --probability-rose: #D4507A;
    --chalk-white: #F0EDE6;
    --warm-graphite: #3D3548;
    --rice-paper: #F5F0E8;
    --faded-chalk: #5A5670;
    --theorem-gold: #C9A84C;
    --stochastic-teal: #2E8B8B;
    --parchment: #D8D0C4;
    --watermark-color: #1E1345;
    --content-width: min(680px, 85vw);
}

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

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

body {
    background-color: var(--deep-indigo);
    color: var(--chalk-white);
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.05vw, 1.15rem);
    line-height: 1.9;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* --- Scroll Progress Indicator --- */
.scroll-progress {
    position: fixed;
    top: 0;
    right: 0;
    width: 3px;
    height: 100vh;
    z-index: 1000;
    background: transparent;
}

.scroll-progress-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, var(--deep-indigo), var(--probability-rose));
    transition: height 0.1s ease-out;
    clip-path: polygon(
        0% 100%,
        100% 100%,
        100% 95%,
        60% 90%,
        40% 85%,
        30% 80%,
        20% 75%,
        15% 70%,
        10% 65%,
        5% 60%,
        2% 55%,
        0% 50%,
        2% 45%,
        5% 40%,
        10% 35%,
        15% 30%,
        20% 25%,
        30% 20%,
        40% 15%,
        60% 10%,
        100% 5%,
        100% 0%,
        0% 0%
    );
}

/* --- Hero Section --- */
.hero-section {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 30% 70%, var(--deep-indigo-warm), var(--deep-indigo));
    overflow: hidden;
}

.dice-constellation {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    opacity: 0;
    transform: rotate(7deg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Crect x='4' y='4' width='8' height='8' rx='1' fill='%23F0EDE6' fill-opacity='0.05' stroke='%23F0EDE6' stroke-opacity='0.03' stroke-width='0.5'/%3E%3Ccircle cx='8' cy='8' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Crect x='28' y='18' width='8' height='8' rx='1' fill='%23F0EDE6' fill-opacity='0.04' stroke='%23F0EDE6' stroke-opacity='0.03' stroke-width='0.5'/%3E%3Ccircle cx='30' cy='20' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='34' cy='24' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Crect x='55' y='5' width='8' height='8' rx='1' fill='%23F0EDE6' fill-opacity='0.05' stroke='%23F0EDE6' stroke-opacity='0.03' stroke-width='0.5'/%3E%3Ccircle cx='57' cy='7' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Ccircle cx='61' cy='7' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Ccircle cx='59' cy='11' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Crect x='12' y='50' width='8' height='8' rx='1' fill='%23F0EDE6' fill-opacity='0.04' stroke='%23F0EDE6' stroke-opacity='0.03' stroke-width='0.5'/%3E%3Ccircle cx='14' cy='52' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='18' cy='52' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='14' cy='56' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='18' cy='56' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Crect x='48' y='42' width='8' height='8' rx='1' fill='%23F0EDE6' fill-opacity='0.05' stroke='%23F0EDE6' stroke-opacity='0.03' stroke-width='0.5'/%3E%3Ccircle cx='52' cy='46' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Ccircle cx='50' cy='44' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Ccircle cx='54' cy='44' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Ccircle cx='50' cy='48' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Ccircle cx='54' cy='48' r='1' fill='%23F0EDE6' fill-opacity='0.05'/%3E%3Crect x='65' y='60' width='8' height='8' rx='1' fill='%23F0EDE6' fill-opacity='0.04' stroke='%23F0EDE6' stroke-opacity='0.03' stroke-width='0.5'/%3E%3Ccircle cx='67' cy='62' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='71' cy='62' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='69' cy='64' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='67' cy='66' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3Ccircle cx='71' cy='66' r='1' fill='%23F0EDE6' fill-opacity='0.04'/%3E%3C/svg%3E");
    background-repeat: repeat;
    transition: opacity 1.2s ease;
}

.dice-constellation.visible {
    opacity: 1;
}

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

.hero-title {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--chalk-white);
    letter-spacing: 0.3em;
    opacity: 0;
    font-feature-settings: 'liga' 1, 'onum' 1;
    transition: opacity 0.8s ease, letter-spacing 0.8s ease;
}

.hero-title.visible {
    opacity: 1;
    letter-spacing: -0.02em;
}

.hero-kanji {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-style: italic;
    font-size: 2rem;
    color: var(--theorem-gold);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.6s ease, transform 0.6s ease;
    margin-top: 0.5rem;
}

.hero-kanji.visible {
    opacity: 1;
    transform: translateY(0);
}

.hero-subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--faded-chalk);
    margin-top: 1.5rem;
    opacity: 0;
    transition: opacity 0.5s ease;
    min-height: 1.5em;
}

.hero-subtitle.visible {
    opacity: 1;
}

/* --- Mathematical Watermarks --- */
.math-watermark {
    position: absolute;
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    color: var(--watermark-color);
    pointer-events: none;
    user-select: none;
    z-index: 0;
}

.dark-section .math-watermark {
    color: var(--watermark-color);
}

.light-section .math-watermark {
    color: #EDE8DF;
}

.watermark-sigma {
    font-size: 40vh;
    top: 10%;
    right: 5%;
    line-height: 1;
}

.watermark-integral {
    font-size: 50vh;
    top: -5%;
    left: 2%;
    line-height: 1;
}

.watermark-P {
    font-size: 45vh;
    top: 5%;
    right: 8%;
    line-height: 1;
}

/* --- Breathing Canvas Sections --- */
.breathing-canvas {
    position: relative;
    width: 100%;
    min-height: 60vh;
    background: radial-gradient(ellipse at 30% 70%, var(--deep-indigo-warm), var(--deep-indigo));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.breathing-canvas canvas {
    width: 100%;
    height: 60vh;
    display: block;
}

/* --- Theorem Sections --- */
.theorem-section {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 8vh 0;
    overflow: hidden;
}

.dark-section {
    background: radial-gradient(ellipse at 30% 70%, var(--deep-indigo-warm), var(--deep-indigo));
    color: var(--chalk-white);
}

.light-section {
    background-color: var(--rice-paper);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    color: var(--warm-graphite);
}

.light-section .theorem-heading {
    color: var(--deep-indigo);
}

.light-section .formula {
    color: var(--probability-rose);
}

.light-section .circled-numeral {
    color: var(--theorem-gold);
}

/* --- Section Numbers --- */
.section-number {
    position: absolute;
    top: 4vh;
    left: calc(50% - var(--content-width) / 2 - 3rem);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s ease, transform 0.3s ease;
}

.section-number.visible {
    opacity: 1;
    transform: scale(1);
}

.circled-numeral {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.5rem, 2vw, 2.5rem);
    color: var(--theorem-gold);
}

/* --- Margin Annotations --- */
.margin-annotations {
    position: absolute;
    top: 50%;
    left: calc(50% - var(--content-width) / 2 - 14rem);
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 10rem;
}

.margin-note {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--faded-chalk);
    opacity: 0;
    transition: opacity 0.6s ease;
    line-height: 1.4;
}

.margin-note.visible {
    opacity: 1;
}

/* --- Theorem Content --- */
.theorem-content {
    width: var(--content-width);
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.theorem-heading {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(2rem, 5.5vw, 4.8rem);
    letter-spacing: -0.02em;
    color: var(--chalk-white);
    margin: 1rem 0;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-feature-settings: 'liga' 1, 'onum' 1;
}

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

.theorem-body {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.05vw, 1.15rem);
    line-height: 1.9;
    letter-spacing: 0.01em;
    margin: 1.5rem 0;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.theorem-body.visible {
    opacity: 1;
    transform: translateY(0);
}

.dark-section .theorem-body {
    color: var(--parchment);
}

.light-section .theorem-body {
    color: var(--warm-graphite);
}

/* --- Inline Formulas --- */
.formula {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.75rem, 0.85vw, 0.9rem);
    color: var(--probability-rose);
    filter: blur(2px);
    opacity: 0.5;
    transition: filter 0.2s ease, opacity 0.2s ease;
    display: inline;
    padding: 0 0.15em;
}

.formula.revealed {
    filter: blur(0);
    opacity: 1;
}

/* --- Wasan Brushstroke Dividers --- */
.wasan-divider {
    width: 100%;
    height: 20px;
    overflow: visible;
}

.wasan-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 0.8s ease;
}

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

/* --- Closing Section --- */
.closing-kanji {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--theorem-gold);
    text-align: center;
    margin-top: 4rem;
    opacity: 0;
    transition: opacity 1s ease;
}

.closing-kanji.visible {
    opacity: 1;
}

.closing-domain {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 300;
    font-size: 0.8rem;
    color: var(--faded-chalk);
    text-align: center;
    margin-top: 1rem;
    letter-spacing: 0.2em;
    opacity: 0;
    transition: opacity 1s ease;
}

.closing-domain.visible {
    opacity: 1;
}

/* --- Clip-path section transition --- */
.theorem-section {
    clip-path: inset(0 0 0 0);
}

.theorem-section.clip-enter {
    clip-path: inset(100% 0 0 0);
    animation: clipReveal 0.6s ease forwards;
}

@keyframes clipReveal {
    from {
        clip-path: inset(100% 0 0 0);
    }
    to {
        clip-path: inset(0 0 0 0);
    }
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    .margin-annotations {
        display: none;
    }

    .section-number {
        left: 1.5rem;
    }
}

@media (max-width: 768px) {
    .margin-annotations {
        display: none;
    }

    .section-number {
        left: 1rem;
        top: 2vh;
    }

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

    .hero-kanji {
        font-size: 1.5rem;
    }

    .hero-subtitle {
        font-size: 0.75rem;
        padding: 0 1rem;
    }

    .theorem-content {
        padding: 0 1rem;
    }

    .watermark-sigma,
    .watermark-integral,
    .watermark-P {
        font-size: 30vh;
    }
}

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