:root {
  --primary-color: #4ade80;
  --secondary-color: #22c55e;
  --accent-color: #f43f5e;
  --bg-color: #f8fafc;
  --text-color: #1e293b;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --canvas-bg: #0f172a;
  --canvas-border: #334155;
  --button-bg: #e2e8f0;
  --button-hover: #cbd5e1;
  --button-text: #1e293b;
  --snake-head: #4ade80;
  --snake-body: #22c55e;
  --food-color: #f43f5e;
  --easy-color: #4ade80;
  --medium-color: #f59e0b;
  --hard-color: #ef4444;
}

[data-theme="dark"] {
  --primary-color: #4ade80;
  --secondary-color: #22c55e;
  --accent-color: #f43f5e;
  --bg-color: #0f172a;
  --text-color: #f8fafc;
  --card-bg: #1e293b;
  --border-color: #334155;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --canvas-bg: #000000;
  --canvas-border: #334155;
  --button-bg: #334155;
  --button-hover: #475569;
  --button-text: #f8fafc;
}

[data-theme="neon"] {
  --primary-color: #39ff14;
  --secondary-color: #00ff00;
  --accent-color: #ff00ff;
  --bg-color: #000000;
  --text-color: #39ff14;
  --card-bg: #0a0a0a;
  --border-color: #39ff14;
  --shadow-color: rgba(57, 255, 20, 0.3);
  --canvas-bg: #000000;
  --canvas-border: #39ff14;
  --button-bg: #0a0a0a;
  --button-hover: #1a1a1a;
  --button-text: #39ff14;
  --snake-head: #39ff14;
  --snake-body: #00ff00;
  --food-color: #ff00ff;
  --easy-color: #39ff14;
  --medium-color: #ffff00;
  --hard-color: #ff00ff;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  position:static
  transition:relativebackground-color 0.3s, color 0.3s;
}

.game-container {
  max-width: 400px;
  width: 100%;
  background-color: var(--card-bg);
  border-radius: 14px;
  box-shadow: 0 8px 20px var(--shadow-color);
  padding: 20px;
  transition: background-color 0.3s, box-shadow 0.3s;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-color);
  transition: color 0.3s;
}

.theme-selector {
  display: flex;
  gap: 6px;
}

.theme-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s;
}

.theme-btn:hover {
  transform: scale(1.1);
}

.theme-btn.active {
  transform: scale(1.2);
  box-shadow: 0 0 0 2px var(--primary-color);
}

.theme-btn.light {
  background-color: #f8fafc;
}

.theme-btn.dark {
  background-color: #0f172a;
}

.theme-btn.neon {
  background-color: #000;
  border-color: #39ff14;
  box-shadow: 0 0 5px #39ff14;
}

/* Settings Bar */
.settings-bar {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.difficulty-selector {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
}

.difficulty-buttons {
  display: flex;
  gap: 4px;
}

.difficulty-btn {
  background-color: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.difficulty-btn:hover {
  background-color: var(--button-hover);
}

.difficulty-btn.active {
  font-weight: 600;
  box-shadow: 0 0 0 2px var(--primary-color);
}

.difficulty-btn[data-difficulty="easy"].active {
  background-color: var(--easy-color);
  color: #fff;
}

.difficulty-btn[data-difficulty="medium"].active {
  background-color: var(--medium-color);
  color: #fff;
}

.difficulty-btn[data-difficulty="hard"].active {
  background-color: var(--hard-color);
  color: #fff;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

canvas {
  width: 100%;
  height: auto;
  background-color: var(--canvas-bg);
  border: 2px solid var(--canvas-border);
  border-radius: 6px;
  display: block;
  transition: background-color 0.3s, border-color 0.3s;
}

.stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.stat-box {
  flex: 1;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
  box-shadow: 0 2px 4px var(--shadow-color);
  transition: background-color 0.3s, border-color 0.3s;
}

.stat-label {
  font-size: 12px;
  color: var(--text-color);
  opacity: 0.8;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-color);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.control-btn {
  background-color: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.control-btn:hover {
  background-color: var(--button-hover);
}

.control-btn:active {
  transform: scale(0.95);
}

.mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.horizontal-controls {
  display: flex;
  gap: 8px;
}

.direction-btn {
  width: 48px;
  height: 48px;
  background-color: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 50%;
  font-size: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.direction-btn:active {
  transform: scale(0.9);
  background-color: var(--primary-color);
  color: white;
}

/* Difficulty Info */
.difficulty-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.info-label {
  font-size: 10px;
  color: var(--text-color);
  opacity: 0.7;
}

.info-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.game-over-modal {
  background-color: var(--card-bg);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  max-width: 90%;
  width: 280px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  animation: modalAppear 0.3s ease-out;
}

.difficulty-tag {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  margin: 8px 0 16px;
}

[data-difficulty="easy"] .difficulty-tag {
  background-color: var(--easy-color);
}

[data-difficulty="medium"] .difficulty-tag {
  background-color: var(--medium-color);
}

[data-difficulty="hard"] .difficulty-tag {
  background-color: var(--hard-color);
}

@keyframes modalAppear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.game-over-modal h2 {
  color: var(--accent-color);
  font-size: 22px;
  margin-bottom: 12px;
}

.game-over-modal p {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text-color);
}

.restart-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.restart-btn:hover {
  background-color: var(--secondary-color);
}

.restart-btn:active {
  transform: scale(0.95);
}

/* Obstacles */
.obstacle {
  position: absolute;
  background-color: var(--accent-color);
  border-radius: 2px;
}

/* Pause button states */
#pauseBtn.paused .pause-icon {
  display: none;
}

#pauseBtn:not(.paused) .play-icon {
  display: none;
}

/* Start Screen Styles */
.start-modal {
  background-color: var(--card-bg);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  max-width: 90%;
  width: 320px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  animation: modalAppear 0.3s ease-out;
}

.start-modal h2 {
  color: var(--primary-color);
  font-size: 28px;
  margin-bottom: 20px;
}

.start-modal h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--text-color);
}

