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

:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --border: #2a2a2a;
  --accent: #7fff6a;
  --accent-dim: #3d7a33;
  --text: #e8e8e8;
  --muted: #555;
  --danger: #ff5a5a;
  --cell: 20px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px 16px 32px;
  width: 100%;
  max-width: 520px;
}

/* ---- Header ---- */
header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 2rem;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-shadow: 0 0 16px var(--accent-dim);
}

#scores {
  display: flex;
  gap: 16px;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.label {
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--muted);
}

#score, #best {
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--text);
  min-width: 3ch;
  text-align: right;
}

/* ---- Canvas wrapper ---- */
#canvas-wrapper {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 0 40px rgba(127, 255, 106, 0.04);
}

#game {
  display: block;
}

/* ---- Overlay ---- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 13, 13, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.overlay.active {
  opacity: 1;
  pointer-events: all;
}

.overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.overlay-title {
  font-size: 2.5rem;
  letter-spacing: 0.4em;
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-dim);
}

.overlay-sub {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--muted);
}

#final-score-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#final-score {
  font-size: 3rem;
  font-weight: bold;
  color: var(--text);
}

#start-btn {
  margin-top: 8px;
  padding: 12px 40px;
  background: var(--accent);
  color: #0d0d0d;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0.25em;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

#start-btn:hover {
  background: #a0ffaa;
}

#start-btn:active {
  transform: scale(0.96);
}

/* ---- D-pad ---- */
#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  user-select: none;
}

.dpad-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dpad-center {
  width: 44px;
  height: 44px;
}

.dpad-btn {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dpad-btn:active {
  background: var(--border);
}

#hint {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* ---- Responsive ---- */
@media (min-width: 500px) {
  #dpad { display: none; }
  #hint { margin-top: -8px; }
}
