:root {
  --bg: #0f1220;
  --bg-elev: #1a1e33;
  --bg-elev-2: #232847;
  --accent: #ff5a5f;
  --accent-2: #ffd23f;
  --accent-3: #3fd6ff;
  --text: #f4f5fb;
  --text-dim: #9aa0c0;
  --border: #2c3156;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

a { color: inherit; text-decoration: none; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.site-header .brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.site-header .back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

.site-header .player-name {
  font-size: 0.85rem;
  color: var(--text-dim);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 18px 60px;
}

.hero {
  text-align: center;
  padding: 28px 10px 8px;
}

.hero h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  margin: 0 0 8px;
}

.hero p {
  color: var(--text-dim);
  margin: 0;
  font-size: 1rem;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin-top: 28px;
}

.game-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.game-card:active { transform: scale(0.97); }

@media (hover: hover) {
  .game-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--accent);
  }
}

.game-card .icon {
  font-size: 2.4rem;
  line-height: 1;
}

.game-card .name {
  font-weight: 700;
  font-size: 1rem;
}

.game-card .best {
  font-size: 0.78rem;
  color: var(--accent-2);
  min-height: 1em;
}

.game-shell {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px;
}

.game-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.game-title-row h1 {
  font-size: 1.4rem;
  margin: 0;
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.hud .stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
  flex: 1;
  text-align: center;
}

.hud .stat b {
  display: block;
  font-size: 1.15rem;
  color: var(--text);
}

.stage-wrap {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}

canvas {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 100%;
  touch-action: none;
  display: block;
}

.controls-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn {
  background: var(--accent);
  color: #1a1220;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255,90,95,0.35);
}

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

.btn.secondary {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
  margin-top: 16px;
  user-select: none;
}

.dpad button {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1.3rem;
  touch-action: none;
}

.dpad button:active { background: var(--accent); }

.leaderboard {
  margin-top: 22px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.leaderboard h2 {
  font-size: 1rem;
  margin: 0 0 10px;
  color: var(--accent-2);
}

.leaderboard ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
  counter-reset: rank;
}

.leaderboard li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

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

.leaderboard li::before {
  content: counter(rank) ".";
  color: var(--text-dim);
  margin-right: 8px;
  width: 1.4em;
  display: inline-block;
}

.leaderboard .empty {
  color: var(--text-dim);
  font-size: 0.88rem;
  text-align: center;
  padding: 10px 0;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 20, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.overlay.hidden { display: none; }

.overlay-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 22px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.overlay-card h2 { margin: 0 0 8px; }
.overlay-card p { color: var(--text-dim); margin: 0 0 16px; font-size: 0.9rem; }

.overlay-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 14px;
}

.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 30px 16px 40px;
}

.tag-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0 0;
}

.tag {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.tab-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 26px 0 6px;
}

.tab-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: #1a1220;
  border-color: var(--accent);
}

.hidden { display: none !important; }

.gpx-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg-elev-2);
}

.gamepix-status {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
  padding: 16px 0;
}
