/* ==========================================================================
   addrenvoy.com - Cottagecore Technical Field Guide
   Color Palette:
     Deep Background (Midnight Indigo): #0D1B2A
     Panel Background (Dark Navy): #1B2A4A
     Primary Text (Parchment Cream): #F2E8D5
     Accent Primary (Copper Ink): #D4A574
     Accent Secondary (Sage Mist): #7A9E7E
     Accent Tertiary (Dusty Rose): #C4868B
     Highlight (Warm Gold): #E8C468
   Fonts:
     Headlines: Cormorant Garamond
     Body: Source Serif 4
     Labels/Annotations: Caveat
     Code: IBM Plex Mono
   ========================================================================== */

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

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

body {
    background-color: #0D1B2A;
    color: #F2E8D5;
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: 18px;
    line-height: 1.75;
    overflow-x: hidden;
    overflow-y: hidden;
}

/* --- Linen texture overlay --- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    mix-blend-mode: overlay;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='4' height='4' fill='%23F2E8D5'/%3E%3Crect width='1' height='1' fill='%230D1B2A' opacity='0.3'/%3E%3Crect x='2' y='2' width='1' height='1' fill='%230D1B2A' opacity='0.3'/%3E%3C/svg%3E");
}

/* Diamond lattice overlay on panels */
.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28'%3E%3Cpath d='M14,0 L28,14 L14,28 L0,14 Z' fill='none' stroke='%23D4A574' stroke-width='0.5'/%3E%3C/svg%3E");
}

/* --- Progress Bar --- */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: rgba(13, 27, 42, 0.8);
    z-index: 100;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: #D4A574;
    transition: width 0.3s ease;
}

/* --- Page Indicators --- */
.page-indicators {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 100;
}

.page-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1.5px solid #D4A574;
    color: #D4A574;
    font-family: 'Cormorant Garamond', serif;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-dot:hover {
    background: rgba(212, 165, 116, 0.15);
    transform: scale(1.1);
}

.page-dot.active {
    background: #E8C468;
    border-color: #E8C468;
    color: #0D1B2A;
}

/* --- Scroll Container --- */
.scroll-container {
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar */
.scroll-container::-webkit-scrollbar {
    display: none;
}

.scroll-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* --- Panels --- */
.panel {
    position: relative;
    flex: 0 0 100vw;
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    background: radial-gradient(ellipse at center, #1B2A4A 0%, #0D1B2A 100%);
    overflow: hidden;
}

/* --- Panel Borders (double-rule) --- */
.panel-border {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    pointer-events: none;
    z-index: 5;
}

.panel-border::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 1.5px solid #D4A574;
    border-radius: 2px;
}

.panel-border::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    border: 1px solid #7A9E7E;
    border-radius: 1px;
}

/* --- Corner Ornaments --- */
.corner-ornament {
    position: absolute;
    width: 24px;
    height: 24px;
    z-index: 6;
}

.corner-ornament::before,
.corner-ornament::after {
    content: '';
    position: absolute;
    background: transparent;
}

.corner-ornament::before {
    width: 16px;
    height: 16px;
    border: 1.5px solid #D4A574;
    transform: rotate(45deg);
}

.corner-ornament::after {
    width: 8px;
    height: 8px;
    border: 1px solid #E8C468;
    transform: rotate(45deg);
    top: 4px;
    left: 4px;
}

.corner-ornament.top-left {
    top: -4px;
    left: -4px;
}

.corner-ornament.top-right {
    top: -4px;
    right: -4px;
}

.corner-ornament.bottom-left {
    bottom: -4px;
    left: -4px;
}

.corner-ornament.bottom-right {
    bottom: -4px;
    right: -4px;
}

/* --- Panel Inner (55/45 split) --- */
.panel-inner {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 2;
}

.panel-text {
    flex: 0 0 55%;
    padding: 80px 40px 80px 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow-y: auto;
}

/* Vertical divider between text and illustration */
.panel-text::after {
    content: '';
    position: absolute;
    top: 40px;
    right: 0;
    bottom: 40px;
    width: 2px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='20'%3E%3Cpath d='M1,0 Q2,5 1,10 Q0,15 1,20' fill='none' stroke='%23D4A574' stroke-width='0.8'/%3E%3C/svg%3E") repeat-y;
    opacity: 0.5;
}

.panel-illustration {
    flex: 0 0 45%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

/* --- Typography --- */
.chapter-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.5rem);
    color: #D4A574;
    letter-spacing: -0.01em;
    margin-bottom: 1.5rem;
    line-height: 1.2;
}

