/* ============================================================
   daitoua.quest — Diplomatic-Archival Retro
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --deep-parchment: #2c2418;
    --aged-vellum: #e8d8c0;
    --ink-black: #1a1510;
    --bone-white: #ede2d0;
    --sunset-amber: #c9a84c;
    --burnt-sienna: #a85a3a;
    --cartographic-teal: #5a8a7a;
    --faded-ink: #6e5a42;
    --shadow-umber: #1e1a12;
    --khaki: #c4a35a;
    --burnt-umber: #6e3a1a;

    --font-display: 'Zilla Slab', serif;
    --font-body: 'Source Serif 4', serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

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

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

body {
    background-color: var(--deep-parchment);
    color: var(--bone-white);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Folio Base Styles --- */
.folio {
    min-height: 80vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folio__inner {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: clamp(2rem, 6vw, 5rem) clamp(1.5rem, 4vw, 3rem);
    position: relative;
}

/* --- Paper Surface for Dispatch Folios --- */
.folio__paper {
    background-color: var(--aged-vellum);
    position: relative;
    filter: url(#paperGrain);
    box-shadow: inset 0 0 80px rgba(30, 26, 18, 0.12);
}

.folio__paper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 15% 25%, rgba(160, 130, 90, 0.06) 0%, transparent 40px),
        radial-gradient(circle at 70% 60%, rgba(160, 130, 90, 0.06) 0%, transparent 60px),
        radial-gradient(circle at 40% 80%, rgba(160, 130, 90, 0.06) 0%, transparent 50px),
        radial-gradient(circle at 85% 15%, rgba(160, 130, 90, 0.06) 0%, transparent 45px);
}

.folio--dispatch .folio__inner,
.folio--map .folio__inner {
    color: var(--ink-black);
}

/* --- COVER FOLIO --- */
.folio--cover {
    min-height: 100vh;
    background-color: var(--deep-parchment);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
}

.folio--cover .folio__inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Cover horizontal line */
.cover__line {
    width: 60vw;
    max-width: 600px;
    height: 1px;
    background-color: var(--sunset-amber);
    transform: scaleX(0);
    transform-origin: center;
    margin-bottom: 2rem;
    order: 2;
}

.cover__line.animate {
    animation: lineReveal 600ms ease-out 500ms forwards;
}

@keyframes lineReveal {
    to { transform: scaleX(1); }
}

/* Cover title */
.cover__title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.8rem, 7vw, 5.5rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bone-white);
    position: relative;
    order: 1;
    margin-bottom: 0;
    overflow: hidden;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.typewriter-text {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    width: 0;
    border-right: none;
}

.typewriter-text.animate {
    animation: typewrite 1200ms steps(13, end) 1100ms forwards;
}

@keyframes typewrite {
    to { width: 100%; }
}

/* Blinking cursor */
.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: var(--sunset-amber);
    margin-left: 2px;
    opacity: 0;
    vertical-align: middle;
}

.typewriter-cursor.animate {
    animation: cursorAppear 0ms 1100ms forwards, cursorBlink 500ms 2300ms 4 forwards, cursorFade 300ms 4300ms forwards;
}

@keyframes cursorAppear {
    to { opacity: 1; }
}

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

@keyframes cursorFade {
    to { opacity: 0; }
}

/* Cover subtitle */
.cover__subtitle {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    color: var(--faded-ink);
    opacity: 0;
    transform: translateY(10px);
    order: 3;
    margin-top: 1.5rem;
}

.cover__subtitle.animate {
    animation: fadeUp 600ms ease-out 2700ms forwards;
}

@keyframes fadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cover stamp watermark */
.cover__stamp {
    position: absolute;
    bottom: -40px;
    right: -20px;
    width: 120px;
    height: 120px;
    border: 2px dashed var(--sunset-amber);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(12deg);
    opacity: 0;
}

.cover__stamp.animate {
    animation: stampFade 800ms ease-out 2700ms forwards;
}

@keyframes stampFade {
    to { opacity: 0.08; }
}

.stamp__text {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--sunset-amber);
}

/* Scroll chevron */
.cover__chevron {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--sunset-amber);
    opacity: 0.5;
    animation: chevronPulse 1.5s ease-in-out infinite;
    z-index: 10;
    transition: opacity 0.5s ease;
}

.cover__chevron.hidden {
    opacity: 0;
    pointer-events: none;
}

@keyframes chevronPulse {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(5px); }
}

/* --- SECTION DIVIDERS --- */
.folio-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 0;
    background-color: var(--deep-parchment);
}

.divider__line {
    flex: 0 1 200px;
    height: 1px;
    border: none;
    background-color: rgba(201, 168, 76, 0.4);
}

.divider__ornament {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--faded-ink);
    letter-spacing: 0.08em;
    flex-shrink: 0;
}

