/* ========================================
   rust.quest — styles.css
   Wabi-sabi immersive scroll experience
   ======================================== */

/* --- CSS Custom Properties --- */
:root {
    --iron-black: #1A1210;
    --rust-ember: #8B3A1A;
    --patina-verdigris: #5A8C6F;
    --kintsugi-gold: #C8963E;
    --parchment-cream: #F5EDE0;
    --earth-brown: #3B2F2F;
    --fog-gray: #A89B8C;
    --copper-blush: #D4A88C;
    --deep-iron: #2B1D1D;
    --body-light: #D4C5B5;
    --body-dark: #4A3B3B;
    --ochre: #8B6F4E;
    --warm-gold: #DAA94E;
    --mid-rust: #3D2218;
    --mid-sienna: #6B3D2A;

    --cursor-x: 50;
    --cursor-y: 50;
    --scroll-progress: 0;
}

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

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

body {
    font-family: 'EB Garamond', Georgia, serif;
    background-color: var(--iron-black);
    color: var(--body-light);
    overflow-x: hidden;
    transition: background-color 0.05s linear;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.04;
    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-repeat: repeat;
    background-size: 256px 256px;
}

/* --- Progress Bar --- */
#progress-bar {
    position: fixed;
    right: 0;
    top: 0;
    width: 2px;
    height: 100vh;
    z-index: 999;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

#progress-bar:hover {
    opacity: 0.7;
}

#progress-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, var(--rust-ember), var(--patina-verdigris));
    transform-origin: top center;
    transform: scaleY(0);
    transition: transform 0.1s linear;
}

/* --- Typography --- */
.title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(2.8rem, 6vw, 5.5rem);
    letter-spacing: 0.06em;
    line-height: 1.1;
    color: var(--parchment-cream);
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(calc(var(--i) * 0.5px - 2px));
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.letter.visible {
    opacity: 1;
}

.subtitle {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: 1.2rem;
    letter-spacing: 0.02em;
    color: var(--ochre);
    opacity: 0;
    margin-top: 1.5rem;
    transition: opacity 1s ease;
}

.subtitle.visible {
    opacity: 0.7;
}

.section-heading {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 300;
    font-size: clamp(2rem, 4.5vw, 3.8rem);
    letter-spacing: 0.06em;
    line-height: 1.1;
    color: var(--parchment-cream);
    margin-bottom: 3rem;
}

.body-text {
    font-family: 'EB Garamond', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.2vw, 1.25rem);
    line-height: 1.75;
    max-width: 38em;
    color: var(--body-light);
    margin-bottom: 4rem;
}

.body-text em {
    font-style: italic;
}

.caption {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: var(--ochre);
    display: block;
    margin-top: 0.8rem;
    text-align: center;
}

.accent-text {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(1.2rem, 1.8vw, 1.5rem);
    color: var(--kintsugi-gold);
}

.handwritten-aside {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--ochre);
    display: block;
    margin-top: 2rem;
    opacity: 0.8;
}

/* --- Stratum Sections --- */
.stratum {
    position: relative;
    width: 100%;
}

/* Stratum I — Raw Iron */
#stratum-1 {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stratum-1-content {
    text-align: center;
    position: relative;
}

.chevron {
    position: absolute;
    bottom: -30vh;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    animation: chevron-pulse 2s ease-in-out 4s 1 forwards;
}

@keyframes chevron-pulse {
    0% { opacity: 0; transform: translateX(-50%) scale(1); }
    15% { opacity: 0.6; transform: translateX(-50%) scale(1); }
    50% { opacity: 0.6; transform: translateX(-50%) scale(1.15); }
    85% { opacity: 0.6; transform: translateX(-50%) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) scale(1); }
}

/* Stratum II — First Oxidation */
#stratum-2 {
    min-height: 150vh;
    padding: 10vh 0;
}

.narrow-column {
    max-width: 540px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Stratum III — Patina Bloom */
#stratum-3 {
    min-height: 150vh;
    padding: 10vh 0;
}

.medium-column {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Stratum IV — Golden Repair */
#stratum-4 {
    min-height: 150vh;
    padding: 10vh 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kintsugi-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 4rem 1.5rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
}

.kintsugi-crack {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

#crack-path {
    filter: drop-shadow(0 0 12px rgba(200, 150, 62, 0.3));
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: filter 0.3s ease;
}

