/* ============================================
   DAITOUA.COM — Declassified Archive Styles
   ============================================
   Design notes (per DESIGN.md):
   - Headlines: Playfair Display" (Google Fonts) -- (institutional authority)
   - Body: Source Serif 4" (Google Fonts) -- (documentary body)
   - **Inter-document spacers:** between document sections show date stamps.
   - Scroll-triggered events use Intersection Observer with threshold 0.3 --
     elements begin their entrance when 30% visible.
   ============================================ */

/* --- Color Palette ---
   #f5efe0  Archival Parchment (base)
   #e8dcc8  Foxed Edge
   #3d2e22  Ink Brown (body text)
   #6b4c3b  Institutional Rust (UI)
   #8b6b52  Annotation Sienna (marginalia)
   #8c2f1b  Redaction Crimson (stamps)
   #2b2118  Archive Dark (deep bg)
   #c4956a  Brass Accent (active nav)
   ============================================ */

:root {
    --parchment: #f5efe0;
    --foxed: #e8dcc8;
    --ink: #3d2e22;
    --rust: #6b4c3b;
    --sienna: #8b6b52;
    --crimson: #8c2f1b;
    --archive-dark: #2b2118;
    --brass: #c4956a;
    --ease-archive: cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.85;
    color: var(--ink);
    background: var(--archive-dark);
    overflow-x: hidden;
    min-height: 100vh;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* --- Paper texture (zero-image) --- */
.paper-texture {
    position: absolute;
    inset: 0;
    background-color: var(--parchment);
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(ellipse at 20% 18%, rgba(139,107,82,0.10) 0%, transparent 35%),
        radial-gradient(ellipse at 88% 78%, rgba(139,107,82,0.12) 0%, transparent 40%),
        radial-gradient(circle at 70% 30%, rgba(140,47,27,0.04) 0%, transparent 12%);
}

.paper-texture::after {
    content: '';
    position: absolute;
    inset: 0;
    filter: url(#paperGrain);
    opacity: 0.04;
    mix-blend-mode: multiply;
    pointer-events: none;
}

.vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(107,76,59,0.18) 100%);
}

/* --- Sticky vertical year navigation --- */
.year-nav {
    position: fixed;
    left: 0;
    top: 0;
    width: 48px;
    height: 100vh;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to right, rgba(43,33,24,0.92), rgba(43,33,24,0.55) 80%, transparent);
    pointer-events: none;
}

.year-nav ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 38px;
    pointer-events: auto;
}

.year-nav li a {
    display: block;
    font-family: 'DM Mono', 'Courier New', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.2em;
    color: var(--rust);
    text-decoration: none;
    transform: rotate(-90deg);
    transform-origin: center;
    padding: 4px 8px;
    transition: color 0.6s var(--ease-archive), text-shadow 0.6s var(--ease-archive);
    white-space: nowrap;
}

.year-nav li a:hover,
.year-nav li a.active {
    color: var(--brass);
    text-shadow: 0 0 8px rgba(196, 149, 106, 0.6);
}

/* --- Opening declassification stamp --- */
.opening-stamp {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--parchment);
    padding: clamp(40px, 6vw, 80px);
    overflow: hidden;
}

.stamp-frame {
    position: relative;
    z-index: 2;
    padding: clamp(40px, 6vw, 80px) clamp(50px, 8vw, 110px);
    border: 2px solid var(--rust);
    outline: 1px solid var(--rust);
    outline-offset: 4px;
    text-align: center;
    transform: rotate(-1.2deg);
    filter: blur(12px);
    opacity: 0;
    transition: filter 3s var(--ease-archive), opacity 2s var(--ease-archive);
    background: rgba(245, 239, 224, 0.4);
}

.stamp-frame.revealed {
    filter: blur(0);
    opacity: 1;
}

.stamp-meta-top,
.stamp-meta-bottom {
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--rust);
    margin: 0;
}

.stamp-meta-top {
    margin-bottom: 28px;
}

.stamp-meta-bottom {
    margin-top: 28px;
}

.stamp-title {
    font-family: 'Playfair Display', 'Times New Roman', serif;
    font-weight: 900;
    font-size: clamp(40px, 8vw, 110px);
    line-height: 1;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--ink);
    margin: 0;
    text-indent: 0.25em;
}

