/* ============================================================
   namu.market -- Luxury-Premium Night Market
   Palette: Deep Burgundy
   Typography: Art Deco Display (Josefin Sans, Cormorant Garamond, DM Mono)
   Layout: Modular Blocks with Progressive Disclosure
   ============================================================ */

/* --- Custom Properties --- */
:root {
    --midnight-burgundy: #1a0a10;
    --velvet-wine: #5c1a2a;
    --dried-rose: #8a3a4a;
    --antique-gold: #c9a050;
    --amber-glow: #d4a855;
    --parchment-cream: #f0e6d4;
    --dusty-mauve: #7a5a60;
    --dark-mahogany: #2a0f1a;
    --moss-green: #4a7a3a;
    --canopy-teal: #2a6a5a;
    --muted-gold: #a08040;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background-color: var(--midnight-burgundy);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence baseFrequency='0.45' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    color: var(--parchment-cream);
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Scroll Progress Vine --- */
#scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    z-index: 1000;
    pointer-events: none;
}

#scroll-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--antique-gold);
    transition: width 50ms linear;
}

.scroll-bud {
    position: absolute;
    top: -4px;
    opacity: 0;
    transition: opacity 200ms ease;
}

.scroll-bud-25 { left: 25%; }
.scroll-bud-50 { left: 50%; }
.scroll-bud-75 { left: 75%; }

.scroll-bud.visible {
    opacity: 1;
}

/* --- Intro Section --- */
#intro {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--midnight-burgundy);
    z-index: 10;
    overflow: hidden;
}

#intro.collapsed {
    position: fixed;
    top: 0;
    left: 0;
    height: auto;
    padding: 20px 0;
    z-index: 100;
    background: linear-gradient(180deg, var(--midnight-burgundy) 0%, rgba(26, 10, 16, 0.95) 100%);
    transition: all 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

#ring-motif {
    opacity: 0;
    transition: opacity 800ms cubic-bezier(0.16, 1, 0.3, 1);
}

#ring-motif svg {
    display: block;
}

#ring-motif.visible {
    opacity: 1;
}

#ring-motif.shrunk {
    transform: scale(0.4) translateY(-30vh);
    transition: transform 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

.ring-outer {
    animation: none;
    transform-origin: center;
}
.ring-middle {
    animation: none;
    transform-origin: center;
}
.ring-inner {
    animation: none;
    transform-origin: center;
}

.ring-outer.spinning { animation: spin-slow 3s linear infinite; }
.ring-middle.spinning { animation: spin-slow 5s linear infinite reverse; }
.ring-inner.spinning { animation: spin-slow 8s linear infinite; }

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

/* Intro collapsed state */
#intro.collapsed #ring-motif {
    transform: scale(0.2);
    position: absolute;
    left: 30px;
    top: 50%;
    margin-top: -20px;
}

#intro.collapsed #intro-title {
    transform: scale(0.5);
    opacity: 0.8;
}

#intro.collapsed #title-line {
    display: none;
}

/* Intro Title */
#intro-title {
    text-align: center;
    margin-top: 30px;
    opacity: 0;
}

#intro-title.visible {
    opacity: 1;
}

#title-namu {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(3.5rem, 9vw, 7rem);
    color: var(--antique-gold);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    line-height: 1;
}

#title-namu span {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 300ms ease, transform 300ms ease;
}

#title-namu span.revealed {
    opacity: 1;
    transform: translateY(0);
}

#title-line {
    width: 0;
    height: 1px;
    background: var(--antique-gold);
    margin: 15px auto;
    transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

#title-line.drawn {
    width: 30vw;
}

#title-market {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(2.1rem, 5.4vw, 4.2rem);
    color: var(--antique-gold);
    letter-spacing: 0.35em;
    text-transform: uppercase;
    line-height: 1;
}

#title-market span {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 300ms ease, transform 300ms ease;
}

#title-market span.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* --- Canopy Overlay --- */
#canopy-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: hidden;
}

.canopy-leaf {
    position: absolute;
    opacity: 0.05;
    will-change: transform;
}

.canopy-leaf-1 { top: 8%; left: 5%; width: 80px; height: 120px; }
.canopy-leaf-2 { top: 25%; right: 8%; width: 60px; height: 90px; }
.canopy-leaf-3 { top: 50%; left: 15%; width: 70px; height: 105px; }
.canopy-leaf-4 { top: 65%; right: 12%; width: 50px; height: 75px; }
.canopy-leaf-5 { top: 85%; left: 40%; width: 65px; height: 97px; }

@keyframes canopy-drift {
    0%, 100% { transform: translateX(0) translateY(0) rotate(0deg); }
    25% { transform: translateX(10px) translateY(-5px) rotate(2deg); }
    50% { transform: translateX(-5px) translateY(3px) rotate(-1deg); }
    75% { transform: translateX(8px) translateY(-2px) rotate(1.5deg); }
}

