/* Maps on davalerio.com: the map palette, essay steps, embeds and map pages.
   Loaded only on pages that carry a map. */

:root {
    --map-water: #6F8FA6;
    --map-contour: #A39A8C;
    --map-city: #D9D2C4;
    --map-city-line: #6B7075;
    --map-shadow: #4A4F55;
    --map-highlight: #FFFFFF;
    --map-coal-anthracite: #85827C;
    --map-coal-bituminous: #BAB7B1;
    --map-coal-subbituminous: #D6D3CD;
    --map-coal-lignite: #E7E4DF;
    --map-wide: min(82rem, calc(100vw - 3rem));
}

@media screen and (prefers-color-scheme: dark) {
    :root {
        --map-water: #3F5B70;
        --map-contour: #5E5A54;
        --map-city: #3A3833;
        --map-city-line: #9BA0A4;
        --map-shadow: #000000;
        --map-highlight: #3A4045;
        --map-coal-anthracite: #6B6964;
        --map-coal-bituminous: #4F4D49;
        --map-coal-subbituminous: #3A3936;
        --map-coal-lignite: #2B2C2B;
    }
}

/* The canvas and its labels */

.map-canvas {
    position: absolute;
    inset: 0;
    background: var(--paper);
}

.map-label {
    font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9rem;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    color: var(--ink);
    text-shadow: 0 0 3px var(--paper), 0 0 3px var(--paper), 0 0 6px var(--paper);
    transition: opacity 0.4s;
}

.map-label.place {
    font-weight: 600;
    font-size: 1rem;
}

.map-label.water {
    font-style: italic;
    color: var(--map-water);
    filter: brightness(0.75);
}

@media (prefers-color-scheme: dark) {
    .map-label.water { filter: brightness(1.6); }
}

.map-label.off {
    visibility: hidden;
}

.maplibregl-ctrl-group {
    border-radius: 0 !important;
    box-shadow: none !important;
    border: 1px solid var(--hair);
    background: var(--paper) !important;
}

@media (prefers-color-scheme: dark) {
    .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
        filter: invert(0.85);
    }

    .maplibregl-ctrl-group button + button {
        border-top-color: var(--hair) !important;
    }
}

.maplibregl-ctrl-attrib {
    display: none;
}

/* The note for email and feed readers, which the page itself does not need */

.map-note {
    display: none;
}

/* Essay steps: a still beside every change of view, upgraded to a pinned map */

.map-stage {
    display: none;
}

.still a {
    border: 0;
}

.scrolly.live {
    display: grid;
    grid-template-columns: minmax(20rem, 26rem) 1fr;
    gap: 0 3rem;
    width: var(--map-wide);
    margin-left: calc((100% - var(--map-wide)) / 2);
}

.scrolly.live .map-stage {
    display: block;
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 1rem;
    height: calc(100svh - 2rem);
    margin-bottom: 1rem;
    border: 1px solid var(--hair);
}

.scrolly.live .steps {
    grid-column: 1;
    grid-row: 1;
}

.scrolly.live .map-step {
    min-height: 80svh;
    padding: 30svh 0 0;
}

.scrolly.live .map-step:first-child {
    padding-top: 12svh;
}

/* A link to a passage lands it below a pinned map, not under it. */
.scrolly .map-step {
    scroll-margin-top: 1rem;
}

.scrolly.live .map-step:last-child {
    min-height: 0;
    padding-bottom: 35svh;
}

.scrolly.live .map-step > * + * {
    margin-top: 1.35em;
}

.scrolly.ready .still {
    display: none;
}

.scrolly:not(.live) .map-step > * + * {
    margin-top: 1.35em;
}

.map-explore {
    position: absolute;
    left: 0.75rem;
    bottom: 0.75rem;
    z-index: 2;
    font: inherit;
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--hair);
    border-radius: 0;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
}

.map-explore:hover {
    color: var(--accent);
}

.map-explore:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 899px) {
    .scrolly.live {
        display: block;
        width: auto;
        margin-left: 0;
    }

    .scrolly.live .map-stage {
        top: 0;
        height: 40svh;
        margin: 0 -1.5rem;
        border: 0;
        border-bottom: 1px solid var(--hair);
        z-index: 2;
    }

    .scrolly.live .map-step {
        min-height: 60svh;
        padding-top: 8svh;
    }

    .scrolly.live .map-step:first-child {
        padding-top: 4svh;
    }

    .scrolly.live .map-step {
        scroll-margin-top: calc(40svh + 1rem);
    }
}

