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

:root {
  --sidebar-w: 280px;
  --sidebar-bg: #1e1e2e;
  --sidebar-text: #cdd6f4;
  --sidebar-muted: #6c7086;
  --sidebar-hover: #313244;
  --sidebar-active: #313244;
  --accent: #a6e3a1;
  --accent-dark: #40a02b;
  --run-btn: #a6e3a1;
  --run-btn-text: #1e1e2e;
  --content-bg: #fafafa;
  --content-text: #24292f;
  --border: #e1e4e8;
  --code-bg: #0d1117;
  --tip-bg: #ddf4ff;
  --tip-border: #54aeff;
  --warn-bg: #fff8c5;
  --warn-border: #d4a72c;
  --note-bg: #f0fff4;
  --note-border: #a6e3a1;
  --radius: 8px;
  --mono: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

#layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  padding: 20px 16px 12px;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
  letter-spacing: -0.3px;
}

.progress-wrap { margin-bottom: 4px; }

.progress-bg {
  background: #313244;
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-label {
  font-size: 11px;
  color: var(--sidebar-muted);
}

#moduleList {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
}

#moduleList::-webkit-scrollbar { width: 4px; }
#moduleList::-webkit-scrollbar-track { background: transparent; }
#moduleList::-webkit-scrollbar-thumb { background: #45475a; border-radius: 4px; }

.mod-header {
  padding: 10px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--sidebar-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.mod-header:hover { color: var(--sidebar-text); }

.mod-header .mod-icon { font-size: 13px; }

.mod-header .mod-toggle {
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.2s;
}

.mod-header.collapsed .mod-toggle { transform: rotate(-90deg); }

.mod-lessons { overflow: hidden; }
.mod-lessons.collapsed { display: none; }

.lesson-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px 7px 28px;
  font-size: 13px;
  color: var(--sidebar-text);
  text-decoration: none;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.15s;
}

.lesson-link:hover { background: var(--sidebar-hover); }

.lesson-link.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

.lesson-link.done .check { color: var(--accent); }
.lesson-link:not(.done) .check { color: #45475a; }

.check { font-size: 12px; flex-shrink: 0; }

/* ── Main content ── */
#main {
  flex: 1;
  overflow-y: auto;
  background: var(--content-bg);
}

#main::-webkit-scrollbar { width: 6px; }
#main::-webkit-scrollbar-track { background: transparent; }
#main::-webkit-scrollbar-thumb { background: #d0d7de; border-radius: 4px; }

#lesson {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 40px 80px;
}

/* ── Home screen ── */
.home-hero {
  text-align: center;
  padding: 48px 0 40px;
}

.home-hero h1 {
  font-size: 40px;
  font-weight: 800;
  color: var(--content-text);
  margin-bottom: 12px;
}

.home-hero p {
  font-size: 18px;
  color: #57606a;
  margin-bottom: 32px;
}

.home-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 48px;
}

.stat {
  text-align: center;
}

.stat-n {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent-dark);
}

.stat-label {
  font-size: 13px;
  color: #57606a;
}

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

.module-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  text-align: left;
}

.module-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.module-card .card-icon { font-size: 24px; margin-bottom: 10px; }
.module-card h3 { font-size: 15px; font-weight: 700; color: var(--content-text); margin-bottom: 4px; }
.module-card p { font-size: 13px; color: #57606a; }
.module-card .card-count { margin-top: 10px; font-size: 12px; color: var(--sidebar-muted); }

/* ── Lesson content ── */
.lesson-header { margin-bottom: 32px; }

.lesson-breadcrumb {
  font-size: 12px;
  color: #57606a;
  margin-bottom: 8px;
}

.lesson-breadcrumb span { color: var(--accent-dark); font-weight: 600; }

.lesson-header h1 {
  font-size: 32px;
  font-weight: 800;
  color: var(--content-text);
  line-height: 1.2;
}

.lesson-body h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--content-text);
  margin: 32px 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

.lesson-body h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--content-text);
  margin: 24px 0 8px;
}

.lesson-body p {
  font-size: 15px;
  color: #444d56;
  line-height: 1.75;
  margin-bottom: 14px;
}

.lesson-body ul, .lesson-body ol {
  padding-left: 20px;
  margin-bottom: 14px;
}

.lesson-body li {
  font-size: 15px;
  color: #444d56;
  line-height: 1.75;
  margin-bottom: 4px;
}

.lesson-body code {
  font-family: var(--mono);
  font-size: 13px;
  background: #f3f4f6;
  color: #d73a49;
  padding: 2px 5px;
  border-radius: 4px;
}

