:root {
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --bg-tertiary: #2a2a2a;
  --text-primary: #e0e0e0;
  --text-secondary: #aaaaaa;
  --accent: #bb86fc;
  --accent-dark: #9a67cb;
  --snake: #4caf50;
  --food: #ff5252;
  --success: #69f0ae;
  --warning: #ff9100;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  touch-action: manipulation;
  overscroll-behavior-y: none;
  overflow-x: hidden;
  min-height: 100vh;
}

.container {
  max-width: 100%;
  min-height: 100vh;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 15px;
  padding: 0 20px;
}

h1 {
  color: var(--accent);
  font-size: 2.1rem;
  white-space: nowrap;
  letter-spacing: 2px;
}

.wallet-btn {
  background-color: var(--accent-dark);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 600;
  z-index: 10;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  touch-action: manipulation; /* Better touch support */
}

.wallet-btn:active {
  transform: scale(0.95);
}

.wallet-btn.connected {
  background-color: var(--success);
}

.game-area {
  width: 100%;
  max-width: 430px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.canvas-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-secondary);
  border-radius: 14px;
  box-shadow: 0 1px 14px #000a;
  padding: 7px;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #181818;
  border-radius: 10px;
  box-shadow: 0 1px 6px #0006;
}

.score-display {
  width: 100%;
  display: flex;
  justify-content: space-around;
  gap: 20px;
}

.score-box {
  background: var(--bg-tertiary);
  border-radius: 10px;
  padding: 10px 15px;
  text-align: center;
  flex: 1;
  max-width: 150px;
  box-shadow: 0 1px 4px #0003;
}

.score-box span:first-child {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.score-box span:last-child {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--accent);
}

.action-buttons {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 15px;
}

.action-btn {
  background-color: var(--accent);
  color: white;
  border: none;
  padding: 12px 0;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  max-width: 120px;
  transition: all 0.2s;
  box-shadow: 0 1px 4px #0002;
}

.action-btn:active {
  transform: scale(0.96);
}

.action-btn:disabled {
  background-color: #555;
  cursor: not-allowed;
  opacity: 0.7;
}

.mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 10px;
}

.horizontal-controls {
  display: flex;
  gap: 60px;
}

.control-btn {
  background: rgba(187,134,252,0.2);
  color: var(--accent);
  border: 2px solid var(--accent);
  width: 70px;
  height: 70px;
  font-size: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s;
  touch-action: manipulation;
}

.control-btn:active {
  background: rgba(187,134,252,0.4);
  transform: scale(0.97);
}

.wallet-info {
  width: 100%;
  max-width: 400px;
  background: var(--bg-tertiary);
  border-radius: 10px;
  padding: 10px 15px;
  margin: 15px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

#walletAddress {
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--accent);
  word-break: break-word;
  flex: 1;
}

.disconnect-btn {
  background: transparent;
  color: var(--warning);
  border: 1px solid var(--warning);
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.disconnect-btn:active {
  background: rgba(255, 145, 0, 0.09);
}

.toggle-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 8px 15px;
  font-size: 1rem;
  cursor: pointer;
  margin: 10px 0;
}

.leaderboard {
  width: 100%;
  max-width: 400px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 15px;
  margin-top: 10px;
  display: none;
  box-shadow: 0 2px 10px #0003;
  overflow: hidden; /* Prevent content overflow */
}

.leaderboard.show {
  display: block;
}

.leaderboard h2 {
  text-align: center;
  margin-bottom: 15px;
  font-size: 1.3rem;
}

.leaderboard-content {
  max-height: 300px;
  overflow-y: auto;
}

#topScoresList {
  list-style: none;
  width: 100%;
}

#leaderboardTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

#leaderboardTable th {
  text-align: center;
  padding: 8px;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
  font-weight: bold;
}

#leaderboardTable td {
  text-align: center;
  padding: 10px 5px;
  border-bottom: 1px solid #333;
}

.rank-cell {
  font-weight: bold;
  width: 60px;
}

.medal {
  display: inline-block;
  font-size: 1.2em;
  margin-right: 5px;
}

.gold { color: gold; }
.silver { color: silver; }
.bronze { color: #cd7f32; }

.toggle-btn.collapsed::after {
  content: " ▼";
}

.toggle-btn.expanded::after {
  content: " ▲";
}

/* Input field focus styles for wallet interaction */
input:focus, 
button:focus, 
a:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Allow text selection in the leaderboard and wallet sections */
.leaderboard,
.wallet-info,
#walletAddress {
  user-select: text;
}

@media (max-width: 600px) {
  .game-header {
    flex-direction: column;
    gap: 10px;
  }
  h1 {
    font-size: 1.5rem;
  }
  .game-area {
    gap: 15px;
  }
  .mobile-controls {
    display: flex;
  }
  .action-buttons {
    gap: 8px;
  }
  .action-btn {
    padding: 10px 0;
    font-size: 0.9rem;
  }
  .control-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
  }
  .horizontal-controls {
    gap: 50px;
  }
  .canvas-container {
    max-width: 97vw;
  }
  .leaderboard {
    max-width: 90vw;
  }
}