:root {
  --ink: #17231f;
  --muted: #68766f;
  --line: #d5dfd9;
  --paper: #f1f3ea;
  --surface: #fffdf7;
  --panel: #f7f8f1;
  --teal: #08766b;
  --teal-dark: #04564f;
  --blue: #1e66d0;
  --amber: #c97816;
  --rose: #d44855;
  --green-soft: #e1f1eb;
  --map-backdrop: #dce8e2;
  --shadow: 0 24px 70px rgba(27, 48, 40, 0.16);
  font-family: "Be Vietnam Pro", "Segoe UI", sans-serif;
}

body {
  background:
    radial-gradient(circle at 8% 8%, rgba(240, 177, 72, 0.2), transparent 24rem),
    radial-gradient(circle at 92% 18%, rgba(8, 118, 107, 0.18), transparent 30rem),
    linear-gradient(135deg, #eef2e8 0%, #f7f3e8 46%, #e6f0eb 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(23, 35, 31, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 35, 31, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 78%);
}

.app-shell {
  background: rgba(244, 247, 240, 0.96);
  border-color: rgba(42, 67, 58, 0.12);
  box-shadow: var(--shadow);
}

.topbar {
  position: relative;
  isolation: isolate;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  overflow: hidden;
  border-bottom-color: rgba(48, 76, 66, 0.12);
  background:
    radial-gradient(circle at 88% 12%, rgba(238, 176, 66, 0.2), transparent 17rem),
    linear-gradient(110deg, rgba(255, 254, 248, 0.99), rgba(239, 247, 241, 0.98));
  box-shadow: 0 7px 24px rgba(27, 48, 40, 0.07);
}

.topbar::after {
  position: absolute;
  right: -42px;
  bottom: -70px;
  z-index: -1;
  width: 190px;
  height: 130px;
  border: 22px solid rgba(8, 118, 107, 0.07);
  border-radius: 50%;
  content: "";
  transform: rotate(-12deg);
}

.brand-mark {
  border: 1px solid rgba(8, 118, 107, 0.18);
  background: #fffdf7;
  box-shadow: 0 8px 22px rgba(4, 86, 79, 0.16);
}

.eyebrow {
  color: var(--teal-dark);
  letter-spacing: 0.07em;
}

h1 {
  color: #14221d;
  letter-spacing: -0.025em;
}

.top-stats span {
  border-color: rgba(8, 118, 107, 0.13);
  background: rgba(255, 253, 247, 0.78);
  box-shadow: 0 3px 10px rgba(27, 48, 40, 0.035);
}

.screen {
  background:
    radial-gradient(circle at 92% 3%, rgba(8, 118, 107, 0.06), transparent 18rem),
    #f3f6f0;
}

.search-box,
.tool-button,
.fullscreen-trigger,
.secondary-button {
  border-color: rgba(42, 67, 58, 0.14);
  background: rgba(255, 254, 249, 0.96);
}

.search-box {
  box-shadow: 0 10px 26px rgba(27, 48, 40, 0.08);
}

.search-box:focus-within {
  border-color: rgba(8, 118, 107, 0.52);
  box-shadow: 0 0 0 4px rgba(8, 118, 107, 0.1), 0 12px 26px rgba(27, 48, 40, 0.08);
}

.map-mode-bar {
  padding: 4px;
  border: 1px solid rgba(42, 67, 58, 0.11);
  border-radius: 14px;
  background: rgba(227, 235, 229, 0.88);
}

.map-mode {
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 0.78rem;
}

.map-mode.active {
  background: linear-gradient(145deg, #0a7c70, #04564f);
  box-shadow: 0 8px 18px rgba(4, 86, 79, 0.22);
}

.map-stage {
  border-color: rgba(31, 71, 58, 0.18);
  border-radius: 20px;
  box-shadow: 0 22px 52px rgba(27, 48, 40, 0.18);
}

.real-map .leaflet-tile-pane {
  filter: saturate(0.82) contrast(1.035) brightness(1.025) sepia(0.035);
}

.map-tools,
.atlas-title,
.atlas-legend,
.map-load-status,
.map-coordinate-readout {
  border-color: rgba(42, 67, 58, 0.13);
  background: rgba(255, 254, 249, 0.93);
  box-shadow: 0 10px 28px rgba(27, 48, 40, 0.15);
  backdrop-filter: blur(18px) saturate(1.1);
}

.map-tools {
  border-radius: 13px;
}

.atlas-title {
  border-radius: 13px;
}

.hamlet-map-pin {
  box-shadow: 0 4px 12px rgba(24, 49, 40, 0.28);
}

.hamlet-map-pin.selected {
  background: #08766b;
  box-shadow: 0 0 0 5px rgba(8, 118, 107, 0.16), 0 7px 18px rgba(4, 86, 79, 0.32);
}

.quick-panel,
.hamlet-item,
.detail-card,
.boundary-box,
.stats-grid div,
.coordinate-history {
  border-color: rgba(42, 67, 58, 0.12);
  border-radius: 16px;
  background: rgba(255, 254, 249, 0.97);
  box-shadow: 0 10px 28px rgba(27, 48, 40, 0.07);
}

.quick-panel {
  background:
    radial-gradient(circle at 100% 0%, rgba(239, 176, 65, 0.12), transparent 15rem),
    linear-gradient(180deg, #fffef9, #f8fbf6);
}

.selected-summary > strong,
.detail-card h2 {
  letter-spacing: -0.025em;
}

.selected-stats span,
.info-grid div {
  border-color: rgba(8, 118, 107, 0.1);
  background: linear-gradient(145deg, #f8fbf6, #eef5ef);
}

.primary-button {
  background: linear-gradient(145deg, #0a7c70, #04564f);
  box-shadow: 0 9px 20px rgba(4, 86, 79, 0.23);
}

.route-button {
  background: linear-gradient(145deg, #2874d8, #174fa7);
  box-shadow: 0 9px 20px rgba(30, 102, 208, 0.2);
}

.hamlet-item {
  position: relative;
  overflow: hidden;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.hamlet-item::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(#0a7c70, #efb041);
  content: "";
  opacity: 0.76;
}

.hamlet-item:hover {
  border-color: rgba(8, 118, 107, 0.28);
  box-shadow: 0 16px 34px rgba(27, 48, 40, 0.11);
  transform: translateY(-2px);
}

.population-bar i {
  background: linear-gradient(90deg, #08766b, #42a68e);
}

.list-filter-bar {
  border-color: rgba(42, 67, 58, 0.11);
  border-radius: 14px;
  background: rgba(226, 235, 228, 0.9);
}

.list-filter-bar button {
  border-radius: 10px;
}

.list-filter-bar button.active {
  background: #fffef9;
  box-shadow: 0 6px 16px rgba(27, 48, 40, 0.09);
}

.bottom-nav {
  border-color: rgba(42, 67, 58, 0.12);
  background: rgba(255, 254, 249, 0.96);
  box-shadow: 0 -12px 30px rgba(27, 48, 40, 0.08);
  backdrop-filter: blur(18px);
}

.nav-item {
  position: relative;
  border-radius: 13px;
}

.nav-item.active {
  background: linear-gradient(145deg, #e4f4ed, #d9ede5);
  box-shadow: inset 0 0 0 1px rgba(8, 118, 107, 0.09);
}

.nav-item.active::after {
  position: absolute;
  bottom: 3px;
  width: 18px;
  height: 3px;
  border-radius: 99px;
  background: var(--teal);
  content: "";
}

@media (hover: hover) and (pointer: fine) {
  button,
  a {
    transition: filter 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  }

  button:hover,
  a:hover {
    filter: brightness(1.015);
  }

  .primary-button:hover,
  .route-button:hover,
  .tool-button:hover,
  .secondary-button:hover {
    transform: translateY(-1px);
  }
}

@media (min-width: 1120px) {
  body {
    padding: 20px;
  }

  .app-shell {
    grid-template-columns: 94px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    width: min(1500px, calc(100vw - 40px));
    max-width: 1500px;
    height: calc(100dvh - 40px);
    max-height: 1040px;
    overflow: hidden;
    border: 1px solid rgba(42, 67, 58, 0.14);
    border-radius: 28px;
  }

  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 17px 26px 16px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    border-radius: 14px;
  }

  h1 {
    font-size: 1.34rem;
  }

  .top-stats {
    margin-top: 7px;
  }

  main {
    grid-column: 2;
    grid-row: 2;
  }

  .screen {
    padding: 20px 22px 22px;
  }

  #mapView.screen.active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(320px, 23vw, 360px);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px 18px;
    overflow: hidden;
  }

  #mapView .search-row {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  #mapView .map-stage {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    flex: none;
  }

  #mapView .quick-panel {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 18px;
    overflow: hidden;
  }

  #mapView .selected-summary > strong {
    font-size: 1.38rem;
  }

  #mapView .selected-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #mapView .selected-stats span {
    min-height: 64px;
    align-content: center;
    padding: 9px 10px;
  }

  #mapView .coordinate-audit {
    display: none;
  }

  #mapView .quick-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: auto;
  }

  #mapView .quick-actions > * {
    width: 100%;
    min-height: 42px;
    padding-inline: 7px;
    font-size: 0.64rem;
  }

  #mapView #selectedMeta {
    margin-block: 4px 0;
    font-size: 0.78rem;
    line-height: 1.55;
  }

  #mapView .selected-boundary-evidence {
    white-space: normal;
  }

  #installBtn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .bottom-nav {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, min-content);
    align-content: center;
    gap: 10px;
    padding: 18px 10px;
    border-top: 0;
    border-right: 1px solid rgba(42, 67, 58, 0.12);
    box-shadow: 8px 0 28px rgba(27, 48, 40, 0.05);
  }

  .nav-item {
    height: 72px;
    padding: 8px 4px;
    font-size: 0.68rem;
  }

  .nav-item svg {
    width: 22px;
    height: 22px;
  }

  .nav-item.active::after {
    right: 3px;
    bottom: auto;
    width: 3px;
    height: 24px;
  }

  #listView.screen.active {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
  }

  #listView .hamlet-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: start;
    overflow: auto;
    padding: 4px 5px 18px;
  }

  #googleView .compare-grid {
    min-height: 560px;
  }

  #detailView .detail-card {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 24px;
  }
}