.chapter-num {
    display: block;
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: #7A9E7E;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.panel-text p {
    margin-bottom: 1rem;
    max-width: 540px;
}

.panel-text p + p {
    text-indent: 1.5em;
}

.annotation-text {
    font-family: 'Caveat', cursive;
    font-size: 16px;
    color: #D4A574;
    text-indent: 0 !important;
    font-style: italic;
}

/* --- Code styling --- */
code {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 14px;
    background: rgba(27, 42, 74, 0.5);
    padding: 2px 6px;
    border-radius: 2px;
    color: #E8C468;
}

/* --- Title Page (Panel 1) --- */
.title-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    position: relative;
    z-index: 2;
}

.title-cartouche {
    position: relative;
    width: min(600px, 80vw);
    text-align: center;
    margin-bottom: 40px;
}

.cartouche-border {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
}

.title-text {
    position: relative;
    z-index: 2;
    padding: 60px 40px;
}

.title-annotation {
    display: block;
    font-family: 'Caveat', cursive;
    font-size: clamp(1rem, 2.5vw, 1.3rem);
    color: #7A9E7E;
    margin-bottom: 0.5rem;
}

.title-content h1 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 7vw, 5rem);
    color: #D4A574;
    letter-spacing: -0.01em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.title-subtitle {
    font-weight: 600;
    font-size: 0.6em;
    color: #E8C468;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.title-edition {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: #F2E8D5;
    opacity: 0.7;
    line-height: 1.6;
}

.title-vignette {
    width: 200px;
}

.cottage-vignette {
    width: 100%;
    height: auto;
}

/* --- Panel Dividers --- */
.panel-divider {
    flex: 0 0 30px;
    width: 30px;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0D1B2A;
    scroll-snap-align: none;
}

.divider-svg {
    width: 30px;
    height: 100%;
}

.divider-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1.5s ease;
}

.panel-divider.revealed .divider-path {
    stroke-dashoffset: 0;
}

/* --- Page Numbers --- */
.page-number {
    position: absolute;
    bottom: 35px;
    right: 45px;
    z-index: 10;
}

.page-number span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid #D4A574;
    border-radius: 50%;
    font-family: 'Cormorant Garamond', serif;
    font-size: 12px;
    font-weight: 600;
    color: #D4A574;
    opacity: 0.6;
}

/* --- SVG Illustrations --- */
.village-map,
.journey-diagram,
.crossroads-diagram,
.archive-illustration,
.garden-gate-svg {
    width: 100%;
    max-width: 450px;
    height: auto;
}

/* Draw-in animation */
.draw-in {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    opacity: 0;
    transition: stroke-dashoffset 1.5s ease, opacity 0.5s ease;
}

.panel.in-view .draw-in {
    stroke-dashoffset: 0;
    opacity: 1;
}

/* Stagger the draw-in */
.panel.in-view .draw-in:nth-child(1) { transition-delay: 0s; }
.panel.in-view .draw-in:nth-child(2) { transition-delay: 0.1s; }
.panel.in-view .draw-in:nth-child(3) { transition-delay: 0.2s; }
.panel.in-view .draw-in:nth-child(4) { transition-delay: 0.3s; }
.panel.in-view .draw-in:nth-child(5) { transition-delay: 0.4s; }
.panel.in-view .draw-in:nth-child(6) { transition-delay: 0.5s; }
.panel.in-view .draw-in:nth-child(7) { transition-delay: 0.6s; }
.panel.in-view .draw-in:nth-child(8) { transition-delay: 0.7s; }
.panel.in-view .draw-in:nth-child(9) { transition-delay: 0.8s; }
.panel.in-view .draw-in:nth-child(10) { transition-delay: 0.9s; }
.panel.in-view .draw-in:nth-child(11) { transition-delay: 1.0s; }
.panel.in-view .draw-in:nth-child(12) { transition-delay: 1.1s; }
.panel.in-view .draw-in:nth-child(13) { transition-delay: 1.2s; }
.panel.in-view .draw-in:nth-child(14) { transition-delay: 1.3s; }
.panel.in-view .draw-in:nth-child(15) { transition-delay: 1.4s; }

