:root,
:root .theme-dark,
:root .theme-light,
:root .theme-contrast {
  --bm-panel-bg: #17223a;
  --bm-panel-bg-soft: #222f49;
  --bm-panel-border: rgba(255, 255, 255, 0.08);
  --bm-panel-muted: #9ca9c0;
  --bm-panel-text: #f4f7fb;
  --bm-panel-success: #f4f7fb;
  --bm-panel-disabled: #7f8ca3;
  --bm-panel-warning: #f0c55b;
  --bm-panel-link: #9fc6ff;
  --bm-panel-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
  --bm-diplomacy-nation: #2ecc71;
  --bm-diplomacy-ally: #0d6efd;
  --bm-diplomacy-enemy: #dc3545;
  --bm-diplomacy-neutral: #ffffff;
}

html.bm-enhanced-ui,
html.bm-enhanced-ui body {
  background: #0d1730;
  color: var(--bm-panel-text);
  color-scheme: dark;
}

html.bm-enhanced-ui #map-container .bm-marker-popup {
  border: 1px solid var(--bm-panel-border);
  border-radius: 0.75rem;
  background: rgba(23, 34, 58, 0.92);
  backdrop-filter: blur(18px);
}

html.bm-enhanced-ui .side-menu {
  background: rgba(18, 28, 47, 0.94);
  backdrop-filter: blur(18px);
}

.bm-search-shell {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 4.25rem);
  left: 50%;
  z-index: 20040;
  width: min(28rem, calc(100vw - 2rem));
  transform: translateX(-50%);
  pointer-events: auto;
}

.bm-search {
  display: grid;
  gap: 0.55rem;
}

.bm-search__group {
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--bm-panel-border);
  border-radius: 1rem;
  background: rgba(23, 34, 58, 0.95);
  box-shadow: var(--bm-panel-shadow);
  backdrop-filter: blur(18px);
}

.bm-search__group .form-control,
.bm-search__group .btn {
  border: 0;
  box-shadow: none;
}

.bm-search__group .form-control {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.72rem 0.9rem;
  background: transparent;
  color: var(--bm-panel-text);
}

.bm-search__group .form-control::placeholder {
  color: var(--bm-panel-muted);
}

.bm-search__group .form-control:focus {
  background: transparent;
  color: var(--bm-panel-text);
}

.bm-search__group .btn {
  color: var(--bm-panel-text);
  background: rgba(255, 255, 255, 0.04);
}

.bm-search__clear {
  flex: 0 0 3rem;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.bm-search__group .btn:disabled {
  color: var(--bm-panel-muted);
  background: rgba(255, 255, 255, 0.02);
  opacity: 0.55;
}

.bm-search__group .btn:not(:disabled):hover,
.bm-search__group .btn:focus-visible {
  color: var(--bm-panel-text);
  background: rgba(255, 255, 255, 0.08);
}

.bm-search__results {
  max-height: min(24rem, calc(100dvh - 10rem));
  overflow-y: auto;
  border: 1px solid var(--bm-panel-border);
  border-radius: 1rem;
  background: rgba(23, 34, 58, 0.97);
  box-shadow: var(--bm-panel-shadow);
}

.bm-search__result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0.9rem;
  border-color: var(--bm-panel-border);
  background: transparent;
  color: var(--bm-panel-text);
}

.bm-search__result:hover,
.bm-search__result:focus-visible {
  color: var(--bm-panel-text);
  background: rgba(255, 255, 255, 0.04);
}

.bm-search__result.active {
  border-color: var(--bm-panel-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--bm-panel-text);
}

.bm-search__result-label {
  min-width: 0;
  font-size: 0.98rem;
  font-weight: 600;
  text-align: left;
}

