/* Snek — Berry Garden theme
   Mobile-first, responsive, with accessible tokens and focus states. */

:root {
  --bg: #fff4e6;
  --surface: #fffaf1;
  --ink: #4a2c44;
  --muted: #8a6a80;
  --accent: #4cc99a;
  --accent-dark: #17856a;
  --berry: #ff7fb2;
  --berry-dark: #d64f8c;
  --gold: #ffce54;
  --ice: #6fc3e8;
  --sage: #97c05c;
  --sage-dark: #5e8231;
  --tangerine: #ff9d5c;
  --tangerine-dark: #d96b2f;
  --ghostly: #cfc4f4;
  --ghostly-dark: #8a76c9;
  --mystery: #b06ad4;
  --mystery-dark: #7c3f99;
  --board-line: #f0d9c4;
  --cell: #fdeee0;
  --border: #f0d9c4;
  --radius: 14px;
  --shadow: 0 6px 18px rgba(126, 74, 108, 0.14);
  --focus: 3px solid #2f6db3;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Baloo 2", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #ffe3ef 0%, var(--bg) 55%, #e3f7ea 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

a {
  color: var(--accent-dark);
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

.site-header {
  text-align: center;
  padding: 1rem 1rem 0.75rem;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3rem);
  letter-spacing: 0.02em;
  color: var(--accent-dark);
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.game-shell {
  width: 100%;
  max-width: 620px;
  padding: 0.75rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.hud {
  width: 100%;
  text-align: center;
}

.scoreboard {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 0 0 0.5rem;
}

.stat {
  margin: 0;
}

.stat dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat dd {
  margin: 0.1rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.status {
  margin: 0.25rem 0 0;
  font-weight: 600;
  min-height: 1.4em;
}

.effect {
  margin: 0.25rem 0 0;
  color: var(--accent-dark);
  font-weight: 600;
  min-height: 1.2em;
}

.board {
  --cells: 20;
  display: grid;
  grid-template-columns: repeat(var(--cells), 1fr);
  gap: 1px;
  width: min(92vw, 560px, calc(100vh - 340px));
  max-width: 560px;
  aspect-ratio: 1 / 1;
  padding: 6px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: none;
}

.cell {
  aspect-ratio: 1 / 1;
  background: var(--cell);
  border-radius: 3px;
}

/* Snake */
.snake-body {
  background: var(--accent);
  border-radius: 30%;
}

.snake-head {
  background: var(--accent-dark);
  border-radius: 35%;
  position: relative;
}

.snake-head::before,
.snake-head::after {
  content: "";
  position: absolute;
  width: 22%;
  height: 22%;
  background: #fff;
  border-radius: 50%;
  top: 22%;
}

.snake-head::before {
  left: 20%;
}

.snake-head::after {
  right: 20%;
}

/* Death drama: the board shakes and the crashed snake flashes red. */
.board-wrap.crashed {
  animation: board-shake 0.5s ease-in-out;
}

@keyframes board-shake {
  0%,
  100% {
    transform: translate(0, 0) rotate(0);
  }

  20% {
    transform: translate(-4px, 2px) rotate(-0.6deg);
  }

  40% {
    transform: translate(3px, -2px) rotate(0.5deg);
  }

  60% {
    transform: translate(-2px, 1px) rotate(-0.3deg);
  }

  80% {
    transform: translate(2px, -1px) rotate(0.2deg);
  }
}

.snake-head.crashed,
.snake-body.crashed {
  background: var(--berry-dark);
  animation: crash-flash 0.6s ease-out 1 both;
}

@keyframes crash-flash {
  0% {
    filter: brightness(2.2);
  }

  100% {
    filter: brightness(1);
  }
}

/* Food: a berry */
.food {
  background: var(--berry);
  border-radius: 50%;
  position: relative;
  box-shadow: inset -2px -2px 0 var(--berry-dark);
}

.food::before {
  content: "";
  position: absolute;
  left: 25%;
  top: -18%;
  width: 40%;
  height: 40%;
  background: var(--accent);
  border-radius: 80% 20% 60% 40%;
}

/* Board wrapper hosts the floating bonus toast over the board. The height
   term is floored so short landscape viewports still get a playable board
   (the page may scroll); dvh is preferred where supported for iOS Safari. */
.board-wrap {
  position: relative;
  width: min(92vw, 560px, max(240px, calc(100vh - 340px)));
  max-width: 560px;
}

@supports (width: 1dvh) {
  .board-wrap {
    width: min(92vw, 560px, max(240px, calc(100dvh - 340px)));
  }
}

.board-wrap .board {
  width: 100%;
}

.toast {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translate(-50%, 0);
  margin: 0;
  padding: 0.4rem 0.9rem;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 999px;
  font-weight: 700;
  color: var(--accent-dark);
  box-shadow: var(--shadow);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.toast.show {
  animation: toast-pop 1.2s ease forwards;
}

@keyframes toast-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.9);
  }

  12% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }

  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(1);
  }
}

