@font-face {
  font-family: "SpecialElite";
  src: url("../fonts/SpecialElite.ttf") format("truetype");
  font-display: swap;
  border-right: 1px solid var(--panel-border);
}

@font-face {
  font-family: "bolf-font";
  src: url("../fonts/bolf-font.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "RobotoBlack";
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url("https://fonts.gstatic.com/s/roboto/v50/KFOMCnqEu92Fr1ME7kSn66aGLdTylUAMQXC89YmC2DPNWuZtammT.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: radial-gradient(circle at 20% 20%, #1d1f27, #0f1116 55%);
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.06);
  --control-border: rgba(255, 255, 255, 0.1);
  --control-bg: rgba(255, 255, 255, 0.05);
  --accent: #ffcc66;
  --text: #e8edf5;
  --muted: #aab3c2;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  --radius: 2px;
  --font: "SpecialElite", "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  --sidebar-panel-width: min(360px, 85vw);
  --sidebar-tab: 68px;
}

:root[data-theme="light"] {
  --bg: radial-gradient(circle at 22% 28%, #f1e7d5, #e4d6b8 55%);
  --panel: rgba(248, 241, 223, 0.95);
  --panel-border: rgba(139, 111, 63, 0.4);
  --control-border: rgba(92, 70, 40, 0.35);
  --control-bg: rgba(92, 70, 40, 0.06);
  --accent: #7a5c2b;
  --text: #2b2416;
  --muted: #5b4a2d;
  --shadow: 0 14px 32px rgba(58, 43, 24, 0.18);
  --font: "SpecialElite", "Georgia", "Times New Roman", serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 18px 48px;
}

.shell {
  width: min(1200px, 100%);
  display: grid;
  gap: 18px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: relative;
  padding-left: 0;
  min-height: 42px;
}

.header-copy {
  flex: 1 1 auto;
}

/* Sidebar Toggle (Unified for desktop/mobile) */
.sidebar-toggle {
  /* Positioning: Always fixed to the screen */
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 2000 !important; /* High but below sidebar */
  
  /* Size & Shape */
  width: 50px;
  height: 50px;
  border-radius: 12px;
  
  /* Visuals */
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  color: var(--text);
  
  /* Flex layout for hamburger icon */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-toggle:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.6);
}

.sidebar-toggle:active {
  transform: translateY(0);
}

.hamburger {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  margin: 2px 0;
}

@media (max-width: 700px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  :root {
    --sidebar-tab: 56px;
    --sidebar-panel-width: min(320px, 82vw);
  }
}

/* FIXED SIDEBAR - Removes ghost borders */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-panel-width);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 2100 !important;
  display: flex;
  flex-direction: column;
  /* CRITICAL: Transparent container */
  padding: 0;
  background: transparent;
  border: none;
  backdrop-filter: none;
  pointer-events: none;
}

.sidebar-open .sidebar {
  transform: translateX(0);
  pointer-events: auto;
}

.sidebar-panel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  /* Visuals moved here */
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  overflow-y: auto;
  pointer-events: auto;
}

.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.sidebar-close {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  transition: color 0.15s ease;
}

.sidebar-close:hover {
  color: var(--accent);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 8px;
}

.sidebar-lede {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.sidebar-tool {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--control-border);
  background: rgba(0, 0, 0, 0.25);
}

:root[data-theme="light"] .sidebar-tool {
  background: rgba(255, 255, 255, 0.7);
}

.sidebar-tool.is-active {
  border-color: var(--accent);
  background: rgba(255, 204, 102, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.sidebar-tool.is-active .eyebrow {
  color: var(--accent);
}

.tool-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.cta {
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #1b1203;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.25);
}

.cta.is-disabled,
.cta:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.ghost-link {
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  opacity: 0.8;
}

.ghost-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.site-version {
  margin-top: 18px;
  text-align: center;
  color: var(--muted);
  font-family: "SpecialElite", var(--font);
  font-size: 12px;
  letter-spacing: 0.6px;
}

:root[data-theme="light"] .site-version {
  color: rgba(43, 36, 22, 0.65);
}

.sidebar-backdrop,
#sidebarBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  z-index: 800;
  transition: opacity 0.3s ease;
  display: none;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.sidebar-open #sidebarBackdrop {
  display: block !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  visibility: visible !important;
}

#sidebarBackdrop[hidden] {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

.title {
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin: 0;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--accent);
  font-size: 14px;
  letter-spacing: 0.2px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  padding: 14px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: relative;
  z-index: 120;
  touch-action: pan-y;
}

