/* ===== AL Academy — base UI ===== */
:root {
  --bg: #0d1117;
  --bg-2: #111722;
  --bg-3: #161d29;
  --panel: #0f1521;
  --border: #233044;
  --text: #d7e0ee;
  --text-dim: #8a98ad;
  --accent: #4dd0a7;
  --accent-2: #6aa6ff;
  --warn: #ffcc66;
  --danger: #ff6b6b;
  --ok: #56d364;
  --radius: 10px;
  --mono: "JetBrains Mono", "Fira Code", "SF Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-theme="light"] {
  --bg: #f6f8fb; --bg-2: #eef2f7; --bg-3: #e6ecf4; --panel: #ffffff;
  --border: #d3dbe6; --text: #1b2430; --text-dim: #5b6675;
  --accent: #119a73; --accent-2: #2f6fe0;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

#app { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }

/* ---- Sidebar ---- */
#sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 18px 16px 12px; }
.brand .logo { font-size: 28px; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--text-dim); }
.search { padding: 6px 14px 12px; }
.search input {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text);
  font-size: 13px; outline: none;
}
.search input:focus { border-color: var(--accent); }

.tree { overflow-y: auto; flex: 1; padding: 4px 8px 16px; min-height: 0; }
.tree-group { margin: 6px 0; }
.tree-group > .group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; cursor: pointer; border-radius: 8px;
  font-weight: 600; font-size: 13px; color: var(--text);
  user-select: none;
}
.tree-group > .group-head:hover { background: var(--bg-3); }
.group-head .chev { transition: transform .15s ease; color: var(--text-dim); font-size: 11px; }
.tree-group.collapsed .chev { transform: rotate(-90deg); }
.tree-group.collapsed .group-body { display: none; }
.group-emoji { width: 18px; text-align: center; }
.group-count { margin-left: auto; font-size: 11px; color: var(--text-dim); }

