/**
 * Map root + canvas stack.
 *
 * The paint order here (tiles → shadow-lift blend → PA field → overlay) is
 * consumed by the canvas rendering engine (map_view.js and its engine_*
 * controllers), which this redesign does not touch. Z-indices, the
 * ::before/::after filter pseudo-elements, and the --map-* custom properties
 * they read (written per-theme by config.js applyMapFilterVars) are load-
 * bearing infrastructure, not decoration — preserved exactly.
 */

#layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  min-height: 0;
  min-width: 0;
}
aside, section { min-height: 0; }

#mapPane {
  position: relative;
  background: var(--ink-950);
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
}

#mapRoot {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Filtered background layer — matches tile filters so loading areas blend. */
#mapRoot::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-map-bg);
  background: var(--map-bg, var(--ink-850));
  filter: saturate(var(--map-saturate, 1)) brightness(var(--map-brightness, 1)) contrast(var(--map-contrast, 1));
  pointer-events: none;
}

#tilesCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-map-tiles);
  touch-action: none;
  will-change: transform;
}

/* Shadow-lift mix layer, between tiles and the pollution field. */
#mapRoot::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-map-lift);
  pointer-events: none;
  background: rgb(160, 170, 186);
  opacity: var(--map-shadow-lift);
  mix-blend-mode: screen;
}

#paFieldCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-map-field);
  pointer-events: none;
  will-change: transform;
}

#overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-map-overlay);
  touch-action: none;
  will-change: transform;
}

/* Map shades: a dim scrim with a centered word. #mapLoadingShade shows
   LOADING; #pbPausedShade shows PAUSED (paused, live view) — same treatment,
   same code path. pointer-events pass through so the map stays interactive. */
#mapLoadingShade,
#pbPausedShade {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-100);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  pointer-events: none;
}
#mapLoadingShade {
  z-index: var(--z-map-shade);
  background: var(--scrim-strong);
}
#pbPausedShade {
  z-index: var(--z-map-overlay);
  background: var(--scrim-weak);
  transition: opacity var(--ease-emphasized);
}
#mapLoadingShade.hidden,
#pbPausedShade.hidden { display: none; }

/* ◀◀ REW badge: kept in the DOM, hidden pending a future decision (per the
   session's own note on this component). */
#pbRewBadge { display: none; }

/* ── Floating map-overlay icon buttons (camera replay / center-fit) ── */
#camReplayBtn,
#camCenterBtn {
  position: absolute;
  right: var(--space-3);
  z-index: var(--z-camera-btn);
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 1px solid var(--hairline);
  background: var(--ink-900);
  color: var(--ink-500);
  font-size: var(--text-xs);
  font-family: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background var(--ease-standard), color var(--ease-standard), width var(--ease-standard);
  line-height: 1;
  white-space: nowrap;
  padding: 0;
}
#camReplayBtn { top: 110px; display: none; }
#camReplayBtn.visible { display: flex; }
#camCenterBtn { top: 150px; display: flex; }
#camReplayBtn:hover,
#camCenterBtn:hover { background: var(--ink-800); color: var(--ink-100); }
#camReplayBtn.replaying {
  color: oklch(65% 0.18 25);
  border-color: oklch(65% 0.18 25 / 0.4);
  width: auto;
  padding: 0 var(--space-2);
}

.camClientPicker {
  position: absolute;
  top: 110px;
  right: 52px;
  z-index: var(--z-topbar);
  background: var(--ink-900);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-raised);
  max-height: 260px;
  overflow-y: auto;
  min-width: 150px;
  padding: var(--space-1) 0;
}
.camClientPicker.hidden { display: none; }
.camClientItem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: var(--text-xs);
  color: var(--ink-500);
  white-space: nowrap;
  transition: background var(--ease-standard);
}
.camClientItem:hover { background: var(--ink-800); color: var(--ink-100); }
.camClientItem .count { opacity: 0.6; font-size: var(--text-2xs); }
