/* ============================================
   gabs.wiki — Styles
   Kintsugi Encyclopedia of Worth
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Palette */
    --kiln-interior: #1A1613;
    --ash-grey: #2A2520;
    --ember-dark: #1E1812;
    --fired-parchment: #E8DDD0;
    --aged-paper: #C8BFAD;
    --clay-shadow: #8B7D6B;
    --kintsugi-gold: #C4A77D;
    --liquid-gold: #D4A855;
    --fracture-trace: #A08B6D;
    --terracotta-blush: #B85C3A;

    /* Dynamic values (updated via JS) */
    --scroll: 0;
    --cursor-x: 50%;
    --cursor-y: 50%;
    --bg-color: #1A1613;

    /* Typography */
    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'Source Serif 4', 'Georgia', serif;
    --font-annotation: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    --font-korean: 'Noto Serif KR', 'Cormorant Garamond', serif;
}

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

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

body {
    background-color: var(--bg-color);
    color: var(--aged-paper);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Clay grain texture via SVG feTurbulence */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='5' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncR type='linear' slope='0.08' intercept='0.06'/%3E%3CfeFuncG type='linear' slope='0.06' intercept='0.04'/%3E%3CfeFuncB type='linear' slope='0.04' intercept='0.03'/%3E%3CfeFuncA type='linear' slope='0.04'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    background-size: 600px 600px;
}

body.loaded::before {
    opacity: 1;
}

/* --- Background Watermark --- */
#watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-korean);
    font-weight: 500;
    font-size: 80vw;
    color: var(--kintsugi-gold);
    opacity: 0.025;
    pointer-events: none;
    z-index: 0;
    animation: watermark-breathe 8s ease-in-out infinite;
    will-change: transform, opacity;
    line-height: 1;
    user-select: none;
}

@keyframes watermark-breathe {
    0%, 100% { opacity: 0.02; }
    50% { opacity: 0.035; }
}

/* --- Crack Network SVG --- */
#crack-network {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

#crack-network .crack {
    stroke: var(--kintsugi-gold);
    stroke-width: 0.75;
    fill: none;
    opacity: 0;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: opacity 0.3s ease, filter 0.3s ease;
}

#crack-network .crack.revealed {
    opacity: 0.2;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 2s ease-out, opacity 1s ease;
}

#crack-network .crack.illuminated {
    opacity: 0.5;
    filter: drop-shadow(0 0 6px rgba(196, 167, 125, 0.25));
}

#crack-network .crack.final-state {
    opacity: 0.5;
}

/* --- Gold Dust Particles --- */
#gold-dust {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.dust {
    position: absolute;
    background-color: var(--liquid-gold);
    opacity: 0.2;
    animation: dust-rotate linear infinite;
    will-change: transform;
}

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

.dust.settled {
    animation-play-state: paused;
}

/* --- Scroll Progress Indicator --- */
#scroll-progress {
    position: fixed;
    left: 16px;
    top: 10%;
    height: 80%;
    width: 2px;
    z-index: 100;
}

#scroll-track {
    position: absolute;
    inset: 0;
    background-color: var(--kintsugi-gold);
    opacity: 0.15;
}

#scroll-fill {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 0%;
    background-color: var(--kintsugi-gold);
    opacity: 0.5;
    transition: height 0.1s linear;
}

.diamond {
    position: absolute;
    left: 50%;
    width: 6px;
    height: 6px;
    background-color: var(--kintsugi-gold);
    opacity: 0.4;
    transform: translateX(-50%) rotate(45deg);
    transition: opacity 0.3s ease, background-color 0.3s ease;
}

.diamond.active {
    opacity: 0.8;
    background-color: var(--liquid-gold);
}

/* --- Sections --- */
.section {
    position: relative;
    z-index: 2;
    padding: 0 5%;
}

/* --- THE KILN MOUTH --- */
#kiln-mouth {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding-left: 10%;
    position: relative;
    overflow: hidden;
}

.opening-crack-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.crack-draw {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    opacity: 0;
}

body.loaded .crack-draw {
    opacity: 0.35;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1.2s ease-out 0.4s, opacity 0.6s ease 0.4s;
}

body.loaded .crack-draw.crack-draw-delay {
    transition: stroke-dashoffset 1.4s ease-out 0.6s, opacity 0.6s ease 0.6s;
}

#kiln-title {
    position: relative;
    z-index: 2;
}

#gabs-character {
    font-family: var(--font-korean);
    font-weight: 700;
    font-size: clamp(20rem, 40vw, 50rem);
    color: var(--kiln-interior);
    line-height: 0.85;
    opacity: 0;
    transition: color 0.8s ease, opacity 0.8s ease;
    user-select: none;
}

body.loaded #gabs-character {
    color: #6B4F3A;
    opacity: 1;
    transition: color 0.8s ease 1.6s, opacity 0.8s ease 1.6s;
}

#wiki-subtitle {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(1.2rem, 2.5vw, 2.4rem);
    color: var(--clay-shadow);
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-top: -0.5em;
    margin-left: 0.2em;
    opacity: 0;
    clip-path: inset(0 100% 0 0);
}

body.loaded #wiki-subtitle {
    opacity: 1;
    clip-path: inset(0 0% 0 0);
    transition: clip-path 0.6s ease-out 2.4s, opacity 0.3s ease 2.4s;
}

#kiln-tagline {
    margin-top: 3rem;
    z-index: 2;
}