.start-options {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 20px;
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.start-difficulty-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.start-difficulty-btn {
  background-color: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.start-difficulty-btn:hover {
  background-color: var(--button-hover);
}

.start-difficulty-btn.active {
  font-weight: 600;
  box-shadow: 0 0 0 2px var(--primary-color);
}

.start-difficulty-btn[data-difficulty="easy"].active {
  background-color: var(--easy-color);
  color: #fff;
}

.start-difficulty-btn[data-difficulty="medium"].active {
  background-color: var(--medium-color);
  color: #fff;
}

.start-difficulty-btn[data-difficulty="hard"].active {
  background-color: var(--hard-color);
  color: #fff;
}

.difficulty-description {
  min-height: 40px;
  font-size: 12px;
  color: var(--text-color);
  opacity: 0.8;
}

.start-theme-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.start-theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-color);
  font-size: 12px;
}

.theme-preview {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  transition: transform 0.2s;
}

.start-theme-btn:hover .theme-preview {
  transform: scale(1.1);
}

.start-theme-btn.active .theme-preview {
  transform: scale(1.2);
  box-shadow: 0 0 0 2px var(--primary-color);
}

.theme-preview.light {
  background-color: #f8fafc;
}

.theme-preview.dark {
  background-color: #0f172a;
}

.theme-preview.neon {
  background-color: #000;
  border-color: #39ff14;
  box-shadow: 0 0 5px #39ff14;
}

.start-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.start-btn:hover {
  background-color: var(--secondary-color);
}

.start-btn:active {
  transform: scale(0.95);
}

.overlay.active {
  display: flex;
}

