/* Aura map v1: map index, map viewer, layers, pins and the linked result list.
   Loaded only by Pages/Database/Maps.cshtml and Map.cshtml, after knowledge-base.css.
   All art is CSS/inline SVG drawn for Aura; map sheets come from Aura's own client tiles. */

.am-map, .am-index {
    --am-npc: #e2be72;
    --am-npc-hi: #f8e3ae;
    --am-gather: #7fd6a4;
    --am-gather-hi: #b8f0cf;
    --am-quest: #d5a7fa;
    --am-quest-hi: #e9ccff;
    --am-cond: #86cdff;
    --am-ink: #04060b;
    --am-surface: var(--kb-surface, #101a29);
    --am-border: var(--kb-border, #27364c);
    --am-max-h: min(76vh, 820px);
}

/* Facts strip. */
.am-facts {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.6rem;
    margin: 0 0 1rem;
    padding: .7rem .95rem;
    border: 1px solid var(--am-border);
    border-top-color: var(--au-gold-line);
    background: var(--am-surface);
}
.am-facts div { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.am-facts dt { color: var(--au-muted); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.am-facts dd { margin: 0; color: var(--au-text); font-variant-numeric: tabular-nums; }
.am-focus { margin: 0 0 1rem; padding: .75rem 1rem; }

/* Shell: map beside a results panel on wide screens, stacked below 1000 px. */
.am-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 372px);
    align-items: start;
    gap: 1rem;
}
.am-shell--list { grid-template-columns: minmax(0, 1fr); }
.am-stage { position: sticky; top: 1rem; margin: 0; min-width: 0; }
.am-shell--list .am-panel { max-width: 860px; }

/* Viewer frame. */
.am-viewer {
    width: 100%;
    max-width: calc(var(--am-max-h) * var(--am-ratio, 1) + 14px);
    margin-inline: auto;
    padding: 6px;
    border: 1px solid var(--au-line-strong);
    background:
        linear-gradient(135deg, var(--au-gold-line), transparent 22%) top left / 46px 46px no-repeat,
        linear-gradient(315deg, var(--au-gold-line), transparent 22%) bottom right / 46px 46px no-repeat,
        var(--au-abyss);
    clip-path: var(--au-cut);
}
.am-viewer__body { position: relative; }
.am-viewport {
    position: relative;
    overflow: hidden;
    width: min(100%, calc(var(--am-max-h) * var(--am-ratio, 1)));
    aspect-ratio: var(--am-ratio, 1);
    margin-inline: auto;
    background:
        repeating-linear-gradient(0deg, #86cdff0a 0 1px, transparent 1px 48px),
        repeating-linear-gradient(90deg, #86cdff0a 0 1px, transparent 1px 48px),
        radial-gradient(ellipse at 50% 40%, #13243a, var(--au-deep) 75%);
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    outline-offset: -3px;
}
.am-map.is-ready .am-viewport { cursor: grab; }
.am-map.is-zoomed .am-viewport { touch-action: none; }
.am-map.is-dragging .am-viewport { cursor: grabbing; }
.as-body .am-viewport:focus-visible { outline: 2px solid var(--au-aether); outline-offset: -3px; }
.am-canvas {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    --am-inv: 1;
}
.am-map.is-dragging .am-canvas, .am-map.is-animating .am-canvas { will-change: transform; }
.am-map.is-animating .am-canvas { transition: transform .22s cubic-bezier(.2, .7, .2, 1); }
.am-canvas img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    -webkit-user-drag: none;
}
.am-pins { position: absolute; inset: 0; pointer-events: none; }

/* Pins: shape and colour both encode the layer; a hollow ring marks conditional points. */
.am-pin {
    position: absolute;
    width: 8px;
    height: 8px;
    transform: translate(-50%, -50%) scale(var(--am-inv, 1));
    background: var(--am-npc);
    box-shadow: 0 0 0 2px #04060be6;
}
.am-pin--npcs, .am-pin--other { width: 7px; height: 7px; transform: translate(-50%, -50%) scale(var(--am-inv, 1)) rotate(45deg); }
.am-pin--gathering { border-radius: 50%; background: var(--am-gather); }
.am-pin--quests { width: 8px; height: 10px; background: var(--am-quest); border-radius: 2px 2px 4px 4px; }
.am-pin--conditional {
    border-radius: 50%;
    background: transparent;
    box-shadow: inset 0 0 0 1.6px var(--am-cond), 0 0 0 2px #04060be6;
    transform: translate(-50%, -50%) scale(var(--am-inv, 1));
}
.am-pins.has-selection .am-pin:not(.is-selected) { opacity: .22; }
.am-pins.has-preview .am-pin:not(.is-preview) { opacity: .22; }
.am-pins.has-preview .am-pin.is-preview { opacity: 1; }
.am-pin.is-selected, .am-pin.is-focus, .am-pin.is-preview {
    z-index: 2;
    width: 12px;
    height: 12px;
    background: var(--am-npc-hi);
    box-shadow: 0 0 0 2px var(--am-ink), 0 0 12px #f4dfa8b0;
}
.am-pin--gathering.is-selected, .am-pin--gathering.is-focus, .am-pin--gathering.is-preview { background: var(--am-gather-hi); box-shadow: 0 0 0 2px var(--am-ink), 0 0 12px #b8f0cfa0; }
.am-pin--quests.is-selected, .am-pin--quests.is-focus, .am-pin--quests.is-preview { background: var(--am-quest-hi); box-shadow: 0 0 0 2px var(--am-ink), 0 0 12px #e9ccffa0; }
.am-pin--conditional.is-selected, .am-pin--conditional.is-focus, .am-pin--conditional.is-preview {
    background: #86cdff38;
    box-shadow: inset 0 0 0 2px var(--am-cond), 0 0 0 2px var(--am-ink), 0 0 12px #86cdffa0;
}
.am-pin.is-active { z-index: 3; outline: 2px solid var(--au-gold-hi); outline-offset: 2px; }
.am-pin--legend {
    position: static;
    display: inline-block;
    flex: none;
    transform: none;
}
.am-pin--legend.am-pin--npcs { transform: rotate(45deg); }

/* Zoom controls. */
.am-tools {
    position: absolute;
    z-index: 4;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.am-tools[hidden] { display: none; }
.as-body .am-tool {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--au-gold-line);
    background: #080c15e6;
    color: var(--au-gold-hi);
    font: 400 1.3rem/1 var(--au-ui);
    clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.as-body .am-tool:hover:not(:disabled) { background: #162338; border-color: var(--au-gold); }
.as-body .am-tool:focus-visible { outline: 2px solid var(--au-aether); outline-offset: 1px; clip-path: none; }
.as-body .am-tool:disabled { opacity: 1; background: #080c15e6; color: #9aa7bc8c; border-color: var(--au-line-strong); cursor: default; }
.am-tool__icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; }
.am-tools__zoom {
    min-width: 38px;
    padding: 2px 4px;
    background: #080c15cc;
    color: var(--au-soft);
    font: 600 .68rem/1.4 var(--au-ui);
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.as-body .am-help { flex-basis: 100%; margin: 0; color: var(--au-muted); }

/* Pin popup. */
.am-tip {
    position: absolute;
    z-index: 5;
    left: 0;
    top: 0;
    width: max-content;
    max-width: min(260px, calc(100% - 24px));
    padding: .6rem 2.1rem .65rem .75rem;
    border: 1px solid var(--au-gold-line);
    border-top: 2px solid var(--au-gold);
    background: #0b1422f2;
    box-shadow: 0 10px 28px #000a;
    color: var(--au-text);
    font-size: .82rem;
    line-height: 1.35;
    user-select: text;
    -webkit-user-select: text;
    cursor: auto;
}
.am-tip[hidden] { display: none; }
.as-body .am-tip__title { margin: 0; font-family: var(--au-display); font-size: 1rem; color: var(--au-gold-hi); overflow-wrap: anywhere; }
.as-body .am-tip__meta { margin: .15rem 0 0; color: var(--au-muted); font-size: .74rem; }
.am-tip__actions { display: flex; flex-wrap: wrap; gap: .25rem .7rem; margin-top: .45rem; }
.am-tip__actions:empty { display: none; }
.as-body .am-tip__actions a, .as-body .am-tip__actions button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--au-aether);
    font-size: .78rem;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.as-body .am-tip__close {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--au-muted);
    font-size: 1.2rem;
    line-height: 1;
}
.as-body .am-tip__close:hover { color: var(--au-gold-hi); }

/* Legend. */
.am-caption {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem 1.1rem;
    padding: .6rem .65rem .35rem;
    color: var(--au-soft);
    font-size: .76rem;
    line-height: 1.5;
}
.am-legend { display: inline-flex; align-items: center; gap: .45rem; }

/* No art. */
.am-noart {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 0;
    padding: 1rem 1.1rem;
}
.am-noart__glyph {
    flex: none;
    width: 44px;
    height: 44px;
    border: 1px solid var(--au-gold-line);
    background:
        linear-gradient(var(--au-gold-line), var(--au-gold-line)) 50% 0 / 1px 100% no-repeat,
        linear-gradient(var(--au-gold-line), var(--au-gold-line)) 0 50% / 100% 1px no-repeat,
        radial-gradient(circle, var(--au-gold) 0 3px, transparent 3.5px),
        var(--au-deep);
    transform: rotate(45deg) scale(.78);
}
.as-body .am-noart p { margin: 0; }

/* Search and layers. */
.am-panel { min-width: 0; }
.am-search {
    margin: 0 0 1rem;
    padding: .75rem;
    border: 1px solid var(--am-border);
    border-top-color: var(--au-gold-line);
    background: var(--am-surface);
}
.am-layers { margin: 0 0 .7rem; }
.am-layers ul {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.am-layers li { flex: 1 1 auto; min-width: 0; }
.as-body .am-layers a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 40px;
    padding: .35rem .7rem;
    border: 1px solid var(--am-border);
    background: #09121e;
    color: var(--au-soft);
    font-size: .8rem;
    text-decoration: none;
    white-space: nowrap;
}
.as-body .am-layers a small { color: var(--au-muted); font-size: .7rem; font-variant-numeric: tabular-nums; }
.as-body .am-layers__link::before {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    background: var(--am-npc);
    transform: rotate(45deg);
}
.as-body .am-layers__link--gathering::before { border-radius: 50%; background: var(--am-gather); transform: none; }
.as-body .am-layers__link--quests::before { border-radius: 2px 2px 4px 4px; background: var(--am-quest); transform: none; }
.as-body .am-layers a:hover { border-color: var(--au-gold-line); color: var(--au-gold-hi); }
.as-body .am-layers a[aria-current] {
    border-color: var(--au-gold);
    background: linear-gradient(180deg, #d9b56c22, #d9b56c08);
    color: var(--au-gold-hi);
}
.am-search__field { display: grid; gap: .3rem; }
.am-search__field label {
    color: var(--au-muted);
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.am-search__row { display: flex; gap: .4rem; }
.am-search__row input {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    padding: .4rem .6rem;
    border: 1px solid var(--am-border);
    border-radius: 3px;
    background: #09121e;
    color: var(--au-text);
    color-scheme: dark;
}
.am-search__row input:focus { border-color: var(--au-gold-line); }
.as-body .am-search__row .au-button { min-height: 40px; padding: .4rem .9rem; font-size: .72rem; }
.as-body .am-search__clear { justify-self: start; font-size: .78rem; color: var(--au-aether); }

/* Results. */
.am-results__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: .2rem 1rem;
    border-bottom: 1px solid var(--au-line);
    margin-bottom: .6rem;
}
.as-body .am-results__head .kb-h2 { margin: 0 0 .5rem; font-size: 1.2rem; }
.as-body .am-results__head .kb-count { margin: 0 0 .5rem; }
.am-results {
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--am-border);
    background: var(--au-abyss);
}
.am-result { border-bottom: 1px solid var(--au-line); scroll-margin: 1rem; }
.am-result:last-child { border-bottom: 0; }
.am-result.is-focus { background: linear-gradient(90deg, #d9b56c12, transparent 60%); }
.am-result.is-selected { box-shadow: inset 3px 0 0 var(--au-gold); background: linear-gradient(90deg, #d9b56c1c, transparent 70%); }
.am-result--gathering.is-selected { box-shadow: inset 3px 0 0 var(--am-gather); background: linear-gradient(90deg, #7fd6a41a, transparent 70%); }
.am-result > details > summary {
    display: flex;
    align-items: center;
    gap: .65rem;
    min-height: 48px;
    padding: .45rem .75rem;
    cursor: pointer;
    list-style: none;
}
.am-result > details > summary::-webkit-details-marker { display: none; }
.am-result > details > summary::after {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    margin-inline-start: auto;
    border-right: 1.5px solid var(--au-gold);
    border-bottom: 1.5px solid var(--au-gold);
    transform: rotate(-45deg);
    transition: transform .15s;
}
.am-result > details[open] > summary::after { transform: rotate(45deg); }
.am-result > details > summary:hover { background: #142337; }
.am-result__glyph {
    flex: none;
    width: 9px;
    height: 9px;
    margin: 0 .2rem;
    background: var(--am-npc);
    transform: rotate(45deg);
    box-shadow: 0 0 0 3px #e2be7222;
}
.am-result--gathering .am-result__glyph { border-radius: 50%; background: var(--am-gather); transform: none; box-shadow: 0 0 0 3px #7fd6a422; }
.am-result--quests .am-result__glyph { border-radius: 2px 2px 4px 4px; background: var(--am-quest); transform: none; box-shadow: 0 0 0 3px #d5a7fa22; }
.am-result__text { display: grid; gap: .1rem; min-width: 0; }
.am-result__name { color: var(--au-text); font-weight: 600; font-size: .9rem; overflow-wrap: anywhere; }
.am-result__meta { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .6rem; color: var(--au-muted); font-size: .74rem; }
.am-flag { color: var(--am-cond); }
.am-result__body { padding: 0 .75rem .75rem; }
.am-result__actions { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem; margin: 0 0 .55rem; font-size: .8rem; }
.as-body .am-show {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: 34px;
    padding: .3rem .7rem;
    border: 1px solid var(--au-gold-line);
    background: #0c1320;
    color: var(--au-gold-hi);
    font-size: .76rem;
}
.as-body .am-show[hidden] { display: none; }
.as-body .am-show::before {
    content: "";
    width: 9px;
    height: 9px;
    border: 1.5px solid currentColor;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
}
.as-body .am-show:hover { border-color: var(--au-gold); background: #162338; }
.as-body .am-show[aria-pressed="true"] { border-color: var(--au-gold); background: #d9b56c26; }
.am-coords :where(th, td) { padding: 5px 10px; font-variant-numeric: tabular-nums; }
.am-result .au-table-wrap { max-height: 18rem; overflow: auto; }
.am-empty { margin: 0; }
.am-panel .kb-pager { margin-top: .8rem; }

/* Map index. */
.am-search--index { max-width: 640px; }
.am-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.am-card { display: flex; min-width: 0; }
.am-card[hidden] { display: none; }
.as-body .am-card__link {
    position: relative;
    display: grid;
    grid-template-rows: auto 1fr;
    flex: 1;
    min-height: 74px;
    overflow: hidden;
    border: 1px solid var(--am-border);
    border-top: 2px solid #8e6c3088;
    background: radial-gradient(ellipse at 0 0, #1d304766, transparent 70%), var(--am-surface);
    color: var(--au-text);
    text-decoration: none;
}
.as-body .am-card__link:hover, .as-body .am-card__link:focus-visible { border-color: var(--au-gold-line); border-top-color: var(--au-gold); background: radial-gradient(ellipse at 0 0, #2a415c88, transparent 70%), #142337; }
.as-body .am-card__image {
    display: block;
    width: 100%;
    height: clamp(130px, 16vw, 200px);
    object-fit: cover;
    object-position: center 42%;
    border-bottom: 1px solid var(--am-border);
}
.am-card__body { display: grid; align-content: start; gap: .25rem; min-width: 0; padding: .8rem .95rem; }
.am-card__name { font-family: var(--au-display); font-size: 1.08rem; line-height: 1.25; overflow-wrap: anywhere; }
.as-body .am-card__link:hover .am-card__name, .as-body .am-card__link:focus-visible .am-card__name { color: var(--au-gold-hi); }
.am-card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .7rem; color: var(--au-muted); font-size: .74rem; font-variant-numeric: tabular-nums; }
.am-card__layer { display: inline-flex; align-items: center; gap: .35rem; }
.am-card__layer::before { content: ""; width: 6px; height: 6px; background: var(--am-npc); transform: rotate(45deg); }
.am-card__layer--gathering::before { border-radius: 50%; background: var(--am-gather); transform: none; }
.am-card__layer--quests::before { border-radius: 2px 2px 4px 4px; background: var(--am-quest); transform: none; }
.am-index .am-empty { margin-top: .5rem; }

@media (max-width: 1000px) {
    .am-shell { grid-template-columns: minmax(0, 1fr); }
    .am-stage { position: static; }
    .am-map { --am-max-h: 72vh; }
}
@media (max-width: 620px) {
    .am-viewer { padding: 4px; }
    .am-tools { top: 10px; right: 10px; }
    .as-body .am-tool { width: 44px; height: 44px; }
    .am-facts { gap: .35rem 1.1rem; padding: .6rem .75rem; }
    .am-layers li { flex: 1 1 100%; }
    .as-body .am-layers a { justify-content: flex-start; min-height: 44px; }
    .as-body .am-layers a span { margin-inline-end: auto; }
    .am-search__row input, .as-body .am-search__row .au-button { min-height: 44px; }
    .am-result > details > summary { min-height: 52px; }
    .as-body .am-show { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
    .am-map.is-animating .am-canvas, .am-result > details > summary::after { transition: none; }
}
@media (forced-colors: active) {
    .am-pin, .am-result__glyph, .am-card__layer::before, .am-layers__link::before { forced-color-adjust: none; }
    .am-viewer { clip-path: none; }
    .as-body .am-layers a[aria-current] { border: 2px solid Highlight; }
    .am-result.is-selected { outline: 2px solid Highlight; outline-offset: -2px; }
}
