/* ============================================
   20241204.com - Pixel Art Chronicle Styles
   ============================================ */

/* CSS Custom Properties */
:root {
    /* Color Palette */
    --amber-glow: #f5a623;
    --burnt-coral: #e8573a;
    --twilight-indigo: #1a0a2e;
    --desert-sand: #faf3e8;
    --dusky-rose: #8b2252;
    --saffron-thread: #d4783a;
    --warm-charcoal: #2d1b4e;
    --faded-plum: #6b4c7a;
    --cream-white: #f5efe6;
    --pixel-outline: #3a1f5e;

    /* Scroll-driven property */
    --scroll-progress: 0;

    /* Layout */
    --sidebar-width: 48px;
    --timeline-node-size: 24px;
    --entry-gap: 120px;
    --chapter-gap: 200px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 1.7;
    color: var(--warm-charcoal);
    background-color: var(--twilight-indigo);
    overflow-x: hidden;
    image-rendering: pixelated;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   Scroll-Driven Background
   ============================================ */
body {
    background: linear-gradient(
        to bottom,
        #1a0a2e 0%,
        #2d1b4e 10%,
        #3a1f5e 20%,
        #6b4c7a 30%,
        #d4783a 40%,
        #f5a623 48%,
        #faf3e8 52%,
        #f5a623 58%,
        #d4783a 65%,
        #e8573a 72%,
        #8b2252 82%,
        #3a1f5e 90%,
        #1a0a2e 100%
    );
}

/* ============================================
   Mobile Progress Bar
   ============================================ */
.mobile-progress-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(26, 10, 46, 0.3);
    z-index: 1000;
}

.mobile-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--amber-glow), var(--burnt-coral));
    transition: width 0.1s linear;
}

/* ============================================
   Sidebar Minimap
   ============================================ */
.sidebar-minimap {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: rgba(26, 10, 46, 0.85);
    border-right: 2px solid var(--pixel-outline);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.minimap-track {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 20px 0;
}

.minimap-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.3s ease, transform 0.3s ease;
    image-rendering: pixelated;
}

.minimap-icon:hover,
.minimap-icon.active {
    opacity: 1;
    transform: scale(1.2);
}

.minimap-icon.active svg {
    filter: drop-shadow(0 0 4px rgba(245, 166, 35, 0.6));
}

.minimap-indicator {
    position: absolute;
    left: -4px;
    width: 4px;
    height: 24px;
    background: var(--amber-glow);
    border-radius: 2px;
    transition: top 0.3s ease;
    top: 20px;
}

/* ============================================
   Timeline Container
   ============================================ */
.timeline-container {
    position: relative;
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px 100px;
    margin-left: calc(var(--sidebar-width) + ((100vw - var(--sidebar-width) - 1000px) / 2));
}

/* Timeline spine */
.timeline-container::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 4px;
    transform: translateX(-50%);
    background: repeating-linear-gradient(
        to bottom,
        var(--amber-glow) 0px,
        var(--amber-glow) 4px,
        var(--burnt-coral) 4px,
        var(--burnt-coral) 8px,
        var(--amber-glow) 8px,
        var(--amber-glow) 10px,
        transparent 10px,
        transparent 12px
    );
    image-rendering: pixelated;
    z-index: 1;
}

/* ============================================
   Chapter Banners
   ============================================ */
.chapter {
    position: relative;
    margin-bottom: var(--chapter-gap);
    z-index: 2;
}

.chapter:first-child {
    padding-top: 60px;
}

.chapter-banner {
    position: relative;
    width: 100vw;
    margin-left: calc(-50vw + 500px - 10px);
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 60px 20px;
}

.chapter-title {
    font-family: 'Silkscreen', 'Fira Sans', sans-serif;
    font-weight: 700;
    font-size: 48px;
    letter-spacing: 2px;
    color: var(--cream-white);
    text-shadow:
        4px 4px 0 var(--pixel-outline),
        -2px -2px 0 var(--pixel-outline),
        2px -2px 0 var(--pixel-outline),
        -2px 2px 0 var(--pixel-outline);
    position: relative;
    z-index: 3;
    image-rendering: pixelated;
    animation: chapter-pulse 1.2s ease-in-out infinite;
}