.lesson-link {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 30px; border-radius: 7px; cursor: pointer;
  font-size: 12.5px; color: var(--text-dim);
}
.lesson-link:hover { background: var(--bg-3); color: var(--text); }
.lesson-link.active { background: var(--accent); color: #04130d; font-weight: 600; }
.lesson-link .wk { font-variant-numeric: tabular-nums; opacity: .7; font-size: 11px; }
.lesson-link.done::after { content: "✓"; margin-left: auto; color: var(--ok); }
.lesson-link.active.done::after { color: #04130d; }

.sidebar-foot {
  border-top: 1px solid var(--border); padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.progress-summary { font-size: 11.5px; color: var(--text-dim); }
.ghost-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 7px; padding: 6px 9px; cursor: pointer; font-size: 12px;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---- Main / lesson ---- */
#main { overflow-y: auto; min-height: 0; }
.lesson { max-width: 920px; margin: 0 auto; padding: 32px 40px 120px; }

.lesson-head { border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 8px; }
.crumbs { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.lesson-title { font-size: 30px; margin: 0 0 12px; line-height: 1.15; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-2);
}
.badge.track { color: #04130d; background: var(--accent); border-color: transparent; font-weight: 600; }
.badge.level { color: var(--accent-2); border-color: var(--accent-2); }
.badge.date { font-variant-numeric: tabular-nums; }

/* "Where you can use it" callout */
.where {
  margin: 22px 0; padding: 14px 16px; border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(106,166,255,.10), rgba(106,166,255,.03));
  border: 1px solid rgba(106,166,255,.35);
}
.where h4 { margin: 0 0 6px; font-size: 13px; color: var(--accent-2); letter-spacing: .3px; text-transform: uppercase; }
.where p { margin: 0; font-size: 14px; color: var(--text); }

/* Markdown body */
.md { font-size: 15.5px; line-height: 1.65; }
.md h2 { font-size: 22px; margin: 30px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 18px; margin: 24px 0 8px; }
.md p, .md li { color: var(--text); }
.md code { font-family: var(--mono); font-size: .9em; background: var(--bg-3); padding: 1.5px 5px; border-radius: 5px; }
.md pre { background: #0a0e16; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.md blockquote { border-left: 3px solid var(--accent); margin: 14px 0; padding: 4px 14px; color: var(--text-dim); background: var(--bg-2); border-radius: 0 8px 8px 0; }
.md table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.md th { background: var(--bg-3); }

/* ---- Code runner block ---- */
.runner { margin: 22px 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.runner-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg-3); border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.runner-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.r { background: #ff5f56; } .dot.y { background: #ffbd2e; } .dot.g { background: #27c93f; }
.runner-head .label { color: var(--text-dim); margin-left: 6px; }
.runner-head .spacer { flex: 1; }
.CodeMirror { height: auto; font-family: var(--mono); font-size: 13.5px; }
.CodeMirror-scroll { min-height: 60px; }

.btn {
  border: none; border-radius: 7px; padding: 6px 13px; cursor: pointer;
  font-size: 12.5px; font-weight: 600; font-family: var(--sans);
}
.btn.run { background: var(--accent); color: #04130d; }
.btn.check { background: var(--accent-2); color: #02122e; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn:disabled { opacity: .5; cursor: progress; }

.runner-actions { display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--bg-2); }
.output {
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-word;
  padding: 12px 14px; background: #07090e; color: #cfe8df; min-height: 0; max-height: 320px; overflow: auto;
  border-top: 1px solid var(--border);
}
.output:empty { display: none; }
.output .err { color: var(--danger); }
.output .pass { color: var(--ok); font-weight: 600; }
.output .fail { color: var(--warn); font-weight: 600; }

/* Run-locally banner */
.run-local {
  margin: 18px 0; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid rgba(255,204,102,.4); background: rgba(255,204,102,.08);
  font-size: 13.5px; color: var(--text);
}
.run-local strong { color: var(--warn); }

/* Exercises */
.exercises { margin-top: 36px; }
.exercises > h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.exercise { margin: 18px 0; }
.exercise .ex-prompt { font-size: 14.5px; margin-bottom: 8px; }

/* Reference solution reveal */
.solution { border-top: 1px solid var(--border); padding: 12px 14px; background: rgba(86,211,100,.06); }
.solution-head { font-size: 12.5px; color: var(--ok); font-weight: 600; margin-bottom: 8px; }
.solution pre { margin: 0 0 10px; background: #07090e; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.solution pre code { font-family: var(--mono); font-size: 13px; }

/* Quiz */
.quiz { margin-top: 36px; }
.quiz > h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.quiz-q { margin: 16px 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.quiz-prompt { font-weight: 600; margin-bottom: 10px; font-size: 14.5px; }
.quiz-choice { display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.quiz-choice:hover { background: var(--bg-3); }
.quiz-feedback { margin-top: 8px; font-size: 13px; }
.quiz-feedback.ok { color: var(--ok); }
.quiz-feedback.no { color: var(--warn); }
.quiz-score { font-size: 13px; color: var(--text-dim); align-self: center; }

/* Mobile menu toggle + scrim */
.menu-toggle {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 40;
  width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text); font-size: 20px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.sidebar-scrim {
  display: none; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.5);
}

/* Toast */
.py-toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 50;
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 9px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

/* Welcome / empty state */
.welcome { text-align: center; padding: 56px 20px; }
.welcome h1 { font-size: 34px; margin-bottom: 4px; }
.welcome .program-name { font-size: 16px; font-weight: 600; color: var(--accent); max-width: 620px; margin: 2px auto 14px; }
.welcome p { color: var(--text-dim); max-width: 600px; margin: 8px auto; font-size: 15px; }
.welcome .welcome-sub { margin-top: 18px; font-size: 13.5px; }
.welcome .cta { margin-top: 8px; }
.welcome .cta-links { margin-top: 16px; }
a.btn { display: inline-block; text-decoration: none; }
a.btn:hover { text-decoration: none; }
.diploma-btn { padding: 11px 20px; font-size: 14px; }

.stat-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px;
  max-width: 680px; margin: 28px auto 6px;
}
.stat {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 8px;
}
.stat-num { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 11.5px; color: var(--text-dim); margin-top: 6px; text-transform: uppercase; letter-spacing: .4px; }
@media (max-width: 680px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }

/* Responsive */
@media (max-width: 880px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; z-index: 30; width: 300px; height: 100vh; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .lesson { padding: 22px 18px 100px; }
  #main { padding-top: 56px; }            /* clear the floating menu button */
  .menu-toggle { display: block; }
  .sidebar-scrim:not([hidden]) { display: block; }
}
