.snake-view {
  background:
    radial-gradient(circle at 18% 8%, rgba(57, 126, 99, .24), transparent 34%),
    radial-gradient(circle at 82% 100%, rgba(24, 83, 69, .3), transparent 42%),
    #081711;
}

.snake-layout {
  grid-template-columns: minmax(0, 980px) 290px;
}

.snake-stage {
  border-color: rgba(119, 192, 158, .35);
  background: #06130e;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .32), inset 0 0 40px rgba(89, 174, 136, .06);
}

#snakeCanvas {
  border: 1px solid rgba(138, 207, 176, .15);
  background: #0b211a;
}

.snake-touch-controls {
  display: none;
}

.evolution-card {
  margin: 18px 0 8px;
  padding: 15px;
  border: 1px solid rgba(119, 209, 153, .2);
  background: linear-gradient(135deg, rgba(72, 139, 109, .17), rgba(11, 27, 20, .72));
}

.evolution-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font: 11px/1.4 "Microsoft YaHei", sans-serif;
  color: #8fa79a;
}

.evolution-card-top strong {
  color: #f3d77b;
  font-size: 20px;
  letter-spacing: .12em;
}

.evolution-track {
  height: 5px;
  margin: 12px 0 9px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, .08);
}

.evolution-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #56c58d, #f1cf65);
  box-shadow: 0 0 12px rgba(241, 207, 101, .55);
  transition: width .25s ease;
}

.evolution-card > small {
  display: block;
  color: #9cb1a5;
  font: 11px/1.5 "Microsoft YaHei", sans-serif;
}

.leaderboard strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard strong small {
  display: block;
  margin-top: 3px;
  color: #7f9588;
  font-size: 10px;
  font-weight: 400;
}

.leaderboard li > span:last-child {
  color: #f1d579;
  white-space: nowrap;
}

@media (max-width: 850px) {
  .snake-layout {
    grid-template-columns: 1fr;
  }

  .snake-sidebar {
    display: grid;
    grid-template-columns: minmax(170px, .75fr) minmax(0, 1.25fr);
    gap: 12px;
    align-items: center;
  }

  .snake-sidebar > .eyebrow,
  .snake-sidebar > h2,
  .snake-sidebar > .snake-help {
    display: none;
  }

  .evolution-card {
    margin: 0;
  }

  .leaderboard {
    margin: 0;
  }
}

@media (max-width: 520px) {
  .snake-view {
    padding: 12px 8px;
  }

  .snake-heading {
    margin-bottom: 10px;
  }

  .snake-heading h1 {
    font-size: 24px;
  }

  .snake-sidebar {
    grid-template-columns: 1fr;
  }

  .leaderboard {
    padding-bottom: 2px;
  }

  .leaderboard li {
    min-width: 145px;
  }
}

html.touch-input.snake-playing,
html.touch-input.snake-playing body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html.touch-input .snake-view {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
}

html.touch-input .snake-layout,
html.touch-input .snake-stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
}

html.touch-input #snakeCanvas {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border: 0;
}

html.touch-input .snake-heading {
  position: absolute;
  z-index: 8;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  pointer-events: none;
}

html.touch-input .snake-heading > div {
  display: none;
}

html.touch-input .snake-heading .back-button,
html.touch-input .snake-heading .status-badge {
  pointer-events: auto;
  background: rgba(4, 18, 13, .72);
  border: 1px solid rgba(138, 207, 176, .28);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

html.touch-input .snake-heading .back-button {
  padding: 8px 12px;
}

html.touch-input .snake-sidebar {
  position: absolute;
  z-index: 7;
  top: calc(max(10px, env(safe-area-inset-top)) + 48px);
  left: 50%;
  display: block;
  width: min(210px, 54vw);
  padding: 0;
  border: 0;
  background: transparent;
  transform: translateX(-50%);
  pointer-events: none;
}

html.touch-input .snake-sidebar > .eyebrow,
html.touch-input .snake-sidebar > h2,
html.touch-input .snake-sidebar > .leaderboard,
html.touch-input .snake-sidebar > .snake-help {
  display: none;
}

html.touch-input .evolution-card {
  margin: 0;
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(4, 18, 13, .72);
  backdrop-filter: blur(8px);
}

html.touch-input .evolution-card-top strong {
  font-size: 15px;
}

html.touch-input .evolution-track {
  margin: 5px 0;
  height: 3px;
}

html.touch-input .evolution-card > small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9px;
}