/* Under reduced motion the animation is disabled by the global rule and
   toast-pop's forwards fill would land on opacity 0; show the toast
   statically instead so the message stays visible. */
@media (prefers-reduced-motion: reduce) {
  .toast.show {
    animation: none;
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Legend explaining what each pickup does. */
.legend {
  width: 100%;
  max-width: 460px;
}

.legend-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1.1rem;
  margin: 0;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  list-style: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  display: inline-block;
  width: 0.95em;
  height: 0.95em;
  flex: none;
}

.swatch-berry {
  background: var(--berry);
  border-radius: 50%;
  box-shadow: inset -1px -1px 0 var(--berry-dark);
}

.swatch-star {
  background: var(--gold);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.swatch-slow {
  background: var(--ice);
  border-radius: 50%;
}

.swatch-shrink {
  background: var(--sage);
  border-radius: 30%;
  box-shadow: inset -1px -1px 0 var(--sage-dark);
}

.swatch-double {
  background: var(--tangerine);
  border-radius: 50%;
  box-shadow: inset -1px -1px 0 var(--tangerine-dark);
}

.swatch-ghost {
  background: var(--ghostly);
  border: 2px dashed var(--ghostly-dark);
  border-radius: 50% 50% 45% 55% / 60% 60% 40% 40%;
}

.swatch-golden {
  background: var(--gold);
  border-radius: 50%;
  box-shadow:
    inset -1px -1px 0 rgba(0, 0, 0, 0.25),
    0 0 3px 1px rgba(255, 206, 84, 0.75);
}

/* Bonuses gently pulse so they read as pickups worth chasing. */
.bonus {
  position: relative;
  animation: bonus-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes bonus-pulse {
  from {
    transform: scale(0.8);
  }

  to {
    transform: scale(1.05);
  }
}

.bonus-points {
  background: var(--gold);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.bonus-slow {
  background: var(--ice);
  border-radius: 50%;
}

.bonus-slow::before {
  content: "❄";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 70%;
  color: #fff;
}

/* Shrink: sage rounded square with shears. */
.bonus-shrink {
  background: var(--sage);
  border-radius: 30%;
  box-shadow: inset -2px -2px 0 var(--sage-dark);
}

.bonus-shrink::before {
  content: "✂";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 70%;
  color: #fff;
}

/* Double points: tangerine circle with an ×2 mark. */
.bonus-double {
  background: var(--tangerine);
  border-radius: 50%;
  box-shadow: inset -2px -2px 0 var(--tangerine-dark);
}

.bonus-double::before {
  content: "×2";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 55%;
  font-weight: 700;
  color: #fff;
}

/* Ghost: pale blob with a dashed outline, reads as intangible. */
.bonus-ghost {
  background: var(--ghostly);
  border: 2px dashed var(--ghostly-dark);
  border-radius: 50% 50% 45% 55% / 60% 60% 40% 40%;
}

.bonus-ghost::before {
  content: "👻";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 60%;
}

/* Mystery: unexplained purple box with a question mark. */
.bonus-mystery {
  background: var(--mystery);
  border-radius: 22%;
  box-shadow: inset -2px -2px 0 var(--mystery-dark);
}

.bonus-mystery::before {
  content: "?";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 75%;
  font-weight: 700;
  color: #fff;
}

/* Golden berry: gilded berry with a sparkle; blinks before it vanishes. */
.golden {
  background: var(--gold);
  border-radius: 50%;
  position: relative;
  box-shadow:
    inset -2px -2px 0 rgba(0, 0, 0, 0.25),
    0 0 6px 1px rgba(255, 206, 84, 0.75);
}

.golden::before {
  content: "✦";
  position: absolute;
  left: 15%;
  top: -28%;
  font-size: 90%;
  color: #fff;
}

.golden-fading {
  animation: crumble-blink 0.4s ease-in-out infinite;
}

@keyframes crumble-blink {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

/* Ghost-mode snake: translucent with a pale glow. */
.snake-head.ghost,
.snake-body.ghost {
  opacity: 0.55;
  box-shadow: 0 0 0 2px var(--ghostly), 0 0 6px 2px var(--ghostly);
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.primary-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 0.65rem 1.15rem;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

.btn-primary:hover {
  background: #10614d;
  border-color: #10614d;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.dpad-btn {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
}

.dpad-btn:active {
  background: var(--accent);
  color: #fff;
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
}

/* Hide the on-screen pad and its hint when a fine pointer + keyboard is
   available. */
@media (hover: hover) and (pointer: fine) {
  .dpad {
    display: none;
  }

  .swipe-hint {
    display: none;
  }
}

.swipe-hint {
  margin: 0.25rem 0 0;
  font-weight: 600;
  color: var(--muted);
}

.audio-controls {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.5rem 1.25rem;
  align-items: center;
  width: 100%;
  max-width: 460px;
  padding: 0.75rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.toggle input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--accent);
}

.volume {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 44px;
  justify-content: center;
}

.volume input[type="range"] {
  width: 140px;
  accent-color: var(--accent);
}

.site-footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  margin-top: auto;
}

.site-footer a {
  font-weight: 700;
}

.made-by,
.support {
  margin: 0.35rem 0;
}

.fine-print {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Credits page */
.credits-shell {
  width: 100%;
  max-width: 680px;
  padding: 0.75rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.credits-intro {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.credits-intro h2 {
  margin-top: 0;
}

.credits-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.credits-list > h2 {
  margin: 0.25rem 0 0;
}

.credit-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.credit-entry h3 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.credit-entry dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 1.1rem;
  margin: 0;
}

.credit-entry dt {
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.credit-entry dd {
  margin: 0;
  line-height: 1.6;
}

/* Ko-fi widget accessibility/safety overrides. The widget injects its own
   inline styles; these are more specific/important so they win. */
.kofi-button {
  background-color: #14607f !important;
  min-height: 44px;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

.kofi-button:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 420px) {
  .audio-controls {
    grid-template-columns: 1fr;
  }
}

/* Theme toggle switch */
.theme-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 460px;
  padding: 0.75rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.footer-theme {
  max-width: 340px;
  margin: 0 auto 0.75rem;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  min-height: 44px;
  font-weight: 600;
  font-size: 0.95rem;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  flex: none;
  transition: background-color 0.2s;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch input:focus-visible + .switch-track {
  outline: var(--focus);
  outline-offset: 2px;
}

/* Dark theme tokens */
[data-theme="dark"] {
  --bg: #2b1f2e;
  --surface: #37263a;
  --ink: #ffeaf5;
  --muted: #d9bccf;
  --accent: #5fd6a4;
  --accent-dark: #a9e8c8;
  --berry: #ff8fb8;
  --berry-dark: #ffb6d2;
  --gold: #ffd76a;
  --ice: #7fc9ec;
  --sage: #a5d46a;
  --sage-dark: #7ba84a;
  --tangerine: #ffb27a;
  --tangerine-dark: #d9844f;
  --ghostly: #ded4ff;
  --ghostly-dark: #a493dd;
  --mystery: #c98ce0;
  --mystery-dark: #9a5cb8;
  --board-line: #57405f;
  --cell: #3d2c40;
  --border: #5c4662;
}

[data-theme="dark"] body {
  background: radial-gradient(circle at 20% 10%, #3d2740 0%, #2b1f2e 55%, #1e2b2b 100%);
}

[data-theme="dark"] .btn-primary {
  background: #1f8a6b;
  border-color: #1f8a6b;
  color: #fff;
}

[data-theme="dark"] .btn-primary:hover {
  background: #166b53;
  border-color: #166b53;
}

[data-theme="dark"] .snake-head::before,
[data-theme="dark"] .snake-head::after {
  background: #241d2b;
}

