:root {
    --survey-cream: #F4EDE0;
    --cadastral-brown: #2B2520;
    --isoline-tan: #C8BFA9;
    --demarcation-red: #A63D2F;
    --overlay-olive: #5E6B4A;
    --hydro-blue: #4A6B82;
    --sediment-pale: #E8E0D0;
    --sediment-mid: #B8AD96;
    --altitude-ochre: #C49A3C;
    --stratum-dark: #DED5C3;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--survey-cream);
    color: var(--cadastral-brown);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.65;
    overflow-x: hidden;
    position: relative;
}

/* ============================================
   COORDINATE GRID
   ============================================ */

.coord-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.8s ease;
    background-image:
        repeating-linear-gradient(
            to right,
            rgba(200, 191, 169, 0.3) 0px,
            rgba(200, 191, 169, 0.3) 1px,
            transparent 1px,
            transparent calc(100% / 12)
        ),
        repeating-linear-gradient(
            to bottom,
            rgba(200, 191, 169, 0.15) 0px,
            rgba(200, 191, 169, 0.15) 1px,
            transparent 1px,
            transparent 80px
        );
}

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

/* ============================================
   CONTOUR FIELD
   ============================================ */

.contour-field {
    position: absolute;
    top: 20vh;
    left: 0;
    width: 100%;
    height: 400px;
    z-index: 1;
    pointer-events: none;
}

.contour-line {
    fill: none;
    stroke: var(--isoline-tan);
    stroke-width: 0.5;
    vector-effect: non-scaling-stroke;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: drawContour 3s ease forwards;
}

.contour-line:nth-child(1) { animation-delay: 0.5s; }
.contour-line:nth-child(2) { animation-delay: 0.8s; }
.contour-line:nth-child(3) { animation-delay: 1.1s; }
.contour-line:nth-child(4) { animation-delay: 1.4s; }
.contour-line:nth-child(5) { animation-delay: 1.7s; }

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

/* ============================================
   INDEX PLATE / OPENING
   ============================================ */

.index-plate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: relative;
    z-index: 2;
}

.cartouche {
    border: 2px solid var(--cadastral-brown);
    padding: 2.5rem 3rem;
    position: relative;
    margin-left: calc(100% / 12);
    max-width: calc(100% * 7 / 12);
}

.cartouche::before,
.cartouche::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-color: var(--cadastral-brown);
    border-style: solid;
}

.cartouche::before {
    top: -10px;
    left: -10px;
    border-width: 2px 0 0 2px;
}

.cartouche::after {
    top: -10px;
    right: -10px;
    border-width: 2px 2px 0 0;
}

.cartouche-inner::before,
.cartouche-inner::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-color: var(--cadastral-brown);
    border-style: solid;
}

.cartouche-inner::before {
    bottom: -10px;
    left: -10px;
    border-width: 0 0 2px 2px;
}

.cartouche-inner::after {
    bottom: -10px;
    right: -10px;
    border-width: 0 2px 2px 0;
}

.cartouche-inner {
    position: relative;
}

.cartouche-title {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--cadastral-brown);
    margin-bottom: 0.75rem;
}

.cartouche-rule {
    width: 100%;
    height: 1px;
    background-color: var(--cadastral-brown);
    margin-bottom: 0.75rem;
}

.cartouche-subtitle {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: 15px;
    color: var(--cadastral-brown);
    font-style: italic;
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.survey-main {
    position: relative;
    z-index: 2;
}

.stratum-bar {
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    height: 40px;
    background: repeating-linear-gradient(
        to bottom,
        var(--sediment-pale) 0px,
        var(--sediment-pale) 2px,
        var(--stratum-dark) 2px,
        var(--stratum-dark) 4px
    );
    display: flex;
    align-items: center;
    padding-left: calc(100% / 12 + 1.5rem);
}

.stratum-label {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--cadastral-brown);
    background-color: var(--sediment-pale);
    padding: 0 0.75rem;
}

