/* ============================================
   diplomatic.quest - Styles
   Cold War-era diplomatic dossier aesthetic
   ============================================ */

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

:root {
    --parchment-warm: #F0E8D8;
    --dossier-dark: #2C2A26;
    --ink-charcoal: #2A2622;
    --annotation-umber: #8C7B5E;
    --diplomatic-vermillion: #B83A2A;
    --seal-gold: #C4993A;
    --vault-black: #1A1916;
    --mist-warm: #D8CEBC;
    --stone-mid: #5C5549;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--parchment-warm);
    color: var(--ink-charcoal);
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: clamp(16px, 1.2vw, 19px);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* Halftone Grain Overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23D8CEBC'/%3E%3C/svg%3E");
    background-repeat: repeat;
    opacity: 0.03;
    mix-blend-mode: multiply;
    pointer-events: none;
    z-index: 9999;
}

/* --- Wax Seal Overlay --- */
#wax-seal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--parchment-warm);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.6s ease-out;
}

#wax-seal-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

#wax-seal {
    width: 320px;
    height: 320px;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

#wax-seal.visible {
    opacity: 1;
    transform: scale(1);
    animation: seal-pendulum 6s ease-in-out infinite;
}

#wax-seal.move-up {
    opacity: 0;
    transform: translateY(-35vh) scale(0.6);
    transition: transform 0.8s ease-out, opacity 0.6s ease-out 0.2s;
    animation: none;
}

@keyframes seal-pendulum {
    0%, 100% { transform: scale(1) rotate(-2deg); }
    50% { transform: scale(1) rotate(2deg); }
}

#seal-svg {
    width: 100%;
    height: 100%;
}

/* --- Main Layout --- */
#main-layout {
    display: grid;
    grid-template-columns: 22vw 78vw;
    min-height: 100vh;
    opacity: 0;
    transition: opacity 0.5s ease-out, grid-template-columns 0.5s ease;
}

#main-layout.visible {
    opacity: 1;
}

/* --- Dossier Margin (Left Column) --- */
#dossier-margin {
    position: fixed;
    top: 0;
    left: 0;
    width: 22vw;
    height: 100vh;
    background-color: var(--dossier-dark);
    overflow-y: auto;
    z-index: 100;
    transform: translateX(-22vw);
    transition: transform 0.6s ease-out;
    scrollbar-width: thin;
    scrollbar-color: var(--annotation-umber) var(--dossier-dark);
}

#dossier-margin.visible {
    transform: translateX(0);
}

#margin-content {
    padding: 40px 24px;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.margin-header {
    margin-bottom: 48px;
}

.seal-small {
    width: 48px;
    height: 48px;
    margin-bottom: 20px;
}

.seal-small svg {
    width: 100%;
    height: 100%;
}

/* --- Timeline --- */
#timeline {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.timeline-item {
    position: relative;
    padding: 16px 0 16px 28px;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.timeline-item:hover {
    opacity: 0.8;
}

.timeline-marker {
    position: absolute;
    left: 0;
    top: 20px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--diplomatic-vermillion);
    background-color: transparent;
    transition: background-color 0.4s ease;
}

.timeline-marker.active {
    background-color: var(--diplomatic-vermillion);
}

.timeline-line {
    position: absolute;
    left: 5px;
    top: 34px;
    width: 1px;
    height: calc(100% - 18px);
    background-color: var(--stone-mid);
    transition: background-color 0.4s ease;
}

.timeline-item:last-child .timeline-line {
    display: none;
}

.timeline-item.active .timeline-line {
    background-color: var(--diplomatic-vermillion);
}

.timeline-label {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--parchment-warm);
    margin-bottom: 4px;
}

.timeline-note {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--annotation-umber);
    line-height: 1.4;
}

/* Margin footer */
.margin-footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--annotation-umber);
}

.margin-ref {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--annotation-umber);
    line-height: 1.8;
}

/* --- Stamp Marks --- */
.stamp-mark {
    display: inline-block;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--diplomatic-vermillion);
    border: 3px solid var(--diplomatic-vermillion);
    padding: 4px 12px;
    position: relative;
    transform: rotate(-3deg);
    opacity: 0.85;
}

.stamp-mark::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border: 1px solid var(--diplomatic-vermillion);
}

.section-stamp {
    margin: -8px 0 24px 0;
}

/* --- Document Field (Right Column) --- */
#document-field {
    grid-column: 2;
    padding: 0;
}

/* --- Document Sections --- */
.doc-section {
    max-width: 680px;
    margin: 0 auto;
    padding: 60px 40px 80px;
}

.doc-section p {
    margin-bottom: 24px;
}

.doc-section p:last-child {
    margin-bottom: 0;
}

/* --- Section Breaks (Double Rules with Diamond) --- */
.section-break {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 40px;
}

