:root {
  --bg: #070b16;
  --surface: rgba(15, 22, 42, 0.85);
  --surface-solid: #0f162a;
  --surface-2: rgba(24, 34, 62, 0.78);
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #00f0ff;
  --accent-2: #ff2e93;
  --emerald: #22ff88;
  --amber: #ffb800;
  --radius: 18px;
}

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

body {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  filter: blur(130px);
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  top: -180px;
  left: -120px;
  background: #00f0ff;
}

.bg-glow-2 {
  bottom: -200px;
  right: -120px;
  background: #ff2e93;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(7, 11, 22, 0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(135deg, #00f0ff, #6d28d9);
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.3);
}

.brand-title {
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.04em;
}

.brand-title span {
  color: var(--accent);
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.room-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid rgba(0, 240, 255, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.room-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.25);
}

.room-pill-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.room-pill-code {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 19px;
  color: var(--accent);
  letter-spacing: 0.12em;
}

.room-pill-count {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(34, 255, 136, 0.15);
  color: var(--emerald);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, filter 0.14s ease, background 0.14s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 8px 13px;
  font-size: 13px;
}

.btn-primary {
  background: linear-gradient(135deg, #00f0ff, #3b82f6);
  color: #04101f;
  box-shadow: 0 6px 20px rgba(0, 240, 255, 0.28);
}

.btn-secondary {
  background: linear-gradient(135deg, #ff2e93, #a855f7);
  color: #fff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-play {
  background: linear-gradient(135deg, #22ff88, #00d2ff);
  color: #031510;
  padding: 9px 18px;
  box-shadow: 0 6px 18px rgba(34, 255, 136, 0.25);
}

/* Container */
.container {
  position: relative;
  z-index: 1;
  max-width: 1360px;
  margin: 0 auto;
  padding: 22px 28px 48px;
}

/* Players Dock */
.players-dock {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px dashed rgba(148, 163, 184, 0.25);
  transition: all 0.2s ease;
  position: relative;
}

.player-slot.connected {
  border-style: solid;
  border-color: var(--slot-color, var(--accent));
  background: linear-gradient(135deg, rgba(18, 28, 54, 0.95), rgba(12, 18, 36, 0.95));
  box-shadow: 0 0 22px rgba(0, 240, 255, 0.09);
}

.slot-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--slot-color);
  border: 1px solid color-mix(in srgb, var(--slot-color) 45%, transparent);
  flex-shrink: 0;
}

.player-slot.connected .slot-badge {
  background: var(--slot-color);
  color: #06101f;
  font-size: 20px;
}

.slot-info {
  min-width: 0;
  flex: 1;
}

.slot-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-slot.empty .slot-name {
  color: var(--muted);
  font-weight: 500;
}

.slot-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.acct-pill {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 240, 255, 0.14);
  color: var(--accent);
}

.acct-pill.guest {
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
}

.slot-kick {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.slot-kick:hover {
  background: rgba(239, 68, 68, 0.35);
  color: #fff;
}

/* Connect Banner */
.connect-banner {
  display: grid;
  grid-template-columns: 1.4fr auto;
  gap: 28px;
  align-items: center;
  padding: 26px 30px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(16, 26, 52, 0.92), rgba(20, 14, 44, 0.92));
  border: 1px solid rgba(0, 240, 255, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  margin-bottom: 30px;
}

.pill-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: rgba(0, 240, 255, 0.12);
  border: 1px solid rgba(0, 240, 255, 0.28);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.connect-left h1 {
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.12;
  font-weight: 900;
  margin-bottom: 10px;
}

.connect-desc {
  color: #cbd5e1;
  font-size: 15px;
  line-height: 1.55;
  max-width: 650px;
  margin-bottom: 18px;
}

.connect-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(7, 11, 22, 0.65);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 16px;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent);
  color: #04101f;
  font-weight: 900;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.mono-url {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--emerald);
  word-break: break-all;
}

.big-pin-inline {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--amber);
}

.connect-qr-card {
  background: rgba(7, 11, 22, 0.72);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  text-align: center;
}

.qr-frame {
  width: 176px;
  height: 176px;
  border-radius: 14px;
  background: #fff;
  padding: 8px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
}

.qr-frame img {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-caption span {
  display: block;
  font-weight: 700;
  font-size: 14px;
}

.qr-caption small {
  color: var(--muted);
  font-size: 11px;
}

/* Catalog Section */
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.section-header h2 {
  font-size: 24px;
  font-weight: 800;
}

.section-header p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}

.lobby-hint {
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(255, 184, 0, 0.1);
  border: 1px solid rgba(255, 184, 0, 0.25);
  color: #fde68a;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: rgba(0, 240, 255, 0.45);
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.45);
}

.game-preview-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #050811;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.game-preview-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.game-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 5px 10px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.badge-quiz {
  background: rgba(168, 85, 247, 0.85);
  color: #fff;
}