.content-grid {
    display: grid;
    grid-template-columns: 7fr 5fr;
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    gap: 2rem;
}

.survey-col {
    position: relative;
}

.coord-crosshair {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 9px;
    color: var(--isoline-tan);
    cursor: pointer;
    display: inline-block;
    margin-bottom: 0.5rem;
    transition: transform 0.2s ease, color 0.2s ease;
    position: relative;
}

.coord-crosshair:hover {
    transform: scale(1.2);
    color: var(--demarcation-red);
}

.coord-crosshair:hover::after {
    content: attr(data-coord);
    position: absolute;
    left: 1.5em;
    top: -2px;
    font-size: 9px;
    color: var(--demarcation-red);
    white-space: nowrap;
    opacity: 1;
}

.coord-crosshair::after {
    content: attr(data-coord);
    position: absolute;
    left: 1.5em;
    top: -2px;
    font-size: 9px;
    color: var(--isoline-tan);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.coord-crosshair:hover::after {
    opacity: 1;
}

.section-title {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 600;
    font-size: clamp(1.5rem, 3.5vw, 2.8rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cadastral-brown);
    line-height: 1.15;
    margin-bottom: 1.25rem;
    text-align: left;
}

.survey-body {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.65;
    color: var(--cadastral-brown);
    margin-bottom: 1.25rem;
    text-align: left;
}

/* ============================================
   MARGINALIA RAIL
   ============================================ */

.marginalia-rail {
    position: sticky;
    top: 2rem;
    align-self: start;
    padding-left: 1rem;
    border-left: 1px solid var(--isoline-tan);
}

.margin-note {
    margin-bottom: 1.5rem;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.margin-note.visible {
    opacity: 1;
}

.margin-coord {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 10px;
    letter-spacing: 0.05em;
    color: var(--demarcation-red);
    margin-bottom: 0.2rem;
}

.margin-text {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 11px;
    line-height: 1.5;
    color: var(--sediment-mid);
}

/* ============================================
   FOLD-OUT DIAGRAMS
   ============================================ */

.fold-out-diagram {
    display: block;
    margin: 2rem 0;
    max-width: 300px;
}

.diagram-path {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 1.5s ease;
}

.diagram-path.drawn {
    stroke-dashoffset: 0;
}

.diagram-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 9px;
    fill: var(--cadastral-brown);
}

/* ============================================
   LEGEND FOOTER
   ============================================ */

.legend-footer {
    background-color: var(--sediment-pale);
    border-top: 2px solid var(--cadastral-brown);
    padding: 2.5rem 1.5rem;
    position: relative;
    z-index: 2;
}

.legend-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 2rem;
}

.legend-heading {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--cadastral-brown);
    margin-bottom: 0.75rem;
}

.legend-item {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: var(--cadastral-brown);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    display: inline-block;
    flex-shrink: 0;
}

.scale-bar {
    display: flex;
    margin-bottom: 0.5rem;
    width: 120px;
}

.scale-segment {
    height: 8px;
    flex: 1;
}

.scale-segment.dark {
    background-color: var(--cadastral-brown);
}

.scale-segment.light {
    background-color: var(--survey-cream);
    border: 1px solid var(--cadastral-brown);
}

.scale-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    color: var(--sediment-mid);
}

.north-arrow {
    display: block;
    margin-bottom: 0.75rem;
}

.legend-cite {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    line-height: 1.5;
    color: var(--sediment-mid);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .marginalia-rail {
        position: static;
        border-left: 2px solid var(--isoline-tan);
        padding: 1rem;
        margin-top: 1.5rem;
    }

    .margin-note {
        opacity: 1;
    }

    .cartouche {
        margin-left: 0;
        max-width: 100%;
    }

    .stratum-bar {
        padding-left: 1.5rem;
    }

    .legend-inner {
        grid-template-columns: 1fr;
    }
}
