/* ==========================================================================
   Snake 2048 - "Cyber-Circuit Neon" in-game HUD
   Same design tokens as the landing screen (theme.css). Everything in here is
   pure chrome: it sits over the PIXI canvas and never eats a pointer event, so
   steering and boosting keep working exactly as before.
   game-ui.js toggles .is-live and feeds the readouts.
   ========================================================================== */

#game-hud {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
  font-family: var(--font-mono);
  color: var(--on-surface);
  opacity: 0;
  transition: opacity 0.5s ease;
}

#game-hud[hidden] {
  display: none;
}

#game-hud.is-live {
  opacity: 1;
}

/* --- background chrome --------------------------------------------------- */

/* The circuit grid, dialled well below the landing screen's so it reads as
   glass over the arena instead of competing with the snakes. */
.gh-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 220, 230, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 220, 230, 0.028) 1px, transparent 1px);
  background-size: 40px 40px;
  /* keep the playable centre clean - only the rim carries the grid */
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 42%, #000 88%);
  mask-image: radial-gradient(ellipse at center, transparent 42%, #000 88%);
}

.gh-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(2, 3, 5, 0.55) 100%),
    linear-gradient(to bottom, rgba(0, 220, 230, 0.05), transparent 18%),
    linear-gradient(to top, rgba(254, 0, 254, 0.04), transparent 18%);
}

/* --- frame + corner ticks ("digital framing" from DESIGN.md) -------------- */

/* The game owns the top-right (leaderboard) and bottom-right (boost button)
   corners, so the frame hugs the extreme viewport edge and the ticks stay
   short - anything inset further collides with the game's own HUD. */
.gh-frame {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(0, 220, 230, 0.16);
  box-shadow: inset 0 0 48px rgba(0, 220, 230, 0.05);
}

.gh-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 0 solid var(--primary-fixed-dim);
  opacity: 0.7;
  filter: drop-shadow(0 0 6px rgba(0, 220, 230, 0.55));
}

.gh-corner.tl { top: 0;    left: 0;  border-top-width: 2px;    border-left-width: 2px; }
.gh-corner.tr { top: 0;    right: 0; border-top-width: 2px;    border-right-width: 2px; }
.gh-corner.bl { bottom: 0; left: 0;  border-bottom-width: 2px; border-left-width: 2px; }
.gh-corner.br { bottom: 0; right: 0; border-bottom-width: 2px; border-right-width: 2px; }

/* magenta on the bottom pair, mirroring the landing title lockup */
.gh-corner.bl,
.gh-corner.br {
  border-color: var(--secondary);
  filter: drop-shadow(0 0 6px rgba(255, 171, 243, 0.5));
}

/* --- top readout --------------------------------------------------------- */

/* clears the sound toggle and the pause button, both 44px squares pinned along
   the top-left at 12px and 68px, and centres on them */
.gh-top {
  position: absolute;
  top: 12px;
  left: 124px;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gh-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: rgba(17, 19, 24, 0.62);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 220, 230, 0.28);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--outline);
  white-space: nowrap;
}

.gh-chip b {
  font-weight: 600;
  color: var(--primary-fixed);
  text-shadow: 0 0 8px rgba(0, 220, 230, 0.55);
}

.gh-chip.is-tile {
  border-color: rgba(254, 0, 254, 0.3);
}

.gh-chip.is-tile b {
  color: var(--secondary);
  text-shadow: 0 0 8px rgba(255, 171, 243, 0.55);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.04em;
}

/* these chips only earn their space when they have a value */
.gh-chip.is-tile[hidden],
.gh-chip.is-count[hidden],
.gh-chip.is-coins[hidden],
.gh-chip.is-cost[hidden] {
  display: none;
}

/* coins - lime, the palette's "you gained something" colour */
.gh-chip.is-coins {
  border-color: rgba(121, 255, 91, 0.28);
}

