/* ==========================================================================
   GPT Academy — estilos
   ========================================================================== */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-read: "Charter", "Iowan Old Style", "Source Serif Pro", Georgia, serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 10px;
  --sidebar-w: 300px;
  --topbar-h: 52px;
}
[data-theme="dark"] {
  --bg: #111318;
  --bg-2: #171a21;
  --bg-3: #1e222b;
  --line: #2a2f3a;
  --text: #e6e3dc;
  --text-2: #a7a59e;
  --text-3: #75746f;
  --accent: #ef7d4f;
  --accent-soft: rgba(239,125,79,.14);
  --teal: #4fc1b0;
  --teal-soft: rgba(79,193,176,.14);
  --danger: #ff6b6b;
  --code-bg: #0c0e12;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #f7f4ee;
  --bg-2: #fffdf9;
  --bg-3: #efeae1;
  --line: #e1dacd;
  --text: #22211e;
  --text-2: #5d5a53;
  --text-3: #8f8b82;
  --accent: #c8532a;
  --accent-soft: rgba(200,83,42,.10);
  --teal: #13867a;
  --teal-soft: rgba(19,134,122,.10);
  --danger: #c62828;
  --code-bg: #f6f8fa;
  --shadow: 0 8px 30px rgba(60,40,20,.10);
}

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

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; letter-spacing: -.01em; }
.brand-sub { color: var(--text-3); font-size: 13px; }
.topbar-progress { display: flex; align-items: center; gap: 8px; margin-left: 18px; color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.bar { width: 140px; height: 6px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--teal)); border-radius: 99px; transition: width .4s; }
.spacer { flex: 1; }
.icon-btn { background: none; border: 1px solid transparent; color: var(--text-2); font-size: 17px; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.kernel-chip { font-size: 12px; color: var(--text-3); padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.kernel-chip.busy { color: var(--accent); border-color: var(--accent); }
.kernel-chip.idle { color: var(--teal); border-color: color-mix(in srgb, var(--teal) 50%, transparent); }

/* ---------- layout ---------- */
.layout { display: flex; padding-top: var(--topbar-h); height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--line);
  background: var(--bg-2); padding: 12px 10px 40px; transition: margin-left .2s;
}
body.sidebar-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
.main { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.scroll { overflow-y: auto; height: 100%; }

.search-wrap { padding: 2px 4px 10px; }
#search { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 13px; outline: none; }
#search:focus { border-color: var(--accent); }

.nav-section { margin-bottom: 6px; }
.nav-section-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px; cursor: pointer; user-select: none; border-radius: 8px; color: var(--text-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.nav-section-head:hover { background: var(--bg-3); }
.nav-section-head .count { margin-left: auto; font-weight: 500; color: var(--text-3); text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.nav-section-head .chev { transition: transform .15s; font-size: 10px; }
.nav-section.collapsed .chev { transform: rotate(-90deg); }
.nav-section.collapsed .nav-items { display: none; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 6px 8px 6px 10px; border-radius: 7px; color: var(--text); font-size: 13.5px; line-height: 1.3; cursor: pointer; }
.nav-item:hover { background: var(--bg-3); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .dot { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--line); flex-shrink: 0; display: grid; place-items: center; font-size: 10px; color: transparent; }
.nav-item.visited .dot { border-color: var(--text-3); }
.nav-item.done .dot { background: var(--teal); border-color: var(--teal); color: #fff; }
.nav-item .tag { margin-left: auto; font-size: 10px; color: var(--text-3); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; }

/* ---------- home ---------- */
.home { max-width: 1040px; margin: 0 auto; padding: 48px 40px 80px; }
.hero h1 { font-family: var(--font-read); font-size: 44px; line-height: 1.08; margin: 0 0 14px; letter-spacing: -.02em; font-weight: 600; }
.hero h1 em { color: var(--accent); font-style: italic; }
.hero p { color: var(--text-2); font-size: 17px; max-width: 680px; line-height: 1.55; margin: 0 0 22px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-size: 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--bg-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-top: 36px; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: transform .12s, border-color .12s; color: var(--text); }
.card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.card .icon { font-size: 22px; }
.card h3 { margin: 10px 0 4px; font-size: 16px; }
.card p { margin: 0 0 12px; color: var(--text-2); font-size: 13px; line-height: 1.45; }
.card .bar { width: 100%; }
.card .meta { font-size: 12px; color: var(--text-3); margin-top: 6px; font-variant-numeric: tabular-nums; }
.home h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin: 44px 0 12px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.step { border-left: 2px solid var(--accent); padding: 4px 0 4px 14px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.step b { color: var(--text); display: block; margin-bottom: 2px; }
.env { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { font-size: 12.5px; padding: 5px 10px; border-radius: 99px; background: var(--bg-2); border: 1px solid var(--line); color: var(--text-2); font-family: var(--font-mono); }
.pill.ok { border-color: color-mix(in srgb, var(--teal) 50%, transparent); color: var(--teal); }
.pill.bad { border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }
.continue { margin-top: 26px; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.continue .label { color: var(--text-2); font-size: 13px; }
.continue .title { font-weight: 600; }

/* ---------- lesson ---------- */
.lesson-head { display: flex; align-items: center; gap: 14px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.lesson-head .crumb { font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.lesson-head h1 { font-size: 18px; margin: 2px 0 0; letter-spacing: -.01em; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--bg-2); }
.seg button { background: none; border: 0; padding: 7px 13px; color: var(--text-2); cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lesson-body { flex: 1; display: flex; min-height: 0; }
.pane { min-width: 0; height: 100%; overflow-y: auto; }
.pane.theory { flex: 1; }
.pane.practice { flex: 1; background: var(--bg); }
.lesson-body.split .pane.theory { flex: 0 0 var(--split, 50%); border-right: 1px solid var(--line); }
.lesson-body:not(.split) .divider { display: none; }
.lesson-body.mode-theory .pane.practice, .lesson-body.mode-practice .pane.theory { display: none; }
.divider { width: 6px; margin-left: -3px; margin-right: -3px; cursor: col-resize; z-index: 2; position: relative; }
.divider:hover, .divider.drag { background: var(--accent-soft); }
.done-toggle.on { background: var(--teal-soft); color: var(--teal); border-color: var(--teal); }

/* ---------- theory (markdown) ---------- */
.theory-wrap { display: flex; gap: 32px; max-width: 1180px; margin: 0 auto; padding: 34px 40px 100px; }
.lesson-body.split .theory-wrap { padding: 26px 28px 100px; }
.lesson-body.split .toc { display: none; }
.md { flex: 1; min-width: 0; max-width: 780px; font-family: var(--font-read); font-size: 18px; line-height: 1.68; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--font-ui); letter-spacing: -.015em; line-height: 1.25; scroll-margin-top: 20px; }
.md h1 { font-size: 34px; margin: 0 0 18px; }
.md h2 { font-size: 25px; margin: 46px 0 14px; padding-top: 18px; border-top: 1px solid var(--line); }
.md h3 { font-size: 20px; margin: 32px 0 10px; }
.md h4 { font-size: 17px; margin: 24px 0 8px; }
.md p, .md li { color: var(--text); }
.md blockquote { margin: 18px 0; padding: 4px 18px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; color: var(--text-2); }
.md code { font-family: var(--font-mono); font-size: .82em; background: var(--bg-3); padding: .12em .38em; border-radius: 5px; }
.md pre code { background: none; padding: 0; font-size: 13.5px; }
.md table { border-collapse: collapse; width: 100%; font-family: var(--font-ui); font-size: 14px; margin: 18px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--bg-3); }
.md tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-3) 40%, transparent); }
.md img { max-width: 100%; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 34px 0; }
.md .mermaid { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 20px 0; text-align: center; overflow-x: auto; font-family: var(--font-ui); }
.toc { width: 230px; flex-shrink: 0; position: sticky; top: 20px; align-self: flex-start; max-height: calc(100vh - 160px); overflow-y: auto; font-size: 13px; font-family: var(--font-ui); }
.toc .toc-title { text-transform: uppercase; font-size: 11px; letter-spacing: .08em; color: var(--text-3); margin-bottom: 8px; }
.toc a { display: block; color: var(--text-2); padding: 3px 0 3px 10px; border-left: 2px solid var(--line); line-height: 1.35; }
.toc a.h3 { padding-left: 22px; font-size: 12.5px; }
.toc a:hover, .toc a.on { color: var(--accent); border-left-color: var(--accent); text-decoration: none; }
@media (max-width: 1250px) { .toc { display: none; } }

/* code block w/ toolbar */
.codeblock { margin: 18px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--code-bg); overflow: hidden; font-family: var(--font-ui); }
.codeblock .cb-bar { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); font-size: 12px; color: var(--text-3); }
.codeblock .cb-bar .lang { text-transform: lowercase; font-family: var(--font-mono); }
.codeblock .cb-bar .grow { flex: 1; }
.codeblock pre { margin: 0; padding: 14px 16px; overflow-x: auto; line-height: 1.55; }
.codeblock .CodeMirror { height: auto; font-size: 13.5px; }
.codeblock .snippet-out { border-top: 1px dashed var(--line); }
.codeblock .snippet-out:empty { display: none; }
.lesson-foot { margin-top: 60px; padding-top: 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; font-family: var(--font-ui); }

/* ---------- notebook ---------- */
.nb { max-width: 1020px; margin: 0 auto; padding: 0 22px 120px; }
.nb-toolbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.nb-toolbar .grow { flex: 1; }
.nb-toolbar .nb-name { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); margin-right: 6px; }
.nb-toolbar select { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; font-size: 12.5px; }
.nb-status { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nb-status.busy { color: var(--accent); }
.nb-status.idle { color: var(--teal); }
.nb-note { font-size: 13px; color: var(--text-2); background: var(--teal-soft); border: 1px solid color-mix(in srgb, var(--teal) 35%, transparent); padding: 10px 14px; border-radius: 9px; margin-bottom: 16px; line-height: 1.5; }

.cell { position: relative; display: grid; grid-template-columns: 62px 1fr; gap: 0 8px; margin: 6px 0; border-radius: var(--radius); border: 1px solid transparent; padding: 4px 6px 4px 0; }
.cell:hover { border-color: var(--line); }
.cell.selected { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.cell .gutter { text-align: right; padding-top: 9px; font-family: var(--font-mono); font-size: 12px; color: var(--text-3); user-select: none; }
.cell .gutter .run { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-2); color: var(--text-2); cursor: pointer; font-size: 11px; margin-bottom: 4px; }
.cell .gutter .run:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.cell.running .gutter .run { background: var(--accent); color: #fff; border-color: var(--accent); animation: pulse 1.2s infinite; }
.cell.queued .gutter .run { border-color: var(--accent); color: var(--accent); }
@keyframes pulse { 50% { opacity: .55; } }
.cell .count { display: block; }
.cell .editor { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.cell .editor .CodeMirror { height: auto; font-size: 13.5px; background: transparent; }
.cell .editor .CodeMirror-scroll { max-height: 70vh; }
.cell-tools { position: absolute; right: 8px; top: -11px; display: none; gap: 2px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 7px; padding: 2px; z-index: 3; }
.cell:hover .cell-tools, .cell.selected .cell-tools { display: flex; }
.cell-tools button { background: none; border: 0; color: var(--text-2); cursor: pointer; font-size: 12px; padding: 3px 7px; border-radius: 5px; }
.cell-tools button:hover { background: var(--bg-3); color: var(--text); }
.cell.md-cell .body { font-family: var(--font-read); font-size: 16.5px; line-height: 1.62; padding: 2px 8px; }
.cell.md-cell .body h1 { font-size: 28px; margin: 6px 0 12px; font-family: var(--font-ui); }
.cell.md-cell .body h2 { font-size: 21px; margin: 18px 0 8px; font-family: var(--font-ui); }
.cell.md-cell .body h3 { font-size: 17px; font-family: var(--font-ui); }
.cell.md-cell textarea { width: 100%; min-height: 140px; font-family: var(--font-mono); font-size: 13px; background: var(--code-bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px; resize: vertical; }
.add-cell { display: flex; justify-content: center; gap: 8px; margin: 18px 0; }

/* outputs */
.outputs { font-family: var(--font-mono); font-size: 13px; }
.outputs:empty { display: none; }
.out.stdout pre, .out.stderr pre, .out.error pre { max-height: 440px; overflow-y: auto; }
.out { padding: 6px 10px; overflow-x: auto; }
.out pre { margin: 0; white-space: pre-wrap; word-break: break-word; line-height: 1.5; font-family: var(--font-mono); }
.out.stderr pre { color: #e9a970; }
.out.error { background: color-mix(in srgb, var(--danger) 9%, transparent); border-left: 3px solid var(--danger); border-radius: 0 6px 6px 0; }
.out img { max-width: 100%; background: #fff; border-radius: 6px; }
.out.html { font-family: var(--font-ui); }
.out.html table { border-collapse: collapse; font-size: 12.5px; }
.out.html td, .out.html th { border: 1px solid var(--line); padding: 3px 8px; }
.out-tools { display: flex; gap: 6px; padding: 2px 10px; }
.out-tools button { background: none; border: 0; color: var(--text-3); font-size: 11.5px; cursor: pointer; padding: 0; }
.out-tools button:hover { color: var(--accent); }
.ansi-bold { font-weight: 700; }

/* CodeMirror theming */
.CodeMirror { font-family: var(--font-mono); background: var(--code-bg); color: var(--text); padding: 6px 0; }
.CodeMirror-cursor { border-left-color: var(--accent); }
.CodeMirror-selected { background: color-mix(in srgb, var(--accent) 22%, transparent) !important; }
.CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--accent) 28%, transparent) !important; }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { padding: 0 14px; }
[data-theme="dark"] .cm-keyword { color: #ff9f7a; }
[data-theme="dark"] .cm-def { color: #7fd1ff; }
[data-theme="dark"] .cm-variable-2 { color: #c8c3ff; }
[data-theme="dark"] .cm-builtin { color: #6fe0c8; }
[data-theme="dark"] .cm-string { color: #b8e28a; }
[data-theme="dark"] .cm-number { color: #f3c96b; }
[data-theme="dark"] .cm-comment { color: #6f7685; font-style: italic; }
[data-theme="dark"] .cm-operator { color: #e6e3dc; }
[data-theme="dark"] .cm-property { color: #a9c7ff; }
[data-theme="dark"] .cm-meta { color: #ffd479; }
[data-theme="light"] .cm-keyword { color: #b23d14; }
[data-theme="light"] .cm-def { color: #1f5fb0; }
[data-theme="light"] .cm-builtin { color: #0b7a6c; }
[data-theme="light"] .cm-string { color: #4c7a12; }
[data-theme="light"] .cm-number { color: #a5650a; }
[data-theme="light"] .cm-comment { color: #8f8b82; font-style: italic; }
[data-theme="dark"] .CodeMirror-matchingbracket { color: var(--teal) !important; text-decoration: underline; }

/* misc */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px; font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.loading { padding: 60px; text-align: center; color: var(--text-3); }
.kbd { font-family: var(--font-mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; padding: 1px 5px; border-radius: 4px; color: var(--text-2); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .sidebar { position: fixed; top: var(--topbar-h); bottom: 0; z-index: 15; }
  body:not(.sidebar-open) .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  .brand-sub, .topbar-progress { display: none; }
  .theory-wrap, .home { padding: 24px 18px 80px; }
}
.lesson-body.split .nb-toolbar .nb-name { display: none; }
.lesson-body.split .nb-toolbar .btn.small { padding: 4px 8px; }

.lang-toggle button { padding: 5px 10px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.lang-note { font-family: var(--font-ui); font-size: 13.5px; line-height: 1.5; padding: 9px 14px; border-radius: 9px; margin: 0 0 22px; background: var(--accent-soft); color: var(--text-2); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.lang-note.subtle { background: transparent; border-color: var(--line); color: var(--text-3); font-size: 12.5px; }
