/* Match screen: a full-window canvas with the HUD laid over its corners. */
.match {
  padding: 0;
  place-items: stretch;
  align-content: stretch;
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  animation: none;
}

.match__canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg-0);
  cursor: default;
}

/* A unit is picked: the next click on the map sends it. */
.match__canvas[data-armed='true'] {
  cursor: crosshair;
}

.match__canvas:focus-visible {
  outline-offset: -2px;
}

.match__hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud {
  position: absolute;
  inset: var(--space-3);
  display: grid;
  grid-template-columns: auto 1fr auto;
  /* The middle row never grows with what is in it, so the bottom row is
     always on screen. On a short window the deck reaches down into the free
     space above the bottom-left corner instead. */
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-3);
}

/* HUD pieces take clicks; the gaps between them let clicks reach the map. */
.hud__chip {
  pointer-events: auto;
  background: var(--bg-veil);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  animation: chip-in var(--dur-expressive) var(--ease-enter) both;
}

@keyframes chip-in {
  from {
    opacity: 0;
    transform: translateY(calc(var(--travel) * -1));
  }
}

.hud__identity {
  grid-area: 1 / 1;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
}

.hud__dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.hud__name {
  font-weight: 600;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud__energy-label {
  margin-left: var(--space-3);
}

/* The home shield: one fixed width (it reads "Down" once dropped), so nothing beside it moves. */
.hud__shield {
  min-width: 4ch;
  font-weight: 700;
  line-height: 1;
  color: var(--text-dim);
  text-align: right;
}

/*
 * The shield's cost beside it, in words, and a way to the switch that drops
 * it. Its room is kept while the shield is free, so nothing moves when it shows.
 */
.hud__upkeep {
  min-width: 38ch;
  padding: 0;
  background: none;
  border: 0;
  border-bottom: 1px dotted currentColor;
  font: 600 var(--text-xs) / 1.2 var(--font-mono);
  text-align: left;
  color: var(--warn);
  cursor: pointer;
}

.hud__upkeep:empty {
  visibility: hidden;
}

.hud__upkeep:hover,
.hud__upkeep:focus-visible {
  color: var(--text);
}

.hud__energy {
  min-width: 4ch;
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  text-align: right;
}

.hud__buttons {
  grid-area: 1 / 3;
  padding: 0 var(--space-1);
  gap: 0;
}

.hud__buttons .button {
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

.hud__buttons .button[hidden] {
  display: none;
}

.hud__overview {
  grid-area: 3 / 3;
  align-self: end;
  padding: var(--space-2);
  display: grid;
  gap: var(--space-2);
}

.minimap__canvas {
  display: block;
  width: 240px;
  height: 160px;
  max-width: 44vw;
  aspect-ratio: 3 / 2;
  height: auto;
  border: 1px solid var(--line-strong);
  cursor: pointer;
  touch-action: none;
}

.hud__view-buttons {
  gap: var(--space-1);
  flex-wrap: nowrap;
}

.hud__small {
  min-width: var(--target);
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

.hud__center {
  flex: 1;
}

.hud__hint {
  grid-area: 3 / 1 / 4 / 3;
  align-self: end;
  justify-self: start;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-veil);
  border-left: 2px solid var(--accent);
  font-size: var(--text-sm);
  color: var(--text-dim);
  transition: opacity var(--dur-cinematic) var(--ease-exit);
}

.hud__hint.is-leaving {
  opacity: 0;
}

/* Results sit over the map, which keeps playing behind them. */
.results {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgb(5 7 11 / 0.6);
  animation: overlay-in var(--dur-cinematic) var(--ease-standard) both;
}

.results[hidden] {
  display: none;
}

.results__panel {
  width: min(44rem, 100%);
  border-color: var(--accent-line);
  animation: screen-in var(--dur-cinematic) var(--ease-enter) both;
}

.results__title {
  font-size: var(--text-xl);
}

/* You are out, but the match goes on: say so, and offer the way back. */
.hud__out {
  grid-area: 1 / 2;
  justify-self: center;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  max-width: 34rem;
  padding: var(--space-2) var(--space-4);
  border-color: var(--warn);
  font-size: var(--text-sm);
}

.hud__out p {
  flex: 1 1 14rem;
}

/*
 * Narrow screens. The match is built for a keyboard and mouse, but on a small
 * window nothing may overlap, clip, or scroll: the HUD stacks, and the deck
 * becomes a row of five buttons along the bottom.
 */
@media (max-width: 48rem) {
  .hud {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    gap: var(--space-2);
  }

  .hud__identity {
    grid-area: 1 / 1;
    flex-wrap: wrap;
    row-gap: 0;
  }

  .hud__energy-label {
    margin-left: auto;
  }

  /* The top buttons wrap onto a second line before they would ever scroll. */
  .hud__buttons {
    grid-area: 2 / 1;
    flex-wrap: wrap;
  }

  .hud__out {
    grid-area: 3 / 1;
    justify-self: stretch;
  }

  .hud__overview {
    grid-area: 5 / 1;
    justify-self: end;
  }

  .minimap__canvas {
    width: 150px;
  }

  .hud__hint {
    display: none;
  }
}
