/*
 * The world map of the knowledge base.
 *
 * Only this page loads it, together with Leaflet, so the Leaflet overrides
 * live here rather than in components.css: nothing else on the site draws a
 * map, and its controls come with a light theme of their own.
 */

.db-map {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-s);
}

/* ---- The acts, at the top of the panel ---- */
/*
 * A column, not a strip over the map: an act is the biggest of the choices
 * on this page, and everything that says what is being looked at belongs in
 * one place. Full width each, so the list reads as a list of one thing.
 */
.db-map__acts {
    display: flex;
    flex-direction: column;
    gap: var(--space-3xs);
}

.db-map__act {
    padding: var(--space-3xs) var(--space-2xs);
    border: var(--border-thin) solid transparent;
    border-radius: var(--radius-s);
    background: none;
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: var(--text-2xs);
    letter-spacing: var(--tracking-wide);
    text-align: start;
    text-transform: uppercase;
    cursor: pointer;
}

.db-map__act:hover,
.db-map__act:focus-visible {
    border-color: var(--color-border-accent);
    color: var(--color-accent);
}

.db-map__act:hover {
    background: var(--color-surface-hover);
}

.db-map__act--current {
    border-color: var(--color-border-accent);
    background: var(--color-surface-raised);
    color: var(--color-heading);
}

/* ---- The side panel ---- */
/*
 * What is drawn on the canvas, beside it rather than over it: the filters of
 * the markers are coming to stand under the layers, and a floating panel of
 * that size would cover the map it steers. Its own column on a desktop, a
 * band above the map on a phone.
 */
.db-map__body {
    display: grid;
    grid-template-columns: minmax(0, 18rem) minmax(0, 1fr);
    gap: var(--space-s);
}

/*
 * As tall as the canvas beside it: the row is as tall as the map, and a
 * panel that stopped at its last checkbox left a column of nothing under it
 * reading as a hole in the page. Its own scrollbar, so a longer list of
 * filters lengthens the panel and never the page.
 */
.db-map__side {
    display: flex;
    flex-direction: column;
    gap: var(--space-m);
    overflow-y: auto;
    padding: var(--space-m);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-m);
    background: var(--color-surface);
}

.db-map__group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
}

.db-map__group-title {
    margin: 0;
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: var(--text-3xs);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

/*
 * The layers of one act - the surface and the dungeons under it. A pair of
 * halves rather than loose buttons, like the game switcher in the section
 * strip: there are two of them and they are two states of one thing. In the
 * panel they split its width, so neither half reads as the longer answer.
 */
.db-map__layers {
    display: flex;
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-m);
    overflow: hidden;
}

.db-map__layer {
    flex: 1 1 0;
    padding: var(--space-3xs) var(--space-2xs);
    border: 0;
    background: none;
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: var(--text-2xs);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    cursor: pointer;
}

.db-map__layer:hover,
.db-map__layer:focus-visible {
    color: var(--color-accent);
}

.db-map__layer--current {
    background: var(--color-border-accent);
    color: var(--color-heading);
}

/* ---- The marker filters ---- */
/*
 * Checkboxes, not a segmented switch: several kinds are shown at once. Each
 * carries the pin it turns on, so the panel is also the legend - a dot on the
 * map means nothing until something says what the colour is.
 */
.db-map__filters {
    margin: 0;
    padding: 0;
    list-style: none;
}

.db-map__check {
    display: flex;
    gap: var(--space-2xs);
    align-items: center;
    padding: var(--space-3xs) 0;
    color: var(--color-text-muted);
    font-size: var(--text-2xs);
    cursor: pointer;
}

.db-map__check:hover {
    color: var(--color-text);
}

.db-map__check input {
    margin: 0;
}

.db-map__check-label {
    flex: 1 1 auto;
}

/* Blank until the markers of this layer are counted; a zero would read as a
   filter that does nothing rather than as a layer that holds none. */
.db-map__count {
    color: var(--color-text-muted);
    font-size: var(--text-3xs);
    font-variant-numeric: tabular-nums;
}

/* ---- The pins ---- */
/*
 * Drawn in CSS rather than loaded as icons: a marker is a dot with a ring,
 * and the ring is what keeps it visible over both the pale stone of a town
 * and the black of a cave. The same class draws the legend in the panel, so
 * the two cannot drift apart.
 */
.db-map__pin {
    box-sizing: border-box;
    flex: 0 0 auto;
    width: 0.875rem;
    height: 0.875rem;
    border: 2px solid rgba(0, 0, 0, 0.65);
    border-radius: 50%;
    background: var(--pin-color, var(--color-accent));
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.db-map__pin--place {
    --pin-color: #e3d8cc;
}

.db-map__pin--npc {
    --pin-color: #e3785c;
}

.db-map__pin--quest {
    --pin-color: #f2dd6e;
}

.db-map__pin--sidequest {
    --pin-color: #5fc9c0;
}

.db-map__pin--boss {
    --pin-color: #d4544f;
}

.db-map__pin--shrine {
    --pin-color: #e38fc0;
}

.db-map__pin--portal {
    --pin-color: #6fb7e3;
}

.db-map__pin--merchant {
    --pin-color: #e0b24e;
}

.db-map__pin--caravan {
    --pin-color: #9aa7b8;
}

.db-map__pin--enchanter {
    --pin-color: #b47ad6;
}

.db-map__pin--mystic {
    --pin-color: #7ed39a;
}

/* The legend swatch of the areas: they are printed as names, so the dot is
   only there to keep the row shaped like the others. */
.db-map__pin--area {
    --pin-color: #b9ae9f;
}

/*
 * An area is a stretch of map, not a point on it, so its marker is the name
 * itself - the word the game prints, standing on the middle of the block of
 * levels it covers. The icon is a point of no size and the name is centred
 * on it by the child, because Leaflet owns the icon's own transform.
 */
.db-map__area {
    width: 0;
    height: 0;
}

/* The name itself, which rides on an always-open tooltip. The class has to
   beat the tooltip theming below, which gives a panel to the names that pop
   up under the cursor; an area name stands on the map and a panel under it
   would hide the ground it names. */
.db-map .leaflet-tooltip.db-map__area-name {
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-heading);
    font-family: var(--font-heading);
    font-size: var(--text-2xs);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    white-space: nowrap;
    /* Readable over pale sand as well as over the black of a cave. */
    text-shadow:
        0 0 3px rgba(0, 0, 0, 0.9),
        0 0 6px rgba(0, 0, 0, 0.7);
}

