html,
body,
.app {
  height: 100%;
  margin: 0;
  background: #0b0b0c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.app {
  display: flex;
  height: 100%;
  min-height: 100dvh;
}

#map {
  flex: 1 1 64%;
  min-width: 50vw;
  order: 1;
}

.panel,
.output-panel {
  position: absolute;
  z-index: 10;
  backdrop-filter: blur(8px);
  background: rgba(20, 20, 22, 0.68);
  color: #eaeaea;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font:
    14px/1.35 system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    sans-serif;
}

.panel {
  position: relative;
  z-index: 10;
  flex: 0 0 clamp(360px, 32vw, 440px);
  order: 2;
  width: auto;
  max-width: 440px;
  min-width: 360px;
  height: 100dvh;
  overflow-y: auto;
  padding: 14px;
  border-top: 0;
  border-bottom: 0;
  border-right: 0;
  border-radius: 0;
}

.panel-title,
.output-header {
  font-weight: 700;
  font-size: 14px;
}

.row {
  display: grid;
  grid-template-columns: minmax(108px, 0.9fr) minmax(0, 1.4fr) minmax(64px, auto);
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  padding: 10px;
  background: rgba(36, 36, 40, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}

.row label {
  min-width: 0;
  opacity: 0.95;
  cursor: pointer;
}

.row > * {
  min-width: 0;
}

.value {
  min-width: 3.5rem;
  text-align: right;
  opacity: 0.9;
}

.hint {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 4px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
}

input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: #7cd2ff;
}

.panel input[type="number"],
.panel select {
  width: 76px;
  background: #1b1b1d;
  border: 1px solid #444;
  border-radius: 6px;
  color: #eee;
  padding: 4px 6px;
  box-sizing: border-box;
  font:
    14px system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    sans-serif;
  transition:
    border 0.2s,
    background 0.2s;
}

.panel select {
  width: 100%;
  grid-column: 2 / -1;
}

.panel input[type="number"]:focus,
.panel select:focus {
  outline: none;
  border-color: #7cd2ff;
  background: #242427;
}

.panel button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 0;
  background: linear-gradient(180deg, #75c7ff, #4ba6e8);
  color: #021725;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(77, 162, 231, 0.35);
}

.panel button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:active {
  transform: translateY(1px);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.1) !important;
  color: #eaeaea !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  box-shadow: none !important;
}

.danger-button {
  margin-top: 14px;
  background: rgba(125, 48, 48, 0.78) !important;
  color: #f5eeee !important;
  border: 1px solid rgba(255, 150, 150, 0.22) !important;
  box-shadow: none !important;
}

.danger-button:hover {
  background: rgba(145, 58, 58, 0.82) !important;
}

.button-row,
.region-controls,
.action-buttons {
  display: flex;
  gap: 8px;
}

.button-row {
  margin-top: 14px;
}

.region-controls {
  grid-column: 2 / -1;
}

.region-list {
  display: grid;
  gap: 6px;
  margin: -2px 0 10px;
}

.panel .region-summary {
  width: 100%;
  padding: 8px 10px;
  background: rgba(36, 36, 40, 0.62);
  color: #d7d7da;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  box-shadow: none;
  font-size: 12px;
  text-align: left;
}

.panel .region-summary::after {
  content: "Show";
  float: right;
  color: #9ecff0;
}

.panel .region-summary[aria-expanded="true"]::after {
  content: "Hide";
}

.region-item {
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 5px 5px 10px;
  background: rgba(36, 36, 40, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}

.region-name {
  overflow: hidden;
  color: #d7d7da;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel .region-remove {
  display: grid;
  place-items: center;
  width: 28px;
  height: 24px;
  padding: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #eaeaea;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  box-shadow: none;
  font-size: 17px;
  line-height: 1;
}

.panel .region-remove:hover {
  background: rgba(125, 48, 48, 0.65);
}

.button-row button,
.region-controls button,
.action-buttons button {
  flex: 1;
}

.action-buttons {
  align-items: stretch;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
}

.switch {
  position: relative;
  width: 52px;
  height: 30px;
  justify-self: end;
  grid-column: 3;
}

.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #3a3a3e;
  transition: 0.2s;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.slider::before {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #c3c3c6;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: #1d8fea;
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
  background: #fff;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 14px 0 10px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}

.panel .tab {
  margin: 0;
  box-shadow: none;
  background: transparent;
  color: #eaeaea;
}

.panel .tab.active {
  background: #eaeaea;
  color: #111;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  padding: 2px 0 4px;
}

#progress {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 12px;
  margin-bottom: 4px;
}

#progress[hidden],
#stats[hidden],
#actionButtons[hidden],
#exportPopup[hidden] {
  display: none;
}