.canopy-leaf-1 { animation: canopy-drift 20s ease-in-out infinite; }
.canopy-leaf-2 { animation: canopy-drift 25s ease-in-out infinite 3s; }
.canopy-leaf-3 { animation: canopy-drift 18s ease-in-out infinite 7s; }
.canopy-leaf-4 { animation: canopy-drift 22s ease-in-out infinite 5s; }
.canopy-leaf-5 { animation: canopy-drift 28s ease-in-out infinite 10s; }

/* --- Main Content --- */
#market {
    position: relative;
    z-index: 6;
    padding: 60px 5% 40px;
    max-width: 1400px;
    margin: 0 auto;
}

/* --- Chapter Labels --- */
.chapter-label {
    display: block;
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    color: var(--antique-gold);
    opacity: 0.6;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 30px;
}

.market-chapter {
    margin-bottom: 60px;
}

/* --- Market Grid --- */
.market-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(80px, auto);
    gap: 3px;
    position: relative;
}

.market-grid::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

/* --- Market Blocks --- */
.market-block {
    position: relative;
    min-height: 80px;
    transition: all 500ms ease-out;
}

.block-surface {
    position: relative;
    height: 100%;
    background: var(--dark-mahogany);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='t'%3E%3CfeTurbulence baseFrequency='0.8' numOctaves='4' seed='42'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23t)' opacity='0.03'/%3E%3C/svg%3E");
    background-blend-mode: multiply;
    border: 1px solid rgba(201, 160, 80, 0.15);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    padding: 20px;
    overflow: hidden;
    transition: border-color 200ms ease, box-shadow 200ms ease;
}

.market-block.expanded .block-surface {
    border-color: rgba(201, 160, 80, 0.6);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 40px rgba(201, 160, 80, 0.08);
}

/* --- Block Header --- */
.block-header {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.block-title {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 600;
    font-size: clamp(0.95rem, 2vw, 1.2rem);
    color: var(--antique-gold);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    flex: 1;
}

.leaf-icon {
    flex-shrink: 0;
    transition: fill 300ms ease;
}

.market-block:hover .leaf-icon ellipse {
    fill: var(--velvet-wine);
    transition: fill 300ms ease;
}

.sparkline-mini {
    flex-shrink: 0;
    opacity: 0.6;
}

/* --- Block Toggle --- */
.block-toggle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--velvet-wine);
    border: 1px solid var(--antique-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 200ms ease;
}

.block-toggle:hover {
    background: var(--dried-rose);
}

.toggle-icon {
    font-family: 'DM Mono', monospace;
    font-size: 14px;
    color: var(--antique-gold);
    line-height: 1;
    display: block;
    transition: transform 300ms ease;
}

.market-block.expanded .toggle-icon {
    transform: rotate(45deg);
}

/* --- Block Content (Progressive Disclosure) --- */
.block-content {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 500ms ease-out, opacity 400ms ease-out;
    margin-top: 0;
}

.market-block.expanded .block-content {
    max-height: 800px;
    opacity: 1;
    margin-top: 16px;
}

.block-content p {
    margin-bottom: 12px;
    color: var(--parchment-cream);
}

.block-content .stagger-item {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 300ms ease, transform 300ms ease;
}

.block-content .stagger-item.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Data Labels --- */
.data-label {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    color: var(--muted-gold);
    letter-spacing: 0.06em;
}

/* --- Ring List --- */
.ring-list {
    list-style: none;
    padding: 0;
}

.ring-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    font-size: clamp(0.9rem, 1.5vw, 1rem);
}

.ring-bullet {
    flex-shrink: 0;
    margin-top: 4px;
}

/* --- Market Quote --- */
.market-quote {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    color: var(--amber-glow);
    border-left: 2px solid rgba(201, 160, 80, 0.3);
    padding-left: 16px;
    margin-bottom: 12px;
    line-height: 1.6;
}

/* --- Hours Display --- */
.hours-display {
    margin-bottom: 12px;
}

.hour-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(201, 160, 80, 0.1);
}

.hour-value {
    font-family: 'DM Mono', monospace;
    font-size: clamp(0.9rem, 1.5vw, 1.05rem);
    color: var(--antique-gold);
    letter-spacing: 0.06em;
}

/* --- Archive Numbers --- */
.archive-numbers {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.archive-stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    color: var(--antique-gold);
    letter-spacing: 0.08em;
    line-height: 1.2;
}

/* --- Whisper Entries --- */
.whisper-entries {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.whisper {
    font-style: italic;
    color: var(--parchment-cream);
    opacity: 0.85;
    font-size: clamp(0.9rem, 1.4vw, 1rem);
}

/* --- Lantern Dots --- */
.lantern-dots {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    justify-content: center;
}

.lantern-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
    opacity: 0.8;
    animation: lantern-pulse 3s ease-in-out infinite;
}

