/* World Map "Layers" drawer (right edge), redesigned: wider glass panel, sticky header, group rows
 * with switches, sub-layers as compact checkbox rows, a cleaner edge tab and a smoother slide.
 * Markup comes from worldmap.js (buildLegendAndToggles); open/close from worldmap-ui.js. Loaded
 * after worldmap-ui.css, which styles these with !important, hence the !important here. */
#worldMapControls.wm-controls {
  --l-fg: #f5f5f2;
  --l-muted: rgba(245, 245, 242, .58);
  --l-faint: rgba(255, 255, 255, .09);
  --l-hover: rgba(255, 255, 255, .06);
  width: min(318px, calc(100% - 52px)) !important;
  right: 34px !important;
  max-height: min(78dvh, calc(100dvh - 120px)) !important;
  padding: 0 0 10px !important;
  border-radius: 16px !important;
  border: 1px solid var(--l-faint) !important;
  background: rgba(10, 10, 12, .93) !important;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .55) !important;
  backdrop-filter: blur(18px) saturate(1.2) !important;
  color: var(--l-fg) !important;
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif !important;
  opacity: 0;
  transform: translate(0, -50%) translateX(24px) !important;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .2s ease, visibility 0s linear .28s !important;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .22) transparent;
}
#worldMapControls.wm-controls.wm-ui-layers-open {
  padding-top: 0 !important;
  opacity: 1;
  transform: translate(0, -50%) !important;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .2s ease, visibility 0s !important;
}

/* Close button: small icon in the header corner */
#worldMapControls > .wm-panel-close {
  position: absolute !important; top: 12px !important; right: 12px !important; z-index: 6 !important;
  width: 28px; height: 28px; min-height: 0 !important; padding: 0 !important;
  border: 0 !important; border-radius: 8px !important; background: transparent !important;
  color: var(--l-muted) !important; font-size: 0 !important;
}
#worldMapControls.wm-ui-layers-open > .wm-panel-close { display: grid !important; place-items: center; }
#worldMapControls > .wm-panel-close::before { content: '✕'; font-size: 13px; }
#worldMapControls > .wm-panel-close:hover { background: var(--l-hover) !important; color: var(--l-fg) !important; }

/* Sticky header: title + Show all / Hide all */
#worldMapControls .wm-panel-title {
  position: sticky; top: 0; z-index: 5;
  display: flex !important; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 0 4px !important; padding: 14px 52px 12px 16px !important;
  border-bottom: 1px solid var(--l-faint) !important;
  background: rgba(10, 10, 12, .97) !important;
  color: var(--l-fg) !important;
  font: 700 15px/1.2 -apple-system, BlinkMacSystemFont, 'Inter', sans-serif !important;
  letter-spacing: -.01em !important; text-transform: none !important;
}
#worldMapControls .wm-panel-title > span { display: inline-flex; gap: 6px; }
#worldMapControls .wm-panel-title .wm-link-btn {
  height: 26px; padding: 0 10px !important; margin: 0 !important;
  border: 1px solid var(--l-faint) !important; border-radius: 999px !important; background: transparent !important;
  color: var(--l-muted) !important; font: 600 11.5px/1 -apple-system, BlinkMacSystemFont, 'Inter', sans-serif !important;
  text-transform: none !important; letter-spacing: 0 !important; text-decoration: none !important; cursor: pointer;
}
#worldMapControls .wm-panel-title .wm-link-btn:hover { color: var(--l-fg) !important; background: var(--l-hover) !important; }