@keyframes chapter-pulse {
    0%, 100% {
        text-shadow:
            4px 4px 0 var(--pixel-outline),
            -2px -2px 0 var(--pixel-outline),
            2px -2px 0 var(--pixel-outline),
            -2px 2px 0 var(--pixel-outline);
    }
    50% {
        text-shadow:
            4px 4px 0 var(--pixel-outline),
            -2px -2px 0 var(--pixel-outline),
            2px -2px 0 var(--pixel-outline),
            -2px 2px 0 var(--pixel-outline),
            0 0 20px rgba(245, 166, 35, 0.3);
    }
}

.chapter-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--amber-glow);
    margin-top: 12px;
    position: relative;
    z-index: 3;
}

/* Banner Pixel Scenes */
.banner-pixel-scene {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 1;
}

/* Dawn Scene */
.dawn-banner {
    background: linear-gradient(to bottom, #1a0a2e 0%, #3a1f5e 40%, #d4783a 80%, #f5a623 100%);
}

.pixel-skyline {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 150px;
}

.pixel-building {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: 40px;
    height: var(--h);
    background: var(--twilight-indigo);
    box-shadow:
        inset 4px 0 0 var(--pixel-outline),
        inset -4px 0 0 var(--pixel-outline),
        inset 0 4px 0 var(--pixel-outline);
    image-rendering: pixelated;
}

.pixel-building.tall {
    width: 48px;
}

.pixel-building::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 8px;
    height: 8px;
    background: var(--amber-glow);
    box-shadow:
        16px 0 0 var(--amber-glow),
        0 16px 0 var(--saffron-thread),
        16px 16px 0 var(--amber-glow),
        0 32px 0 var(--amber-glow),
        16px 32px 0 transparent;
    image-rendering: pixelated;
}

.pixel-antenna {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: 4px;
    height: var(--h);
    background: var(--pixel-outline);
}

.pixel-antenna::before {
    content: '';
    position: absolute;
    top: 0;
    left: -4px;
    width: 12px;
    height: 4px;
    background: var(--burnt-coral);
    animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.pixel-sun {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 0;
    image-rendering: pixelated;
}

.dawn-sun {
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--amber-glow);
    box-shadow:
        0 -4px 0 var(--burnt-coral),
        4px 0 0 var(--burnt-coral),
        -4px 0 0 var(--burnt-coral),
        0 4px 0 var(--saffron-thread),
        8px -4px 0 rgba(245, 166, 35, 0.4),
        -8px -4px 0 rgba(245, 166, 35, 0.4),
        12px 0 0 rgba(245, 166, 35, 0.2),
        -12px 0 0 rgba(245, 166, 35, 0.2);
}

/* Morning Scene */
.morning-banner {
    background: linear-gradient(to bottom, #3a1f5e 0%, #d4783a 30%, #f5a623 60%, #faf3e8 100%);
}

.morning-sun {
    top: 40px;
    right: 20%;
    width: 48px;
    height: 48px;
    background: var(--amber-glow);
    box-shadow:
        0 -8px 0 rgba(245, 166, 35, 0.5),
        8px 0 0 rgba(245, 166, 35, 0.5),
        -8px 0 0 rgba(245, 166, 35, 0.5),
        0 8px 0 rgba(245, 166, 35, 0.5),
        8px -8px 0 rgba(245, 166, 35, 0.3),
        -8px -8px 0 rgba(245, 166, 35, 0.3),
        8px 8px 0 rgba(245, 166, 35, 0.3),
        -8px 8px 0 rgba(245, 166, 35, 0.3);
}

.pixel-cloud {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: 48px;
    height: 16px;
    background: rgba(250, 243, 232, 0.7);
    image-rendering: pixelated;
}

.pixel-cloud::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 8px;
    width: 32px;
    height: 8px;
    background: rgba(250, 243, 232, 0.7);
}

.pixel-cloud::after {
    content: '';
    position: absolute;
    top: -16px;
    left: 16px;
    width: 16px;
    height: 8px;
    background: rgba(250, 243, 232, 0.5);
}

