:root {
  --bg: #03030f;
  --panel: #0a0a22;
  --maze-blue: #2121de;
  --pac-yellow: #ffde00;
  --pinky: #ff54a0;
  --inky: #00f0ff;
  --blinky: #ff3c46;
  --neon-grad: linear-gradient(90deg, var(--inky), var(--pinky), var(--pac-yellow));
  --font: 'Press Start 2P', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: #e8e8ff;
  font-family: var(--font);
  overflow: hidden;
}

#app {
  height: 100vh;
  height: 100dvh; /* mobile browsers with dynamic chrome */
  position: relative;
}

/* ---- CRT overlay: scanlines + vignette (pure decoration) ---- */
#crt {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background:
    repeating-linear-gradient(0deg,
      rgba(0, 0, 0, 0.18) 0px,
      rgba(0, 0, 0, 0.18) 1px,
      transparent 1px,
      transparent 3px);
}
#crt::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center,
    transparent 55%, rgba(0, 0, 10, 0.55) 100%);
}

/* ---- Full-viewport board; every control floats above it ---- */
#board-wrap {
  position: absolute;
  inset: 0;
  background: #03030f;
}

#board, #board-overlay {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#board {
  z-index: 0;
  cursor: grab;
  touch-action: none; /* all touch gestures are handled by the game */
}
#board-overlay {
  z-index: 1;
  pointer-events: none;
}
#board.grabbing { cursor: grabbing; }

/* ---- Corner overlay panels ---- */
.overlay {
  position: absolute;
  z-index: 15;
  background: rgba(7, 7, 28, 0.88);
  border: 2px solid var(--maze-blue);
  border-radius: 10px;
  box-shadow: 0 0 14px rgba(33, 33, 222, 0.55);
  padding: 9px 11px;
}

#panel-stats { top: 12px; left: 12px; }
#mini-title {
  font-size: 8px;
  letter-spacing: 2px;
  margin-bottom: 8px;
  background: var(--neon-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 8px rgba(0, 240, 255, 0.45));
  white-space: nowrap;
}
/* "BETA" pill — overrides the gradient text-clip of its parents so it
   renders as a solid neon badge wherever it appears. */
.beta-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  padding: 2px 5px;
  font-size: 6px;
  letter-spacing: 1px;
  line-height: 1;
  color: var(--pac-yellow);
  -webkit-text-fill-color: var(--pac-yellow);
  background: rgba(255, 84, 160, 0.16);
  border: 1px solid var(--pinky);
  border-radius: 4px;
  filter: none;
  text-shadow: 0 0 6px rgba(255, 222, 0, 0.55);
}

#stats { display: flex; gap: 14px; align-items: center; }
#stats .stat { text-align: left; }
#stats .label { color: var(--inky); margin-bottom: 4px; font-size: 7px; }
#stats .value { color: #fff; font-size: 9px; text-shadow: 0 0 6px var(--pinky); }
#stats .stat:nth-child(1) .value { text-shadow: 0 0 6px var(--inky); }
#stats .stat:nth-child(3) .value { color: var(--pac-yellow); text-shadow: 0 0 6px var(--pac-yellow); }
#energy-bar { color: var(--inky); letter-spacing: 1px; }
#energy-bar.low { color: var(--blinky); }

#panel-nav {
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 60vw;
  z-index: 25; /* above help panel */
}

#map-nav {
  --zoom-control-size: 44px;
  --zoom-step-height: 40px;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  padding: 0;
  z-index: 25; /* above help panel so +/- stay clickable */
  overflow: hidden;
}

/* Single stacked control: + | readout + reset | − */
.zoom-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--zoom-control-size);
  gap: 0;
}

