:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #22c55e;
  --accent-soft: #dcfce7;
  --accent-hover: #16a34a;
  --banner-bg: #0a0a0a;
  --banner-text: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 280px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

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

a { color: inherit; text-decoration: none; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.breadcrumb {
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.breadcrumb .crumb {
  cursor: pointer;
}
.breadcrumb .crumb:hover { color: var(--text); }
.breadcrumb .sep { color: var(--border); }
.breadcrumb .current { color: var(--text); font-weight: 500; }

.offline-btn {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.offline-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}
.offline-btn:disabled { cursor: default; opacity: 0.7; }

/* ---------- Modules grid ---------- */
.view-modules {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}
.modules-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
@media (max-width: 1024px) {
  .modules-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .modules-grid { grid-template-columns: 1fr; }
}

.module-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.module-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.banner {
  background: var(--banner-bg);
  color: var(--banner-text);
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.06), transparent 70%);
  pointer-events: none;
}
.banner-text {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0.02em;
  position: relative;
  z-index: 1;
}

.card-body {
  padding: 16px 18px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text);
}
.card-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.progress-wrap {
  margin-top: auto;
}
.progress-bar {
  height: 6px;
  width: 100%;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.empty {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}
.empty code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ---------- Module view ---------- */
.view-module {
  display: flex;
  height: calc(100vh - 57px);
  background: var(--bg);
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 0;
  margin-bottom: 8px;
  transition: color 0.15s;
}
.back-btn:hover { color: var(--text); }
.sidebar-module-name {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}
.sidebar-progress {
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar-progress .progress-bar {
  margin-top: 4px;
}

.lesson-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
}
.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 14px;
  border-left: 3px solid transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}
.lesson-item:hover {
  background: #fafafa;
}
.lesson-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 500;
}
.lesson-item.completed .lesson-name {
  color: var(--text-muted);
  text-decoration: line-through;
}
.lesson-icon {
  flex-shrink: 0;
  font-size: 16px;
  width: 20px;
  text-align: center;
}
.lesson-name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}
.lesson-check {
  flex-shrink: 0;
  color: var(--accent);
  font-size: 14px;
  opacity: 0;
}
.lesson-item.completed .lesson-check { opacity: 1; }

/* ---------- Content area ---------- */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}
.lesson-viewer {
  max-width: 960px;
  margin: 0 auto;
}
.lesson-viewer h1 {
  font-size: 24px;
  margin: 0 0 20px;
  font-weight: 700;
  line-height: 1.3;
}

.viewer-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-muted);
  font-size: 15px;
}

/* Video */
.video-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.video-wrap video {
  display: block;
  width: 100%;
  background: #000;
  max-height: 70vh;
}

/* PDF */
.pdf-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  height: 75vh;
}
.pdf-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

/* Image */
.image-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.image-wrap img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  transition: transform 0.2s;
}
.image-wrap img.zoomed {
  cursor: zoom-out;
  transform: scale(1.5);
}

/* Text */
.text-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 40px;
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}

/* Stack assets vertically (video on top, text/pdf/image below) */
.asset-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.complete-btn {
  margin-top: 20px;
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s;
}
.complete-btn:hover { background: var(--accent-hover); }
.complete-btn.done {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .view-module {
    flex-direction: column;
    height: auto;
  }
  .sidebar {
    width: 100%;
    max-height: 280px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content-area {
    padding: 20px 16px;
  }
  .lesson-viewer h1 { font-size: 20px; }
  .text-wrap { padding: 20px; }
  .topbar-inner { padding: 12px 16px; gap: 12px; }
  .breadcrumb { font-size: 13px; }
}
