/* ===== SNAKE GAME ===== */

:root {
  --bg:          #08080F;
  --surface:     #0F0F1A;
  --border:      rgba(255,255,255,0.07);
  --text:        #E8E8F5;
  --muted:       rgba(232,232,245,0.45);

  --accent:      #39FF14;
  --accent-dim:  rgba(57,255,20,0.15);
  --accent-glow: 0 0 12px #39FF14, 0 0 30px rgba(57,255,20,0.4);

  --grid-line:   rgba(255,255,255,0.04);
  --food:        #FF4757;
  --t:           0.2s;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── BACK ── */
.back {
  position: fixed; top: 1.25rem; left: 1.5rem; z-index: 100;
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.8rem; font-weight: 500;
  color: var(--muted); text-decoration: none;
  transition: color var(--t);
  letter-spacing: 0.02em;
}
.back:hover { color: var(--text); }
.back svg { opacity: 0.7; transition: opacity var(--t); }
.back:hover svg { opacity: 1; }

/* ── HERO ── */
.hero {
  min-height: 36vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  padding: 6rem 1.5rem 2.5rem;
  text-align: center;
}

.hero-bg {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 70% 55% at 50% 60%, rgba(57,255,20,0.09) 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 50% 90%, rgba(57,255,20,0.04) 0%, transparent 60%);
  animation: aurora 14s ease-in-out infinite alternate;
}

@keyframes aurora {
  0%   { opacity: 0.5; transform: scale(1) rotate(0deg); }
  100% { opacity: 0.85; transform: scale(1.12) rotate(2deg); }
}

.badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: 0.72rem; font-weight: 500; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent);
  border: 1px solid rgba(57,255,20,0.22); border-radius: 50px;
  padding: 0.35rem 1rem; margin-bottom: 1.2rem;
  background: rgba(57,255,20,0.06);
  animation: fade-up 0.8s cubic-bezier(.16,1,.3,1) 0.3s both;
}
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.65); }
}

.hero h1 {
  font-family: 'Instrument Serif', serif;
  font-size: clamp(3.2rem, 10vw, 6.8rem);
  font-weight: 400; line-height: 1; letter-spacing: -0.02em;
  color: var(--text); margin-bottom: 1rem;
  animation: fade-up 0.9s cubic-bezier(.16,1,.3,1) 0.45s both;
}
.hero h1 .accent-text { font-style: italic; color: var(--accent); }

.hero-subtitle {
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  color: var(--muted); max-width: 360px; line-height: 1.7;
  animation: fade-up 0.9s cubic-bezier(.16,1,.3,1) 0.6s both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── MAIN ── */
main {
  display: flex; flex-direction: column; align-items: center;
  padding-bottom: 5rem;
}

/* ── GAME WRAPPER ── */
.game-wrapper {
  display: flex; flex-direction: column; gap: 1rem;
  width: 100%; max-width: 520px;
  padding: 0 1rem;
  animation: fade-up 0.7s cubic-bezier(.16,1,.3,1) 0.15s both;
}

/* ── SCORE BAR ── */
.score-bar {
  display: flex; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
}

.score-item {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
}

.score-label {
  font-size: 0.65rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted);
}

.score-value {
  font-family: 'Instrument Serif', serif;
  font-size: 1.8rem; line-height: 1;
  color: var(--accent);
  transition: transform 0.15s ease;
}

.score-value.pop {
  animation: score-pop 0.3s cubic-bezier(.16,1,.3,1);
}

@keyframes score-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); color: #fff; }
  100% { transform: scale(1); }
}

/* ── GAME BOARD CONTAINER ── */
.game-board-container {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(57,255,20,0.08);
  aspect-ratio: 1;
}

canvas#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── OVERLAYS ── */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.75rem;
  background: rgba(8,8,15,0.82);
  backdrop-filter: blur(4px);
  text-align: center;
  animation: fade-in 0.3s ease;
}

.overlay.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-hint {
  font-size: 1rem; font-weight: 500; color: var(--text);
}
.overlay-hint kbd {
  display: inline-block;
  padding: 0.15em 0.5em;
  font-family: 'Inter', sans-serif;
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: var(--accent);
}
.overlay-sub {
  font-size: 0.8rem; color: var(--muted);
}
.overlay-icon {
  font-size: 2.5rem; line-height: 1;
}

