.arcade-section {
  padding-top: 2.5rem;
}

.arcade-heading {
  max-width: 780px;
  margin-inline: auto;
}

.snake-game-card {
  position: relative;
  width: min(100%, 760px);
  margin: 1.75rem auto 0;
  padding: clamp(1rem, 3vw, 1.45rem);
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    radial-gradient(
      circle at 12% 0%,
      rgba(0, 229, 255, 0.16),
      transparent 18rem
    ),
    linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 35%),
    rgba(3, 13, 17, 0.82);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.025) inset;
  backdrop-filter: blur(16px);
  contain: layout paint;
}

.snake-game-card::before,
.snake-game-card::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.snake-game-card::before {
  inset: 0;
  border-top: 2px solid rgba(0, 229, 255, 0.66);
  opacity: 0.76;
  box-shadow: 0 -1px 22px rgba(0, 229, 255, 0.38);
}

.snake-game-card::after {
  top: 1rem;
  right: 1rem;
  width: 58px;
  height: 58px;
  border-top: 1px solid rgba(92, 242, 255, 0.34);
  border-right: 1px solid rgba(92, 242, 255, 0.34);
}

.snake-game-header {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.snake-stat,
.snake-action {
  min-height: 44px;
  border: 1px solid rgba(0, 229, 255, 0.28);
  background: rgba(0, 229, 255, 0.055);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.025) inset;
}

.snake-stat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 9rem;
  padding: 0.55rem 0.8rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.snake-stat strong {
  color: var(--cyan-soft);
  font-size: 1.05rem;
  text-shadow: 0 0 12px rgba(0, 229, 255, 0.54);
}

.snake-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 7.5rem;
  padding: 0.55rem 0.9rem;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease;
}

.snake-action:hover,
.snake-action:focus-visible,
.snake-joystick-btn:hover,
.snake-joystick-btn:focus-visible {
  border-color: rgba(0, 229, 255, 0.82);
  background: rgba(0, 229, 255, 0.11);
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.22);
  outline: none;
}

.snake-action:hover,
.snake-action:focus-visible {
  transform: translateY(-2px);
}

.snake-action:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.snake-action.is-awaiting-action {
  border-color: rgba(124, 247, 255, 0.78);
  animation: snake-start-float 1800ms ease-in-out infinite;
}

.snake-difficulty {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 0.7rem;
  width: min(100%, 520px);
  margin: 0 auto 1rem;
  padding: 0.85rem;
  border: 1px solid rgba(0, 229, 255, 0.22);
  background:
    linear-gradient(
      90deg,
      rgba(0, 229, 255, 0.08),
      transparent 48%,
      rgba(0, 140, 255, 0.08)
    ),
    rgba(0, 229, 255, 0.045);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.025) inset,
    0 0 20px rgba(0, 229, 255, 0.12);
}

.snake-difficulty-topline,
.snake-difficulty-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.snake-difficulty-topline label,
#snakeDifficultyValue {
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.snake-difficulty-topline label {
  color: var(--muted);
}

#snakeDifficultyValue {
  color: var(--cyan-soft);
  text-align: right;
  text-shadow: 0 0 12px rgba(0, 229, 255, 0.42);
}

.snake-difficulty-range {
  width: 100%;
  height: 34px;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
  touch-action: pan-x;
  background: transparent;
}

.snake-difficulty-range:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

.snake-difficulty-range::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid rgba(0, 229, 255, 0.36);
  background:
    linear-gradient(90deg, rgba(0, 229, 255, 0.24), rgba(92, 242, 255, 0.42)),
    rgba(0, 10, 14, 0.86);
  box-shadow:
    0 0 16px rgba(0, 229, 255, 0.2),
    inset 0 0 10px rgba(0, 229, 255, 0.12);
}

