/* Colors */

:root {
  --light-sky-blue: #ddeeff;
  --light-cloud-blue: #ccddee;
  --highlight-blue: #007ce3;
  --middle-blue: #0066bb;
  --dark-blue: #005399;
  --focus-blue: #0022ff;
  --light-text-color: #fcfcfc;
  --body-text-color: #444444;
  --dim-text-color: #666666;
  --grey-border-color: #cccccc;
  --light-grey-background: #e0e0e0;
  --dark-shadow: rgba(0, 0, 0, 0.25);
  --black: #000000;
  --translucent-black: rgba(0, 0, 0, 0.75);
  --white: #ffffff;
  --translucent-white: rgba(255, 255, 255, 0.9);
  --error-text-color: #902000;
}

/* Overall Styles */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: sans-serif;
  color: var(--body-text-color);
}
#map {
  z-index: 0;
  position: fixed;
  inset: 0;
  /* fallback positioning if inset not supported */
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
a,
a:visited {
  color: var(--middle-blue);
  text-decoration: none;
}
a:hover,
a:focus,
a:active {
  color: var(--highlight-blue);
  text-decoration: underline;
}
.mapboxgl-ctrl-attrib a,
.mapboxgl-ctrl-attrib a:visited {
  color: var(--translucent-black);
  text-decoration: none;
}

/* Page overlay (contains orientation popup) */
#page-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--translucent-black);
  display: none; /* Hidden by default */
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.page-popup {
  font-size: 1rem;
  line-height: 1.5;
  font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
  background: var(--white);
  padding: 2rem;
  border-radius: 6px;
  max-width: 600px;
  text-align: center;
  box-shadow: 0 10px 25px var(--dark-shadow);
  position: relative;
}

.page-popup p {
  text-align: left;
}

.page-popup .credits p {
  font-size: 0.75em;
  color: var(--dim-text-color);
  text-align: center;
}

.page-popup h1 {
  font-size: 1.25em;
  margin-top: 0;
}

/* Open & Close Buttons (& Matching Links) */

#panel nav {
  margin: 0;
  padding: 0;
}
.close-button,
.open-button {
  font-size: 1rem;
  margin: 0 0 0.75em 0;
  padding: 0.625em 1.25em;
  background-color: var(--middle-blue);
  color: var(--light-text-color);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  text-decoration: none;
  text-align: center;
}
.open-button {
  display: inline-block;
  box-sizing: border-box;
  width: 100%;
}
.open-button:last-child {
  margin-bottom: 0;
}
.close-button:hover,
.open-button:hover {
  background-color: var(--dark-blue);
  text-decoration: none;
}
.close-button:focus-visible,
.open-button:focus-visible {
  /* The browser default focus ring outline for these buttons could
   * be hard to see around an already bright-blue button
   * on a white background, especially when the button has
   * width:100% in a parent with overlay:hidden, causing the
   * sides of the outline to clip. For better visibility,
   * use a white box-shadow inset, then an outline with
   * a negative offset, to place a contrasting white-blue
   * ring inside the button dimensions */
  outline: 3px solid var(--focus-blue);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 6px var(--white);
}
a.open-button,
a.close-button {
  color: var(--light-text-color);
  text-decoration: none;
}

/* Loading Message */

.loading {
  position: fixed;
  inset: 0;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  place-content: center;
  padding: 1rem;
  font-size: 1.25rem;
  text-align: center;
  background-color: var(--white);
  color: var(--body-text-color);
}
.loading .error {
  color: var(--error-text-color);
}
#loading-map {
  z-index: 99; /* above map, under the panel */
}
.spinner {
  border: 4px solid var(--grey-border-color);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border-left-color: var(--highlight-blue);
  animation: spin 1s linear infinite;
  display: block;
  margin: 1rem auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Map Panel (includes map controls) */
#panel {
  /* overlay above map with position:absolute, leaving 1em space around */
  position: absolute;
  top: 1em;
  left: 1em;
  z-index: 100;
  max-height: calc(100vh - 2em);
  width: 22.5%;
  min-width: 260px;
  overflow: auto;
  box-sizing: border-box;
  font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  background-color: var(--translucent-white);
  box-shadow: 0 1px 2px var(--dark-shadow);
  border-radius: 6px;
  padding: 1em;
}
#panel header {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0;
}
#panel h2 {
  flex: 1 1 0;
  font-size: 1rem;
  margin: 0;
}
#panel p {
  margin: 1em 0;
}
/* Animate panel expand/collapse. This requires a grid wrapper (#panel-body)
* with a transition on 'grid-template-rows' which can be toggled from 1fr
* to 0fr to show/hide. It also requires a grid child item (#panel-inner)
* with min-height:0px and overflow:hidden.
* Technique: https://nemzes.net/posts/animating-height-auto/
* */
#panel-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.5s ease-out;
}
#panel-inner {
  min-height: 0px;
  overflow: hidden;
}