.db-map .leaflet-tooltip.db-map__area-name::before {
    display: none;
}

/* On the map Leaflet positions the icon itself, so it must not be a flex
   item there and it has to sit above the tiles' own hover handling. */
.leaflet-marker-icon.db-map__pin {
    cursor: default;
}

/*
 * A mouth whose far side is known: clicking it moves the map to the other
 * end of the same passage. The second ring says so before the tooltip does -
 * among a hundred dots, the ones that are doors have to look like doors.
 */
.leaflet-marker-icon.db-map__pin--gate {
    cursor: pointer;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.35),
        0 0 0 3px rgba(227, 216, 204, 0.55);
}

.leaflet-marker-icon.db-map__pin--gate:hover {
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.35),
        0 0 0 4px rgba(227, 216, 204, 0.9);
}

/* ---- The canvas ---- */

.db-map__canvas {
    /*
     * The colours of the areas. Five, because greedy colouring of the
     * fifty-five zones of the world needs five for no two near each other to
     * share one; the script reads them from here, since Leaflet writes a
     * shape's colour inline and a class on the shape would be overruled.
     * Muted on purpose: they lie over the game's own art, which is already
     * brown and green, and a saturated wash would be read as terrain.
     */
    --map-zone-0: #d8cbb8;
    --map-zone-1: #8fbcd4;
    --map-zone-2: #d0a86a;
    --map-zone-3: #93c49b;
    --map-zone-4: #b899cf;
    /*
     * Leaflet hands its own panes z-index up to 1000 - the controls alone sit
     * at 800 - while the site's sticky header sits at 50. Without a stacking
     * context of its own the map scrolls over the header. `isolation` makes
     * one without giving the canvas a z-index of its own, so every number
     * Leaflet writes is settled inside it and the header stays on top.
     */
    isolation: isolate;
    /*
     * Tall enough to be a map and not a strip, short enough that the section
     * strip above it stays on screen; the floor keeps it usable on a phone
     * held in landscape.
     */
    height: min(72vh, 46rem);
    min-height: 20rem;
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-m);
    /* The void between the regions, where no tile was written. */
    background: var(--color-surface-sunken);
}

/* ---- Leaflet, in the site's colours ---- */

.db-map .leaflet-container {
    background: transparent;
    font-family: inherit;
}

.db-map .leaflet-bar {
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-m);
    box-shadow: none;
}

.db-map .leaflet-bar a {
    border-bottom: var(--border-thin) solid var(--color-border);
    background: var(--color-surface-raised);
    color: var(--color-text);
}

.db-map .leaflet-bar a:hover,
.db-map .leaflet-bar a:focus {
    background: var(--color-surface-hover);
    color: var(--color-heading);
}

.db-map .leaflet-bar a.leaflet-disabled {
    background: var(--color-surface);
    color: var(--color-text-muted);
}

/* The panel becomes a band over the map: a column of its width would leave
   the canvas too narrow to be a map. */
/*
 * On a phone the panel is a band above the map, and every row of it is a
 * row the map does not get. So each group lies across instead of down, and
 * the groups keep their order: the act, then the layer, then the filters.
 */
@media (max-width: 48rem) {
    .db-map__body {
        grid-template-columns: minmax(0, 1fr);
    }

    .db-map__side {
        gap: var(--space-s);
        padding: var(--space-2xs) var(--space-s) var(--space-s);
    }

    /*
     * The acts on one line that scrolls, not a block that wraps: seven of
     * them wrap to three rows, and three rows of buttons over a map is most
     * of a phone screen. The same strip the forum navigation uses.
     */
    .db-map__acts {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: var(--space-2xs);
        overflow-x: auto;
        /* Room for the focus ring of the first and last, which a scroll
           container would otherwise clip. */
        padding: 2px;
        margin: -2px;
        scrollbar-width: thin;
    }

    .db-map__act {
        flex: 0 0 auto;
        /* In a row with nothing around them the halves need their own edge;
           in the column the current one alone carries it. */
        border-color: var(--color-border);
    }

    /* Two or three columns of checkboxes rather than eight rows. */
    .db-map__filters {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
        column-gap: var(--space-s);
    }
}

/* Leaflet's tooltip comes in its own light theme. */
.db-map .leaflet-tooltip {
    padding: var(--space-3xs) var(--space-2xs);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-s);
    background: var(--color-surface-raised);
    color: var(--color-text);
    font-size: var(--text-2xs);
    box-shadow: none;
}

.db-map .leaflet-tooltip-top::before {
    border-top-color: var(--color-border);
}
