/* ============================================
   bability.pro - The Architecture of Chance
   Art-Deco meets Data Visualization
   ============================================ */

/* --- Palette --- */
:root {
    --deep-obsidian: #0b0c1a;
    --midnight-indigo: #12142e;
    --parchment-ivory: #f0e6d0;
    --burnished-gold: #c9a84c;
    --slate-mist: #7a8a9a;
    --aurora-violet: #1a0a2e;
    --aurora-teal: #0a2a4a;
    --aurora-emerald: #2a4a3a;
    --probability-red: #8a2a2a;
    --pure-black: #000000;
}

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

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

body {
    background-color: var(--deep-obsidian);
    color: var(--parchment-ivory);
    font-family: 'Playfair Display', Georgia, serif;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Chamber Base --- */
.chamber {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.chamber-content {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 1400px;
    padding: 2rem;
}

/* --- Hexagonal Background Patterns --- */
.hex-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.hex-bg-lg {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='104' height='120'%3E%3Cpolygon points='52,0 104,30 104,90 52,120 0,90 0,30' fill='none' stroke='%23c9a84c' stroke-width='0.5' opacity='0.12'/%3E%3C/svg%3E") repeat;
}

.hex-bg-sm {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='69' height='80'%3E%3Cpolygon points='34.5,0 69,20 69,60 34.5,80 0,60 0,20' fill='none' stroke='%23c9a84c' stroke-width='0.5' opacity='0.10'/%3E%3C/svg%3E") repeat;
}

/* --- Section Numerals --- */
.section-numeral {
    font-family: 'Poiret One', sans-serif;
    font-size: clamp(1rem, 2vw, 1.8rem);
    color: var(--burnished-gold);
    letter-spacing: 0.1em;
    margin-bottom: 2rem;
    text-align: center;
}

/* --- Gold Decorative Lines --- */
.gold-rule {
    width: 60%;
    height: 0.5px;
    background: var(--burnished-gold);
    margin: 2rem auto;
    opacity: 0.4;
}

/* ============================================
   CHAMBER I: The Foyer of Fortune
   ============================================ */
#chamber-1 {
    background-color: var(--deep-obsidian);
    min-height: 100vh;
}

.chamber-1-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

#anagram-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 20vw;
    min-height: 120px;
    max-height: 300px;
    cursor: pointer;
}

.anagram-letter {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--parchment-ivory);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    position: absolute;
    opacity: 0;
    transition: all 2.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: transform, opacity;
}

.anagram-letter.settled {
    position: relative;
    opacity: 1;
    transform: none !important;
}

/* Tagline */
#tagline-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 3rem;
    opacity: 0;
    transition: opacity 1s ease 3.5s;
}

#tagline-container.visible {
    opacity: 1;
}

#tagline-line {
    width: min(400px, 60vw);
    height: 2px;
    margin-bottom: 1.5rem;
}

#tagline-line line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2s ease-out 3.5s;
}

#tagline-container.visible #tagline-line line {
    stroke-dashoffset: 0;
}

#tagline-text {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: 1rem;
    color: var(--slate-mist);
    letter-spacing: 0.04em;
}

/* ============================================
   CHAMBER II: The Gallery of Distributions
   ============================================ */
#chamber-2 {
    background-color: var(--midnight-indigo);
    min-height: 100vh;
}

.chamber-2-content {
    display: flex;
    gap: 4rem;
    align-items: flex-start;
    padding-top: 4rem;
    padding-bottom: 4rem;
}

.chamber-2-left {
    flex: 0 0 61.8%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chamber-2-right {
    flex: 0 0 calc(38.2% - 4rem);
}

#bell-curve {
    width: 100%;
    max-width: 600px;
}

#bell-stroke {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 2s ease-out;
}

#bell-stroke.drawn {
    stroke-dashoffset: 0;
}

#bell-fill {
    transition: opacity 1.5s ease-out 0.5s;
}

#bell-fill.filled {
    opacity: 1;
}

.sd-marker,
.sd-label {
    transition: opacity 0.8s ease-out 2.5s;
}

.sd-marker.visible,
.sd-label.visible {
    opacity: 0.6;
}

/* Quote cascade */
.quote-cascade {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-top: 2rem;
}

