/* ---------- THEME VARIABLES ---------- */
:root {
  --sidebar-bg: #16181d;
  --sidebar-text: #e7eaf0;
  --sidebar-muted: #7d8494;
  --sidebar-active: #2f6fed;
  --sidebar-hover: rgba(255,255,255,.05);
  --accent: #2f6fed;
  --accent-green: #22b573;
  --font-ui: 'Source Sans 3', system-ui, sans-serif;
  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --surface-2: #eef0f3;
  --text: #1c2230;
  --text-muted: #5a6376;
  --border: #e3e6ec;
  --code-bg: #f6f7f9;
  --code-text: #2a3040;
  --editor-head-bg: #edeff2;
  --preview-bg: #ffffff;
  --tok-com: #6a9955; --tok-tag: #22863a; --tok-str: #c2410c;
  --tok-kw: #8250df; --tok-prop: #005cc5; --tok-val: #c2410c;
  --tok-sel: #22863a;
}
:root[data-theme="dark"] {
  --bg: #15181c;
  --surface: #1a1e24;
  --surface-2: #22272e;
  --text: #e5e9f0;
  --text-muted: #8b93a3;
  --border: #2a2f37;
  --code-bg: #1e2127;
  --code-text: #d4d9e0;
  --editor-head-bg: #23272e;
  --preview-bg: #22262c;
  --tok-com: #6a9955; --tok-tag: #4ec9b0; --tok-str: #ce9178;
  --tok-kw: #c586c0; --tok-prop: #9cdcfe; --tok-val: #ce9178;
  --tok-sel: #dcdcaa;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
#root { height: 100vh; }

.app-shell {
  display: grid;
  grid-template-columns: 210px 1fr;
  height: 100vh;
  transition: background .25s, color .25s;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid #000;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 20px 18px 16px;
  font-family: var(--font-display);
}
.brand-mark { font-size: 22px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -.5px; }

.progress-wrap { padding: 0 18px 14px; }
.progress-label { font-size: 11px; color: var(--sidebar-muted); margin-bottom: 6px; font-family: var(--font-mono); }
.progress-track { height: 5px; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-green)); transition: width .4s; }

.nav { flex: 1; padding: 4px 0; }
.nav-section { margin-bottom: 2px; }
.section-head {
  width: 100%; background: none; border: none; cursor: pointer;
  color: var(--sidebar-text); text-align: left;
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 18px; font-family: var(--font-ui);
}
.section-head:hover { background: var(--sidebar-hover); }
.section-titles { display: flex; flex-direction: column; }
.section-title { font-weight: 600; font-size: 14.5px; }
.section-sub { font-size: 10.5px; color: var(--sidebar-muted); margin-top: 2px; }
.chevron { color: var(--sidebar-muted); transition: transform .2s; font-size: 11px; }
.chevron.open { transform: rotate(90deg); }

.lesson-list { padding: 2px 0 6px; }
.lesson-item {
  width: 100%; background: none; border: none; cursor: pointer;
  color: var(--sidebar-muted); text-align: left;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px 8px 20px; font-size: 13px; font-family: var(--font-ui);
  transition: background .12s, color .12s;
}
.lesson-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.lesson-item.active {
  background: var(--sidebar-active); color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 #a9c5ff;
}
.check {
  width: 15px; height: 15px; border-radius: 50%;
  border: 1.5px solid var(--sidebar-muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; flex-shrink: 0;
}
.check.done { background: var(--accent-green); border-color: var(--accent-green); color: #fff; }
.lesson-item.active .check { border-color: #cfe0ff; }
.lesson-label { flex: 1; }

.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-foot a { color: var(--sidebar-muted); font-size: 12px; text-decoration: none; }
.sidebar-foot a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- MAIN ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); transition: background .25s; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 22px; border-bottom: 1px solid var(--border);
  background: var(--bg); transition: background .25s, border-color .25s;
}
.hamburger { display: none; background: none; border: none; font-size: 20px; color: var(--text); cursor: pointer; }
.topnav { display: flex; gap: 22px; flex: 1; }
.topnav-link { color: var(--text-muted); font-size: 15px; cursor: pointer; text-decoration: none; }
.topnav-link.active, .topnav-link:hover { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.theme-toggle { display: flex; background: var(--surface); border-radius: 20px; padding: 3px; border: 1px solid var(--border); }
.th-btn {
  border: none; background: none; cursor: pointer; font-size: 15px;
  width: 30px; height: 26px; border-radius: 16px; color: var(--text-muted);
  transition: background .2s, color .2s;
}
.th-btn.on { background: var(--bg); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.view-toggle {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; color: var(--text); font-size: 14px;
  font-family: var(--font-ui);
}
.view-toggle:hover { border-color: var(--accent); }
.vt-label { font-weight: 500; }
.vi { opacity: .35; font-size: 14px; }
.vi.on { opacity: 1; }

/* ---------- SPLIT ---------- */
.split {
  flex: 1; display: grid; grid-template-columns: minmax(340px, 1fr) minmax(420px, 1.15fr);
  overflow: hidden;
}
.lesson-panel {
  padding: 26px 30px; overflow-y: auto; border-right: 1px solid var(--border);
}
.breadcrumb { font-size: 17px; font-weight: 600; margin-bottom: 22px; font-family: var(--font-display); }
.crumb-section { color: var(--accent); }
.crumb-sep { color: var(--text-muted); }
.crumb-lesson { color: var(--text); }

.explain p { font-size: 15.5px; line-height: 1.7; margin-bottom: 16px; color: var(--text); }
.explain b { font-weight: 700; }
.explain i { font-style: italic; }
.inline-code {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--surface-2); padding: 2px 6px; border-radius: 4px;
  color: var(--accent); white-space: nowrap;
}

.task-callout {
  margin-top: 8px; padding: 14px 16px; background: var(--surface);
  border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0;
  font-size: 15px; line-height: 1.6;
}
.task-word { font-weight: 700; }
.task-callout .inline-code { background: var(--bg); }

.done-banner {
  margin-top: 18px; padding: 12px 16px; border-radius: 8px;
  background: rgba(34,181,115,.12); color: var(--accent-green);
  font-weight: 600; font-size: 14px; border: 1px solid rgba(34,181,115,.3);
}

/* ---------- WORKSPACE ---------- */
.workspace { display: flex; flex-direction: column; overflow: hidden; padding: 16px; gap: 12px; }
.editor-block {
  flex: 1; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  min-height: 180px;
}
.editor-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--editor-head-bg); border-bottom: 1px solid var(--border);
}
.filename { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }
.run-btn {
  background: var(--accent-green); color: #fff; border: none; cursor: pointer;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  font-family: var(--font-ui); transition: transform .08s, filter .15s;
}
.run-btn:hover { filter: brightness(1.08); }
.run-btn:active { transform: scale(.96); }

