/*
 * The match on a phone, upright and sideways. Every piece is pinned to its
 * own place, so a bar that comes and goes never pushes a button somewhere
 * else, and nothing scrolls. The page keeps clear of the notch and the home
 * bar. Plan: docs/plans/13-phone-play.md.
 *
 * Upright:  top bar and Menu / Send and Box at left, overview at right /
 *           the picked unit's panel / the formation bar / the deck row
 * Sideways: the deck down the left edge with Send and Box under it / top
 *           bar and Menu / the panel and the formation bar in the middle /
 *           the overview at bottom right
 */
:root[data-phone='true'] {
  --phone-gap: var(--space-2);
  --phone-deck-row: 4.25rem;
  /* Wide enough for three touch tools in a row, Send at its widest (×1,000). */
  --phone-deck-column: 10.25rem;
  --phone-top: calc(var(--target) + var(--phone-gap));
}

:root[data-phone='true'] .hud {
  display: block;
  inset: max(var(--phone-gap), env(safe-area-inset-top))
    max(var(--phone-gap), env(safe-area-inset-right))
    max(var(--phone-gap), env(safe-area-inset-bottom))
    max(var(--phone-gap), env(safe-area-inset-left));
}

:root[data-phone='true'] .hud > * {
  position: absolute;
  margin: 0;
  /* The desktop grid's self-alignment would shrink a pinned box to its content. */
  justify-self: normal;
  align-self: normal;
}

:root[data-phone='true'] .hud__hint {
  display: none;
}

/* The top bar: who you are and your energy, in one row. */
:root[data-phone='true'] .hud__identity {
  top: 0;
  left: 0;
  right: calc(4.5rem + var(--phone-gap));
  height: var(--target);
  flex-wrap: nowrap;
  gap: var(--space-2);
  padding: 0 var(--space-3);
}

:root[data-phone='true'] .hud__name {
  max-width: 8rem;
  font-size: var(--text-sm);
}

/* The energy needs no label on a phone: it is the big number, in the color. */
:root[data-phone='true'] .hud__energy-label {
  display: none;
}

:root[data-phone='true'] .hud__energy {
  margin-left: auto;
}

/* No room for the shield number on a phone: the ring on the base shows it. */
:root[data-phone='true'] .hud__shield,
:root[data-phone='true'] .hud__upkeep {
  display: none;
}

:root[data-phone='true'] .hud__identity .tag {
  padding: 0 var(--space-1);
  font-size: 0.625rem;
}

:root[data-phone='true'] .hud__energy {
  font-size: var(--text-lg);
}

/* Menu, and the buttons it opens below itself. */
:root[data-phone='true'] .hud__menu-toggle {
  display: inline-flex;
  top: 0;
  right: 0;
  width: 4.5rem;
  min-height: var(--target);
  pointer-events: auto;
  background: var(--bg-veil);
}

:root[data-phone='true'] .hud__menu-toggle[aria-expanded='true'] {
  border-color: var(--accent);
  color: var(--accent);
}

:root[data-phone='true'] .hud__buttons {
  display: none;
  top: var(--phone-top);
  right: 0;
  z-index: 2;
  width: 12.5rem;
  flex-direction: column;
  align-items: stretch;
  padding: var(--space-1);
  background: var(--bg-1, var(--bg-0));
}

:root[data-phone='true'] .hud__menu-toggle[aria-expanded='true'] + .hud__buttons {
  display: flex;
}

:root[data-phone='true'] .hud__buttons .button {
  justify-content: flex-start;
  min-height: var(--target);
  padding: 0 var(--space-3);
}

/* Out of the match: the notice takes the deck's empty place at the bottom,
   so the overview stays in reach for watching, and the touch tools go. */
:root[data-phone='true'] .hud__out {
  bottom: 0;
  left: 0;
  right: 0;
  max-width: none;
}

:root[data-phone='true'] .hud:has(.hud__out:not([hidden])) .touch-tools {
  display: none;
}

/* The deck: the list and the panel are placed on their own. */
:root[data-phone='true'] .deck {
  display: contents;
}

:root[data-phone='true'] .deck__list,
:root[data-phone='true'] .deck__panel {
  position: absolute;
  margin: 0;
  justify-self: normal;
  align-self: normal;
}

:root[data-phone='true'] .deck__list {
  gap: var(--space-1);
  padding: var(--space-1);
}

:root[data-phone='true'] .card__pick {
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: center;
  height: 100%;
  padding: var(--space-1) var(--space-2);
}

:root[data-phone='true'] .card {
  min-height: 0;
}

/* The full name is still read out; the short one is what shows. */
:root[data-phone='true'] .card__name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

:root[data-phone='true'] .card__short {
  display: block;
  font: 600 var(--text-sm) / 1.2 var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-phone='true'] .card__key,
:root[data-phone='true'] .card__icon,
:root[data-phone='true'] .card__queue,
:root[data-phone='true'] .deck__hint {
  display: none;
}

:root[data-phone='true'] .card__status {
  grid-column: 1 / 3;
}

:root[data-phone='true'] .deck__panel {
  z-index: 1;
  width: auto;
  overflow: hidden;
}

:root[data-phone='true'] .formation-bar {
  width: auto;
}

/* Two fixed rows: the count with Clear, then the kinds of formation. */
:root[data-phone='true'] .formation-bar__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  row-gap: var(--space-1);
}

:root[data-phone='true'] .formation-bar .segments {
  grid-column: 1 / -1;
  grid-row: 2;
}

:root[data-phone='true'] .formation-bar .segment {
  font-size: var(--text-xs);
}

/* The overview and its buttons. */
:root[data-phone='true'] .hud__overview {
  padding: var(--space-1);
  gap: var(--space-1);
}

:root[data-phone='true'] .minimap__canvas {
  width: 8.25rem;
  max-width: none;
}

:root[data-phone='true'] .hud__view-buttons {
  flex-wrap: wrap;
}

:root[data-phone='true'] .touch-tools {
  flex-direction: column;
  padding: var(--space-1);
}

/* The panel and the formation bar share one spot. With a unit picked a tap
   sends it, so the formation bar is of no use until the card is put away. */
:root[data-phone='true'] .hud:has(.deck__panel:not([hidden])) .formation-bar {
  display: none;
}

/* Notices sit under the top bar, out of the way of the deck, and let taps through. */
:root[data-phone='true'] .toasts {
  top: calc(max(var(--phone-gap), env(safe-area-inset-top)) + var(--phone-top));
  bottom: auto;
}

:root[data-phone='true'] .toast {
  pointer-events: none;
}
