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

html {
  overscroll-behavior-y: contain;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overscroll-behavior-y: contain;
}

.container {
  background: #1a1a2e;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  max-width: 500px;
  width: 100%;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

h1 {
  color: #00ff88;
  font-size: 2rem;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.scores {
  display: flex;
  gap: 10px;
}

.score-box {
  background: #16213e;
  border-radius: 6px;
  padding: 8px 15px;
  text-align: center;
  border: 1px solid #00ff88;
}

.score-box .label {
  display: block;
  font-size: 0.7rem;
  color: #888;
  text-transform: uppercase;
}

.score-box .value {
  display: block;
  font-size: 1.2rem;
  font-weight: bold;
  color: #fff;
}

.game-wrapper {
  position: relative;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 15px;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4/3;
}

.game-message {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
}

.game-message.active {
  display: flex;
}

.game-message p {
  font-size: 1.5rem;
  font-weight: bold;
  color: #00ff88;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.game-message button {
  background: #00ff88;
  color: #000;
  border: none;
  padding: 12px 30px;
  font-size: 1rem;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.game-message button:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

@media (pointer: coarse) {
  .mobile-controls {
    display: flex;
  }
}

.control-row {
  display: flex;
  gap: 10px;
}

.control-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #16213e;
  border: 2px solid #00ff88;
  color: #00ff88;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
  -webkit-user-select: none;
}

.control-btn:active {
  background: #00ff88;
  color: #000;
}

.actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}

.actions button:hover {
  transform: scale(1.02);
}

.actions button:active {
  transform: scale(0.98);
}

#new-game {
  background: #16213e;
  color: #00ff88;
  border: 1px solid #00ff88;
}

#login-btn {
  background: #00ff88;
  color: #000;
}

#login-btn.logged-in {
  background: #16213e;
  color: #00ff88;
  border: 1px solid #00ff88;
}

.leaderboard {
  background: #16213e;
  border-radius: 6px;
  padding: 15px;
  margin-bottom: 15px;
  position: relative;
}

.leaderboard h3 {
  color: #00ff88;
  margin-bottom: 10px;
  font-size: 1rem;
}

.refresh-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: 1px solid #00ff88;
  color: #00ff88;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

.refresh-btn:hover {
  background: rgba(0, 255, 136, 0.1);
}

.leaderboard ul {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}

.leaderboard li {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #24243e;
  font-size: 0.9rem;
}

.leaderboard li:last-child {
  border-bottom: none;
}

.leaderboard li.loading,
.leaderboard li.empty,
.leaderboard li.error {
  color: #666;
  justify-content: center;
  padding: 20px;
}

.leaderboard .rank {
  width: 30px;
  font-weight: bold;
  color: #00ff88;
}

.leaderboard .player {
  flex: 1;
  font-family: monospace;
  color: #fff;
  text-decoration: none;
  transition: color 0.2s;
}

.leaderboard a.player:hover {
  color: #00ff88;
  text-decoration: underline;
}

.leaderboard .score {
  font-weight: bold;
  color: #fff;
}

footer {
  text-align: center;
  color: #666;
  font-size: 0.8rem;
}

footer a {
  color: #00ff88;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: #1a1a2e;
  border-radius: 12px;
  padding: 30px;
  max-width: 400px;
  width: 90%;
  border: 1px solid #00ff88;
}

.modal-content h2 {
  color: #00ff88;
  margin-bottom: 20px;
  text-align: center;
}

.login-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.login-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 20px;
  background: #16213e;
  border: 1px solid #00ff88;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.login-option:hover {
  background: #24243e;
}

.login-option .icon {
  font-size: 2rem;
}

.login-option .text {
  font-weight: bold;
  color: #fff;
}

.login-option .desc {
  font-size: 0.8rem;
  color: #888;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #666;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #333;
}

.privkey-login {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.privkey-login input {
  padding: 12px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #16213e;
  color: #fff;
  font-size: 1rem;
}

.privkey-login input:focus {
  outline: none;
  border-color: #00ff88;
}

.privkey-login button {
  padding: 12px;
  background: #00ff88;
  color: #000;
  border: none;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
}

.close-modal {
  width: 100%;
  margin-top: 15px;
  padding: 12px;
  background: transparent;
  border: 1px solid #666;
  color: #666;
  border-radius: 6px;
  cursor: pointer;
}

.close-modal:hover {
  border-color: #888;
  color: #888;
}