#exportAllPopup[hidden] {
  display: none;
}

#progressBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4ba6e8, #7cd2ff);
  transition: width 0.2s ease-out;
}

#stats {
  margin-top: 6px;
  color: #bbb;
}

.export-popup {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 54px;
  z-index: 12;
  padding: 8px;
  background: rgba(20, 20, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.export-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.export-options.two {
  grid-template-columns: repeat(2, 1fr);
}

.output-panel {
  left: 12px;
  right: auto;
  bottom: 42px;
  width: min(360px, calc(100vw - 488px));
  max-height: 38%;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 10px 12px;
  z-index: 9;
  font-size: 13px;
}

.output-header {
  margin-bottom: 8px;
}

.output-section + .output-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.output-section-title {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: #bdbdbf;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.empty-output {
  color: #9a9a9d;
  font-size: 12px;
  padding: 6px;
}

.output-row {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
}

.output-row:hover {
  background: rgba(255, 255, 255, 0.08);
}

.output-row.active {
  background: rgba(124, 210, 255, 0.18);
  border-color: #7cd2ff;
}

.coords {
  display: grid;
  grid-template-columns: 1fr min-content 0.5fr auto 1fr min-content 0.5fr;
  align-items: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
  font-size: 12px;
  opacity: 0.92;
  gap: 4px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.point-coords {
  grid-template-columns: 1fr min-content 1fr;
}

.coords span {
  text-align: right;
}

.coords .arrow {
  text-align: center;
  color: #7cd2ff;
  padding: 0 4px;
}

.countries {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.3;
  color: #bbb;
  display: none;
}

.output-row.active .countries {
  display: block;
}

@media (max-width: 900px) {
  html,
  body,
  .app {
    min-height: 100dvh;
    height: auto;
  }

  body {
    background: #0b0b0c;
    overflow-x: hidden;
  }

  .app {
    flex-direction: column;
  }

  #map {
    order: 1;
    flex: none;
    width: 100%;
    min-width: 0;
    height: 56vh;
    min-height: 360px;
    max-height: 560px;
  }

  .panel,
  .output-panel {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    width: 100%;
    max-height: none;
    margin: 0;
    overflow: visible;
    backdrop-filter: none;
    background: rgba(20, 20, 22, 0.96);
  }

  .panel {
    order: 2;
    height: auto;
    max-width: 100%;
    min-width: 0;
    padding: 14px clamp(12px, 3vw, 18px);
    flex: none;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
  }

  .row {
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr) minmax(56px, 76px);
  }

  .row label {
    grid-column: 1 / -1;
  }

  .region-controls,
  .panel select {
    grid-column: 1 / -1;
  }

  .row > input[type="range"] {
    grid-column: 1;
  }

  .row > input[type="number"],
  .row > .value {
    grid-column: 2;
  }

  .value {
    width: 100%;
    min-width: 0;
    text-align: right;
  }

  .panel select,
  .panel input[type="number"] {
    width: 100%;
    max-width: none;
  }

  .row:has(.switch) {
    align-items: center;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .row:has(.switch) label {
    grid-column: 1;
  }

  .row:has(.switch) .switch {
    grid-column: 2;
    grid-row: 1;
  }

  .action-buttons {
    flex-direction: column;
  }

  .button-row,
  .region-controls {
    flex-direction: row;
  }

  .button-row button,
  .region-controls button {
    min-width: 0;
  }

  .output-panel {
    order: 3;
    width: calc(100% - 24px);
    margin: 0 12px 18px;
  }

  .coords {
    grid-template-columns: 1fr min-content 1fr;
  }

  .coords .arrow {
    grid-column: 1 / -1;
    padding: 2px 0;
  }
}
