/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ── Container ────────────────────────────────────────────── */
.game-container {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Header ───────────────────────────────────────────────── */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.back-link {
  color: #8888cc;
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: #aaaaee;
}

.score-area {
  display: flex;
  gap: 18px;
}

.score-label {
  font-size: 1rem;
  font-weight: 600;
  color: #ccc;
}

.score-label.best {
  color: #ffd740;
}

.score-label span {
  color: #fff;
}

/* ── Difficulty selector ─────────────────────────────────── */
.difficulty-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.diff-btn {
  padding: 8px 22px;
  border: 2px solid #444;
  border-radius: 6px;
  background: #2a2a3e;
  color: #ccc;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn:hover {
  background: #3a3a5e;
  border-color: #666;
}

.diff-btn.active {
  background: #4a4a7e;
  border-color: #7777bb;
  color: #fff;
}

/* ── Canvas wrapper (keeps overlays positioned) ───────────── */
.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1 / 1;
  border: 2px solid #333;
  border-radius: 6px;
  overflow: hidden;
  background: #1b5e20;
  touch-action: none;
}

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

/* ── Overlays ─────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay-content h1 {
  font-size: 2.2rem;
  margin-bottom: 14px;
  color: #4caf50;
  text-shadow: 0 0 12px rgba(76, 175, 80, 0.5);
}

.overlay-content .start-prompt {
  font-size: 1rem;
  color: #bbb;
  animation: pulse 1.8s ease-in-out infinite;
}

.final-score {
  font-size: 1.4rem;
  margin-bottom: 20px;
  color: #eee;
}

.btn-play-again {
  background: #4caf50;
  color: #fff;
  border: none;
  padding: 10px 28px;
  font-size: 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-play-again:hover {
  background: #66bb6a;
}

.btn-play-again:active {
  transform: scale(0.96);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Controls hint ────────────────────────────────────────── */
.controls-hint {
  margin-top: 12px;
  font-size: 0.85rem;
  color: #777;
  text-align: center;
}

/* ── How to Play ──────────────────────────────────────────── */
.how-to-play {
  margin-top: 16px;
  width: 100%;
  max-width: 600px;
  background: #2a2a3e;
  border: 1px solid #444;
  border-radius: 8px;
  overflow: hidden;
}

.how-to-play summary {
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #bbb;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.2s;
}

.how-to-play summary:hover {
  background: #3a3a5e;
}

.how-to-play-body {
  padding: 12px 16px 16px;
  font-size: 0.88rem;
  color: #aaa;
  line-height: 1.6;
  border-top: 1px solid #444;
}

.how-to-play-body p {
  margin-bottom: 8px;
}

.how-to-play-body p:last-child {
  margin-bottom: 0;
}

.how-to-play-body ul {
  margin: 4px 0 8px 20px;
}

.how-to-play-body li {
  margin-bottom: 4px;
}

/* ── Touch arrow controls ─────────────────────────────────── */
.touch-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.touch-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.touch-btn {
  width: 68px;
  height: 60px;
  font-size: 22px;
  border: none;
  border-radius: 12px;
  background: rgba(76, 175, 80, 0.18);
  color: #4caf50;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
  background: rgba(76, 175, 80, 0.45);
}

/* ── Mobile / Desktop hint toggling ───────────────────────── */
.mobile-hint  { display: none; }
.desktop-hint { display: block; }

body.has-touch .mobile-hint  { display: block; }
body.has-touch .desktop-hint { display: none; }
body.has-touch .touch-controls { display: flex; }

/* ── Responsive tweaks ────────────────────────────────────── */
@media (max-width: 440px) {
  body {
    padding: 10px;
  }

  .game-header {
    margin-bottom: 8px;
  }

  .back-link {
    font-size: 0.85rem;
  }

  .score-label {
    font-size: 0.9rem;
  }

  .overlay-content h1 {
    font-size: 1.7rem;
  }

  .diff-btn {
    padding: 6px 14px;
    font-size: 0.85rem;
  }
}
