:root {
  --bg: #f6f7fb; --panel: #ffffff; --panel2: #f0f2f8; --text: #1b2033; --muted: #66708a;
  --line: #e1e5f0; --accent: #2f5fe8; --accent2: #7c4dff; --good: #12a150; --bad: #d92d3f; --warn: #c77a00;
  --code-bg: #fbfcff; --code-text: #1b2033; --shadow: 0 1px 2px rgba(20,30,70,.06), 0 8px 24px rgba(20,30,70,.06);
  --btn: #2f5fe8; --kw: #7c3aed; --str: #0f7b4b; --num: #b45309; --com: #66708a; --def: #1d4ed8;
}
:root[data-theme="dark"] {
  --btn: #3b63e6;
  --bg: #0e1220; --panel: #161b2e; --panel2: #1d2340; --text: #e6e9f5; --muted: #98a2c3;
  --line: #2a3256; --accent: #6d94ff; --accent2: #a58bff; --good: #38d27d; --bad: #ff6b7a; --warn: #ffb54d;
  --code-bg: #0f1426; --code-text: #e6e9f5; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  --kw: #b79cff; --str: #7ee0a8; --num: #ffc36b; --com: #8a95bd; --def: #7fb0ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--panel2); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
h1, h2, h3, h4, h5 { line-height: 1.25; margin: 1.4em 0 .5em; }
h1 { font-size: 1.9rem; margin-top: 0; }
h2 { font-size: 1.4rem; } h3 { font-size: 1.15rem; }
.muted { color: var(--muted); }

#shell { display: flex; min-height: 100vh; }
#sidebar { width: 250px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; color: var(--text); padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-weight: 800; }
#nav { display: flex; flex-direction: column; gap: 3px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text); font-weight: 500; }
#nav a i { font-style: normal; width: 20px; text-align: center; color: var(--muted); }
#nav a:hover { background: var(--panel2); text-decoration: none; }
#nav a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
#nav a.active i { color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.chip { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); background: var(--panel2); padding: 7px 10px; border-radius: 999px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.chip[data-state="ready"] .dot { background: var(--good); }
.chip[data-state="loading"] .dot, .chip[data-state="busy"] .dot { background: var(--warn); animation: pulse 1s infinite; }
.chip[data-state="error"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
#menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 560px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
#search-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; box-shadow: var(--shadow); max-height: 60vh; overflow: auto; }
#search-results a { display: block; padding: 9px 14px; color: var(--text); border-bottom: 1px solid var(--line); }
#search-results a:last-child { border-bottom: 0; }
#search-results a:hover { background: var(--panel2); text-decoration: none; }
#search-results small { color: var(--muted); display: block; }
.streak { margin-left: auto; font-weight: 700; color: var(--warn); white-space: nowrap; }

#view { padding: 28px 32px 80px; max-width: 1100px; width: 100%; margin: 0 auto; outline: none; }
button { font: inherit; cursor: pointer; }
.btn, button.primary, .mini.primary { background: var(--btn); color: #fff; border: 0; padding: 9px 16px; border-radius: 10px; font-weight: 600; display: inline-block; }
.btn:hover, button.primary:hover { filter: brightness(1.08); text-decoration: none; }
.btn.alt, button.alt { background: var(--panel2); color: var(--text); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); padding: 8px 12px; border-radius: 10px; }
button:disabled { opacity: .55; cursor: default; }
.mini { background: var(--panel2); color: var(--text); border: 1px solid var(--line); padding: 3px 10px; border-radius: 8px; font-size: .82rem; }
.mini.primary { padding: 3px 12px; border: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.hero { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, var(--panel)), color-mix(in srgb, var(--accent2) 16%, var(--panel))); border: 1px solid var(--line); border-radius: 20px; padding: 28px; margin-bottom: 20px; }
.hero h1 { margin-bottom: 6px; }
.stat { text-align: center; }
.stat b { font-size: 1.8rem; display: block; }
.stat span { color: var(--muted); font-size: .85rem; }
.bar { height: 9px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 99px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--panel2); color: var(--muted); font-size: .78rem; font-weight: 600; }
.pill.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.pill.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }

.week-link { display: flex; gap: 14px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); margin-bottom: 8px; }
.week-link:hover { border-color: var(--accent); text-decoration: none; }
.week-num { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--panel2); font-weight: 700; flex: none; }
.week-link.done .week-num { background: var(--good); color: #fff; }
.daylist a { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); margin-bottom: 8px; color: var(--text); }
.daylist a:hover { border-color: var(--accent); text-decoration: none; }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .8rem; color: transparent; flex: none; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 9px 14px; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

.lesson { max-width: 820px; }
.lesson p, .lesson li { font-size: 1.02rem; }
.lesson blockquote { margin: 1em 0; padding: 10px 16px; border-left: 4px solid var(--accent); background: var(--panel2); border-radius: 0 10px 10px 0; }
.table-wrap { overflow-x: auto; margin: 1em 0; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; vertical-align: top; }
th { background: var(--panel2); }

