/* =========================================================================
   storiographer.net  -- the architecture of narrative
   MUJI-inspired narrative cartography
   Z-pattern reading flow, slab-serif, sunset-warm palette,
   hover-lift, geometric-abstract story maps, circuit motifs.
   ========================================================================= */

:root {
    /* Palette (from DESIGN.md) */
    --bg-parchment:    #F5EBD8;
    --bg-margin:       #F0E0C8;
    --text-umber:      #4A3728;
    --text-brown:      #5C4A3A;
    --copper:          #B87333;
    --gold:            #8B6914;
    --terracotta:      #C4725A;
    --deep-ground:    #2C1E14;
    --sienna-mist:     #9E7B5B;
    --emboss-dark:     #D4A864;
    --emboss-light:    #F5D69C;
    --dot-color:       #D9C9A8;

    /* Typography */
    --font-head:  "Zilla Slab", Georgia, serif;
    --font-body:  "Source Sans 3", "Inter", system-ui, sans-serif;
    --font-mono:  "IBM Plex Mono", ui-monospace, "Menlo", monospace;

    /* Layout */
    --margin-col-w:    80px;
    --max-content:     1200px;
    --grid-gutter:     24px;
    --section-pad-y:   8vh;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.015em;
    color: var(--text-brown);
    background-color: var(--bg-parchment);
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* ---------- Fixed dot-grid texture (does not scroll) ---------- */
.dot-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, var(--dot-color) 1px, transparent 1.4px);
    background-size: 48px 48px;
    background-position: 0 0;
    opacity: 0;
    transition: opacity 500ms ease;
}
.dot-grid.is-visible {
    opacity: 0.5;
}

/* ---------- Field Journal Margin ---------- */
.field-margin {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--margin-col-w);
    height: 100vh;
    background: var(--bg-margin);
    border-right: 1px solid var(--emboss-dark);
    z-index: 2;
    padding: 32px 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.margin-mark {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--sienna-mist);
    letter-spacing: 0.08em;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    opacity: 0.85;
}
.margin-mark::before {
    content: attr(data-mark);
    font-family: var(--font-head);
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--gold);
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}
.margin-time { color: var(--gold); }
.margin-tick { color: var(--copper); margin: 2px 0; }

/* ---------- Index Tabs (right edge) ---------- */
.index-tabs {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 5;
    pointer-events: auto;
}

.tab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 24px;
    background: var(--bg-margin);
    border-left: 2px solid var(--terracotta);
    border-top: 1px solid var(--emboss-dark);
    border-bottom: 1px solid var(--emboss-dark);
    color: var(--gold);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-decoration: none;
    box-shadow: 0 1px 4px rgba(44, 30, 20, 0.08);
    transition: transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 200ms ease, background 200ms ease;
}
.tab:hover {
    transform: translateY(-2px) translateX(-2px);
    box-shadow: 0 4px 10px rgba(44, 30, 20, 0.15);
    background: var(--emboss-light);
}
.tab.is-active {
    background: var(--terracotta);
    color: var(--bg-parchment);
    border-left-color: var(--gold);
}

/* ---------- Page wrapper ---------- */
.page {
    position: relative;
    z-index: 1;
    padding-left: var(--margin-col-w);
    padding-right: 60px; /* room for tabs */
    max-width: 100%;
}

/* ---------- HERO ---------- */
.hero {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--section-pad-y) 6vw;
    text-align: center;
    position: relative;
}

.hero-title {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 6rem);
    color: var(--text-umber);
    letter-spacing: 0.03em;
    line-height: 1.05;
    margin: 0 0 1.4rem 0;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}
.hero-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 600ms ease, transform 600ms ease;
}
.hero-title.is-typed .letter {
    opacity: 1;
    transform: translateY(0);
}

.hero-subtitle {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--sienna-mist);
    letter-spacing: 0.06em;
    margin: 0 0 2.4rem 0;
    opacity: 0;
    transition: opacity 600ms ease;
}
.hero-subtitle.is-visible { opacity: 1; }

