/* =====================================================================
   Neon Pac-Man — fixed "midnight arcade" theme.
   Like Flappy Bird / Tunnel Flyer, this page deliberately ignores the
   center's light/dark mode and the shared glass chrome (no glass.css is
   loaded). Every colour is hardcoded from the game's own neon canvas
   palette: deep indigo void, glowing cyan maze walls, gold Pac-Man and
   four saturated ghost hues.
   ===================================================================== */
:root {
  --pm-void:    #05010f;   /* page + maze background */
  --pm-void2:   #0b0526;
  --pm-cyan:    #00e5ff;   /* maze wall glow */
  --pm-cyan-2:  #7cf9ff;
  --pm-gold:    #ffe94f;   /* Pac-Man + dots */
  --pm-magenta: #ff2d95;
  --pm-purple:  #b14bff;
  --pm-green:   #39ff14;
  --pm-orange:  #ff7a1a;
  --pm-fright:  #2a5bff;   /* frightened ghost */
  --pm-text:    #d6f4ff;
  --pm-muted:   #7aa6c4;
  --pm-panel:   #0a0722;
  --pm-line:    rgba(0, 229, 255, .85);
}

html, body { height: 100%; }
body.pm-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: manipulation;
  background:
    radial-gradient(120% 90% at 50% -10%, #14093a 0%, transparent 55%),
    radial-gradient(90% 70% at 50% 120%, #1a0733 0%, transparent 60%),
    linear-gradient(180deg, var(--pm-void2), var(--pm-void));
  color: var(--pm-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.pm-page *,
body.pm-page *::before,
body.pm-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(11, 5, 38, .55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--pm-cyan);
  box-shadow: 0 0 18px rgba(0, 229, 255, .35);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 0 6px rgba(255, 233, 79, .8)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--pm-gold);
  text-shadow: 0 0 10px rgba(255, 233, 79, .55), 0 0 2px rgba(255, 233, 79, .9);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat {
  font-size: 14px; font-weight: 700; letter-spacing: .04em; white-space: nowrap;
  color: var(--pm-muted); text-transform: uppercase;
}
.stat b { color: var(--pm-cyan-2); font-size: 17px; font-variant-numeric: tabular-nums; text-shadow: 0 0 8px rgba(0, 229, 255, .6); }

/* ---------- Buttons (neon outline chips) ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--pm-line);
  background: rgba(0, 229, 255, .06);
  color: var(--pm-cyan-2);
  box-shadow: 0 0 10px rgba(0, 229, 255, .25), inset 0 0 10px rgba(0, 229, 255, .08);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease, color .15s ease;
}
.c-btn:hover { background: rgba(0, 229, 255, .16); color: #fff; box-shadow: 0 0 16px rgba(0, 229, 255, .5); }
.c-btn:active { transform: translateY(2px); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(0, 229, 255, .45), 0 0 16px rgba(0, 229, 255, .5); }
.c-btn--primary {
  background: linear-gradient(140deg, var(--pm-magenta), #d5137a);
  border-color: rgba(255, 45, 149, .9);
  color: #fff;
  text-shadow: 0 0 6px rgba(0, 0, 0, .4);
  box-shadow: 0 0 16px rgba(255, 45, 149, .55), inset 0 0 10px rgba(255, 255, 255, .12);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #ff4ba7, var(--pm-magenta)); color: #fff; box-shadow: 0 0 22px rgba(255, 45, 149, .7); }

/* ---------- Table / stage ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.pm-stage {
  position: relative;
  /* maze is 19 x 21 tiles; cap by viewport height minus chrome. */
  width: min(94vw, calc((100vh - 150px) * 0.9048), calc((100dvh - 150px) * 0.9048), 460px);
  aspect-ratio: 19 / 21;
  border-radius: 14px;
  overflow: hidden;
  background: var(--pm-void);
  border: 2px solid var(--pm-cyan);
  box-shadow: 0 0 22px rgba(0, 229, 255, .4), inset 0 0 40px rgba(0, 229, 255, .08);
  touch-action: none;
}
#board {
  display: block; width: 100%; height: 100%;
  touch-action: none;
  image-rendering: auto;
}

/* ---------- Ready / game-over overlay ---------- */
.pm-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(5, 1, 15, .72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.pm-overlay[hidden] { display: none; }
.pm-card {
  touch-action: manipulation;
  max-width: 300px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, #120a35, var(--pm-panel));
  border: 2px solid var(--pm-cyan);
  box-shadow: 0 0 24px rgba(0, 229, 255, .45), 0 20px 50px rgba(0, 0, 0, .6);
  color: var(--pm-text);
  animation: pmPop .3s ease;
}
@keyframes pmPop { from { transform: scale(.88); opacity: 0; } }
.pm-card__big svg { width: 78px; height: 78px; display: block; margin: 0 auto; filter: drop-shadow(0 0 10px rgba(255, 233, 79, .6)); }
.pm-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--pm-gold);
  text-shadow: 0 0 10px rgba(255, 233, 79, .5);
}
.pm-card p { margin: 0 0 14px; color: var(--pm-muted); font-size: 13.5px; line-height: 1.55; }
.pm-card .c-btn { font-size: 14px; }
.pm-card kbd, .c-modal kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--pm-cyan-2);
  background: rgba(0, 229, 255, .1);
  border: 1px solid var(--pm-line);
  border-radius: 6px;
}

/* ---------- On-screen D-pad (touch only) ---------- */
.pm-dpad { position: absolute; inset: 0; z-index: 4; pointer-events: none; display: none; }
@media (pointer: coarse) { .pm-dpad { display: block; } }
.pm-dbtn {
  pointer-events: auto;
  position: absolute;
  width: 46px; height: 46px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: var(--pm-cyan-2);
  background: rgba(10, 7, 34, .5);
  border: 2px solid var(--pm-line);
  border-radius: 12px;
  box-shadow: 0 0 10px rgba(0, 229, 255, .3);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  touch-action: manipulation;
}
.pm-dbtn:active { background: rgba(0, 229, 255, .28); color: #fff; }
.pm-dbtn--up    { left: 50%; top: 10px;    transform: translateX(-50%); }
.pm-dbtn--down  { left: 50%; bottom: 10px; transform: translateX(-50%); }
.pm-dbtn--left  { left: 10px;  bottom: 64px; }
.pm-dbtn--right { right: 10px; bottom: 64px; }

/* ---------- Rules modal (overlay scrolls, never the card) ---------- */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; padding: 16px;
  overflow-y: auto;               /* the overlay scrolls, not the card */
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(3, 0, 10, .68);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.c-modal__panel {
  position: relative; z-index: 1;
  margin: auto;                   /* centres AND lets a tall card scroll from the top */
  width: min(92vw, 480px);
  background: linear-gradient(160deg, #101a3a, var(--pm-panel));
  color: var(--pm-text);
  border-radius: 16px;
  border: 2px solid var(--pm-cyan);
  box-shadow: 0 0 26px rgba(0, 229, 255, .4), 0 24px 60px rgba(0, 0, 0, .6);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0, 229, 255, .35);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--pm-cyan-2); text-shadow: 0 0 8px rgba(0, 229, 255, .5);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--pm-muted); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--pm-gold); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; color: var(--pm-muted); }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--pm-gold);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--pm-cyan-2); }
.c-modal__lead { margin: 12px 0; color: var(--pm-text); }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 229, 255, .08);
  border: 1px solid rgba(0, 229, 255, .3);
  font-size: 13px;
  color: var(--pm-text);
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 700px), (max-height: 560px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
}
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .pm-card { transition: none; animation: none; }
}