.snake-difficulty-range::-webkit-slider-thumb {
  width: 28px;
  height: 28px;
  margin-top: -11px;
  border: 1px solid rgba(247, 255, 255, 0.86);
  border-radius: 0;
  appearance: none;
  background: linear-gradient(135deg, var(--cyan), #7af7ff);
  box-shadow:
    0 0 18px rgba(0, 229, 255, 0.62),
    0 0 0 4px rgba(0, 229, 255, 0.12);
}

.snake-difficulty-range::-moz-range-track {
  height: 8px;
  border: 1px solid rgba(0, 229, 255, 0.36);
  background:
    linear-gradient(90deg, rgba(0, 229, 255, 0.24), rgba(92, 242, 255, 0.42)),
    rgba(0, 10, 14, 0.86);
  box-shadow:
    0 0 16px rgba(0, 229, 255, 0.2),
    inset 0 0 10px rgba(0, 229, 255, 0.12);
}

.snake-difficulty-range::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(247, 255, 255, 0.86);
  border-radius: 0;
  background: linear-gradient(135deg, var(--cyan), #7af7ff);
  box-shadow:
    0 0 18px rgba(0, 229, 255, 0.62),
    0 0 0 4px rgba(0, 229, 255, 0.12);
}

.snake-difficulty-labels {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.3;
}

.snake-difficulty-labels span:nth-child(2) {
  color: var(--cyan-soft);
}

@keyframes snake-start-float {
  0%,
  100% {
    background: rgba(0, 229, 255, 0.075);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.025) inset,
      0 0 16px rgba(0, 229, 255, 0.16);
    transform: translateY(0);
  }

  50% {
    background: rgba(0, 229, 255, 0.14);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.04) inset,
      0 0 28px rgba(0, 229, 255, 0.36),
      0 0 46px rgba(0, 140, 255, 0.16);
    transform: translateY(-4px);
  }
}

.snake-canvas-shell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: min(100%, 520px);
  margin-inline: auto;
  padding: clamp(0.55rem, 2vw, 0.8rem);
  border: 1px solid rgba(0, 229, 255, 0.26);
  background:
    linear-gradient(rgba(0, 229, 255, 0.065) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.045) 1px, transparent 1px),
    rgba(1, 6, 9, 0.88);
  background-size: 32px 32px;
  box-shadow:
    0 0 32px rgba(0, 229, 255, 0.16),
    inset 0 0 30px rgba(0, 229, 255, 0.055);
}

#snakeCanvas {
  display: block;
  width: min(100%, 480px);
  max-width: 100%;
  aspect-ratio: 1;
  height: auto;
  border: 1px solid rgba(0, 229, 255, 0.42);
  background: #010405;
  box-shadow:
    0 0 24px rgba(0, 229, 255, 0.22),
    inset 0 0 34px rgba(0, 229, 255, 0.07);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#snakeCanvas:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

.snake-countdown {
  position: absolute;
  inset: clamp(0.55rem, 2vw, 0.8rem);
  z-index: 2;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #7cf7ff;
  font-size: clamp(5rem, 18vw, 9.5rem);
  font-weight: 950;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  text-shadow:
    0 0 12px rgba(124, 247, 255, 0.95),
    0 0 32px rgba(0, 229, 255, 0.72),
    0 0 52px rgba(0, 229, 255, 0.4);
  transform: scale(0.86);
}

.snake-countdown::before,
.snake-countdown::after {
  position: absolute;
  top: 50%;
  left: 50%;
  content: attr(data-count);
  opacity: 0;
  pointer-events: none;
  text-shadow:
    0 0 10px rgba(255, 43, 214, 0.9),
    0 0 28px rgba(255, 0, 204, 0.58);
}

.snake-countdown::before {
  color: #ff2bd6;
  transform: translate(-53%, -50%);
}

.snake-countdown::after {
  color: rgba(247, 255, 255, 0.88);
  transform: translate(-47%, -50%);
}

.snake-countdown.is-visible {
  animation: snake-countdown-pop 840ms ease both;
}

.snake-countdown.is-visible::before {
  animation: snake-countdown-glitch 840ms steps(2, end) both;
}

.snake-countdown.is-visible::after {
  animation: snake-countdown-glitch-alt 840ms steps(2, end) both;
}