/* Isolate from global button typography/padding — grid centers SVG icons */
.zoom-controls > button.zoom-step {
  display: grid;
  place-items: center;
  width: var(--zoom-control-size);
  height: var(--zoom-step-height);
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font: 0/0 sans-serif;
  line-height: 0;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid rgba(33, 33, 222, 0.55);
  box-shadow: none;
  text-shadow: none;
  flex-shrink: 0;
  cursor: pointer;
  background: #11113a;
  color: #e8e8ff;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.zoom-step-icon {
  display: block;
  width: 16px;
  height: 16px;
  overflow: visible;
  pointer-events: none;
}

.zoom-step-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
  filter: drop-shadow(0 0 4px rgba(0, 240, 255, 0.45));
}

.zoom-controls > button.zoom-step:hover {
  transform: none;
  z-index: 1;
  border-color: var(--inky);
  box-shadow: none;
  color: var(--inky);
}

.zoom-controls > button.zoom-step:active {
  transform: none;
  background: #0c0c32;
}

#zoom-in {
  border-radius: 8px 8px 0 0;
}

#zoom-out {
  border-bottom: none;
  border-radius: 0 0 8px 8px;
}

.zoom-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: var(--zoom-control-size);
  box-sizing: border-box;
  padding: 7px 0 6px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(33, 33, 222, 0.55);
  background: rgba(0, 0, 0, 0.28);
}

.zoom-readout-label {
  font-size: 5px;
  letter-spacing: 1px;
  color: var(--inky);
  opacity: 0.75;
  text-shadow: 0 0 4px rgba(0, 240, 255, 0.35);
  line-height: 1;
}

#map-zoom {
  display: block;
  width: var(--zoom-control-size);
  height: 10px;
  font-size: 7px;
  line-height: 10px;
  text-align: center;
  color: var(--pac-yellow);
  letter-spacing: 0;
  text-shadow: 0 0 8px rgba(255, 222, 0, 0.55);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  white-space: nowrap;
}

#zoom-reset {
  display: grid;
  place-items: center;
  width: 30px;
  height: 22px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  flex-shrink: 0;
  border-radius: 5px;
  background: rgba(17, 17, 58, 0.6);
  border: 1px solid rgba(33, 33, 222, 0.65);
  color: #8899cc;
  text-shadow: none;
  box-shadow: none;
  opacity: 0.45;
  cursor: default;
  font: 0/0 sans-serif;
  overflow: visible;
}

.zoom-reset-icon {
  display: block;
  width: 14px;
  height: 14px;
  overflow: visible;
  pointer-events: none;
}

.zoom-reset-icon path {
  fill: currentColor;
  stroke: none;
  filter: drop-shadow(0 0 4px rgba(0, 240, 255, 0.45));
}

#zoom-reset:not(:disabled) {
  opacity: 1;
  color: var(--inky);
  cursor: pointer;
  text-shadow: 0 0 4px rgba(0, 240, 255, 0.45);
}

#zoom-reset:not(:disabled):hover {
  border-color: var(--inky);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.45);
  transform: translateY(-1px);
}

#zoom-reset:not(:disabled):active {
  transform: translateY(0);
}

/* ---- Shapes tray (bottom-left) ---- */
#panel-shapes {
  bottom: 12px;
  left: 12px;
  max-width: min(460px, calc(100vw - 24px));
  padding: 8px;
}
#shapes-buttons { display: flex; gap: 8px; }

#shape-tray {
  margin-bottom: 8px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 4px;
}
#shape-tray.hidden { display: none; }

.tray-hint {
  font-size: 7px;
  color: var(--pac-yellow);
  text-shadow: 0 0 6px rgba(255, 222, 0, 0.6);
  margin: 2px 0 6px;
  letter-spacing: 1px;
}

.tray-group {
  font-size: 7px;
  color: var(--inky);
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.6);
  padding: 7px 2px 4px;
  border-bottom: 1px solid rgba(33, 33, 222, 0.5);
  margin-bottom: 5px;
}

.tray-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.tray-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 64px;
  padding: 5px 2px 4px;
  background: #060618;
  border: 2px solid rgba(33, 33, 222, 0.7);
  border-radius: 8px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* drag is handled with pointer events */
}
.tray-tile:hover {
  border-color: var(--inky);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}
