:root {
  color-scheme: dark;
}
html,
body {
  margin: 0;
  height: 100%;
  background: #000;
  font-family: system-ui, sans-serif;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-image: url(gca.svg);
  background-size: cover;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  color: #eee;
  gap: 14px;


  .title {
    font-size: 6em;
    font-weight: 800;
    letter-spacing: 0;
    line-height: 0.65;
    color: white;
    text-align: center;
    -webkit-text-stroke: 8px black;
    paint-order: stroke fill;
  }

  .load-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 56px;
  }

  .load-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }

  .bar {
    position: relative;
    width: 340px;
    max-width: 80vw;
    height: 4px;
    background: #333;
    border-radius: 2px;
    overflow: hidden;
  }

  .load-map {
    display: none;
    position: relative;
    width: min(58vh, 40vw);
    aspect-ratio: 1;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    overflow: hidden;
    background: #0a0f1c;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  }

  &.active .load-map {
    display: block;
  }
}

#loadbar {
  position: relative;
  height: 100%;
  width: 0;
  background: #ffd36e;
  overflow: hidden;

  /* A highlight sweeping along the filled part: a compositor animation, so it
     keeps moving even while the main thread is busy. */
  &::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 60px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
    animation: loadsweep 1.4s linear infinite;
  }
}


@keyframes loadsweep {
  from {
    transform: translateX(-60px);
  }
  to {
    transform: translateX(340px);
  }
}

#loadcity {
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffd36e;
  text-shadow: 0 1px 3px #000;
  min-height: 1.2em;
}

#loadmsg {
  text-shadow: 0 1px 3px #000;
}

#loaddetail {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #9aa6c0;
  min-height: 1.2em;
  text-shadow: 0 1px 3px #000;
}

#loadmap {
  width: 100%;
  height: 100%;
}

/* Waiting for the terrain: a scan line over the empty map. */
#loading.scanning .load-map::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 30%;
  background: linear-gradient(180deg, transparent, rgba(127, 211, 255, 0.12), transparent);
  animation: loadscan 2.4s ease-in-out infinite alternate;
}

@keyframes loadscan {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(333%);
  }
}

#loadtip {
  position: absolute;
  bottom: 6vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, 90vw);
  text-align: center;
  font-size: 14px;
  color: #cfd6e6;
  text-shadow: 0 1px 3px #000;
  opacity: 0;
  transition: opacity 0.4s;

  &.show {
    opacity: 1;
  }

  b {
    color: #ffd36e;
  }
}


/* Portrait (phones): map under the title. */
@media (max-aspect-ratio: 1/1) {
  #loading {
    .load-main {
      flex-direction: column;
      gap: 24px;
    }
    .load-map {
      width: min(84vw, 40vh);
    }
    .title {
      font-size: 4.5em;
    }
  }
}

#hud {
  position: absolute;
  right: 24px;
  bottom: 20px;
  color: #fff;
  text-align: right;
  text-shadow: 0 1px 4px #000;
  pointer-events: none;

  .speed {
    font-size: 44px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
  }

  .unit {
    font-size: 14px;
    opacity: 0.8;
  }

  .info {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 4px;
  }
}

#stats {
  position: absolute;
  left: 8px;
  top: 8px;
  color: #8f8;
  font: 11px monospace;
  white-space: pre;
  text-shadow: 0 0 2px #000;
  pointer-events: none;
}

#perf {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  color: #cfe;
  font: 11px monospace;
  white-space: pre;
  text-align: center;
  text-shadow: 0 0 2px #000;
  pointer-events: none;
}

#mapview {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;

  canvas {
    width: min(80vw, 80vh);
    height: min(80vw, 80vh);
    border-radius: 10px;
    opacity: 0.9;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  }
}

#help {
  position: absolute;
  left: 12px;
  bottom: 12px;
  color: #ddd;
  font-size: 12px;
  line-height: 1.5;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

#menu {
  position: absolute;
  right: 12px;
  top: 60px;
  max-height: calc(100% - 80px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(10, 12, 20, 0.7);
  padding: 10px;
  border-radius: 8px;
  color: #eee;
  font-size: 12px;

  .menu-section {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    font-weight: 700;
    letter-spacing: 0.08em;
    opacity: 0.8;
  }

  &.hidden {
    display: none;
  }

  label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
  }

  select,
  input,
  button {
    font-size: 12px;
  }
}

#errors {
  position: absolute;
  z-index: 20;
  left: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  right: 8px;
  color: #f66;
  font: 12px monospace;
  white-space: pre-wrap;
  display: none;
  background: rgba(0, 0, 0, 0.8);
  max-height: 40%;
  overflow: auto;
  user-select: text;
  -webkit-user-select: text;
}

#errors > div {
  padding: 2px 4px;
  border-bottom: 1px solid rgba(255, 102, 102, 0.25);
}

/* Repeat count of a message reported again (reportError). */
#errors > div[data-n]::after {
  content: ' ' attr(data-n);
  color: #fc6;
}

#menu .menu-title {
  font-weight: 700;
  letter-spacing: 0.1em;
}

#toolbar {
  position: absolute;
  right: 12px;
  top: 12px;
  display: flex;
  gap: 6px;

  button {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 8px;
    background: rgba(10, 12, 20, 0.6);
    color: #eee;
    font-size: 20px;
    cursor: pointer;
  }

  button:hover {
    background: rgba(40, 44, 60, 0.8);
  }

  button.on {
    background: rgba(255, 211, 110, 0.35);
  }
}

#camlabel {
  position: absolute;
  right: 12px;
  top: 58px;
  color: #fff;
  font-size: 12px;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

#menu:not(.hidden)~#camlabel {
  display: none;
}

canvas {
  touch-action: none;
}
/* ?diag=1 panel (src/ui/diag.ts): above everything, small, selectable. */
#diag {
  position: absolute;
  z-index: 30;
  top: env(safe-area-inset-top, 0px);
  left: env(safe-area-inset-left, 0px);
  max-width: min(100%, 720px);
  max-height: 70%;
  overflow: auto;
  background: rgba(0, 0, 0, 0.82);
  color: #cfe;
  font: 10px/1.25 ui-monospace, Menlo, monospace;
  user-select: text;
  -webkit-user-select: text;
}

#diag .diag-bar {
  display: flex;
  gap: 4px;
  padding: 3px;
}

#diag .diag-bar button {
  font: 11px ui-monospace, Menlo, monospace;
  color: #fff;
  background: #345;
  border: 0;
  border-radius: 3px;
  padding: 3px 8px;
}

#diag pre {
  margin: 0;
  padding: 3px 6px 6px;
  white-space: pre-wrap;
  word-break: break-all;
}