.faction-group {
  display: flex;
  gap: 8px;
  margin-right: auto;
}

.faction-group .toggle {
  min-width: 84px;
  text-align: center;
}

.faction-group .toggle:nth-child(3) {
  min-width: 70px;
}

.toggle.active {
  background-color: var(--accent);
  color: #1d1f27;
  font-weight: 700;
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(255, 204, 102, 0.35);
}

:root[data-theme="light"] .toggle.active {
  color: #f1e7d5;
}

@media (max-width: 600px) {
  .faction-group {
    margin-right: 0;
    width: 100%;
    justify-content: center;
  }
}

label {
  font-size: 14px;
  color: var(--muted);
}

select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--text);
  min-width: 200px;
  font-size: 16px;
  height: 44px;
}

select option {
  background: #1a1d24;
  color: #e8edf5;
  opacity: 1;
}

:root[data-theme="light"] select option {
  background: #f1e7d5;
  color: #2b2416;
  opacity: 1;
}

.toggle {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

:root[data-theme="light"] .toggle {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.map-wrap {
  --zoom: 1;
  position: relative;
  
  /* TIGHT WRAPPING MAGIC */
  display: inline-flex;
  width: fit-content;
  height: auto;
  margin: 0 auto;
  overflow: hidden;
  
  /* NEW: Removes the gap caused by the .panel class */
  padding: 0;
  
  border-radius: var(--radius);
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid var(--panel-border);
  background: transparent;
  backdrop-filter: none !important;
  box-shadow: none !important;
  touch-action: none;
}

.map-stage {
  cursor: crosshair;
  touch-action: none;
}

.map-wrap.dragging .map-stage {
  cursor: grabbing;
}

.map-image {
  display: block;
  /* changed from height: 75vh to max-height so it shrinks to fit */
  max-height: 75vh; 
  height: auto;     
  
  width: auto;
  max-width: 100vw;
  
  object-fit: contain;
  
  /* Changed from #06070b to transparent to remove the black bars */
  background: transparent; 
}

.map-picture {
  display: contents;
}

.map-stage {
  width: max-content;
  height: max-content;
  transform-origin: 0 0;
  /* Use translate3d to force hardware acceleration */
  transform: translate3d(var(--pan-x, 0px), var(--pan-y, 0px), 0) scale(var(--zoom));
  will-change: transform;
  backface-visibility: hidden;
  -webkit-font-smoothing: subpixel-antialiased;
}

.map-stage.zoom-transition {
  transition: transform 0.22s ease-out;
}

/* --- OPTIMIZED SVG GRID --- */
.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  will-change: transform;
  transform: translateZ(0);
}

.grid-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  transition: opacity 0.15s;
  will-change: opacity;
}

.grid-line {
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 1.5px;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}

.subgrid-line {
  stroke: rgba(0, 0, 0, 0.4);
  stroke-width: 0.3px;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.detailed-grid .subgrid-line {
  opacity: 1;
}

.grid-labels {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
}

.grid-label-cell {
  position: relative;
}

.grid-label-text {
  position: absolute;
  top: 4px;
  left: 6px;
  font-family: "RobotoBlack", sans-serif;
  font-weight: 900;
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  transform-origin: top left;
  transform: scale(var(--inverse-zoom, 1));
  text-shadow: 1px 1px 2px #000;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* NEW: Style for the Red Dots Overlay */
.markers-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

/* --- UPDATED MARKER STYLES --- */

.marker {
  position: absolute;
  width: 64px;
  height: 64px;
  transform: translate3d(-50%, -50%, 0);
  cursor: pointer;
  pointer-events: auto;
  display: block;
  transform-origin: center center;
  will-change: transform;
}

/* 1. THE PULSE ANIMATION KEYFRAMES */
@keyframes enemy-pulse {
  0% {
    transform: translate(-50%, -50%) scale(0.55);
    opacity: 0.95;
  }
  65% {
    transform: translate(-50%, -50%) scale(2.6);
    opacity: 0.4;
  }
  100% {
    transform: translate(-50%, -50%) scale(3.2);
    opacity: 0;
  }
}

/* 2. THE PULSING RING */
.marker::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60%;
  height: 60%;
  transform: translate(-50%, -50%) scale(0.55);
  transform-origin: center center;
  box-sizing: border-box;
  border-radius: 50%;
  background-color: rgba(255, 70, 70, 0.32);
  border: 2px solid rgba(255, 90, 90, 0.75);
  box-shadow: 0 0 18px rgba(255, 70, 70, 0.45);
  animation: enemy-pulse 2s ease-out infinite;
  pointer-events: none;
  z-index: 1;
}

/* 3. THE ICON ITSELF */
.marker > img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  display: block;
  z-index: 2;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.65)) drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
  background: none;
  border-radius: 50%;
  transform-origin: center center;
  transform: translate(-50%, -50%);
  transition: transform 0.2s ease;
}