/* Media queries for start screen */
@media only screen and (max-width: 320px) {
  .game-container {
    padding: 10px;
    border-radius: 10px;
  }
  
  h1 {
    font-size: 18px;
  }
  
  .theme-selector {
    gap: 4px;
  }
  
  .theme-btn {
    width: 16px;
    height: 16px;
  }
  
  .settings-bar {
    margin-bottom: 8px;
    padding-bottom: 8px;
  }
  
  .difficulty-selector {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .difficulty-buttons {
    width: 100%;
    justify-content: space-between;
  }
  
  .difficulty-btn {
    flex: 1;
    padding: 3px 6px;
    font-size: 10px;
    text-align: center;
  }
  
  .stat-box {
    padding: 5px;
  }
  
  .stat-label {
    font-size: 9px;
    margin-bottom: 2px;
  }
  
  .stat-value {
    font-size: 12px;
  }
  
  .control-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  
  .direction-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  
  .difficulty-info {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  
  .info-item {
    flex-direction: row;
    justify-content: space-between;
    padding: 2px 0;
  }
  
  .game-over-modal {
    padding: 20px;
    width: 280px;
  }
  
  .game-over-modal h2 {
    font-size: 22px;
    margin-bottom: 10px;
  }
  
  .game-over-modal p {
    font-size: 14px;
  }
  
  .restart-btn {
    padding: 8px 16px;
    font-size: 14px;
  }
  
  .start-modal {
    padding: 16px;
    width: 280px;
  }
  
  .start-modal h2 {
    font-size: 22px;
    margin-bottom: 15px;
  }
  
  .start-modal h3 {
    font-size: 14px;
  }
  
  .start-options {
    gap: 15px;
  }
  
  .start-difficulty-btn {
    padding: 6px 12px;
    font-size: 12px;
  }
  
  .difficulty-description {
    font-size: 11px;
  }
  
  .start-btn {
    padding: 10px 20px;
    font-size: 14px;
  }
}

/* Small Devices (phones, 321px to 480px) */
@media only screen and (min-width: 321px) and (max-width: 480px) {
  .game-container {
    padding: 16px;
  }
  
  h1 {
    font-size: 22px;
  }
  
  .difficulty-selector {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .difficulty-buttons {
    width: 100%;
    justify-content: space-between;
  }
  
  .stat-label {
    font-size: 12px;
  }
  
  .stat-value {
    font-size: 16px;
  }
  
  .direction-btn {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  
  .difficulty-info {
    grid-template-columns: 1fr;
  }
  
  .info-item {
    flex-direction: row;
    justify-content: space-between;
  }
}

/* Medium Devices (tablets, 481px to 768px) */
@media only screen and (min-width: 481px) and (max-width: 768px) {
  .game-container {
    padding: 20px;
    max-width: 90%;
  }
  
  .mobile-controls {
    display: flex;
  }
  
  .difficulty-info {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .info-item {
    flex-direction: column;
  }
}

/* Large Devices (desktops, 769px to 1024px) */
@media only screen and (min-width: 769px) and (max-width: 1024px) {
  .game-container {
    max-width: 600px;
    padding: 30px;
  }
  
  h1 {
    font-size: 32px;
  }
  
  .theme-btn {
    width: 28px;
    height: 28px;
  }
  
  .difficulty-btn {
    padding: 8px 16px;
    font-size: 16px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .control-btn {
    padding: 12px 24px;
    font-size: 18px;
  }
}

/* Extra Large Devices (large desktops, 1025px and up) */
@media only screen and (min-width: 1025px) {
  .game-container {
    max-width: 700px;
    padding: 40px;
  }
  
  h1 {
    font-size: 36px;
  }
  
  .theme-btn {
    width: 32px;
    height: 32px;
  }
  
  .difficulty-btn {
    padding: 10px 20px;
    font-size: 16px;
  }
  
  .stat-box {
    padding: 15px;
  }
  
  .stat-label {
    font-size: 16px;
  }
  
  .stat-value {
    font-size: 28px;
  }
  
  .control-btn {
    padding: 15px 30px;
    font-size: 18px;
  }
  
  .info-label {
    font-size: 14px;
  }
  
  .info-value {
    font-size: 16px;
  }
}

/* Portrait and Landscape Orientations */
@media screen and (orientation: portrait) {
  .mobile-controls {
    display: flex;
  }
}

@media screen and (orientation: landscape) and (max-height: 500px) {
  body {
    padding: 10px;
  }
  
  .game-container {
    padding: 15px;
    max-width: 95%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 15px;
    align-items: center;
  }
  
  .header {
    grid-column: 1 / -1;
    margin-bottom: 10px;
  }
  
  .settings-bar {
    grid-column: 1 / -1;
    margin-bottom: 10px;
    padding-bottom: 10px;
  }
  
  .game-area {
    grid-column: 1;
    margin-bottom: 0;
  }
  
  .stats {
    flex-direction: column;
    gap: 5px;
  }
  
  .controls, .mobile-controls, .difficulty-info {
    grid-column: 2;
  }
  
  .mobile-controls {
    display: flex;
  }
  
  .difficulty-info {
    grid-template-columns: 1fr;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }
  
  .info-item {
    flex-direction: row;
    justify-content: space-between;
  }
  
  canvas {
    max-height: 60vh;
    width: auto;
    margin: 0 auto;
  }
  
  .start-modal {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 90%;
    max-width: 500px;
    gap: 15px;
    align-items: center;
  }
  
  .start-modal h2 {
    grid-column: 1 / -1;
    margin-bottom: 10px;
  }
  
  .start-options {
    display: contents;
  }
  
  .start-btn {
    grid-column: 1 / -1;
  }
}

/* High-DPI Screens */
@media only screen and (-webkit-min-device-pixel-ratio: 2),
       only screen and (min-resolution: 192dpi) {
  .game-container {
    box-shadow: 0 10px 30px var(--shadow-color);
  }
  
  canvas {
    border-width: 3px;
  }
}

/* Dark Mode Preference */
@media (prefers-color-scheme: dark) {
  body:not([data-theme]) {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --card-bg: #1e293b;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --canvas-bg: #000000;
    --canvas-border: #334155;
    --button-bg: #334155;
    --button-hover: #475569;
    --button-text: #f8fafc;
  }
}

/* Reduced Motion Preference */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .game-over-modal, .start-modal {
    animation: none;
  }
}

/* Touch Devices */
@media (hover: none) and (pointer: coarse) {
  .mobile-controls {
    display: flex;
  }
  
  .direction-btn {
    width: 65px;
    height: 65px;
  }
  
  .control-btn, .difficulty-btn, .restart-btn, .start-btn {
    padding: 12px 24px;
  }
}

/* Specific Device Adjustments */
/* iPhone SE and other small devices */
@media only screen and (device-width: 375px) and (device-height: 667px) {
  .game-container {
    padding: 15px;
  }
  
  .mobile-controls {
    margin-top: 10px;
  }
  
  .direction-btn {
    width: 48px;
    height: 48px;
  }
}

/* iPad and tablets */
@media only screen and (device-width: 768px) and (device-height: 1024px) {
  .game-container {
    max-width: 80%;
  }
  
  canvas {
    max-height: 60vh;
  }
}

/* Foldable devices in folded state */
@media (max-width: 280px) {
  .game-container {
    padding: 10px;
  }
  
  h1 {
    font-size: 18px;
  }
  
  .difficulty-btn {
    padding: 3px 6px;
    font-size: 11px;
  }
  
  .direction-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  
  .start-modal {
    padding: 12px;
    width: 260px;
  }
  
  .start-modal h2 {
    font-size: 20px;
  }
  
  .start-difficulty-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
}