#kiln-tagline .annotation {
    font-family: var(--font-annotation);
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    color: var(--clay-shadow);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* --- SORTING TABLE --- */
#sorting-table {
    padding-top: 10vh;
    padding-bottom: 10vh;
}

/* --- REPAIR ROOM --- */
#repair-room {
    padding-top: 10vh;
    padding-bottom: 10vh;
}

.cluster-dense .shard-annotation {
    margin-top: -100px;
}

/* --- COLLECTION SHELF --- */
#collection-shelf {
    padding-top: 10vh;
    padding-bottom: 15vh;
    min-height: 80vh;
}

.collection-column {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 2rem;
}

.collection-column .shard {
    width: 100%;
    margin-left: 0;
}

#final-gabs {
    font-family: var(--font-korean);
    font-weight: 700;
    font-size: clamp(6rem, 15vw, 14rem);
    color: var(--kintsugi-gold);
    text-align: center;
    margin-top: 4rem;
    opacity: 0;
    transition: opacity 1.5s ease;
    text-shadow: 0 0 40px rgba(196, 167, 125, 0.3), 0 0 80px rgba(196, 167, 125, 0.15);
}

#final-gabs.visible {
    opacity: 1;
}

/* --- Shard Clusters --- */
.shard-cluster {
    position: relative;
    margin-bottom: 80px;
    padding: 20px 0;
}

.cluster-connector {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* --- Shards --- */
.shard {
    position: relative;
    z-index: 1;
    padding: 2rem 2.4rem;
    border: 1px solid rgba(196, 167, 125, 0.12);
    background-color: rgba(42, 37, 32, 0.4);
    box-shadow: 3px 4px 12px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(196, 167, 125, 0.08);
    margin-bottom: 1.5rem;
}

.shard-major {
    padding: 2.8rem 3rem;
}

.shard-annotation {
    padding: 1.6rem 2rem;
    background-color: rgba(42, 37, 32, 0.6);
    border-color: rgba(196, 167, 125, 0.08);
}

.shard-dust {
    padding: 1rem 1.4rem;
    background-color: rgba(30, 24, 18, 0.5);
    border-color: rgba(196, 167, 125, 0.06);
}

/* Golden gap glow between shards */
.shard::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 10%;
    right: 10%;
    height: 8px;
    background: linear-gradient(to bottom, rgba(196, 167, 125, 0.08), transparent);
    pointer-events: none;
}

/* --- Shard Reveal Animation --- */
.shard-reveal {
    opacity: 0;
    transform: translateY(20px) rotate(1.5deg);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.shard-reveal.visible {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
}

/* --- Section Dividers --- */
.section-divider {
    display: block;
    width: 100%;
    height: 20px;
    margin-bottom: 6vh;
    overflow: visible;
}

/* --- Typography --- */
.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.2rem, 5vw, 4.8rem);
    color: var(--fired-parchment);
    letter-spacing: 0.02em;
    line-height: 1.05;
    margin-bottom: 1.5rem;
}

/* Character-by-character reveal for headings */
.section-heading .char {
    display: inline-block;
    opacity: 0.3;
    color: var(--clay-shadow);
    transition: opacity 0.2s ease, color 0.2s ease;
}

.section-heading .char.fired {
    opacity: 1;
    color: var(--fired-parchment);
}

p {
    margin-bottom: 1.2em;
    color: var(--aged-paper);
}

p:last-child {
    margin-bottom: 0;
}

em {
    font-style: italic;
    color: var(--fired-parchment);
}

.annotation {
    font-family: var(--font-annotation);
    font-weight: 400;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--clay-shadow);
    line-height: 1.6;
    margin-bottom: 0.5em;
}

.meta {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(0.85rem, 1vw, 0.95rem);
    color: var(--clay-shadow);
    line-height: 1.65;
    margin-bottom: 0.8em;
}

/* --- Responsive adjustments --- */
@media (max-width: 900px) {
    .shard-major,
    .shard-annotation,
    .shard-dust {
        width: 90% !important;
        margin-left: 5% !important;
        margin-top: 0 !important;
    }

    .shard-cluster {
        margin-bottom: 50px;
    }

    #kiln-mouth {
        padding-left: 6%;
    }

    #gabs-character {
        font-size: clamp(10rem, 30vw, 20rem);
    }

    #scroll-progress {
        left: 8px;
    }

    .cluster-dense .shard-annotation {
        margin-top: 0 !important;
    }
}

@media (max-width: 600px) {
    .section {
        padding: 0 3%;
    }

    .shard {
        padding: 1.4rem 1.6rem;
    }

    .shard-major {
        padding: 1.8rem 2rem;
    }

    .collection-column {
        padding: 0 1rem;
    }

    #gabs-character {
        font-size: clamp(8rem, 25vw, 15rem);
    }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .shard-reveal {
        opacity: 1;
        transform: none;
    }

    .crack-draw {
        stroke-dashoffset: 0;
        opacity: 0.35;
    }

    #gabs-character {
        color: #6B4F3A;
        opacity: 1;
    }

    #wiki-subtitle {
        opacity: 1;
        clip-path: none;
    }

    #crack-network .crack {
        opacity: 0.2;
        stroke-dashoffset: 0;
    }

    #final-gabs {
        opacity: 1;
    }

    .section-heading .char {
        opacity: 1;
        color: var(--fired-parchment);
    }

    body::before {
        opacity: 1;
    }

    #watermark {
        animation: none;
        opacity: 0.025;
    }

    .dust {
        animation: none;
    }
}