.hero-rule {
    width: min(80vw, 720px);
    height: 2px;
    background: transparent;
    position: relative;
    margin: 0 auto 3rem auto;
    overflow: hidden;
}
.hero-rule .rule-fill {
    display: block;
    width: 0;
    height: 100%;
    margin: 0 auto;
    background: var(--copper);
    transition: width 800ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.hero-rule.is-drawn .rule-fill { width: 100%; }

.scroll-chevron {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    animation: chevron-pulse 2.4s ease-in-out infinite;
    opacity: 0.85;
}
@keyframes chevron-pulse {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.6; }
    50%      { transform: translateX(-50%) translateY(8px); opacity: 1; }
}

/* ---------- Chapter Dividers ---------- */
.chapter-divider {
    width: 100%;
    padding: 6vh 6vw;
    text-align: center;
}
.chapter-number {
    font-family: var(--font-head);
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--gold);
    letter-spacing: 0.18em;
    margin-bottom: 1rem;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 500ms ease, transform 500ms ease;
}
.chapter-divider.is-visible .chapter-number {
    opacity: 1;
    transform: translateY(0);
}

.embossed-rule {
    width: min(72vw, 900px);
    margin: 0 auto;
    height: 2px;
    border-top: 1px solid var(--emboss-dark);
    border-bottom: 1px solid var(--emboss-light);
    background: transparent;
    position: relative;
    overflow: hidden;
}
.embossed-rule .rule-inner {
    display: block;
    width: 0;
    height: 100%;
    background: var(--copper);
    transition: width 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.chapter-divider.is-visible .embossed-rule .rule-inner { width: 100%; }

/* ---------- Z-Pattern Sections ---------- */
.z-section {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    column-gap: var(--grid-gutter);
    row-gap: var(--grid-gutter);
    align-items: stretch;
    padding: var(--section-pad-y) 6vw;
    position: relative;
}

/* Z-odd: text top-left, figure bottom-right */
.z-section.z-odd .z-text-tl {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    justify-self: start;
    align-self: start;
}
.z-section.z-odd .z-figure-br {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    justify-self: end;
    align-self: end;
}

/* Z-even: figure bottom-left, text top-right */
.z-section.z-even .z-figure-bl {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    justify-self: start;
    align-self: end;
}
.z-section.z-even .z-text-tr {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    justify-self: end;
    align-self: start;
    text-align: right;
}

.z-text {
    max-width: 460px;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transition-delay: 0ms;
}
.z-section.is-visible .z-text {
    opacity: 1;
    transform: translateY(0);
}

.z-figure {
    margin: 0;
    width: clamp(260px, 32vw, 420px);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transition-delay: 100ms;
}
.z-section.is-visible .z-figure {
    opacity: 1;
    transform: translateY(0);
}

.eyebrow {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--sienna-mist);
    letter-spacing: 0.12em;
    text-transform: lowercase;
    margin-bottom: 1.2rem;
}

.z-heading {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4rem);
    color: var(--text-umber);
    letter-spacing: 0.03em;
    line-height: 1.15;
    margin: 0 0 1.4rem 0;
}

.z-body {
    font-family: var(--font-body);
    font-weight: 300;
    color: var(--text-brown);
    margin: 0 0 1.1rem 0;
}
.z-body:last-child { margin-bottom: 0; }

.figure-caption {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--sienna-mist);
    letter-spacing: 0.08em;
    margin-top: 0.6rem;
    text-align: center;
}

