/* ------------------------------------------------------------ game screen */
.screen-game {
  padding: 0;
  background: var(--bg);
  touch-action: none;
  overflow: hidden;
}
.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: none;
}
body.in-game { touch-action: none; }

.flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  z-index: 2;
}
/*
 * Top bar: [match + view controls] [scoreboard] [voice controls].
 * One row when there is room; on narrow portrait screens the scoreboard gets
 * the full first row and the two control clusters share the second.
 * The renderers measure this element and fit the table below it.
 */
.hud-top {
  --hud-btn: 40px;
  /* Both side columns get the width of the larger (left) cluster, so the
     scoreboard stays centred even when the voice group is hidden. */
  --hud-side: calc(var(--hud-btn) * 4 + 30px);
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: calc(8px + var(--safe-l));
  right: calc(8px + var(--safe-r));
  display: grid;
  grid-template-columns: minmax(var(--hud-side), 1fr) minmax(0, 720px) minmax(var(--hud-side), 1fr);
  grid-template-areas: "l c r";
  align-items: center;
  column-gap: 10px;
  row-gap: 8px;
  z-index: 6;
  pointer-events: none;
}
.hud-cluster { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.hud-cluster-l { grid-area: l; justify-content: flex-start; }
.hud-cluster-r { grid-area: r; justify-content: flex-end; position: relative; }
.hud-group {
  display: flex; align-items: center; gap: 2px;
  padding: 2px;
  border-radius: 14px;
  background: rgba(10, 14, 34, 0.72);
  border: 1px solid var(--line);
}
.hud-voice { border-color: rgba(60, 255, 160, 0.3); background: linear-gradient(180deg, rgba(10, 36, 30, 0.78), rgba(8, 20, 24, 0.72)); }
.hud-top .icon-btn {
  width: var(--hud-btn); height: var(--hud-btn);
  border: 1px solid transparent; border-radius: 11px;
  background: transparent;
  transition: background 0.15s, transform 0.1s, box-shadow 0.2s;
}
.hud-top .icon-btn:hover { background: rgba(41, 227, 255, 0.1); }
.hud-top .icon-btn:active { transform: scale(0.9); background: rgba(41, 227, 255, 0.2); }
.hud-top .icon-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.hud {
  grid-area: c;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 6px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(10, 13, 32, 0.82), rgba(10, 13, 32, 0.55));
  border: 1px solid var(--line);
  pointer-events: none;
}
.hud-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-left { justify-content: flex-start; }
.hud-right { justify-content: flex-end; }
.hud-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-score {
  font-family: var(--body);
  font-weight: 700;
  font-size: 34px;
  line-height: 1;
  min-width: 1.2em;
  text-align: center;
  display: inline-block;
}
.hud-score.c-blue { color: var(--blue); text-shadow: 0 0 12px rgba(41, 227, 255, 0.8); }
.hud-score.c-red { color: var(--red); text-shadow: 0 0 12px rgba(255, 47, 109, 0.8); }
.hud-name.c-blue { color: #bff6ff; }
.hud-name.c-red { color: #ffc7d6; }
.hud-score.bump { animation: bump 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.4); }
@keyframes bump { 0% { transform: scale(1); } 30% { transform: scale(1.7); } 100% { transform: scale(1); } }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hud-timer { font-family: var(--body); font-weight: 700; font-size: 18px; letter-spacing: 0.08em; }
.hud-net { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 11px; }
.bars b { width: 3px; background: rgba(255, 255, 255, 0.2); border-radius: 1px; }
.bars b:nth-child(1) { height: 4px; }
.bars b:nth-child(2) { height: 7px; }
.bars b:nth-child(3) { height: 11px; }
.hud-net.q3 .bars b { background: #3cffa0; }
.hud-net.q2 .bars b:nth-child(-n+2) { background: var(--gold); }
.hud-net.q1 .bars b:nth-child(1) { background: var(--red); }
.hud-net.offline { color: var(--red); }

/* Each player's name with their ping under it: yours from your own clock, the
   opponent's measured by their client and relayed once a second. */
.hud-who { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.hud-left .hud-who { align-items: flex-start; }
.hud-right .hud-who { align-items: flex-end; }
.hud-ping-chip { font-size: 11px; gap: 4px; }
.hud-ping-chip .bars { height: 8px; }
.hud-ping-chip .bars b { width: 2px; }
.hud-ping-chip .bars b:nth-child(1) { height: 3px; }
.hud-ping-chip .bars b:nth-child(2) { height: 5px; }
.hud-ping-chip .bars b:nth-child(3) { height: 8px; }


.countdown { pointer-events: none; z-index: 8; }
.countdown span {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(90px, 22vmin, 180px);
  color: #fff;
  text-shadow: 0 0 20px var(--violet), 0 0 60px rgba(41, 227, 255, 0.6);
}
.countdown span.tick { animation: count-pop 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes count-pop {
  0% { opacity: 0; transform: scale(2.2); }
  25% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.7); }
}

.goal-banner { pointer-events: none; z-index: 8; }
.goal-banner span {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(56px, 14vmin, 120px);
  letter-spacing: 0.1em;
  animation: goal-in 0.85s cubic-bezier(0.2, 0.9, 0.2, 1) both;
}
.goal-banner.c-blue span { color: #dffbff; text-shadow: 0 0 18px var(--blue), 0 0 50px var(--blue); }
.goal-banner.c-red span { color: #ffe0ea; text-shadow: 0 0 18px var(--red), 0 0 50px var(--red); }
@keyframes goal-in {
  0% { opacity: 0; transform: scale(0.4) rotate(-6deg); }
  20% { opacity: 0.95; transform: scale(1.15) rotate(0); }
  35% { transform: scale(1); }
  60% { opacity: 0.85; }
  100% { opacity: 0; transform: scale(1.05) translateY(-30px); }
}

.result-panel { gap: 12px; }
.result-title {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(34px, 9vw, 48px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.result-title.win { color: var(--gold); text-shadow: 0 0 20px rgba(255, 209, 102, 0.7); }
.result-title.lose { color: var(--muted); }
.result-title.c-blue { color: var(--blue); text-shadow: 0 0 20px rgba(41, 227, 255, 0.7); }
.result-title.c-red { color: var(--red); text-shadow: 0 0 20px rgba(255, 47, 109, 0.7); }
.result-score { font-family: var(--body); font-weight: 700; font-size: 64px; display: flex; justify-content: center; gap: 18px; }
.result-score i { font-style: normal; color: var(--muted); }
#result-l { color: var(--blue); text-shadow: 0 0 16px rgba(41, 227, 255, 0.7); }
#result-r { color: var(--red); text-shadow: 0 0 16px rgba(255, 47, 109, 0.7); }
.result-panel.flip #result-l { color: var(--red); text-shadow: 0 0 16px rgba(255, 47, 109, 0.7); }
.result-panel.flip #result-r { color: var(--blue); text-shadow: 0 0 16px rgba(41, 227, 255, 0.7); }

.debug {
  position: absolute;
  left: calc(8px + var(--safe-l));
  bottom: calc(8px + var(--safe-b));
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
  z-index: 7;
}

/* Narrow screens (either layout, including landscape chosen with the rotate
   button on a phone held upright): full-width score bar, control clusters below it */
@media (max-width: 699px) {
  .hud-top { grid-template-columns: 1fr 1fr; grid-template-areas: "c c" "l r"; }
  .hud { gap: 8px; padding: 5px 10px; }
  .hud-name { font-size: 14px; }
  .hud-score { font-size: 26px; }
}
@media (max-height: 420px) {
  .hud-top { top: calc(4px + var(--safe-t)); }
  .hud { padding: 3px 12px; }
  .hud-score { font-size: 24px; }
  .panel { padding: 16px 18px; gap: 10px; }
  .overlay.modal .panel { width: min(520px, 100%); }
}

.hud-name.speaking { text-shadow: 0 0 10px #3cffa0, 0 0 2px #3cffa0; }
.hud-name.speaking::after {
  content: '';
  display: inline-block;
  width: 7px; height: 7px; margin-left: 6px;
  border-radius: 50%;
  background: #3cffa0;
  box-shadow: 0 0 8px #3cffa0;
  vertical-align: middle;
  animation: talk-pulse 0.6s ease-in-out infinite alternate;
}
@keyframes talk-pulse { to { transform: scale(1.5); opacity: 0.6; } }

.voice-pill {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(10, 14, 34, 0.8);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  z-index: 6;
  pointer-events: none;
}

