:root {
  --bg: #0f0f10;
  --surface: #1a1a1d;
  --surface-2: #232328;
  --surface-3: #2a2a30;
  --border: #2e2e35;
  --text: #fafafa;
  --text-dim: #a1a1aa;
  --text-muted: #71717a;
  --accent: #8b5cf6;
  --accent-2: #6366f1;
  --accent-glow: rgba(139, 92, 246, 0.15);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

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

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a42; }

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 110%, rgba(99, 102, 241, 0.10), transparent 60%),
    var(--bg);
}

/* ───────────── Auth pages (login/register) ───────────── */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(26, 26, 29, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.5s ease;
}

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

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.auth-logo .mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.auth-logo .mark svg { color: white; }

.auth-logo h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-card .subtitle {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}

.field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: white;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-3); box-shadow: none; }

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #dc2626);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.2);
}

.auth-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}
.auth-footer a { color: var(--accent); font-weight: 500; }
.auth-footer a:hover { text-decoration: underline; }

.alert {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3); color: #fecaca; }
.alert-success { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.3); color: #bbf7d0; }

/* ───────────── App shell ───────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 15, 16, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

@media (max-width: 640px) {
  .topbar-inner { padding: 10px 14px; gap: 8px; }
  .nav-actions { gap: 4px; }
  .nav-btn { padding: 8px 8px; }
  .brand span { font-size: 15px; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand .mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.search {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.search input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px 10px 40px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

.nav-actions { display: flex; align-items: center; gap: 8px; }

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.nav-btn:hover { color: var(--text); background: var(--surface-2); }

.user-menu { display: flex; align-items: center; gap: 10px; transition: opacity 0.15s; }
.user-menu:hover { opacity: 0.85; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

/* ───────────── Dashboard ───────────── */

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 0;
  color: var(--text-dim);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.course-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  animation: fadeUp 0.4s ease backwards;
}

.course-card:hover {
  transform: translateY(-2px);
  border-color: rgba(139, 92, 246, 0.4);
  box-shadow: var(--shadow-md);
}

.course-thumb {
  aspect-ratio: 16 / 9;
  position: relative;
  background: linear-gradient(135deg, #2a2a30, #1a1a1d);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

.course-thumb svg.bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0.7;
}

.course-thumb .initials {
  position: relative;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: white;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}

.course-thumb .badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: white;
}

.course-info {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.course-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.course-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.course-meta span { display: inline-flex; align-items: center; gap: 4px; }

.progress-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}

/* skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-dim);
}

.empty-state svg { color: var(--text-muted); margin-bottom: 16px; }

/* ───────────── Course view ───────────── */

.course-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: calc(100vh - 64px);
}

.course-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
  overflow: hidden;
}

/* Toggle buttons hidden on desktop — overridden in mobile media query below */
.sidebar-close,
.sidebar-open { display: none !important; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 35;
  animation: fadeIn 0.18s ease;
}
.sidebar-backdrop.show { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

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

  .course-sidebar {
    position: fixed;
    inset: 60px auto 0 0;
    width: min(380px, 88vw);
    height: calc(100vh - 60px);
    z-index: 40;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .course-sidebar.open { transform: translateX(0); }

  .sidebar-close {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0;
    z-index: 1;
  }
  .sidebar-close:hover { color: var(--text); background: var(--surface-3); }

  .course-sidebar-head { padding: 18px 56px 16px 20px; }

  .sidebar-open {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    margin: 14px 16px 0;
    padding: 9px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    align-self: flex-start;
    transition: border-color 0.15s, background 0.15s;
    line-height: 1;
  }
  .sidebar-open:hover { background: var(--surface-2); border-color: rgba(139, 92, 246, 0.4); }
  .sidebar-open svg { color: var(--accent); }
}

.course-sidebar-head {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.course-sidebar-head h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.course-sidebar-head .meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
}

.course-sidebar-head .progress-bar {
  margin-top: 12px;
  margin-bottom: 6px;
}

.course-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.tree-part { margin-bottom: 4px; }

.tree-toggle {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tree-toggle:hover { color: var(--text); }

.tree-toggle .chev {
  transition: transform 0.15s;
}
.tree-part.collapsed .tree-toggle .chev { transform: rotate(-90deg); }
.tree-part.collapsed .tree-section { display: none; }

.tree-section { padding: 0 8px 8px; }

.tree-section-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  padding: 8px 12px 6px;
}

.tree-lesson {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  border: 1px solid transparent;
}

.tree-lesson:hover { background: var(--surface-2); color: var(--text); }

.tree-lesson.active {
  background: var(--accent-glow);
  color: var(--text);
  border-color: rgba(139, 92, 246, 0.3);
}

.tree-lesson.completed .check { color: var(--success); }
.tree-lesson .check {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--text-muted);
}
.tree-lesson .title { flex: 1; }

