/* ==========================================================================
   Wildsforge interactive map (/map/). Needs /assets/site.css loaded first for tokens.
   Leaflet's own stylesheet loads from cdnjs before this file.
   ========================================================================== */

.map-intro { max-width: 760px; margin: 10px 0 14px; }
.map-intro h1 { font-size: clamp(26px, 4.2vw, 36px); }
.map-intro p { margin: 10px 0 0; color: var(--muted); }

/* Panel on the left, map filling the rest; the whole app fits the screen height */
.map-app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: min(78vh, 860px);
  min-height: 480px;
  overflow: hidden;
  overflow: clip; /* like hidden, but the browser can never scroll it (it did, when bringing the layers panel into view) */
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}
.map-panel__head { padding: 12px; border-bottom: 1px solid var(--border); }
.map-panel__head input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.map-panel__actions { display: flex; gap: 8px; margin-top: 8px; }
.map-panel__actions button {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.map-panel__actions button:hover { border-color: var(--accent); }
.map-panel__list { flex: 1; overflow-y: auto; padding: 4px 0 12px; overscroll-behavior: contain; }
.map-panel__close { display: none; }

/* One group: a header row with its own on/off box, then its categories */
.map-group { border-bottom: 1px solid var(--border); }
.map-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
.map-group summary::-webkit-details-marker { display: none; }
.map-group summary::after { content: "▸"; margin-left: auto; color: var(--muted); transition: transform 0.15s; }
.map-group[open] summary::after { transform: rotate(90deg); }
.map-group__count { color: var(--muted); font-size: 12px; font-weight: 400; }
.map-group ul { margin: 0; padding: 0 12px 10px 40px; list-style: none; }
.map-group li { margin: 2px 0; }
.map-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.map-check input { accent-color: var(--accent); }
.map-check span:last-child { margin-left: auto; color: var(--muted); font-size: 12px; }
.map-swatch { width: 22px; height: 22px; flex: none; }
.map-empty { padding: 16px 12px; color: var(--muted); font-size: 14px; }

/* Sea colour sampled from the map tiles, so the area round the map shows as ocean instead of grey */
.map-canvas { position: relative; min-width: 0; background: #677775; }
#map { position: absolute; inset: 0; background: #677775; }
.map-layers-button { display: none; }

/* Shown only if the map image fails to load from the wiki's server */
.map-notice {
  position: absolute;
  left: 50%;
  top: 62px; /* under the zoom and Layers buttons, so it is in view on phones too */
  z-index: 1000;
  width: min(92%, 420px);
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.3);
  transform: translateX(-50%);
}

/* Leaflet controls and popups, in the site's colours */
.map-canvas .leaflet-bar a,
.map-canvas .leaflet-control-attribution,
.map-canvas .leaflet-popup-content-wrapper,
.map-canvas .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.map-canvas .leaflet-bar a { border-color: var(--border); }
.map-canvas .leaflet-control-attribution { font-size: 11px; }
.map-canvas .leaflet-control-attribution a,
.map-canvas .leaflet-popup-content a { color: var(--accent); }
.map-canvas .leaflet-popup-content { margin: 12px 14px; font-size: 14px; line-height: 1.45; }
.map-popup__title { margin: 0; font-size: 15px; font-weight: 700; }
.map-popup__kind { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.map-popup__desc { margin: 6px 0 0; }
.map-popup__links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 8px 0 0; font-size: 13px; }

.map-notes { max-width: 760px; margin: 18px 0 0; color: var(--muted); font-size: 14px; }
.map-notes p { margin: 6px 0; }

/* Phones: full-width map; the Layers button sits top-right so it is always in view, and the
   layers open as a sheet fixed to the bottom of the screen (the map itself can be taller than the screen) */
@media (max-width: 760px) {
  .map-app {
    display: block;
    position: relative;
    height: calc(100dvh - 150px);
    min-height: 420px;
    margin: 0 -16px;
    border-radius: 0;
    border-width: 1px 0;
    /* No clipping here on phones: some mobile browsers (Safari especially) stop drawing a zoomed-in
       map inside a clipped frame. The map trims its own edges, and the layers sheet is fixed to the screen. */
    overflow: visible;
  }
  .map-canvas { position: absolute; inset: 0; }
  .map-layers-button {
    display: inline-flex;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    box-shadow: 0 4px 14px rgb(0 0 0 / 0.3);
  }
  .map-panel {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1100;
    max-height: 70vh;
    max-height: 70dvh;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    background: var(--surface);
    box-shadow: 0 -8px 24px rgb(0 0 0 / 0.3);
    transform: translateY(105%);
    transition: transform 0.25s ease;
  }
  .map-app.is-panel-open .map-panel { transform: none; }
  .map-panel__close {
    display: block;
    margin-left: auto;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 13px;
  }
  .map-panel__top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }
}
@media (min-width: 761px) { .map-panel__top { display: none; } }

@media (prefers-reduced-motion: reduce) { .map-panel { transition: none; } }

/* Readable guide under the map: what's on it, and common questions */
.map-guide { max-width: 760px; margin: 26px 0 0; }
.map-guide h2 { margin: 26px 0 8px; font-size: 21px; }
.map-guide h3 { margin: 16px 0 4px; font-size: 16px; }
.map-guide p, .map-guide li { color: var(--muted); }
.map-guide ul { padding-left: 20px; }
.map-guide li { margin: 5px 0; }
.map-guide strong { color: var(--text); }