#crack-path.drawn {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 2s ease-out, filter 0.3s ease;
}

#crack-path.glow {
    filter: drop-shadow(0 0 24px rgba(218, 169, 78, 0.5));
    stroke: var(--warm-gold);
}

.crack-panel {
    position: relative;
    z-index: 3;
}

.crack-panel-left {
    padding-right: 2rem;
}

.crack-panel-right {
    padding-left: 2rem;
    margin-top: 4rem;
}

.gold-heading {
    color: var(--kintsugi-gold);
}

/* Stratum V — Meadow Return */
#stratum-5 {
    min-height: 100vh;
    padding: 10vh 0;
}

.meadow-column {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.meadow-heading {
    color: var(--earth-brown);
}

.meadow-text {
    color: var(--earth-brown);
}

.final-line-container {
    text-align: center;
    padding: 8rem 0 2rem;
}

.final-line {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 300;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    letter-spacing: 0.06em;
    color: var(--earth-brown);
    opacity: 0.85;
}

.breath-space {
    height: 40vh;
}

/* --- Imagery --- */
.image-container {
    margin-bottom: 4rem;
}

.vintage-image {
    filter: sepia(0.15) contrast(0.92) brightness(0.95) saturate(0.8);
    border-radius: 2px;
    overflow: hidden;
}

.vintage-image svg {
    display: block;
    width: 100%;
    height: auto;
}

.eroded-edge {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 400'%3E%3Cellipse cx='300' cy='200' rx='290' ry='190' fill='white'/%3E%3Cellipse cx='100' cy='80' rx='110' ry='90' fill='white'/%3E%3Cellipse cx='500' cy='320' rx='120' ry='95' fill='white'/%3E%3Cellipse cx='300' cy='50' rx='200' ry='60' fill='white'/%3E%3Cellipse cx='300' cy='350' rx='220' ry='70' fill='white'/%3E%3C/svg%3E");
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 400'%3E%3Cellipse cx='300' cy='200' rx='290' ry='190' fill='white'/%3E%3Cellipse cx='100' cy='80' rx='110' ry='90' fill='white'/%3E%3Cellipse cx='500' cy='320' rx='120' ry='95' fill='white'/%3E%3Cellipse cx='300' cy='50' rx='200' ry='60' fill='white'/%3E%3Cellipse cx='300' cy='350' rx='220' ry='70' fill='white'/%3E%3C/svg%3E");
    mask-size: cover;
    -webkit-mask-size: cover;
    mask-position: center;
    -webkit-mask-position: center;
}

/* --- Reveal Animation --- */
.reveal-image {
    opacity: 0;
    filter: blur(12px);
    transform: scale(0.97);
    transition: opacity 1.2s ease-out, filter 1.2s ease-out, transform 1.2s ease-out;
}

.reveal-image.revealed {
    opacity: 1;
    filter: blur(0px);
    transform: scale(1);
}

/* --- Bubble System --- */
#bubble-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    overflow: hidden;
}

.bubble {
    position: absolute;
    border-radius: 50%;
    will-change: transform;
    animation: bubble-bob var(--bob-duration, 6s) ease-in-out infinite alternate;
}

@keyframes bubble-bob {
    0% { transform: translate(var(--tx, 0px), var(--ty, 0px)) translateY(0px); }
    100% { transform: translate(var(--tx, 0px), var(--ty, 0px)) translateY(calc(var(--bob-amount, -10px))); }
}

/* Stratum V upward drift */
.bubble.meadow-drift {
    animation: bubble-rise var(--bob-duration, 8s) linear infinite;
}

@keyframes bubble-rise {
    0% { transform: translate(var(--tx, 0px), var(--ty, 0px)) translateY(0px); opacity: 0.6; }
    100% { transform: translate(var(--tx, 0px), var(--ty, 0px)) translateY(-100vh); opacity: 0; }
}

/* --- Stratum-aware text colors --- */
body.stratum-light .section-heading,
body.stratum-light .body-text {
    color: var(--earth-brown);
}

body.stratum-light .caption {
    color: var(--ochre);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .kintsugi-container {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .crack-panel-left,
    .crack-panel-right {
        padding: 0;
        margin-top: 0;
    }

    .kintsugi-crack {
        display: none;
    }
}