.stamp-rule {
    height: 1px;
    background: var(--rust);
    margin: 20px auto 0;
    width: 70%;
    opacity: 0.7;
}

.hanko-top-right {
    position: absolute;
    top: -30px;
    right: -28px;
    transform: rotate(8deg);
    opacity: 0.78;
    filter: blur(0.3px);
    transition: opacity 0.4s var(--ease-archive), transform 0.4s var(--ease-archive);
}

.hanko-top-right:hover {
    opacity: 0.92;
    transform: rotate(8deg) scale(1.04);
}

.opening-instruction {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--rust);
    opacity: 0;
    transition: opacity 1.2s var(--ease-archive) 2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.opening-instruction.revealed {
    opacity: 0.7;
}

.cursor-blink {
    display: inline-block;
    width: 8px;
    height: 13px;
    background: transparent;
    border-right: 2px solid var(--rust);
    animation: blink 0.53s steps(2) infinite;
    vertical-align: text-bottom;
}

@keyframes blink {
    0%, 50% { border-color: var(--rust); }
    51%, 100% { border-color: transparent; }
}

/* --- Document sections --- */
.document {
    position: relative;
    width: 92%;
    max-width: 980px;
    margin: 8vh auto;
    min-height: 85vh;
    background: var(--parchment);
    padding: clamp(40px, 6vw, 80px);
    box-shadow:
        0 2px 12px rgba(67,47,35,0.15),
        0 0 1px rgba(67,47,35,0.1);
    transition: box-shadow 0.4s var(--ease-archive);
    overflow: hidden;
}

.document.is-visible {
    box-shadow:
        0 4px 20px rgba(67,47,35,0.2),
        0 0 1px rgba(67,47,35,0.12);
}

/* Document border-draw animation */
.document::before {
    content: '';
    position: absolute;
    inset: 14px;
    border: 1px solid var(--rust);
    pointer-events: none;
    z-index: 2;
    clip-path: inset(0 100% 0 0);
    transition: clip-path 0.8s var(--ease-archive);
}

.document.is-visible::before {
    clip-path: inset(0 0 0 0);
}

/* Red margin line on typescript pages */
.red-margin-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 8%;
    width: 1px;
    background: var(--crimson);
    opacity: 0;
    z-index: 1;
    transition: opacity 0.8s var(--ease-archive) 0.4s;
}

.typescript .red-margin-line {
    display: block;
}

.plate .red-margin-line {
    display: none;
}

.document.is-visible .red-margin-line {
    opacity: 0.85;
}

/* Ruling lines (ledger paper) */
.ruling-lines {
    position: absolute;
    inset: 0;
    z-index: 1;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent 27px,
        rgba(107,76,59,0.10) 27px,
        rgba(107,76,59,0.10) 28px
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.2s var(--ease-archive) 0.6s;
}

.document.is-visible .ruling-lines {
    opacity: 1;
}