.cell { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 14px 0; background: var(--code-bg); }
.cell-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cell-label { flex: 1; font-size: .78rem; color: var(--muted); font-weight: 600; min-width: 140px; }
.cell-note { padding: 8px 12px; font-size: .85rem; color: var(--warn); border-top: 1px solid var(--line); background: var(--panel2); }
.stdin { display: block; width: 100%; border: 0; border-top: 1px dashed var(--line); background: var(--code-bg); color: var(--text); padding: 8px 12px; font: .9rem ui-monospace, Consolas, monospace; resize: vertical; }
.out { border-top: 1px solid var(--line); padding: 10px 14px; background: var(--code-bg); }
.out pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: .9rem/1.5 ui-monospace, Consolas, monospace; color: var(--code-text); }
.out .err { color: var(--bad); } .out .echo { color: var(--accent); }
.out-status { color: var(--muted); font-size: .8rem; }
.out-imgs img { max-width: 100%; border-radius: 8px; margin-top: 8px; background: #fff; }

.CodeMirror { height: auto; font: .92rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--code-bg); color: var(--code-text); }
.CodeMirror-gutters { background: var(--code-bg); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--com); }
.CodeMirror-cursor { border-left-color: var(--text); }
.CodeMirror-selected { background: color-mix(in srgb, var(--accent) 25%, transparent) !important; }
.cm-s-default .cm-keyword { color: var(--kw); } .cm-s-default .cm-string, .cm-s-default .cm-string-2 { color: var(--str); }
.cm-s-default .cm-number { color: var(--num); } .cm-s-default .cm-comment { color: var(--com); font-style: italic; }
.cm-s-default .cm-def, .cm-s-default .cm-builtin { color: var(--def); } .cm-s-default .cm-variable-2 { color: var(--text); }
.cm-s-default .cm-operator, .cm-s-default .cm-variable, .cm-s-default .cm-property { color: var(--code-text); }
.cm-s-default .cm-meta { color: var(--num); } .cm-s-default .cm-atom { color: var(--num); }

.quiz-q { margin-bottom: 18px; }
.opt { display: block; width: 100%; text-align: left; padding: 10px 14px; margin: 6px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--panel)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--panel)); }
.why { margin-top: 6px; font-size: .92rem; color: var(--muted); }
.test-row { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .93rem; }
.test-row:last-child { border-bottom: 0; }
.test-row .msg { color: var(--muted); font-size: .85rem; }
details { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 10px 0; background: var(--panel); }
details summary { cursor: pointer; font-weight: 600; }

.ws { display: grid; grid-template-columns: 210px 1fr; gap: 14px; }
.ws-files { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; align-self: start; }
.ws-files .f { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-family: ui-monospace, Consolas, monospace; font-size: .88rem; }
.ws-files .f.on { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.ws-files .f:hover { background: var(--panel2); }
.ws-files .x { color: var(--muted); border: 0; background: none; }
.editor-box { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.editor-box .CodeMirror { min-height: 260px; }
textarea.input, input.input, select.input { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; }
textarea.input { min-height: 90px; resize: vertical; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: .95rem; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); margin-right: 4px; }
.err-box { border-left: 4px solid var(--bad); }
.filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 16px; }
.filter button { padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: .85rem; }
.filter button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.footer-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 30px; flex-wrap: wrap; }

@media (max-width: 860px) {
  #sidebar { position: fixed; left: -270px; z-index: 40; transition: left .2s; width: 260px; }
  body.menu-open #sidebar { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  #menu-btn { display: inline-block; }
  #view { padding: 20px 16px 70px; }
  #topbar { padding: 10px 14px; }
  .ws { grid-template-columns: 1fr; }
}

@media print {
  #sidebar, #topbar, button, .search, input.input, .footer-nav { display: none !important; }
  body, #main { background: #fff !important; }
  #view { padding: 0; max-width: none; }
  .card { box-shadow: none; }
}

.test-row .msg { white-space: pre-wrap; font-family: ui-monospace, Consolas, monospace; }

.predict { border-top: 1px solid var(--line); padding: 10px 12px; background: color-mix(in srgb, var(--warn) 10%, var(--code-bg)); }
.predict textarea { margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; }
.predict-cmp { border-top: 1px solid var(--line); padding: 10px 14px; background: var(--code-bg); }
.predict-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.predict-grid pre { margin: 4px 0 0; padding: 8px; background: var(--panel2); border-radius: 8px; white-space: pre-wrap; font: .85rem ui-monospace, Consolas, monospace; }
@media (max-width: 600px) { .predict-grid { grid-template-columns: 1fr; } }

