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

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #06142e 0%, #01010a 55%, #000 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f8f8ff;
}

.wrapper {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.title {
  font-size: 1.8rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: center;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-size: 0.95rem;
}

.score-label,
.level-label,
.lives-label {
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.level-label {
  border-color: rgba(245, 195, 59, 0.45);
  color: #ffd966;
}

.restart-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  background: #f5c33b;
  color: #1b1b1b;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease,
    background 0.15s ease;
}

.restart-btn:hover {
  background: #ffd54a;
}

.restart-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

canvas {
  display: block;
  border-radius: 8px;
  border: none;
  background: #000016;
  box-shadow: none;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  flex: 1 1 auto;
  min-height: 0;
}

.hint {
  font-size: 0.75rem;
  opacity: 0.75;
  text-align: center;
  flex-shrink: 0;
}

@media (max-width: 768px), (pointer: coarse) {
  .wrapper {
    padding: 36px 6px 8px;
    justify-content: flex-start;
  }

  .header {
    gap: 2px;
    margin-bottom: 4px;
  }

  /* Card already shows "Pac-Man Arcade" — drop duplicate title */
  .title {
    display: none;
  }

  .scoreboard {
    gap: 6px;
    font-size: 0.75rem;
  }

  .score-label,
  .level-label,
  .lives-label {
    padding: 4px 8px;
  }

  .restart-btn {
    padding: 4px 10px;
    font-size: 0.75rem;
  }

  .hint {
    display: none;
  }

  .game-container {
    justify-content: flex-start;
    gap: 8px;
  }

  canvas {
    width: min(100%, 96%);
    max-height: calc(100% - 118px);
    flex: 0 1 auto;
  }
}

/* Modal Popup Overlay */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(1, 1, 10, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: #090e1a;
  border: 2px solid #00f0ff;
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.4);
  border-radius: 16px;
  padding: 24px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 320px;
  width: 90%;
  animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: #ff3366;
  text-shadow: 0 0 12px rgba(255, 51, 102, 0.6);
  letter-spacing: 1px;
}

.modal-title.win {
  color: #00f0ff;
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.6);
}

.modal-message {
  font-size: 0.9rem;
  color: #cbd5e1;
}

.modal-stats {
  font-size: 1rem;
  color: #94a3b8;
  margin-top: 4px;
}

.modal-stats strong {
  color: #f5c33b;
  font-size: 1.2rem;
}

.modal-btn {
  margin-top: 8px;
  border: none;
  border-radius: 12px;
  padding: 10px 22px;
  background: #00f0ff;
  color: #05070a;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
  transition: transform 0.15s ease, background 0.15s ease;
}

.modal-btn:hover {
  background: #4df4ff;
  transform: scale(1.05);
}

/* Touch / Mobile D-Pad — phones/tablets only, never on desktop web */
.dpad-container {
  display: none !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 0;
  padding: 2px 0 4px;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  z-index: 10;
}

@media (hover: none) and (pointer: coarse) {
  .dpad-container {
    display: flex !important;
  }
}

.dpad-middle-row {
  display: flex;
  gap: 44px;
  align-items: center;
  justify-content: center;
}

.dpad-btn {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid rgba(0, 240, 255, 0.7);
  color: #00f0ff;
  font-size: 1.1rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.25);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.1s ease, transform 0.08s ease, border-color 0.1s ease;
}

.dpad-btn:active,
.dpad-btn.active {
  background: rgba(0, 240, 255, 0.4);
  border-color: #00f0ff;
  transform: scale(0.92);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.55);
}

@media (max-height: 700px) {
  .dpad-btn {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
  .dpad-middle-row {
    gap: 36px;
  }
  .dpad-container {
    gap: 2px;
    padding-bottom: 2px;
  }
}

@media (max-height: 560px) {
  .dpad-btn {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
  }
  .dpad-middle-row {
    gap: 30px;
  }
}