.story-map {
    width: 100%;
    height: auto;
    display: block;
    background: transparent;
    transition: transform 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.z-figure:hover .story-map {
    transform: translateY(-4px);
}

/* ---------- Circuit Interludes ---------- */
.circuit-interlude {
    height: 20vh;
    min-height: 140px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6vw;
}
.circuit-interlude .circuit {
    width: 100%;
    height: 100%;
    max-height: 200px;
    overflow: visible;
}
.circuit-trace {
    fill: none;
    stroke: var(--copper);
    stroke-opacity: 0.4;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 2400;
    stroke-dashoffset: 2400;
    transition: stroke-dashoffset 1200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.circuit-interlude.is-visible .circuit-trace {
    stroke-dashoffset: 0;
}
.circuit-node {
    fill: var(--copper);
    fill-opacity: 0.55;
    transform-origin: center;
    transform-box: fill-box;
    transform: scale(0);
    transition: transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.circuit-interlude.is-visible .circuit-node {
    transform: scale(1);
}
.circuit-interlude.is-visible .circuit-node:nth-of-type(1) { transition-delay: 200ms; }
.circuit-interlude.is-visible .circuit-node:nth-of-type(2) { transition-delay: 400ms; }
.circuit-interlude.is-visible .circuit-node:nth-of-type(3) { transition-delay: 600ms; }
.circuit-interlude.is-visible .circuit-node:nth-of-type(4) { transition-delay: 800ms; }
.circuit-interlude.is-visible .circuit-node:nth-of-type(5) { transition-delay: 1000ms; }
.circuit-interlude.is-visible .circuit-node:nth-of-type(6) { transition-delay: 1200ms; }

/* ---------- Footer ---------- */
.page-footer {
    background: var(--deep-ground);
    color: var(--bg-parchment);
    min-height: 100vh;
    padding: 10vh 6vw;
    display: flex;
    align-items: center;
    justify-content: center;
}

.footer-inner {
    width: 100%;
    max-width: 900px;
    text-align: center;
}

.footer-heading {
    font-family: var(--font-head);
    font-weight: 500;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    color: var(--emboss-light);
    letter-spacing: 0.05em;
    margin: 0 0 4vh 0;
}

.footer-map-wrap {
    margin: 0 auto 4vh auto;
    max-width: 540px;
}
.footer-map {
    width: 100%;
    height: auto;
}

.footer-meta {
    border-top: 1px solid var(--copper);
    padding-top: 2.4rem;
    margin-top: 2.4rem;
}
.footer-domain {
    font-family: var(--font-head);
    font-weight: 500;
    font-size: 1rem;
    color: var(--emboss-light);
    letter-spacing: 0.08em;
    margin: 0 0 0.6rem 0;
}
.footer-copy {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--sienna-mist);
    letter-spacing: 0.08em;
    margin: 0;
}
.copy-mark, .copy-year { color: var(--copper); }

/* ---------- Floating Index Card ---------- */
.index-card {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 200px;
    min-height: 100px;
    background: var(--bg-margin);
    border: 1px solid var(--emboss-dark);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(44, 30, 20, 0.1);
    padding: 14px 16px;
    z-index: 10;
    transition: transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 200ms ease;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.index-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 16px rgba(44, 30, 20, 0.15);
}
.card-label {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--sienna-mist);
    letter-spacing: 0.12em;
    text-transform: lowercase;
}
.card-title {
    font-family: var(--font-head);
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-umber);
    letter-spacing: 0.02em;
    line-height: 1.25;
    transition: opacity 200ms ease;
}
.card-progress {
    width: 100%;
    height: 3px;
    background: var(--emboss-light);
    border-radius: 2px;
    overflow: hidden;
}
.card-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--terracotta);
    transition: width 160ms linear;
}
.card-meta {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--gold);
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    gap: 6px;
}
.card-dot { color: var(--copper); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    :root {
        --margin-col-w: 0px;
    }
    .field-margin {
        position: static;
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
        padding: 14px 16px;
        border-right: none;
        border-bottom: 1px solid var(--emboss-dark);
        gap: 12px;
    }
    .margin-mark { flex-direction: row; gap: 6px; }
    .margin-mark::before { margin-bottom: 0; }

    .index-tabs { display: none; }

    .page {
        padding-left: 0;
        padding-right: 0;
    }

    .z-section {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        row-gap: 32px;
    }
    .z-section.z-odd .z-text-tl,
    .z-section.z-odd .z-figure-br,
    .z-section.z-even .z-text-tr,
    .z-section.z-even .z-figure-bl {
        grid-column: 1 / 2;
        justify-self: stretch;
        align-self: auto;
    }
    .z-section.z-odd .z-text-tl  { grid-row: 1 / 2; }
    .z-section.z-odd .z-figure-br{ grid-row: 2 / 3; justify-self: center; }
    .z-section.z-even .z-figure-bl { grid-row: 2 / 3; justify-self: center; }
    .z-section.z-even .z-text-tr { grid-row: 1 / 2; text-align: left; }

    .index-card {
        right: 12px;
        bottom: 12px;
        width: 170px;
    }
}

@media (max-width: 540px) {
    .index-card { width: 150px; padding: 10px 12px; }
    .card-title { font-size: 0.85rem; }
    .hero-title { letter-spacing: 0.02em; }
}
