:root {
  --color-bg: #171310;
  --color-header-bg: #0d0b09;
  --color-accent: #d6553f;
  --color-accent-dark: #a8402f;
  /* A lighter tint of --color-accent, for text sitting directly on the
     header's wood-grain photo (.subtitle below) -- the base accent's red
     is dark enough that it reads as low-contrast against the wood's
     lighter grain highlights, even with a text-shadow. */
  --color-accent-light: #ffc2a1;
  --color-parchment: #efe3c8;
  --color-parchment-dark: #ddccA0;
  --color-text-dark: #2b2417;
  --color-text-light: #f4ece0;
  --color-sea: #3333aa; /* matches legend.py's "~" Sea terrain color, not a separate shade */
  --color-border: rgba(0, 0, 0, 0.35);
  --sidebar-width: 320px;
  --header-height: 76px;
  --footer-height: 34px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text-dark);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

/* ---------- Header ---------- */

.site-header {
  height: var(--header-height);
  flex: 0 0 auto;
  background: var(--color-header-bg) url("../img/wood2.jpg") repeat-x;
  color: var(--color-text-light);
  display: flex;
  align-items: center;
  gap: 1em;
  padding: 0 1em;
  box-shadow: 0 2px 8px var(--color-border);
  /* z-index only has an effect on a positioned element -- without this,
     the z-index below was silently ignored (header stayed position:
     static), leaving nothing to stop Leaflet's internal panes (z-index
     200-900, plus `transform` on tiles for GPU positioning) from being
     stacked above page chrome on browsers that don't contain/cap them
     properly -- most visibly on iOS Safari/Chrome (both WebKit-based),
     which has long-standing bugs around transformed elements escaping
     their intended stacking context. isolation:isolate is a second,
     belt-and-braces guard against exactly that. */
  position: relative;
  isolation: isolate;
  z-index: 20;
}

.site-header .logo img {
  display: block;
  height: 56px;
  width: auto;
}

.site-header .titles {
  flex: 1 1 auto;
  min-width: 0;
}

.site-header h1 {
  font-size: 1.3em;
  margin: 0;
  text-shadow: 1px 1px 2px #000;
}

.site-header .subtitle {
  margin: 0;
  font-size: 0.8em;
  color: var(--color-accent-light);
  text-shadow: 1px 1px 1px #000, 0 0 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button, #make-link {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--color-text-light);
  border-radius: 0.4em;
  padding: 0.5em 0.9em;
  font-size: 0.85em;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover, #make-link:hover {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.icon-button {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.icon-button span {
  display: block;
  height: 2px;
  background: var(--color-text-light);
  border-radius: 1px;
}

/* ---------- Layout ---------- */

.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

#map {
  flex: 1 1 auto;
  background: var(--color-sea);
  min-width: 0;
  /* Leaflet's own internal panes (tiles, markers, tooltips, popups) run
     from z-index 200 up to 900, and tiles are positioned with `transform`
     for GPU acceleration. z-index:auto (the default) does NOT establish a
     stacking context, so without an explicit value here those panes
     aren't contained/capped -- their stacking gets resolved against
     whatever ancestor actually does establish one, which on WebKit
     (iOS Safari/Chrome) can mean they paint above unrelated page chrome
     like the header/sidebar instead of staying confined to the map area.
     An explicit z-index (even 0) plus isolation:isolate properly traps
     them inside this box. */
  position: relative;
  isolation: isolate;
  z-index: 0;
}

.leaflet-container {
  background: var(--color-sea);
  font-family: inherit;
}

/* While the ASCII/text layer is both toggled on AND within its supported
   zoom range, the empty-tile background (open ocean outside any
   continent) switches from a flat color to a repeating tile of the same
   "~" glyph the text layer itself uses at that exact zoom level --
   map.js's setupAsciiLayerToggle() sets background-image directly (it
   varies per zoom, ascii-sea-tile-{9,10,11}.png, so it can't be a single
   static rule here); this only supplies the repeat/rendering behavior and
   a solid-black fallback base. */