/* Label fade-in (800ms delay after draw) */
.label-fade {
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

.panel.in-view .label-fade {
    opacity: 1;
    transition-delay: 1.8s;
}

/* Cottage groups inside draw-in */
.cottage-group {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}

.panel.in-view .cottage-group {
    stroke-dashoffset: 0;
}

/* --- Step List (Panel 3) --- */
.step-list {
    margin: 1.5rem 0;
}

.step {
    display: flex;
    gap: 16px;
    margin-bottom: 1.2rem;
    align-items: flex-start;
}

.step-number {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #D4A574;
    border-radius: 50%;
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: 16px;
    color: #D4A574;
    margin-top: 2px;
}

.step-content {
    flex: 1;
}

.step-content strong {
    display: block;
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.1rem, 2.5vw, 1.3rem);
    color: #D4A574;
    margin-bottom: 0.25rem;
}

.step-content p {
    font-size: 16px;
    line-height: 1.65;
    margin-bottom: 0;
    text-indent: 0 !important;
}

/* --- Rule Block (Panel 4) --- */
.rule-block {
    margin: 1.5rem 0;
}

.rule {
    display: flex;
    gap: 16px;
    margin-bottom: 1.2rem;
    align-items: flex-start;
}

.rule-marker {
    flex: 0 0 28px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 18px;
    color: #7A9E7E;
    text-align: center;
    margin-top: 2px;
}

.rule > div {
    flex: 1;
}

.rule strong {
    display: block;
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.1rem, 2.5vw, 1.3rem);
    color: #D4A574;
    margin-bottom: 0.25rem;
}

.rule p {
    font-size: 16px;
    line-height: 1.65;
    margin-bottom: 0;
    text-indent: 0 !important;
}

/* --- Code Ledger (Panel 5) --- */
.code-ledger {
    margin: 1.2rem 0;
    border: 1px solid rgba(212, 165, 116, 0.3);
    border-radius: 3px;
    overflow: hidden;
    background: rgba(13, 27, 42, 0.6);
}

.ledger-header {
    padding: 8px 16px;
    border-bottom: 1px solid rgba(212, 165, 116, 0.2);
    background: rgba(27, 42, 74, 0.4);
}

.ledger-title {
    font-family: 'Caveat', cursive;
    font-size: 14px;
    color: #D4A574;
}

.ledger-code {
    padding: 16px;
    overflow-x: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #F2E8D5;
    background: transparent;
}

.ledger-code code {
    background: none;
    padding: 0;
    font-size: 12px;
    color: #F2E8D5;
}

/* --- Gate Page (Panel 6) --- */
.gate-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    position: relative;
    z-index: 2;
    padding: 60px;
}

.gate-illustration {
    width: min(500px, 80vw);
    margin-bottom: 30px;
}

.gate-text {
    text-align: center;
    max-width: 600px;
}

