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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3347;
  --text: #e4e6f0;
  --text-dim: #8b8fa7;
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --success: #00b894;
  --success-light: #55efc4;
  --warning: #fdcb6e;
  --danger: #e17055;
  --accent: #fd79a8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header .logo {
  font-size: 28px;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.progress-summary {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.progress-ring-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-ring { transform: rotate(-90deg); }
.progress-ring-bg { fill: none; stroke: var(--surface2); stroke-width: 5; }
.progress-ring-fill {
  fill: none;
  stroke: var(--success);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 163.36;
  stroke-dashoffset: 163.36;
  transition: stroke-dashoffset 0.6s ease;
}

#progress-pct {
  position: absolute;
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
}

.progress-text {
  font-size: 13px;
  color: var(--text-dim);
}

#lesson-list {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.lesson-item:hover { background: var(--surface2); color: var(--text); }
.lesson-item.active { background: var(--primary); color: white; }
.lesson-item.completed { color: var(--success); }
.lesson-item.completed .lesson-check { opacity: 1; }

.lesson-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  transition: all 0.3s;
}

.lesson-item.completed .lesson-check {
  background: var(--success);
  border-color: var(--success);
}

.lesson-item.active .lesson-check {
  border-color: rgba(255,255,255,0.5);
}

.reset-btn {
  margin: 12px 16px 16px;
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.reset-btn:hover { border-color: var(--danger); color: var(--danger); }

/* ── Main ── */
#main {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ── Welcome ── */
.welcome-content {
  max-width: 640px;
  margin: auto;
  padding: 40px 24px;
  text-align: center;
}

.welcome-emoji { font-size: 64px; margin-bottom: 16px; animation: bounce 2s infinite; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.welcome-content h2 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 12px;
}

.welcome-content > p {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 32px;
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 36px;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  transition: transform 0.2s, border-color 0.2s;
}

.feature-card:hover { transform: translateY(-4px); border-color: var(--primary); }
.feature-icon { font-size: 32px; display: block; margin-bottom: 10px; }
.feature-card h3 { font-size: 15px; margin-bottom: 6px; }
.feature-card p { font-size: 12px; color: var(--text-dim); line-height: 1.4; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #5b4bd5; transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: none; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 32px; font-size: 16px; }

/* ── Lesson ── */
.lesson-header {
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.lesson-badge {
  display: inline-block;
  padding: 4px 10px;
  background: var(--primary);
  color: white;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.lesson-header h2 { font-size: 22px; font-weight: 700; }

.lesson-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.explanation-panel {
  padding: 24px 28px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  line-height: 1.7;
  font-size: 14px;
}

.explanation-panel h3 {
  font-size: 16px;
  margin: 20px 0 10px;
  color: var(--primary-light);
}

.explanation-panel h3:first-child { margin-top: 0; }

.explanation-panel p { margin-bottom: 12px; color: var(--text-dim); }
.explanation-panel strong { color: var(--text); }
.explanation-panel em { color: var(--warning); font-style: normal; }

.explanation-panel code {
  font-family: 'Fira Code', monospace;
  background: var(--surface2);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--accent);
}

.explanation-panel pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 12px 0;
  overflow-x: auto;
  font-family: 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.6;
}

.explanation-panel pre code {
  background: none;
  padding: 0;
  color: var(--text);
}

.explanation-panel ul, .explanation-panel ol {
  margin: 10px 0 14px 20px;
  color: var(--text-dim);
}

.explanation-panel li { margin-bottom: 6px; }

.callout {
  background: rgba(108, 92, 231, 0.1);
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 14px 0;
}

.callout.success {
  background: rgba(0, 184, 148, 0.1);
  border-left-color: var(--success);
}

/* ── Editor ── */
.editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.editor-toolbar, .output-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.editor-label { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.editor-actions { display: flex; gap: 6px; }

#code-editor {
  flex: 1;
  min-height: 180px;
  background: var(--bg);
  color: var(--text);
  border: none;
  padding: 16px;
  font-family: 'Fira Code', monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
  tab-size: 2;
}

.output-panel {
  border-top: 1px solid var(--border);
  min-height: 120px;
  max-height: 200px;
  display: flex;
  flex-direction: column;
}

#output {
  flex: 1;
  padding: 12px 16px;
  font-family: 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-y: auto;
  color: var(--success-light);
  white-space: pre-wrap;
}

#output .error { color: var(--danger); }

/* ── Lesson Footer ── */
.lesson-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#challenge-status {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

#challenge-status.passed { color: var(--success); }
#challenge-status.pending { color: var(--warning); }

/* ── Modal ── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
}
.modal.active { display: flex; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow);
}

.modal-content h3 { margin-bottom: 12px; }
.modal-content p { color: var(--text-dim); margin-bottom: 20px; line-height: 1.6; font-size: 14px; }

/* ── Celebration ── */
.celebration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall 1.5s ease-out forwards;
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(80vh) rotate(720deg) scale(0.5); }
}

/* ── Achievement ── */
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 28px 0;
}

.achievement {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.achievement .emoji { font-size: 28px; margin-bottom: 6px; }
.achievement .label { font-size: 12px; color: var(--text-dim); }

/* ── Responsive ── */
@media (max-width: 900px) {
  #sidebar { width: 60px; min-width: 60px; }
  .sidebar-header h1, .progress-summary, .lesson-item span:not(.lesson-check), .reset-btn { display: none; }
  .sidebar-header { justify-content: center; padding: 16px 8px; }
  .lesson-item { justify-content: center; padding: 10px; }
  #lesson-list { padding: 8px 4px; }
  .lesson-body { grid-template-columns: 1fr; }
  .explanation-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .feature-cards { grid-template-columns: 1fr; }
}