.lesson-body pre code { background: none; color: inherit; padding: 0; }

/* ── Code blocks ── */
.code-block {
  margin: 16px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #30363d;
}

.code-block-header {
  background: #161b22;
  padding: 8px 14px;
  font-size: 12px;
  color: #8b949e;
  font-family: var(--mono);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.code-block pre {
  margin: 0;
  background: var(--code-bg) !important;
  padding: 16px !important;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
}

.code-block pre code {
  font-family: var(--mono) !important;
  font-size: 14px;
  background: none;
  color: inherit;
  padding: 0;
}

/* ── Runner ── */
.runner {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.runner-header {
  background: #f6f8fa;
  padding: 8px 14px;
  font-size: 12px;
  color: #57606a;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.runner textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 14px;
  padding: 16px;
  border: none;
  outline: none;
  resize: vertical;
  min-height: 120px;
  background: #f6f8fa;
  color: var(--content-text);
  line-height: 1.6;
  tab-size: 4;
}

.runner-footer {
  padding: 8px 14px;
  background: #f6f8fa;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.run-btn {
  background: var(--accent);
  color: var(--run-btn-text);
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.run-btn:hover { background: #94d2a0; }
.run-btn:active { transform: scale(0.97); }

.reset-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  color: #57606a;
  cursor: pointer;
  transition: background 0.15s;
}

.reset-btn:hover { background: #e1e4e8; }

.runner-output {
  font-family: var(--mono);
  font-size: 13px;
  padding: 12px 16px;
  background: #0d1117;
  color: #c9d1d9;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  display: none;
  border-top: 1px solid #30363d;
  min-height: 40px;
}

.runner-output.visible { display: block; }
.runner-output.error { color: #ff7b72; }
.runner-hint { font-size: 12px; color: #8c959f; }

/* ── Callout boxes ── */
.tip, .warn, .note {
  padding: 14px 16px;
  border-radius: var(--radius);
  margin: 16px 0;
  font-size: 14px;
  line-height: 1.65;
}

.tip { background: var(--tip-bg); border-left: 4px solid var(--tip-border); }
.warn { background: var(--warn-bg); border-left: 4px solid var(--warn-border); }
.note { background: var(--note-bg); border-left: 4px solid var(--note-border); }

.tip strong, .warn strong, .note strong { display: block; margin-bottom: 4px; }

/* ── Key points ── */
.key-points {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 24px 0;
}

.key-points h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--sidebar-muted);
  margin-bottom: 10px;
}

.key-points ul { padding-left: 16px; }
.key-points li { font-size: 14px; color: #444d56; line-height: 1.7; }

/* ── Nav bar ── */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.nav-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--content-text);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover { background: #f6f8fa; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.nav-btn.primary { background: var(--accent); color: var(--run-btn-text); border-color: var(--accent); }
.nav-btn.primary:hover { background: #94d2a0; }
.nav-btn:disabled { opacity: 0.35; cursor: default; box-shadow: none; }

.complete-btn {
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-dark);
  cursor: pointer;
  transition: background 0.15s;
}

.complete-btn:hover { background: var(--note-bg); }
.complete-btn.done { background: var(--accent); color: var(--run-btn-text); border-color: var(--accent); }

/* ── Table ── */
.lesson-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 16px 0;
}

.lesson-body th {
  background: #f6f8fa;
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--content-text);
}

.lesson-body td {
  padding: 9px 12px;
  border: 1px solid var(--border);
  color: #444d56;
}

.lesson-body tr:nth-child(even) td { background: #f9fafb; }

/* ── User section ── */
.user-section {
  padding: 12px 14px;
  border-top: 1px solid #313244;
  flex-shrink: 0;
}

.signin-btn {
  width: 100%;
  background: #4285f4;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}

.signin-btn:hover { background: #3367d6; }

.signin-note {
  font-size: 11px;
  color: var(--sidebar-muted);
  text-align: center;
  margin-top: 7px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-sync {
  font-size: 11px;
  color: var(--accent);
  margin-top: 2px;
}

.signout-btn {
  background: none;
  border: 1px solid #45475a;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--sidebar-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.signout-btn:hover { border-color: var(--sidebar-text); color: var(--sidebar-text); }

.user-section:has(.user-avatar) {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #sidebar { width: 240px; min-width: 240px; }
  #lesson { padding: 24px 20px 60px; }
  .home-hero h1 { font-size: 28px; }
  .modules-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  #layout { flex-direction: column; }
  #sidebar { width: 100%; min-width: unset; height: auto; max-height: 50vh; }
  #main { flex: 1; }
}
