/* ═══════════════════════════════════════════════════
   PyLab — Design System
   ═══════════════════════════════════════════════════ */
:root {
  --bg:         #0d1117;
  --bg2:        #161b22;
  --bg3:        #21262d;
  --border:     #30363d;
  --text:       #e6edf3;
  --muted:      #8b949e;
  --dim:        #6e7681;

  --green:      #3fb950;
  --blue:       #58a6ff;
  --purple:     #bc8cff;
  --gold:       #e3b341;
  --red:        #f85149;
  --teal:       #39d3c3;

  --t1: #3fb950;   /* Nucleotide */
  --t2: #58a6ff;   /* Amino Acid */
  --t3: #bc8cff;   /* Organelle  */
  --t4: #e3b341;   /* Organism   */
  --t5: #f85149;   /* Ecosystem  */

  --radius: 8px;
  --sidebar-w: 270px;
  --lb-w: 280px;
}

/* ─── Light theme ───────────────────────────────────
   Overrides the design tokens; everything else inherits. */
:root[data-theme="light"] {
  --bg:         #ffffff;
  --bg2:        #f6f8fa;
  --bg3:        #eaeef2;
  --border:     #d0d7de;
  --text:       #1f2328;
  --muted:      #656d76;
  --dim:        #8c959f;

  --green:      #1a7f37;
  --blue:       #0969da;
  --purple:     #8250df;
  --gold:       #9a6700;
  --red:        #cf222e;
  --teal:       #1b7c83;

  --t1: #1a7f37;
  --t2: #0969da;
  --t3: #8250df;
  --t4: #9a6700;
  --t5: #cf222e;
}