.lantern-dot:nth-child(2) { animation-delay: 0.5s; }
.lantern-dot:nth-child(3) { animation-delay: 1s; }
.lantern-dot:nth-child(4) { animation-delay: 1.5s; }

@keyframes lantern-pulse {
    0%, 100% { opacity: 0.6; box-shadow: 0 0 6px currentColor; }
    50% { opacity: 1; box-shadow: 0 0 14px currentColor; }
}

/* --- Tree Ring Charts --- */
.tree-ring-chart {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 12px 0;
}

.tree-ring-chart svg {
    display: block;
    max-width: 100%;
    height: auto;
}

.tree-ring {
    transition: stroke-dashoffset 600ms cubic-bezier(0.33, 1, 0.68, 1);
}

.tree-ring.animated {
    stroke-dashoffset: 0 !important;
}

/* --- Vine Sparklines --- */
.vine-sparkline {
    margin: 12px 0;
}

.vine-sparkline svg {
    display: block;
    max-width: 100%;
    height: auto;
}

.vine-path {
    transition: stroke-dashoffset 1.5s ease;
}

.vine-path.drawn {
    stroke-dashoffset: 0 !important;
}

.vine-leaf {
    transition: transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: center;
}

.vine-leaf.popped {
    transform: scale(2) !important;
}

/* --- Canopy Heatmap --- */
.canopy-heatmap {
    margin: 12px 0;
}

.canopy-heatmap svg {
    display: block;
    max-width: 100%;
    height: auto;
}

.heatmap-leaf {
    transition: opacity 400ms ease, transform 400ms ease;
}

.heatmap-leaf.revealed {
    opacity: 0.8 !important;
}

/* --- Branch Divider --- */
.branch-divider {
    width: 60%;
    margin: 30px auto;
    opacity: 0.6;
}

.branch-divider svg {
    display: block;
    width: 100%;
    height: auto;
}

/* --- Footer / Keeper's Ledger --- */
#chapter-ledger {
    position: relative;
    z-index: 6;
    padding: 60px 5% 40px;
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

#chapter-ledger .chapter-label {
    text-align: left;
}

.ledger-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    margin: 30px 0;
    flex-wrap: wrap;
}

.ledger-ring svg {
    display: block;
}

.ledger-text {
    text-align: left;
    max-width: 400px;
}

.ledger-title {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    color: var(--antique-gold);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.ledger-subtitle {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-style: italic;
    font-size: clamp(1rem, 1.8vw, 1.2rem);
    color: var(--dusty-mauve);
    margin-bottom: 12px;
}

.ledger-note {
    color: var(--parchment-cream);
    opacity: 0.8;
    margin-bottom: 12px;
}

.footer-branch {
    width: 50%;
    margin: 30px auto 0;
    opacity: 0.4;
}

.footer-branch svg {
    display: block;
    width: 100%;
    height: auto;
}

/* --- Interactive Link Hover with Leaf --- */
a, .interactive-link {
    color: var(--parchment-cream);
    text-decoration: none;
    transition: color 200ms ease;
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

a:hover, .interactive-link:hover {
    color: var(--antique-gold);
}

/* --- Mobile Adaptation --- */
@media (max-width: 768px) {
    .market-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;
        gap: 0;
    }

    .market-block {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
        border-bottom: 1px solid rgba(201, 160, 80, 0.2);
    }

    .block-surface {
        border: none;
        border-bottom: 1px solid rgba(201, 160, 80, 0.15);
        box-shadow: none;
    }

    .market-block.expanded .block-surface {
        box-shadow: none;
    }

    #canopy-overlay {
        display: none;
    }

    .branch-divider {
        width: 80%;
    }

    .ledger-content {
        flex-direction: column;
        text-align: center;
    }

    .ledger-text {
        text-align: center;
    }

    #chapter-ledger .chapter-label {
        text-align: center;
    }

    #intro.collapsed #ring-motif {
        display: none;
    }

    #intro.collapsed #intro-title {
        transform: scale(0.6);
    }
}

@media (max-width: 480px) {
    #market {
        padding: 40px 3% 30px;
    }

    .chapter-label {
        font-size: 1.2rem;
        margin-bottom: 20px;
    }

    .block-surface {
        padding: 14px;
    }

    .tree-ring-chart svg,
    .vine-sparkline svg,
    .canopy-heatmap svg {
        max-width: 200px;
    }

    .tree-ring-large svg {
        max-width: 220px;
    }
}

/* --- Smooth transitions for grid gap gold lines --- */
.market-grid {
    background: rgba(201, 160, 80, 0.08);
    padding: 3px;
    border-radius: 0;
}

/* --- Utility for stagger reveal --- */
.reveal-stagger > * {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 300ms ease, transform 300ms ease;
}

.reveal-stagger > *.visible {
    opacity: 1;
    transform: translateY(0);
}