.stdin[hidden], textarea[hidden], .predict[hidden], .predict-cmp[hidden] { display: none !important; }


/* ---- AI Automation course: lesson layout ---- */
.lesson h4.lesson-title { font-size: 1.4rem; margin: 2.4em 0 .6em; padding-top: 1em; border-top: 3px solid var(--accent); scroll-margin-top: 70px; }
.lesson h4.lesson-title:first-child { margin-top: .4em; border-top: 0; padding-top: 0; }
.lesson p.co { padding: 9px 14px; border-left: 4px solid var(--line); border-radius: 8px; background: var(--panel2); margin: .8em 0; }
.lesson p.co-goal { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--panel)); }
.lesson p.co-task { border-left-color: var(--good); background: color-mix(in srgb, var(--good) 9%, var(--panel)); }
.lesson p.co-see { border-left-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 9%, var(--panel)); }
.lesson p.co-cost { border-left-color: var(--muted); }
.lesson p.co-done, .lesson p.co-mistakes { display: inline-block; padding: 3px 12px; border-left-width: 0; border-radius: 99px; font-size: .88rem; margin-bottom: .2em; }
.lesson p.co-done { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.lesson p.co-mistakes { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.lesson blockquote p { margin: .45em 0; }
.lesson hr { margin: 2em 0; border: 0; border-top: 1px solid var(--line); }
.today .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.today .chip-link { display: inline-block; padding: 5px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--panel2); color: var(--text); font-size: .88rem; }
.today .chip-link:hover { border-color: var(--accent); text-decoration: none; }
.lesson li input[type=checkbox] { width: 1.05em; height: 1.05em; vertical-align: -2px; accent-color: var(--good); }
@media (max-width: 600px) { .lesson h4.lesson-title { font-size: 1.2rem; } .today .chip-link { width: 100%; } }


/* ---- practice widgets and diagrams ---- */
.widget { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 1.2em 0; background: var(--panel); }
.w-title { font-weight: 800; font-size: 1.05rem; margin-bottom: 6px; }
.w-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.w-grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
@media (max-width: 760px) { .w-grid { grid-template-columns: 1fr; } }
.w-lab { display: block; font-size: .82rem; color: var(--muted); font-weight: 700; margin: 8px 0 4px; }
.w-code { width: 100%; font: .88rem/1.45 ui-monospace, Consolas, monospace; background: var(--code-bg, var(--panel2)); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.w-out { margin: 0; padding: 10px 12px; background: var(--panel2); border-radius: 10px; min-height: 2.4em; white-space: pre-wrap; word-break: break-word; font: .95rem/1.4 ui-monospace, Consolas, monospace; }
.w-out.bad { color: var(--bad); }
.w-task { margin-top: 10px; padding: 8px 12px; border-left: 4px solid var(--good); background: color-mix(in srgb, var(--good) 9%, var(--panel)); border-radius: 8px; }
.w-fb { margin-top: 10px; padding: 8px 12px; border-left: 4px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border-radius: 8px; }
.w-opts .opt { margin: 6px 0; }
.w-table { width: 100%; border-collapse: collapse; margin: .6em 0; }
.w-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.w-warn { color: var(--warn); font-weight: 600; }
.w-field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.dg { width: 100%; height: auto; color: var(--text); }
.dg-box rect { fill: var(--panel2); stroke: var(--line); stroke-width: 2; }
.dg-box.dg-a rect { fill: color-mix(in srgb, var(--accent) 16%, var(--panel)); stroke: var(--accent); }
.dg-box.dg-b rect { fill: color-mix(in srgb, var(--accent2) 14%, var(--panel)); stroke: var(--accent2); }
.dg-box.dg-c rect { fill: color-mix(in srgb, var(--good) 16%, var(--panel)); stroke: var(--good); }
.dg-box text { fill: var(--text); font: 600 14px system-ui, sans-serif; }
.dg-arrow { stroke: currentColor; stroke-width: 2; fill: none; }
.dg-axis { stroke: var(--muted); stroke-width: 2; }
.dg-win { fill: color-mix(in srgb, var(--good) 22%, var(--panel)); stroke: var(--good); stroke-width: 2; }
.dg-wt, .dg-note { fill: var(--muted); font: 600 13px system-ui, sans-serif; }

/* ---- check yourself ---- */
.chk { margin: 1.4em 0; padding: 12px 16px; border: 1px dashed var(--accent); border-radius: 12px; background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
.chk-h { font-weight: 800; }
.chk-q { margin: .5em 0; }
.chk .opt { margin: 5px 0; }
.w-scroll { overflow-x: auto; }
.w-table th { text-align: left; font-size: .8rem; color: var(--muted); padding: 4px 8px; }
.w-res { white-space: nowrap; }
.mini.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
.w-table input.input, .w-table textarea.input { width: 100%; min-width: 140px; }