@media (min-width: 1120px) and (max-height: 800px) {
  body {
    padding-block: 10px;
  }

  .app-shell {
    height: calc(100dvh - 20px);
  }

  .topbar {
    padding-block: 12px;
  }

  #mapView .map-stage {
    min-height: 350px;
  }
}

@media (min-width: 1220px) {
  #listView .hamlet-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 1119px) {
  .app-shell {
    max-width: 820px;
  }

  .map-stage {
    flex-basis: clamp(380px, 56dvh, 560px);
    height: clamp(380px, 56dvh, 560px);
  }
}

@media (max-width: 520px) {
  .topbar {
    padding-inline: 13px;
  }

  .brand-mark {
    border-radius: 11px;
  }

  .top-stats {
    flex-wrap: nowrap;
    padding-bottom: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .top-stats::-webkit-scrollbar {
    display: none;
  }

  .top-stats span {
    flex: 0 0 auto;
  }

  .screen {
    padding-inline: 10px;
  }

  .screen.active {
    gap: 11px;
  }

  .map-stage {
    flex-basis: clamp(380px, 57dvh, 540px);
    height: clamp(380px, 57dvh, 540px);
    border-radius: 18px;
  }

  .quick-panel {
    padding: 14px;
  }

  .bottom-nav {
    padding-inline: 8px;
  }
}

.atlas-title {
  display: none;
}

@keyframes app-arrive {
  from { opacity: 0; transform: translateY(10px) scale(0.995); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes surface-arrive {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: no-preference) {
  .app-shell {
    animation: app-arrive 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .screen.active > * {
    animation: surface-arrive 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .screen.active > :nth-child(2) { animation-delay: 45ms; }
  .screen.active > :nth-child(3) { animation-delay: 90ms; }
  .screen.active > :nth-child(4) { animation-delay: 135ms; }
}

/* Keep map controls compact so the geography remains the primary surface. */
.atlas-title {
  gap: 1px;
  max-width: min(220px, calc(100% - 96px));
  padding: 7px 9px;
}

.atlas-title strong {
  font-size: 0.76rem;
  line-height: 1.25;
}

.atlas-title #coordinateProgress,
.atlas-title #boundaryEvidenceStatus {
  display: none;
}

.atlas-title .mymaps-source-link {
  margin-top: 2px;
  padding: 3px 6px;
}

.atlas-legend {
  top: 54px;
  display: block;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  pointer-events: auto;
}

.atlas-legend summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  color: var(--teal-dark);
  cursor: pointer;
  font-size: 0.66rem;
  font-weight: 900;
  list-style: none;
}

.atlas-legend summary::-webkit-details-marker {
  display: none;
}

.atlas-legend summary::before {
  width: 8px;
  height: 8px;
  border: 2px solid currentColor;
  border-radius: 2px;
  content: "";
}

.atlas-legend summary::after {
  content: "+";
  font-size: 0.86rem;
  line-height: 1;
}

.atlas-legend[open] summary::after {
  content: "-";
}

.atlas-legend-content {
  display: none;
  gap: 5px;
  padding: 0 9px 9px;
  border-top: 1px solid rgba(42, 67, 58, 0.1);
}

.atlas-legend[open] .atlas-legend-content {
  display: grid;
  padding-top: 8px;
}

.map-tools {
  gap: 3px;
  padding: 3px;
}

.map-tool-action {
  padding-inline: 7px;
}

/* Keep the map viewport clear: the utility menu owns its own compact surface. */
.map-tools {
  left: auto;
  right: 12px;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

@media (max-width: 520px) {
  .map-tools {
    left: auto;
    right: 12px;
  }

  .atlas-title {
    max-width: calc(100% - 86px);
  }

  .atlas-title strong {
    font-size: 0.7rem;
  }
}

/* Landscape phones have little vertical room; keep the interactive map above the navigation rail. */
@media (orientation: landscape) and (max-height: 600px) {
  .topbar {
    gap: 8px;
    padding: max(26px, calc(8px + env(safe-area-inset-top))) 14px 8px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  h1 {
    font-size: 1.12rem;
  }

  .top-stats {
    margin-top: 4px;
  }

  .screen {
    padding: 10px 14px calc(78px + env(safe-area-inset-bottom));
  }

  #mapView.screen.active {
    gap: 8px;
  }

  .map-stage {
    flex-basis: clamp(190px, calc(100dvh - 210px), 300px);
    height: clamp(190px, calc(100dvh - 210px), 300px);
    min-height: 190px;
  }
}
