:root {
  color-scheme: dark;
  --bg: #080b11;
  --surface: rgba(15, 19, 27, 0.94);
  --surface-raised: rgba(27, 33, 44, 0.88);
  --surface-hover: rgba(42, 50, 65, 0.92);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f7fa;
  --muted: #9ba6b7;
  --accent: #d9a45b;
  --accent-bright: #f3c77f;
  --accent-soft: rgba(217, 164, 91, 0.16);
  --danger: #ef7d7d;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  --radius-xl: 24px;
  --radius-lg: 17px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button,
summary,
select,
.toggle-switch {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  background: #05070a;
}

/* Sidebar */
#menu {
  position: fixed;
  top: 16px;
  bottom: auto;
  left: 16px;
  z-index: 1100;
  display: flex;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(135%);
  -webkit-backdrop-filter: blur(22px) saturate(135%);
  transition: width 180ms ease, height 180ms ease, background 180ms ease, border-color 180ms ease;
}

.menu-header {
  display: flex;
  min-height: 76px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 16px 14px 18px;
  border-bottom: 1px solid var(--border);
}

.map-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.map-brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid rgba(243, 199, 127, 0.32);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(217, 164, 91, 0.28), rgba(217, 164, 91, 0.08));
  color: var(--accent-bright);
  font-size: 20px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.map-brand-mark img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: brightness(0.9) saturate(0.82) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.map-brand div {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.map-brand strong {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.map-brand div > span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#toggleMenu {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--muted);
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

#toggleMenu:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
  color: var(--text);
}

#toggleMenu:active {
  transform: scale(0.96);
}

#toggleMenu:focus-visible,
.accordion-trigger:focus-visible,
.region-info-button:focus-visible,
.info-panel-close:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.menu-icon {
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}

.menu-icon-open {
  display: none;
  font-size: 18px;
}

#menu.is-collapsed {
  bottom: auto;
  width: 58px;
  height: 58px;
  border-color: var(--border-strong);
  border-radius: 18px;
  background: rgba(15, 19, 27, 0.9);
}

#menu.is-collapsed .menu-header {
  min-height: 58px;
  justify-content: center;
  padding: 8px;
  border-bottom: 0;
}

#menu.is-collapsed .map-brand,
#menu.is-collapsed #menuContent,
#menu.is-collapsed .menu-icon-close {
  display: none;
}

#menu.is-collapsed .menu-icon-open {
  display: block;
}

#menuContent {
  display: flex;
  min-height: 0;
  max-height: calc(100dvh - 108px);
  flex: 0 1 auto;
  flex-direction: column;
  gap: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
}

#menuContent::-webkit-scrollbar,
#infoPanel::-webkit-scrollbar {
  width: 6px;
}

#menuContent::-webkit-scrollbar-track,
#infoPanel::-webkit-scrollbar-track {
  background: transparent;
}

#menuContent::-webkit-scrollbar-thumb,
#infoPanel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.control-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.035);
}

.locations-card {
  order: 0;
}

.regions-card {
  order: 1;
}

.patrols-card {
  order: 2;
}

/* Accordion sections */
.accordion {
  overflow: hidden;
}

.accordion-trigger {
  display: flex;
  width: 100%;
  min-height: 51px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  appearance: none;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 650;
  text-align: left;
  user-select: none;
  transition: background 150ms ease, border-color 180ms ease;
}

.accordion-trigger:hover {
  background: rgba(255, 255, 255, 0.035);
}

.accordion-trigger:focus {
  outline: none;
}

.accordion-trigger:focus-visible {
  border-radius: var(--radius-lg);
  box-shadow: inset 0 0 0 2px var(--accent-bright);
}

.accordion-chevron {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 160ms ease, border-color 160ms ease;
}

.accordion.is-open > .accordion-trigger {
  border-bottom: 1px solid var(--border);
}

.accordion.is-open .accordion-chevron {
  border-color: var(--accent-bright);
  transform: rotate(225deg) translate(-1px, -1px);
}

.accordion-panel {
  display: grid;
  grid-template-rows: 0fr;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition:
    grid-template-rows 260ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 160ms ease,
    visibility 0s linear 260ms;
}

