:root {
  --bg: #0d1117;
  --bg-2: #11161f;
  --panel: #161b24;
  --panel-2: #1c2330;
  --border: #2a3342;
  --text: #e6edf3;
  --muted: #8b98a9;
  --faint: #5d6a7c;
  --accent: #ffd43b;      /* Python yellow */
  --accent-2: #4b8bbe;    /* Python blue */
  --green: #3fb950;
  --red: #f85149;
  --orange: #f0883e;
  --purple: #a371f7;
  --code-bg: #0b0f15;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
code, pre, .mono { font-family: var(--mono); }
button { font: inherit; }
.hidden { display: none !important; }

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  min-height: 64px;
  flex-shrink: 0;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; white-space: nowrap; }
.brand-mark {
  display: inline-block; background: linear-gradient(135deg, var(--accent-2), #306998);
  color: #fff; border-radius: 6px; padding: 0 6px; margin-right: 2px;
}
.brand-mp { color: var(--accent); }
.nav-stats { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: center; min-width: 0; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 12px; display: flex; align-items: center; gap: 10px; min-height: 46px;
}
.mp-stat .stat-label { color: var(--accent); font-weight: 700; font-size: 12px; }
.mp-stat .stat-value { font: 700 22px var(--mono); color: var(--accent); min-width: 56px; text-align: right; transition: transform .2s; }
.mp-stat .stat-value.bump { transform: scale(1.18); }
.rank-stat { flex-direction: column; align-items: stretch; gap: 3px; width: 300px; }
.rank-row { display: flex; align-items: center; gap: 8px; }
.rank-badge {
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px;
  background: var(--accent-2); color: #fff;
}
.rank-title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .6s ease; }
.rank-next { font-size: 11px; color: var(--muted); }
.streak-stat { min-width: 190px; }
.streak-icon { font-size: 20px; }
.streak-title { font-weight: 600; font-size: 13px; }
.streak-sub { font-size: 11px; color: var(--muted); }
.streak-stat.forfeit { border-color: #5a2a2a; }
.streak-stat.forfeit .streak-icon { filter: grayscale(1); opacity: .6; }
.streak-stat.earned { border-color: #2e5a35; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px;
  white-space: nowrap; transition: filter .15s, background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .quiz-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }
.btn-run { background: #1f3d64; border-color: #2d5a91; }
.btn-submit { background: #1f6f3a; border-color: #2a8c4b; }
.btn-unlock { background: transparent; border-color: #6b4b16; color: var(--accent); }
.btn-danger { background: #5c1f1f; border-color: #8a2b2b; }
.btn-primary { background: var(--accent); color: #111; border-color: var(--accent); }
.icon-btn { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); }

/* ── Workspace ──────────────────────────────────────────── */
.workspace { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 250px; flex-shrink: 0; overflow-y: auto; background: var(--bg-2);
  border-right: 1px solid var(--border); padding: 10px 8px 24px;
}
.sidebar.collapsed { display: none; }
.chapter { margin-bottom: 10px; }
.chapter-head { padding: 6px 8px; }
.chapter-num { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; justify-content: space-between; }
.chapter-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.chapter-bar { height: 3px; background: var(--panel-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.chapter-bar > div { height: 100%; background: var(--green); transition: width .4s; }
.nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none;
  border: none; color: var(--muted); padding: 6px 8px 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-item .state { width: 18px; text-align: center; flex-shrink: 0; font-size: 12px; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .quiz-dot { font-size: 10px; color: var(--faint); }
.nav-item .quiz-dot.done { color: var(--purple); }
.nav-item.boss .label { color: var(--orange); font-weight: 600; }

.lesson-pane {
  width: 40%; max-width: 560px; min-width: 340px; overflow-y: auto; padding: 22px 24px 48px;
  border-right: 1px solid var(--border);
}
.ide-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Lesson content ─────────────────────────────────────── */
.crumb { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.lesson-title { font-size: 22px; line-height: 1.25; margin: 4px 0 10px; letter-spacing: -0.01em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); }
.chip.ok { color: var(--green); border-color: #2e5a35; }
.chip.boss { color: var(--orange); border-color: #6b3d1a; }
.chip.warn { color: var(--red); border-color: #5a2a2a; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.card.task { border-color: #2d5a91; background: #131c2a; }
.card.task h3 { color: #79b8ff; }
.card.boss-card { border-color: #6b3d1a; background: #1d1610; }
.card.boss-card h3 { color: var(--orange); }
.md p { margin: 0 0 10px; }
.md p:last-child, .md ul:last-child, .md ol:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px;
  font-size: 12.5px; color: #ffd98a; word-break: break-word;
}
.md strong { color: #fff; }

.hint { border-top: 1px solid var(--border); padding: 8px 0; }
.hint:first-of-type { border-top: none; }
.hint-num { font-size: 11px; font-weight: 700; color: var(--accent); margin-right: 6px; }

.quiz-q { margin-bottom: 10px; font-weight: 500; }
.quiz-option {
  display: block; width: 100%; text-align: left; margin: 6px 0; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 13.5px;
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent-2); }
.quiz-option.correct { border-color: var(--green); background: #12261a; }
.quiz-option.wrong { border-color: var(--red); background: #2a1414; animation: shake .3s; }
.quiz-option:disabled { cursor: default; }
.quiz-option .letter { font-weight: 700; color: var(--muted); margin-right: 8px; }
.quiz-feedback { margin-top: 8px; font-size: 13px; }
.quiz-feedback.ok { color: var(--green); }
.quiz-feedback.bad { color: var(--red); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

pre.solution {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  overflow-x: auto; font-size: 12.5px; line-height: 1.5; margin: 0 0 10px; white-space: pre;
}
.done-banner {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: #12261a; border: 1px solid #2e5a35; color: var(--green); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; font-weight: 600;
}

/* ── Editor ─────────────────────────────────────────────── */
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.file-tab { display: flex; align-items: center; gap: 8px; font: 13px var(--mono); color: var(--muted); }
.file-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.editor-host { flex: 1; min-height: 160px; position: relative; background: #0f141b; }
.editor-host textarea.fallback-editor {
  width: 100%; height: 100%; resize: none; border: none; outline: none; padding: 12px 16px;
  background: #0f141b; color: var(--text); font: 14px/1.6 var(--mono); tab-size: 4;
}
.editor-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* ── Terminal ───────────────────────────────────────────── */
.terminal { height: 36%; min-height: 150px; display: flex; flex-direction: column; border-top: 1px solid var(--border); background: var(--code-bg); }
.terminal-bar { display: flex; align-items: center; gap: 10px; padding: 5px 10px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.terminal-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.runtime-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-loading { background: var(--accent); animation: pulse 1s infinite; }
.dot-ready { background: var(--green); }
.dot-busy { background: var(--accent-2); animation: pulse .6s infinite; }
.dot-error { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }
.terminal-body { flex: 1; overflow-y: auto; padding: 10px 14px; font: 13px/1.5 var(--mono); }
.term-block { margin-bottom: 12px; }
.term-meta { color: var(--faint); font-size: 12px; }
.term-out { white-space: pre-wrap; word-break: break-word; color: #d6e2ee; }
.term-err { white-space: pre-wrap; word-break: break-word; color: #ff8b84; }
.term-empty { color: var(--faint); font-style: italic; }
.badge { display: inline-block; font: 700 11px var(--font); padding: 2px 8px; border-radius: 4px; margin-right: 8px; letter-spacing: .04em; }
.badge.pass { background: var(--green); color: #04130a; }
.badge.fail { background: var(--red); color: #fff; }
.badge.info { background: var(--panel-2); color: var(--muted); }
.test-line { margin-top: 6px; display: flex; align-items: baseline; gap: 4px; }
.test-line .msg { white-space: pre-wrap; }

/* ── Modal & toasts ─────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(1, 4, 9, .7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px 24px; width: min(480px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal h2 { margin: 0 0 10px; font-size: 19px; }
.modal p { color: #c9d4df; margin: 0 0 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.rankup-emoji { font-size: 48px; text-align: center; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; min-width: 220px; max-width: 340px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: toast-in .25s ease;
}
.toast.gain { border-left-color: var(--green); }
.toast.loss { border-left-color: var(--red); }
.toast b { font-family: var(--mono); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1180px) {
  .rank-stat { width: 220px; }
  .streak-stat { display: none; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .navbar { flex-wrap: wrap; padding: 8px 16px; }
  .nav-stats { order: 3; width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .rank-stat { flex: 1; width: auto; }
  .workspace { flex-direction: column; overflow: visible; }
  .sidebar { width: 100%; max-height: 260px; border-right: none; border-bottom: 1px solid var(--border); }
  .lesson-pane { width: 100%; max-width: none; min-width: 0; border-right: none; padding: 18px 16px; overflow: visible; }
  .ide-pane { min-height: 720px; }
  .editor-host { min-height: 360px; }
}
