/* ======================================= */
/* SNAKE - TOOLIFY STIJL                   */
/* ======================================= */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=Fredoka+One&display=swap');

:root {
  --bg:         #f0f4ff;
  --surface:    #ffffff;
  --surface2:   #f8faff;
  --border:     #dde3f5;
  --text:       #2d3561;
  --text-muted: #7b84b0;

  --blue:   #3b82f6;
  --purple: #8b5cf6;
  --pink:   #ec4899;
  --teal:   #14b8a6;
  --orange: #f97316;
  --red:    #ef4444;
  --green:  #22c55e;

  --shadow-sm: 0 2px 8px  rgba(59,82,246,0.08);
  --shadow-md: 0 6px 24px rgba(59,82,246,0.13);
  --shadow-lg: 0 12px 40px rgba(59,82,246,0.18);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 32px;
}

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

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 1.5rem 1rem 1rem;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(34,197,94,0.07)   0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(6,182,212,0.07)   0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(139,92,246,0.04)  0%, transparent 60%);
  -webkit-tap-highlight-color: transparent;
}

/* ======================================= */
/* HEADER                                  */
/* ======================================= */
.game-header {
  text-align: center;
  margin-bottom: 1.4rem;
}

.game-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.8rem;
  line-height: 1;
  background: linear-gradient(135deg, var(--green), var(--teal), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(34,197,94,0.25));
  margin-bottom: 0.3rem;
}

.game-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ======================================= */
/* GAME LAYOUT                             */
/* ======================================= */
.game-layout {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: flex-start;
}

/* ======================================= */
/* SIDE PANELS                             */
/* ======================================= */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: 110px;
  flex-shrink: 0;
}

.info-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.info-label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.info-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  color: var(--text);
  line-height: 1;
}

.score-val  { color: var(--purple); font-size: 1.3rem; }
.lives-val  { color: var(--red); }
.length-val { color: var(--green); }
.speed-val  { color: var(--orange); }

/* Legend cards */
.legend-card, .ctrl-legend-card { padding: 0.55rem 0.6rem; text-align: left; }

.legend-line {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.8;
}

.leg-icon { font-size: 0.85rem; flex-shrink: 0; }

/* Mini highscores */
.hs-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.7rem;
  box-shadow: var(--shadow-sm);
}

.hs-mini { list-style: none; margin-top: 0.4rem; }

.hs-mini li {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
  border-bottom: 1px solid var(--border);
}

.hs-mini li:last-child { border-bottom: none; }
.hs-mini li span:first-child { color: var(--text-muted); }
.hs-mini li span:last-child  { color: var(--purple); font-family: 'Fredoka One', cursive; }

.hs-mini-empty {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.3rem 0;
}

/* Action buttons */
.action-btns { display: flex; flex-direction: column; gap: 0.4rem; }

.action-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.action-btn:hover     { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.action-btn.new-btn   { border-color: #86efac; color: var(--green); }
.action-btn.pause-btn { border-color: #93c5fd; color: var(--blue); }

/* Speed slider */
.speed-slider-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}

.speed-slider-label {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-muted);
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--orange), var(--red));
  outline: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--green);
  box-shadow: 0 2px 8px rgba(34,197,94,0.35);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.speed-slider::-webkit-slider-thumb:hover {
  border-color: var(--teal);
  box-shadow: 0 4px 14px rgba(20,184,166,0.45);
}

.speed-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--green);
  box-shadow: 0 2px 8px rgba(34,197,94,0.35);
  cursor: pointer;
}

.speed-slider-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  color: var(--green);
  min-width: 1.5rem;
  text-align: center;
}

/* ======================================= */
/* CANVAS WRAP                             */
/* ======================================= */
.canvas-wrap {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-lg);
  border: 3px solid var(--border);
  display: inline-flex;
  flex-shrink: 0;
}

#snake-canvas {
  display: block;
  border-radius: var(--radius-sm);
  background: #1a1e3a;
  touch-action: none;
}

/* ======================================= */
/* MOBILE CONTROLS                         */
/* ======================================= */
.mobile-controls {
  display: none;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
  margin-top: 1rem;
  padding-bottom: 1.5rem;
}

.ctrl-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.ctrl-spacer { width: 62px; height: 62px; }

