* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1b1410;
}

/* ---------- Map viewport ---------- */

#map-viewport {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  background: #0d0a08;
}

#map-viewport.dragging {
  cursor: grabbing;
}

#map-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  /* transform (translate + scale) is set dynamically by app.js */
  will-change: transform;
}

#map-image {
  display: block;
  /* Prevent the browser from blurring pixel art borders too aggressively */
  image-rendering: -webkit-optimize-contrast;
  user-select: none;
  pointer-events: none;
}

/* ---------- Highlight overlay ----------
   #highlight-overlay is a <canvas> created dynamically by app.js. It's
   sized to the bmp's resolution and CSS-stretched to align with the map
   image, so no static styling is needed here beyond what app.js sets
   inline (position/size). */

/* ---------- Search panel ---------- */

#search-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 320px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  z-index: 10;
  font-size: 14px;
}

#province-search {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #5a4632;
  background: rgba(30, 22, 16, 0.92);
  color: #f3e6d0;
  font-size: 15px;
  outline: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

#province-search::placeholder {
  color: #b8a487;
}

#province-search:focus {
  border-color: #ffcf4a;
}

#search-results {
  list-style: none;
  margin: 6px 0 0 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  border-radius: 8px;
  background: rgba(30, 22, 16, 0.95);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  display: none;
}

#search-results.visible {
  display: block;
}

#search-results li {
  padding: 7px 12px;
  color: #f3e6d0;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  gap: 9px;
}

#search-results li:last-child {
  border-bottom: none;
}

#search-results li:hover,
#search-results li.active {
  background: rgba(255, 207, 74, 0.18);
}

#search-results li.no-match {
  color: #b8a487;
  cursor: default;
}

#search-results li.selected {
  background: rgba(143, 227, 154, 0.12);
}

.result-checkbox {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  accent-color: #ffcf4a;
  cursor: pointer;
}

.result-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Type badge: small fixed-width pill identifying province/area/region/
   superregion/continent, so similarly-named entries are easy to tell apart. */
.type-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 20px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1b1410;
}

.badge-province { background: #7fd1ff; }        /* light blue  */
.badge-area { background: #8fe39a; }            /* green      */
.badge-region { background: #d6a6ff; }          /* purple     */
.badge-superregion { background: #ffb86b; }     /* orange     */
.badge-continent { background: #ff8f8f; }       /* red/coral  */
.badge-tradenode { background: #f5e16b; }       /* gold/amber */
.badge-provincegroup { background: #d0cec2; }   /* light grey */
.badge-unknown { background: #cccccc; }

/* ---------- Selected-items chip list ---------- */

#selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  max-height: 140px;
  overflow-y: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 8px;
  border-radius: 999px;
  background: rgba(41, 31, 2, 0.832);
  border: 1px solid rgba(255, 207, 74, 0.35);
  color: #f3e6d0;
  font-size: 12px;
  max-width: 100%;
}

.chip .type-badge {
  width: 20px;
  height: 16px;
  font-size: 9px;
}

.chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.chip .chip-remove {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #f3e6d0;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
}

.chip .chip-remove:hover {
  opacity: 1;
}

/* ---------- Clear selection button ---------- */

#clear-selection {
  margin-top: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #5a4632;
  background: rgba(30, 22, 16, 0.92);
  color: #f3e6d0;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#clear-selection:hover:not(:disabled) {
  background: rgba(255, 99, 99, 0.18);
  border-color: #ff8f8f;
}

#clear-selection:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- Zoom controls ---------- */

#zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#zoom-controls button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid #5a4632;
  background: rgba(30, 22, 16, 0.92);
  color: #f3e6d0;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#zoom-controls button:hover {
  background: rgba(255, 207, 74, 0.18);
}

/* ---------- Hover tooltip ---------- */
/* #province-tooltip is created and positioned dynamically by app.js
   (ProvinceHoverTooltip), fixed to the viewport and following the cursor. */

#province-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none; /* never intercepts the mouse, so it can't itself trigger hide/move logic */
  background: rgba(20, 15, 10, 0.96);
  border: 1px solid #5a4632;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  padding: 8px 10px;
  font-size: 12px;
  color: #f3e6d0;
}

#province-tooltip.hidden {
  display: none;
}

.tooltip-table {
  border-collapse: collapse;
}

.tooltip-table td {
  padding: 2px 6px;
  white-space: nowrap;
  vertical-align: middle;
}

.tooltip-table .type-badge {
  width: 22px;
  height: 17px;
  font-size: 10px;
}

.tooltip-label {
  color: #b8a487;
  font-weight: 600;
  padding-right: 10px !important;
}

.tooltip-value {
  color: #f3e6d0;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The groups row can list many names (a province can sit in 10+ province
   groups at once) — wrap it instead of truncating, unlike every other
   (always single-valued) row above it. */
.tooltip-value.groups-value {
  white-space: normal;
  max-width: 260px;
  overflow: visible;
  text-overflow: unset;
}

/* ---------- Contact / feedback button ----------
   A small circular icon button, the standard pattern for "contact /
   help / feedback" widgets (chat-bubble icon, fixed bottom corner).
   Sits just left of the zoom controls so the two clusters don't overlap. */

#contact-button {
  position: absolute;
  bottom: 20px;
  right: 64px; /* zoom-controls is 38px wide at right:16px, so this clears it with a gap */
  z-index: 10;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #5a4632;
  background: rgba(30, 22, 16, 0.92);
  color: #f3e6d0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  text-decoration: none;
  cursor: pointer;
}

#contact-button:hover,
#contact-button:focus-visible {
  background: rgba(255, 207, 74, 0.18);
}

#contact-button svg {
  width: 19px;
  height: 19px;
}

/* Pure CSS, no JS/delay — deliberately different from the province hover
   tooltip's 800ms debounce, since this one should appear instantly. */
#contact-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  white-space: nowrap;
  background: rgba(20, 15, 10, 0.96);
  border: 1px solid #5a4632;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  padding: 7px 10px;
  font-size: 12px;
  color: #f3e6d0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#contact-button:hover #contact-tooltip,
#contact-button:focus-visible #contact-tooltip {
  opacity: 1;
  visibility: visible;
}