/* editor */
.editor-wrap {
  flex: 1; display: flex; background: var(--code-bg); overflow: hidden; position: relative;
}
.gutter {
  background: var(--code-bg); color: var(--text-muted); opacity: .55;
  font-family: var(--font-mono); font-size: 13px; line-height: 21px;
  padding: 12px 8px 12px 12px; text-align: right; user-select: none;
  overflow: hidden; min-width: 40px;
}
.gutter-line { height: 21px; }
.code-area { flex: 1; position: relative; overflow: hidden; }
.highlight-layer, .code-input {
  margin: 0; border: 0; padding: 12px 14px;
  font-family: var(--font-mono); font-size: 13px; line-height: 21px;
  white-space: pre; overflow: auto; tab-size: 2;
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.highlight-layer { pointer-events: none; color: var(--code-text); }
.highlight-layer code { font-family: inherit; }
.code-input {
  background: transparent; color: transparent; caret-color: var(--text);
  resize: none; outline: none;
}
.code-input::selection { background: rgba(79,140,255,.35); }

/* tokens */
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-tag { color: var(--tok-tag); }
.tok-str { color: var(--tok-str); }
.tok-kw { color: var(--tok-kw); }
.tok-prop { color: var(--tok-prop); }
.tok-val { color: var(--tok-val); }
.tok-sel { color: var(--tok-sel); }

/* preview */
.preview-pane {
  flex: 1; border: 1px solid var(--border); border-radius: 10px;
  background: var(--preview-bg); overflow: hidden; position: relative;
  min-height: 160px; transition: background .25s;
}
.preview-idle {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 14px;
}
.preview-scroll { height: 100%; overflow: auto; }
.preview-scroll.mobile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 16px 0; background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(128,128,128,.04) 10px, rgba(128,128,128,.04) 20px);
}
.device-fluid { width: 100%; height: 100%; }
.device-frame {
  width: 270px; height: 480px;
  border: 8px solid #2a2f37; border-radius: 22px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.35); background: #fff; flex-shrink: 0;
}
.device-badge {
  margin-top: 10px; font-family: var(--font-mono); font-size: 11px;
  color: var(--text-muted); background: var(--surface); padding: 3px 10px; border-radius: 10px;
}
.preview-frame { width: 100%; height: 100%; border: none; background: #fff; }
.device-frame .preview-frame {
  width: 540px; height: 960px; transform: scale(.5); transform-origin: top left;
}
.sparkle { position: absolute; bottom: 10px; right: 14px; color: var(--text-muted); opacity: .3; font-size: 20px; pointer-events: none; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 12px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); z-index: 100; animation: pop .3s ease;
  color: #fff;
}
.toast-success { background: var(--accent-green); }
.toast-info { background: var(--accent); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

.scrim { display: none; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 60;
    transform: translateX(-100%); transition: transform .25s;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; }
  .hamburger { display: block; }
  .topnav { display: none; }
  .split { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .lesson-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: 45vh; }
  .workspace { min-height: 60vh; }
  .vt-label { display: none; }
}
@media (max-width: 480px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .lesson-panel { padding: 18px; }
}