.rule-double {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rule-line {
    display: block;
    width: 100%;
    height: 1px;
    background-color: var(--annotation-umber);
}

.section-break .diamond {
    font-size: 10px;
    color: var(--seal-gold);
    line-height: 1;
    flex-shrink: 0;
}

/* --- Section Headings --- */
.section-heading {
    font-family: 'Libre Bodoni', serif;
    font-weight: 700;
    font-size: clamp(20px, 2.5vw, 36px);
    letter-spacing: 0.06em;
    line-height: 1.08;
    color: var(--ink-charcoal);
    margin-bottom: 32px;
}

/* --- Reveal Animation --- */
.reveal-section {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.reveal-section.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* --- Redaction Bars --- */
.redacted {
    position: relative;
    cursor: pointer;
    color: transparent;
    display: inline;
}

.redacted::before {
    content: attr(data-hidden);
    position: absolute;
    top: 0;
    left: 0;
    color: var(--diplomatic-vermillion);
    font-weight: 600;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.redacted::after {
    content: '';
    position: absolute;
    top: 0;
    left: -2px;
    right: -2px;
    bottom: 0;
    background-color: var(--ink-charcoal);
    z-index: 2;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), backdrop-filter 0.4s ease;
    backdrop-filter: blur(8px);
}

.redacted:hover::after,
.redacted.revealed-text::after {
    opacity: 0.15;
    backdrop-filter: blur(0);
}

.redacted:hover::before,
.redacted.revealed-text::before {
    opacity: 1;
    z-index: 3;
}

/* --- Treaty Panels --- */
.treaty-panel {
    width: 100%;
    min-height: 80vh;
    background-color: var(--vault-black);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Halftone on dark panels */
.treaty-panel::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23D8CEBC'/%3E%3C/svg%3E");
    background-repeat: repeat;
    opacity: 0.05;
    mix-blend-mode: screen;
    pointer-events: none;
}

.treaty-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 40px;
}

.treaty-title {
    font-family: 'Libre Bodoni', serif;
    font-weight: 700;
    font-size: clamp(28px, 5vw, 72px);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.08;
    color: var(--parchment-warm);
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

.treaty-title.typewriter-active {
    opacity: 1;
}

.treaty-title.typewriter-done {
    opacity: 1;
}

/* Typewriter cursor */
.treaty-title .cursor {
    display: inline-block;
    width: 3px;
    height: 0.9em;
    background-color: var(--parchment-warm);
    margin-left: 4px;
    vertical-align: baseline;
    animation: blink-cursor 530ms step-end infinite;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* --- Saul Bass Geometric Shapes --- */
.bass-shapes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.bass-shape {
    position: absolute;
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.bass-shape.visible {
    opacity: 1;
}

/* Panel 1 shapes */
.bass-circle {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background-color: var(--diplomatic-vermillion);
    top: 15%;
    left: 10%;
    clip-path: polygon(0 0, 100% 0, 100% 50%, 0 50%);
    transform: rotate(15deg);
}

.bass-rect {
    width: 120px;
    height: 200px;
    background-color: var(--seal-gold);
    top: 20%;
    right: 12%;
    transform: rotate(-15deg);
    opacity: 0.7;
}

.bass-rect.visible {
    opacity: 0.7;
}

.bass-triangle {
    width: 0;
    height: 0;
    border-left: 80px solid transparent;
    border-right: 80px solid transparent;
    border-bottom: 140px solid var(--diplomatic-vermillion);
    bottom: 15%;
    right: 30%;
    transform: rotate(15deg);
}

/* Panel 2 shapes */
.bass-rect-2 {
    width: 200px;
    height: 100px;
    background-color: var(--seal-gold);
    top: 18%;
    left: 8%;
    transform: rotate(15deg);
}

.bass-circle-2 {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background-color: var(--diplomatic-vermillion);
    bottom: 20%;
    right: 10%;
}

.bass-line {
    width: 250px;
    height: 3px;
    background-color: var(--parchment-warm);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
}

/* Panel 3 shapes */
.bass-triangle-2 {
    width: 0;
    height: 0;
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    border-bottom: 180px solid var(--seal-gold);
    top: 10%;
    right: 15%;
    transform: rotate(-15deg);
}

.bass-circle-3 {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background-color: var(--diplomatic-vermillion);
    bottom: 15%;
    left: 12%;
    clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%);
}

/* --- Cipher Footer --- */
#cipher-footer {
    background-color: var(--vault-black);
    padding: 60px 40px 40px;
}

.cipher-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1px;
    max-width: 900px;
    margin: 0 auto;
    border: 1px solid var(--annotation-umber);
}

.cipher-cell {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--annotation-umber);
    padding: 12px 8px;
    text-align: center;
    border: 1px solid rgba(140, 123, 94, 0.2);
    transition: color 0.3s ease, background-color 0.3s ease;
}

.cipher-cell:hover {
    color: var(--parchment-warm);
    background-color: rgba(140, 123, 94, 0.1);
}

.cipher-footer-line {
    max-width: 900px;
    margin: 32px auto 0;
    padding-top: 24px;
    border-top: 1px solid var(--annotation-umber);
    text-align: center;
}

.cipher-footer-line span {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 9px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--stone-mid);
}

/* --- Treaty Panel Layout Collapse --- */
body.treaty-active #main-layout {
    grid-template-columns: 0vw 100vw;
}

body.treaty-active #dossier-margin {
    transform: translateX(-22vw);
    transition: transform 0.5s ease;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    #main-layout {
        grid-template-columns: 1fr;
    }

    #dossier-margin {
        position: relative;
        width: 100%;
        height: auto;
        transform: translateX(0);
        max-height: 40vh;
    }

    #dossier-margin.visible {
        transform: translateX(0);
    }

    #document-field {
        grid-column: 1;
    }

    .doc-section {
        padding: 40px 20px 60px;
    }

    .cipher-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .treaty-title {
        font-size: clamp(24px, 8vw, 48px);
    }

    .bass-shape {
        transform: scale(0.6);
    }

    .seal-small {
        display: none;
    }
}

/* --- Selection Color --- */
::selection {
    background-color: var(--diplomatic-vermillion);
    color: var(--parchment-warm);
}

/* --- Scrollbar Styling for Document Field --- */
#document-field::-webkit-scrollbar {
    width: 6px;
}

#document-field::-webkit-scrollbar-track {
    background: var(--parchment-warm);
}

#document-field::-webkit-scrollbar-thumb {
    background-color: var(--annotation-umber);
    border-radius: 3px;
}
