:root {
  --bg: #0b0e14;
  --surface: #12161f;
  --surface-2: #1a202c;
  --border: #232a3b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --emerald: #10b981;
  --danger: #ef4444;
  --radius: 14px;
}

body.light-theme {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 10px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 16px;
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: -0.3px; display: flex; align-items: center; gap: 8px; }
.brand-badge { background: var(--primary); color: #fff; padding: 3px 8px; border-radius: 8px; font-size: 12px; }
.pill-btn {
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; gap: 6px;
}
.pill-btn.key-active { border-color: var(--emerald); color: var(--emerald); }
.pill-btn.key-locked { border-color: var(--danger); color: #fca5a5; }
.pill-btn.xp { border-color: #f59e0b; color: #fbbf24; }

/* Layout */
.layout { display: flex; flex: 1; }
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.2s ease;
}
.nav-item {
  padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; color: var(--muted); text-align: left;
}
.nav-item:hover, .nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active { border-left: 3px solid var(--primary); }

.main { flex: 1; padding: 20px; max-width: 1200px; margin: 0 auto; width: 100%; }
.footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* Search & Banner */
.search-row { display: flex; gap: 10px; margin-bottom: 18px; }
.search-input {
  flex: 1; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px;
}
.btn-emerald {
  background: var(--emerald); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
}
.btn-primary {
  background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
}
.btn-danger {
  background: var(--danger); color: #fff; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 12px;
}
.hero-banner {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: var(--radius); padding: 22px; margin-bottom: 20px; color: #fff;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
}

/* Grids & Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.compact-card { padding: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.xp-highlight { color: #fbbf24; font-weight: 700; }
.card-badges { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge.new { background: rgba(16, 185, 129, 0.15); color: var(--emerald); }
.badge.cat { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }
.card-title { font-size: 16px; font-weight: 700; }
.card-desc { font-size: 13px; color: var(--muted); line-height: 1.45; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); }

/* Tabs & Chapters */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.tab-btn {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface);
}
.tab-btn.active { background: var(--primary); color: #fff; }
.chapter-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid #3b82f6;
  border-radius: 10px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;
}

/* Player & Modals */
.player-wrap {
  background: #000; border-radius: var(--radius); overflow: hidden; margin-bottom: 16px;
  position: relative; aspect-ratio: 16 / 9;
}
.player-wrap video, .player-wrap #ytPlayerBox { width: 100%; height: 100%; display: block; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); display: none; place-items: center; z-index: 60; padding: 16px;
}
.modal-backdrop.open { display: grid; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; max-width: 440px; width: 100%; display: flex; flex-direction: column; gap: 12px;
}
.modal-close { justify-content: center; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-control {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 14px;
}

@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 60px; bottom: 0; z-index: 50; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
}