/* Midday Scene */
.midday-banner {
    background: linear-gradient(to bottom, #f5a623 0%, #faf3e8 50%, #f5a623 100%);
}

.pixel-market {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
}

.market-stall {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: 60px;
    height: 50px;
    background: var(--saffron-thread);
    image-rendering: pixelated;
}

.market-stall::before {
    content: '';
    position: absolute;
    top: -20px;
    left: -8px;
    width: 76px;
    height: 20px;
    background: var(--burnt-coral);
    clip-path: polygon(10% 100%, 0% 0%, 100% 0%, 90% 100%);
}

.pixel-figure {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: 12px;
    height: 24px;
    background: var(--warm-charcoal);
    image-rendering: pixelated;
    animation: figure-walk 2s ease-in-out infinite;
    animation-delay: var(--delay);
}

.pixel-figure::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 2px;
    width: 8px;
    height: 8px;
    background: var(--cream-white);
    border-radius: 0;
}

@keyframes figure-walk {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(8px); }
}

/* Afternoon Scene */
.afternoon-banner {
    background: linear-gradient(to bottom, #faf3e8 0%, #f5a623 30%, #d4783a 70%, #e8573a 100%);
}

.pixel-park {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
}

.pixel-tree {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: 8px;
    height: 40px;
    background: var(--warm-charcoal);
}

.pixel-tree::before {
    content: '';
    position: absolute;
    top: -32px;
    left: -12px;
    width: 32px;
    height: 32px;
    background: #3a6b35;
    box-shadow:
        0 -8px 0 #2d5a2a,
        -8px 8px 0 #4a8b45,
        8px 8px 0 #4a8b45;
    image-rendering: pixelated;
}

.pixel-bench {
    position: absolute;
    bottom: 4px;
    left: var(--x);
    width: 32px;
    height: 8px;
    background: var(--saffron-thread);
}

.pixel-bench::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    width: 32px;
    height: 4px;
    background: var(--saffron-thread);
}

.pixel-bench::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 4px;
    width: 4px;
    height: 4px;
    background: var(--warm-charcoal);
    box-shadow: 20px 0 0 var(--warm-charcoal);
}

.afternoon-sun {
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: var(--saffron-thread);
    box-shadow:
        0 -4px 0 var(--amber-glow),
        4px 0 0 var(--amber-glow),
        -4px 0 0 var(--amber-glow),
        0 4px 0 var(--amber-glow);
    opacity: 0.8;
}

/* Evening Scene */
.evening-banner {
    background: linear-gradient(to bottom, #8b2252 0%, #3a1f5e 40%, #2d1b4e 70%, #1a0a2e 100%);
}

.pixel-evening-sky {
    position: absolute;
    inset: 0;
}

.pixel-star {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: 4px;
    height: 4px;
    background: var(--cream-white);
    animation: twinkle 2s ease-in-out infinite;
    animation-delay: var(--delay);
    image-rendering: pixelated;
}

.pixel-star::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 0;
    width: 4px;
    height: 4px;
    background: rgba(245, 239, 230, 0.5);
}

.pixel-star::after {
    content: '';
    position: absolute;
    top: 0;
    left: -4px;
    width: 4px;
    height: 4px;
    background: rgba(245, 239, 230, 0.5);
}

@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.pixel-lamppost {
    position: absolute;
    bottom: 0;
    left: var(--x);
    width: 4px;
    height: 80px;
    background: var(--pixel-outline);
}

.pixel-lamppost::before {
    content: '';
    position: absolute;
    top: 0;
    left: -6px;
    width: 16px;
    height: 8px;
    background: var(--amber-glow);
    box-shadow: 0 8px 24px rgba(245, 166, 35, 0.4);
}

/* ============================================
   Cultural Dividers
   ============================================ */
.cultural-divider {
    width: 80%;
    max-width: 600px;
    height: 16px;
    margin-top: 24px;
    position: relative;
    z-index: 3;
    image-rendering: pixelated;
}