/* 4. HOVER EFFECT */
.markers-layer:not(.has-selection) .marker:hover > img {
  transform: translate(-50%, -50%) scale(1.2);
}

.markers-layer:not(.has-selection) .marker:hover::before {
  animation: none;
  transform: translate(-50%, -50%) scale(1.2);
  opacity: 1;
  background-color: rgba(255, 50, 50, 0.2);
  box-shadow: 0 0 10px rgba(255, 50, 50, 0.8);
  border: 1px solid rgba(255, 50, 50, 0.6);
}

/* --- NEW HTML LABEL STYLES --- */

/* Soft base shadow */
.marker::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  height: 18px;
  transform: translate(-50%, -8%) scale(1);
  background: radial-gradient(circle, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.25) 45%, transparent 75%);
  filter: blur(3px);
  opacity: 0.95;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.marker:hover::after,
.marker.active::after {
  opacity: 0.75;
  transform: translate(-50%, -8%) scale(1.2);
}

/* --- MOBILE LAYOUT SUPPORT --- */
@media (max-width: 768px) {
  body {
    padding: 0;
    height: 100dvh; /* Use dynamic viewport height */
    overflow: hidden;
  }

  /* 1. Full Screen Map */
  .shell {
    width: 100%;
    height: 100%;
    gap: 0;
    display: flex;
    flex-direction: column;
  }

  .map-wrap {
    position: relative;
    top: auto; left: auto;
    width: 100%; 
    height: 100%;
    flex: 1 1 auto;
    border: none;
    border-radius: 0;
    z-index: 1;
    /* CRITICAL: Stop browser handling gestures */
    touch-action: none; 
  }

  .map-image {
    max-height: none;
    width: 100%; height: 100%;
    object-fit: cover;
  }

  /* 2. Header placed above map */
  header {
    position: fixed;
    top: 20px;
    left: 80px; /* leave space for button */
    right: 10px;
    z-index: 20;
    pointer-events: none;
    display: flex;
    justify-content: center;
    padding: 0;
    background: transparent;
  }

  .header-copy {
    background: rgba(15, 17, 22, 0.85);
    backdrop-filter: blur(8px);
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    pointer-events: auto;
    display: inline-block;
    width: auto;
    max-width: 100%;
    text-align: center;
  }
  .subtitle { display: none; } /* Save space */
  .title {
    font-size: 12px;
    letter-spacing: 0.5px;
    line-height: 1.2;
    margin: 0;
  }

  /* 3. Bottom Controls Tray */
  .panel.controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    flex-direction: column;
    padding: 16px;
    z-index: 100;
    background: rgba(15, 17, 22, 0.95);
    border: 1px solid var(--accent);
    border-bottom: none;
    gap: 12px;
    touch-action: pan-y; /* Allow scrolling inside panel */
  }

  /* Adjust inputs for touch */
  select {
    width: 100%;
    height: 44px;
    font-size: 16px; /* Prevents iOS zoom */
  }
  
  .faction-group {
    width: 100%;
    display: flex;
  }
  .faction-group .toggle { flex: 1; }
  
  /* Hide Legend to save space */
  .legend { display: none; }

  /* 5. Markers: Fix Touch Target & Alignment */
  .marker {
    width: 44px; /* Big touch target */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .marker img {
    /* Restore visual size */
    width: 32px !important; 
    height: 32px !important;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Ensure ring matches icon size, not touch target size */
  .marker::before {
    width: 32px !important;
    height: 32px !important;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Fix flag alignment in labels */
  .label-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
}

/* Container for the label and buttons */
.marker-label {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  margin-bottom: 14px;
  
  /* Visual styling */
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 4px 6px;
  
  /* Layout */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 120px; /* Ensures buttons don't jump around */
  
  /* Hidden by default */
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

/* 1. ACTIVE STATE (High Priority) */
/* Always show the label when active */
.marker.active .marker-label {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  transform: translateX(-50%) translateY(-5px);
}

/* 2. HOVER STATE (Conditional) */
/* Only show hover label if NO selection is currently active */
.markers-layer:not(.has-selection) .marker:hover .marker-label {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateX(-50%) translateY(-5px);
}

/* The Text Span */
.label-text {
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-family: "RobotoBlack", sans-serif;
  text-align: center;
  flex-grow: 1;
  user-select: none;
  white-space: nowrap;
  
  /* --- FLEXBOX ALIGNMENT --- */
  display: inline-flex;
  flex-direction: row; /* Force left-to-right layout */
  align-items: center; /* Vertically center items */
  justify-content: center; /* Center the group in the label box */
  gap: 8px; /* Space between flag and text */
}

/* Ensure the flag behaves as a flex item, not absolute */
.label-flag {
  height: 16px;
  width: auto;
  object-fit: contain;
  margin: 0; 
  display: block; /* Important: remove inline-block quirks */
  position: static; /* Important: prevent it from floating away */
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
  flex-shrink: 0; /* Don't let the flag squash */
}

.label-copy {
  display: inline-block;
  line-height: 1; /* Prevent vertical misalignment */
}

/* The Arrow Buttons */
.nav-arrow {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  padding: 0 4px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, color 0.1s;
}

.nav-arrow:hover {
  color: #ffffff;
  transform: scale(1.2);
  text-shadow: 0 0 5px var(--accent);
}

.nav-arrow:active {
  transform: scale(0.95);
}

.legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--control-bg);
  border: 1px solid var(--control-border);
}

.chip img {
  width: 20px;
  height: 20px;
}

.note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.zoom-overlay {
  position: absolute;
  right: 30px;
  bottom: 30px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 0;
  background: transparent;
  color: var(--text);
  pointer-events: none;
  z-index: 20;
}

:root[data-theme="light"] .zoom-overlay {
  background: transparent;
}

.map-wrap.dragging {
  cursor: grabbing;
}

.map-wrap.dragging .map-stage {
  transition: none !important;
}

.scale-wrapper {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 0px;
  pointer-events: none;
  transition: width 0.1s linear;
}

.scale-bar-graphic {
  position: relative;
  height: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0, 0, 0, 0.6);
  width: 100%;
}

