:root {
  --bg-top: #1a0b2e;
  --bg-bottom: #33145e;
  --accent: #ff9d00;
  --accent2: #ff2e9a;
  --text: #ffffff;
  --board-bg: #0d1b2a;
  --grid-line: rgba(255, 255, 255, 0.06);
  --panel: rgba(255, 255, 255, 0.08);
  --panel-border: rgba(255, 255, 255, 0.18);
}

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

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", "Trebuchet MS", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 20% 20%, var(--bg-top), var(--bg-bottom) 70%);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  justify-content: center;
}

/* Animated floating blobs behind the game for extra kid-fun */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120px 120px at 15% 25%, rgba(255, 157, 0, 0.25), transparent 70%),
    radial-gradient(150px 150px at 85% 20%, rgba(255, 46, 154, 0.25), transparent 70%),
    radial-gradient(130px 130px at 80% 85%, rgba(46, 196, 255, 0.22), transparent 70%),
    radial-gradient(140px 140px at 10% 90%, rgba(120, 255, 120, 0.2), transparent 70%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-2%, 3%) scale(1.15); }
}

.game-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: auto;
}

/* ---------- Top bar ---------- */
.topbar {
  width: 100%;
  text-align: center;
}

.title {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.t-snake { color: #7ef0a0; }
.t-buddies { color: var(--accent); }

.stats {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 6px 14px;
  min-width: 72px;
  backdrop-filter: blur(4px);
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #cdc3ef;
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
}

/* ---------- Board ---------- */
.board-frame {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  padding: 6px;
  border-radius: 22px;
  background: linear-gradient(135deg, #ff9d00, #ff2e9a, #7e5bff);
  box-shadow: 0 0 40px rgba(255, 157, 0, 0.35), 0 18px 40px rgba(0, 0, 0, 0.45);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--board-bg);
  border-radius: 18px;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 6px;
  border-radius: 18px;
  background: rgba(13, 27, 42, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  transition: opacity 0.3s ease;
}

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

.overlay-card {
  text-align: center;
  padding: 18px;
}

.overlay-emoji {
  font-size: 3rem;
  animation: bounce 1.4s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

.overlay-title {
  font-size: 1.8rem;
  margin: 6px 0 8px;
  color: var(--accent);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

.overlay-text {
  color: #dcd3ff;
  margin-bottom: 18px;
  line-height: 1.5;
}

/* ---------- Buttons ---------- */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  color: #fff;
  font-family: inherit;
  transition: transform 0.08s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(3px) scale(0.98); }

.btn-big {
  font-size: 1.5rem;
  padding: 14px 46px;
  background: linear-gradient(135deg, #ff9d00, #ff5e3a);
  box-shadow: 0 8px 0 #b34a00, 0 12px 24px rgba(255, 94, 58, 0.4);
}

.btn-big:active { box-shadow: 0 3px 0 #b34a00; }

.hint {
  margin-top: 14px;
  font-size: 0.85rem;
  color: #b9adf2;
}

kbd {
  background: #2a2050;
  border: 1px solid #51437f;
  border-radius: 6px;
  padding: 1px 6px;
  font-family: inherit;
}

/* ---------- Control row ---------- */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-ctrl {
  font-size: 1rem;
  padding: 10px 18px;
  background: linear-gradient(135deg, #7e5bff, #5b8cff);
  box-shadow: 0 5px 0 #3d3b7a;
}

.btn-ctrl:active { box-shadow: 0 2px 0 #3d3b7a; }

.btn-mode {
  background: linear-gradient(135deg, #ff9d00, #ff2e9a);
  box-shadow: 0 5px 0 #b34a00;
  color: #fff;
}
.btn-mode:active { box-shadow: 0 2px 0 #b34a00; }

/* ---------- Skin bar ---------- */
.skin-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.skin-swatch {
  cursor: pointer;
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease, box-shadow 0.08s ease, border-color 0.2s ease;
  background: var(--panel);
}
.skin-swatch:hover { filter: brightness(1.1); }
.skin-swatch:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.skin-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 4px 0 rgba(0, 0, 0, 0.35); }

.skin-swatch span {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: block;
}

/* ---------- D-pad ---------- */
.dpad {
  margin-top: 4px;
}

.dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 64px);
  gap: 8px;
}

.dpad-btn {
  cursor: pointer;
  border: none;
  border-radius: 16px;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(145deg, #ff9d00, #ff5e3a);
  box-shadow: 0 5px 0 #b34a00;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.dpad-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b34a00; }

.dpad-btn[data-dir="up"]    { grid-column: 2; grid-row: 1; }
.dpad-btn[data-dir="left"]  { grid-column: 1; grid-row: 2; }
.dpad-btn[data-dir="right"] { grid-column: 3; grid-row: 2; }
.dpad-btn[data-dir="down"]  { grid-column: 2; grid-row: 3; }

/* Hide D-pad on desktop where keyboard/swipe is available */
@media (hover: hover) and (pointer: fine) {
  .dpad { display: none; }
}

/* ---------- Collapsible extras (stats + versions) ---------- */
.extras-panel {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  backdrop-filter: blur(4px);
}

.extras-toggle {
  cursor: pointer;
  list-style: none;
  padding: 11px 14px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  text-align: center;
  user-select: none;
}

.extras-toggle::-webkit-details-marker { display: none; }
.extras-toggle::after { content: " ▾"; }
.extras-panel[open] .extras-toggle::after { content: " ▴"; }
.extras-toggle:hover { filter: brightness(1.1); }

.extras-panel[open] .history-panel,
.extras-panel[open] .version-switch {
  display: flex;
}

/* ---------- History panel ---------- */
.history-panel {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border-top: 1px solid var(--panel-border);
  border-radius: 0 0 16px 16px;
  padding: 10px 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
}

.history-stats {
  display: flex;
  gap: 18px;
  justify-content: center;
  font-size: 0.85rem;
  color: #dcd3ff;
}

.history-stats b { color: var(--accent); }

#historyChart {
  display: block;
  width: 100%;
  height: 60px;
  border-radius: 10px;
}

/* ---------- Version switch ---------- */
.version-switch {
  display: none;
  justify-content: center;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--panel-border);
}

.foot {
  font-size: 0.85rem;
  color: #c9bff5;
  text-align: center;
}

@media (max-height: 700px) {
  .dpad-grid { grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 54px); }
  .title { font-size: 1.5rem; }
}