html,
body {
  margin: 0;
  height: 100%;
  background: #000;
}

/* The canvas size itself is chosen in main.js (the largest whole-pixel
   scale that fits the window); this only centers it, with the marquee (when
   shown) right above it. */
body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* ---------- The arcade marquee (marquee.js) ----------
   A backlit sign in a chrome frame with a ring of bulbs, as wide as the
   canvas. JS sets its size, the letter size and the colors it shares with
   the canvas title (--marquee-width, --marquee-height, --marquee-gap,
   --marquee-letter-size, --marquee-frame, --marquee-ghost-size,
   --marquee-wall, --marquee-title-*, --marquee-extrude-*); the rest of the
   look is tuned with the variables below. */
#marquee {
  --marquee-chrome-light: #f4f6fb;
  --marquee-chrome-mid: #9aa0ad;
  --marquee-chrome-dark: #464a56;
  --marquee-panel-center: #1c2272;
  --marquee-panel-edge: #04050f;
  --marquee-glow: rgba(90, 130, 255, 0.55);
  --marquee-glow-size: 14px;
  --marquee-tilt: 16deg;
  --marquee-perspective: 240px;
  --marquee-outline: 2px;
  --marquee-bulb-size: 5px;
  --marquee-bulb-light: #fffbe6;
  --marquee-bulb-body: #ffd84a;
  --marquee-bulb-edge: #ff8c1a;
  --marquee-bulb-glow: rgba(255, 200, 80, 0.9);
  /* Animations (transform and opacity only, so they stay cheap). The shine
     crosses the sign in the first quarter of each period (see @keyframes
     marquee-shine); the chase lights move on one bulb every chase step,
     every third bulb lit, the others dimmed to bulb-dim. */
  --marquee-shine-period: 4s;
  --marquee-shine-color: rgba(255, 255, 255, 0.5);
  --marquee-chase-step: 0.12s;
  --marquee-bulb-dim: 0.25;
  /* Reactions to the game (marquee.js setMarqueeMood, celebrateMarquee):
     a burst of all bulbs together (eaten ghost, fruit, extra life); dark
     after a death (bulbs nearly off, the sign under a black veil, faded in
     and out); all bulbs on and off together while the maze flashes. */
  --marquee-burst-flash: 0.1s;
  --marquee-burst-flashes: 4;
  --marquee-bulb-off: 0.1;
  --marquee-dark-veil: 0.6;
  --marquee-dark-fade: 0.4s;
  /* Power-on (marquee.js powerOnMarquee): the bulbs light one by one around
     the frame in power-bulbs-time, under a black veil that then flickers off
     like a warming neon tube; power-time is the whole sequence. */
  --marquee-power-time: 1.2s;
  --marquee-power-bulbs-time: 0.6s;
  --marquee-power-bulb: 0.05s;
  --marquee-power-veil: 0.85;
  /* Bulb patterns (data-pattern, marquee.js; chase is the default above):
     odd and even bulbs swap every alternate-step; fill lights the frame
     bulb by bulb, holds it and goes dark, once per fill-time; in sparkle
     each bulb twinkles once per sparkle-period at its own random moment. */
  --marquee-alternate-step: 0.4s;
  --marquee-fill-time: 3s;
  --marquee-sparkle-period: 2.5s;
  position: relative;
  flex: none;
  width: var(--marquee-width);
  height: var(--marquee-height);
  margin-bottom: var(--marquee-gap);
}

/* display rules below would otherwise override the hidden attribute. */
#marquee[hidden] {
  display: none;
}

/* Chrome: bands of light and dark like polished metal, a highlight on the
   top edge and a shadow under the sign. */