/* Celtic knotwork pattern */
.celtic-divider {
    background: repeating-linear-gradient(
        90deg,
        var(--amber-glow) 0px,
        var(--amber-glow) 4px,
        transparent 4px,
        transparent 8px,
        var(--burnt-coral) 8px,
        var(--burnt-coral) 12px,
        transparent 12px,
        transparent 16px
    );
    border-top: 2px solid var(--amber-glow);
    border-bottom: 2px solid var(--amber-glow);
}

/* Japanese wave pattern */
.seigaiha-divider {
    background:
        radial-gradient(circle at 8px 8px, transparent 4px, var(--amber-glow) 4px, var(--amber-glow) 6px, transparent 6px),
        radial-gradient(circle at 24px 8px, transparent 4px, var(--burnt-coral) 4px, var(--burnt-coral) 6px, transparent 6px);
    background-size: 32px 16px;
}

/* Moroccan zellige pattern */
.zellige-divider {
    background:
        linear-gradient(45deg, var(--amber-glow) 25%, transparent 25%),
        linear-gradient(-45deg, var(--amber-glow) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--burnt-coral) 75%),
        linear-gradient(-45deg, transparent 75%, var(--burnt-coral) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

/* Mesoamerican step-fret pattern */
.stepfret-divider {
    background: repeating-linear-gradient(
        90deg,
        var(--amber-glow) 0px,
        var(--amber-glow) 4px,
        var(--saffron-thread) 4px,
        var(--saffron-thread) 8px,
        var(--burnt-coral) 8px,
        var(--burnt-coral) 12px,
        var(--dusky-rose) 12px,
        var(--dusky-rose) 16px
    );
    clip-path: polygon(
        0% 50%, 4% 0%, 8% 50%, 12% 0%, 16% 50%, 20% 0%,
        24% 50%, 28% 0%, 32% 50%, 36% 0%, 40% 50%, 44% 0%,
        48% 50%, 52% 0%, 56% 50%, 60% 0%, 64% 50%, 68% 0%,
        72% 50%, 76% 0%, 80% 50%, 84% 0%, 88% 50%, 92% 0%,
        96% 50%, 100% 0%, 100% 100%,
        96% 50%, 92% 100%, 88% 50%, 84% 100%, 80% 50%, 76% 100%,
        72% 50%, 68% 100%, 64% 50%, 60% 100%, 56% 50%, 52% 100%,
        48% 50%, 44% 100%, 40% 50%, 36% 100%, 32% 50%, 28% 100%,
        24% 50%, 20% 100%, 16% 50%, 12% 100%, 8% 50%, 4% 100%,
        0% 50%
    );
}

/* ============================================
   Timeline Grid
   ============================================ */
.timeline-grid {
    display: flex;
    flex-direction: column;
    gap: var(--entry-gap);
    position: relative;
    z-index: 2;
    padding-bottom: var(--chapter-gap);
}

/* ============================================
   Timeline Entries
   ============================================ */
.timeline-entry {
    display: grid;
    grid-template-columns: 1fr 48px 1fr;
    align-items: center;
    position: relative;
}

.timeline-node {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    position: relative;
    z-index: 3;
}

.node-sprite {
    width: 24px;
    height: 24px;
    image-rendering: pixelated;
    animation: pulse 0.8s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        filter: drop-shadow(0 0 0 rgba(245, 166, 35, 0.4));
    }
    50% {
        filter: drop-shadow(0 0 8px rgba(245, 166, 35, 0.6));
    }
}

.entry-connector {
    width: 100%;
    height: 4px;
    background: repeating-linear-gradient(
        90deg,
        var(--amber-glow) 0px,
        var(--amber-glow) 4px,
        transparent 4px,
        transparent 8px
    );
    image-rendering: pixelated;
}

