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

/* ===== Base ===== */
body {
  background: #080c10;
  color: #e2e8f0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  background-image:
    radial-gradient(ellipse 700px 500px at 50% 40%, #0a1f12 0%, transparent 70%),
    radial-gradient(ellipse 400px 300px at 80% 80%, #0d1520 0%, transparent 60%);
}

/* ===== Header ===== */
header {
  text-align: center;
  padding: 32px 16px 12px;
}

.logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #4ade80;
  text-shadow: 0 0 30px rgba(74, 222, 128, 0.45);
}

.tagline {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #475569;
  letter-spacing: 0.06em;
}

/* ===== Main ===== */
main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0 16px 16px;
  width: 100%;
  max-width: 480px;
}

/* ===== Top bar ===== */
#top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* ===== Scoreboard ===== */
#scoreboard {
  flex: 1;
  display: flex;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  overflow: hidden;
}

.score-cell {
  flex: 1;
  padding: 8px 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.score-cell + .score-cell { border-left: 1px solid #1e293b; }

.score-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #475569;
}
.score-cell span:not(.score-label) {
  font-size: 1.5rem;
  font-weight: 700;
  color: #f1f5f9;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.score-cell span.highlight { color: #4ade80; }

/* ===== Pause button ===== */
#btn-pause {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  color: #64748b;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#btn-pause:not(:disabled):hover  { background: #1e293b; color: #e2e8f0; border-color: #334155; }
#btn-pause:not(:disabled):active { background: #334155; color: #4ade80; }
#btn-pause:disabled { opacity: 0.35; cursor: default; }

/* ===== Canvas wrapper ===== */
#canvas-wrap {
  position: relative;
  border-radius: 12px;
  padding: 2px;
  background: linear-gradient(135deg, #22c55e55, #1e293b 50%, #22c55e22);
  box-shadow:
    0 0 0 1px #1e293b,
    0 0 50px rgba(34, 197, 94, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5);
}

canvas {
  border-radius: 10px;
  background: #0d1117;
  display: block;
  /* scale down on small screens */
  max-width: 100%;
  height: auto;
}

/* ===== Status message ===== */
#message {
  font-size: 0.85rem;
  color: #475569;
  min-height: 1.3em;
  text-align: center;
  letter-spacing: 0.03em;
}
#message b { color: #4ade80; font-weight: 600; }

/* ===== Difficulty selector ===== */
#difficulty {
  display: flex;
  gap: 8px;
}

.diff-btn {
  padding: 7px 18px;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  color: #64748b;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}
.diff-btn:hover  { background: #1e293b; color: #e2e8f0; border-color: #334155; }
.diff-btn.active {
  background: #14532d;
  border-color: #16a34a;
  color: #4ade80;
}

/* ===== D-pad ===== */
#controls {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
}

.dpad-btn {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  color: #64748b;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.dpad-btn:hover  { background: #1e293b; color: #e2e8f0; border-color: #334155; }
.dpad-btn:active { background: #334155; color: #4ade80; transform: scale(0.94); }

#btn-up    { grid-column: 2; grid-row: 1; }
#btn-left  { grid-column: 1; grid-row: 2; }
#btn-down  { grid-column: 2; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }

/* ===== How to play ===== */
#how-to-play {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  font-size: 0.75rem;
  color: #334155;
  letter-spacing: 0.03em;
}

/* ===== Game Over Overlay ===== */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  padding: 16px;
}
#overlay.hidden  { display: none; }
#overlay.visible { opacity: 1; pointer-events: auto; }

.overlay-card {
  position: relative;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 24px;
  padding: 40px 48px 36px;
  text-align: center;
  box-shadow:
    0 0 0 1px #22c55e18,
    0 30px 80px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 320px;
  animation: cardIn 0.3s ease both;
}

@keyframes cardIn {
  from { transform: translateY(20px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.overlay-icon { font-size: 2.4rem; line-height: 1; }

.overlay-card h2 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #f87171;
  text-shadow: 0 0 24px rgba(248, 113, 113, 0.5);
  margin-top: -4px;
}

.overlay-stats {
  display: flex;
  gap: 28px;
  margin: 4px 0;
}

.overlay-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.stat-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #475569;
}
.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: #f1f5f9;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stat-value.green { color: #4ade80; }

#btn-restart {
  margin-top: 6px;
  padding: 13px 40px;
  background: #4ade80;
  color: #052e16;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 4px 20px rgba(74, 222, 128, 0.3);
}
#btn-restart:hover  { background: #86efac; box-shadow: 0 4px 28px rgba(74, 222, 128, 0.45); }
#btn-restart:active { transform: scale(0.97); }

.overlay-hint {
  font-size: 0.75rem;
  color: #334155;
}

#btn-close-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid #1e293b;
  border-radius: 8px;
  color: #475569;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
#btn-close-overlay:hover { background: #1e293b; color: #e2e8f0; }

/* ===== Footer ===== */
footer {
  margin-top: auto;
  padding: 20px 16px;
  font-size: 0.72rem;
  color: #1e293b;
  letter-spacing: 0.05em;
  text-align: center;
}

/* ===== Mobile tweaks ===== */
@media (max-width: 440px) {
  .logo { font-size: 1.6rem; }
  #canvas-wrap { width: calc(100vw - 36px); }
  canvas { width: 100%; height: auto; }
  .overlay-card { padding: 32px 28px 28px; }
}
