:root {
  --color-bg: #0E0F11;
  --color-panel: #1A1B1F;
  --color-primary: #1473E6;
  --color-primary-hover: #0D5AB7;
  --color-accent: #2D2E33;
  --color-text: #959595;
  --color-strong: #ffffff;
  --color-muted: #67686c;
  --radius: 12px;
  --font-main: "Roboto", "Inter", "Segoe UI", Arial, sans-serif;
  --font-size-base: 1rem;
  --input-height: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  font-family: var(--font-main);
  font-weight: 400;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--font-size-base);
}

button,
input,
a {
  font: inherit;
}

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

.heightmapper-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  min-height: 520px;
  background: var(--color-bg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  height: 70px;
  margin: 10px;
  padding: 0 1.25rem;
  background: var(--color-panel);
  border-radius: var(--radius);
  position: relative;
  z-index: 20;
}

.left-side,
.right-side {
  display: flex;
  align-items: center;
  min-width: 0;
}

.left-side {
  flex: 1 1 auto;
  gap: 1rem;
}

.right-side {
  flex: 0 0 auto;
  gap: 0.75rem;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 1 300px;
  height: var(--input-height);
  min-width: 180px;
  padding: 0 1rem;
  background: var(--color-accent);
  border-radius: 24px;
}

.search-icon {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-text);
  border-radius: 50%;
  opacity: 0.75;
  position: relative;
  flex: 0 0 auto;
}

.search-icon::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: -4px;
  width: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--color-text);
  transform: rotate(45deg);
}

.search input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text);
}

.search input::placeholder {
  color: #cccccc;
  opacity: 0.7;
}

.search-suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-panel);
  border: 1px solid var(--color-accent);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 100;
}

.search-suggestions.show {
  display: flex;
}

.suggestion-item {
  padding: 10px 14px;
  color: var(--color-text);
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-item:hover {
  background: var(--color-accent);
  color: var(--color-primary);
}

.btn,
.btn-flat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  height: 44px;
  border-radius: 24px;
  padding: 0 20px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.btn {
  color: var(--color-text);
  background: transparent;
  border: 2px solid var(--color-accent);
}

.btn:hover {
  background: var(--color-accent);
}

.btn-primary {
  color: #fff;
  background: var(--color-primary);
  border: none;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.button-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn.is-loading .button-spinner {
  display: inline-block;
}

.btn.is-loading {
  cursor: progress;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn:disabled,
.btn-flat:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-flat {
  color: var(--color-text);
  background: transparent;
  border: none;
}

.btn-flat:hover,
.btn-flat:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  outline: none;
}

.zoom-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  min-width: 70px;
  padding: 0 16px;
  border: 2px solid var(--color-accent);
  border-radius: 24px;
  color: var(--color-text);
  background: transparent;
}

label.height-slider {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  flex: 0 0 auto;
  width: auto;
  height: var(--input-height);
  min-height: var(--input-height);
  max-height: var(--input-height);
  margin: 0;
  padding: 0 16px;
  box-sizing: border-box;
  overflow: hidden;
  border-radius: 24px;
  color: var(--color-text);
  gap: 10px;
  min-width: 310px;
  line-height: 1;
  background: transparent;
  vertical-align: top;
}

.height-slider span {
  color: var(--color-muted);
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
}

.height-slider input {
  appearance: none;
  -webkit-appearance: none;
  flex: 1 1 auto;
  width: 100%;
  height: 18px;
  min-width: 120px;
  background: transparent;
  outline: none;
  cursor: pointer;
  display: block;
}

.height-slider input::-webkit-slider-runnable-track {
  width: 100%;
  height: 14px;
  background: #2b2c30;
  border: none;
  border-radius: 7px;
}

.height-slider input::-moz-range-track {
  width: 100%;
  height: 14px;
  background: #2b2c30;
  border: none;
  border-radius: 7px;
}

.height-slider input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -2px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.height-slider input::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
}

.height-slider input:hover::-webkit-slider-thumb {
  background: #1b83ff;
  transform: scale(1.08);
}

.height-slider .value-text {
  min-width: 32px;
  color: var(--color-text);
  text-align: right;
  font-size: 0.95rem;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 1fr);
  gap: 10px;
  flex: 1;
  min-height: 0;
  margin: 0 10px 10px;
}

.map-pane,
.preview-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: #20232a;
}

#map,
#terrainCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.heightmap-preview {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: none;
  width: auto;
  height: auto;
  max-width: 170px;
  max-height: 170px;
  border-radius: 10px;
  background: #000;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

.heightmap-preview.is-ready {
  display: block;
}

.selection-frame {
  position: absolute;
  left: 20%;
  top: 22%;
  width: 60%;
  height: 54%;
  border: 2px solid var(--color-primary);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(14, 15, 17, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.18) inset;
  pointer-events: auto;
  z-index: 3;
  cursor: move;
  touch-action: none;
}