.gh-chip.is-coins b {
  color: var(--tertiary-fixed);
  text-shadow: 0 0 8px rgba(121, 255, 91, 0.55);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.gh-chip.is-coins.is-gain {
  animation: gh-payout 1.1s ease-out;
}

/* revive price. .is-short = the player can't cover it, so the button is inert */
.gh-chip.is-cost b {
  color: var(--tertiary-fixed);
  text-shadow: 0 0 8px rgba(121, 255, 91, 0.55);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.gh-chip.is-cost.is-short {
  border-color: rgba(255, 180, 171, 0.4);
}

.gh-chip.is-cost.is-short b {
  color: var(--error);
  text-shadow: 0 0 8px rgba(147, 0, 10, 0.9);
}

@keyframes gh-payout {
  0%   { border-color: var(--tertiary-fixed); box-shadow: 0 0 18px rgba(121, 255, 91, 0.55); }
  100% { border-color: rgba(121, 255, 91, 0.28); box-shadow: none; }
}

.gh-chip.is-count {
  border-color: rgba(255, 180, 171, 0.34);
}

.gh-chip.is-count b {
  color: var(--error);
  text-shadow: 0 0 8px rgba(147, 0, 10, 0.9);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.gh-live {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--tertiary-fixed);
  box-shadow: 0 0 8px rgba(121, 255, 91, 0.9);
  animation: gh-blink 1.6s ease-in-out infinite;
}

/* --- alarm states -------------------------------------------------------- */

/* .is-down = killed, revive window still open. .is-over = run finished.
   The whole frame swings to the error pair so the canvas screens underneath
   (KILLED / game over, both already recoloured by game-ui.js) read as one
   moment rather than two unrelated layers. */

#game-hud.is-down .gh-frame,
#game-hud.is-over .gh-frame {
  border-color: rgba(255, 180, 171, 0.3);
  box-shadow: inset 0 0 64px rgba(147, 0, 10, 0.22);
}

#game-hud.is-down .gh-corner,
#game-hud.is-over .gh-corner {
  border-color: var(--error);
  opacity: 0.9;
  filter: drop-shadow(0 0 7px rgba(147, 0, 10, 0.85));
}

#game-hud.is-down .gh-vignette,
#game-hud.is-over .gh-vignette {
  background:
    radial-gradient(ellipse at center, transparent 45%, rgba(30, 0, 3, 0.6) 100%),
    linear-gradient(to bottom, rgba(147, 0, 10, 0.14), transparent 22%),
    linear-gradient(to top, rgba(147, 0, 10, 0.12), transparent 22%);
}

#game-hud.is-down .gh-chip,
#game-hud.is-over .gh-chip {
  border-color: rgba(255, 180, 171, 0.3);
}

#game-hud.is-down .gh-live,
#game-hud.is-over .gh-live {
  background: var(--error);
  box-shadow: 0 0 8px rgba(147, 0, 10, 0.9);
}

/* the status light stops blinking once the run is truly over */
#game-hud.is-over .gh-live {
  animation: none;
  opacity: 0.5;
}

#game-hud.is-down .gh-status-val {
  color: var(--error);
  text-shadow: 0 0 8px rgba(147, 0, 10, 0.9);
}

#game-hud.is-over .gh-status-val {
  color: var(--secondary);
  text-shadow: 0 0 8px rgba(255, 171, 243, 0.6);
}

/* the tile reading freezes on death, so mute it - it is a result now, not a gauge */
#game-hud.is-down .gh-chip.is-tile,
#game-hud.is-over .gh-chip.is-tile {
  border-color: rgba(255, 171, 243, 0.22);
}

/* --- bottom readout ------------------------------------------------------ */

.gh-foot {
  position: absolute;
  left: 22px;
  bottom: 18px;
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: 0.1em;
  color: rgba(132, 148, 149, 0.4);
}

/* --- gameplay-only toggles ----------------------------------------------- */

/* Both corner buttons declare display:flex, which outranks the UA [hidden]
   rule, so every hidden state needs an explicit selector here.

   Visibility has two independent owners - landing.js (menu vs run) and
   game-pause.js (paused) - so they get a class each instead of both writing
   style.display and clobbering one another. */
#cyber-sound-btn.is-hidden-menu,
#cyber-sound-btn.is-hidden-paused,
#cyber-sound-btn[hidden] {
  display: none;
}

/* --- pause control ------------------------------------------------------- */

/* Sits beside the sound toggle in index.html and shares its glass-square look,
   minus the pulse - two pulsing buttons in one corner reads as noise. Lives
   outside #game-hud because that layer is pointer-events:none. */