.gate-text .chapter-title {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.gate-text p {
    text-align: center;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Explore Links --- */
.explore-links {
    margin-top: 2rem;
}

.explore-label {
    display: block;
    font-family: 'Caveat', cursive;
    font-size: 18px;
    color: #7A9E7E;
    margin-bottom: 1rem;
}

.explore-items {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.explore-link {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: 16px;
    color: #F2E8D5;
    text-decoration: none;
    padding: 8px 20px;
    border: 1px solid rgba(212, 165, 116, 0.4);
    border-radius: 2px;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.explore-link:hover {
    background: rgba(212, 165, 116, 0.1);
    border-color: #D4A574;
    color: #D4A574;
    transform: scale(1.05);
}

.link-chevron {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    color: #7A9E7E;
}

.closing-annotation {
    font-family: 'Caveat', cursive;
    font-size: 20px;
    color: #D4A574;
    margin-top: 2rem !important;
    opacity: 0.7;
    text-indent: 0 !important;
}

/* --- Zigzag underlines for links --- */
.explore-link {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='4'%3E%3Cpath d='M0,3 L4,1 L8,3' fill='none' stroke='%23C4868B' stroke-width='0.8'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: bottom;
    background-size: 8px 4px;
    padding-bottom: 12px;
}

/* --- Stars twinkle --- */
.star {
    animation: twinkle 3s ease-in-out infinite alternate;
}

.star:nth-child(2) { animation-delay: 0.5s; }
.star:nth-child(3) { animation-delay: 1s; }
.star:nth-child(4) { animation-delay: 1.5s; }
.star:nth-child(5) { animation-delay: 0.3s; }
.star:nth-child(6) { animation-delay: 0.8s; }
.star:nth-child(7) { animation-delay: 1.2s; }
.star:nth-child(8) { animation-delay: 0.6s; }
.star:nth-child(9) { animation-delay: 1.4s; }
.star:nth-child(10) { animation-delay: 0.2s; }
.star:nth-child(11) { animation-delay: 0.9s; }

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

/* --- Traveling envelope animation --- */
.traveling-envelope {
    animation: floatEnvelope 4s ease-in-out infinite;
}

@keyframes floatEnvelope {
    0% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-15px) rotate(2deg); }
    50% { transform: translateY(0) rotate(0deg); }
    75% { transform: translateY(15px) rotate(-2deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

/* --- Envelope icon bobbing on village map --- */
.envelope-icon {
    animation: bobEnvelope 3s ease-in-out infinite;
}

@keyframes bobEnvelope {
    0%, 100% { transform: translate(160px, 240px) rotate(0deg); }
    50% { transform: translate(160px, 234px) rotate(3deg); }
}

/* --- Panel enter animation --- */
.panel-text > *,
.gate-text > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.panel.in-view .panel-text > *,
.panel.in-view .gate-text > * {
    opacity: 1;
    transform: translateY(0);
}

.panel.in-view .panel-text > *:nth-child(1),
.panel.in-view .gate-text > *:nth-child(1) { transition-delay: 0.1s; }
.panel.in-view .panel-text > *:nth-child(2),
.panel.in-view .gate-text > *:nth-child(2) { transition-delay: 0.25s; }
.panel.in-view .panel-text > *:nth-child(3),
.panel.in-view .gate-text > *:nth-child(3) { transition-delay: 0.4s; }
.panel.in-view .panel-text > *:nth-child(4),
.panel.in-view .gate-text > *:nth-child(4) { transition-delay: 0.55s; }
.panel.in-view .panel-text > *:nth-child(5),
.panel.in-view .gate-text > *:nth-child(5) { transition-delay: 0.7s; }
.panel.in-view .panel-text > *:nth-child(6),
.panel.in-view .gate-text > *:nth-child(6) { transition-delay: 0.85s; }

/* Gate illustration animation */
.gate-content .gate-illustration {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.panel.in-view .gate-illustration {
    opacity: 1;
    transform: translateY(0);
}

/* Title page animations */
.title-content .title-cartouche {
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 1s ease, transform 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.panel.in-view .title-cartouche {
    opacity: 1;
    transform: scale(1);
}

.title-content .title-vignette {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease 0.6s, transform 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.6s;
}

.panel.in-view .title-vignette {
    opacity: 1;
    transform: translateY(0);
}

/* --- Responsive (vertical scroll below 768px) --- */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
    }

    .scroll-container {
        flex-direction: column;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
        scroll-snap-type: y mandatory;
    }

    .panel {
        flex: 0 0 auto;
        width: 100vw;
        min-height: 100vh;
        height: auto;
        scroll-snap-align: start;
    }

    .panel-inner {
        flex-direction: column-reverse;
    }

    .panel-text {
        flex: 0 0 auto;
        padding: 40px 24px;
    }

    .panel-text::after {
        display: none;
    }

    .panel-illustration {
        flex: 0 0 auto;
        padding: 30px 24px 0;
        max-height: 50vh;
    }

    .village-map,
    .journey-diagram,
    .crossroads-diagram,
    .archive-illustration,
    .garden-gate-svg {
        max-width: 300px;
    }

    .panel-divider {
        flex: 0 0 40px;
        width: 100vw;
        height: 40px;
    }

    .divider-svg {
        width: 100%;
        height: 40px;
        transform: rotate(90deg);
    }

    .page-indicators {
        bottom: 10px;
        gap: 10px;
    }

    .page-dot {
        width: 26px;
        height: 26px;
        font-size: 9px;
    }

    .title-text {
        padding: 40px 20px;
    }

    .title-content h1 {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    .gate-content {
        padding: 40px 24px;
    }

    .explore-items {
        flex-direction: column;
    }

    .explore-link {
        justify-content: center;
    }

    .step, .rule {
        gap: 12px;
    }

    .code-ledger {
        margin-left: -10px;
        margin-right: -10px;
    }

    .ledger-code {
        font-size: 11px;
        padding: 12px;
    }
}

/* --- Very small screens --- */
@media (max-width: 480px) {
    .panel-text {
        padding: 30px 16px;
    }

    .panel-border {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .title-content h1 {
        font-size: clamp(1.8rem, 10vw, 2.5rem);
    }

    .chapter-title {
        font-size: clamp(1.5rem, 5vw, 2.2rem);
    }
}
