body.play {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);   /* the canvas's internal 960+ px width must not widen the page */
  overflow: hidden;
  position: relative;
  -webkit-touch-callout: none; /* no long-press menu on iPhone */
}
/* No pinch zoom or double-tap zoom on the game or its top bar (#stage has touch-action: none).
   Not on the whole body: the high-score screen must still scroll on short phones. */
#hud { touch-action: manipulation; }

/* Words that differ by device: .k = keyboard wording, .t = touch wording (phones and tablets). */
.t { display: none; }
@media (pointer: coarse) {
  .k { display: none; }
  .t { display: inline; }
}
/* Darkened background behind the board. */
body.play::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--scrim);
  pointer-events: none;
}

#hud {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  /* the notch / camera cut-out and rounded corners never cover a button, in either orientation */
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
#exit { justify-self: start; }
#sound { justify-self: end; }
#sound[data-on='true'] .off, #sound[data-on='false'] .on { display: none; }

.score-box {
  font-weight: 800;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.score-box .label { font-size: 0.8rem; font-weight: 700; opacity: 0.8; margin-right: 4px; }
#score { font-variant-numeric: tabular-nums; }

#stage {
  position: relative;
  z-index: 1;
  min-height: 0;
  padding: 4px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  touch-action: none;          /* swipes steer; they must not scroll or zoom the page */
  user-select: none;
  -webkit-user-select: none;
}
#game { width: 100%; height: 100%; overflow: hidden; }
#game canvas { border-radius: 10px; }

#instructions {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  grid-template: 100% / 100%;   /* a definite cell, so the card's % sizes work on short screens */
  background: rgba(24, 12, 20, 0.45);
  pointer-events: none;
}
/* The card always fits: a phone held sideways is only ~300 px tall. */
#instructions img { max-width: min(92%, 640px); max-height: 94%; width: auto; height: auto; object-fit: contain; }
#instructions > * { max-height: 100%; overflow: hidden; }

/* ---------- ending: Marlo tossed onto the screen (src/ui/ending.js) ---------- */
#ending {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(24, 12, 20, 0.35);   /* the board stays visible behind the glass */
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
}
#ending .faceplant { height: auto; max-width: none; grid-area: 1 / 1; will-change: transform; }
#ending .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#ending .skip {
  position: absolute;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  font-weight: 700;
  opacity: 0.7;
}

/* ---------- PLAY AGAIN popover: appears under wherever the game-over screen is tapped ---------- */
.again-pop {
  position: fixed;
  z-index: 12;
  font-family: var(--font-arcade);
  font-size: var(--text-md);
  letter-spacing: 0.06em;
  color: var(--paper);
  background: var(--ink);
  border: 0;
  border-radius: 6px;
  padding: var(--gap-sm) var(--gap-md);
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;            /* tap target */
  box-shadow: 0 4px 0 rgb(0 0 0 / 0.35);
  animation: pop-in 0.14s ease-out;
}
.again-pop::before {             /* little pointer up to the tap */
  content: '';
  position: absolute;
  top: -7px;
  left: var(--arrow-x, 50%);
  translate: -50% 0;
  border: 7px solid transparent;
  border-top: 0;
  border-bottom-color: var(--ink);
}
.again-pop:focus-visible { outline: 3px solid var(--magenta); outline-offset: 2px; }
@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } }

/* ---------- high-score screen: an arcade page (arcade.css) laid over the game ---------- */
#results {
  position: fixed;
  inset: 0;
  z-index: 11;
  min-height: 0;
  overflow-y: auto;            /* the panel centres, but scrolls from the top if taller than the screen */
}
/* PLAY AGAIN / EXIT always on screen: when the score table is taller than the phone, the buttons
   stay pinned to the bottom edge while the table scrolls under them. */
#results .arcade-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: var(--gap-sm) calc(-1 * var(--panel-padding-x)) 0;
  padding: var(--gap-sm) var(--panel-padding-x) max(var(--gap-sm), env(safe-area-inset-bottom));
  background: var(--panel-fill);
  row-gap: 0;                  /* EXIT wraps under PLAY AGAIN on narrow phones: keep the pair compact */
}
#results .arcade-btn.primary { white-space: nowrap; }
/* Short screens (phones, phone sideways): a tighter table so less needs scrolling. */
@media (max-height: 760px) {
  #results .arcade-title { margin-bottom: var(--gap-sm); }
  #results .score-table td { padding-block: 2px; }
  #results .arcade-heading { margin-bottom: var(--gap-xs); }
}