.tray-tile:active { cursor: grabbing; }
.tray-tile.selected {
  border-color: var(--pac-yellow);
  box-shadow: 0 0 14px rgba(255, 222, 0, 0.6);
}
.tray-tile.selected span { color: var(--pac-yellow); }
.tray-tile canvas {
  image-rendering: pixelated;
  background: #03030f;
  border-radius: 4px;
}
.tray-tile span {
  font-size: 6px;
  color: #b8b8f0;
  text-align: center;
  line-height: 1.4;
  word-break: break-word;
}

.tray-empty {
  font-size: 7px;
  color: #6a6ab0;
  padding: 8px 4px 10px;
  line-height: 1.7;
  max-width: 200px;
}

/* Discovery progress badge on the SHAPES button */
#shapes-progress {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 4px;
  font-size: 7px;
  color: var(--pac-yellow);
  background: rgba(255, 222, 0, 0.12);
  border: 1px solid rgba(255, 222, 0, 0.5);
  border-radius: 5px;
}

.builder-sub {
  font-size: 7px;
  color: #8a8ad0;
  text-align: center;
  margin: -4px 0 8px;
  line-height: 1.5;
}

#builder-sizes {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}
.builder-size {
  font-family: inherit;
  font-size: 7px;
  padding: 4px 7px;
  color: #b8b8f0;
  background: #060618;
  border: 1px solid rgba(33, 33, 222, 0.7);
  border-radius: 6px;
  cursor: pointer;
}
.builder-size:hover { border-color: var(--inky); }
.builder-size.active {
  color: #03030f;
  background: var(--pac-yellow);
  border-color: var(--pac-yellow);
}

/* Re-add: custom shape tiles carry a remove button */
.tray-tile-custom { position: relative; }
.tile-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  padding: 0;
  font-size: 11px;
  line-height: 13px;
  color: #ff5a8a;
  background: #060618;
  border: 2px solid rgba(255, 90, 138, 0.7);
  border-radius: 50%;
  cursor: pointer;
}
.tile-del:hover {
  color: #fff;
  background: #ff5a8a;
  box-shadow: 0 0 8px rgba(255, 90, 138, 0.7);
}

/* Admin mode indicator on the SHAPES button */
body.admin #shapes-progress {
  color: #03030f;
  background: var(--pac-yellow);
  border-color: var(--pac-yellow);
}
body.admin #shapes-progress::after { content: " \2605"; }

/* ---- Reward modal (shape discovery) ------------------------------------- */
#reward-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 2, 14, 0.82);
  backdrop-filter: blur(3px);
}
#reward-modal.hidden { display: none; }

#reward-card {
  width: min(340px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px 18px 16px;
  background: #07071c;
  border: 2px solid var(--inky);
  border-radius: 14px;
  box-shadow: 0 0 28px rgba(0, 240, 255, 0.45), inset 0 0 18px rgba(0, 240, 255, 0.08);
  text-align: center;
  animation: reward-pop 0.28s ease-out;
}
@keyframes reward-pop {
  from { transform: scale(0.82); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#reward-burst {
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--pac-yellow);
  text-shadow: 0 0 8px rgba(255, 222, 0, 0.7);
  animation: reward-flash 1s steps(2) infinite;
}
@keyframes reward-flash { 50% { opacity: 0.55; } }

#reward-name {
  font-size: 16px;
  margin: 8px 0 4px;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.8);
}
.reward-tag {
  display: inline-block;
  font-size: 7px;
  padding: 2px 7px;
  color: var(--inky);
  border: 1px solid rgba(0, 240, 255, 0.5);
  border-radius: 8px;
  margin-bottom: 10px;
}

