:root {
  --map-ocean: #8bb0ec;
  font-synthesis: none;
}

html,
body {
  background: var(--map-ocean);
}

.raster-batch-pixelated image { image-rendering: pixelated; }

body {
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
}

body.sidebar-collapsed { grid-template-columns: 0 1fr; }
body.feature-open.sidebar-collapsed { grid-template-columns: 360px 1fr; }
body.feature-open:not(.sidebar-collapsed) { grid-template-columns: 660px 1fr; }

.sidebar {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: row;
  padding: 0;
  background: var(--color-header);
  border-right: 1px dashed var(--color-border);
  overflow: hidden;
  z-index: 2;
}

.sidebar-catalog {
  display: flex;
  width: 300px;
  flex: 0 0 300px;
  min-height: 100%;
  flex-direction: column;
  gap: 24px;
  padding: 28px 24px 20px;
  overflow-y: auto;
}

body.sidebar-collapsed .sidebar-catalog { display: none; }
body.feature-open:not(.sidebar-collapsed) .sidebar-catalog { border-right: 1px dashed var(--color-border); }

body.sidebar-collapsed:not(.feature-open) .sidebar {
  transform: translateX(-100%);
  visibility: hidden;
  pointer-events: none;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -.02em;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-heading button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 12px;
}

.layer-list { border-top: 1px solid var(--color-border); }

.place-search {
  position: relative;
  flex: 1;
}

.place-search input {
  width: 100%;
  height: 42px;
  padding: 0 42px 0 13px;
  border: 0;
  border: 1px solid var(--color-border);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  outline: 0;
  background: var(--color-input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b8f98' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat calc(100% - 13px) center;
  color: var(--color-text);
  box-shadow: none;
  font-size: 14px;
}

.place-search input::placeholder { color: var(--color-muted-2); }
.place-search input:focus,
.place-search input:focus-visible {
  border-color: var(--color-accent);
  outline: 0;
  box-shadow: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  display: none;
  max-height: 290px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-header);
  box-shadow: none;
}

.search-results.open { display: block; }

.search-result {
  display: block;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
}

.search-result:last-child { border-bottom: 0; }
.search-result:hover, .search-result.active { background: var(--color-card); }
.search-result strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.search-result span { display: block; margin-top: 2px; color: var(--color-muted); font-size: 10px; }
.search-empty { padding: 12px; color: var(--color-muted); font-size: 12px; }

.catalog-controls {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 7px;
  margin-bottom: 12px;
}

.catalog-controls #layer-search { grid-column: 1 / -1; }

.catalog-controls input,
.catalog-controls select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  outline: 0;
  background: var(--color-input-bg);
  color: var(--color-text);
  font-size: 12px;
}

.catalog-controls input:focus,
.catalog-controls select:focus { border-color: var(--color-accent); box-shadow: 0 0 0 2px var(--color-focus); }

.language-section h2 { margin-bottom: 12px; }

.blend-section h2 { margin-bottom: 12px; }

.blend-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.blend-toggle input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--color-accent);
}

.blend-toggle span { display: grid; gap: 3px; }
.blend-toggle strong { font-size: 13px; font-weight: 600; }
.blend-toggle small { color: var(--color-muted); font-size: 11px; line-height: 1.35; }
.blend-toggle:has(input:disabled) { cursor: not-allowed; opacity: .48; }

.blend-opacity {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: var(--color-muted);
  font-size: 11px;
}

.blend-opacity span { display: flex; justify-content: space-between; }
.blend-opacity output { color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }

.blend-opacity input {
  width: 100%;
  margin: 0;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.blend-opacity:has(input:disabled) { opacity: .48; }
.blend-opacity input:disabled { cursor: not-allowed; }

.language-section select {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-input-bg);
  color: var(--color-text);
  font: inherit;
  font-size: 12px;
}

.layer-group {
  margin: 13px 0 4px;
  color: var(--color-muted-2);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.empty-layers {
  padding: 16px 0;
  color: var(--color-muted);
  font-size: 12px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  font-size: 14px;
}

.layer-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-accent);
}