.accordion.is-open > .accordion-panel {
  grid-template-rows: 1fr;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition:
    grid-template-rows 260ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 190ms ease 40ms,
    visibility 0s linear 0s;
}

.accordion-content {
  min-height: 0;
  max-height: min(58vh, 560px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
}

.accordion-content::-webkit-scrollbar {
  width: 5px;
}

.accordion-content::-webkit-scrollbar-track {
  background: transparent;
}

.accordion-content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.toggle-switches {
  display: grid;
  gap: 4px;
  padding: 8px;
}

.accordion-content > .toggle-switch {
  margin-right: 8px;
  margin-left: 8px;
}

.accordion-content > .toggle-switch:first-child {
  margin-top: 8px;
}

.accordion-content > .toggle-switch:last-child {
  margin-bottom: 8px;
}

.toggle-switch {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  padding: 7px 8px;
  transition: background 130ms ease, border-color 130ms ease;
}

.toggle-switch:hover {
  border-color: rgba(255, 255, 255, 0.055);
  background: rgba(255, 255, 255, 0.045);
}

.toggle-switch label {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex: 0 0 38px;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  transition: background 160ms ease, border-color 160ms ease;
}

.toggle-slider::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #a6afbd;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  content: "";
  transition: transform 160ms ease, background 160ms ease;
}

.toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.toggle-switch input:checked + .toggle-slider {
  border-color: rgba(217, 164, 91, 0.62);
  background: rgba(217, 164, 91, 0.34);
}

.toggle-switch input:checked + .toggle-slider::before {
  background: var(--accent-bright);
  transform: translateX(16px);
}

.toggle-text {
  min-width: 0;
  flex: 1;
  color: #d9dee7;
  font-size: 12.5px;
  line-height: 1.35;
}

.world-events-note {
  margin: 2px 10px 10px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  padding: 11px 4px 2px;
}

.region-info-button {
  display: flex;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(217, 164, 91, 0.25);
  border-radius: 10px;
  background: rgba(217, 164, 91, 0.14);
  color: var(--accent-bright);
  cursor: pointer;
  font-size: 0;
  padding: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: color 130ms ease, background 130ms ease, border-color 130ms ease, transform 130ms ease;
}

.region-info-button::before {
  display: block;
  width: 17px;
  height: 17px;
  background: currentColor;
  content: "";
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M12 10.5v6' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='12' cy='7.5' r='1.2' fill='black'/%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'%3E%3Ccircle cx='12' cy='12' r='9' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M12 10.5v6' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='12' cy='7.5' r='1.2' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
}

.region-info-button:hover {
  border-color: rgba(243, 199, 127, 0.5);
  background: rgba(217, 164, 91, 0.24);
  transform: translateY(-1px);
}

.region-hover-card {
  position: fixed;
  z-index: 1300;
  width: min(380px, calc(100vw - 32px));
  max-height: min(560px, 78vh);
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: rgba(15, 19, 27, 0.98);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  color: var(--text);
  opacity: 0;
  padding: 14px 15px;
  pointer-events: none;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
  transform: translateX(-6px) scale(0.985);
  transform-origin: left center;
  transition: opacity 150ms ease, transform 150ms ease;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.region-hover-card.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.region-hover-card::before {
  position: absolute;
  top: var(--arrow-top, 24px);
  left: -6px;
  width: 10px;
  height: 10px;
  border-bottom: 1px solid var(--border-strong);
  border-left: 1px solid var(--border-strong);
  background: rgba(15, 19, 27, 0.98);
  content: "";
  transform: rotate(45deg);
}

.region-hover-title {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.region-hover-description {
  color: #c4cad4;
  font-size: 12px;
  line-height: 1.5;
}

.region-hover-description p {
  margin: 0 0 9px;
}

.region-hover-description p:last-child {
  margin-bottom: 0;
}

.region-hover-description ul {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.region-hover-description li {
  position: relative;
  padding-left: 13px;
}

.region-hover-description li::before {
  position: absolute;
  top: 0.65em;
  left: 1px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  opacity: 0.75;
}

/* Location details panel */
#infoPanel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1050;
  width: min(420px, calc(100vw - 36px));
  max-height: min(62vh, 620px);
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: rgba(15, 19, 27, 0.96);
  box-shadow: var(--shadow);
  color: #dce1e9;
  padding: 20px;
  backdrop-filter: blur(22px) saturate(135%);
  -webkit-backdrop-filter: blur(22px) saturate(135%);
  animation: info-panel-in 180ms ease both;
}

@keyframes info-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#infoPanel h3 {
  margin: 0 38px 12px 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

#infoContent {
  color: #c4cad4;
  font-size: 13px;
  line-height: 1.58;
}

#infoContent p {
  margin: 0 0 12px;
}

