:root {
  --bg: #1a1a2e;
  --panel: #16213e;
  --accent: #32cd32;
  --text: #f5f5f5;
  --muted: #a8b2d1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(circle at top, #243b55, var(--bg));
  color: var(--text);
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

.app-icon {
  display: block;
  margin: 0 auto 0.75rem;
  border-radius: 22%;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(2rem, 5vw, 3rem);
}

header p {
  margin: 0;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  align-items: start;
}

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

.game-shell {
  background: var(--panel);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.game-shell:fullscreen {
  width: 100%;
  height: 100%;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-shadow: none;
}

.game-shell:fullscreen #game {
  max-width: none;
  margin: 0;
}

#game {
  display: block;
  width: 100%;
  max-width: 450px;
  margin: 0 auto;
  border-radius: 8px;
  background: #fff8dc;
  touch-action: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1rem;
}

button {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #0f2f0f;
}

button.secondary {
  background: #4a5568;
  color: white;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.player-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.player-label {
  color: var(--muted);
  font-size: 0.95rem;
}

.username-input {
  width: min(220px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font: inherit;
}

.username-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.score-bar {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.75rem;
  font-weight: 700;
}

.score-status {
  min-height: 1.25rem;
  margin: 0.5rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.leaderboard {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-item,
.leaderboard-empty {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.leaderboard-item.is-current {
  border: 1px solid var(--accent);
}

.leaderboard-rank {
  color: var(--muted);
  font-weight: 700;
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  font-weight: 700;
  color: var(--accent);
}

.leaderboard-empty {
  display: block;
  color: var(--muted);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.text-button {
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.backend-status {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
}

.backend-status.ok {
  color: #7dffb2;
}

.backend-status.warn {
  color: #ffd166;
}

.backend-status.error {
  color: #ff8f8f;
}

.leaderboard-help {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.card p,
.card li {
  color: var(--muted);
  line-height: 1.5;
}

.download-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.download-list a {
  display: block;
  text-decoration: none;
  color: white;
  background: #0f3460;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.download-list a:hover {
  background: #1a4f86;
}

.download-list a.unavailable {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  background: #2d3748;
}

.download-list small {
  display: block;
  color: var(--muted);
  margin-top: 0.25rem;
}

.touch-controls {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.touch-controls button {
  padding: 1rem;
  font-size: 1.25rem;
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}