.scale-bar-graphic::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 50%;
  background: rgba(255, 255, 255, 0.8);
}

.scale-tick {
  position: absolute;
  bottom: -6px;
  width: 2px;
  height: 8px;
  background: #fff;
  z-index: 2;
  text-shadow: 0 1px 2px black;
}

.t-start { left: 0; }
.t-mid   { left: 50%; transform: translateX(-50%); }
.t-end   { right: 0; }

.scale-labels {
  display: flex;
  width: 100%;
  height: 20px;
  position: relative;
  margin-top: 6px;
}

.zoom-lbl {
  font-family: "RobotoBlack", sans-serif;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  text-shadow: 2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000;
  margin-bottom: 2px;
  text-align: right;
}

.scale-lbl {
  font-family: "RobotoBlack", sans-serif;
  font-size: 12px;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
  position: absolute;
  transform: translateX(-50%);
}

.l-start { left: 0; }
.l-mid   { left: 50%; }
.l-end   { left: 100%; }

@media (max-width: 720px) {
  body { padding: 22px 14px; }
  .map-wrap { border-radius: 10px; }
  .marker { width: 36px; height: 36px; }
}

/* --- ACTIVE MARKER STATE --- */

/* 1. Fix the Shadow (::after) to stay BEHIND the icon */
.marker.active::after {
  opacity: 0.8;     /* Slightly darker shadow when active */
  z-index: 0;       /* IMPORTANT: Keep this at 0 so it stays behind the image */
  transform: translate(-50%, -8%) scale(1.3); /* Grow the shadow slightly */
  
  /* Remove border/box-shadow from the shadow element, 
     as it creates a weird box around the oval gradient */
  border: none;     
  box-shadow: none; 
}

/* 2. Highlight the icon */
.marker.active > img {
  transform: translate(-50%, -50%) scale(1.3);
  filter: drop-shadow(0 0 8px rgba(255, 204, 60, 0.9));
  z-index: 50; /* Image sits on top of the shadow */
}

/* 3. Change the pulse ring color for the active one */
.marker.active::before {
  border-color: var(--accent);
  background-color: rgba(255, 204, 60, 0.3);
  opacity: 1;
  animation: none;
  transform: translate(-50%, -50%) scale(1.3);
  z-index: 1; /* Ring sits between shadow and image */
}