/* Left entries: card | connector | node */
.entry-left {
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.entry-left .entry-card {
    grid-column: 1;
    grid-row: 1;
}

.entry-left .entry-connector {
    grid-column: 2;
    grid-row: 1;
    justify-self: stretch;
}

.entry-left .timeline-node {
    grid-column: 3;
    grid-row: 1;
    justify-self: start;
}

/* Right entries: node | connector | card */
.entry-right {
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.entry-right .timeline-node {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
}

.entry-right .entry-connector {
    grid-column: 2;
    grid-row: 1;
    justify-self: stretch;
}

.entry-right .entry-card {
    grid-column: 3;
    grid-row: 1;
}

/* Visible state */
.timeline-entry.visible {
    opacity: 1;
    transform: translateX(0);
}

/* ============================================
   Entry Cards
   ============================================ */
.entry-card {
    background: var(--desert-sand);
    padding: 24px;
    position: relative;
    /* Pixel-art border via box-shadow stacking */
    box-shadow:
        0 0 0 2px var(--amber-glow),
        2px 2px 0 2px var(--pixel-outline),
        -2px -2px 0 0px var(--pixel-outline),
        4px 4px 0 0px var(--pixel-outline);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.entry-card:hover {
    transform: translateY(-4px);
    box-shadow:
        0 0 0 2px var(--amber-glow),
        2px 2px 0 2px var(--amber-glow),
        -2px -2px 0 0px var(--amber-glow),
        4px 4px 0 0px var(--amber-glow),
        0 8px 24px rgba(26, 10, 46, 0.2);
}

.entry-timestamp {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--faded-plum);
    display: block;
    margin-bottom: 8px;
}

.entry-title {
    font-family: 'Fira Sans', sans-serif;
    font-weight: 700;
    font-size: 22px;
    color: var(--warm-charcoal);
    margin-bottom: 12px;
    line-height: 1.3;
}

.entry-body {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 1.7;
    color: var(--faded-plum);
}

/* ============================================
   Timeline End Marker
   ============================================ */
.timeline-end {
    text-align: center;
    padding: 80px 20px;
    position: relative;
    z-index: 2;
}

.end-marker {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.end-sprite {
    image-rendering: pixelated;
    animation: pulse 0.8s ease-in-out infinite;
}

.end-text {
    font-family: 'Silkscreen', 'Fira Sans', sans-serif;
    font-size: 24px;
    color: var(--cream-white);
    text-shadow: 2px 2px 0 var(--pixel-outline);
    margin-bottom: 8px;
}

.end-timestamp {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--amber-glow);
}

/* ============================================
   Responsive: Mobile < 768px
   ============================================ */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
        --entry-gap: 60px;
        --chapter-gap: 100px;
    }

    .sidebar-minimap {
        display: none;
    }

    .mobile-progress-bar {
        display: block;
    }

    .timeline-container {
        margin-left: auto;
        margin-right: auto;
        padding: 0 16px 60px;
        max-width: 100%;
    }

    /* Move spine to left edge */
    .timeline-container::before {
        left: 24px;
        transform: none;
    }

    /* Collapse to single column */
    .timeline-entry {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 0;
    }

    .entry-left,
    .entry-right {
        transform: translateX(-20px);
    }

    .entry-left .timeline-node,
    .entry-right .timeline-node {
        order: 1;
        flex-shrink: 0;
        width: 48px;
    }

    .entry-left .entry-connector,
    .entry-right .entry-connector {
        order: 2;
        width: 24px;
        flex-shrink: 0;
    }

    .entry-left .entry-card,
    .entry-right .entry-card {
        order: 3;
        flex: 1;
        min-width: 0;
    }

    .chapter-banner {
        margin-left: 0;
        width: 100%;
        min-height: 200px;
        padding: 40px 16px;
    }

    .chapter-title {
        font-size: 32px;
    }

    .entry-title {
        font-size: 18px;
    }

    .entry-body {
        font-size: 14px;
    }

    .cultural-divider {
        width: 90%;
    }
}

/* ============================================
   Responsive: Centered container fix
   ============================================ */
@media (max-width: 1100px) and (min-width: 769px) {
    .timeline-container {
        margin-left: calc(var(--sidebar-width) + 20px);
        margin-right: 20px;
        max-width: calc(100vw - var(--sidebar-width) - 40px);
    }

    .chapter-banner {
        margin-left: calc(-50vw + 50% + 10px);
        width: calc(100vw - var(--sidebar-width));
    }
}