#map.ascii-mode.leaflet-container {
  background-color: #000;
  background-repeat: repeat;
  image-rendering: pixelated;
}

.load-error {
  padding: 2em;
  color: #900;
  background: #fff;
}

/* ---------- Sidebar ---------- */

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  background: linear-gradient(var(--color-parchment), var(--color-parchment-dark));
  color: var(--color-text-dark);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px var(--color-border);
  /* Same reasoning as .site-header above -- z-index needs a position to
     do anything. This didn't visibly matter on desktop (the sidebar and
     #map are side-by-side flex items, so they never overlap regardless of
     stacking), but the mobile layout below overlays the sidebar on top of
     #map, where it does matter. */
  position: relative;
  isolation: isolate;
  z-index: 10;
}

.sidebar-scroll {
  overflow-y: auto;
  padding: 0.75em;
  flex: 1 1 auto;
}

.search-input {
  width: 100%;
  padding: 0.5em 0.7em;
  margin-bottom: 0.75em;
  border: 1px solid var(--color-parchment-dark);
  border-radius: 0.4em;
  font-size: 0.95em;
  background: rgba(255, 255, 255, 0.6);
}

.filter-group { margin-bottom: 1em; }

/* Shared collapsible-section header (Location type / Continent / Layers /
   Locations) -- see collapsible.js. A plain button so the whole row is
   one click target and gets the right default keyboard/AT semantics. */
.section-header {
  display: flex;
  align-items: center;
  gap: 0.4em;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 0.4em;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

.filter-group h3 {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
  color: var(--color-text-dark);
  opacity: 0.7;
}

/* Plain triangle, no image/font-icon dependency -- rotates to point right
   when its section is collapsed. */
.chevron {
  width: 0;
  height: 0;
  flex: 0 0 auto;
  border-left: 0.3em solid transparent;
  border-right: 0.3em solid transparent;
  border-top: 0.35em solid currentColor;
  opacity: 0.6;
  transition: transform 0.15s ease;
}

.filter-group.is-collapsed .section-body { display: none; }
.filter-group.is-collapsed .chevron { transform: rotate(-90deg); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35em;
}

.chip {
  --chip-color: #888;
  border: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  padding: 0.3em 0.7em;
  font-size: 0.8em;
  cursor: pointer;
  color: var(--color-text-dark);
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}

.chip::before {
  content: "";
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: var(--chip-color);
  flex: 0 0 auto;
}

.chip--all::before { display: none; }

.chip.active {
  background: var(--color-accent);
  border-color: var(--color-accent-dark);
  color: #fff;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.9em;
  cursor: pointer;
  margin-bottom: 0.4em;
}

.toggle-row.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toggle-hint {
  font-size: 0.8em;
  opacity: 0.65;
}

.location-list-group { flex: 1 1 auto; }

.location-group.is-hidden { display: none; }
.location-group { margin-top: 0.6em; }
/* #location-list's real first child is .continent-stack (empty until a
   continent scrolls past it), not the first .location-group -- target it
   directly rather than :first-child so Laenor's group doesn't inherit an
   unwanted top gap. */
.continent-stack + .location-group { margin-top: 0; }

/* Pinned strip above the list -- continent bars get moved in here once
   their whole group scrolls past (see createContinentStackRecomputer in
   markers.js), so previously-visited continents stay visible and
   clickable instead of disappearing as you scroll further down. Packed
   with no gaps so pinned bars sit flush against each other. */
.continent-stack {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
}

.continent-stack:not(:empty) { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); }

/* Pinned bars sit flush against each other -- square corners and a hairline
   divider read as one contiguous strip instead of a stack of separate
   floating pills (the live, not-yet-passed bar below keeps its own
   rounded/shadowed look, so it's visually distinct as "still scrolling"). */
.continent-stack .location-group-heading {
  border-radius: 0;
  box-shadow: none;
}