/* Fold creases */
.fold-crease {
    position: absolute;
    pointer-events: none;
    z-index: 1;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.fold-crease-1 {
    background: linear-gradient(135deg,
        transparent 32%,
        rgba(107,76,59,0.07) 33%,
        rgba(107,76,59,0.04) 34%,
        transparent 35%);
}

.fold-crease-2 {
    background: linear-gradient(135deg,
        transparent 65%,
        rgba(107,76,59,0.06) 66%,
        rgba(107,76,59,0.03) 67%,
        transparent 68%);
}

/* Document stamp (corner / tilted) */
.doc-stamp {
    position: absolute;
    z-index: 5;
    border: 2px solid var(--crimson);
    outline: 1px solid var(--crimson);
    outline-offset: 3px;
    padding: 8px 14px;
    text-align: center;
    background: rgba(245, 239, 224, 0.55);
    font-family: 'DM Mono', monospace;
    color: var(--crimson);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    opacity: 0;
    transform: rotate(-3deg) scale(0.92);
    transition:
        opacity 0.6s var(--ease-archive) 0.3s,
        transform 0.8s var(--ease-archive) 0.3s;
}

.doc-stamp-corner {
    top: 40px;
    right: 40px;
}

.doc-stamp-tilted {
    top: 30px;
    right: 60px;
    transform: rotate(2.5deg) scale(0.92);
}

.document.is-visible .doc-stamp {
    opacity: 0.92;
    transform: rotate(-3deg) scale(1);
}

.document.is-visible .doc-stamp-tilted {
    transform: rotate(2.5deg) scale(1);
}

.doc-stamp .stamp-text {
    display: block;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    margin-bottom: 4px;
}

.doc-stamp .stamp-date {
    display: block;
    font-size: 9px;
    line-height: 1;
    opacity: 0.85;
}

/* Document content */
.doc-content {
    position: relative;
    z-index: 3;
    max-width: 720px;
    margin: 0 auto 0 14%;
    padding-top: clamp(60px, 8vw, 100px);
    filter: blur(4px);
    opacity: 0;
    transition:
        filter 0.6s var(--ease-archive) 0.5s,
        opacity 0.8s var(--ease-archive) 0.5s;
}

.plate-content {
    margin: 0 auto;
    padding-top: 30px;
}

.document.is-visible .doc-content {
    filter: blur(0);
    opacity: 1;
}

.doc-header {
    margin-bottom: 36px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--rust);
}

.doc-meta {
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--rust);
    margin-bottom: 18px;
}

.doc-title {
    font-family: 'Playfair Display', 'Times New Roman', serif;
    font-weight: 700;
    font-size: clamp(24px, 4.5vw, 54px);
    line-height: 1.18;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink);
    margin-bottom: 10px;
}

.doc-subtitle {
    font-family: 'Source Serif 4', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: 16px;
    color: var(--sienna);
    letter-spacing: 0.04em;
}

.doc-body {
    color: var(--ink);
}

.doc-paragraph {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 17px;
    line-height: 1.85;
    color: var(--ink);
    margin-bottom: 22px;
    text-align: justify;
    hyphens: auto;
}

.doc-paragraph em {
    font-style: italic;
    font-weight: 400;
    color: var(--ink);
}

.redacted {
    display: inline-block;
    background: var(--ink);
    color: var(--ink);
    padding: 0 8px;
    margin: 0 2px;
    border-radius: 1px;
    user-select: none;
    text-shadow: none;
    letter-spacing: 0.05em;
}

/* Typewriter strike variation */
.typewriter-strikes .doc-paragraph {
    /* Each character is left untouched globally; JS adds spans */
}

.typewriter-strikes .strike {
    display: inline-block;
}

/* Marginalia */
.marginalia {
    position: absolute;
    z-index: 4;
    width: clamp(140px, 12vw, 200px);
    font-family: 'Caveat', 'Brush Script MT', cursive;
    font-size: 16px;
    line-height: 1.3;
    color: var(--sienna);
    opacity: 0;
    transform: translateX(-30px);
    transition:
        opacity 0.4s var(--ease-archive) 1s,
        transform 0.6s var(--ease-archive) 1s;
}

.document.is-visible .marginalia {
    opacity: 0.7;
    transform: translateX(0);
}

.marginalia-1 {
    left: 2%;
    top: 38%;
    transform: translateX(-30px) rotate(-3deg);
}

.document.is-visible .marginalia-1 {
    transform: translateX(0) rotate(-3deg);
}

.marginalia-2 {
    left: 1.5%;
    top: 68%;
    transform: translateX(-30px) rotate(-5deg);
}

.document.is-visible .marginalia-2 {
    transform: translateX(0) rotate(-5deg);
}

.doc-footer {
    margin-top: 36px;
    padding-top: 18px;
    border-top: 1px dashed var(--rust);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.folio-number {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--rust);
}

.hanko-inline {
    opacity: 0.78;
    filter: blur(0.3px);
    transition: opacity 0.4s var(--ease-archive), transform 0.4s var(--ease-archive);
    display: inline-block;
}

.hanko-inline:hover {
    opacity: 0.95;
    transform: scale(1.03);
}

.hanko-end {
    opacity: 0.85;
}