html.touch-input .snake-message {
  z-index: 9;
  top: 43%;
  width: min(280px, 78vw);
  border-radius: 999px;
  text-align: center;
  background: rgba(4, 18, 13, .82);
  backdrop-filter: blur(8px);
}

html.touch-input .snake-touch-controls {
  position: absolute;
  z-index: 11;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: rgba(232, 248, 238, .82);
  font: 10px/1.2 "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

html.touch-input .snake-touch-controls > span {
  padding: 5px 9px;
  border: 1px solid rgba(166, 224, 194, .2);
  border-radius: 999px;
  background: rgba(2, 17, 11, .58);
  box-shadow: 0 5px 16px rgba(0, 0, 0, .18);
  backdrop-filter: blur(7px);
}

.snake-joystick {
  position: relative;
  width: 116px;
  height: 116px;
  overflow: hidden;
  border: 1px solid rgba(190, 239, 212, .38);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(55, 130, 94, .34) 0 12%, transparent 13%),
    radial-gradient(circle at 50% 50%, rgba(8, 37, 25, .72) 0 44%, rgba(3, 21, 14, .84) 45% 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .13),
    inset 0 -12px 28px rgba(0, 0, 0, .34),
    0 12px 34px rgba(0, 0, 0, .38),
    0 0 0 5px rgba(77, 166, 120, .08);
  backdrop-filter: blur(9px);
  touch-action: none;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.snake-joystick::before,
.snake-joystick::after {
  content: '';
  position: absolute;
  pointer-events: none;
}

.snake-joystick::before {
  inset: 14px;
  border: 1px solid rgba(157, 218, 184, .14);
  border-radius: 50%;
}

.snake-joystick::after {
  inset: 50% 12px auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(173, 226, 197, .18), transparent);
  box-shadow: 0 -1px 0 rgba(0, 0, 0, .18);
}

.snake-joystick-compass {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  pointer-events: none;
}

.snake-joystick-compass::before,
.snake-joystick-compass::after {
  content: '';
  position: absolute;
  background: rgba(173, 226, 197, .2);
}

.snake-joystick-compass::before {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
}

.snake-joystick-compass::after {
  top: 50%;
  right: 0;
  left: 0;
  height: 1px;
}

.snake-joystick-knob {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border: 1px solid rgba(224, 255, 237, .58);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 30%, rgba(236, 255, 244, .75) 0 5%, transparent 7%),
    radial-gradient(circle at 42% 38%, #73c89a, #267051 62%, #123b2b 100%);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, .25),
    inset 0 -5px 9px rgba(0, 0, 0, .28),
    0 6px 16px rgba(0, 0, 0, .38),
    0 0 14px rgba(91, 215, 146, .25);
  transform: translate3d(0,0,0);
  transition: transform .15s cubic-bezier(.2,.8,.3,1), box-shadow .18s ease;
  pointer-events: none;
}

.snake-joystick-knob i {
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(224, 255, 237, .34);
  border-radius: 50%;
}

.snake-joystick.active {
  border-color: rgba(171, 244, 205, .72);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .17),
    inset 0 -12px 28px rgba(0, 0, 0, .28),
    0 14px 38px rgba(0, 0, 0, .4),
    0 0 0 6px rgba(74, 190, 127, .14),
    0 0 26px rgba(82, 215, 142, .2);
  transform: scale(1.025);
}

.snake-joystick.active .snake-joystick-knob {
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, .28),
    inset 0 -5px 9px rgba(0, 0, 0, .24),
    0 8px 20px rgba(0, 0, 0, .42),
    0 0 20px rgba(105, 235, 164, .46);
  transition: box-shadow .18s ease;
}

@media (prefers-reduced-motion: reduce) {
  .evolution-track i,
  .snake-joystick,
  .snake-joystick-knob {
    transition: none;
  }
}
