:root {
  --ink: #1f2933;
  --muted: #5b6874;
  --paper: #f7f5ef;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(31, 41, 51, 0.12);
  --accent: #1f7a5c;
  --accent-strong: #145c45;
  --accent-soft: #e5f3ec;
  --danger: #b23b3b;
  --danger-soft: #fbeaea;
  --blue: #2b6cb0;
  --shadow: 0 18px 50px rgba(20, 30, 40, 0.2);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

a {
  color: var(--accent-strong);
}

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

.panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: min(370px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-style: italic;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.target-card {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(31, 122, 92, 0.18);
  border-radius: 14px;
  background: var(--accent-soft);
}

.target-card__label {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.target-card__name {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.target-card__meta {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  padding: 9px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #fff;
}

.stat__label {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat__value {
  font-size: 1.05rem;
  font-weight: 750;
}

.control-group {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.field[hidden] {
  display: none;
}

.field__label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.range-value {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.field select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input[type="range"] {
  width: 100%;
  height: 22px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #dbe6df;
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(31, 41, 51, 0.22), 0 2px 5px rgba(31, 41, 51, 0.2);
  appearance: none;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: #dbe6df;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(31, 41, 51, 0.22), 0 2px 5px rgba(31, 41, 51, 0.2);
}

input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.field select:focus-visible,
.layer-row input:focus-visible,
.button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(31, 122, 92, 0.28);
  outline-offset: 2px;
}

.layers {
  margin-bottom: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #fff;
}

.layers summary {
  padding: 10px 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  list-style: none;
  text-transform: uppercase;
}

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

.layers summary::after {
  content: "+";
  float: right;
  color: var(--muted);
  font-weight: 500;
}

.layers[open] summary::after {
  content: "–";
}

.layer-list {
  display: grid;
  gap: 2px;
  padding: 0 8px 8px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 6px;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.9rem;
}

.layer-row:hover {
  background: #f4f6f4;
}

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

.layers--locked .layer-row {
  cursor: default;
  opacity: 0.6;
}

.layers--locked .layer-row input {
  cursor: not-allowed;
}

.lock-note {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.lock-note[hidden] {
  display: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.actions .button {
  flex: 1 1 120px;
}

.button {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button--primary {
  flex-basis: 100%;
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #fff;
}

.button--primary:hover {
  background: var(--accent-strong);
}

.button--secondary {
  border-color: var(--panel-border);
  background: #fff;
  color: var(--ink);
}

.button--secondary:hover {
  border-color: rgba(31, 41, 51, 0.28);
}

.button--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button--ghost:hover {
  background: #f1f3f2;
  color: var(--ink);
}

.feedback {
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #fff;
  font-size: 0.92rem;
  line-height: 1.4;
}

.feedback p {
  margin: 0;
}

.feedback p + p {
  margin-top: 6px;
}

.feedback__hint {
  color: var(--muted);
}

.feedback__meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.feedback--success {
  border-color: rgba(39, 174, 96, 0.35);
  background: #effaf3;
}

.feedback--success strong {
  color: #1e8449;
}

.feedback--error {
  border-color: rgba(192, 57, 43, 0.3);
  background: var(--danger-soft);
}

.feedback--error strong {
  color: var(--danger);
}

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

.toast {
  position: fixed;
  z-index: 3000;
  bottom: 24px;
  left: 50%;
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(31, 41, 51, 0.94);
  color: #fff;
  font-size: 0.86rem;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
}

.toast[hidden] {
  display: none;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  z-index: 4000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 32, 0.42);
  backdrop-filter: blur(2px);
}

.modal__card {
  position: relative;
  width: min(520px, 100%);
  max-height: min(80vh, 720px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal__card h2 {
  margin: 0 0 12px;
  font-size: 1.35rem;
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.modal__actions .button {
  flex: 1 1 140px;
}

.summary__score {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.summary__list {
  display: grid;
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.summary__list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #f6f7f6;
  font-size: 0.9rem;
}

.summary__list .ok {
  color: #1e8449;
  font-weight: 700;
}

.summary__list .bad {
  color: var(--danger);
  font-weight: 700;
}

.sources {
  display: grid;
  gap: 10px;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.5;
}

.sources p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.noscript {
  position: fixed;
  z-index: 5000;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
}

.map-dot {
  width: 16px;
  height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(31, 41, 51, 0.35), 0 3px 8px rgba(31, 41, 51, 0.3);
}

.debug-marker {
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.debug-marker__dot {
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(31, 41, 51, 0.3);
}

.debug-marker__label {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.blind-popup .maplibregl-popup-content {
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.3;
}

@media (max-width: 760px) {
  #map {
    bottom: 52vh;
    bottom: 52dvh;
  }

  .panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 52vh;
    height: 52dvh;
    max-height: 52vh;
    max-height: 52dvh;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 20px 20px 0 0;
  }

  .panel__header {
    margin-bottom: 8px;
  }

  h1 {
    font-size: 1rem;
  }

  .target-card {
    margin-bottom: 10px;
    padding: 9px 11px;
  }

  .target-card__name {
    font-size: 1.3rem;
  }

  .stats {
    gap: 6px;
    margin-bottom: 10px;
  }

  .stat {
    padding: 7px 8px;
  }

  .control-group {
    gap: 8px;
    margin-bottom: 10px;
  }

  .layers {
    margin-bottom: 10px;
  }

  .actions {
    margin-bottom: 8px;
  }

  .feedback {
    min-height: 42px;
  }

  .lock-note {
    margin: -2px 0 8px;
    font-size: 0.74rem;
  }

  .panel__footnote {
    display: none;
  }

  .maplibregl-ctrl-scale {
    display: none;
  }

  .toast {
    bottom: calc(52vh + 16px);
    bottom: calc(52dvh + 16px);
  }
}

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