.bm-search__result-type {
  flex: 0 0 auto;
  color: var(--bm-panel-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.bm-search__status {
  min-height: 1rem;
  padding: 0 0.2rem;
  color: var(--bm-panel-muted);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
}

.bm-search__status.is-error {
  color: #ffb58e;
}

.bm-town-panel {
  --bs-offcanvas-width: min(420px, 100vw);
  --bs-offcanvas-bg: var(--bm-panel-bg);
  --bs-offcanvas-color: var(--bm-panel-text);
  --bs-offcanvas-border-width: 0;
  --bs-offcanvas-box-shadow: var(--bm-panel-shadow);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  height: 100dvh;
  max-height: 100dvh;
  width: min(420px, 100vw);
  max-width: 100vw;
  z-index: 20050 !important;
  border-right: 1px solid var(--bm-panel-border);
  border-radius: 0 !important;
  overflow: hidden;
  visibility: hidden;
  transform: translateX(-100%);
}

.bm-town-panel.show,
.bm-town-panel.showing,
.bm-town-panel.hiding {
  visibility: visible !important;
}

.bm-town-panel.show,
.bm-town-panel.showing {
  transform: none !important;
}

.bm-town-panel .offcanvas-header {
  flex: 0 0 auto;
  padding: 1.25rem 1.5rem 0.75rem;
}

.bm-town-panel .offcanvas-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 1.5rem 1.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.bm-town-view {
  min-height: 100%;
}

.bm-town-view__header {
  display: grid;
  gap: 1rem;
  justify-items: center;
  text-align: center;
}

.bm-town-view__flags {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0.45rem;
  width: min(256px, 100%);
  max-width: 100%;
}

.bm-town-view__flags.is-single {
  gap: 0;
}

.bm-town-view__flag-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(256px, 100%);
  min-height: 4.5rem;
  padding: 0.95rem 1rem;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.03);
  text-align: center;
}

.bm-town-view__flag-notice-link {
  color: var(--bm-panel-link);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}

.bm-town-view__flag-notice-link:hover,
.bm-town-view__flag-notice-link:focus-visible {
  color: #c5ddff;
}

.bm-town-view__flag-frame {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 100%;
}

.bm-town-view__flags.is-paired .bm-town-view__flag-frame {
  flex: 1 1 0;
}

.bm-town-view__flags.is-single .bm-town-view__flag-frame {
  flex: 0 1 100%;
}

.bm-town-view__flag-frame[hidden] {
  display: none !important;
}

.bm-town-view__flag {
  position: relative;
  display: block;
  width: 100%;
  max-width: 100%;
  max-width: 256px;
  aspect-ratio: 2 / 1;
  flex: 1 1 auto;
  overflow: hidden;
  isolation: isolate;
}

.bm-town-view__flag-image,
.bm-town-view__flag-effect {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.bm-town-view__flag-image {
  object-fit: contain;
  image-rendering: pixelated;
}

.bm-town-view__flag-effect {
  object-fit: fill;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0.72;
}

.bm-town-view__title {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.05;
  width: auto;
  padding: 0;
  text-align: center;
}

.bm-town-view__title::after {
  display: none;
  content: none;
}

.bm-town-view__identity {
  display: grid;
  gap: 0.45rem;
  justify-items: center;
  width: 100%;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--bm-panel-border);
}

.bm-town-view__subtitle {
  margin: 0;
  color: var(--bm-panel-muted);
  font-size: 1.05rem;
  text-align: center;
}

.bm-town-view__mayor {
  display: grid;
  gap: 0.7rem;
  justify-items: center;
  width: 100%;
}

.bm-town-view__mayor-portrait {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 176px;
  height: 210px;
  background: url("./player-bg-new.png") center bottom / 172px 210px no-repeat;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.24));
}

.bm-town-view__mayor-image {
  display: block;
  width: 156px;
  height: 156px;
  object-fit: contain;
  image-rendering: pixelated;
  transform: translateY(-6px);
}

