:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #eef2f8;
  --text: #172033;
  --muted: #637087;
  --border: #dbe4f0;
  --accent: #6d28d9;
  --accent-strong: #4c1d95;
  --accent-soft: rgba(109, 40, 217, 0.14);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}

html[data-theme='dark'] {
  --bg: #070b14;
  --panel: #111827;
  --panel-soft: #172033;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #243041;
  --accent: #a78bfa;
  --accent-strong: #c4b5fd;
  --accent-soft: rgba(167, 139, 250, 0.18);
  --shadow: 0 22px 44px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top, var(--accent-soft), transparent 35%), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button, input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  padding: 0.8rem 1rem;
  cursor: pointer;
}

button.secondary {
  background: var(--panel-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

button.ghost-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.hidden { display: none; }

.topbar {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
}

.topbar p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  max-width: 60ch;
}

.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 1.25rem;
  align-items: start;
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.game-panel {
  padding: 1.2rem;
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.game-header h2,
.sidebar-section h2 {
  margin: 0;
  font-size: 1.1rem;
}

.game-header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.game-mount {
  border-radius: 20px;
  border: 1px dashed var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel-soft) 85%, transparent), color-mix(in srgb, var(--panel) 92%, transparent));
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 420px;
}

.game-mount-large {
  min-height: min(72vh, 720px);
}

.game-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 999;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 0;
  border: none;
}

.game-fullscreen .game-shell,
.game-fullscreen canvas {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.scoreline {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.85rem;
  color: var(--muted);
}

.sidebar {
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.sidebar-section {
  padding: 0.35rem;
}

.game-list {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.game-card {
  padding: 0.95rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.game-card:hover,
.game-card.active {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 10px 24px var(--accent-soft);
}

.game-card h3 {
  margin: 0 0 0.35rem;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.auth-section-bottom {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

#authForm {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

label {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.95rem;
}

input {
  padding: 0.8rem 0.95rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.status {
  min-height: 1.3rem;
  color: var(--muted);
}

.leaderboards {
  display: grid;
  gap: 0.9rem;
}

.leaderboard-card {
  padding: 0.95rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.leaderboard-card ol {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.leaderboard-card li + li {
  margin-top: 0.35rem;
}

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

  .sidebar {
    order: 2;
  }
}

@media (max-width: 640px) {
  .topbar,
  .layout {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-header {
    flex-direction: column;
  }

  .game-header-actions,
  .auth-actions {
    width: 100%;
  }

  .game-header-actions button,
  .auth-actions button,
  #themeToggle {
    flex: 1 1 100%;
  }

  .game-mount-large {
    min-height: 62vh;
  }
}
