@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Rubik:wght@400;500;700&display=swap');

:root {
  --bg: #050510;
  --bg-panel: #0b0b1e;
  --wall-blue: #2121de;
  --pac-yellow: #ffd400;
  --accent: #00e5ff;
  --danger: #ff4d4d;
  --text: #e8e8ff;
  --text-dim: #8888aa;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 0%, #10102a 0%, #050510 60%, #020208 100%);
  color: var(--text);
  font-family: 'Rubik', system-ui, sans-serif;
  min-height: 100%;
  overflow-x: hidden;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 12px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.topbar {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
}

.backlink {
  align-self: flex-start;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  transition: color 0.15s ease;
}
.backlink:hover { color: var(--accent); }

.logo {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  letter-spacing: 2px;
  color: var(--pac-yellow);
  text-shadow: 0 0 12px rgba(255, 212, 0, 0.55);
  margin: 6px 0 0;
}
.logo span { color: var(--accent); text-shadow: 0 0 12px rgba(0, 229, 255, 0.55); }

.stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid #1c1c3d;
  border-radius: 10px;
  padding: 10px 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat .label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.stat .value {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.85rem;
  color: var(--text);
}

#highscore { color: var(--pac-yellow); }
#lives { color: var(--danger); }

.stage {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 1px #1c1c3d, 0 20px 60px -20px rgba(0, 229, 255, 0.25);
}

canvas#game {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 2, 10, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  transition: opacity 0.2s ease;
}

.overlay.hidden { display: none; }

.overlay-panel { max-width: 380px; }

.overlay-panel h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.15rem;
  color: var(--pac-yellow);
  margin: 0 0 14px;
  text-shadow: 0 0 10px rgba(255, 212, 0, 0.5);
}

.overlay-panel p {
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 20px;
}

.btn {
  font-family: 'Rubik', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid #2c2c5c;
  background: #14142e;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #1c1c44;
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.25);
}

.btn:active:not(:disabled) { transform: scale(0.96); }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--pac-yellow);
  color: #1a1400;
  border-color: var(--pac-yellow);
}
.btn-primary:hover:not(:disabled) {
  background: #ffe259;
  box-shadow: 0 0 18px rgba(255, 212, 0, 0.55);
}

.btn-danger { border-color: #5c2020; }
.btn-danger:hover:not(:disabled) {
  background: #2e1414;
  box-shadow: 0 0 14px rgba(255, 77, 77, 0.3);
}

.btn-mute[aria-pressed="true"] {
  color: var(--text-dim);
  border-color: #2c2c5c;
  background: #0e0e22;
}

.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
  user-select: none;
}

.dbtn {
  background: #14142e;
  border: 1px solid #2c2c5c;
  border-radius: 10px;
  color: var(--accent);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}
.dbtn:active { background: #24244c; transform: scale(0.94); }

.dup { grid-column: 2; grid-row: 1; }
.dleft { grid-column: 1; grid-row: 2; }
.ddown { grid-column: 2; grid-row: 3; }
.dright { grid-column: 3; grid-row: 2; }

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: center;
  margin: 0;
}

@media (min-width: 560px) {
  .dpad { display: none; }
}

@media (max-width: 400px) {
  .logo { font-size: 1.25rem; }
  .stat .value { font-size: 0.72rem; }
  .overlay-panel h2 { font-size: 0.95rem; }
}