/* Rarity tiers (reward tag + tray tile accent) */
.reward-tag[data-tier="LEGENDARY"] { color: #ffd23f; border-color: #ffd23f; text-shadow: 0 0 8px rgba(255, 210, 63, 0.7); }
.reward-tag[data-tier="EPIC"] { color: #c77dff; border-color: #c77dff; }
.reward-tag[data-tier="RARE"] { color: #5ab0ff; border-color: #5ab0ff; }
.reward-tag[data-tier="UNCOMMON"] { color: #5affa0; border-color: #5affa0; }
.reward-tag[data-tier="COMMON"] { color: #b8b8f0; border-color: rgba(184, 184, 240, 0.5); }

.tray-tile[data-tier="LEGENDARY"] { border-color: rgba(255, 210, 63, 0.7); }
.tray-tile[data-tier="EPIC"] { border-color: rgba(199, 125, 255, 0.7); }
.tray-tile[data-tier="RARE"] { border-color: rgba(90, 176, 255, 0.7); }

#reward-canvas {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
  background: #03030f;
  border: 1px solid rgba(33, 33, 222, 0.6);
  border-radius: 8px;
}
#reward-gen {
  font-size: 8px;
  color: #8a8ad0;
  margin: 6px 0 8px;
}

#reward-blurb {
  font-size: 8px;
  line-height: 1.7;
  color: #c8c8f5;
  margin-bottom: 10px;
  text-align: left;
}

#reward-props {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  text-align: left;
}
#reward-props li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(33, 33, 222, 0.4);
}
#reward-props li span { color: #7a7ac0; }
#reward-props li b { color: var(--inky); font-weight: normal; }

#reward-progress {
  font-size: 8px;
  color: var(--pac-yellow);
  margin-bottom: 12px;
}

#reward-close {
  width: 100%;
  padding: 9px;
  font-family: inherit;
  font-size: 9px;
  color: #03030f;
  background: var(--inky);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.5);
}
#reward-close:hover { background: #fff; }

/* Floating thumbnail that follows the pointer while dragging a shape */
#drag-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  padding: 4px;
  background: rgba(7, 7, 28, 0.9);
  border: 2px solid var(--pac-yellow);
  border-radius: 8px;
  box-shadow: 0 0 14px rgba(255, 222, 0, 0.6);
}
#drag-ghost.hidden { display: none; }
#drag-ghost.over-map { opacity: 0.35; } /* the board ghost preview takes over */
#drag-ghost canvas { display: block; image-rendering: pixelated; }

/* ---- Toast + connection status ---- */
#toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  padding: 8px 14px;
  border: 2px solid var(--blinky);
  border-radius: 8px;
  background: rgba(20, 0, 10, 0.85);
  color: var(--blinky);
  text-shadow: 0 0 8px rgba(255, 60, 70, 0.8);
  pointer-events: none;
  z-index: 30;
}
#toast.hidden { display: none; }

#conn-status {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 8px;
  color: var(--inky);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.7);
  pointer-events: none;
  z-index: 10;
}

/* ---- Discovery notification (non-blocking) ------------------------------ */
#discovery-notice {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-family: var(--font);
  font-size: 8px;
  letter-spacing: 0.5px;
  color: #03030f;
  background: var(--pac-yellow);
  border: 2px solid #fff6b0;
  border-radius: 999px;
  box-shadow: 0 0 18px rgba(255, 222, 0, 0.7);
  cursor: pointer;
  white-space: nowrap;
}
#discovery-notice.hidden { display: none; }
#discovery-notice .dn-burst { color: #b86b00; }
#discovery-notice .dn-count {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #03030f;
  color: var(--pac-yellow);
  border-radius: 999px;
  font-size: 8px;
}
#discovery-notice .dn-cta { opacity: 0.65; }
#discovery-notice.pulse {
  animation: dn-pop 0.45s ease-out, dn-glow 1.5s ease-in-out 0.45s infinite;
}
@keyframes dn-pop {
  0% { transform: translateX(-50%) scale(0.7); }
  60% { transform: translateX(-50%) scale(1.08); }
  100% { transform: translateX(-50%) scale(1); }
}
@keyframes dn-glow {
  0%, 100% { box-shadow: 0 0 14px rgba(255, 222, 0, 0.5); }
  50% { box-shadow: 0 0 28px rgba(255, 222, 0, 0.95); }
}