/* Rows */
#worldMapControls .wm-toggle {
  display: flex !important; align-items: center !important; gap: 10px !important;
  min-height: 34px; margin: 0 8px !important; padding: 6px 8px !important;
  border-radius: 9px; color: var(--l-fg) !important; cursor: pointer; text-align: left !important;
  transition: background .12s;
}
#worldMapControls .wm-toggle:hover { background: var(--l-hover); }
/* Group rows: bold, separated, switch on the right */
#worldMapControls .wm-toggle:not(.wm-toggle-sub) {
  margin-top: 8px !important; padding-top: 10px !important; padding-bottom: 8px !important;
  font-weight: 650; font-size: 13.5px;
}
#worldMapControls .wm-toggle:not(.wm-toggle-sub) ~ .wm-toggle:not(.wm-toggle-sub) { border-top: 1px solid var(--l-faint); border-radius: 0 0 9px 9px; }
#worldMapControls .wm-toggle-sub { min-height: 30px; padding-left: 12px !important; color: rgba(245, 245, 242, .82) !important; font-size: 12.5px; font-weight: 450; }
#worldMapControls .wm-toggle-text { flex: 1 1 auto; min-width: 0; color: inherit !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Inputs: switches for groups, small checkboxes for sub-layers */
#worldMapControls .wm-toggle input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: 0 0 auto; order: 3; margin: 0 !important; cursor: pointer;
  position: relative; outline: none;
}
#worldMapControls .wm-toggle:not(.wm-toggle-sub) input[type="checkbox"] {
  width: 32px; height: 18px; border-radius: 999px; background: rgba(255, 255, 255, .16); transition: background .18s;
}
#worldMapControls .wm-toggle:not(.wm-toggle-sub) input[type="checkbox"]::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .4); transition: transform .18s cubic-bezier(.2, .8, .2, 1);
}
#worldMapControls .wm-toggle:not(.wm-toggle-sub) input[type="checkbox"]:checked { background: #22c55e; }
#worldMapControls .wm-toggle:not(.wm-toggle-sub) input[type="checkbox"]:checked::after { transform: translateX(14px); }
#worldMapControls .wm-toggle-sub input[type="checkbox"] {
  width: 16px; height: 16px; border-radius: 5px; border: 1.5px solid rgba(255, 255, 255, .35); background: transparent; transition: background .12s, border-color .12s;
}
#worldMapControls .wm-toggle-sub input[type="checkbox"]:checked { background: var(--l-fg); border-color: var(--l-fg); }
#worldMapControls .wm-toggle-sub input[type="checkbox"]:checked::after {
  content: ''; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px;
  border: solid #0a0a0c; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
#worldMapControls .wm-toggle input[type="checkbox"]:focus-visible { box-shadow: 0 0 0 2px rgba(255, 255, 255, .6); }

/* Legend symbols: a fixed slot so labels line up */
#worldMapControls .wm-toggle > :is(.wm-dot, .wm-swatch, .wm-lane-swatch, .wm-site-swatch, svg, img) { flex: 0 0 auto; order: 0; }
#worldMapControls .wm-toggle > .wm-toggle-text { order: 1; }
#worldMapControls .wm-dot { width: 10px !important; height: 10px !important; margin: 0 4px !important; border-radius: 50% !important; }
#worldMapControls .wm-swatch { width: 16px !important; height: 11px !important; border-radius: 3px !important; }

/* Solo: appears on hover, sits before the switch */
#worldMapControls .wm-solo {
  order: 2; flex: 0 0 auto; height: 20px; padding: 0 7px !important; margin: 0 !important;
  border: 1px solid var(--l-faint) !important; border-radius: 6px !important; background: transparent !important;
  color: var(--l-muted) !important; font: 600 10px/18px -apple-system, BlinkMacSystemFont, 'Inter', sans-serif !important;
  letter-spacing: .02em !important; text-transform: none !important; opacity: 0; transition: opacity .12s;
}
#worldMapControls .wm-toggle:hover .wm-solo, #worldMapControls .wm-solo:focus-visible { opacity: 1; }
#worldMapControls .wm-solo:hover { color: var(--l-fg) !important; background: var(--l-hover) !important; }
#worldMapControls .wm-solo.wm-solo-on { opacity: 1; background: #16a34a !important; border-color: #22c55e !important; color: #fff !important; }

/* Embedded sections (resources, networks, live news…) */
#worldMapControls :is(.wm-respanel, .wm-networks, .wm-live, .wm-site-catalog) { margin: 8px 16px 0 !important; color: var(--l-fg) !important; }
#worldMapControls :is(input[type="search"], input[type="text"], select) {
  min-height: 32px; padding: 6px 10px !important; border: 1px solid var(--l-faint) !important; border-radius: 8px !important;
  background: rgba(0, 0, 0, .35) !important; color: var(--l-fg) !important; font-size: 12.5px !important;
}
#worldMapControls :is(.wm-respanel, .wm-networks) button:not(.wm-solo) { border-radius: 8px !important; }