/* --- DISPATCH FOLIOS --- */
.folio--dispatch,
.folio--map {
    background-color: var(--deep-parchment);
    padding: 2rem clamp(1rem, 3vw, 3rem);
}

.folio--dispatch .folio__paper,
.folio--map .folio__paper {
    opacity: 0;
    transition: opacity 400ms ease-out;
}

.folio--dispatch.is-visible .folio__paper,
.folio--map.is-visible .folio__paper {
    opacity: 1;
}

/* Document number */
.dispatch__docnum {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: clamp(0.75rem, 1.4vw, 0.9rem);
    letter-spacing: 0.08em;
    color: var(--faded-ink);
    margin-bottom: 0.75rem;
    overflow: hidden;
    white-space: nowrap;
    width: 0;
}

.is-visible .dispatch__docnum[data-typewrite] {
    animation: typewriteDocnum 300ms steps(12, end) 400ms forwards;
}

@keyframes typewriteDocnum {
    to { width: max-content; }
}

/* Section heading */
.dispatch__heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.6rem, 3.5vw, 2.4rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-black);
    margin-bottom: 1.5rem;
    overflow: hidden;
    white-space: nowrap;
    width: 0;
}

.is-visible .dispatch__heading[data-typewrite] {
    animation: typewriteHeading 500ms steps(30, end) 700ms forwards;
}

@keyframes typewriteHeading {
    to { width: 100%; }
}

/* Body text */
.dispatch__body {
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    position: relative;
}

.dispatch__body p[data-fadein] {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
    margin-bottom: 1.25rem;
}

.is-visible .dispatch__body p[data-fadein] {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger body paragraphs */
.is-visible .dispatch__body p[data-fadein]:nth-child(1) { transition-delay: 1200ms; }
.is-visible .dispatch__body p[data-fadein]:nth-child(2) { transition-delay: 1400ms; }
.is-visible .dispatch__body p[data-fadein]:nth-child(3) { transition-delay: 1600ms; }
.is-visible .dispatch__body p[data-fadein]:nth-child(4) { transition-delay: 1800ms; }
.is-visible .dispatch__body p[data-fadein]:nth-child(5) { transition-delay: 2000ms; }
.is-visible .dispatch__body p[data-fadein]:nth-child(6) { transition-delay: 2200ms; }

/* Block quotes */
.dispatch__quote {
    border-left: 3px solid rgba(168, 90, 58, 0.3);
    padding-left: 1.5rem;
    margin: 1.5rem 0;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

.dispatch__quote[data-fadein] {
    margin-bottom: 1.25rem;
}

.is-visible .dispatch__quote[data-fadein] {
    opacity: 1;
    transform: translateY(0);
}

.is-visible .dispatch__quote[data-fadein]:nth-child(2) { transition-delay: 1400ms; }
.is-visible .dispatch__quote[data-fadein]:nth-child(3) { transition-delay: 1600ms; }
.is-visible .dispatch__quote[data-fadein]:nth-child(4) { transition-delay: 1800ms; }

.dispatch__quote p {
    font-style: italic;
    color: var(--ink-black);
    margin-bottom: 0.5rem;
}

.dispatch__quote cite {
    font-family: var(--font-mono);
    font-size: clamp(0.75rem, 1.4vw, 0.85rem);
    color: var(--faded-ink);
    font-style: normal;
}

/* Document stamps */
.dispatch__stamp {
    position: absolute;
    width: 90px;
    height: 90px;
    border: 2px dashed var(--sunset-amber);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    z-index: 1;
    pointer-events: none;
    transition: opacity 800ms ease-out;
}

.stamp--corner {
    top: 20px;
    right: 20px;
    transform: rotate(-8deg);
}

.stamp--right {
    top: 30px;
    right: 25px;
    transform: rotate(15deg);
}

.is-visible .dispatch__stamp {
    opacity: 0.08;
}

.dispatch__stamp .stamp__text {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--sunset-amber);
}

/* Margin annotations */
.margin-note {
    position: absolute;
    left: -60px;
    font-family: var(--font-mono);
    font-style: italic;
    font-size: 0.7rem;
    color: rgba(168, 90, 58, 0.5);
    white-space: nowrap;
}

/* Redaction bars */
.redaction {
    position: relative;
    display: inline;
    cursor: pointer;
}

.redaction__bar {
    position: absolute;
    top: 0;
    left: -2px;
    right: -2px;
    bottom: 0;
    background-color: var(--ink-black);
    z-index: 2;
    transition: transform 350ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: left;
}

.redaction__text {
    color: var(--burnt-sienna);
    position: relative;
    z-index: 1;
}

.redaction.revealed .redaction__bar {
    transform: translateX(105%);
}

.redaction.revealed .redaction__text {
    box-shadow: 0 0 8px rgba(168, 90, 58, 0.3);
    animation: glowFade 1s ease-out 0.35s forwards;
}

@keyframes glowFade {
    to { box-shadow: 0 0 0 rgba(168, 90, 58, 0); }
}

/* --- MAP FOLIO --- */
.folio--map {
    min-height: 90vh;
}

.map__container {
    width: 100%;
    max-width: 700px;
    margin: 2rem auto;
    aspect-ratio: 4 / 3;
}

.map__svg {
    width: 100%;
    height: 100%;
}

.map__hub-label,
.map__label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
}

