/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c0c0c;
  --bg-card: #141414;
  --bg-card-hover: #1a1a1a;
  --accent: #c8ff00;
  --accent-dim: rgba(200, 255, 0, 0.12);
  --accent-dim2: rgba(200, 255, 0, 0.06);
  --text: #ffffff;
  --text-secondary: #888;
  --text-muted: #555;
  --border: #222;
  --danger: #ff4444;
  --nav-height: 64px;
  --radius: 16px;
  --radius-sm: 10px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + 16px);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ── Pages ────────────────────────────────────────────────────────────────── */
.page { display: none; padding: 20px 16px; }
.page.active { display: block; }

.page-header {
  margin-bottom: 24px;
  padding-top: 8px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.page-header .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
  font-weight: 400;
}

/* ── Bottom Nav ───────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(12, 12, 12, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 100;
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn .nav-icon { font-size: 20px; line-height: 1; }

.nav-btn.active {
  color: var(--accent);
}

.nav-btn:active { background: var(--accent-dim2); }

/* ── Cards Grid ───────────────────────────────────────────────────────────── */
.cards-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Course Card ──────────────────────────────────────────────────────────── */
.course-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.course-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  right: 0; height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s;
}

.course-card:active {
  background: var(--bg-card-hover);
  transform: scale(0.98);
}

.course-card:active::before { transform: scaleX(1); }

.course-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.course-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.course-desc {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.course-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.course-meta {
  display: flex;
  gap: 12px;
}

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

.course-price {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.course-price.owned {
  font-size: 14px;
  color: #4ade80;
  font-weight: 700;
}

/* ── Skeleton ─────────────────────────────────────────────────────────────── */
.skeleton-card {
  height: 160px;
  background: var(--bg-card);
  border-radius: var(--radius);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Presets ──────────────────────────────────────────────────────────────── */
.presets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.preset-card:active {
  border-color: var(--accent);
  transform: scale(0.97);
}

.preset-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.preset-title {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
}

.preset-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* ── Preset Result ────────────────────────────────────────────────────────── */
.preset-result {
  margin-top: 20px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  font-size: 14px;
  color: var(--accent);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.close-btn:active { background: var(--border); }

.result-content {
  padding: 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

/* ── Profile ──────────────────────────────────────────────────────────────── */
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  margin-bottom: 14px;
}

.profile-name {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}

.profile-id {
  font-size: 12px;
  color: var(--text-muted);
  font-family: monospace;
}

/* ── Settings Section ─────────────────────────────────────────────────────── */
.settings-section, .stats-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.settings-title {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
}

.setting-row, .stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 15px;
}

.stat-row + .stat-row {
  border-top: 1px solid var(--border);
}

.stat-value {
  font-weight: 800;
  color: var(--accent);
}

/* ── Toggle ───────────────────────────────────────────────────────────────── */
.toggle {
  width: 48px;
  height: 28px;
  background: var(--border);
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  transition: background 0.25s;
  -webkit-tap-highlight-color: transparent;
}

.toggle.on { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  transition: transform 0.25s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.toggle.on .toggle-thumb { transform: translateX(20px); }

/* ── Progress ─────────────────────────────────────────────────────────────── */
.progress-course {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}

.progress-course-title {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 12px;
}

.progress-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-label {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: slide-up 0.3s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--border);
  border: none;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-title {
  font-size: 22px;
  font-weight: 900;
  margin-bottom: 8px;
  padding-right: 40px;
  letter-spacing: -0.3px;
}

.modal-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.modal-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  text-align: center;
  letter-spacing: -0.2px;
  transition: opacity 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active { opacity: 0.85; transform: scale(0.98); }

.btn-outline {
  display: block;
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  margin-top: 10px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-outline:active { background: var(--accent-dim); }

/* ── Lesson List ──────────────────────────────────────────────────────────── */
.lesson-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.lesson-item:last-child { border-bottom: none; }

.lesson-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-top: 2px;
}

.lesson-num.done {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.lesson-name {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-secondary);
}

.lesson-name.done { color: var(--text); }

/* ── Loader ───────────────────────────────────────────────────────────────── */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(12,12,12,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.loader.hidden { display: none; }

.loader-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 20px;
  gap: 12px;
}

.empty-icon { font-size: 48px; }

.empty-state p {
  color: var(--text-secondary);
  font-size: 15px;
  max-width: 240px;
  line-height: 1.5;
}

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