#cyber-pause-btn {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(68px + env(safe-area-inset-left, 0px));
  z-index: 10000;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 19, 24, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 220, 230, 0.5);
  cursor: pointer;
  transition: all 0.3s ease;
}

#cyber-pause-btn[hidden] {
  display: none;
}

#cyber-pause-btn:hover {
  background: rgba(0, 220, 230, 0.15);
  border-color: var(--primary-fixed-dim);
  box-shadow: 0 0 20px rgba(0, 220, 230, 0.6), inset 0 0 15px rgba(0, 220, 230, 0.1);
  transform: scale(1.08);
}

#cyber-pause-btn:active {
  transform: scale(0.95);
  background: rgba(0, 220, 230, 0.25);
}

#cyber-pause-btn .material-symbols-outlined {
  font-size: 22px;
  color: var(--primary-fixed-dim);
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  filter: drop-shadow(0 0 4px rgba(0, 220, 230, 0.6));
}

#cyber-pause-btn::before,
#cyber-pause-btn::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
}

#cyber-pause-btn::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--primary-fixed-dim);
  border-left: 2px solid var(--primary-fixed-dim);
}

#cyber-pause-btn::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--primary-fixed-dim);
  border-right: 2px solid var(--primary-fixed-dim);
}

/* --- pause overlay ------------------------------------------------------- */

#pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 5, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

#pause-overlay[hidden] {
  display: none;
}

#pause-overlay.is-open {
  opacity: 1;
}

.po-panel {
  position: relative;
  min-width: 280px;
  padding: 36px 48px 32px;
  text-align: center;
  background: rgba(17, 19, 24, 0.82);
  border: 1px solid rgba(0, 220, 230, 0.3);
  box-shadow: 0 0 40px rgba(0, 220, 230, 0.12);
  transform: scale(0.94);
  transition: transform 0.25s ease;
}

#pause-overlay.is-open .po-panel {
  transform: scale(1);
}

/* corner brackets, same ornament as the landing CTA */
.po-panel > i {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 0 solid var(--primary-fixed);
}

.po-panel > i:nth-child(1) { top: -1px; left: -1px;  border-top-width: 2px;    border-left-width: 2px; }
.po-panel > i:nth-child(2) { top: -1px; right: -1px; border-top-width: 2px;    border-right-width: 2px; }
.po-panel > i:nth-child(3) { bottom: -1px; left: -1px;  border-bottom-width: 2px; border-left-width: 2px; }
.po-panel > i:nth-child(4) { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }

.po-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--outline);
}

.po-title {
  margin: 6px 0 24px;
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 20px rgba(0, 220, 230, 0.6);
}

.po-btn {
  width: 100%;
  padding: 14px 24px;
  border: 1px solid rgba(0, 220, 230, 0.5);
  border-radius: 0;
  background: var(--surface);
  color: #fff;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.po-btn:hover {
  border-color: var(--primary-fixed);
  box-shadow: 0 0 22px rgba(0, 220, 230, 0.5);
}

.po-btn:active {
  transform: scale(0.97);
}

.po-btn:focus-visible {
  outline: 2px solid var(--primary-fixed);
  outline-offset: 3px;
}

.po-hint {
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--outline);
}

.po-hint b {
  color: var(--primary-fixed);
  font-weight: 600;
}

/* --- animations ---------------------------------------------------------- */

@keyframes gh-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}

/* --- responsive ---------------------------------------------------------- */

@media (max-width: 639px) {
  .gh-corner { width: 12px; height: 12px; }
  .gh-top { top: 10px; left: 112px; height: 40px; gap: 6px; }
  .gh-chip { padding: 4px 8px; font-size: 9px; }
  #cyber-pause-btn { left: calc(62px + env(safe-area-inset-left, 0px)); }
  .po-panel { min-width: 0; width: min(88vw, 340px); padding: 28px 24px 24px; }
  .po-title { font-size: 34px; }
  .gh-chip.is-tile b { font-size: 12px; }
  /* the boost button owns the bottom-right on phones - drop the footer text */
  .gh-foot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gh-live { animation: none; }
}