/* --- LOADING OVERLAY --- */
.map-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 17, 22, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(4px);
}

.map-loader.visible {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--control-bg);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}

.loading-text {
  color: var(--accent);
  font-family: "SpecialElite", sans-serif;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Coordinate readout */
.coord-readout {
  position: absolute;
  left: 16px;
  bottom: 16px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-family: "RobotoBlack", sans-serif;
  font-size: 13px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.coord-readout.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Force clicks to pass through overlays so they hit the map */
.map-overlay, 
.grid-overlay, 
.markers-layer {
  pointer-events: none !important;
}

/* Allow clicking on the markers themselves */
.marker {
  pointer-events: auto !important;
}

/* css/style.css - Performance Patch */

/* 1. HIDE THE HEAVY GRID WHILE ZOOMING */
/* This is the #1 performance fix. It stops the expensive recalculations. */
.is-interacting .grid-overlay {
  opacity: 0;
  transition: opacity 0.05s ease; /* Fade out instantly */
}

/* 2. DISABLE FANCY IMAGE SMOOTHING */
/* While moving, use "pixelated" rendering which is 10x faster */
.is-interacting .map-image {
  image-rendering: pixelated; 
}

/* 3. DISABLE SHADOWS & BLURS */
/* Shadows force the GPU to repaint the whole area every frame */
.is-interacting .map-wrap {
  box-shadow: none !important;
  backdrop-filter: none !important;
}

/* 4. SIMPLIFY MARKERS */
/* Hide the pulsing rings and shadows while zooming */
.is-interacting .marker::before,
.is-interacting .marker::after {
  display: none !important;
}
.is-interacting .marker img {
  filter: none !important; /* Removes the drop-shadow on the icon */
}

/* 5. SMOOTH RETURN */
/* When you stop zooming, fade everything back in nicely */
.grid-overlay, .marker, .map-wrap {
  transition: opacity 0.15s, box-shadow 0.15s, filter 0.15s;
}

/* --- MOBILE LAYOUT OVERRIDES --- */
@media (max-width: 768px) {
  body {
    padding: 0;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
  }

  /* 1. Full Screen Map */
  .shell {
    width: 100%;
    height: 100%;
    gap: 0;
    display: flex;
    flex-direction: column;
  }

  .map-wrap {
    position: relative;
    width: 100%; 
    height: 100%;
    flex: 1 1 auto;
    border: none;
    border-radius: 0;
    z-index: 1;
    touch-action: none; 
    margin: 0; 
  }

  .map-image {
    max-height: none;
    width: 100%; height: 100%;
    object-fit: cover;
  }

  /* 2. Header: Positioned Top-Left (Next to Button) */
  header {
    position: fixed;
    top: 10px;      /* Align vertically with button */
    left: 70px;     /* Push right to clear the button (50px button + 20px gap) */
    right: 10px;    /* Stop before right edge */
    z-index: 20;
    padding: 0;
    pointer-events: none;
    display: flex;
    justify-content: flex-start; /* Align text block to the left */
    background: transparent;
    align-items: flex-start; /* Align top */
  }

  .header-copy {
    background: rgba(15, 17, 22, 0.90);
    backdrop-filter: blur(8px);
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--control-border);
    pointer-events: auto;
    text-align: left;
    width: auto;
    /* Limit width to ensure wrapping happens before screen edge */
    max-width: 100%; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }

  .title { 
    font-size: 13px;
    letter-spacing: 0.5px;
    color: var(--accent);
    text-shadow: 0 1px 2px black;
    line-height: 1.3;
    margin: 0;
    
    /* Allow Text Wrapping */
    white-space: normal; 
    overflow: visible;
    text-overflow: clip;
    word-wrap: break-word;
  }
  
  .subtitle { display: none; } 

  /* 3. Sidebar Button (Fixed Top Left) */
  .sidebar-toggle {
    top: 10px; 
    left: 10px;
    width: 50px; 
    height: 50px;
    background: rgba(15, 17, 22, 0.90) !important;
    border: 1px solid var(--control-border) !important;
    border-radius: 12px;
    z-index: 2000 !important; /* Ensure high z-index, but lower than sidebar */
  }

  /* 4. Controls Panel (Bottom) */
  .panel.controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    flex-direction: column;
    padding: 16px;
    z-index: 100;
    background: rgba(15, 17, 22, 0.95);
    border-top: 1px solid var(--accent);
    gap: 12px;
    max-height: 60vh;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .panel.controls > label:first-child { display: none; }
  
  .panel.controls > select:first-of-type {
    width: 100%;
    margin-bottom: 8px;
    font-size: 16px;
    height: 44px;
  }

  .faction-group {
    width: 100%;
    display: flex;
  }
  .faction-group .toggle { flex: 1; min-width: auto; }

  .panel.controls > .toggle:last-child {
    width: 100%;
    margin-top: 4px;
  }

  /* 5. Version Tag: Centered bottom (Lifted slightly up) */
  .site-version {
    position: absolute;
    /* Increased from 12px to 35px to lift it up */
    bottom: calc(35px + env(safe-area-inset-bottom, 0px)); 
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    top: auto;
    
    margin: 0;
    padding: 0;
    
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-family: "SpecialElite", monospace;
    font-size: 11px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 10;
    width: max-content;
  }
  
  /* Zoom/Scale Overlay: Stacked above Version Tag */
  .zoom-overlay {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    
    /* Increased from 32px to 60px to keep spacing relative to version tag */
    bottom: calc(60px + env(safe-area-inset-bottom, 0px)); 
    
    display: flex;
    flex-direction: column;
    align-items: center; 
    text-align: center;
    
    background: transparent;
    pointer-events: none;
    z-index: 10;
    width: auto;
  }

  /* Hide Legend */
  .legend { display: none; }

  /* 5. Markers: Fix Touch Target & Alignment */
  .marker {
    width: 44px; /* Big touch target */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* CRITICAL FIX: Added ">" to only target the garrison icon, not the flag */
  .marker > img {
    width: 32px !important; 
    height: 32px !important;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Ensure ring matches icon size */
  .marker::before {
    width: 75% !important; 
    height: 75% !important;
  }
  
  /* Ensure Label Layout is correct */
  .label-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  
  /* Ensure flag is static (not absolute) so it sits next to text */
  .label-flag {
    position: static !important;
    transform: none !important;
    margin: 0 !important;
  }

  /* Sidebar Fix */
  .sidebar { backdrop-filter: none !important; }
}

/* --- MOBILE PANEL TOGGLE (DROPBAR) --- */
@media (max-width: 768px) {
  /* 1. The Toggle Handle button */
  .controls-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    
    position: absolute;
    top: -28px; /* Height of the handle, sitting on top */
    left: 50%;
    transform: translateX(-50%);
    
    width: 60px;
    height: 28px;
    
    background: rgba(15, 17, 22, 0.95); /* Match your dark panel bg */
    border: 1px solid var(--accent);
    border-bottom: none; /* Connect visually to the panel */
    border-radius: 8px 8px 0 0;
    
    cursor: pointer;
    z-index: 110;
    padding: 0;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.25);
  }

  /* 2. The Chevron Icon (CSS arrow) */
  .controls-toggle::after {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--accent);
    border-bottom: 2px solid var(--accent);
    transform: rotate(45deg) translate(-2px, -2px); /* Points Down initially */
    transition: transform 0.3s ease;
  }

  /* 3. Enable Smooth Animation on the Panel */
  .panel.controls {
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    transform: translateY(0); /* Default state: Visible */
  }

  /* 4. Minimized State (Hidden) */
  .panel.controls.minimized {
    /* Moves the panel 100% down. The handle remains visible because of top: -28px */
    transform: translateY(100%); 
  }

  /* 5. Flip the arrow when minimized */
  .panel.controls.minimized .controls-toggle::after {
    transform: rotate(-135deg) translate(-2px, -2px); /* Points Up */
  }
}

/* Hide toggle on desktop */
@media (min-width: 769px) {
  .controls-toggle {
    display: none;
  }
}

/* PERFORMANCE BOOSTERS */
.map-stage {
  /* Tells browser this element is independent. Huge boost for moving elements. */
  contain: layout paint style; 
  will-change: transform;
}

.marker {
  /* Markers don't affect the layout of the map image */
  contain: layout style;
}

.grid-overlay {
  /* The grid is complex, isolate it */
  contain: strict;
}

/* Removes the grey tap highlight on mobile */
.marker, 
.nav-arrow, 
.controls-toggle, 
button, 
select {
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

/* Prevent context menu and save image on map */
.map-image,
.map-stage,
.map-wrap {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  pointer-events: none;
}

.map-stage {
  pointer-events: auto;
}