@keyframes snake-countdown-pop {
  0% {
    opacity: 0;
    transform: scale(0.78);
  }

  16% {
    opacity: 1;
    transform: scale(1);
  }

  70% {
    opacity: 1;
    transform: scale(1.09);
  }

  100% {
    opacity: 0;
    transform: scale(1.22);
  }
}

@keyframes snake-countdown-glitch {
  0%,
  12%,
  100% {
    opacity: 0;
  }

  18%,
  26%,
  58%,
  66% {
    opacity: 0.72;
  }
}

@keyframes snake-countdown-glitch-alt {
  0%,
  18%,
  100% {
    opacity: 0;
  }

  24%,
  34%,
  62% {
    opacity: 0.34;
  }
}

.snake-help,
.snake-message {
  position: relative;
  z-index: 1;
  max-width: 540px;
  margin: 0.9rem auto 0;
  color: var(--muted);
  text-align: center;
}

.snake-help {
  font-size: 0.92rem;
}

.snake-help-mobile {
  display: none;
}

.snake-message {
  min-height: 1.6rem;
  color: var(--cyan-soft);
  font-size: 0.96rem;
  font-weight: 850;
  text-shadow: 0 0 14px rgba(0, 229, 255, 0.42);
}

.snake-joystick {
  position: relative;
  z-index: 1;
  display: none;
  grid-template-columns: repeat(3, minmax(56px, 72px));
  grid-template-rows: repeat(2, minmax(52px, 64px));
  justify-content: center;
  gap: 0.55rem;
  width: min(100%, 260px);
  margin: 1rem auto 0;
}

.snake-joystick-btn {
  min-width: 56px;
  min-height: 52px;
  color: var(--cyan-soft);
  border: 1px solid rgba(0, 229, 255, 0.34);
  background: rgba(0, 229, 255, 0.07);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.025) inset,
    0 0 18px rgba(0, 229, 255, 0.12);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 950;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
}

.snake-joystick-btn[data-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}

.snake-joystick-btn[data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.snake-joystick-btn[data-dir="down"] {
  grid-column: 2;
  grid-row: 2;
}

.snake-joystick-btn[data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

@media (max-width: 820px), (hover: none), (pointer: coarse) {
  .arcade-section {
    padding-top: 2rem;
  }

  .snake-game-card {
    width: min(100%, 32rem);
  }

  .snake-game-header {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .snake-stat,
  .snake-action {
    width: 100%;
    min-width: 0;
  }

  .snake-help-desktop {
    display: none;
  }

  .snake-help-mobile,
  .snake-joystick {
    display: grid;
  }

  .snake-help-mobile {
    display: block;
  }
}

@media (max-width: 430px) {
  .snake-game-card {
    padding: 0.85rem;
  }

  .snake-game-header {
    gap: 0.5rem;
  }

  .snake-stat,
  .snake-action {
    padding-inline: 0.55rem;
    font-size: 0.82rem;
  }

  .snake-difficulty {
    padding: 0.75rem;
  }

  .snake-difficulty-topline,
  .snake-difficulty-labels {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
  }

  #snakeDifficultyValue {
    text-align: left;
  }

  .snake-difficulty-labels {
    font-size: 0.68rem;
  }

  .snake-canvas-shell {
    padding: 0.45rem;
  }

  .snake-help,
  .snake-message {
    font-size: 0.86rem;
  }
}

@media (max-width: 340px) {
  .snake-game-header {
    grid-template-columns: 1fr;
  }

  .snake-difficulty-topline label,
  #snakeDifficultyValue {
    font-size: 0.7rem;
  }

  .snake-joystick {
    grid-template-columns: repeat(3, minmax(50px, 1fr));
    width: min(100%, 210px);
  }

  .snake-joystick-btn {
    min-width: 50px;
    min-height: 50px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .snake-action,
  .snake-joystick-btn {
    transition-duration: 0.01ms;
  }

  .snake-action.is-awaiting-action {
    animation: none;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.025) inset,
      0 0 24px rgba(0, 229, 255, 0.24);
  }

  .snake-countdown,
  .snake-countdown.is-visible,
  .snake-countdown.is-visible::before,
  .snake-countdown.is-visible::after {
    animation-duration: 0.01ms;
  }
}