.marquee-frame {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  padding: var(--marquee-frame);
  border-radius: calc(var(--marquee-frame) * 0.75);
  background: linear-gradient(
    180deg,
    var(--marquee-chrome-light) 0%,
    var(--marquee-chrome-mid) 30%,
    var(--marquee-chrome-light) 50%,
    var(--marquee-chrome-dark) 75%,
    var(--marquee-chrome-mid) 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 -1px 0 rgba(0, 0, 0, 0.6),
    0 3px 8px rgba(0, 0, 0, 0.7);
}

/* Lit from behind: brighter in the middle, a soft blue glow along the inner
   edge. The perspective gives the tilted title its depth; overflow hides
   the halves of the peeking ghosts outside the sign. */
.marquee-panel {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: var(--marquee-perspective);
  background: radial-gradient(
    ellipse at 50% 45%,
    var(--marquee-panel-center) 0%,
    var(--marquee-panel-edge) 75%
  );
  box-shadow:
    inset 0 0 var(--marquee-glow-size) 2px var(--marquee-glow),
    inset 0 0 2px 1px #000;
}

/* The title leans back a little, so its bottom comes toward the viewer. */
.marquee-title {
  display: flex;
  align-items: center;
  font: var(--marquee-letter-size) / 1 "Press Start 2P", monospace;
  transform: rotateX(var(--marquee-tilt));
}

/* Each word twice in the same place: the text itself is the back (the
   outline in the maze wall color and a 3D block of stacked shadows, front
   to back), ::after is the face with the yellow-to-orange gradient. */
.marquee-word {
  position: relative;
  color: var(--marquee-extrude-near);
  -webkit-text-stroke: var(--marquee-outline) var(--marquee-wall);
  text-shadow:
    1px 1px 0 color-mix(in srgb, var(--marquee-extrude-near), var(--marquee-extrude-far) 20%),
    2px 2px 0 color-mix(in srgb, var(--marquee-extrude-near), var(--marquee-extrude-far) 40%),
    3px 3px 0 color-mix(in srgb, var(--marquee-extrude-near), var(--marquee-extrude-far) 60%),
    4px 4px 0 color-mix(in srgb, var(--marquee-extrude-near), var(--marquee-extrude-far) 80%),
    5px 5px 0 var(--marquee-extrude-far),
    6px 6px 6px rgba(0, 0, 0, 0.6);
}

.marquee-word::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  color: transparent;
  -webkit-text-stroke: 0;
  text-shadow: none;
  background: linear-gradient(
    180deg,
    var(--marquee-title-light) 0%,
    var(--marquee-title-body) 50%,
    var(--marquee-title-shade) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
}

/* Our Pac-Man in the dash's place (size set by marquee.js), with the same
   depth as the letters. */
.marquee-pacman {
  margin: 0 calc(var(--marquee-letter-size) * 0.2);
  filter: drop-shadow(3px 3px 0 var(--marquee-extrude-far));
}

/* Half outside the sign, so they seem to peek in from behind the frame. */
.marquee-ghost {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.marquee-ghost-left {
  left: calc(var(--marquee-ghost-size) * -0.45);
}

.marquee-ghost-right {
  right: calc(var(--marquee-ghost-size) * -0.45);
}

/* The bulbs sit on the frame's middle line (positions from marquee.js). */
.marquee-bulbs {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.marquee-bulb {
  position: absolute;
  width: var(--marquee-bulb-size);
  height: var(--marquee-bulb-size);
  margin: calc(var(--marquee-bulb-size) / -2) 0 0 calc(var(--marquee-bulb-size) / -2);
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 35%,
    var(--marquee-bulb-light) 0%,
    var(--marquee-bulb-body) 45%,
    var(--marquee-bulb-edge) 100%
  );
  box-shadow: 0 0 4px 1px var(--marquee-bulb-glow);
  /* Three steps per cycle: lit for one, dim for two. Each bulb starts one
     step later than the one before it (a negative delay starts it already
     running), so the lit bulbs seem to run clockwise around the sign. */
  animation: marquee-chase calc(3 * var(--marquee-chase-step)) step-end infinite;
  animation-delay: calc(var(--bulb-index) * var(--marquee-chase-step) * -1);
}

@keyframes marquee-chase {
  0% {
    opacity: 1;
  }
  33.333% {
    opacity: var(--marquee-bulb-dim);
  }
}

/* A slanted band of light the size of the panel, moved across it like a
   glint on the sign's glass. 'screen' only ever brightens: the letters
   flash almost white, the dark panel gets a faint streak. */
.marquee-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  background: linear-gradient(
    105deg,
    transparent 42%,
    var(--marquee-shine-color) 50%,
    transparent 58%
  );
  transform: translateX(-100%);
  animation: marquee-shine var(--marquee-shine-period) ease-in-out infinite;
}

/* The sweep takes the first 25% of the period, then the band waits off the
   right edge until the next one. */
@keyframes marquee-shine {
  0% {
    transform: translateX(-100%);
  }
  25%,
  100% {
    transform: translateX(100%);
  }
}

/* A black veil over the whole sign, seen only while it is dark. */
.marquee-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: #000;
  opacity: 0;
}

/* The reactions, weakest first: a later rule wins over an earlier one
   (same specificity), so dark beats the maze flash, which beats a burst. */
/* How far the fill pattern has gone around the frame: below 0 all dark,
   1 all lit, above 1 held lit. A registered number, so it can be animated
   smoothly and every bulb can compare it with its own place. */