/* ---- Account avatar (in the nav row) + profile modal -------------------- */
#account-btn.nav-account {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  color: var(--inky);
}
#account-btn.nav-account:hover { border-color: var(--inky); }
.account-icon {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 11px;
  line-height: 1;
  color: currentColor;
}
.account-icon .person { width: 16px; height: 16px; fill: currentColor; display: block; }
/* Logged in: gold avatar with the nickname initial. */
#account-btn.logged {
  color: var(--pac-yellow);
  border-color: var(--pac-yellow);
  box-shadow: 0 0 10px rgba(255, 222, 0, 0.45);
}

#profile-modal {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 2, 14, 0.82);
  backdrop-filter: blur(3px);
}
#profile-modal.hidden { display: none; }
#profile-anon.hidden, #profile-account.hidden, #email-login.hidden { display: none; }
#profile-card {
  position: relative;
  width: min(360px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px 18px 16px;
  background: #07071c;
  border: 2px solid var(--inky);
  border-radius: 14px;
  box-shadow: 0 0 28px rgba(0, 240, 255, 0.45);
}
#profile-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 16px;
  line-height: 20px;
  color: #8a8ad0;
  background: none;
  border: none;
  cursor: pointer;
}
#profile-close:hover { color: #fff; }
.profile-title {
  font-size: 12px;
  color: var(--pac-yellow);
  text-shadow: 0 0 8px rgba(255, 222, 0, 0.6);
  text-align: center;
  margin-bottom: 8px;
}
.profile-sub { font-size: 8px; line-height: 1.7; color: #b8b8f0; text-align: center; margin-bottom: 12px; }
.profile-or { font-size: 7px; color: #6a6ab0; text-align: center; margin: 12px 0 8px; }
.profile-label { font-size: 7px; color: var(--inky); margin: 10px 0 5px; }
.profile-msg { font-size: 8px; color: var(--pac-yellow); min-height: 12px; margin-top: 6px; text-align: center; }

#social-buttons { display: flex; flex-direction: column; gap: 8px; }
.social-btn-form { margin: 0; }
.social-btn {
  width: 100%;
  font-family: inherit;
  font-size: 8px;
  padding: 11px;
  color: #fff;
  background: #11113a;
  border: 2px solid var(--maze-blue);
  border-radius: 9px;
  cursor: pointer;
}
.social-btn:hover { border-color: var(--inky); }
.social-btn[data-provider="discord"] { border-color: #5865f2; }
.social-btn[data-provider="facebook"] { border-color: #1877f2; }

.email-row { display: flex; gap: 6px; }
.email-row input {
  flex: 1;
  font-family: inherit;
  font-size: 9px;
  padding: 9px 8px;
  color: #fff;
  background: #03030f;
  border: 2px solid rgba(33, 33, 222, 0.7);
  border-radius: 8px;
}
.email-row input:focus { outline: none; border-color: var(--inky); }
.email-row button {
  font-family: inherit;
  font-size: 8px;
  padding: 0 12px;
  color: #03030f;
  background: var(--inky);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.email-row button:disabled { opacity: 0.4; cursor: default; }

#profile-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 8px;
  color: #8a8ad0;
  margin-bottom: 12px;
}
#profile-stats b { color: var(--pac-yellow); }
#logout-btn {
  width: 100%;
  margin-top: 14px;
  font-family: inherit;
  font-size: 8px;
  padding: 10px;
  color: #ff5a8a;
  background: #060618;
  border: 2px solid rgba(255, 90, 138, 0.6);
  border-radius: 9px;
  cursor: pointer;
}
#logout-btn:hover { color: #fff; background: #ff5a8a; }

.reward-unsaved { color: var(--pac-yellow) !important; }
.tray-tile-first::after {
  content: "\2605";
  position: absolute;
  top: -7px;
  left: -6px;
  font-size: 11px;
  color: var(--pac-yellow);
  text-shadow: 0 0 6px rgba(255, 222, 0, 0.8);
}
.tray-tile { position: relative; }
#conn-status.offline {
  color: var(--blinky);
  animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- Help panel (on demand) ---- */
#help-panel {
  position: absolute;
  top: 64px;
  right: 12px;
  max-width: 440px;
  padding: 14px 16px;
  background: rgba(7, 7, 28, 0.95);
  border: 2px solid var(--maze-blue);
  border-radius: 10px;
  box-shadow: 0 0 18px rgba(33, 33, 222, 0.7);
  font-size: 8px;
  line-height: 1.9;
  z-index: 20;
}
#help-panel.hidden { display: none; }
#help-panel .help-title {
  color: var(--pac-yellow);
  text-shadow: 0 0 8px rgba(255, 222, 0, 0.6);
  margin-bottom: 8px;
  font-size: 9px;
}
#help-panel ul { list-style: none; }
#help-panel li { margin-bottom: 4px; color: #b8b8f0; }
#help-panel b { color: var(--inky); }
#help-panel .help-contact {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(33, 33, 222, 0.6);
  color: #b8b8f0;
  line-height: 1.8;
}
#help-panel .help-contact a {
  color: var(--pac-yellow);
  text-shadow: 0 0 6px rgba(255, 222, 0, 0.5);
  text-decoration: none;
}
#help-panel .help-contact a:hover { text-decoration: underline; }