.course-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.player-wrap {
  background: black;
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-height: 70vh;
  contain: layout;
}

.player-wrap video {
  width: 100%;
  height: 100%;
}

.lesson-info {
  padding: 24px 28px;
}

@media (max-width: 1024px) {
  .player-wrap { max-height: none; }
}
@media (max-width: 640px) {
  .lesson-info { padding: 18px 16px; }
  .lesson-info h1 { font-size: 19px; }
  .lesson-actions .btn { font-size: 12.5px; padding: 9px 13px; }
}

.lesson-breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lesson-info h1 {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lesson-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.lesson-actions .btn { width: auto; padding: 10px 16px; font-size: 13px; }

.resources {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.resources h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.resource-list { display: flex; flex-direction: column; gap: 8px; }

.resource-item {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color 0.15s;
  overflow: hidden;
}
.resource-item:hover { border-color: rgba(139, 92, 246, 0.4); }
.resource-item.expanded { border-color: rgba(139, 92, 246, 0.5); }

.resource-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}

.resource-item .icon {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  flex-shrink: 0;
}
.resource-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.resource-item .ext {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  flex-shrink: 0;
}
.resource-row a,
.resource-row .resource-toggle {
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.resource-row a:hover,
.resource-row .resource-toggle:hover { background: var(--surface-2); border-color: rgba(139, 92, 246, 0.4); }

.resource-toggle .chev { transition: transform 0.2s; }
.resource-item.expanded .resource-toggle .chev { transform: rotate(180deg); }
.resource-item.expanded .resource-toggle { background: var(--accent-glow); border-color: rgba(139, 92, 246, 0.4); }

.resource-preview {
  border-top: 1px solid var(--border);
  background: #0a0a0c;
  animation: rpFade 0.18s ease;
}
@keyframes rpFade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.resource-preview pre.rp-text {
  margin: 0;
  padding: 18px 22px;
  background: #16161a;
  color: #e4e4e7;
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 520px;
  overflow: auto;
  tab-size: 2;
}
.resource-preview iframe.rp-html,
.resource-preview iframe.rp-pdf {
  width: 100%;
  height: 70vh;
  min-height: 420px;
  border: 0;
  display: block;
}
.resource-preview iframe.rp-html { background: white; }
.resource-preview iframe.rp-pdf  { background: #1a1a1d; }

.resource-preview .rp-image {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  min-height: 240px;
  background:
    linear-gradient(45deg, #1a1a1d 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1d 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1d 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #0a0a0c;
}
.resource-preview .rp-image img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 4px;
}

.resource-preview .rp-loading,
.resource-preview .rp-error {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 20px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}
.resource-preview .rp-loading svg { animation: spin 0.8s linear infinite; opacity: 0.6; }
.resource-preview .rp-error a { color: var(--accent); margin-left: 6px; font-weight: 500; }

/* ───────────── Admin ───────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 20px;
}

.section-card h3 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-card .actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.section-card .btn { width: auto; padding: 8px 14px; font-size: 13px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 500;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
table tr:last-child td { border-bottom: none; }
table .role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
table .role-badge.admin { background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }
table .role-badge.user { background: var(--surface-3); color: var(--text-dim); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── Plyr theme overrides ───────────── */

.plyr--full-ui input[type="range"] {
  color: var(--accent);
}

.plyr__control--overlaid {
  background: var(--accent);
}
.plyr--video .plyr__control:hover,
.plyr__control[aria-expanded="true"] {
  background: var(--accent);
}
.plyr--video .plyr__control.plyr__tab-focus {
  background: var(--accent);
}