#panel fieldset:last-of-type {
  margin-bottom: 1em;
}
#panel legend {
  font-size: 1em;
  font-weight: bold;
}
#panel label {
  display: flex;
  align-items: center;
  margin: 8px 0 10px;
}
/* ensure that the label text grows to fill space between input element and icon */
.label-text {
  flex: 1;
}
/* Create a mask-image using the same icon assigned to map features
* (the .label-icon elements will be assigned a background color when
* they are dynamically added to the page in the map.on('load'... function.
* The mask image ensures that the background color only applies in the
* shape of the icon, allowing the label icon to match the dynamic SDF
* icons defined in the mapbox style)
*/
.label-icon {
  width: 1lh;
  height: 1lh;
  margin-left: 6px;
  display: block;
  -webkit-mask-image: url("./images/pin64.sdf.png");
  mask-image: url("./images/pin64.sdf.png");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}
@supports not (height: 1lh) {
  .label-icon {
    height: 21px;
    width: 21px;
  }
}

input[type="checkbox"],
input[type="radio"] {
  vertical-align: middle;
  position: relative;
  bottom: 1px;
  margin-right: 8px;
}

/* Panel Toggle Button (Inside #panel > header) */

button#panel-toggle {
  flex: 0 0 auto;
  width: 2em;
  height: 2em;
  padding: 0;
  margin: 0 0 0 1em;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  display: none;
  color: var(--dark-blue);
  background-color: transparent;
}
button#panel-toggle:hover {
  color: var(--middle-blue);
  background-color: var(--light-sky-blue);
}
button#panel-toggle:active {
  color: var(--middle-blue);
  background-color: var(--light-cloud-blue);
}
/* Skip Button (For Keyboard Navigation, Hidden Unless Focused)
*  Inside #panel > header, but absolutely positioned out of flow
*  (Note: the #skip-to-map button is also styled with '.visually-hidden' ) */
#skip-to-map {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  border-width: 0px;
}
#skip-to-map:focus,
#skip-to-map:focus-visible {
  right: 0;
  padding: 0.25em 0.5em;
  background: var(--white);
  color: var(--middle-blue);
}
/* Style for visually hidden elements (intended for screen reader only) */
.visually-hidden {
  height: 1px;
  width: 1px;
  padding: 0;
  border-width: 0;
  margin: -1px;
  clip-path: inset(50%);
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}
.visually-hidden:focus,
.visually-hidden:focus-visible {
  clip-path: none;
  clip: auto;
  height: auto;
  width: auto;
  margin: 0;
  overflow: visible;
  z-index: 999;
  border-radius: 2px;
  background-color: var(--white);
}

/* Tweaks to mapboxgl popup style */
.mapboxgl-popup-content {
  border-radius: 6px;
}
.mapboxgl-popup {
  font-size: 0.875rem;
  line-height: 1.57;
}
.mapboxgl-popup:focus,
.mapboxgl-popup:focus-visible {
  /* do not show focus ring around popup container, as it is not itself an interactive element */
  outline: 0px none;
}

/* Style for place name popup content
* set it as a flexbox colum and set all children
* with order:0 except button (order:1) to ensure
* button is visually at the bottom despite coming
* first in the DOM for focus trap .
* */
.placename-popup-content {
  display: flex;
  flex-direction: column;
}
.placename-popup-content > * {
  order: 0;
}
button.exit-button {
  margin-top: 1em;
  font-size: 1em;
  padding: 0.3em;
  background-color: var(--light-grey-background);
  color: var(--black);
  border: solid 1px var(--grey-border-color);
  border-radius: 4px;
  cursor: pointer;
}
button.exit-button:hover,
button.exit-button:active {
  background-color: var(--body-text-color);
  color: var(--light-text-color);
  border: solid 1px var(--black);
}
.placename-popup-content > button.exit-button {
  order: 1;
  align-self: flex-start;
}