/* ---- Buttons & inputs ---- */
button {
  font-family: var(--font);
  font-size: 8px;
  color: #e8e8ff;
  background: #11113a;
  border: 2px solid var(--maze-blue);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
  text-shadow: 0 0 4px rgba(0, 240, 255, 0.4);
  touch-action: manipulation; /* no double-tap zoom on rapid presses */
  user-select: none;
  -webkit-user-select: none;
}

button:hover {
  border-color: var(--inky);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.5);
  transform: translateY(-1px);
}

button:active { transform: translateY(1px); }

button.active {
  border-color: var(--pac-yellow);
  color: var(--pac-yellow);
  box-shadow: 0 0 14px rgba(255, 222, 0, 0.55);
  text-shadow: 0 0 6px rgba(255, 222, 0, 0.8);
}

/* Admin-only for now: hidden by default, revealed once the connection is
   flagged admin (body.admin, set from the "admin" cable event). */
.goto-box {
  display: none;
  align-items: center;
  gap: 5px;
}
body.admin .goto-box { display: inline-flex; }

.goto-box input {
  font-family: var(--font);
  font-size: 8px;
  width: 92px;
  padding: 8px 5px;
  color: var(--pac-yellow);
  background: #060618;
  border: 2px solid var(--maze-blue);
  border-radius: 8px;
  outline: none;
  text-align: center;
}
.goto-box input:focus {
  border-color: var(--inky);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

/* ---- Life builder modal ---- */
#builder-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 8, 0.8);
}
#builder-modal.hidden { display: none; }

#builder-card {
  background: var(--panel);
  border: 3px solid var(--maze-blue);
  border-radius: 12px;
  box-shadow: 0 0 24px rgba(33, 33, 222, 0.8);
  padding: 16px;
  text-align: center;
}

.builder-title {
  font-size: 10px;
  color: var(--pac-yellow);
  text-shadow: 0 0 8px rgba(255, 222, 0, 0.6);
  margin-bottom: 12px;
}