.swatch {
  width: 8px;
  height: 8px;
  margin-left: auto;
  border: 1px solid color-mix(in srgb, var(--color-text) 16%, transparent);
  border-radius: 50%;
}

.loader {
  width: 12px;
  height: 12px;
  margin-left: auto;
  border: 2px solid color-mix(in srgb, var(--color-text) 16%, transparent);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.drop-section h2 { margin-bottom: 12px; }

.drop-zone {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 18px 12px;
  border: 1px dashed var(--color-border);
  border-radius: 8px;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 12px;
  text-align: center;
  transition: .2s ease;
}

.drop-zone strong { color: var(--color-text); font-size: 13px; }
.drop-zone.dragging { border-color: var(--color-accent); background: var(--color-card); transform: scale(1.01); }
.drop-icon { color: var(--color-accent); font-size: 24px; line-height: 1; }
#file-input { position: absolute; width: 1px; height: 1px; clip: rect(0 0 0 0); }
.custom-layers { margin-top: 10px; font-size: 12px; color: var(--color-muted); }

.map-shell {
  position: relative;
  height: 100vh;
  overflow: hidden;
  background: var(--map-ocean);
}

#map {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#map.interactive-hover { cursor: pointer; }
#map.dragging { cursor: grabbing; }

#viewport {
  transform-box: view-box;
  transform-origin: 0 0;
  will-change: transform;
}

.map-layer path, .map-layer circle {
  vector-effect: non-scaling-stroke;
  transition: opacity .15s ease;
}

#geometry-viewport .vector-base-blended { opacity: var(--vector-base-opacity, .46); }

.map-label {
  fill: #5f6a69;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 2.5px;
  stroke-linejoin: round;
  font-size: var(--label-size, 10px);
  font-weight: 500;
  letter-spacing: var(--label-spacing, 0px);
  pointer-events: none;
  text-anchor: middle;
}

.map-label.interactive {
  pointer-events: auto;
  cursor: pointer;
}

.map-label.interactive:hover,
.map-label.interactive:focus {
  fill: var(--color-accent-hover);
}

.feature-panel {
  position: relative;
  width: 360px;
  flex: 0 0 360px;
  height: 100%;
  overflow-y: auto;
  background: var(--color-header);
}

.feature-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-input-bg);
  color: var(--color-muted);
  cursor: pointer;
}

.feature-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.feature-close:hover { background: var(--color-card-strong); color: var(--color-text); }

.feature-hero {
  position: relative;
  height: 190px;
  overflow: hidden;
  background: var(--color-input-bg);
}

.feature-image-attribution {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 1;
}

.feature-image-attribution > button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 50%;
  background: rgba(32, 36, 39, .48);
  color: rgba(255, 255, 255, .88);
  cursor: pointer;
  font: 600 13px/20px Georgia, serif;
}

.feature-image-credit {
  position: absolute;
  right: 36px;
  bottom: 30px;
  display: none;
  width: 220px;
  max-height: 120px;
  padding: 7px 8px;
  overflow-y: auto;
  border-radius: 5px;
  background: rgba(32, 36, 39, .76);
  color: rgba(255, 255, 255, .88);
  font-size: 10px;
  line-height: 1.35;
}

.feature-image-credit p { margin: 0 0 5px; }
.feature-image-credit p:last-child { margin-bottom: 0; }
.feature-image-credit a { color: inherit; }
.feature-image-attribution.open .feature-image-credit { display: block; }

.feature-hero.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, var(--color-card-strong) 20%, var(--color-card) 40%, var(--color-card-strong) 60%);
  background-size: 200% 100%;
  animation: feature-skeleton 1.25s ease-in-out infinite;
}