.bm-town-view__mayor-name {
  color: var(--bm-panel-text);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

.bm-town-view__mayor-label {
  color: var(--bm-panel-muted);
  font-weight: 600;
}

.bm-town-view__mayor-separator {
  display: inline;
}

.bm-town-view__title-link,
.bm-town-view__subtitle-link,
.bm-town-view__list-link,
.bm-town-view__value-link,
.bm-town-view__player-link {
  color: var(--bm-panel-link);
}

.bm-town-view__title-link,
.bm-town-view__subtitle-link,
.bm-town-view__list-link,
.bm-town-view__value-link {
  color: var(--bm-panel-link);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}

.bm-town-view__player-link {
  text-decoration: none;
}

.bm-town-view__title-link:hover,
.bm-town-view__title-link:focus-visible,
.bm-town-view__subtitle-link:hover,
.bm-town-view__subtitle-link:focus-visible,
.bm-town-view__list-link:hover,
.bm-town-view__list-link:focus-visible,
.bm-town-view__value-link:hover,
.bm-town-view__value-link:focus-visible,
.bm-town-view__player-link:hover,
.bm-town-view__player-link:focus-visible {
  color: #c5ddff;
}

.bm-town-view__subtitle-inline {
  display: inline;
}

.bm-town-view__list-link,
.bm-town-view__player-link {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.bm-town-view__board {
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--bm-panel-border);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  color: #c4cedf;
  font-style: italic;
}

.bm-town-view__section-label {
  margin: 0 0 0.25rem;
  color: var(--bm-panel-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.bm-town-view__grid {
  --bs-gutter-x: 0.75rem;
  --bs-gutter-y: 0.75rem;
}

.bm-town-view__card {
  height: 100%;
  border: 1px solid var(--bm-panel-border);
  background: rgba(255, 255, 255, 0.04);
}

.bm-town-view__card.is-overclaimed,
.bm-town-view__card.is-danger {
  border-color: rgba(255, 99, 112, 0.45);
  background: rgba(220, 53, 69, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 99, 112, 0.12);
}

.bm-town-view__card.is-overclaimed .bm-town-view__value,
.bm-town-view__card.is-danger .bm-town-view__value {
  color: #ff9aa5;
  font-weight: 700;
}

.bm-town-view__card.is-success {
  border-color: rgba(87, 242, 135, 0.4);
  background: rgba(46, 204, 113, 0.16);
  box-shadow: inset 0 0 0 1px rgba(87, 242, 135, 0.12);
}

.bm-town-view__card.is-success .bm-town-view__value {
  color: #9cf6b8;
  font-weight: 700;
}

.bm-town-view__card .card-body {
  padding: 0.9rem 1rem;
}

.bm-town-view__meta {
  margin-bottom: 0.35rem;
  color: var(--bm-panel-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.bm-town-view__value {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--bm-panel-text);
}

.bm-town-view__value--board {
  color: #c4cedf;
  font-style: italic;
  font-weight: 500;
  line-height: 1.5;
}

.bm-town-view__value.is-enabled {
  color: var(--bm-panel-success);
}

.bm-town-view__value.is-disabled {
  color: var(--bm-panel-disabled);
}

.bm-town-view__value.is-warning {
  color: var(--bm-panel-warning);
}

.bm-town-view__wealth {
  border: 1px solid rgba(240, 197, 91, 0.18);
  background: rgba(240, 197, 91, 0.09);
}

.bm-town-view__wealth .card-body {
  padding: 1rem 1.1rem;
}

.bm-town-view__wealth-value {
  color: #ffe17d;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.1;
}

.bm-town-view__accordion .accordion-item {
  border: 1px solid var(--bm-panel-border);
  background: transparent;
}

.bm-town-view__accordion .accordion-button {
  background: transparent;
  color: var(--bm-panel-text);
  font-weight: 600;
  padding: 1rem 1.1rem;
  box-shadow: none;
}

.bm-town-view__accordion .accordion-button:not(.collapsed) {
  background: rgba(255, 255, 255, 0.03);
  color: var(--bm-panel-text);
}

.bm-town-view__accordion .accordion-button::after {
  filter: invert(1) brightness(1.5);
}

.bm-town-view__accordion .accordion-body {
  padding: 0 1rem 1rem;
  background: rgba(255, 255, 255, 0.02);
}

.bm-town-view__residents {
  margin: 0.35rem 0 0;
}

.bm-town-view__residents .list-group-item,
.bm-town-view__details .list-group-item {
  border-color: var(--bm-panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--bm-panel-text);
}

.bm-town-view__details .list-group-item {
  padding: 0.95rem 1rem;
}

.bm-town-view__detail-label {
  color: var(--bm-panel-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.bm-town-view__detail-value {
  color: var(--bm-panel-text);
}

.bm-town-view__detail-value.is-enabled {
  color: var(--bm-panel-success);
}

.bm-town-view__detail-value.is-disabled {
  color: var(--bm-panel-disabled);
}

.bm-town-view__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.bm-town-view__badges .badge {
  padding: 0.5rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.bm-diplomacy-view {
  width: 100%;
}

.bm-diplomacy-view__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.95rem 1rem;
  border: 1px solid var(--bm-panel-border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.04);
  color: var(--bm-panel-text);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: none;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.bm-diplomacy-view__button:hover,
.bm-diplomacy-view__button:focus-visible {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--bm-panel-text);
}

.bm-diplomacy-view__button.is-active {
  border-color: rgba(87, 242, 135, 0.36);
  background: rgba(46, 204, 113, 0.16);
}

.bm-diplomacy-view__button:disabled {
  opacity: 0.72;
  cursor: wait;
}

.bm-diplomacy-view__icon {
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
}

.bm-diplomacy-view__text {
  min-width: 0;
}

.bm-diplomacy-legend {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  z-index: 20045;
  width: min(40rem, calc(100vw - 1.5rem));
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(1rem);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.bm-diplomacy-legend.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bm-diplomacy-legend__inner {
  pointer-events: auto;
  padding: 0.85rem 1rem;
  border: 1px solid var(--bm-panel-border);
  border-radius: 1.2rem;
  background: rgba(23, 34, 58, 0.95);
  box-shadow: var(--bm-panel-shadow);
  backdrop-filter: blur(18px);
}

.bm-diplomacy-legend__header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding-inline: 2.4rem;
  margin-bottom: 0.55rem;
}

.bm-diplomacy-legend__title {
  margin: 0;
  color: var(--bm-panel-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
}

.bm-diplomacy-legend__viewing {
  margin: 0 0 0.65rem;
  color: var(--bm-panel-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.bm-diplomacy-legend__nation-link {
  color: var(--bm-panel-link);
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
}

.bm-diplomacy-legend__nation-link:hover,
.bm-diplomacy-legend__nation-link:focus-visible {
  color: #c5ddff;
}

.bm-diplomacy-legend__close {
  position: absolute;
  top: 50%;
  right: 0;
  flex: 0 0 auto;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0 0.35rem;
  border: 1px solid var(--bm-panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--bm-panel-text);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: none;
  transform: translateY(-50%);
}

.bm-diplomacy-legend__close:hover,
.bm-diplomacy-legend__close:focus-visible {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--bm-panel-text);
}

.bm-diplomacy-legend__close:disabled {
  opacity: 0.7;
  cursor: wait;
}

.bm-diplomacy-legend__items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem 1rem;
}

.bm-diplomacy-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--bm-panel-text);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.bm-diplomacy-legend__dot {
  display: inline-block;
  width: 0.72rem;
  height: 0.72rem;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 999px;
  box-shadow: 0 0 0 0.18rem rgba(255, 255, 255, 0.05);
}

.bm-diplomacy-legend__dot.is-nation {
  background: var(--bm-diplomacy-nation);
}

.bm-diplomacy-legend__dot.is-ally {
  background: var(--bm-diplomacy-ally);
}

.bm-diplomacy-legend__dot.is-enemy {
  background: var(--bm-diplomacy-enemy);
}

.bm-diplomacy-legend__dot.is-neutral {
  background: var(--bm-diplomacy-neutral);
}

@media (max-width: 575.98px) {
  .bm-search-shell {
    top: calc(env(safe-area-inset-top, 0px) + 4.5rem);
    width: min(26rem, calc(100vw - 1rem));
  }

  .bm-search__group .form-control,
  .bm-search__result {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .bm-search__result-label {
    font-size: 0.92rem;
  }

  .bm-town-panel {
    --bs-offcanvas-width: 100vw;
  }

  .bm-town-panel .offcanvas-header {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .bm-town-panel .offcanvas-body {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .bm-town-view__title {
    font-size: 1.85rem;
  }

  .bm-town-view__flag-notice {
    width: min(100%, 256px);
    min-height: 4.1rem;
    padding: 0.85rem 0.9rem;
  }

  .bm-town-view__flag-notice-link {
    font-size: 0.86rem;
  }

  .bm-town-view__mayor-portrait {
    width: 170px;
    height: 204px;
    background-size: 166px 204px;
  }

  .bm-town-view__mayor-image {
    width: 156px;
    height: 156px;
  }

  .bm-town-view__grid {
    --bs-gutter-x: 0.55rem;
    --bs-gutter-y: 0.55rem;
  }

  .bm-town-view__card .card-body,
  .bm-town-view__details .list-group-item,
  .bm-town-view__accordion .accordion-button {
    padding: 0.8rem 0.85rem;
  }

  .bm-town-view__meta,
  .bm-town-view__detail-label {
    font-size: 0.68rem;
    letter-spacing: 0.1em;
  }

  .bm-town-view__value,
  .bm-town-view__detail-value {
    font-size: 0.95rem;
  }

  .bm-town-view__wealth-value {
    font-size: 1.4rem;
  }

  .bm-diplomacy-view__button {
    padding: 0.85rem 0.9rem;
    font-size: 0.9rem;
  }

  .bm-diplomacy-legend {
    width: min(32rem, calc(100vw - 1rem));
    bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
  }

  .bm-diplomacy-legend__inner {
    padding: 0.8rem 0.9rem;
  }

  .bm-diplomacy-legend__header {
    min-height: 1.9rem;
    padding-inline: 2.2rem;
  }

  .bm-diplomacy-legend__items {
    gap: 0.55rem 0.85rem;
  }

  .bm-diplomacy-legend__viewing {
    font-size: 0.74rem;
  }

  .bm-diplomacy-legend__item {
    font-size: 0.68rem;
    letter-spacing: 0.1em;
  }

  .bm-diplomacy-legend__close {
    min-width: 1.9rem;
    min-height: 1.9rem;
    font-size: 0.82rem;
  }
}