.continent-stack .location-group-heading + .location-group-heading {
  border-top: 1px solid rgba(0, 0, 0, 0.2);
}

/* Solid-color bar (background set inline per-continent in markers.js).
   Its `position`/`top` are toggled by markers.js between "sticky, docked
   live below the pinned stack" (this continent is the one currently being
   scrolled through) and "static, inside .continent-stack" (fully passed
   and pinned) -- the CSS values below are just its live-docked default. */
.location-group-heading {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: stretch;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  border-radius: 0.3em;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.chevron-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 2em;
  background: rgba(0, 0, 0, 0.12);
  border: none;
  cursor: pointer;
  color: #fff;
}

.chevron-toggle .chevron {
  border-top-color: #fff;
  opacity: 0.9;
}

.location-group.is-collapsed .chevron-toggle .chevron { transform: rotate(-90deg); }

.loc-group-title {
  flex: 1 1 auto;
  background: none;
  border: none;
  text-align: left;
  padding: 0.45em 0.6em;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  color: inherit;
  text-shadow: inherit;
}

.location-group-body { padding-top: 0.3em; }
.location-group.is-collapsed .location-group-body { display: none; }

.loc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0.3em;
  padding: 0.3em 0.5em;
  font-size: 0.85em;
  cursor: pointer;
  color: var(--color-text-dark);
}

.loc-item:hover { background: rgba(0, 0, 0, 0.08); }
.loc-item.is-hidden { display: none; }

/* ---------- Map markers ---------- */

.loc-marker { background: none; border: none; }

.loc-dot {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  /* Thin on purpose -- a heavier ring ate into the visible color area on a
     12px dot, making similarly-lit types (e.g. two warm hues) harder to
     tell apart at a glance. Just enough border to separate the dot from
     whatever terrain color it happens to sit on. */
  border: 1px solid #fff;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

.loc-dot--tradelane {
  width: 6px;
  height: 6px;
  border-width: 0.5px;
  background: #cbd5e1;
}

/* Permanent name-label tooltip (old site's "MarkerWithLabel" look). */
.leaflet-tooltip.loc-label {
  background: rgba(0, 0, 0, 0.75);
  border: 1px dotted rgba(255, 255, 255, 0.6);
  border-radius: 0.2em;
  color: #fff;
  font-size: 0.75em;
  font-weight: bold;
  padding: 1px 4px;
  white-space: nowrap;
  box-shadow: none;
  /* Clickable -- same action as clicking the marker's own dot (see
     markers.js's tooltipopen handler). Leaflet's default .leaflet-tooltip
     rule sets pointer-events: none; override it explicitly here rather
     than relying on the bindTooltip({interactive: true}) option alone. */
  cursor: pointer;
  pointer-events: auto;
}

.leaflet-tooltip.loc-label::before { display: none; }

.player-marker-icon {
  border-radius: 50%;
  border: 2px solid var(--color-accent);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
  background: #222;
}

/* ---------- Footer ---------- */

.site-footer {
  flex: 0 0 var(--footer-height);
  height: var(--footer-height);
  background: var(--color-header-bg);
  color: var(--color-text-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1em;
  font-size: 0.75em;
  gap: 1em;
}

.cursor-readout {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.copyrights {
  opacity: 0.75;
  white-space: nowrap;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--footer-height) + 1em);
  left: 50%;
  transform: translateX(-50%) translateY(0.5em);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 0.6em 1.1em;
  border-radius: 0.4em;
  font-size: 0.85em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  :root { --header-height: 64px; }

  .icon-button { display: flex; }

  .site-header .subtitle { display: none; }
  .site-header .logo img { height: 40px; }
  #make-link { padding: 0.5em 0.6em; font-size: 0.75em; }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: var(--footer-height);
    left: 0;
    width: min(85vw, 340px);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
  }

  .sidebar.is-open { transform: translateX(0); }

  .copyrights { display: none; }
}