@media (max-width: 560px) {
    .scrolly.live .map-stage {
        margin: 0 -1.15rem;
    }
}

.scrolly.live.exploring .map-stage {
    position: fixed;
    inset: 0;
    height: auto;
    margin: 0;
    z-index: 20;
    border: 0;
}

/* A map set into the text */

.map-embed.live {
    position: relative;
    height: clamp(20rem, 55svh, 32rem);
    border: 1px solid var(--hair);
}

.map-embed.ready .still {
    display: none;
}

/* Cooperative gestures keep a one-finger swipe or plain scroll moving the page past a map, without
   MapLibre's overlay telling readers how to move it: no map carries instructions for using it. */
.maplibregl-cooperative-gesture-screen {
    display: none !important;
}

/* Map pages */

body.wide header.site,
body.wide main {
    max-width: 82rem;
}

.map-full {
    position: relative;
}

.map-full.live {
    height: min(80svh, 56rem);
    min-height: 24rem;
    border: 1px solid var(--hair);
}

.map-full.ready .still {
    display: none;
}

/* Until the map has drawn, its still shows through. */
.map-full.live:not(.ready) .map-canvas,
.map-embed.live:not(.ready) .map-canvas {
    opacity: 0;
}

.map-credits,
.map-downloads {
    margin-top: 0.9rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--stone);
}

/* A map's note and credits are written in markdown: paragraphs, line breaks, lists and links */
div.subtitle > *,
div.map-credits > * {
    margin: 0;
}

div.subtitle > * + *,
div.map-credits > * + * {
    margin-top: 0.5em;
}

div.subtitle ul,
div.subtitle ol,
div.map-credits ul,
div.map-credits ol {
    padding-left: 1.4em;
}

div.subtitle li + li,
div.map-credits li + li {
    margin-top: 0.2em;
}

.showpiece img {
    display: block;
    max-width: 100%;
    max-height: 90svh;
    width: auto;
    height: auto;
    margin: 0 auto;
    border: 1px solid var(--hair);
}

/* Turnable models: the stack on its canvas, the spacing slider and the key. The image stays until the model draws. */

.model-stage {
    position: relative;
    height: min(86svh, 60rem);
    min-height: 26rem;
    overflow: hidden;
}

.model-view:not(.ready) .model-stage,
.model-view:not(.ready) .model-bar,
.model-view:not(.ready) .model-key {
    display: none;
}

.model-view.ready .showpiece {
    display: none;
}

.model-canvas,
.model-marks,
.model-labels {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.model-canvas {
    cursor: grab;
}

.model-canvas:active {
    cursor: grabbing;
}

.model-marks,
.model-labels {
    pointer-events: none;
}

.model-marks line,
.model-marks path {
    stroke: var(--ink);
    stroke-width: 0.8;
    fill: none;
}

/* Town pins stand on the pale ground sheet in both themes, so they carry a halo of the page colour. */
.model-marks .halo {
    stroke: var(--paper);
    stroke-width: 2.6;
}

.model-marks .dot {
    fill: var(--ink);
    stroke: var(--paper);
    stroke-width: 1.2;
}

.model-marks .leader {
    stroke: var(--stone);
    stroke-width: 0.6;
}

.model-marks .north path {
    fill: var(--ink);
    stroke: none;
}

.model-marks .ring {
    fill: none;
    stroke: var(--ink);
    stroke-width: 1;
}

.model-marks .ring.light {
    stroke: #B59F86;
}

.model-marks text {
    font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.75rem;
    fill: var(--ink);
    text-anchor: middle;
}

.model-label {
    position: absolute;
    left: 0;
    top: 0;
    font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.15;
    color: var(--ink);
    white-space: nowrap;
}

.model-label.town {
    font-size: 0.8rem;
    font-weight: 600;
    text-shadow: 0 0 3px var(--paper), 0 0 3px var(--paper), 0 0 6px var(--paper);
}

.model-label.layer {
    font-size: 0.95rem;
    font-weight: 600;
}

/* A narrow stage (set by model.js from the stage's own width) keeps a narrow column for the names. */
.model-stage.narrow .model-label.layer {
    font-size: 0.8rem;
    white-space: normal;
    width: 5.4rem;
}

.model-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 1.6rem;
    margin-top: 0.8rem;
    font-size: 0.9rem;
    color: var(--stone);
}

