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

:root {
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --gold-gradient: linear-gradient(90deg, #ffd89b 0%, #19547b 100%);
  --snake-color: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
  --snake-head: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
  --food-color: #ff3366;
  --bg-dark: #0a0e27;
  --board-bg: #151932;
  --glow-green: 0 0 12px rgba(74, 222, 128, 0.4);
  --glow-cyan: 0 0 15px rgba(96, 165, 250, 0.5);
  --glow-pink: 0 0 20px rgba(255, 51, 102, 0.6);
}

body {
  font-family: 'Orbitron', sans-serif;
  background: var(--bg-dark);
  background-image: 
    radial-gradient(ellipse at top, rgba(102, 126, 234, 0.15), transparent 50%),
    radial-gradient(ellipse at bottom, rgba(118, 75, 162, 0.15), transparent 50%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  padding: 20px 0;
}

.game-container {
  max-width: 820px;
  width: 95vw;
  padding: 20px;
  background: rgba(21, 25, 50, 0.8);
  backdrop-filter: blur(10px);
  border-radius: 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
              0 0 0 1px rgba(255, 255, 255, 0.1);
  animation: containerFadeIn 0.8s ease-out;
}

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

.header {
  text-align: center;
  margin-bottom: 20px;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 900;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 10px;
  animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { 
    filter: brightness(1) drop-shadow(0 0 10px rgba(255, 216, 155, 0.5)); 
  }
  50% { 
    filter: brightness(1.3) drop-shadow(0 0 20px rgba(255, 216, 155, 0.8)); 
  }
}

.score-board {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 15px 20px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.main-content {
  display: flex;
  gap: 20px;
  margin-top: 20px;
  align-items: flex-start;
}

.game-section {
  flex: 1 1 auto;
}

.side-panel {
  flex: 0 0 190px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 14px 16px 16px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.panel-title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.8;
  margin-bottom: 10px;
}

.difficulty-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.difficulty-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.9rem;
}

.difficulty-option input[type="radio"] {
  accent-color: #4ade80;
}

.difficulty-option:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.difficulty-info {
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.difficulty-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
  margin-bottom: 4px;
}

.difficulty-speed {
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.score-item {
  text-align: center;
}

.score-label {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-value {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: transform 0.2s;
}

.score-value.pulse {
  animation: scorePulse 0.3s ease-out;
}

@keyframes scorePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

.game-board-wrapper {
  position: relative;
  width: 100%;
  padding-top: 100%;
  background: var(--board-bg);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 
    inset 0 0 60px rgba(0, 0, 0, 0.5),
    0 10px 40px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.05);
}

#gameBoard {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  grid-template-rows: repeat(20, 1fr);
  gap: 1px;
}

.snake-segment {
  background: var(--snake-color);
  border-radius: 5px;
  box-shadow: var(--glow-green);
  /* Keep segments steady to avoid blinking */
  transition: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.snake-segment.head {
  background: var(--snake-head);
  box-shadow: var(--glow-cyan);
  border-radius: 7px;
  position: relative;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Enhanced mobile snake visibility */
@media (max-width: 600px) {
  .snake-segment {
    box-shadow: 0 0 16px rgba(74, 222, 128, 0.6),
                inset 0 0 8px rgba(255, 255, 255, 0.2);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
  }

  .snake-segment.head {
    box-shadow: 0 0 20px rgba(96, 165, 250, 0.8),
                inset 0 0 10px rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
  }
}

@keyframes snakeAppear {
  from {
    transform: scale(0.5);
    opacity: 0.5;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.food {
  background: #ff3366 !important;
  border-radius: 50%;
  box-shadow: 0 0 12px 4px #ff3366cc;
  border: 4px solid #fff !important;
  width: 90%;
  height: 90%;
  min-width: 18px;
  min-height: 18px;
  max-width: 100%;
  max-height: 100%;
  margin: 5%;
  position: relative;
  z-index: 10;
}

/* Enhanced mobile food visibility */
@media (max-width: 600px) {
  .food {
    box-shadow: 0 0 20px 6px rgba(255, 51, 102, 0.9);
    border: 3px solid #fff !important;
    animation: foodMobilePulse 1.2s ease-in-out infinite;
  }

  @keyframes foodMobilePulse {
    0%, 100% {
      transform: scale(1);
      box-shadow: 0 0 20px 6px rgba(255, 51, 102, 0.9);
    }
    50% {
      transform: scale(1.1);
      box-shadow: 0 0 25px 8px rgba(255, 51, 102, 1);
    }
  }
}

.food::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  background: inherit;
  border-radius: 50%;
  animation: foodPulse 1.5s ease-in-out infinite;
  z-index: -1;
}

@keyframes foodAppear {
  from {
    transform: scale(0) rotate(0deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(360deg);
    opacity: 1;
  }
}

@keyframes foodPulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.8;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.3);
    opacity: 0.3;
  }
}

.game-over-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 14, 39, 0.95);
  backdrop-filter: blur(10px);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 20px;
  z-index: 100;
  animation: overlayFadeIn 0.5s ease-out;
}

.game-over-overlay.show {
  display: flex;
}

@keyframes overlayFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.game-over-title {
  font-size: 2.5rem;
  font-weight: 900;
  background: var(--secondary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 20px;
  animation: gameOverShake 0.5s ease-out;
}

@keyframes gameOverShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

.final-score {
  font-size: 1.5rem;
  margin-bottom: 30px;
  opacity: 0.9;
}

.btn {
  padding: 15px 40px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: 'Orbitron', sans-serif;
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
  transition: all 0.3s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 40px rgba(102, 126, 234, 0.6);
}

.btn:active {
  transform: translateY(-1px);
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.controls-hint {
  text-align: center;
  margin-top: 16px;
  opacity: 0.6;
  font-size: 0.85rem;
  line-height: 1.6;
}

.controls-hint span {
  display: inline-block;
  margin: 5px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* D-Pad Controls */
.dpad-container {
  display: none;
  position: relative;
  width: 140px;
  height: 140px;
  margin: 16px auto 0;
}

.dpad-btn {
  position: absolute;
  width: 45px;
  height: 45px;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.5), rgba(118, 75, 162, 0.5));
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.1s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
  transform: scale(0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.7), rgba(147, 51, 234, 0.7));
}

.dpad-up {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.dpad-down {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.dpad-left {
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.dpad-right {
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}

.dpad-center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 35px;
  height: 35px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  cursor: default;
  pointer-events: none;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

@media (max-width: 600px) {
  body {
    align-items: flex-start;
    padding: 5px;
  }

  .game-container {
    width: 100%;
    max-width: 100vw;
    margin: 0;
    border-radius: 16px;
    padding: 10px 8px 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.7),
                0 0 0 1px rgba(102, 126, 234, 0.3);
    background: radial-gradient(circle at top, rgba(102, 126, 234, 0.4), transparent 60%),
                radial-gradient(circle at bottom, rgba(118, 75, 162, 0.25), transparent 70%),
                rgba(18, 22, 45, 0.95);
    backdrop-filter: blur(12px);
  }

  .header {
    margin-bottom: 8px;
  }

  .main-content {
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
  }

  .side-panel {
    width: 100%;
    border-radius: 14px;
    padding: 12px 14px 14px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
    background: radial-gradient(circle at top left, rgba(96, 165, 250, 0.28), transparent 65%),
                linear-gradient(135deg, rgba(102, 126, 234, 0.15), rgba(118, 75, 162, 0.15)),
                rgba(8, 10, 30, 0.95);
    border: 1px solid rgba(102, 126, 234, 0.25);
  }

  .panel-title {
    font-size: 0.85rem;
    margin-bottom: 8px;
  }

  .difficulty-options {
    gap: 6px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: 1.3rem;
    letter-spacing: 1px;
    filter: drop-shadow(0 0 15px rgba(255, 216, 155, 0.6));
    margin-bottom: 5px;
  }

  .score-board {
    padding: 8px 12px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(102, 126, 234, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .score-label {
    font-size: 0.7rem;
    margin-bottom: 3px;
  }

  .score-value {
    font-size: 1.1rem;
  }

  .controls-hint {
    font-size: 0.7rem;
    margin-top: 8px;
  }

  .controls-hint div {
    display: inline;
    margin: 0 3px;
  }

  .controls-hint span {
    padding: 3px 6px;
    margin: 2px;
  }

  .dpad-container {
    display: block;
    width: 130px;
    height: 130px;
    margin: 12px auto 0;
  }

  .dpad-btn {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }

  .dpad-center {
    width: 32px;
    height: 32px;
  }

  .game-board-wrapper {
    border-radius: 18px;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.7),
                0 12px 30px rgba(0, 0, 0, 0.6),
                0 0 0 2px rgba(102, 126, 234, 0.2);
  }

  .game-over-title {
    font-size: 2rem;
  }

  .btn {
    display: block;
    width: 100%;
    padding: 14px 0;
    font-size: 1.05rem;
    text-align: center;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
  }

  .btn:active {
    transform: scale(0.97);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.6);
  }

  .difficulty-option {
    padding: 8px 10px;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
  }

  .difficulty-label {
    font-size: 0.7rem;
  }

  .difficulty-speed {
    font-size: 1rem;
  }

  .difficulty-option:has(input:checked) {
    background: rgba(74, 222, 128, 0.15);
    border-color: rgba(74, 222, 128, 0.4);
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.3);
  }

  .difficulty-option:active {
    transform: scale(0.98);
  }
}

@media (max-width: 400px) {
  .dpad-container {
    width: 120px;
    height: 120px;
    margin: 10px auto 0;
  }

  .dpad-btn {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }

  .dpad-center {
    width: 28px;
    height: 28px;
  }

  h1 {
    font-size: 1.4rem;
    letter-spacing: 1px;
  }

  .game-over-title {
    font-size: 1.6rem;
  }

  .score-label {
    font-size: 0.75rem;
  }

  .difficulty-option {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .game-container {
    padding: 14px;
  }
}

/* Landscape mobile: make the game fill the screen for easier play */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    align-items: stretch;
    padding: 0;
  }

  .game-container {
    width: 100vw;
    max-width: 100vw;
    min-height: 100vh;
    border-radius: 0;
    margin: 0;
    padding: 8px 10px 10px;
    box-shadow: none;
  }

  .header {
    margin-bottom: 6px;
  }

  h1 {
    font-size: 1.1rem;
    letter-spacing: 0.5px;
  }

  .score-board {
    margin-bottom: 8px;
    padding: 8px 10px;
  }

  .main-content {
    flex-direction: row;
    gap: 10px;
    margin-top: 8px;
  }

  .game-section {
    flex: 1 1 auto;
  }

  .game-board-wrapper {
    height: calc(100vh - 110px);
    padding-top: 0;
  }

  .side-panel {
    flex: 0 0 170px;
  }

  .controls-hint {
    font-size: 0.7rem;
    margin-top: 6px;
  }
}