/* ── BUTTONS ── */
.btn-start {
  margin-top: 0.5rem;
  padding: 0.75rem 2rem;
  background: var(--accent);
  color: #000;
  border: none; border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  transition: opacity var(--t), transform var(--t);
}
.btn-start:hover { opacity: 0.85; transform: scale(1.03); }
.btn-start:active { transform: scale(0.97); }

/* ── D-PAD ── */
.dpad {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 0.5rem 0;
}
.dpad-row {
  display: flex; gap: 4px; justify-content: center;
}

.dpad-btn {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t), transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.dpad-btn:hover {
  border-color: rgba(57,255,20,0.3);
  color: var(--accent);
  background: var(--accent-dim);
}
.dpad-btn:active { transform: scale(0.92); }
.dpad-center { font-size: 0.9rem; }

@media (hover: hover) {
  .dpad { opacity: 0.45; }
  .dpad:hover { opacity: 1; }
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,8,15,0.75);
  backdrop-filter: blur(6px);
  animation: fade-in 0.3s ease;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.8rem;
  width: min(360px, 90vw);
  display: flex; flex-direction: column; align-items: center; gap: 1.4rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6), 0 0 40px rgba(57,255,20,0.06);
  animation: modal-in 0.35s cubic-bezier(.16,1,.3,1);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  font-family: 'Inter', sans-serif;
  font-size: 1.1rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.15em;
  color: var(--text);
}

.modal-stats {
  display: flex; gap: 2rem;
}
.modal-stat {
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
}
.stat-label {
  font-size: 0.65rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted);
}
.stat-value {
  font-family: 'Instrument Serif', serif;
  font-size: 2rem; line-height: 1;
  color: var(--accent);
}

.btn-primary {
  padding: 0.8rem 2.5rem;
  background: var(--accent);
  color: #000;
  border: none; border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem; font-weight: 600;
  cursor: pointer;
  transition: opacity var(--t), transform var(--t);
}
.btn-primary:hover { opacity: 0.85; transform: scale(1.03); }
.btn-primary:active { transform: scale(0.97); }

.modal-actions {
  display: flex; flex-direction: column; gap: 0.6rem; width: 100%;
}
.modal-actions .btn-primary { width: 100%; }

.btn-secondary {
  display: block; width: 100%;
  padding: 0.65rem 1.5rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem; font-weight: 500;
  cursor: pointer; text-align: center; text-decoration: none;
  transition: border-color var(--t), color var(--t), transform var(--t);
  box-sizing: border-box;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); transform: scale(1.02); }
.btn-secondary:active { transform: scale(0.97); }

/* ── FLASH (game over animation) ── */
@keyframes flash-red {
  0%, 100% { box-shadow: 0 0 40px rgba(57,255,20,0.08); }
  50%       { box-shadow: 0 0 40px rgba(255,71,87,0.5); }
}
.game-board-container.flash {
  animation: flash-red 0.4s ease;
}

/* ── INFO SECTION ── */
.info-section {
  margin-top: 3rem;
  max-width: 520px;
  padding: 0 1rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.info-section h2 {
  font-family: 'Instrument Serif', serif;
  font-size: 1.1rem; font-style: italic;
  color: var(--text); font-weight: 400;
}
.info-section p {
  font-size: 0.88rem; color: var(--muted); line-height: 1.7;
}
.info-section ul {
  list-style: none; display: flex; flex-direction: column; gap: 0.35rem;
}
.info-section li {
  font-size: 0.88rem; color: var(--muted); line-height: 1.6;
  padding-left: 1rem; position: relative;
}
.info-section li::before {
  content: '›'; position: absolute; left: 0;
  color: var(--accent);
}

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex; justify-content: center; gap: 0.6rem;
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--text); }

/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  .hero-bg { animation: none; }
  .badge-dot { animation: none; }
  .score-value.pop { animation: none; }
  .game-board-container.flash { animation: none; }
}
