:root {
  --ink: #13221d;
  --muted: #62716d;
  --brand: #0d3328;
  --brand-2: #174b3c;
  --paper: rgba(255, 255, 255, 0.96);
  --line: rgba(21, 55, 45, 0.14);
  --shadow: 0 10px 30px rgba(8, 27, 22, 0.18);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #dce9e5;
}

* { box-sizing: border-box; }

html,
body,
#app,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { color: inherit; }

#map { background: #c6e0e5; }
.map-symbol-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-header {
  position: absolute;
  z-index: 1000;
  top: 0;
  left: 0;
  right: 0;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: white;
  background: linear-gradient(135deg, #0b2e24, #184b3d);
  box-shadow: 0 3px 18px rgba(6, 29, 23, 0.2);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  flex: 0 0 44px;
  width: 44px;
  height: 32px;
  display: grid;
  place-items: center;
  color: white;
}
.brand-mark svg { width: 44px; height: 32px; fill: currentColor; }
.brand-mark .brand-mountain { fill: #c4bb6c; }

.brand-copy { min-width: 0; display: grid; gap: 1px; }
.brand-title { font-size: 18px; font-weight: 750; letter-spacing: -0.02em; }
.brand-status {
  max-width: 52vw;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.72);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-button,
.tool-button,
.location-button,
.base-button,
.sheet-close,
.clear-search {
  border: 0;
  cursor: pointer;
}

.header-button {
  flex: 0 0 auto;
  min-width: 50px;
  min-height: 44px;
  padding: 4px 7px;
  display: grid;
  place-items: center;
  gap: 1px;
  color: white;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  font-size: 9px;
  font-weight: 700;
}

.header-button svg,
.tool-button svg,
.location-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.search-wrap {
  position: absolute;
  z-index: 950;
  top: calc(64px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
}

.search-box {
  height: 46px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 15px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.search-box > svg {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #536660;
  stroke-width: 2;
}

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

.search-box input::placeholder { color: #74817e; }

.clear-search,
.sheet-close {
  display: grid;
  place-items: center;
  color: #52635e;
  background: transparent;
  border-radius: 50%;
}

.clear-search { width: 34px; height: 34px; font-size: 25px; }

.search-results {
  margin-top: 7px;
  max-height: min(52vh, 440px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.search-result {
  width: 100%;
  padding: 12px 15px;
  display: grid;
  gap: 3px;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #e8eeec;
  cursor: pointer;
}

.search-result:last-child { border-bottom: 0; }
.search-result strong { font-size: 15px; }
.search-result span { color: var(--muted); font-size: 12px; line-height: 1.35; }
.search-empty { margin: 0; padding: 18px; color: var(--muted); text-align: center; }

.map-toolbar {
  position: absolute;
  z-index: 900;
  top: calc(118px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.basemap-switch,
.tool-button { pointer-events: auto; box-shadow: 0 6px 20px rgba(9, 34, 27, 0.16); }

.basemap-switch {
  padding: 3px;
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  backdrop-filter: blur(12px);
}

.base-button {
  min-height: 38px;
  padding: 0 9px;
  color: #53635e;
  background: transparent;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 750;
}

.base-button.active {
  color: white;
  background: var(--brand);
}

.base-button.detail-waiting::after {
  content: "zoom";
  margin-left: 3px;
  opacity: .68;
  font-size: 8px;
  font-weight: 650;
}

.tool-button {
  min-height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--brand);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(13, 51, 40, 0.2);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.tool-button[aria-pressed="true"] { color: white; background: var(--brand); }

.location-button {
  position: absolute;
  z-index: 900;
  left: 10px;
  bottom: calc(46px + env(safe-area-inset-bottom));
  min-height: 48px;
  max-width: calc(100vw - 100px);
  padding: 5px 13px 5px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 24px;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(12px);
}

.location-icon {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: white;
  background: #1769e0;
  border-radius: 50%;
}

.location-button.locating .location-icon { animation: pulse 1.2s infinite; }
.location-button.blocked .location-icon { background: #b63b31; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(23, 105, 224, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(23, 105, 224, 0); }
}

.source-strip {
  position: absolute;
  z-index: 850;
  left: 50%;
  bottom: calc(7px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 118px);
  padding: 3px 6px;
  transform: translateX(-50%);
  overflow: hidden;
  color: #52615d;
  background: rgba(255, 255, 255, 0.82);
  border-radius: 6px;
  font-size: 8px;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.source-strip a { color: inherit; text-decoration: none; }

.toast {
  position: absolute;
  z-index: 1400;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  max-width: min(90vw, 440px);
  padding: 10px 14px;
  transform: translateX(-50%);
  color: white;
  background: rgba(16, 48, 39, 0.94);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

.sheet-backdrop {
  position: absolute;
  z-index: 1600;
  inset: 0;
  background: rgba(4, 19, 15, 0.36);
  backdrop-filter: blur(1px);
}

.bottom-sheet,
.modal-card {
  position: absolute;
  z-index: 1700;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 -16px 50px rgba(7, 28, 22, 0.24);
}

.bottom-sheet {
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(78vh, 680px);
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 1px auto 10px;
  background: #d4ddda;
  border-radius: 5px;
}

.sheet-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 15px;
}

.sheet-heading h2,
.modal-card h2 { margin: 1px 0 13px; font-size: 22px; letter-spacing: -0.025em; }
.eyebrow { margin: 0; color: #667873; font-size: 10px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.sheet-close { flex: 0 0 40px; width: 40px; height: 40px; font-size: 29px; }

.layer-options { display: grid; border-top: 1px solid #e8eeec; }
.layer-options label {
  min-height: 44px;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid #e8eeec;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.layer-options input { width: 18px; height: 18px; accent-color: var(--brand); }
.layer-options strong { color: #63736f; font-size: 12px; }
.legend-swatch { width: 25px; height: 17px; border-radius: 4px; }
.app-exploration { background: repeating-linear-gradient(135deg, rgba(38,115,0,.14) 0 4px, #267300 4px 6px); border: 1px solid #267300; }
.active-exploration { background: rgba(38,115,0,.6); border: 1px solid #103300; }
.extension { background: rgba(222,158,102,.6); border: 1px solid #30381f; }
.contest-pending { background: rgba(170,102,205,.6); border: 2px solid #e8beff; }
.contest-open { background: rgba(170,102,205,.65); border: 2px solid #704489; }
.contest-closed { background: rgba(170,102,205,.6); border: 2px solid #999; }
.reserved-area { background: linear-gradient(90deg, rgba(167,169,172,.6) 0 50%, rgba(214,157,188,.6) 50%); border: 1px solid #4e4e4e; }

.bottom-sheet h3 { margin: 19px 0 10px; font-size: 14px; }
.legend-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px 12px; }
.legend-grid span { display: flex; align-items: center; gap: 8px; color: #485a55; font-size: 12px; }
.legend-grid i { width: 18px; height: 18px; background: var(--swatch); border: 1px solid rgba(0,0,0,.28); border-radius: 50%; }
.legend-grid i.hatch { border-radius: 4px; }
.legend-grid i.hatch.exploration { background: repeating-linear-gradient(135deg, transparent 0 4px, #267300 4px 6px); border-color: #267300; }
.legend-grid i.hatch.mining { background: repeating-linear-gradient(135deg, transparent 0 4px, #0084a8 4px 6px); border-color: #0084a8; }
.legend-grid i.hatch.prospecting { background: repeating-linear-gradient(135deg, transparent 0 4px, #a80000 4px 6px); border-color: #a80000; }

.data-status {
  margin-top: 20px;
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  border-top: 1px solid #e8eeec;
  font-size: 11px;
}
.data-status a { color: var(--brand); font-weight: 750; }

.detail-fields { margin: 0; display: grid; grid-template-columns: minmax(92px,.42fr) 1fr; }
.detail-fields dt,
.detail-fields dd { margin: 0; padding: 9px 0; border-bottom: 1px solid #e8eeec; font-size: 13px; line-height: 1.4; }
.detail-fields dt { color: var(--muted); }
.detail-fields dd { overflow-wrap: anywhere; font-weight: 650; }
.detail-actions { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.primary-action,
.secondary-action {
  min-height: 47px;
  padding: 11px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--brand);
  border-radius: 13px;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.primary-action { color: white; background: var(--brand); }
.secondary-action { color: var(--brand); background: white; }

.modal-card {
  top: 50%;
  left: 50%;
  width: min(calc(100vw - 32px), 420px);
  padding: 24px;
  transform: translate(-50%, -50%);
  border-radius: 22px;
  text-align: center;
}
.modal-card > .sheet-close { position: absolute; top: 8px; right: 8px; }
.modal-card p { margin: 0 0 18px; color: var(--muted); line-height: 1.55; }
.modal-card .primary-action { width: 100%; }
.modal-icon {
  width: 55px;
  height: 55px;
  margin: 3px auto 13px;
  display: grid;
  place-items: center;
  color: #b63b31;
  background: #fae9e7;
  border-radius: 50%;
}
.modal-icon svg { width: 29px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.leaflet-control-zoom {
  margin-right: 10px !important;
  margin-bottom: calc(46px + env(safe-area-inset-bottom)) !important;
  border: 0 !important;
  border-radius: 13px !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}
.leaflet-control-zoom a { width: 40px !important; height: 40px !important; line-height: 38px !important; border-color: #e1e8e5 !important; font-size: 21px !important; }
.leaflet-control-container .leaflet-control-attribution { display: none; }
.leaflet-interactive:focus { outline: 3px solid rgba(255, 190, 30, 0.8); outline-offset: 2px; }

.user-location-marker { position: relative; width: 22px; height: 22px; }
.user-location-marker::before {
  content: "";
  position: absolute;
  inset: 3px;
  background: #1769e0;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 9px rgba(0, 45, 120, .45);
}
.user-location-marker::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid rgba(23, 105, 224, .35);
  border-radius: 50%;
}

[hidden] { display: none !important; }

@media (max-width: 390px) {
  .base-button { padding: 0 7px; font-size: 10px; }
  .tool-button { padding: 0 8px; }
  .tool-button span { max-width: 76px; overflow: hidden; text-overflow: ellipsis; }
  .source-strip { max-width: calc(100vw - 112px); }
}

@media (min-width: 760px) {
  .search-wrap { width: min(620px, calc(100vw - 220px)); right: auto; left: 20px; }
  .map-toolbar { top: calc(118px + env(safe-area-inset-top)); left: 20px; right: 20px; }
  .bottom-sheet { left: auto; width: 430px; border-radius: 24px 0 0 0; }
  .location-button { left: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
