:root {
  --bg: #0f1117;
  --bg-soft: #1a1d29;
  --panel: #1e2130;
  --grid: rgba(255, 255, 255, 0.035);
  --accent: #4ade80;
  --accent-dark: #22c55e;
  --food: #f87171;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 800px at 50% -10%, #1b2030 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  overflow: hidden;
  touch-action: manipulation;
}

.app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  margin: 0;
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.scores {
  display: flex;
  gap: 10px;
}

.score-box {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 6px 14px;
  min-width: 68px;
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.score-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.score-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Board */
.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-soft);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.board {
  display: block;
  width: 100%;
  height: 100%;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 23, 0.72);
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 24px;
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  max-width: 300px;
}

.overlay-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 800;
}

.overlay-text {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.4;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #06240f;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 12px 34px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.35);
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}

.btn:hover { box-shadow: 0 10px 26px rgba(34, 197, 94, 0.45); }
.btn:active { transform: translateY(1px) scale(0.98); }

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

/* D-pad (mobile) */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 10px;
  max-width: 260px;
  margin: 0 auto;
  width: 100%;
}

.dpad-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel);
  color: var(--text);
  font-size: 1.3rem;
  border-radius: 14px;
  padding: 16px 0;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s ease, transform 0.05s ease;
}

.dpad-btn:active {
  background: var(--accent-dark);
  color: #06240f;
  transform: scale(0.96);
}

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

/* Show d-pad on touch / small screens */
@media (max-width: 640px), (pointer: coarse) {
  .dpad { display: grid; }
  body { align-items: flex-start; padding-top: 16px; }
}