#infoContent ul {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

#infoContent li {
  position: relative;
  padding-left: 16px;
}

#infoContent li::before {
  position: absolute;
  top: 0.68em;
  left: 2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  opacity: 0.8;
}

.info-panel-close {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  transition: color 130ms ease, background 130ms ease;
}

.info-panel-close:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  visibility: hidden;
  border: 0;
  background: rgba(2, 4, 8, 0.58);
  cursor: default;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
}

/* Leaflet */
.leaflet-container {
  background: #05070a !important;
  font-family: "Inter", system-ui, sans-serif;
  outline: 0;
}

.leaflet-image-layer {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  mix-blend-mode: normal !important;
}

.leaflet-popup-content-wrapper {
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: rgba(20, 25, 34, 0.98);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.4);
  color: var(--text);
}

.leaflet-popup-content {
  margin: 12px 14px;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 12px;
}

.leaflet-popup-tip {
  background: rgba(20, 25, 34, 0.98);
}

.leaflet-popup-close-button {
  color: var(--muted) !important;
}

.leaflet-tooltip.map-details-tooltip {
  width: min(380px, calc(100vw - 90px));
  max-height: min(520px, 78vh);
  overflow-y: auto;
  white-space: normal;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: rgba(15, 19, 27, 0.97);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  color: var(--text);
  padding: 0;
  pointer-events: none;
  scrollbar-width: none;
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.leaflet-tooltip.map-details-tooltip::-webkit-scrollbar {
  display: none;
}

.leaflet-tooltip-right.map-details-tooltip::before {
  border-right-color: rgba(15, 19, 27, 0.97);
}

.map-hover-card {
  padding: 14px 15px;
}

.map-hover-title {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.map-hover-description {
  color: #c4cad4;
  font-size: 12px;
  line-height: 1.5;
}

.map-hover-description p {
  margin: 0 0 9px;
}

.map-hover-description p:last-child {
  margin-bottom: 0;
}

.map-hover-description ul {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.map-hover-description li {
  position: relative;
  padding-left: 13px;
}

.map-hover-description li::before {
  position: absolute;
  top: 0.65em;
  left: 1px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  opacity: 0.75;
}

.marker-container {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: rgba(12, 16, 23, 0.78);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(5px);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.marker-container img {
  width: 31px;
  height: 31px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

.marker-container-gate img {
  image-rendering: pixelated;
}

.marker-container-goblin img {
  transform: translate(-3px, -2px);
}

.marker-container:hover {
  z-index: 2;
  border-color: rgba(243, 199, 127, 0.55);
  background: rgba(30, 26, 20, 0.9);
  transform: translateY(-2px) scale(1.08);
}

.leaflet-marker-icon {
  border: 0 !important;
  background: transparent !important;
}

@media (max-width: 720px) {
  .leaflet-tooltip.map-details-tooltip {
    width: min(300px, calc(100vw - 78px));
    max-height: 55vh;
  }

  #menu {
    top: max(10px, env(safe-area-inset-top));
    bottom: auto;
    left: 10px;
    width: min(360px, calc(100vw - 20px));
    max-height: calc(100dvh - 20px);
  }

  #menu.is-collapsed {
    width: 56px;
    height: 56px;
  }

  body.menu-visible .menu-backdrop {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  #infoPanel {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    max-height: 48vh;
    padding: 17px;
  }

  #infoPanel h3 {
    font-size: 16px;
  }
}

@media (max-height: 620px) and (min-width: 721px) {
  #menu {
    top: 10px;
    bottom: auto;
    max-height: calc(100dvh - 20px);
  }

  .menu-header {
    min-height: 64px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