.selection-frame::before,
.selection-frame::after {
  content: "";
  position: absolute;
  background: var(--color-primary);
}

.selection-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.42);
  pointer-events: auto;
}

.selection-handle.nw {
  left: -9px;
  top: -9px;
  cursor: nwse-resize;
}

.selection-handle.ne {
  right: -9px;
  top: -9px;
  cursor: nesw-resize;
}

.selection-handle.sw {
  left: -9px;
  bottom: -9px;
  cursor: nesw-resize;
}

.selection-handle.se {
  right: -9px;
  bottom: -9px;
  cursor: nwse-resize;
}

.selection-frame::before {
  left: 50%;
  top: -8px;
  bottom: -8px;
  width: 1px;
}

.selection-frame::after {
  top: 50%;
  left: -8px;
  right: -8px;
  height: 1px;
}

.preview-status {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: calc(100% - 32px);
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 18px;
  background: rgba(26, 27, 31, 0.92);
  border: 1px solid rgba(45, 46, 51, 0.95);
  color: var(--color-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.preview-status {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  text-align: center;
  justify-content: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 200;
  display: none;
  max-width: min(520px, calc(100vw - 28px));
  padding: 12px 16px;
  color: #fff;
  background: #1A1B1F;
  border: 1px solid #2D2E33;
  border-left: 4px solid var(--color-primary);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  transform: translateX(-50%);
}

.toast.show {
  display: block;
}

.toast.error {
  border-left-color: #ff5a5f;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(2px);
}

.modal.show {
  display: flex;
}

.modal-content {
  width: min(524px, 100%);
  padding: 22px 32px 30px;
  background: #1a1b1f;
  border: none;
  border-radius: 14px;
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.72);
}

.modal-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 107px;
  padding: 12px 42px 22px;
  border-bottom: 1px solid #303136;
}

.modal-header h2 {
  margin: 0;
  color: #5f6064;
  font-size: 1.35rem;
  line-height: 1.22;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 0;
  right: -8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 2px solid #aeb0b4;
  border-radius: 50%;
  background: transparent;
  color: #d6d7da;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.modal-close:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.08);
  transform: scale(1.06);
}

.modal-close span,
.modal-close span::after {
  display: block;
  width: 12px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
}

.modal-close span {
  transform: rotate(45deg);
}

.modal-close span::after {
  content: "";
  transform: rotate(90deg);
}

.modal-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 29px 0 0;
}

.modal-block .modal-prompt {
  margin: 0;
  color: #fff;
  font-size: 1.65rem;
  line-height: 1.2;
  text-align: center;
}

.modal-prompt strong {
  color: #2182f2;
  font-weight: 600;
}

.modal-map-preview {
  display: block;
  width: min(100%, 442px);
  height: auto;
  margin: 25px auto 18px;
  object-fit: contain;
}

.modal-action {
  align-self: center;
  min-height: 46px;
  padding: 0 21px;
  border-radius: 999px;
  font-size: 1.05rem;
  box-shadow: 0 8px 22px rgba(20, 115, 230, 0.22);
}

@media (max-width: 600px) {
  .modal {
    align-items: flex-start;
    padding: 12px;
  }

  .modal-content {
    margin: auto 0;
    padding: 16px 20px 24px;
  }

  .modal-header {
    min-height: 86px;
    padding: 10px 30px 18px;
  }

  .modal-header h2 {
    font-size: 1.05rem;
  }

  .modal-close {
    right: -4px;
  }

  .modal-block {
    padding-top: 22px;
  }

  .modal-block .modal-prompt {
    font-size: clamp(1.15rem, 5.3vw, 1.45rem);
  }

  .modal-map-preview {
    margin: 20px auto 14px;
  }
}

.maplibregl-ctrl-attrib,
.maplibregl-ctrl-bottom-left {
  font-size: 11px;
}

@media (max-width: 1180px) {
  .topbar {
    height: auto;
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .left-side,
  .right-side {
    width: 100%;
    flex-wrap: wrap;
  }

  .search {
    flex: 1 1 260px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 1fr) minmax(260px, 1fr);
  }
}

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

  .heightmapper-shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    margin: 5px;
    gap: 8px;
    padding: 10px;
  }

  .workspace {
    margin: 0 5px 5px;
    height: 680px;
  }

  .search,
  .btn,
  .btn-flat {
    width: 100%;
  }

  .left-side {
    flex-wrap: nowrap;
    gap: 8px;
  }

  .left-side .search {
    width: auto;
    flex: 1 1 auto;
  }

  .left-side .zoom-display {
    width: auto;
    flex: 0 0 auto;
  }

  .right-side {
    width: 100%;
    gap: 8px;
  }

  .height-slider {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }

  .zoom-display {
    width: 100%;
  }

  .right-side .btn-primary {
    flex: 1 0 100%;
  }

  .selection-frame {
    left: 18%;
    top: 24%;
    width: 64%;
    height: 50%;
  }
}
