#open-terrain[hidden],
#terrain-view [hidden] {
  display: none;
}
#terrain-view {
  color: #f2eef4;
  background: #171d29;
  border: 1px solid #68586a;
  border-radius: 14px;
  padding: 0;
  width: min(1120px, 96vw);
  max-width: 100vw;
  height: min(820px, 92vh);
  height: min(820px, 92dvh);
  max-height: 100dvh;
  overflow: hidden;
}
#terrain-view::backdrop {
  background: #0a0e18bf;
}
#terrain-view[open] {
  display: flex;
  flex-direction: column;
}
#terrain-view header,
#terrain-view footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  flex-wrap: wrap;
}
#terrain-view h2 {
  font-size: 1.05rem;
  margin: 0 auto 0 0;
}
#terrain-view button,
#terrain-view input {
  font: inherit;
  font-size: 0.86rem;
  min-height: 38px;
  padding: 6px 10px;
  color: inherit;
  background: #262c3a;
  border: 1px solid #575766;
  border-radius: 6px;
}
#terrain-view button {
  cursor: pointer;
}
#terrain-view button[aria-pressed='true'] {
  background: #614253;
  border-color: #ee9aaf;
}
#terrain-view :focus-visible {
  outline: 2px solid #ffbea1;
  outline-offset: -2px;
}
.terrain-stage {
  position: relative;
  flex: 1;
  min-height: 150px;
  background: #18333d;
}
.terrain-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  outline-offset: -3px;
}
.terrain-stage canvas:active {
  cursor: grabbing;
}
.terrain-search {
  position: absolute;
  top: 10px;
  left: 10px;
  width: min(255px, 65%);
  z-index: 1;
}
.terrain-search input {
  width: 100%;
  box-sizing: border-box;
}
.terrain-results {
  display: grid;
  background: #1d2231;
  border-radius: 6px;
  overflow: auto;
  max-height: 32vh;
}
#terrain-view .terrain-results button {
  text-align: left;
  border-radius: 0;
}
.terrain-state,
.terrain-selection {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  box-sizing: border-box;
  padding: 9px 12px;
  background: #1a202eee;
  border-radius: 7px;
  font-size: 0.86rem;
}
.terrain-selection {
  display: flex;
  align-items: center;
  gap: 10px;
}
#terrain-view footer {
  gap: 6px;
}
#terrain-view footer output {
  font-size: 0.8rem;
  margin-left: auto;
}
#terrain-view details {
  font-size: 0.78rem;
  color: #d4d6dd;
  padding: 0 12px 7px;
}
#terrain-view summary {
  cursor: pointer;
}
#terrain-view details p {
  margin: 5px 0;
}
#terrain-view a {
  color: #f3afc2;
}
@media (max-width: 700px) {
  #terrain-view {
    width: 100%;
    height: 100dvh;
    max-width: 100%;
    border-radius: 0;
    border: 0;
  }
  #terrain-view header,
  #terrain-view footer {
    padding: 6px 8px;
  }
  #terrain-view button {
    min-height: 42px;
  }
  #terrain-view footer output {
    flex-basis: 100%;
    margin: 0;
  }
  #terrain-view footer {
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
}
#terrain-view {
  margin: auto;
  color-scheme: dark;
  box-shadow: 0 16px 80px #0b111c66;
  font-family: inherit;
}
#terrain-view header {
  border-bottom: 1px solid #484654;
}
#terrain-view footer {
  border-top: 1px solid #484654;
}
#terrain-view .terrain-state {
  margin: 0;
}
#terrain-view footer label {
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
#terrain-view footer input {
  min-height: auto;
  accent-color: #f69bb6;
  width: 16px;
  height: 16px;
}
#terrain-view .terrain-search {
  display: grid;
  gap: 4px;
  pointer-events: none;
}
#terrain-view .terrain-search input,
#terrain-view .terrain-search select,
#terrain-view .terrain-results {
  pointer-events: auto;
}
#terrain-view .terrain-search select {
  width: 100%;
  min-height: 34px;
  box-sizing: border-box;
  background: #242c38f2;
  border: 1px solid #6b6872;
  border-radius: 5px;
  padding: 4px 7px;
  font: inherit;
  font-size: 0.8rem;
  color: #f3eff6;
}
#terrain-view .terrain-results:empty {
  display: none;
}
#terrain-view .terrain-selection span {
  min-width: 0;
  overflow-wrap: anywhere;
}
#terrain-view .terrain-selection button {
  flex: none;
}
@media (max-width: 700px) {
  #terrain-view .terrain-search {
    width: min(250px, 65%);
  }
  #terrain-view footer {
    gap: 4px;
  }
  #terrain-view footer label {
    margin-inline: 3px;
  }
  #terrain-view header {
    padding-top: max(6px, env(safe-area-inset-top));
  }
}
#open-terrain {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #60646d;
  border-radius: 6px;
  background: #182528ed;
  color: #eff2ed;
  font-weight: 650;
  cursor: pointer;
}
#open-terrain:hover {
  background: #263538;
}

/* Keep the complete toolbar reachable above a location sheet on phones. */
@media (max-width: 760px) {
  .map-toolbox {
    top: 64px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    max-width: min(190px, calc(100% - 22px));
  }
  .map-toolbox > .north {
    position: absolute;
    right: 0;
    bottom: calc(100% + 4px);
  }
  .map-toolbox .tool-group {
    display: flex;
  }
  .map-toolbox .tool-group button + button {
    border-top: 0;
    border-left: 1px solid #414255;
  }
}
@media (max-width: 760px) and (max-height: 510px) and (orientation: landscape) {
  .map-toolbox {
    top: 5px;
    max-width: calc(100% - 318px);
  }
  .map-toolbox > .north {
    top: 0;
    right: calc(100% + 4px);
    bottom: auto;
  }
  .atlas-locator {
    left: 8px;
    right: auto;
    top: 55px;
  }
}
@media (max-width: 760px) and (max-height: 360px) and (orientation: landscape) {
  #detail {
    max-height: 53vh;
    max-height: 53dvh;
  }
}
@media (min-width: 761px) and (max-height: 510px) and (pointer: coarse) {
  .map-toolbox > .north {
    position: absolute;
    right: calc(100% + 4px);
    top: 0;
  }
}
