/* Kind colours shared by the map and the cards (the film defines the same set on .film). */
:root {
  --k-water: hsla(204, 58%, 46%, 1);
  --k-land: hsla(142, 36%, 38%, 1);
  --k-people: hsla(282, 32%, 50%, 1);
  --k-built: hsla(var(--hue-primary), 9%, 52%, 1);
  --map-accent: hsla(24, 78%, 52%, 1);
  --k-none: hsla(var(--hue-primary), 8%, 66%, 1);
}

:root[data-theme="dark"] {
  --k-water: hsla(204, 62%, 66%, 1);
  --k-land: hsla(142, 38%, 60%, 1);
  --k-people: hsla(282, 40%, 72%, 1);
  --k-built: hsla(var(--hue-primary), 12%, 64%, 1);
  --map-accent: hsla(26, 86%, 62%, 1);
  --k-none: hsla(var(--hue-primary), 8%, 48%, 1);
}

.map-block { margin-bottom: 30px; }

.map-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* View switch: colour-only selection, no fills inside the map surface's neighbourhood */
.map-views { display: flex; gap: 18px; }

.map-views button {
  border: 0;
  padding: 4px 0;
  background: none;
  color: var(--subtle);
  font-weight: 800;
  cursor: pointer;
  transition: color 160ms ease;
}

.map-views button:hover { color: var(--ink); }
.map-views button[aria-pressed="true"] { color: var(--ink); }

/* The map is the one filled surface here; dots, labels and the legend inside it carry no fills of their own. */
.map-wrap {
  position: relative;
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.map-wrap svg {
  display: block;
  width: 100%;
  height: clamp(380px, 68vh, 720px);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.map-wrap.is-panning svg { cursor: grabbing; }
.map-wrap.is-panning .map-dot { pointer-events: none; }

/* The map is one canvas that fills the region. Every control floats on it as an icon, and the tag tree floats
   over its left edge with no panel of its own: only a wide soft gradient from the corner keeps it readable. */
.map-title { margin-bottom: 12px; }
.map-block { container-type: inline-size; }
.map-stage { position: relative; }
.map-wrap svg { height: clamp(520px, 86vh, 980px); }
.map-side {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 44%);
  margin: 0;
  padding: 18px 16px 18px 20px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  border-radius: var(--radius) 0 0 var(--radius);
  background: none;
  transition: opacity 220ms ease, transform 260ms cubic-bezier(.2,.7,.1,1);
}
.map-side::-webkit-scrollbar { display: none; }
/* the corner gradient: wide, soft, and painted behind the tree only, never a box */
.map-stage::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0 auto 0 0;
  width: min(520px, 70%);
  border-radius: var(--radius) 0 0 var(--radius);
  pointer-events: none;
  background:
    radial-gradient(120% 70% at 0% 0%, hsla(var(--hue-primary), 30%, 98%, 0.96) 0%, hsla(var(--hue-primary), 30%, 98%, 0.82) 38%, hsla(var(--hue-primary), 30%, 98%, 0) 78%),
    linear-gradient(90deg, hsla(var(--hue-primary), 30%, 98%, 0.9) 0%, hsla(var(--hue-primary), 30%, 98%, 0.7) 42%, hsla(var(--hue-primary), 30%, 98%, 0) 100%);
  transition: opacity 260ms ease;
}
:root[data-theme="dark"] .map-stage::before {
  background:
    radial-gradient(120% 70% at 0% 0%, hsla(var(--hue-primary), 14%, 10%, 0.95) 0%, hsla(var(--hue-primary), 14%, 10%, 0.8) 38%, hsla(var(--hue-primary), 14%, 10%, 0) 78%),
    linear-gradient(90deg, hsla(var(--hue-primary), 14%, 10%, 0.88) 0%, hsla(var(--hue-primary), 14%, 10%, 0.66) 42%, hsla(var(--hue-primary), 14%, 10%, 0) 100%);
}
.map-block.tree-collapsed .map-side { opacity: 0; transform: translateX(-24px); pointer-events: none; }
.map-block.tree-collapsed .map-stage::before { opacity: 0; }
.rail-head { position: relative; }
.tree-fold, .tree-open { border: 0; padding: 0; background: none; color: var(--subtle); cursor: pointer; transition: color 160ms ease; }
.tree-fold { position: absolute; top: 0; right: 0; width: 28px; height: 28px; }
.tree-fold:hover, .tree-open:hover { color: var(--ink); }
.tree-open { position: absolute; z-index: 3; top: 14px; left: 14px; width: 38px; height: 38px; font-size: 1.05rem; opacity: 0; pointer-events: none; transition: opacity 200ms ease, color 160ms ease; }
.map-block.tree-collapsed .tree-open { opacity: 1; pointer-events: auto; }

/* floating icon tools: no fills, no borders; the label rises beside the icon on hover */
/* groups, top to bottom: view, ground, source, more filters, zoom. A hairline parts them, and each group
   lights in its own colour when on, so "where am I looking" never reads like "what am I filtering" */