.model-spacing {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--ink);
}

.model-spacing input {
    width: 12rem;
    accent-color: var(--accent);
}

.model-note {
    margin: 0;
}

.model-key {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: 1rem 1.2rem;
    margin: 1.4rem 0 0;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--stone);
}

.model-key li {
    display: flex;
    gap: 0.6rem;
    margin: 0;
}

.model-key .swatch {
    flex: none;
    width: 0.8rem;
    height: 0.8rem;
    margin-top: 0.3rem;
    border-radius: 2px;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--stone) 45%, transparent);
}

.model-key strong {
    display: block;
    color: var(--ink);
    font-weight: 600;
}

.model-key span:not(.swatch) {
    display: block;
}

@media (min-width: 1100px) {
    .model-key {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 560px) {
    .model-stage {
        height: 66svh;
        min-height: 22rem;
    }

    .model-spacing {
        width: 100%;
    }

    .model-spacing input {
        flex: 1;
        width: auto;
    }
}

@media print {
    .model-stage,
    .model-bar,
    .model-key {
        display: none !important;
    }

    .model-view .showpiece {
        display: block !important;
    }
}

/* Still mode: the page reduced to one view, for capturing images */

html.still-mode body > :not(.map-full),
html.still-mode main > :not(.map-full) {
    display: none;
}

html.still-mode body.wide main {
    display: block;
}

html.still-mode body {
    padding: 0;
}

html.still-mode .map-full.live {
    position: fixed;
    inset: 0;
    width: 1200px;
    height: 800px;
    min-height: 0;
    border: 0;
}

@media print {
    .map-stage,
    .map-explore,
    .map-full .map-canvas,
    .map-embed .map-canvas {
        display: none !important;
    }

    .scrolly.live {
        display: block;
        width: auto;
        margin: 0;
    }

    .scrolly .still,
    .map-full .still,
    .map-embed .still {
        display: block !important;
        break-inside: avoid;
    }

    .scrolly.live .map-step {
        min-height: 0 !important;
        padding: 0 !important;
    }

    .scrolly .map-step + .map-step {
        margin-top: 1.35em;
    }

    .map-full.live,
    .map-embed.live {
        height: auto;
        min-height: 0;
        border: 0;
    }
}

/* What a reader sees on clicking a feature, in the map's own type */

.maplibregl-popup-content {
    font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.85rem;
    line-height: 1.35;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--hair);
    border-radius: 0;
    box-shadow: none;
    padding: 0.6rem 1.7rem 0.6rem 0.8rem;
}

.maplibregl-popup-tip {
    display: none;
}

.maplibregl-popup-close-button {
    color: var(--stone);
    font-size: 1.1rem;
    padding: 0 0.4rem;
}

.map-popup-title {
    font-weight: 600;
}

.map-popup-item + .map-popup-item {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--hair);
}

.map-popup-line {
    color: var(--stone);
}

/* The key beneath a map page's map */

.map-legend {
    margin-top: 1.4rem;
    font-family: 'Source Sans 3', 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.85rem;
    line-height: 1.3;
    columns: 3 17rem;
    column-gap: 2.5rem;
}

.map-legend h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0 0 0.35rem;
    break-after: avoid;
}

.map-legend ul {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}

.map-legend li {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    padding: 0.14rem 0;
    break-inside: avoid;
}

.map-legend .swatch {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    flex: none;
    width: 1.15rem;
    height: 0.75rem;
    border: 1px solid var(--hair);
    transform: translateY(0.12rem);
}

.map-legend .swatch.dot {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    border-color: var(--paper);
}

.map-legend .swatch.line {
    height: 0;
    border: 0;
    border-top: 2px solid;
    transform: translateY(-0.2rem);
}

.map-legend .swatch.line.dashed {
    border-top-style: dashed;
}

.map-legend .swatch.line.dotted {
    border-top-style: dotted;
}

.map-legend .code {
    flex: none;
    min-width: 2.4rem;
    color: var(--stone);
}
