/* ============================================
   archaic.works - Digital Scriptorium
   Color Palette & Typography from DESIGN.md
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --parchment: #f2e8d5;
    --lampblack: #2a2118;
    --tarnished-gilt: #b8943e;
    --faded-iron-gall: #6b5c4a;
    --clay-layer: #8b7355;
    --erased-traces: #d4c5a0;
    --bedrock-dark: #1e1810;
    --vermillion-rubric: #9c3a2e;
    --wax-seal-edge: #6b2a20;
    --dark-soil: #3d2b1f;
    --ruled-line: #c4b08a;
}

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

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

body {
    font-family: 'Crimson Pro', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.2vw, 1.25rem);
    line-height: 1.75;
    color: var(--lampblack);
    background-color: var(--parchment);
    overflow-x: hidden;
    position: relative;
}

/* --- Paper Grain Texture Overlay --- */
#texture-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.04;
    mix-blend-mode: multiply;
}

/* --- Ruled Manuscript Lines --- */
#ruled-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background: repeating-linear-gradient(
        transparent,
        transparent 1.75rem,
        #c4b08a22 1.75rem,
        #c4b08a22 1.8rem
    );
}

/* --- Wax Seal Navigation --- */
#wax-seal-nav {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.wax-seal {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, var(--vermillion-rubric), var(--wax-seal-edge));
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 -1px 2px rgba(255, 255, 255, 0.1),
        0 2px 6px rgba(0, 0, 0, 0.2);
    text-decoration: none;
    transition: transform 300ms ease, box-shadow 300ms ease;
    cursor: pointer;
    position: relative;
}

.wax-seal::after {
    content: attr(data-letter);
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1rem;
    color: var(--parchment);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 -1px 0 rgba(255, 255, 255, 0.1);
}

.wax-seal:hover {
    transform: rotate(5deg) translateY(-2px);
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 -1px 2px rgba(255, 255, 255, 0.1),
        0 6px 16px rgba(0, 0, 0, 0.3);
}

/* --- Typography --- */
h1, h2, h3 {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.monospace-date {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--clay-layer);
}

em {
    font-style: italic;
}

strong {
    font-weight: 600;
}

/* --- Title Page --- */
#title-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.title-container {
    text-align: center;
    z-index: 10;
    position: relative;
}

.title-svg {
    width: clamp(320px, 80vw, 900px);
    height: auto;
    overflow: visible;
}

.title-text-stroke {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 120px;
    fill: none;
    stroke: var(--lampblack);
    stroke-width: 1.5;
    stroke-dasharray: 3000;
    stroke-dashoffset: 3000;
    animation: drawTitle 3s ease-out forwards;
}

.title-text-fill {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 120px;
    fill: var(--lampblack);
    opacity: 0;
    animation: revealTitle 800ms ease-out 2.5s forwards;
}

@keyframes drawTitle {
    to {
        stroke-dashoffset: 0;
    }
}

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

.subtitle {
    font-family: 'IM Fell English', serif;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.6rem);
    color: var(--faded-iron-gall);
    margin-top: 1.5rem;
    opacity: 0;
    animation: fadeInSubtitle 800ms ease-out 3s forwards;
}

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

/* --- Ghost Text / Palimpsest Layers --- */
.ghost-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    will-change: transform, opacity;
}

.ghost-fragment {
    position: absolute;
    font-family: 'IM Fell English', serif;
    font-size: clamp(0.85rem, 1.5vw, 1.2rem);
    color: var(--erased-traces);
    opacity: 0.15;
    mix-blend-mode: multiply;
    filter: blur(0.5px);
    transition: opacity 600ms ease, filter 600ms ease;
    pointer-events: auto;
    cursor: default;
    white-space: nowrap;
}

.ghost-fragment:hover {
    opacity: 1;
    filter: blur(0);
    color: var(--faded-iron-gall);
}

.ghost-layer-title {
    z-index: 5;
}

/* --- Strata Separator Bands --- */
.strata-separator {
    width: 100%;
    height: 120px;
    position: relative;
    background: linear-gradient(
        to bottom,
        var(--dark-soil) 0%,
        var(--clay-layer) 35%,
        var(--erased-traces) 65%,
        var(--bedrock-dark) 100%
    );
    overflow: hidden;
}

.strata-artifact {
    position: absolute;
    width: 40px;
    height: 40px;
    opacity: 0.7;
}

/* --- Manuscript Grid Layout --- */
.manuscript-section {
    position: relative;
    padding: 4rem 0;
}

