:root {
  color-scheme: light;
  --ink: #17201e;
  --ink-soft: #26302d;
  --muted: #64706c;
  --soft: #f1f4f2;
  --line: #dce3df;
  --panel: #f8faf9;
  --panel-strong: #ffffff;
  --canvas: #dfe7e2;
  --accent: #07836d;
  --accent-dark: #056655;
  --accent-soft: #def2ea;
  --warm: #ef6548;
  --warning: #c48729;
  --shadow: 0 16px 38px rgba(23, 32, 30, 0.14);
  --shadow-soft: 0 8px 22px rgba(23, 32, 30, 0.1);
  --topbar-height: 68px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  background: var(--canvas);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

::selection {
  color: #fff;
  background: var(--accent);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

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

button {
  color: inherit;
}

.app-shell {
  height: 100%;
  min-height: 100%;
}

.topbar {
  position: relative;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 20px;
  color: #fff;
  background: #141a19;
  border-bottom: 1px solid #2a3431;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
}

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

.brand-mark {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.16);
}

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

.brand > span:last-child {
  display: grid;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  font-size: 16px;
  line-height: 20px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand small {
  overflow: hidden;
  color: #aeb9b5;
  font-size: 11px;
  line-height: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px;
  color: #dce4e1;
  font-size: 12px;
  background: #202826;
  border: 1px solid #34403c;
  border-radius: 999px;
}

.status-pill .status-dot {
  width: 7px;
  height: 7px;
  background: #4bd1a5;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(75, 209, 165, 0.12);
}

.status-pill[data-status="checking"] .status-dot {
  background: #e4a94f;
  box-shadow: 0 0 0 3px rgba(228, 169, 79, 0.14);
}

.status-pill[data-status="error"] .status-dot {
  background: #e26445;
  box-shadow: 0 0 0 3px rgba(226, 100, 69, 0.14);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(380px, 408px) minmax(0, 1fr);
  height: calc(100vh - var(--topbar-height));
}

.control-panel {
  position: relative;
  z-index: 500;
  overflow: auto;
  scrollbar-color: #b8c4bf transparent;
  scrollbar-width: thin;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 6px 0 20px rgba(23, 32, 30, 0.04);
}

.control-panel::-webkit-scrollbar {
  width: 8px;
}

.control-panel::-webkit-scrollbar-thumb {
  background: #b8c4bf;
  border: 2px solid var(--panel);
  border-radius: 8px;
}

.panel-section {
  padding: 24px 26px;
  border-bottom: 1px solid var(--line);
}

.target-section,
.output-section {
  background: var(--panel-strong);
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-heading.compact {
  align-items: center;
  margin-bottom: 14px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 750;
  line-height: 14px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

h1 {
  display: -webkit-box;
  max-width: 292px;
  overflow: hidden;
  font-size: 23px;
  font-weight: 740;
  line-height: 29px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

h2 {
  font-size: 18px;
  font-weight: 720;
  line-height: 22px;
}

.icon-button {
  display: inline-grid;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  color: #d4d9dc;
  background: transparent;
  border: 1px solid #3a3f46;
  border-radius: 7px;
  cursor: pointer;
}

.icon-button:hover {
  color: #fff;
  background: #2b3036;
}

.icon-button:focus-visible,
.map-tool:focus-visible,
.primary-button:focus-visible,
.quick-places button:focus-visible,
.platform-tabs button:focus-visible,
.map-search button:focus-visible,
.section-toggle:focus-visible {
  outline: 3px solid rgba(8, 127, 106, 0.25);
  outline-offset: 2px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button.subtle {
  color: var(--muted);
  background: #f0f3f1;
  border-color: #e4e9e6;
}

.icon-button.subtle:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: #c5e3d9;
}

.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.coordinate-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.coordinate-grid label > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input[type="number"],
input[type="search"],
input[type="text"] {
  min-width: 0;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd4d0;
  border-radius: 6px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.coordinate-grid input {
  width: 100%;
  height: 44px;
  padding: 0 11px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

input[type="number"]:focus,
input[type="search"]:focus,
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 106, 0.11);
}

input.invalid {
  border-color: #c83e34;
  box-shadow: 0 0 0 3px rgba(200, 62, 52, 0.1);
}

input:disabled {
  color: #8a9297;
  cursor: not-allowed;
  background: #f2f4f3;
  opacity: 1;
}

.quick-places {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 15px;
}

.quick-places button {
  min-height: 32px;
  padding: 5px 10px;
  color: #4d565b;
  font-size: 12px;
  font-weight: 620;
  background: #f0f3f1;
  border: 1px solid #e5e9e7;
  border-radius: 6px;
  cursor: pointer;
}

.quick-places button:hover,
.quick-places button.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: #b8ded1;
}

.settings-section {
  padding-top: 0;
  padding-bottom: 0;
}

.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 58px;
  padding: 0;
  font-size: 14px;
  font-weight: 700;
  background: none;
  border: 0;
  cursor: pointer;
}

.section-toggle > span {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.section-toggle svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.toggle-chevron {
  transition: transform 180ms ease;
}

.section-toggle[aria-expanded="false"] .toggle-chevron {
  transform: rotate(180deg);
}

.settings-body {
  padding: 1px 0 19px;
}

.settings-body[hidden] {
  display: none;
}

.rule-options[hidden] {
  display: none;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  border-bottom: 1px solid #e8edea;
}

.field-row label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 620;
}

.field-row label small {
  color: #9aa1a5;
  font-size: 11px;
  font-weight: 500;
}

.field-row input {
  width: 100%;
  height: 34px;
  padding: 0 8px;
  text-align: right;
}

.switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: center;
  gap: 16px;
  min-height: 56px;
  cursor: pointer;
}

.switch-row > span:first-child {
  display: grid;
  min-width: 0;
}

.switch-row strong {
  font-size: 13px;
  line-height: 18px;
}

.switch-row small {
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
}

.switch-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch {
  position: relative;
  width: 40px;
  height: 24px;
  background: #c9cfcc;
  border-radius: 999px;
  transition: background 160ms ease;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(23, 26, 31, 0.28);
  transition: transform 160ms ease;
}

.switch-row input:checked + .switch {
  background: var(--accent);
}

.switch-row input:checked + .switch::after {
  transform: translateX(16px);
}

.switch-row input:focus-visible + .switch {
  outline: 3px solid rgba(8, 127, 106, 0.2);
  outline-offset: 2px;
}

.format-badge {
  padding: 5px 8px;
  color: var(--accent-dark);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-soft);
  border: 1px solid #c5e3d9;
  border-radius: 5px;
}

.platform-tabs {
  display: grid;
  grid-template-columns: 1.35fr 0.85fr 0.9fr 0.7fr;
  gap: 3px;
  padding: 3px;
  background: #edf1ef;
  border: 1px solid #e2e8e4;
  border-radius: 8px;
}

.platform-tabs button {
  min-width: 0;
  min-height: 38px;
  padding: 5px 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.platform-tabs button[aria-selected="true"] {
  color: var(--accent-dark);
  background: #fff;
  box-shadow: inset 0 0 0 1px #bddfd4, 0 1px 3px rgba(23, 32, 30, 0.09);
}

.platform-tabs button:focus-visible {
  outline: 3px solid rgba(8, 127, 106, 0.2);
  outline-offset: 1px;
}

.code-preview-wrap {
  position: relative;
  height: 144px;
  margin-top: 14px;
  overflow: hidden;
  background: #1b2220;
  border: 1px solid #303b38;
  border-radius: 8px;
}

#config-preview {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 14px 44px 14px 14px;
  overflow: auto;
  color: #e0e9e5;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  line-height: 16px;
  white-space: pre;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  color: #afb7b9;
  background: #28312f;
  border-color: #3b4844;
}

.platform-note {
  min-height: 34px;
  margin: 10px 0 13px;
  color: var(--muted);
  font-size: 11px;
  line-height: 17px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  padding: 8px 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 720;
  background: var(--accent);
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(7, 131, 109, 0.22);
}

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.primary-button svg {
  width: 17px;
  height: 17px;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: grid;
  z-index: 550;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
  background-color: #e7ece8;
  background-image:
    linear-gradient(#d3dbd6 1px, transparent 1px),
    linear-gradient(90deg, #d3dbd6 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 1;
  visibility: visible;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.map-loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.map-loading svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.map-search {
  position: absolute;
  z-index: 600;
  top: 18px;
  left: 18px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  width: min(500px, calc(100% - 96px));
  height: 52px;
  padding: 0 7px 0 15px;
  background: #fff;
  border: 1px solid rgba(23, 26, 31, 0.16);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.map-search:focus-within {
  border-color: rgba(7, 131, 109, 0.66);
  box-shadow: 0 0 0 3px rgba(7, 131, 109, 0.13), var(--shadow);
}

.map-search > svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.map-search input {
  width: 100%;
  height: 44px;
  padding: 0 10px;
  border: 0;
  box-shadow: none;
}

.map-search input:focus {
  box-shadow: none;
}

.map-search button {
  min-width: 58px;
  height: 38px;
  padding: 0 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  background: var(--ink-soft);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.map-search button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.map-search button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.map-tools {
  position: absolute;
  z-index: 600;
  top: 18px;
  right: 18px;
  display: grid;
  gap: 8px;
}

.map-tool {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(23, 26, 31, 0.16);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.map-tool:hover {
  color: var(--accent);
}

.map-tool svg {
  width: 19px;
  height: 19px;
}

.map-readout {
  position: absolute;
  z-index: 600;
  bottom: 20px;
  left: 18px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 14px;
  color: #fff;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  background: rgba(23, 32, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  box-shadow: 0 4px 16px rgba(23, 26, 31, 0.18);
}

.readout-dot {
  width: 7px;
  height: 7px;
  background: #54d6ad;
  border-radius: 50%;
}

.map-hint {
  position: absolute;
  z-index: 600;
  right: 18px;
  bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 11px;
  color: #5f676b;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(23, 26, 31, 0.12);
  border-radius: 7px;
  box-shadow: 0 4px 14px rgba(23, 26, 31, 0.1);
}

.map-hint svg {
  width: 15px;
  height: 15px;
}

.leaflet-control-zoom {
  margin-top: 88px !important;
  margin-left: 18px !important;
  border: 0 !important;
  box-shadow: var(--shadow-soft) !important;
}

.leaflet-control-zoom a {
  color: var(--ink) !important;
  border-color: var(--line) !important;
}

.leaflet-control-zoom a:first-child {
  border-radius: 7px 7px 0 0 !important;
}

.leaflet-control-zoom a:last-child {
  border-radius: 0 0 7px 7px !important;
}

.leaflet-control-attribution {
  font-size: 9px !important;
}

.target-marker {
  position: relative;
  width: 26px;
  height: 26px;
  background: var(--warm);
  border: 4px solid #fff;
  border-radius: 50% 50% 50% 0;
  box-shadow: 0 5px 16px rgba(23, 26, 31, 0.28);
  transform: rotate(-45deg);
}

.target-marker::after {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 6px;
  height: 6px;
  content: "";
  background: #fff;
  border-radius: 50%;
}

.toast {
  position: fixed;
  z-index: 2000;
  right: 18px;
  bottom: 68px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  pointer-events: none;
  visibility: hidden;
  background: var(--ink-soft);
  border: 1px solid #3a4743;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms;
}

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

.toast.error {
  background: #8f3029;
  border-color: #a8443a;
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - var(--topbar-height));
  }

  .map-stage {
    order: -1;
    height: min(50vh, 480px);
    min-height: 340px;
  }

  .control-panel {
    overflow: visible;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .target-section,
  .settings-section,
  .output-section {
    max-width: 720px;
    margin-inline: auto;
  }

  .control-panel > .panel-section {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  :root {
    --topbar-height: 60px;
  }

  .topbar {
    padding: 0 12px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand small {
    display: none;
  }

  .status-pill {
    width: 30px;
    padding: 0;
    justify-content: center;
  }

  #source-status-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .topbar .icon-button {
    width: 34px;
    height: 34px;
  }

  .map-stage {
    height: min(44svh, 370px);
    min-height: 300px;
  }

  .map-search {
    top: 12px;
    left: 12px;
    width: calc(100% - 72px);
    height: 46px;
  }

  .map-search input {
    height: 40px;
    padding-right: 5px;
    font-size: 13px;
  }

  .map-search button {
    min-width: 48px;
    height: 34px;
    padding: 0 8px;
  }

  .map-tools {
    top: 12px;
    right: 12px;
  }

  .map-tool {
    width: 40px;
    height: 40px;
  }

  .leaflet-control-zoom {
    display: none;
  }

  .map-readout {
    right: 12px;
    bottom: 12px;
    left: 12px;
    justify-content: center;
  }

  .map-hint {
    display: none;
  }

  .panel-section {
    padding: 21px 16px;
  }

  .settings-section {
    padding-top: 0;
    padding-bottom: 0;
  }

  h1 {
    max-width: min(270px, calc(100vw - 88px));
    font-size: 20px;
    line-height: 26px;
  }

  .coordinate-grid {
    gap: 8px;
  }

  .coordinate-grid input {
    padding: 0 8px;
    font-size: 12px;
  }

  .quick-places {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .quick-places button {
    padding-inline: 4px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .field-row {
    grid-template-columns: minmax(0, 1fr) 96px;
  }

  .platform-note {
    min-height: 0;
  }

  .toast {
    top: calc(var(--topbar-height) + 66px);
    right: auto;
    bottom: auto;
    left: 50%;
    transform: translate(-50%, -8px);
  }

  .toast.visible {
    transform: translate(-50%, 0);
  }
}

@media (max-width: 350px) {
  .quick-places {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .platform-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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