.ctrl-btn {
  width: 62px;
  height: 62px;
  border-radius: var(--radius-md);
  border: 2.5px solid var(--border);
  background: var(--surface);
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ctrl-btn:active {
  transform: scale(0.9);
  background: var(--surface2);
  box-shadow: var(--shadow-sm);
}

#btn-up, #btn-down { border-color: var(--green); }
#btn-left, #btn-right { border-color: var(--blue); }

/* ======================================= */
/* PAUSE OVERLAY                           */
/* ======================================= */
.pause-overlay {
  position: fixed; inset: 0;
  background: rgba(30,30,80,0.55);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.pause-overlay.show { opacity: 1; pointer-events: all; }

.pause-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 280px; width: 90%;
  animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

.pause-emoji { font-size: 3rem; display: block; margin-bottom: 0.5rem; }
.pause-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem; color: var(--text); margin-bottom: 1.2rem;
}

/* ======================================= */
/* GAME OVER OVERLAY                       */
/* ======================================= */
.win-overlay {
  position: fixed; inset: 0;
  background: rgba(30,30,80,0.55);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.win-overlay.show { opacity: 1; pointer-events: all; }

.win-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem; text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 340px; width: 90%;
  animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.win-emoji { font-size: 3.5rem; display: block; margin-bottom: 0.5rem; }

.win-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  background: linear-gradient(135deg, var(--red), var(--purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  margin-bottom: 0.3rem;
}

.win-sub {
  color: var(--text-muted); font-weight: 700; font-size: 0.9rem; margin-bottom: 0.5rem;
}

.win-stats {
  display: flex; justify-content: center; gap: 1.2rem; margin: 1rem 0 1.5rem;
}

.win-stat { text-align: center; }

.win-stat-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem; display: block; color: var(--purple);
}

.win-stat-lbl {
  font-size: 0.72rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}

.win-play-btn {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem; padding: 0.75rem 2rem;
  border-radius: 999px; border: none;
  background: linear-gradient(135deg, var(--green), var(--teal));
  color: #fff; cursor: pointer;
  box-shadow: 0 4px 16px rgba(34,197,94,0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}
.win-play-btn:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 8px 24px rgba(34,197,94,0.45);
}

/* ======================================= */
/* SCORE POP ANIMATION                     */
/* ======================================= */
.score-pop {
  position: absolute;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  font-weight: 900;
  pointer-events: none;
  animation: scorePop 0.9s ease forwards;
  z-index: 20;
  white-space: nowrap;
}

@keyframes scorePop {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  60%  { opacity: 1; transform: translateY(-28px) scale(1.15); }
  100% { opacity: 0; transform: translateY(-48px) scale(0.9); }
}

/* ======================================= */
/* ANIMATIONS                              */
/* ======================================= */
@keyframes popIn {
  0%   { transform: scale(0.7) translateY(30px); opacity: 0; }
  100% { transform: scale(1)   translateY(0);    opacity: 1; }
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-header, .speed-slider-row, .game-layout {
  animation: fadeSlideIn 0.4s ease both;
}
.speed-slider-row { animation-delay: 0.05s; }
.game-layout      { animation-delay: 0.10s; }

/* ======================================= */
/* RESPONSIVE — TABLET                     */
/* ======================================= */
@media (max-width: 700px) {
  .side-panel { width: 88px; }
  .info-val   { font-size: 1.25rem; }
  .score-val  { font-size: 1.1rem; }
}

/* ======================================= */
/* RESPONSIVE — MOBILE                     */
/* ======================================= */
@media (max-width: 520px) {
  body { padding: 1rem 0.5rem 0.5rem; }
  .game-title  { font-size: 2rem; }
  .game-layout { gap: 0.5rem; }

  .side-panel  { width: 70px; gap: 0.5rem; }
  .info-label  { font-size: 0.6rem; }
  .info-val    { font-size: 1.1rem; }
  .score-val   { font-size: 0.95rem; }

  .hs-card, .legend-card, .ctrl-legend-card, .speed-card { display: none; }
  .mobile-controls { display: flex; }
  .action-btn { font-size: 0.75rem; padding: 0.4rem 0.4rem; }
}

@media (max-width: 380px) {
  .side-panel { width: 58px; }
  .info-card  { padding: 0.4rem 0.4rem; }
  .info-label { display: none; }
}