.map-tools { position: absolute; z-index: 5; top: 12px; right: 10px; display: grid; gap: 0; }
.map-tool-group { display: grid; gap: 0; --tone: var(--map-accent); }
.map-tool-group + .map-tool-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.tone-view { --tone: var(--blue); }
.tone-ground { --tone: var(--k-land); }
.tone-source, .tone-filter { --tone: var(--violet); }
.map-tools button {
  position: relative;
  width: 38px;
  height: 32px;
  border: 0;
  padding: 0;
  background: none;
  color: var(--subtle);
  font-size: 1rem;
  cursor: pointer;
  transition: color 160ms ease;
}
.map-tools button:hover { color: var(--ink); }
.map-tools button[aria-pressed="true"] { color: var(--tone); }
.map-tools button.is-on::before { content: ""; position: absolute; top: 8px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--tone); }

/* claims and first letter: a small card beside the tools, opened from the sliders icon */
.filter-pop { position: absolute; z-index: 6; top: 12px; right: 58px; width: min(300px, calc(100% - 80px)); display: grid; gap: 8px; padding: 16px 18px; border-radius: 16px; background: var(--paper); box-shadow: 0 16px 36px var(--shadow-medium); }
.filter-pop[hidden] { display: none; }
.pop-title { margin: 4px 0 0; color: var(--subtle); font-size: 0.76rem; font-weight: 800; }
.pop-row { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.pop-row button { border: 0; padding: 4px 0; background: none; color: var(--muted); font-weight: 800; font-size: 0.88rem; cursor: pointer; transition: color 160ms ease; }
.pop-row button:hover { color: var(--ink); }
.pop-row button[aria-pressed="true"] { color: var(--violet); }
.pop-letters { gap: 2px 4px; }
.pop-letters button { min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: 50%;
  right: calc(100% + 4px);
  transform: translate(4px, -50%);
  white-space: nowrap;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  paint-order: stroke;
  -webkit-text-stroke: 0;
  text-shadow: 0 0 6px var(--panel), 0 0 2px var(--panel);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(0, -50%); }
.tree-open[data-tip]::after { right: auto; left: calc(100% + 4px); }
.map-stage { overflow-x: clip; }

/* legends float at the bottom right of the canvas */
.map-foot { position: absolute; z-index: 1; right: 18px; bottom: 14px; display: grid; justify-items: end; gap: 6px; max-width: min(460px, 55%); pointer-events: none; }
.map-foot .map-legend { pointer-events: auto; }
.map-foot .map-legend { position: static; justify-content: flex-end; }
.map-foot .map-ground-legend { margin: 0; color: var(--muted); font-size: 0.8rem; font-weight: 700; text-align: right; text-shadow: 0 0 6px var(--panel); }

/* phones and narrow windows: the tree leaves the canvas and sits below it at full width */
@container (max-width: 780px) {
  .map-wrap svg { height: clamp(380px, 70vh, 620px); }
  .map-side { position: static; width: auto; max-height: none; overflow: visible; padding: 16px 0 0; }
  .map-stage::before { display: none; }
  .tree-open { top: auto; bottom: -46px; left: 0; }
  .map-block.tree-collapsed .map-side { display: none; }
  .map-foot { max-width: 70%; }
  .map-foot .map-ground-legend { display: none; }
}
.map-hint { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); margin: 0; color: var(--muted); font-size: 0.84rem; font-weight: 800; pointer-events: none; }
.map-hint[hidden] { display: none; }

.map-views-label { color: var(--faded); font-size: 0.8rem; font-weight: 800; padding: 4px 0; }
.map-ground-legend:empty { display: none; }
.map-ground-img { opacity: 0.9; image-rendering: auto; }
.map-wrap[data-ground="relief"] .map-ground-img { opacity: 1; }
:root[data-theme="dark"] .map-wrap[data-ground="relief"] .map-ground-img { opacity: 0.55; }
.map-district { fill: none; stroke: var(--muted); opacity: 0.75; stroke-linejoin: round; stroke-width: calc(var(--u, 1) * 1.2px); }
.map-district-label { font-size: calc(var(--u, 1) * 13px); fill: var(--muted); paint-order: stroke; stroke: var(--panel); stroke-width: calc(var(--u, 1) * 3px); stroke-linejoin: round; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; pointer-events: none; }
.map-wrap:not(.is-wide) .map-districts { display: none; }

.map-ward { fill: none; stroke: var(--line); stroke-linejoin: round; stroke-width: calc(var(--u, 1) * 0.8px); }
.map-road { stroke-width: calc(var(--u, 1) * 1.1px); fill: none; stroke: var(--faded); stroke-linecap: round; stroke-linejoin: round; opacity: 0.55; }

.map-dot {
  cursor: pointer;
  stroke: var(--panel);
  stroke-width: calc(var(--u, 1) * 1.6px);
  transition: opacity 200ms ease;
}