/* Smooth the flip between themes */
body, .topbar, .challenge-sidebar, .lb-sidebar, .main-panel,
.sidebar-section-hdr, .btn {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

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

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: #2d333b; border-color: #58a6ff55; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover { background: #46d058; border-color: #46d058; }

.btn-danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.btn-danger:hover { background: #ff6159; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: var(--bg3); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ─── Tags ──────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.tag-t1 { background: #3fb95022; color: var(--t1); border: 1px solid #3fb95044; }
.tag-t2 { background: #58a6ff22; color: var(--t2); border: 1px solid #58a6ff44; }
.tag-t3 { background: #bc8cff22; color: var(--t3); border: 1px solid #bc8cff44; }
.tag-t4 { background: #e3b34122; color: var(--t4); border: 1px solid #e3b34144; }
.tag-t5 { background: #f8514922; color: var(--t5); border: 1px solid #f8514944; }

/* ─── XP badge ──────────────────────────────────── */
.xp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e3b34122;
  color: var(--gold);
  border: 1px solid #e3b34144;
}

/* ═══════════════════════════════════════════════════
   LANDING PAGE
   ═══════════════════════════════════════════════════ */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Hero ──────────────────────────────────────── */
.hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  background:
    radial-gradient(ellipse 80% 50% at 20% 40%, #3fb95010 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 60%, #58a6ff10 0%, transparent 60%),
    var(--bg);
  position: relative;
  overflow: hidden;
}

/* animated DNA helix background */
.dna-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.dna-strand {
  position: absolute;
  width: 2px;
  background: linear-gradient(to bottom, transparent, #3fb95030, transparent);
  animation: dnaFloat 8s ease-in-out infinite;
}
.dna-strand:nth-child(1)  { left: 5%;  height: 200px; top: 10%; animation-delay: 0s;   }
.dna-strand:nth-child(2)  { left: 12%; height: 160px; top: 50%; animation-delay: 1.2s; }
.dna-strand:nth-child(3)  { left: 88%; height: 180px; top: 20%; animation-delay: 0.6s; }
.dna-strand:nth-child(4)  { left: 93%; height: 220px; top: 60%; animation-delay: 1.8s; }
.dna-strand:nth-child(5)  { left: 50%; height: 140px; top: 5%;  animation-delay: 2.4s; }

@keyframes dnaFloat {
  0%, 100% { transform: translateY(0) scaleX(1); opacity: 0.4; }
  50%       { transform: translateY(-20px) scaleX(-1); opacity: 0.8; }
}

.hero-content {
  max-width: 520px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.hero-logo {
  font-size: 4rem;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px #3fb95060);
}

.hero-title {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #3fb950, #58a6ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.hero-subtitle {
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 40px;
  line-height: 1.6;
}

/* ─── Registration card ─────────────────────────── */
.register-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: left;
}

.register-card h2 {
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: var(--text);
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--green);
}
.form-group input::placeholder { color: var(--dim); }

/* avatar selector */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.avatar-opt {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
.avatar-opt:hover { background: var(--bg3); border-color: var(--muted); }
.avatar-opt.selected { border-color: var(--green); background: #3fb95015; }

/* ─── Feature strip ─────────────────────────────── */
.features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 40px 48px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
}
.feature-card {
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
}
.feature-icon { font-size: 1.8rem; margin-bottom: 8px; }
.feature-card h3 { font-size: 0.95rem; margin-bottom: 4px; color: var(--text); }
.feature-card p  { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }

/* ═══════════════════════════════════════════════════
   GAME PAGE
   ═══════════════════════════════════════════════════ */
.game-page {
  display: grid;
  grid-template-rows: 54px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ─── Top navbar ────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
  letter-spacing: -0.02em;
}
.topbar-logo span { color: var(--muted); font-weight: 400; }

.topbar-player {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 8px;
}
.topbar-avatar { font-size: 1.4rem; line-height: 1; }
.topbar-name { font-weight: 600; font-size: 0.9rem; }
.topbar-level {
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 600;
}

.topbar-xp {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 4px;
  flex: 1;
  max-width: 280px;
}
.xp-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), #46d058);
  border-radius: 3px;
  transition: width 0.6s ease;
}
.xp-label { font-size: 0.78rem; color: var(--gold); font-weight: 600; white-space: nowrap; }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ─── Main layout ───────────────────────────────── */
.game-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--lb-w);
  overflow: hidden;
  transition: grid-template-columns 0.22s ease;
}

/* ─── Hideable side panels ──────────────────────── */
.game-body.hide-left  { grid-template-columns: 0 1fr var(--lb-w); }
.game-body.hide-right { grid-template-columns: var(--sidebar-w) 1fr 0; }
.game-body.hide-left.hide-right { grid-template-columns: 0 1fr 0; }

.game-body.hide-left  .challenge-sidebar,
.game-body.hide-right .lb-sidebar {
  width: 0;
  min-width: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* Panel toggle buttons */
.panel-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 0.95rem;
  line-height: 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.panel-toggle:hover { color: var(--text); border-color: #58a6ff55; }
.panel-toggle.active { color: var(--blue); border-color: #58a6ff55; background: #58a6ff15; }

/* ─── Challenge sidebar ─────────────────────────── */
.challenge-sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
}

/* ─── Collapsible sidebar sections ──────────────── */
.sidebar-section {
  border-bottom: 1px solid var(--border);
}

.sidebar-section-hdr {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px 8px;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 1;
  transition: background 0.12s;
}
.sidebar-section-hdr:hover { background: var(--bg3); }

.sidebar-section-title {
  flex: 1;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-section-count {
  font-size: 0.65rem;
  background: var(--bg3);
  color: var(--dim);
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.sidebar-section-chevron {
  width: 14px;
  height: 14px;
  border-right: 2px solid var(--dim);
  border-bottom: 2px solid var(--dim);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-right: 2px;
}
.sidebar-section-chevron.open {
  transform: rotate(-135deg);
}

.sidebar-section-body {
  overflow: hidden;
  padding: 6px 6px 4px;
}
.sidebar-section-body.collapsed {
  display: none;
}

.challenge-list {
  /* body is now .sidebar-section-body — keep this for compatibility */
}

/* ─── Example items ──────────────────────────────── */
.example-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}
.example-item:hover { background: var(--bg3); }
.example-item.active {
  background: #58a6ff15;
  border-color: #58a6ff40;
}
.example-item .ci-xp { color: var(--blue); }

/* ─── Example mode banner ────────────────────────── */
.example-mode-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #58a6ff10;
  border: 1px solid #58a6ff40;
  border-radius: var(--radius);
  margin-bottom: 14px;
  color: var(--blue);
  font-size: 0.85rem;
  font-weight: 600;
}

.tag-example {
  background: #58a6ff20;
  color: var(--blue);
  border: 1px solid #58a6ff44;
}

/* ─── Project (mini-project) items ──────────────── */
.project-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}
.project-item:hover { background: var(--bg3); }
.project-item.active {
  background: #e3b34115;
  border-color: #e3b34140;
}
.project-item .ci-xp { color: var(--gold); }

/* ─── Project mode banner ────────────────────────── */
.project-mode-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.82rem;
  font-weight: 500;
  background: #e3b34110;
  border: 1px solid #e3b34140;
  color: var(--gold);
}

.tag-project {
  background: #e3b34120;
  color: var(--gold);
  border: 1px solid #e3b34144;
}

.tier-group { margin-bottom: 4px; }

.tier-label {
  padding: 6px 10px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tier-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.challenge-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}
.challenge-item:hover { background: var(--bg3); }
.challenge-item.active {
  background: #3fb95015;
  border-color: #3fb95040;
}
.challenge-item.completed { opacity: 0.65; }
.challenge-item.completed .ci-icon::after {
  content: '✓';
  position: absolute;
  bottom: -3px;
  right: -3px;
  font-size: 0.55rem;
  background: var(--green);
  color: #000;
  border-radius: 50%;
  width: 12px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ci-icon {
  font-size: 1.2rem;
  position: relative;
  flex-shrink: 0;
}
.ci-info { flex: 1; min-width: 0; }
.ci-title {
  font-size: 0.84rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ci-xp { font-size: 0.7rem; color: var(--gold); font-weight: 600; }

/* ─── Main panel ────────────────────────────────── */
.main-panel {
  display: grid;
  grid-template-rows: 1fr 1fr;
  overflow: hidden;
  background: var(--bg);
}

.panel-top {
  display: grid;
  grid-template-columns: 380px 1fr;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.description-pane {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
}

.challenge-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
.challenge-icon-big { font-size: 2rem; line-height: 1; }
.challenge-header h1 { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; }
.challenge-meta { display: flex; gap: 8px; flex-wrap: wrap; }

.challenge-desc {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.7;
}
.challenge-desc code {
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.82em;
  color: var(--teal);
}
.challenge-desc pre {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.82rem;
  line-height: 1.5;
}
.challenge-desc pre code {
  background: none;
  padding: 0;
  color: var(--text);
}
.challenge-desc strong { color: var(--text); }
.challenge-desc table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 0.83rem;
}
.challenge-desc th, .challenge-desc td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
}
.challenge-desc th { background: var(--bg3); color: var(--text); }

/* hints */
.hints-section { margin-top: 16px; }
.hints-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--purple);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-weight: 600;
}
.hints-toggle:hover { text-decoration: underline; }
.hints-list { margin-top: 8px; display: none; }
.hints-list.open { display: block; }
.hint-item {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 6px 12px;
  border-left: 2px solid var(--purple);
  margin-bottom: 6px;
  background: #bc8cff0a;
  border-radius: 0 6px 6px 0;
  filter: blur(4px);
  transition: filter 0.3s;
  cursor: pointer;
}
.hint-item.revealed { filter: none; cursor: default; }
.hint-item.revealed::before { content: '💡 '; }

/* concepts */
.concepts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}
.concept-chip {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* editor pane */
.editor-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.editor-lang {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.python-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
}

#editor-container { flex: 1; overflow: hidden; }

/* ─── Output / test results panel ──────────────── */
.panel-bottom {
  display: grid;
  grid-template-columns: 380px 1fr;
  overflow: hidden;
}

.test-results-pane {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}
.test-results-pane h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.test-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 0.83rem;
  border: 1px solid var(--border);
  background: var(--bg2);
}
.test-item.pass { border-color: #3fb95040; background: #3fb95010; }
.test-item.fail { border-color: #f8514940; background: #f8514910; }

.test-icon { font-size: 0.9rem; flex-shrink: 0; margin-top: 1px; }
.test-desc { color: var(--text); font-weight: 500; }
.test-msg { color: var(--red); font-size: 0.78rem; margin-top: 2px; font-family: monospace; }

.result-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}
.result-summary.all-pass { background: #3fb95018; color: var(--green); border: 1px solid #3fb95040; }
.result-summary.has-fail { background: #f8514918; color: var(--red); border: 1px solid #f8514940; }
.result-summary.idle { background: var(--bg2); color: var(--muted); border: 1px solid var(--border); }

/* stdout pane */
.stdout-pane {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
}
.stdout-pane h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}
.stdout-content {
  flex: 1;
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.stdout-content.error { color: var(--red); }
.stdout-placeholder { color: var(--dim); font-style: italic; font-size: 0.82rem; }

/* ─── Leaderboard sidebar ───────────────────────── */
.lb-sidebar {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lb-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.lb-live { display: flex; align-items: center; gap: 5px; }
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.lb-list { flex: 1; overflow-y: auto; padding: 8px 6px; }

.lb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 3px;
  transition: background 0.12s;
}
.lb-item:hover { background: var(--bg3); }
.lb-item.me { background: #3fb95010; border: 1px solid #3fb95030; }

.lb-rank {
  width: 22px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--dim);
}
.lb-rank-1 { color: #ffd700; }
.lb-rank-2 { color: #c0c0c0; }
.lb-rank-3 { color: #cd7f32; }

.lb-avatar { font-size: 1.2rem; flex-shrink: 0; }
.lb-info { flex: 1; min-width: 0; }
.lb-name {
  font-size: 0.83rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-stats {
  font-size: 0.71rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
}
.lb-xp { font-size: 0.78rem; font-weight: 600; color: var(--gold); white-space: nowrap; }

/* ─── Empty state ───────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--dim);
}
.empty-state-icon { font-size: 3rem; }
.empty-state p { font-size: 0.9rem; }

/* ─── Loading overlay ───────────────────────────── */
#py-loading {
  position: fixed;
  inset: 0;
  background: rgba(13,17,23,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 9999;
  backdrop-filter: blur(4px);
}
#py-loading.hidden { display: none; }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#py-loading p { color: var(--muted); font-size: 0.9rem; }
#py-loading strong { color: var(--green); }

/* ─── Toast ─────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  background: var(--bg2);
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slideIn 0.25s ease;
  max-width: 320px;
}
.toast.success { border-color: #3fb95060; background: #3fb95015; color: var(--green); }
.toast.error   { border-color: #f8514960; background: #f8514915; color: var(--red); }
.toast.info    { border-color: #58a6ff60; background: #58a6ff15; color: var(--blue); }
.toast.gold    { border-color: #e3b34160; background: #e3b34115; color: var(--gold); }

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOut {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

/* ─── XP animation ──────────────────────────────── */
.xp-float {
  position: fixed;
  pointer-events: none;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
  z-index: 10001;
  animation: floatUp 1.2s ease forwards;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
@keyframes floatUp {
  0%   { transform: translateY(0) scale(1);    opacity: 1; }
  60%  { transform: translateY(-50px) scale(1.2); opacity: 1; }
  100% { transform: translateY(-90px) scale(1);  opacity: 0; }
}

/* ─── Completed overlay ─────────────────────────── */
.challenge-complete-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #3fb95018;
  border: 1px solid #3fb95050;
  border-radius: var(--radius);
  margin-bottom: 12px;
  color: var(--green);
  font-size: 0.88rem;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════
   LEADERBOARD PAGE
   ═══════════════════════════════════════════════════ */
.lb-page {
  min-height: 100vh;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.lb-page-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 32px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.lb-page-nav h1 { font-size: 1.1rem; font-weight: 700; color: var(--green); }

.lb-page-body {
  flex: 1;
  padding: 32px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
}
.lb-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.lb-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.lb-table tr:hover td { background: var(--bg2); }
.lb-table tr.me td { background: #3fb95008; }

.lb-table .rank-cell {
  width: 40px;
  font-weight: 700;
  color: var(--dim);
  font-size: 0.95rem;
}
.rank-gold   { color: #ffd700 !important; }
.rank-silver { color: #c0c0c0 !important; }
.rank-bronze { color: #cd7f32 !important; }

.player-cell { display: flex; align-items: center; gap: 10px; }

.level-pill {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}

/* ─── Progress bar (leaderboard page) ──────────── */
.mini-bar-wrap {
  width: 80px;
  height: 5px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.mini-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), #46d058);
  border-radius: 3px;
}

/* ═══════════════════════════════════════════════════
   SPRINT MODE
   ═══════════════════════════════════════════════════ */

/* ─── Sprint banner (slides in from top) ───────── */
.sprint-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(90deg, #f8514912, #e3b34112);
  border-bottom: 2px solid #f8514966;
  position: fixed;
  top: 54px;
  left: 0;
  right: 0;
  z-index: 200;
  animation: bannerSlideIn 0.4s ease;
}
.sprint-banner.hidden { display: none !important; }

.sprint-banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sprint-flag { font-size: 1.4rem; }
.sprint-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--red);
}
.sprint-cname {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sprint-countdown {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
  min-width: 68px;
  text-align: center;
  transition: color 0.3s;
}

.sprint-finishers-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.sprint-finisher-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 500;
  animation: chipPop 0.3s ease;
}
@keyframes chipPop {
  0%   { transform: scale(0.7); opacity: 0; }
  70%  { transform: scale(1.1); }
  100% { transform: scale(1);   opacity: 1; }
}
.sprint-finisher-chip.rank-1 { border-color: #ffd70080; background: #ffd70015; }
.sprint-finisher-chip.rank-2 { border-color: #c0c0c080; background: #c0c0c010; }
.sprint-finisher-chip.rank-3 { border-color: #cd7f3280; background: #cd7f3210; }

/* ─── Sprint results modal ──────────────────────── */
.sprint-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10500;
  backdrop-filter: blur(6px);
}
.sprint-modal.hidden { display: none; }
.sprint-modal-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  animation: modalPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalPop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.sprint-result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  text-align: left;
}
.sprint-result-row.rank-1 { border-color: #ffd70060; background: #ffd70010; }
.sprint-result-row.rank-2 { border-color: #c0c0c060; background: #c0c0c010; }
.sprint-result-row.rank-3 { border-color: #cd7f3260; background: #cd7f3210; }
.sprint-result-medal  { font-size: 1.5rem; width: 36px; text-align: center; }
.sprint-result-avatar { font-size: 1.2rem; }
.sprint-result-name   { flex: 1; font-weight: 600; }
.sprint-result-time   { color: var(--muted); font-family: monospace; font-size: 0.85rem; }
.sprint-result-bonus  { color: var(--gold); font-weight: 700; font-size: 0.88rem; }

/* ─── Bug Hunt tier tag ─────────────────────────── */
.tag-bughunt {
  background: #f8514920;
  color: var(--red);
  border: 1px solid #f8514950;
}

/* ═══════════════════════════════════════════════════
   ONLINE PRESENCE
   ═══════════════════════════════════════════════════ */

/* Online count pill in topbar */
.online-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--green);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  background: #3fb95015;
  border: 1px solid #3fb95030;
  white-space: nowrap;
}

/* Presence section in lb-sidebar */
.lb-online-section {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.lb-presence-list {
  padding: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.presence-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 2px;
  transition: background 0.12s;
}
.presence-chip:hover { background: var(--bg3); }
.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}
.presence-name { font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-challenge { font-size: 0.7rem; color: var(--dim); }

/* ─── Responsive ────────────────────────────────── */
@media (max-width: 1100px) {
  .game-body { grid-template-columns: var(--sidebar-w) 1fr; }
  .lb-sidebar { display: none; }
}
@media (max-width: 820px) {
  :root { --sidebar-w: 220px; }
  .panel-top, .panel-bottom { grid-template-columns: 1fr; }
  .description-pane { display: none; }
  .features { grid-template-columns: 1fr; padding: 24px; }
}
@media (max-width: 640px) {
  .game-body { grid-template-columns: 1fr; }
  .challenge-sidebar { display: none; }
}