@keyframes feature-skeleton {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

.feature-hero img {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: cover;
}

@media (prefers-reduced-motion: reduce) {
  .feature-hero.loading::after { animation: none; }
}

.feature-body { padding: 24px; }
.feature-name { margin: 0; color: var(--color-text); font-size: 26px; font-weight: 600; letter-spacing: -.025em; text-transform: none; }
.feature-description { margin: 20px 0; color: var(--color-text-secondary); font-size: 14px; line-height: 1.55; }
.feature-metrics { display: grid; grid-template-columns: 104px minmax(0, 1fr); align-items: baseline; gap: 14px 16px; margin: 0 0 20px; }
.feature-metrics[hidden] { display: none; }
.feature-metrics dt { color: var(--color-text-secondary); font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.feature-metrics dd { margin: 0; color: var(--color-text); font-size: 15px; font-variant-numeric: tabular-nums; }
.feature-links { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 16px; border-top: 1px solid var(--color-border); }
.feature-links a { padding: 8px 12px; border-radius: 8px; background: var(--color-card-strong); color: var(--color-accent-hover); font-size: 13px; text-decoration: none; }
.feature-links a:hover { text-decoration: underline; }

.label-country {
  fill: #3f4848;
  font-weight: 720;
}

.label-region {
  fill: #6c7775;
  font-weight: 620;
}

.label-city-major {
  fill: #303838;
  font-weight: 680;
}

.label-city { fill: #424c4b; }
.label-local { fill: #5f6968; }

.label-geographic {
  fill: #687b82;
  font-style: italic;
  font-variant: small-caps;
  font-weight: 400;
  letter-spacing: .3px;
}

.point-marker {
  fill: none;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.map-toolbar {
  position: absolute;
  top: 18px;
  right: 18px;
  display: flex;
  z-index: 1;
  gap: 4px;
}

.map-search {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 3;
  display: flex;
  width: min(440px, calc(100% - 190px));
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.map-search .menu-button {
  display: grid;
  flex: 0 0 48px;
  height: 42px;
  place-items: center;
  border: 0;
  border: 1px solid var(--color-border);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  background: var(--color-input-bg);
  box-shadow: none;
  cursor: pointer;
}

.map-toolbar button {
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-input-bg);
  cursor: pointer;
  font-size: 18px;
}

.map-toolbar .icon-button {
  display: grid;
  place-items: center;
}

.map-toolbar button:hover { background: var(--color-card-strong); }
.basemap-switcher {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 2;
  display: flex;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-header);
  box-shadow: none;
}

.basemap-switcher label {
  display: grid;
  width: 82px;
  gap: 6px;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
}

.basemap-group { display: contents; }
.basemap-group-title { display: none; }

.basemap-switcher.expanded .basemap-group {
  display: grid;
  grid-template-columns: repeat(4, 82px);
  gap: 6px 10px;
}

.basemap-switcher.expanded .basemap-group-vector { grid-template-columns: 82px; }

.basemap-switcher.expanded .basemap-group-raster {
  margin-left: 2px;
  padding-left: 12px;
  border-left: 1px solid var(--color-border);
}

.basemap-switcher.expanded .basemap-group-title {
  display: block;
  grid-column: 1 / -1;
  color: var(--color-muted-2);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.basemap-switcher:not(.expanded) label:not(.selected) { display: none; }

.basemap-switcher input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.basemap-preview {
  width: 82px;
  height: 62px;
  border: 2px solid transparent;
  border-radius: 9px;
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 1px rgba(42, 68, 76, .1);
}

.preview-vector {
  background:
    linear-gradient(135deg, transparent 46%, var(--map-ocean) 47% 54%, transparent 55%),
    linear-gradient(25deg, #d8edd2 0 45%, #f3efe5 46% 63%, #d8edd2 64%);
}

.preview-ne6-cross-blended { background-image: url('/map/rasters/NE6_HYP_HR_SR_OB_DR/0/0/0.jpg'); }
.preview-ne6-ne1 { background-image: url('/map/rasters/NE6_NE1_HR_SR_OB_DR/0/0/0.jpg'); }
.preview-ne6-modis-land-cover { background-image: url('/map/rasters/NE6_LC_HR_HD_KNOCKOUT/0/0/0.png'); }
.preview-blue-marble { background-image: url('/map/rasters/BMNG_TOPO_BATHY_200407/0/0/0.jpg?v=200407'); }

.basemap-switcher input:checked + .basemap-preview {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-input-bg), 0 0 0 4px var(--color-accent);
}

.basemap-switcher label:hover .basemap-preview { filter: brightness(1.04); }

.location-accuracy {
  fill: rgba(33, 121, 219, .18);
  stroke: rgba(33, 121, 219, .35);
}

.location-dot {
  fill: #2179db;
  stroke: #fff;
}

.status, .coordinates {
  position: absolute;
  bottom: 18px;
  padding: 7px 10px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--color-header) 90%, transparent);
  color: var(--color-muted);
  box-shadow: 0 1px 5px rgba(45, 74, 85, .1);
  font-size: 11px;
  pointer-events: none;
}

.status { left: 18px; bottom: 132px; }
.status:empty { display: none; }
.coordinates { right: 18px; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  body, body.sidebar-collapsed { display: block; overflow: hidden; }
  .sidebar { position: absolute; inset: 0 auto 0 0; width: auto; max-width: calc(100vw - 54px); min-width: 0; height: 100dvh; overflow-x: auto; }
  body.feature-open .sidebar { width: 100vw; max-width: none; }
  .sidebar-catalog { width: min(300px, calc(100vw - 54px)); flex-basis: min(300px, calc(100vw - 54px)); }
  .feature-panel { width: 100vw; flex-basis: 100vw; }
  .sidebar-catalog { padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); }
  .map-shell { height: 100dvh; min-height: 360px; }
  .map-search {
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    left: calc(12px + env(safe-area-inset-left));
    width: auto;
  }
  .map-search .menu-button { flex-basis: 52px; height: 48px; border-radius: 12px 0 0 12px; }
  .place-search input { height: 48px; border-radius: 0 12px 12px 0; font-size: 16px; }
  body:not(.sidebar-collapsed):not(.feature-open) .sidebar-catalog { padding-top: calc(80px + env(safe-area-inset-top)); }
  body:not(.sidebar-collapsed):not(.feature-open) .map-search { right: auto; width: 52px; }
  body:not(.sidebar-collapsed):not(.feature-open) .place-search { display: none; }
  body:not(.sidebar-collapsed):not(.feature-open) .map-search .menu-button { border-right: 1px solid var(--color-border); border-radius: 12px; }
  body.feature-open .map-search { display: none; }
  .map-toolbar {
    top: auto;
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 0;
    padding: 3px;
    border: 1px solid var(--color-border);
    border-radius: 13px;
    background: color-mix(in srgb, var(--color-header) 94%, transparent);
    box-shadow: 0 2px 10px rgba(45, 74, 85, .12);
  }
  .map-toolbar button { min-width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; }
  .basemap-switcher {
    right: calc(12px + env(safe-area-inset-right));
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    gap: 8px;
    overflow-x: auto;
    border-radius: 13px;
    box-shadow: 0 2px 10px rgba(45, 74, 85, .12);
  }
  .basemap-switcher:not(.expanded) { right: auto; padding: 5px; }
  .basemap-switcher:not(.expanded) label { display: flex; width: auto; align-items: center; gap: 8px; padding-right: 8px; font-size: 12px; }
  .basemap-switcher:not(.expanded) .basemap-preview { width: 42px; height: 34px; flex: 0 0 42px; border-radius: 8px; }
  .basemap-switcher.expanded label { width: 68px; }
  .basemap-switcher.expanded .basemap-preview { width: 68px; height: 48px; }
  .basemap-switcher.expanded .basemap-group { grid-template-columns: repeat(4, 68px); gap: 6px 8px; }
  .basemap-switcher.expanded .basemap-group-vector { grid-template-columns: 68px; }
  .status, .coordinates { bottom: calc(72px + env(safe-area-inset-bottom)); }
  .basemap-switcher.expanded ~ .status,
  .basemap-switcher.expanded ~ .coordinates { bottom: calc(125px + env(safe-area-inset-bottom)); }
  .status { left: calc(12px + env(safe-area-inset-left)); }
  .coordinates { right: calc(12px + env(safe-area-inset-right)); }
  body:not(.sidebar-collapsed) .map-toolbar,
  body:not(.sidebar-collapsed) .basemap-switcher,
  body:not(.sidebar-collapsed) .status,
  body:not(.sidebar-collapsed) .coordinates,
  body.feature-open .map-toolbar,
  body.feature-open .basemap-switcher,
  body.feature-open .status,
  body.feature-open .coordinates { visibility: hidden; pointer-events: none; }
}