.manuscript-grid {
    display: grid;
    grid-template-columns: 1fr minmax(300px, 680px) 1fr;
    gap: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

.margin-left,
.margin-right {
    position: relative;
    padding: 1rem;
}

.central-column {
    position: relative;
    z-index: 10;
}

.central-column p {
    margin-bottom: 1.5rem;
}

.central-column p:last-child {
    margin-bottom: 0;
}

/* --- Illuminated Initials --- */
.illuminated-initial-container {
    float: left;
    width: 4em;
    height: 4em;
    margin-right: 0.75rem;
    margin-bottom: 0.25rem;
    shape-outside: margin-box;
}

.illuminated-initial {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.initial-letter {
    fill: var(--tarnished-gilt);
    opacity: 0;
    transition: opacity 400ms ease;
}

.initial-letter.revealed {
    opacity: 1;
}

.initial-border {
    stroke-dasharray: 440;
    stroke-dashoffset: 440;
    transition: stroke-dashoffset 1.8s ease-out;
}

.initial-border.animate {
    stroke-dashoffset: 0;
}

.initial-inner-border {
    stroke-dasharray: 440;
    stroke-dashoffset: 440;
    transition: stroke-dashoffset 1.8s ease-out 0.3s;
}

.initial-inner-border.animate {
    stroke-dashoffset: 0;
}

.initial-ornament {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1s ease-out 1.2s;
}

.initial-ornament.animate {
    stroke-dashoffset: 0;
}

.dropcap-spacer {
    display: none;
}

/* --- Marginalia / Annotations --- */
.annotation {
    margin-bottom: 2rem;
    opacity: 0.6;
    transition: opacity 400ms ease;
    position: relative;
}

.annotation.active {
    opacity: 1;
}

.annotation-bracket {
    width: 16px;
    height: 50px;
    display: block;
    margin-bottom: 0.3rem;
}

.annotation-bracket path {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 300ms ease;
}

.annotation.active .annotation-bracket path {
    stroke-dashoffset: 0;
}

.annotation-text {
    font-family: 'IM Fell English', serif;
    font-style: italic;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--faded-iron-gall);
    transform: rotate(-0.5deg);
}

/* Inline annotations (mobile) */
.inline-annotation-trigger {
    color: var(--vermillion-rubric);
    font-family: 'Crimson Pro', serif;
    font-weight: 600;
    cursor: pointer;
}

.inline-annotation {
    display: none;
    font-family: 'IM Fell English', serif;
    font-style: italic;
    font-size: 0.9rem;
    color: var(--faded-iron-gall);
    max-height: 0;
    overflow: hidden;
    transition: max-height 400ms ease-out, opacity 300ms ease;
    opacity: 0;
}

.inline-annotation.expanded {
    display: inline;
    max-height: 200px;
    opacity: 1;
}

/* --- Masonry Artifact Gallery --- */
.masonry-gallery {
    column-count: 3;
    column-gap: 1.5rem;
    max-width: 1100px;
    margin: 3rem auto;
    padding: 0 2rem;
}

.artifact-card {
    break-inside: avoid;
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    border: 1px solid var(--faded-iron-gall);
    background: var(--parchment);
    transition: border-color 200ms ease, border-width 200ms ease;
    opacity: 0;
    transform: translateY(30px);
}

.artifact-card.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 500ms ease, transform 500ms ease, border-color 200ms ease;
}

.artifact-card:hover {
    border-color: var(--tarnished-gilt);
    border-width: 2px;
}

.artifact-image {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1rem;
}

.artifact-image svg {
    width: 100%;
    max-width: 180px;
    height: auto;
}

.artifact-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1.1rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--lampblack);
    margin-bottom: 0.3rem;
}

.artifact-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--clay-layer);
    margin-bottom: 0.75rem;
}

.artifact-desc {
    font-family: 'Crimson Pro', serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--faded-iron-gall);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 200ms ease, max-height 300ms ease;
}

.artifact-card:hover .artifact-desc {
    opacity: 1;
    max-height: 300px;
}

/* --- Colophon Section --- */
.colophon-section {
    padding-bottom: 2rem;
}

.colophon-content {
    text-align: left;
}

.colophon-meta {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--erased-traces);
    text-align: center;
}

.colophon-meta p {
    margin-bottom: 0.3rem;
}

/* --- Footer / Bedrock --- */
#footer-bedrock {
    background-color: var(--bedrock-dark);
    padding: 4rem 2rem;
    text-align: center;
}

.footer-text {
    font-family: 'IM Fell English', serif;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--erased-traces);
    margin-bottom: 1.5rem;
    opacity: 0.8;
}

.footer-mark {
    color: var(--clay-layer);
    opacity: 0.6;
}

/* --- Responsive: Tablet --- */
@media (max-width: 1200px) {
    #wax-seal-nav {
        right: 0.75rem;
    }

    .wax-seal {
        width: 38px;
        height: 38px;
    }

    .wax-seal::after {
        font-size: 0.8rem;
    }

    .manuscript-grid {
        grid-template-columns: 1fr;
        max-width: 720px;
    }

    .margin-left,
    .margin-right {
        display: none;
    }

    .inline-annotation {
        display: none;
    }

    .inline-annotation-trigger {
        cursor: pointer;
    }

    .inline-annotation.expanded {
        display: inline;
    }

    .masonry-gallery {
        column-count: 2;
    }
}

/* --- Responsive: Mobile --- */
@media (max-width: 768px) {
    #wax-seal-nav {
        right: 0.5rem;
        gap: 0.8rem;
    }

    .wax-seal {
        width: 32px;
        height: 32px;
    }

    .wax-seal::after {
        font-size: 0.7rem;
    }

    .masonry-gallery {
        column-count: 1;
        padding: 0 1rem;
    }

    .manuscript-grid {
        padding: 0 1rem;
    }

    .illuminated-initial-container {
        width: 3em;
        height: 3em;
    }

    .title-svg {
        width: 90vw;
    }

    .strata-separator {
        height: 80px;
    }

    .ghost-fragment {
        font-size: 0.75rem;
    }
}

/* --- Animations for scroll-reveal --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Utility --- */
.full-viewport {
    min-height: 100vh;
    position: relative;
}
