/* ===========================================
   diplomacy.day — Cartographic War Room
   =========================================== */

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

:root {
    --vellum: #E8E0CC;
    --carbon-ink: #1C1E17;
    --treaty-red: #8B2020;
    --survey-green: #3A4A3A;
    --cable-yellow: #C4A135;
    --briefing-dark: #2A2C26;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--vellum);
    color: var(--carbon-ink);
    font-family: 'IBM Plex Serif', serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.3vw, 1.15rem);
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
}

/* --- Coordinate Grid Underlay --- */
.coordinate-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 800ms ease;
}

.coordinate-grid.visible {
    opacity: 1;
}

.coordinate-grid.border-tension #grid-svg rect {
    fill: url(#gridLarge);
}

/* Grid pulse dots */
.grid-pulse-dot {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--treaty-red);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    animation: pulseDot 2s ease-in-out;
}

@keyframes pulseDot {
    0% { opacity: 0; transform: scale(0.5); }
    30% { opacity: 0.8; transform: scale(1.2); }
    100% { opacity: 0; transform: scale(0.5); }
}

/* --- The Red Thread --- */
.red-thread {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* --- Sections (General) --- */
.section {
    position: relative;
    z-index: 2;
    min-height: 100vh;
}

/* --- SECTION 1: The Table --- */
.section--table {
    display: grid;
    grid-template-columns: 55% 15% 30%;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    padding: 4vh 3vw;
    gap: 0;
}

.table-label {
    grid-column: 1 / 2;
    grid-row: 1;
    padding-left: 22%;
    padding-top: 15vh;
    z-index: 5;
}

.table-label__title {
    font-family: 'Stint Ultra Expanded', serif;
    font-size: clamp(1.8rem, 4vw, 4.5rem);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--carbon-ink);
    white-space: nowrap;
    overflow: hidden;
    line-height: 1.2;
}

.table-label__coords {
    display: block;
    font-family: 'Inconsolata', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--survey-green);
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 600ms ease 1200ms;
}

.table-label__coords.visible {
    opacity: 1;
}

.table-panel {
    position: relative;
    z-index: 3;
}

.table-panel--left {
    grid-column: 1 / 2;
    grid-row: 2;
    background: rgba(232, 224, 204, 0.85);
    border: 1px solid rgba(58, 74, 58, 0.2);
    padding: 3rem 2.5rem;
    margin-top: 4vh;
    transform: translateX(-110%);
    transition: transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 2px 2px 0 rgba(42, 44, 38, 0.2);
}

.table-panel--left.visible {
    transform: translateX(0);
}

.table-panel--right {
    grid-column: 3 / 4;
    grid-row: 1 / 3;
    background: rgba(232, 224, 204, 0.65);
    border: 1px solid rgba(58, 74, 58, 0.15);
    padding: 2.5rem 2rem;
    margin-top: 12vh;
    transform: translateX(110%);
    transition: transform 600ms cubic-bezier(0.22, 1, 0.36, 1) 400ms;
    box-shadow: 2px 2px 0 rgba(42, 44, 38, 0.2);
}

.table-panel--right.visible {
    transform: translateX(0);
}

.panel-text {
    max-width: 58ch;
    margin-bottom: 1.5rem;
    font-weight: 300;
}

/* --- Stamps --- */
.stamp {
    display: inline-block;
    font-family: 'Inconsolata', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.2em 0.6em;
    border: 1px solid var(--cable-yellow);
    color: var(--cable-yellow);
    transform: rotate(2deg);
    position: relative;
    margin-bottom: 1.5rem;
    background: rgba(196, 161, 53, 0.05);
}

.stamp::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
    pointer-events: none;
}

.stamp--cable {
    position: absolute;
    top: -0.5rem;
    right: 1rem;
}

.dispatch-header .stamp--cable {
    position: relative;
    top: auto;
    right: auto;
    float: right;
}

/* --- Annotations --- */
.annotation {
    display: block;
    font-family: 'Inconsolata', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--survey-green);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

/* --- Redaction --- */
.redaction-block {
    background: var(--briefing-dark);
    padding: 0.8rem 1.2rem;
    margin: 1.5rem 0;
    position: relative;
    overflow: hidden;
}

.redaction-block::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.15'/%3E%3C/svg%3E");
    pointer-events: none;
}

.redacted-text {
    font-family: 'Inconsolata', monospace;
    font-size: 0.7rem;
    color: rgba(232, 224, 204, 0.15);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.redaction-inline {
    background: var(--briefing-dark);
    color: var(--briefing-dark);
    padding: 0.1em 0.3em;
    position: relative;
    cursor: default;
}

.redaction-inline::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='30'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='30' filter='url(%23n)' opacity='0.12'/%3E%3C/svg%3E");
    pointer-events: none;
}

/* --- Dispatch Sections --- */
.section--dispatch {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0 2vw;
    padding: 8vh 3vw;
    min-height: 100vh;
    align-content: center;
}

.dispatch--left .dispatch-header,
.dispatch--left .dispatch-body {
    grid-column: 1 / 8;
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity 500ms ease, transform 500ms ease;
}

.dispatch--left .dispatch-margin {
    grid-column: 9 / 13;
}

.dispatch--right .dispatch-header,
.dispatch--right .dispatch-body {
    grid-column: 4 / 13;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 500ms ease, transform 500ms ease;
}

.dispatch--right .dispatch-margin--left {
    grid-column: 1 / 4;
    grid-row: 1 / 3;
}

.section--dispatch.in-view .dispatch-header,
.section--dispatch.in-view .dispatch-body {
    opacity: 1;
    transform: translateX(0);
}

.dispatch-header {
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(58, 74, 58, 0.25);
    margin-bottom: 2rem;
    position: relative;
}

