/* ==========================================================================
   Contour plate — a seeded survey map, drawn at build time (build/contour.go)
   ========================================================================== */

/*
 * Every level is a 1px hairline in ink (currentColor). Index contours, every
 * fifth level, are a step darker, as on a printed sheet. Exactly one level is
 * the accent: the "you are here" line — the Reserve Rule's current position.
 * Strokes use vector-effect: non-scaling-stroke, so they stay 1px at any size.
 */
.contour-plate {
    --plate-line: 0.2;
    --plate-index: 0.42;
    --plate-here: 1;
    --plate-lit: 0.5;
    color: var(--color-fg);
    pointer-events: none;
    user-select: none;
}

.contour-plate__svg {
    display: block;
    width: 100%;
    height: 100%;
}

.contour-plate__level {
    stroke-width: 1;
    stroke-opacity: var(--plate-line);
}

.contour-plate__level--index {
    stroke-opacity: var(--plate-index);
}

.contour-plate__level--here {
    stroke: var(--color-accent);
    stroke-width: 1.25;
    stroke-opacity: var(--plate-here);
}

/*
 * Breathing — contour.js lights one level at a time, walking up the slope.
 * The transition exists only once the script has opted in, and the script
 * returns before opting in under prefers-reduced-motion.
 */
.contour-plate.is-breathing .contour-plate__level {
    transition: stroke-opacity 2.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.contour-plate.is-breathing .contour-plate__level.is-lit {
    stroke-opacity: var(--plate-lit);
}

/* --------------------------------------------------------------------------
   Corner and bleed — the plate as terrain under the page
   -------------------------------------------------------------------------- */

/*
 * Out of flow, behind the content, anchored to the bottom-right of the page
 * and faded toward the centre so it never sits at full strength under text.
 * It takes no space, so it cannot push content down or shift layout.
 *
 * The corner is the homepage's modest version. The bleed is the same
 * treatment at a much larger scale, for the 404 page: nearly the full width,
 * with a wider fade, so the page reads as standing on the map.
 */
body:has(.contour-plate--corner, .contour-plate--bleed) {
    position: relative;
    /* Anchor the plate to the window bottom even when the page is short. */
    min-height: 100svh;
}

.contour-plate--corner,
.contour-plate--bleed {
    --plate-line: 0.16;
    --plate-index: 0.32;
    --plate-here: 0.75;
    --plate-lit: 0.34;
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: -1;
    aspect-ratio: 3 / 2;
}

.contour-plate--corner {
    width: clamp(18rem, 48vi, 44rem);
    -webkit-mask-image: radial-gradient(ellipse 100% 100% at 100% 100%, black 35%, transparent 100%);
    mask-image: radial-gradient(ellipse 100% 100% at 100% 100%, black 35%, transparent 100%);
}

.contour-plate--bleed {
    width: clamp(24rem, 96vi, 110rem);
    -webkit-mask-image: radial-gradient(ellipse 110% 120% at 100% 100%, black 30%, transparent 95%);
    mask-image: radial-gradient(ellipse 110% 120% at 100% 100%, black 30%, transparent 95%);
}

/*
 * The sheet caption is the shared .eyebrow, run up the bottom-right margin.
 * Vertical writing turns the flex row and the rule with it, so the rule is
 * sized in logical units to stay a short 1px mark along the text; it doubles
 * as the map legend for the accent ring.
 */
.contour-plate__caption {
    position: absolute;
    right: calc(var(--page-pad-x) / 2);
    bottom: var(--page-pad-b);
    writing-mode: vertical-rl;
    rotate: 180deg;
    white-space: nowrap;
}

.contour-plate__caption::before {
    width: auto;
    height: auto;
    inline-size: 1.5rem;
    block-size: 1px;
}

/* On a phone the margin is too narrow to share with the map, so the caption
   lies flat along the bottom edge instead, below the ring. */
@media (max-width: 540px) {
    .contour-plate__caption {
        right: var(--page-pad-x);
        bottom: var(--space-l);
        writing-mode: horizontal-tb;
        rotate: none;
    }
}

.js-animated :is(.contour-plate--corner, .contour-plate--bleed) {
    opacity: 0;
    animation: fadeIn 1.2s cubic-bezier(0.4, 0, 0.2, 1) 1.6s forwards;
}

.js-animated .contour-plate--bleed {
    animation-delay: 0.6s;
}

/* --------------------------------------------------------------------------
   Band — behind the title on every inner page (ADR-001, ADR-002)
   -------------------------------------------------------------------------- */

/*
 * A wide, short sheet across the top of the window, behind the breadcrumb,
 * title and metadata. It fades to plain paper before the content starts, so
 * nobody reads over contour lines. Out of flow, so it adds no layout shift;
 * the title text is in the HTML before it, so it is never the LCP element.
 * The SVG aligns to its right edge, keeping the accent ring in view when a
 * narrow screen crops the sheet.
 */
body:has(.contour-plate--band) {
    position: relative;
}

.contour-plate--band {
    --plate-line: 0.14;
    --plate-index: 0.28;
    --plate-here: 0.7;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: -1;
    height: clamp(13rem, 9rem + 14vi, 22rem);
    -webkit-mask-image: linear-gradient(to bottom, black 30%, transparent 100%);
    mask-image: linear-gradient(to bottom, black 30%, transparent 100%);
}

.js-animated .contour-plate--band {
    opacity: 0;
    animation: fadeIn 0.8s cubic-bezier(0.4, 0, 0.2, 1) 0.2s forwards;
}

/* The map is the screen's texture, not the document's. */
@media print {
    .contour-plate {
        display: none;
    }
}