.quote-item {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.quote-item.revealed {
    opacity: 1;
    transform: translateY(0);
}

.quote-playfair {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    color: var(--parchment-ivory);
    letter-spacing: 0.02em;
    line-height: 1.6;
}

.quote-mono {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.8rem, 1.2vw, 1.1rem);
    color: var(--burnished-gold);
    letter-spacing: 0.04em;
    line-height: 1.4;
}

/* ============================================
   CHAMBER III: The Dice Cathedral
   ============================================ */
#chamber-3 {
    background-color: var(--deep-obsidian);
    min-height: 100vh;
}

.chamber-3-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 4rem 2rem;
}

.numeral-3 {
    position: absolute;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
}

/* Parallax layers */
.parallax-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

.parallax-bg {
    z-index: 0;
}

.parallax-mid {
    z-index: 1;
}

.parallax-fg {
    z-index: 2;
}

/* Galton board rings */
.galton-rings {
    position: relative;
    width: 500px;
    height: 500px;
}

.galton-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    border: 0.5px solid var(--burnished-gold);
    opacity: 0.15;
    animation: galton-rotate 720s linear infinite;
}

.ring-1 {
    width: 100px;
    height: 100px;
    margin-top: -50px;
    margin-left: -50px;
}

.ring-2 {
    width: 200px;
    height: 200px;
    margin-top: -100px;
    margin-left: -100px;
}

.ring-3 {
    width: 320px;
    height: 320px;
    margin-top: -160px;
    margin-left: -160px;
}

.ring-4 {
    width: 440px;
    height: 440px;
    margin-top: -220px;
    margin-left: -220px;
}

.ring-5 {
    width: 560px;
    height: 560px;
    margin-top: -280px;
    margin-left: -280px;
}

@keyframes galton-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Dice grid */
.dice-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    max-width: 500px;
    width: 100%;
    padding: 2rem;
}

.die-hex {
    width: 120px;
    height: 120px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background-color: var(--deep-obsidian);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin: 0 auto;
}

.die-hex::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: var(--burnished-gold);
    opacity: 0.3;
    z-index: -1;
}

.die-face {
    width: 70px;
    height: 70px;
    position: relative;
}

.pip {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--probability-red);
}

/* Die 1 */
.die-1 .pip:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

/* Die 2 */
.die-2 .pip:nth-child(1) { top: 10%; right: 10%; }
.die-2 .pip:nth-child(2) { bottom: 10%; left: 10%; }

/* Die 3 */
.die-3 .pip:nth-child(1) { top: 10%; right: 10%; }
.die-3 .pip:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.die-3 .pip:nth-child(3) { bottom: 10%; left: 10%; }

/* Die 4 */
.die-4 .pip:nth-child(1) { top: 10%; left: 10%; }
.die-4 .pip:nth-child(2) { top: 10%; right: 10%; }
.die-4 .pip:nth-child(3) { bottom: 10%; left: 10%; }
.die-4 .pip:nth-child(4) { bottom: 10%; right: 10%; }

/* Die 5 */
.die-5 .pip:nth-child(1) { top: 10%; left: 10%; }
.die-5 .pip:nth-child(2) { top: 10%; right: 10%; }
.die-5 .pip:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.die-5 .pip:nth-child(4) { bottom: 10%; left: 10%; }
.die-5 .pip:nth-child(5) { bottom: 10%; right: 10%; }

/* Die 6 */
.die-6 .pip:nth-child(1) { top: 10%; left: 10%; }
.die-6 .pip:nth-child(2) { top: 10%; right: 10%; }
.die-6 .pip:nth-child(3) { top: 50%; left: 10%; transform: translateY(-50%); }
.die-6 .pip:nth-child(4) { top: 50%; right: 10%; transform: translateY(-50%); }
.die-6 .pip:nth-child(5) { bottom: 10%; left: 10%; }
.die-6 .pip:nth-child(6) { bottom: 10%; right: 10%; }

/* Chamber III foreground text */
.chamber-3-text {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--parchment-ivory);
    text-align: center;
    letter-spacing: 0.02em;
    text-shadow: 0 0 40px rgba(11, 12, 26, 0.8);
}