#builder-grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(16, 1fr);
  width: min(384px, 86vw);
  aspect-ratio: 1 / 1;
  gap: 1px;
  background: #1a1a4a;
  border: 2px solid var(--maze-blue);
  border-radius: 6px;
  padding: 2px;
  margin: 0 auto 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.bcell {
  background: #060618;
  border-radius: 3px;
  cursor: pointer;
}
#builder-grid.dense { gap: 1px; }
#builder-grid.dense .bcell { border-radius: 1px; }
.bcell:hover { background: #15154a; }
.bcell.on {
  background: var(--pac-yellow);
  box-shadow: 0 0 6px rgba(255, 222, 0, 0.8);
}

.builder-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* ---- Small screens (phones) ---- */
@media (max-width: 700px) {
  .overlay { padding: 7px 8px; }
  #panel-stats { top: 8px; left: 8px; }
  #mini-title { display: none; }
  #stats { gap: 9px; }
  #stats .label { font-size: 6px; margin-bottom: 3px; }
  #stats .value { font-size: 7px; }

  /* Bottom controls share one row: shapes (left) + nav (right). The tray
     opens as a sheet ABOVE this row (see #shape-tray below), so nothing
     overlaps. Keep nav on a single line so its height is predictable. */
  #panel-nav {
    top: auto;
    bottom: 8px;
    right: 8px;
    max-width: 66vw;
    flex-wrap: nowrap;
    gap: 3px;
    padding: 5px;
  }
  /* Drop the discovery badge below the top stats/account panels on phones. */
  #discovery-notice { top: 52px; font-size: 7px; padding: 7px 10px; gap: 6px; }
  #discovery-notice .dn-cta { display: none; }

  /* The account avatar adds a 4th icon to the bottom nav; keep it compact so
     the row still fits next to SHAPES/BUILDER on narrow phones. */
  #account-btn.nav-account { width: 26px; height: 26px; }
  #conn-status {
    bottom: auto;
    top: 10px;
    right: 12px;
  }
  .goto-box input { width: 58px; padding: 8px 4px; }
  button { font-size: 7px; padding: 8px 8px; }

  #map-nav {
    --zoom-control-size: 40px;
    --zoom-step-height: 38px;
    right: 8px;
  }
  .zoom-step-icon { width: 14px; height: 14px; }
  .zoom-readout { padding: 6px 0 5px; }
  #map-zoom { height: 9px; font-size: 6px; line-height: 9px; }
  #zoom-reset { width: 28px; height: 20px; padding: 0; }
  .zoom-reset-icon { width: 12px; height: 12px; }

  /* Collapsed, the shapes panel is just the SHAPES/BUILDER buttons pinned
     bottom-left (the tray is detached into a sheet, so it no longer widens
     this panel). */
  /* All controls share one bottom line: SHAPES/BUILDER (left) and the
     icon-only WARP/RECENTER/? nav (right). The tray opens as a sheet above
     them (see below). */
  #panel-shapes {
    bottom: 8px;
    left: 8px;
    max-width: none;
    /* Drop the stacking context (base .overlay sets z-index:15) so the
       fixed tray sheet below can rise above zoom/nav (z-index 25) on its
       own, while the SHAPES/BUILDER buttons don't cover the nav buttons. */
    z-index: auto;
  }
  /* Nav becomes icon-only on phones so the whole control row fits one line. */
  #panel-nav .btn-label { display: none; }
  #panel-nav button { padding: 6px 6px; }
  #shapes-buttons button { padding: 7px 7px; }
  #panel-shapes { padding: 6px; }
  #shapes-buttons { gap: 6px; }

  /* Open tray = a bottom sheet floating above the control row. Anchored
     clear of the bottom buttons and drawn opaque on top of the map/zoom so
     there's no overlap; the top of the map stays visible for placing. */
  #shape-tray {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    margin-bottom: 0;
    padding: 8px;
    max-height: 54vh; /* fallback for browsers without dvh/min() */
    max-height: min(54vh, calc(100dvh - 150px));
    background: rgba(7, 7, 28, 0.96);
    border: 2px solid var(--maze-blue);
    border-radius: 10px;
    box-shadow: 0 0 16px rgba(33, 33, 222, 0.6);
    z-index: 30; /* above zoom (#map-nav) and nav while open */
  }

  #help-panel {
    left: 8px;
    right: 8px;
    top: 56px;
    max-width: none;
    font-size: 7px;
  }

  #builder-card { padding: 12px; max-width: 94vw; }
  .builder-title { font-size: 9px; }
}