.map__hub {
    stroke-dashoffset: 260;
    transition: stroke-dashoffset 400ms ease-out;
}

.is-visible .map__hub {
    stroke-dashoffset: 0;
}

.map__line {
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 200ms ease-out;
}

.map__node {
    transform: scale(0);
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.map__label {
    opacity: 0;
    transition: opacity 300ms ease-out;
}

/* Map animation when visible — staggered via JS classes */
.is-visible .map__line.animate { stroke-dashoffset: 0; }
.is-visible .map__node.animate { transform: scale(1); }
.is-visible .map__label.animate { opacity: 1; }

/* --- INDEX FOLIO --- */
.folio--index {
    background-color: var(--deep-parchment);
    min-height: 60vh;
    padding: 3rem 1.5rem;
}

.folio--index .folio__inner {
    text-align: center;
}

.index__title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.6rem, 3.5vw, 2.4rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bone-white);
    margin-bottom: 2.5rem;
    overflow: hidden;
    white-space: nowrap;
    width: 0;
    display: inline-block;
}

.is-visible .index__title[data-typewrite] {
    animation: typewriteHeading 500ms steps(20, end) 300ms forwards;
}

.index__list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 3rem;
    text-align: left;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.index__entry {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--bone-white);
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(201, 168, 76, 0.15);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 400ms ease-out, transform 400ms ease-out, color 300ms ease;
}

.is-visible .index__entry[data-fadein] {
    opacity: 1;
    transform: translateY(0);
}

.is-visible .index__entry[data-fadein]:nth-child(1) { transition-delay: 800ms; }
.is-visible .index__entry[data-fadein]:nth-child(2) { transition-delay: 1000ms; }
.is-visible .index__entry[data-fadein]:nth-child(3) { transition-delay: 1200ms; }
.is-visible .index__entry[data-fadein]:nth-child(4) { transition-delay: 1400ms; }

.index__entry:hover {
    color: var(--sunset-amber);
}

.index__docnum {
    font-family: var(--font-mono);
    font-size: clamp(0.75rem, 1.4vw, 0.85rem);
    letter-spacing: 0.08em;
    color: var(--faded-ink);
    flex-shrink: 0;
}

.index__dots {
    flex: 1;
    border-bottom: 1px dotted rgba(201, 168, 76, 0.3);
    min-width: 20px;
    align-self: center;
    margin-bottom: 3px;
}

.index__name {
    font-family: var(--font-body);
    font-size: clamp(0.9rem, 1.6vw, 1.05rem);
    font-weight: 400;
    flex-shrink: 0;
}

.index__colophon {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(201, 168, 76, 0.2);
}

.index__meta {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--faded-ink);
    margin-bottom: 0.3rem;
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .folio__inner {
        padding: clamp(1.5rem, 4vw, 2.5rem) 1rem;
    }

    .margin-note {
        position: static;
        display: inline;
        font-family: var(--font-mono);
        font-style: italic;
        font-size: 0.7rem;
        color: rgba(168, 90, 58, 0.5);
    }

    .margin-note::before {
        content: ' (';
    }

    .margin-note::after {
        content: ') ';
    }

    .cover__stamp {
        width: 80px;
        height: 80px;
        bottom: -30px;
        right: -10px;
    }

    .dispatch__stamp {
        width: 70px;
        height: 70px;
    }

    .dispatch__stamp .stamp__text {
        font-size: 0.45rem;
    }

    .map__container {
        aspect-ratio: auto;
        min-height: 300px;
    }

    .index__entry {
        flex-wrap: wrap;
    }

    .index__dots {
        display: none;
    }
}

@media (max-width: 480px) {
    .cover__title {
        font-size: clamp(1.8rem, 10vw, 2.8rem);
    }

    .dispatch__heading {
        white-space: normal;
        width: auto !important;
        overflow: visible;
    }

    .is-visible .dispatch__heading[data-typewrite] {
        animation: simpleFadeIn 500ms ease-out 700ms forwards;
        opacity: 0;
    }

    @keyframes simpleFadeIn {
        to { opacity: 1; }
    }

    .index__title {
        white-space: normal;
        width: auto !important;
        overflow: visible;
    }

    .is-visible .index__title[data-typewrite] {
        animation: simpleFadeIn 500ms ease-out 300ms forwards;
        opacity: 0;
    }
}