hgroup p.kicker {
  font-weight: bold;
  margin: 0;
}
h3.placename-heading {
  font-size: 1.25rem;
  font-weight: bold;
  margin: 0.875rem 0 0 0;
}
h3.placename-heading span.translation {
  font-weight: normal;
}
/* Mapbox Markers for Place Name Accessibility */

/* Hidden keyboard-accessible button: 1×1 clipped element, invisible by default.
   A focus ring (::after) appears only on keyboard focus.
   Note: mapbox also adds .mapboxgl-marker (position:absolute) to this element. */
.placename-marker {
  height: 1px;
  width: 1px;
  padding: 0;
  margin: 0;
  border-width: 0;
  clip-path: inset(50%);
  clip: rect(0 0 0 0); /*fallback to deprecated property for older browsers*/
  white-space: nowrap;
  background-color: transparent;
}
/* Focus ring (teardrop shape) implemented as ::after because mapbox sets
   an inline transform on the parent for positioning, requiring us to add
   a pseudo-element to rotate the teardrop independently of mapbox. */
.placename-marker::after {
  content: "";
  display: block;
  height: 36px;
  width: 36px;
  margin: 0;
  position: absolute;
  left: -18px; /* center the 36px width */
  top: -44px; /* move up to enclose the map icon placed above the feature coordinates */
  outline: 3px solid var(--focus-blue);
  border-radius: 50% 50% 50% 0; /* three rounded and one sharp corner for a teardrop */
  transform: rotate(-45deg); /* rotate the sharp corner to point down at the feature coordinates */
  pointer-events: none;
  opacity: 0; /* safeguard in case browser doesn't fully support 'clip-path' */
}
/* On focus: unclip the parent so the ::after ring can render outside the 1×1 box. */
.placename-marker:focus {
  outline: 0px none transparent; /* remove default focus ring (use ::after) */
  box-shadow: none;
  height: 1px;
  width: 1px;
  clip-path: none;
  clip: auto; /*fallback for older browsers*/
  z-index: 2;
  caret-color: transparent; /* suppress caret for caret-navigation users */
  overflow: visible; /* allow ::after element to overflow */
}
.placename-marker:focus::after {
  opacity: 1;
}
/* Hide the ring for non-keyboard focus (mouse clicks, etc) */
@supports selector(:focus-visible) {
  .placename-marker:focus:not(:focus-visible) {
    clip-path: inset(50%);
    clip: rect(0 0 0 0);
    z-index: auto;
  }
  .placename-marker:focus:not(:focus-visible)::after {
    opacity: 0;
  }
}

/* Respect user OS reduced animation preference */
@media (prefers-reduced-motion: reduce) {
  #panel-body {
    transition: none;
  }
  .spinner {
    animation: none;
    display: none;
  }
}

/* Responsive style overrides for smaller device screens */
@media (max-width: 1440px) {
  #panel {
    font-size: 0.75rem;
  }
  #panel h2 {
    font-size: 0.875rem;
    line-height: 2;
  }
  @supports not (height: 1lh) {
    .label-icon {
      height: 18px;
      width: 18px;
    }
  }
}
@media (max-width: 800px) {
  #panel {
    position: absolute;
    top: 1em;
    left: 1em;
    right: 1em;
    width: auto;
    padding: 1em 1.5em;
  }
  #panel label {
    margin: 0 0 8px;
  }
  #panel-body {
    grid-template-rows: 0fr;
  }
  button#panel-toggle {
    display: block;
  }
  #skip-to-map:focus,
  #skip-to-map:focus-visible {
    /* offset from right to make room for #panel-toggle */
    right: 3em;
  }
  .page-popup {
    font-size: 0.875rem;
  }
  .page-popup h1 {
    font-size: 1.142em;
  }
  .mapboxgl-popup {
    max-width: 320px !important; /* override inline style to restrict width on small screens */
    font-size: 0.75rem;
  }
}