@property --marquee-fill-progress {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

@media (prefers-reduced-motion: no-preference) {
  /* The patterns come first: every reaction below wins over them. */
  #marquee[data-pattern="alternate"] .marquee-bulb {
    animation: marquee-alternate calc(2 * var(--marquee-alternate-step)) step-end infinite;
    animation-delay: calc(mod(var(--bulb-index), 2) * var(--marquee-alternate-step) * -1);
  }

  #marquee[data-pattern="fill"] .marquee-bulbs {
    animation: marquee-fill var(--marquee-fill-time) linear infinite;
  }

  /* Lit once the progress has passed this bulb's place; the large factor
     makes the step from dim to lit instant instead of a slow fade. The
     opacity changes without an animation here, so the dark fade's
     transition would smear every step (and run on through a pause). */
  #marquee[data-pattern="fill"] .marquee-bulb {
    animation: none;
    transition: none;
    opacity: clamp(
      var(--marquee-bulb-dim),
      (var(--marquee-fill-progress) * var(--bulb-count) - var(--bulb-index)) * 1000,
      1
    );
  }

  #marquee[data-pattern="sparkle"] .marquee-bulb {
    animation: marquee-sparkle var(--marquee-sparkle-period) ease-in-out infinite;
    animation-delay: calc(var(--bulb-random) * var(--marquee-sparkle-period) * -1);
  }

  /* Power-on: each bulb waits off for its turn (both = hold the first frame
     before the delay and the last one after the end). */
  #marquee.is-powering-on .marquee-bulb {
    animation: marquee-bulb-on var(--marquee-power-bulb) step-end both;
    animation-delay: calc(var(--bulb-index) / var(--bulb-count) * var(--marquee-power-bulbs-time));
  }

  #marquee.is-powering-on .marquee-frame::after {
    animation: marquee-power-veil var(--marquee-power-time) step-end both;
  }

  /* All bulbs flash together a few times, then the chase comes back. */
  #marquee.is-celebrating .marquee-bulb {
    animation: marquee-burst var(--marquee-burst-flash) step-end var(--marquee-burst-flashes);
  }

  /* Following the maze's walls (game time, set every frame by main.js). */
  /* Sharp steps like the walls: no dark fade here. */
  #marquee.is-flashing .marquee-bulb {
    animation: none;
    transition: none;
    opacity: var(--marquee-bulb-dim);
  }

  #marquee.is-flashing.is-flash-lit .marquee-bulb {
    opacity: 1;
  }

  .marquee-frame::after,
  .marquee-bulb {
    transition: opacity var(--marquee-dark-fade);
  }
}

@keyframes marquee-alternate {
  0% {
    opacity: 1;
  }
  50% {
    opacity: var(--marquee-bulb-dim);
  }
}

/* A short dark pause (below 0), the fill (0 to 1), then held lit (above 1). */
@keyframes marquee-fill {
  from {
    --marquee-fill-progress: -0.15;
  }
  to {
    --marquee-fill-progress: 1.3;
  }
}

/* Dim most of the time, a quick twinkle near the start of each period. */
@keyframes marquee-sparkle {
  0%,
  20%,
  100% {
    opacity: var(--marquee-bulb-dim);
  }
  8% {
    opacity: 1;
  }
}

@keyframes marquee-bulb-on {
  from {
    opacity: var(--marquee-bulb-off);
  }
  to {
    opacity: 1;
  }
}

/* Dark while the bulbs come on, then two flickers before it stays lit. */
@keyframes marquee-power-veil {
  0% {
    opacity: var(--marquee-power-veil);
  }
  55% {
    opacity: 0;
  }
  62% {
    opacity: var(--marquee-power-veil);
  }
  70% {
    opacity: 0;
  }
  76% {
    opacity: var(--marquee-power-veil);
  }
  84%,
  100% {
    opacity: 0;
  }
}

@keyframes marquee-burst {
  0% {
    opacity: 1;
  }
  50% {
    opacity: var(--marquee-bulb-dim);
  }
}

/* A state, not a motion: dark with reduced motion too (without the fade). */
#marquee.is-dark .marquee-bulb {
  animation: none;
  opacity: var(--marquee-bulb-off);
}

#marquee.is-dark .marquee-frame::after {
  opacity: var(--marquee-dark-veil);
}

/* Pause (P, marquee.js): every animation holds where it is. !important,
   because the reactions above set the animation shorthand, which would
   reset the play state to running. */
#marquee.is-paused * {
  animation-play-state: paused !important;
}

/* Players who turn motion off get a still sign: bulbs all lit, no shine. */
@media (prefers-reduced-motion: reduce) {
  #marquee * {
    animation: none;
  }

  .marquee-shine {
    display: none;
  }
}

#game-container {
  /* Anchor for the absolutely positioned debug overlay */
  position: relative;
}

#debug-overlay {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 4px;
  font: 12px monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  /* Keep the double spaces and line break in the stats text */
  white-space: pre;
  pointer-events: none;
}

/* Debug: the sound gallery's live playback-rate slider (soundGallery.js),
   under the canvas's middle, only while the gallery is open. */
#sound-rate {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  font: 12px monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
  white-space: pre;
}

#sound-rate input {
  vertical-align: middle;
}

canvas {
  display: block;
  /* The canvas already has one pixel per screen pixel (main.js); this only
     keeps the pixels sharp if the browser ever has to rescale it */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
