:root {
  color-scheme: light;
  --ink: #102027;
  --muted: #637077;
  --line: rgba(16, 32, 39, 0.14);
  --panel: rgba(252, 253, 251, 0.9);
  --panel-solid: #fcfdfb;
  --accent: #008f83;
  --accent-strong: #006e66;
  --amber: #e7a21f;
  --danger: #c44536;
  --shadow: 0 18px 48px rgba(14, 23, 28, 0.22);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  background: #dbe3df;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

#map {
  position: fixed;
  inset: 0;
}

.fallback-map {
  position: fixed;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  opacity: 0;
  background:
    linear-gradient(34deg, transparent 0 44.4%, rgba(191, 123, 0, 0.5) 44.5% 45.7%, rgba(255, 241, 178, 0.86) 45.8% 46.6%, transparent 46.8%),
    linear-gradient(102deg, transparent 0 52.4%, rgba(0, 95, 88, 0.52) 52.5% 53.4%, rgba(0, 167, 150, 0.72) 53.5% 54.2%, transparent 54.4%),
    linear-gradient(82deg, transparent 0 62.4%, rgba(84, 108, 100, 0.5) 62.5% 63.6%, rgba(255, 253, 245, 0.88) 63.7% 64.6%, transparent 64.8%),
    repeating-linear-gradient(90deg, rgba(0, 85, 79, 0.12) 0 1px, transparent 1px 54px),
    repeating-linear-gradient(0deg, rgba(0, 85, 79, 0.1) 0 1px, transparent 1px 48px),
    linear-gradient(180deg, #eef6f1 0%, #d6e4dc 36%, #adc7bb 100%);
  pointer-events: none;
  transition: opacity 240ms ease;
}

.fallback-map.visible {
  opacity: 0.96;
}

.maplibregl-canvas {
  outline: none;
}

.texture-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.12), transparent 34%, rgba(0, 143, 131, 0.08)),
    repeating-linear-gradient(45deg, rgba(16, 32, 39, 0.04) 0 1px, transparent 1px 5px);
  mix-blend-mode: overlay;
  transition: opacity 180ms ease;
  z-index: 1;
}

body.ultra .texture-layer {
  opacity: 0.28;
}

body.ultra .maplibregl-canvas {
  filter: saturate(1.08) contrast(1.06);
}

.topbar {
  position: fixed;
  z-index: 4;
  top: 18px;
  left: 50%;
  display: flex;
  width: min(960px, calc(100vw - 36px));
  transform: translateX(-50%);
  gap: 12px;
  align-items: flex-start;
}

.search {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr 42px;
  gap: 10px;
  align-items: center;
  min-width: 0;
  flex: 1;
  height: 54px;
  padding: 6px 6px 6px 16px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.search input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
}

.search input::placeholder {
  color: #6d7b82;
}

.toolbar {
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 7px;
  background: rgba(16, 32, 39, 0.07);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(0, 143, 131, 0.13);
}

.icon-button.active,
.icon-button.primary {
  background: var(--accent);
  color: white;
}

.icon-button.danger {
  background: var(--danger);
  color: white;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
}

.panel {
  position: fixed;
  z-index: 3;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.left-panel {
  left: 18px;
  bottom: 18px;
  width: min(354px, calc(100vw - 36px));
  padding: 16px;
}

.right-panel {
  right: 18px;
  bottom: 18px;
  width: 280px;
  padding: 14px;
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(0, 143, 131, 0.16), rgba(231, 162, 31, 0.18)),
    var(--panel-solid);
  color: var(--accent-strong);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.05;
  font-weight: 800;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.style-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 32, 39, 0.05);
}

.style-tab {
  min-width: 0;
  min-height: 36px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.style-tab.active {
  background: var(--panel-solid);
  color: var(--accent-strong);
  box-shadow: 0 3px 10px rgba(16, 32, 39, 0.11);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
}

.metrics div,
.insight-grid div,
.measure-readout {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.metrics dt,
.insight-grid span,
.measure-readout span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metrics dd,
.insight-grid strong,
.measure-readout strong {
  display: block;
  min-width: 0;
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.ai-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ai-title,
.section-title {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
}

.ai-title svg,
.section-title svg {
  width: 18px;
  height: 18px;
  color: var(--accent-strong);
}

.ai-box p {
  margin: 8px 0 0;
  color: #33434a;
  font-size: 13px;
  line-height: 1.45;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.measure-readout {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-top: 8px;
}

.measure-readout strong {
  color: var(--accent-strong);
  font-size: 18px;
}

.results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  display: none;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.results.visible {
  display: block;
}

.result-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  background: white;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.result-item + .result-item {
  border-top: 1px solid var(--line);
}

.result-item:hover {
  background: #eef8f5;
}

.result-item svg {
  width: 18px;
  height: 18px;
  color: var(--accent-strong);
  margin-top: 2px;
}

.result-item strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.result-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  z-index: 5;
  right: 18px;
  top: 88px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  background: rgba(16, 32, 39, 0.9);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
  font-size: 13px;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.maplibregl-popup-content {
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.maplibregl-ctrl-logo {
  display: none !important;
}

.popup-title {
  margin: 0 0 6px;
  font-weight: 800;
}

.popup-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.measure-marker {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid white;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.24);
  font-size: 12px;
  font-weight: 900;
}

@media (max-width: 860px) {
  .topbar {
    top: 10px;
    width: calc(100vw - 20px);
    flex-direction: column;
  }

  .toolbar {
    align-self: stretch;
    justify-content: space-between;
  }

  .toolbar .icon-button {
    flex: 1;
  }

  .left-panel {
    left: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
    padding: 12px;
  }

  .right-panel {
    right: 10px;
    bottom: auto;
    top: 132px;
    width: min(310px, calc(100vw - 20px));
    padding: 12px;
  }

  h1 {
    font-size: 20px;
  }
}

@media (max-width: 560px) {
  .search {
    grid-template-columns: 20px minmax(0, 1fr) 40px;
    height: 50px;
    padding-left: 12px;
  }

  .search input {
    font-size: 14px;
  }

  .right-panel {
    display: none;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .metrics div:nth-child(3),
  .metrics div:nth-child(4) {
    display: none;
  }

  .ai-box p {
    max-height: 58px;
    overflow: auto;
  }
}