.badge-pong {
  background: rgba(0, 240, 255, 0.85);
  color: #04101f;
}

.badge-tetris {
  background: rgba(255, 46, 147, 0.85);
  color: #fff;
}

.badge-snake {
  background: rgba(34, 255, 136, 0.88);
  color: #04190d;
}

.players-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(7, 11, 22, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.game-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

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

.game-title-row h3 {
  font-size: 21px;
  font-weight: 800;
}

.ctrl-type {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(0, 240, 255, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
}

.game-body p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
  flex: 1;
}

.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mode-tag {
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
}

/* Stage View */
.stage-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stage-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.stage-hud-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stage-title-wrap h2 {
  font-size: 20px;
  font-weight: 800;
}

.stage-subtitle {
  font-size: 13px;
  color: var(--muted);
}

.game-stage {
  position: relative;
  min-height: 580px;
  border-radius: 24px;
  background: #060913;
  border: 1px solid rgba(0, 240, 255, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-canvas {
  width: 100%;
  height: auto;
  max-height: 76vh;
  display: block;
}

/* Quiz Stage Styles */
.quiz-stage {
  width: 100%;
  height: 100%;
  min-height: 580px;
  padding: 28px 34px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
  background: radial-gradient(circle at top right, rgba(168, 85, 247, 0.16), transparent 55%),
              radial-gradient(circle at bottom left, rgba(0, 240, 255, 0.12), transparent 55%);
}

.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.quiz-progress {
  font-weight: 800;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}

.quiz-timer-ring {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 800;
  color: var(--amber);
  background: rgba(255, 184, 0, 0.12);
  border: 2px solid rgba(255, 184, 0, 0.4);
  padding: 6px 18px;
  border-radius: 14px;
}

.quiz-question-box {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px;
  text-align: center;
}

.quiz-category {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 10px;
}

.quiz-question-text {
  font-size: clamp(22px, 2.6vw, 32px);
  font-weight: 800;
  line-height: 1.28;
}

.quiz-options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-radius: 16px;
  background: rgba(20, 30, 56, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.09);
  font-size: 18px;
  font-weight: 700;
  transition: all 0.2s ease;
}

.quiz-option-key {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 900;
  flex-shrink: 0;
  color: #04101f;
}

.quiz-option.opt-0 .quiz-option-key { background: #ff4757; color: #fff; }
.quiz-option.opt-1 .quiz-option-key { background: #1e90ff; color: #fff; }
.quiz-option.opt-2 .quiz-option-key { background: #ffa502; color: #04101f; }
.quiz-option.opt-3 .quiz-option-key { background: #2ed573; color: #04101f; }

.quiz-option.correct {
  border-color: #22ff88;
  background: rgba(34, 255, 136, 0.18);
  box-shadow: 0 0 28px rgba(34, 255, 136, 0.25);
}

.quiz-option.dimmed {
  opacity: 0.4;
}

.quiz-players-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.quiz-player-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(15, 22, 42, 0.9);
  border: 1px solid var(--border);
}

.quiz-player-chip.answered {
  border-color: var(--accent);
}

/* Game Over Overlay */
.podium-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 18, 0.88);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  z-index: 20;
  text-align: center;
}

.podium-crown {
  font-size: 54px;
  margin-bottom: 8px;
}

.podium-title {
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 6px;
}

.podium-sub {
  color: var(--muted);
  margin-bottom: 22px;
}

.podium-scores {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 26px;
  width: 100%;
  max-width: 760px;
}

.podium-item {
  min-width: 155px;
  padding: 16px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.podium-item.winner {
  border-color: var(--amber);
  box-shadow: 0 0 26px rgba(255, 184, 0, 0.22);
}

.podium-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.78);
  backdrop-filter: blur(8px);
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: #0e1528;
  border: 1px solid rgba(0, 240, 255, 0.28);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.65);
}

.modal-card.modal-wide {
  max-width: 620px;
  text-align: left;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.modal-card h3 {
  font-size: 22px;
  margin-bottom: 8px;
}

.modal-card p {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 18px;
}

.modal-qr-box {
  width: 230px;
  height: 230px;
  background: #fff;
  padding: 12px;
  border-radius: 18px;
  margin: 0 auto 14px;
}

.modal-qr-box img {
  width: 100%;
  height: 100%;
}

.modal-pin-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--amber);
  margin-bottom: 8px;
}

.modal-url-box {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--emerald);
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 12px;
  border-radius: 12px;
  word-break: break-all;
  margin-bottom: 18px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #111a33;
  border: 1px solid rgba(0, 240, 255, 0.35);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1024px) {
  .players-dock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .connect-banner {
    grid-template-columns: 1fr;
  }
  .games-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
  }
  .container {
    padding: 16px;
  }
  .players-dock {
    grid-template-columns: 1fr;
  }
  .quiz-options-grid {
    grid-template-columns: 1fr;
  }
}