.dispatch-date {
    font-family: 'Inconsolata', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--survey-green);
    display: block;
    margin-top: 0.5rem;
}

.dispatch-routing {
    font-family: 'Inconsolata', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--survey-green);
    opacity: 0.7;
    display: block;
    margin-top: 0.25rem;
}

.dispatch-title {
    font-family: 'Stint Ultra Expanded', serif;
    font-size: clamp(1.8rem, 4vw, 4.5rem);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--carbon-ink);
    margin-bottom: 2rem;
    line-height: 1.2;
}

.dispatch-text {
    max-width: 58ch;
    margin-bottom: 1.5rem;
    font-weight: 300;
}

/* Stamp animation on scroll */
.section--dispatch .stamp--cable {
    opacity: 0;
    transform: rotate(2deg) scale(0.9);
    transition: opacity 300ms ease 200ms, transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1) 200ms;
}

.section--dispatch.in-view .stamp--cable {
    opacity: 1;
    transform: rotate(2deg) scale(1);
}

/* --- Margins / Annotations --- */
.dispatch-margin {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1.5rem;
    padding: 2rem 0;
}

.margin-note {
    display: block;
    font-size: 0.75rem;
    color: var(--survey-green);
    line-height: 1.5;
}

.caveat-note {
    font-family: 'Caveat', cursive;
    font-weight: 600;
    font-size: clamp(1rem, 2vw, 1.6rem);
    color: var(--treaty-red);
    transform: rotate(-1.5deg);
    display: inline-block;
}

.caveat-text {
    font-family: 'Caveat', cursive;
    font-weight: 600;
}

.border-fragments {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* --- SECTION 5: Border Zone --- */
.section--border {
    min-height: 15vh;
    height: 20vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--vellum);
}

.border-zone-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.hatching-svg {
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1200ms ease;
}

.section--border.in-view .hatching-svg {
    opacity: 1;
}

.border-zone-content {
    position: relative;
    z-index: 3;
    text-align: center;
    padding: 0 5vw;
}

.border-inscription {
    display: block;
    font-family: 'Caveat', cursive;
    font-weight: 600;
    font-size: clamp(1.4rem, 3vw, 2.5rem);
    color: var(--treaty-red);
    text-transform: lowercase;
    letter-spacing: 0.05em;
    transform: rotate(-1deg);
}

.border-inscription--sub {
    font-size: clamp(0.9rem, 1.8vw, 1.4rem);
    opacity: 0.7;
    margin-top: 0.5rem;
    transform: rotate(-2deg);
}

.border-line-fragments {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

/* --- SECTION 6: The Archive --- */
.section--archive {
    background: var(--briefing-dark);
    padding: 8vh 3vw;
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
}

.archive-strip {
    height: 8vh;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(58, 74, 58, 0.3);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 400ms ease, transform 400ms ease, height 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.archive-strip[data-index="1"],
.archive-strip[data-index="3"] {
    transform: translateX(30px);
}

.archive-strip.in-view {
    opacity: 1;
    transform: translateX(0);
}

.archive-strip.expanded {
    height: 20vh;
}

.archive-tab {
    display: inline-block;
    font-family: 'Inconsolata', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--briefing-dark);
    background: var(--cable-yellow);
    padding: 0.3em 0.8em;
    margin-right: 2rem;
    flex-shrink: 0;
    min-width: 6rem;
    text-align: center;
}

.archive-strip-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-right: 2rem;
}

.archive-label {
    font-family: 'IBM Plex Serif', serif;
    font-weight: 400;
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    color: var(--vellum);
    letter-spacing: 0.02em;
}

.archive-expanded {
    max-height: 0;
    overflow: hidden;
    transition: max-height 300ms ease, opacity 300ms ease;
    opacity: 0;
}

.archive-strip.expanded .archive-expanded {
    max-height: 20vh;
    opacity: 1;
    margin-top: 0.75rem;
}

.archive-expanded .dispatch-text {
    color: rgba(232, 224, 204, 0.7);
    font-size: 0.85rem;
    font-weight: 300;
}

/* --- Marginal Navigation --- */
.marginal-nav {
    position: fixed;
    left: 0.8vw;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.marginal-nav__link {
    font-family: 'Inconsolata', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--survey-green);
    text-decoration: none;
    opacity: 0.4;
    transition: opacity 300ms ease, color 300ms ease;
    writing-mode: horizontal-tb;
    white-space: nowrap;
    padding: 0.2em 0;
}

.marginal-nav__link:hover,
.marginal-nav__link.active {
    opacity: 1;
    color: var(--treaty-red);
}

/* --- Border Zone Grid Tension Override --- */
.coordinate-grid.border-tension {
    /* Additional styling handled in JS via SVG pattern manipulation */
}

/* --- Utility / Responsive --- */
@media (max-width: 768px) {
    .section--table {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        padding: 3vh 5vw;
    }

    .table-label {
        grid-column: 1;
        grid-row: 1;
        padding-left: 5%;
        padding-top: 10vh;
    }

    .table-panel--left {
        grid-column: 1;
        grid-row: 2;
    }

    .table-panel--right {
        grid-column: 1;
        grid-row: 3;
        margin-top: 2vh;
    }

    .section--dispatch {
        grid-template-columns: 1fr;
        padding: 6vh 5vw;
    }

    .dispatch--left .dispatch-header,
    .dispatch--left .dispatch-body,
    .dispatch--right .dispatch-header,
    .dispatch--right .dispatch-body {
        grid-column: 1;
    }

    .dispatch-margin,
    .dispatch-margin--left {
        grid-column: 1;
    }

    .marginal-nav {
        display: none;
    }

    .dispatch-title {
        font-size: clamp(1.2rem, 5vw, 2rem);
    }
}