/* Edge tab: slim glass pill with an icon */
#wmLayersToggle.wm-layer-edge-tab {
  width: 34px !important; min-height: 104px !important; padding: 12px 0 !important; gap: 10px !important;
  align-items: center !important; justify-content: center !important;
  border: 1px solid rgba(255, 255, 255, .12) !important; border-right: 0 !important; border-radius: 12px 0 0 12px !important;
  background: rgba(10, 10, 12, .9) !important; color: rgba(245, 245, 242, .85) !important;
  backdrop-filter: blur(14px) !important; box-shadow: -8px 0 24px rgba(0, 0, 0, .35) !important;
  font: 600 11px/1 -apple-system, BlinkMacSystemFont, 'Inter', sans-serif !important; letter-spacing: .14em !important; text-transform: uppercase !important;
  transition: background .15s, color .15s, width .15s !important;
}
#wmLayersToggle.wm-layer-edge-tab::before {
  content: ''; width: 16px; height: 16px; flex: 0 0 auto; writing-mode: horizontal-tb;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M12 3 2 8l10 5 10-5z'/%3E%3Cpath d='m2 13 10 5 10-5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M12 3 2 8l10 5 10-5z'/%3E%3Cpath d='m2 13 10 5 10-5'/%3E%3C/svg%3E") center / contain no-repeat;
}
#wmLayersToggle.wm-layer-edge-tab span { display: none !important; }
#wmLayersToggle.wm-layer-edge-tab:hover,
#wmLayersToggle.wm-layer-edge-tab[aria-expanded="true"] { background: rgba(28, 28, 32, .95) !important; color: #fff !important; }

@media (max-width: 900px) {
  #worldMapControls.wm-controls { width: min(318px, calc(100% - 46px)) !important; right: 34px !important; }
}
@media (prefers-reduced-motion: reduce) {
  #worldMapControls.wm-controls, #worldMapControls.wm-controls.wm-ui-layers-open { transition: none !important; }
}
#worldMapControls .wm-toggle input[type="checkbox"] { min-width: 0 !important; min-height: 0 !important; padding: 0 !important; box-sizing: border-box !important; }
#worldMapControls .wm-toggle-sub input[type="checkbox"] { width: 16px !important; height: 16px !important; }
#worldMapControls .wm-toggle:not(.wm-toggle-sub) input[type="checkbox"] { width: 32px !important; height: 18px !important; border: 0 !important; }

/* Drawer behaviour: the panel sits flush against the edge tab and slides out from behind it
   (the tab stays put and stays hoverable, so the hover-open logic never sees a gap). */
#worldMapControls.wm-controls {
  right: 34px !important;
  width: min(330px, calc(100% - 50px)) !important;
  max-height: min(84dvh, calc(100% - 96px)) !important;
  border-right: 0 !important;
  border-radius: 16px 0 0 16px !important;
  opacity: 1;
  transform: translate(0, -50%) translateX(calc(100% + 40px)) !important;
  box-shadow: -18px 0 50px rgba(0, 0, 0, .5) !important;
  transition: transform .34s cubic-bezier(.22, 1, .36, 1), visibility 0s linear .34s !important;
}
#worldMapControls.wm-controls.wm-ui-layers-open {
  transform: translate(0, -50%) !important;
  transition: transform .34s cubic-bezier(.22, 1, .36, 1), visibility 0s !important;
}
/* While open the tab takes the panel's colour so the two read as one sheet. */
#wmLayersToggle.wm-layer-edge-tab[aria-expanded="true"] {
  background: rgba(10, 10, 12, .97) !important; color: #fff !important;
  border-color: rgba(255, 255, 255, .09) !important; box-shadow: none !important;
}
@media (max-width: 900px) {
  #worldMapControls.wm-controls { right: 34px !important; width: min(330px, calc(100% - 50px)) !important; }
}

/* Icon-only edge tab (the accessible name stays "Layers" via aria-label). */
#wmLayersToggle.wm-layer-edge-tab {
  width: 38px !important; min-height: 0 !important; height: 44px !important; padding: 0 !important;
  font-size: 0 !important; letter-spacing: 0 !important; writing-mode: horizontal-tb !important;
  display: grid !important; place-items: center !important;
}
#wmLayersToggle.wm-layer-edge-tab::before { width: 18px; height: 18px; }
#worldMapControls.wm-controls { right: 38px !important; }
@media (max-width: 900px) { #worldMapControls.wm-controls { right: 38px !important; } }