.map-dot.k-water { fill: var(--k-water); }
.map-dot.k-land { fill: var(--k-land); }
.map-dot.k-people { fill: var(--k-people); }
.map-dot.k-built { fill: var(--k-built); }
.map-dot.is-dim { opacity: 0.14; }
.map-dot { r: calc(var(--u, 1) * 6px); }
.map-dot.is-region { r: calc(var(--u, 1) * 2.6px); }
.map-wrap.is-zoomed .map-dot.is-region { r: calc(var(--u, 1) * 3.6px); }
.map-dot.is-big { r: calc(var(--u, 1) * 9px); }
.map-dot.is-region.is-big { r: calc(var(--u, 1) * 7px); }
.map-dot:focus-visible { outline: none; stroke: var(--focus); }

.map-ring { fill: none; stroke: var(--map-accent); pointer-events: none; }

.map-label {
  fill: var(--ink);
  font-family: "Raleway", ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: calc(var(--u, 1) * 4px);
  stroke-linejoin: round;
  pointer-events: none;
}

.map-legend {
  position: absolute;
  left: 18px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  pointer-events: none;
}

.map-legend button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  padding: 2px 0;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-shadow: 0 0 6px var(--panel);
  cursor: pointer;
  transition: color 160ms ease, opacity 160ms ease;
}
.map-legend button:hover { color: var(--ink); }
.map-legend button[aria-pressed="true"] { color: var(--c); }
.map-legend:has([aria-pressed="true"]) button[aria-pressed="false"] { opacity: 0.55; }

.map-legend button::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
}

.map-tip {
  position: absolute;
  z-index: 2;
  max-width: 280px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 16px 36px var(--shadow-medium);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  pointer-events: none;
}

.map-tip b {
  display: block;
  color: var(--ink);
  font-family: "Raleway", ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
}

.map-tip { max-width: 330px; }
.map-tip span { display: block; }
.map-tip .tip-script { color: var(--subtle); font-style: normal; font-weight: 600; }
.map-tip .tip-meta { color: var(--subtle); font-size: 0.78rem; font-weight: 700; margin-bottom: 4px; }
.map-tip .tip-code { margin-top: 6px; --tone: var(--k-built); }
.map-tip .tip-code.k-water { --tone: var(--k-water); }
.map-tip .tip-code.k-land { --tone: var(--k-land); }
.map-tip .tip-code.k-people { --tone: var(--k-people); }
.map-tip .tip-stem { color: var(--tone); font-weight: 800; }
.map-tip .tip-gloss { display: inline; color: var(--ink); }
.map-tip .tip-path { color: var(--subtle); font-size: 0.76rem; font-weight: 700; }
.map-tip .tip-cut { margin-top: 6px; color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.map-tip small { display: block; margin-top: 6px; color: var(--subtle); font-size: 0.78rem; font-weight: 700; }

.map-note { margin-top: 10px; font-size: 0.88rem; }

/* name cards show their kind with a small dot beside the name (colour carries meaning, matches the map) */
.name-card .name-text { display: inline-flex; align-items: baseline; gap: 8px; }
.name-card .name-text::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--k-built));
  transform: translateY(-1px);
}
.name-card.is-linked { background: var(--panel-strong); }

/* region places (OpenStreetMap, meaning guessed from roots): rings, never filled, so they can't pass as sourced points */
.map-dot.is-region { fill: var(--panel); stroke-width: calc(var(--u, 1) * 1.5px); }
.map-dot.is-region.k-water { stroke: var(--k-water); }
.map-dot.is-region.k-land { stroke: var(--k-land); }
.map-dot.is-region.k-people { stroke: var(--k-people); }
.map-dot.is-region.k-built { stroke: var(--k-built); }
.map-dot.is-region.k-none { stroke: var(--faded); }
.map-dot.is-region.is-dim { opacity: 0.1; }
.map-wrap.is-previewing .map-dot.is-dim { opacity: 0.06; }

/* loading: a skeleton with a slow shimmer where content will appear, so nothing pops in or freezes */
.skel { display: block; height: 10px; width: var(--w, 60%); margin: 9px 0; border-radius: 5px;
  background: linear-gradient(90deg, hsla(var(--hue-primary), 18%, 50%, 0.1) 0%, hsla(var(--hue-primary), 18%, 50%, 0.2) 40%, hsla(var(--hue-primary), 18%, 50%, 0.1) 80%) 0 0 / 300% 100%;
  animation: skel-shimmer 1.6s ease-in-out infinite; }
.skel[style*="--w:0%"] { height: 0; margin: 14px 0; }
.map-wrap.is-loading::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, hsla(var(--hue-primary), 20%, 50%, 0) 30%, hsla(var(--hue-primary), 20%, 50%, 0.1) 50%, hsla(var(--hue-primary), 20%, 50%, 0) 70%) 0 0 / 250% 100%;
  animation: skel-shimmer 1.8s ease-in-out infinite; }
@keyframes skel-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skel, .map-wrap.is-loading::after { animation: none; } }

/* the canvas draws ground, wards, roads and dots; the SVG above it holds borders, the label and the ring */
.map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.map-wrap svg { position: relative; background: none; }

.map-views { flex-wrap: wrap; row-gap: 4px; }