/* ============================================
   CHAMBER IV: Pascal's Floor
   ============================================ */
#chamber-4 {
    background-color: var(--midnight-indigo);
    min-height: 100vh;
    padding: 4rem 0;
}

.chamber-4-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.numeral-4 {
    margin-bottom: 3rem;
}

#pascal-triangle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.pascal-row {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.pascal-cell {
    width: clamp(40px, 6vw, 65px);
    height: clamp(46px, 6.9vw, 75px);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

.pascal-cell.illuminated {
    opacity: 1;
    transform: scale(1);
}

.pascal-cell span {
    font-family: 'Poiret One', sans-serif;
    font-size: clamp(0.7rem, 1vw, 0.9rem);
    color: var(--parchment-ivory);
    position: relative;
    z-index: 1;
}

/* ============================================
   CHAMBER V: The Exit Through Entropy
   ============================================ */
#chamber-5 {
    background-color: var(--deep-obsidian);
    min-height: 100vh;
    transition: background-color 4s ease;
}

#chamber-5.faded {
    background-color: var(--pure-black);
}

.chamber-5-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
}

.numeral-5 {
    margin-bottom: 4rem;
}

#hex-fragment-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.hex-fragment {
    position: absolute;
    width: 40px;
    height: 46px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    border: 0.5px solid var(--burnished-gold);
    opacity: 0.12;
    transition: all 3s ease-out;
}

.hex-fragment.fragmented {
    opacity: var(--frag-opacity, 0.03);
    transform: translate(var(--frag-x, 0px), var(--frag-y, 0px)) rotate(var(--frag-rot, 0deg));
}

.chamber-5-quote {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 4rem);
    color: var(--parchment-ivory);
    letter-spacing: 0.02em;
    line-height: 1.4;
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1.5s ease-out, transform 1.5s ease-out;
}

.chamber-5-quote.revealed {
    opacity: 1;
    transform: translateY(0);
}

.chamber-5-domain {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--burnished-gold);
    letter-spacing: 0.08em;
    opacity: 0;
    transition: opacity 1s ease-out 0.5s;
}

.chamber-5-domain.revealed {
    opacity: 1;
    animation: domain-pulse 2s ease 1s 1;
}

@keyframes domain-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .chamber-2-content {
        flex-direction: column;
        gap: 2rem;
    }

    .chamber-2-left {
        flex: 1 1 100%;
    }

    .chamber-2-right {
        flex: 1 1 100%;
    }

    .dice-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
        max-width: 320px;
    }

    .die-hex {
        width: 80px;
        height: 80px;
    }

    .die-face {
        width: 50px;
        height: 50px;
    }

    .pip {
        width: 8px;
        height: 8px;
    }

    .galton-rings {
        width: 300px;
        height: 300px;
    }

    .ring-1 { width: 60px; height: 60px; margin-top: -30px; margin-left: -30px; }
    .ring-2 { width: 120px; height: 120px; margin-top: -60px; margin-left: -60px; }
    .ring-3 { width: 200px; height: 200px; margin-top: -100px; margin-left: -100px; }
    .ring-4 { width: 280px; height: 280px; margin-top: -140px; margin-left: -140px; }
    .ring-5 { width: 340px; height: 340px; margin-top: -170px; margin-left: -170px; }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .anagram-letter {
        transition: none;
    }

    #bell-stroke {
        transition: none;
        stroke-dashoffset: 0;
    }

    #bell-fill {
        transition: none;
        opacity: 1;
    }

    .quote-item {
        transition: none;
        opacity: 1;
        transform: none;
    }

    .pascal-cell {
        transition: none;
        opacity: 1;
        transform: none;
    }

    .galton-ring {
        animation: none;
    }

    .hex-fragment {
        transition: none;
    }

    .chamber-5-quote {
        transition: none;
        opacity: 1;
        transform: none;
    }

    .chamber-5-domain {
        transition: none;
        opacity: 1;
    }

    #tagline-container {
        transition: none;
        opacity: 1;
    }

    #tagline-line line {
        transition: none;
        stroke-dashoffset: 0;
    }

    .chamber-5-domain.revealed {
        animation: none;
    }

    #chamber-5 {
        transition: none;
    }
}