/* --- Photographic plate --- */
.plate-frame {
    position: relative;
    z-index: 3;
    width: 100%;
    max-width: 720px;
    margin: 0 auto 36px;
    padding: 14px 14px 50px;
    background: var(--foxed);
    box-shadow: 0 2px 8px rgba(67,47,35,0.18);
    transform: rotate(-0.6deg);
    opacity: 0;
    transition:
        opacity 1s var(--ease-archive) 0.8s,
        transform 0.8s var(--ease-archive) 0.8s;
}

.document.is-visible .plate-frame {
    opacity: 1;
    transform: rotate(-0.6deg) translateY(0);
}

.plate-image {
    width: 100%;
    aspect-ratio: 400 / 280;
    overflow: hidden;
    background: var(--archive-dark);
    filter: sepia(0.35) saturate(0.85) contrast(0.92);
    border: 1px solid rgba(107,76,59,0.4);
}

.plate-image svg {
    width: 100%;
    height: 100%;
    display: block;
}

.plate-caption {
    margin-top: 16px;
    text-align: left;
    padding-left: 8px;
}

.caption-handwritten {
    font-family: 'Caveat', 'Brush Script MT', cursive;
    font-size: 17px;
    line-height: 1.3;
    color: var(--sienna);
    transform: rotate(-1.5deg);
    display: inline-block;
}

/* --- Interstitial spacers --- */
.interstitial {
    position: relative;
    height: 22vh;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: var(--archive-dark);
    padding: 0 8%;
}

.interstitial-rule {
    width: clamp(180px, 30%, 360px);
    height: 1px;
    border-top: 1px dashed rgba(107,76,59,0.45);
}

.interstitial-stamp {
    font-family: 'DM Mono', monospace;
    font-size: clamp(14px, 2vw, 18px);
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--rust);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.6s var(--ease-archive);
}

.interstitial.is-visible .interstitial-stamp {
    opacity: 1;
}

/* For typewriter effect — chars rendered by JS */
.typewriter-target .tw-char {
    opacity: 0;
    transition: opacity 0.06s linear;
}

.typewriter-target .tw-char.shown {
    opacity: 1;
}

.interstitial-stamp .cursor-blink {
    border-right-color: var(--rust);
    margin-left: 2px;
}

/* --- Final / closing document --- */
.document.final {
    margin-bottom: 4vh;
}

/* --- Colophon --- */
.colophon {
    position: relative;
    width: 100%;
    background: var(--archive-dark);
    padding: 60px 8% 80px;
    text-align: center;
}

.colophon-rule {
    height: 1px;
    background: rgba(196, 149, 106, 0.25);
    width: 60%;
    max-width: 480px;
    margin: 0 auto 30px;
}

.colophon-rule:last-child {
    margin: 30px auto 0;
}

.colophon-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.colophon-meta {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--rust);
    opacity: 0.7;
}

/* --- Responsive --- */
@media (max-width: 760px) {
    .year-nav {
        width: 36px;
    }
    .year-nav ul {
        gap: 28px;
    }
    .year-nav li a {
        font-size: 10px;
    }
    .document {
        width: 94%;
        padding: 50px 28px;
        margin: 6vh auto;
    }
    .doc-content {
        margin-left: 0;
        padding-left: 16px;
        padding-top: 70px;
    }
    .typescript .red-margin-line {
        left: 4%;
    }
    .marginalia {
        position: static;
        width: auto;
        opacity: 0.8;
        margin: 14px 0;
        transform: rotate(-2deg);
    }
    .document.is-visible .marginalia {
        transform: rotate(-2deg);
    }
    .doc-stamp-corner {
        top: 24px;
        right: 24px;
    }
    .doc-stamp-tilted {
        top: 20px;
        right: 30px;
    }
    .stamp-frame {
        padding: 30px 24px;
    }
    .hanko-top-right {
        top: -20px;
        right: -16px;
    }
}

@media (max-width: 480px) {
    .stamp-title {
        font-size: 38px;
        letter-spacing: 0.18em;
    }
    .doc-paragraph {
        font-size: 15px;
        text-align: left;
        hyphens: none;
    }
    .opening-instruction {
        font-size: 9px;
        letter-spacing: 0.2em;
    }
}
