:root { --bg: #f3f4f6; --card: #fff; --ink: #1f2933; --muted: #6b7280; --line: #e5e7eb; --brand: #2f343a; --accent: #1f5fa8; --ok: #2e9e5b; --bad: #d64545; --info: #1e88c8; --warn: #e8a317; }
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.topbar { background: var(--brand); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.15rem; letter-spacing: .3px; border-bottom: 3px solid var(--info); padding: 12px 0; }
.topbar nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.topbar nav a, .topbar nav button.linklike { color: #e5e7eb; }
.topbar nav .who { font-weight: 600; color: #fff; }
button.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: var(--accent); }
main { padding: 18px 16px 30px; }
.footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; padding: 12px 16px 24px; border-top: 1px solid var(--line); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); overflow-x: auto; }
.card.narrow { max-width: 460px; margin: 30px auto; } .card.narrow-wide { max-width: 760px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card h1, .card h2, .card h3 { margin: 0 0 12px; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; } h4.chapter { margin: 16px 0 6px; color: var(--muted); font-weight: 600; }
.page-head { display: flex; align-items: center; gap: 12px; background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; }
.page-head h1 { font-size: 1.2rem; margin: 0; font-weight: 600; } .page-head .back { color: #fff; font-size: 1.3rem; } .page-head .spacer { flex: 1; }
.page-head .btn { background: #fff; }
.hero { text-align: center; padding: 60px 10px; } .hero h1 { font-size: 2.6rem; margin-bottom: 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; } .error { color: var(--bad); font-weight: 600; }
.flash { background: #e6f4ea; border: 1px solid #b7e1c1; color: #1f6b3a; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.banner { background: var(--info); color: #fff; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.btn { display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid #cbd2d9; background: #fff; color: var(--ink); cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { background: #17497f; }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; } .btn.info { background: var(--info); border-color: var(--info); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 4px 10px; font-size: .85rem; } .btn.block { display: block; text-align: center; margin-bottom: 10px; }
button.icon { background: none; border: 0; cursor: pointer; font-size: 1rem; padding: 2px 4px; color: var(--accent); } a.icon { padding: 2px 4px; } button.icon.danger { color: var(--bad); }
form.inline { display: inline; } .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .row.right { justify-content: flex-end; margin-top: 8px; }
label { display: block; margin-bottom: 10px; font-weight: 600; font-size: .9rem; }
label input, label select, label textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
input, select, textarea { padding: 7px 9px; border: 1px solid #cbd2d9; border-radius: 6px; font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec5f5; border-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; } label.check input { width: auto; display: inline; margin: 0; }
label.check.inline { display: inline-flex; margin: 0 0 0 8px; }
textarea.code, .code, pre.code-view, .ce-hl, .ce-input, .ce-gutter { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 13.5px; line-height: 20px; tab-size: 4; }
textarea.code { width: 100%; white-space: pre; overflow: auto; background: #fbfbfd; }
pre.code-view { background: #fbfbfd; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow: auto; white-space: pre; }

/* Line-numbered, syntax-highlighted code editor */
.code-editor { display: flex; border: 1px solid #cbd2d9; border-radius: 6px; overflow: hidden; background: #fbfbfd; min-height: 120px; resize: vertical; box-shadow: inset 0 1px 2px rgba(0,0,0,.03); }
.code-editor:focus-within { outline: 2px solid #9ec5f5; border-color: var(--accent); }
.code-editor.readonly { background: #f4f5f7; }
.ce-gutter { flex: 0 0 auto; overflow: hidden; background: #eef1f5; color: #9aa3ad; text-align: right; user-select: none; border-right: 1px solid #e0e4e9; }
.ce-gutter-inner { padding: 8px 8px 8px 10px; white-space: pre; will-change: transform; }
.ce-area { position: relative; flex: 1 1 auto; overflow: hidden; }
.ce-hl { position: absolute; inset: 0; margin: 0; padding: 0; overflow: hidden; pointer-events: none; background: transparent; }
.ce-hl code { display: block; padding: 8px 12px; white-space: pre; will-change: transform; }
textarea.ce-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 8px 12px; border: 0; outline: none; resize: none; overflow: auto; white-space: pre; background: transparent; color: transparent; caret-color: #111; }
textarea.ce-input::selection { background: #b9d4f6; color: transparent; }
.ce-input:focus { outline: none; }
/* token colours (One Light inspired) */
.tok-comment { color: #a0a1a7; font-style: italic; }
.tok-keyword { color: #a626a4; }
.tok-builtin { color: #4078f2; }
.tok-fn { color: #4078f2; }
.tok-string { color: #50a14f; }
.tok-number { color: #986801; }
.tok-decorator { color: #c18401; }
.tok-ident { color: #383a42; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 10px 0; } legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }
.table { width: 100%; border-collapse: collapse; } .table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; } .table.dark-head thead th { background: #22315a; color: #fff; }
.table .actions { white-space: nowrap; } .table.grid .cell { text-align: center; font-weight: 700; } .scroll-x { overflow-x: auto; }
th.rot { height: 120px; white-space: nowrap; vertical-align: bottom; } th.rot > span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: .75rem; font-weight: 700; color: #fff; background: var(--muted); }
.badge.ok { background: var(--ok); } .badge.bad { background: var(--bad); } .badge.info-badge { background: var(--info); } .badge.muted-badge { background: #9aa3ad; }
.progress { background: #e5e7eb; border-radius: 4px; height: 10px; width: 140px; max-width: 100%; display: inline-block; overflow: hidden; vertical-align: middle; } .progress.big { display: block; width: 100%; height: 14px; }
.progress .bar { background: var(--info); height: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; } .grid-main-side { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid2, .grid-main-side { grid-template-columns: 1fr; } }
.list { list-style: none; padding: 0; margin: 0; } .list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.exlist { list-style: none; padding: 0; margin: 0; } .exlist li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.exlist .mark { display: inline-block; width: 26px; height: 22px; line-height: 22px; text-align: center; border-radius: 4px; background: #e5e7eb; color: #6b7280; font-weight: 700; }
.exlist .st-passed .mark { background: #d4edda; color: var(--ok); } .exlist .st-failed .mark { background: #f8d7da; color: var(--bad); }
.about .about-title { font-weight: 700; padding-bottom: 6px; }
.about div { padding: 6px 0; border-bottom: 1px solid var(--line); } .about div:last-child { border: 0; }
.chapter-toc { color: var(--muted); font-size: .9rem; margin: 8px 0 4px; padding-left: 22px; }
.chapter-toc li { padding: 1px 0; }
.side-progress { padding: 12px 14px; text-align: center; }
.btn .ico { margin-right: 4px; }
.btn.info.block, .btn.danger.block, .btn.success.block { padding: 10px 14px; font-size: .95rem; }
.tags { margin: 6px 0; } .tag { display: inline-block; background: #7c3aed; color: #fff; padding: 2px 8px; border-radius: 4px; font-size: .75rem; margin-right: 4px; }
.ex-title { text-align: center; font-size: 1.5rem; margin-bottom: 4px; } .ex-meta { margin: 10px 0; padding-left: 20px; } .ex-meta b.ok { color: var(--ok); } .ex-meta b.bad { color: var(--bad); }
.md img { max-width: 100%; } .md pre { background: #f6f8fa; padding: 10px; border-radius: 6px; overflow: auto; } .md code { background: #f0f2f5; padding: 1px 4px; border-radius: 3px; font-size: .9em; } .md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--line); padding: 4px 8px; }
.panel { border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; position: sticky; top: 12px; }
.panel-head { background: #4aa3d5; color: #fff; padding: 9px 14px; font-weight: 600; } .panel-body { padding: 10px 12px; min-height: 120px; max-height: 70vh; overflow: auto; }
.section-label { text-transform: uppercase; letter-spacing: .5px; color: #8a94a0; font-size: .78rem; font-weight: 700; margin: 16px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.section-label:first-child { margin-top: 0; }
.btn-add { width: 30px; height: 30px; border-radius: 50%; background: #e8632a; color: #fff !important; display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; line-height: 1; font-weight: 700; border: 0; text-decoration: none; padding: 0; cursor: pointer; }
.btn-add:hover { background: #cf4f1c; text-decoration: none; }
.case { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; background: #fafafa; }
.case.st-passed { border-color: #b7e1c1; } .case.st-failed { border-color: #f1b0b7; } .case.st-error, .case.st-skipped { border-color: #f5d48a; }
.case-head { font-weight: 600; font-size: .9rem; } .case.st-passed .case-head::before { content: "✔ "; color: var(--ok); } .case.st-failed .case-head::before { content: "✘ "; color: var(--bad); } .case.st-error .case-head::before, .case.st-skipped .case-head::before { content: "! "; color: var(--warn); }
.case pre { background: #eceff3; margin: 4px 0; padding: 6px 8px; border-radius: 4px; white-space: pre-wrap; word-break: break-word; font-size: .85rem; max-height: 220px; overflow: auto; }
.case pre.exc { background: #fdecec; color: #7a1c1c; } .case .lbl { color: var(--muted); font-size: .85rem; } .case .msg { font-size: .85rem; margin-top: 4px; }
.summary { padding: 8px 10px; border-radius: 6px; margin-bottom: 10px; font-weight: 600; } .summary.passed { background: #d4edda; color: #1f6b3a; } .summary.failed { background: #f8d7da; color: #7a1c1c; } .summary.error, .summary.running { background: #fff3cd; color: #7a5a00; }
.chapter-block { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; padding: 6px 10px; } .chapter-block summary { cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; padding: 4px 0; }
.chapter-edit { margin: 6px 0; } .chapter-edit input[name=title] { flex: 1; min-width: 160px; }
.items { list-style: none; padding: 0; margin: 6px 0; } .item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; background: #fbfbfd; } .item-actions { white-space: nowrap; }
.lib-item { padding: 10px 6px; border-bottom: 1px solid var(--line); } .lib-item.already { opacity: .6; } .lib-title { color: var(--accent); font-size: 1.05rem; } .excerpt { color: #444; font-size: .9rem; margin: 4px 0; }
.case-row { display: flex; gap: 8px; align-items: flex-start; border: 1px dashed #cbd2d9; border-radius: 6px; padding: 8px; margin-bottom: 8px; } .case-fields { flex: 1; } .case-fields label { margin-bottom: 6px; }
details.sub { margin: 10px 0; } details.sub summary { cursor: pointer; font-weight: 600; }
.exercise-form .mode-function, .exercise-form .mode-stdout, .exercise-form .mode-variables { display: none; }
.exercise-form[data-mode=function] .mode-function, .exercise-form[data-mode=stdout] .mode-stdout, .exercise-form[data-mode=variables] .mode-variables { display: block; }
.exercise-form[data-mode=function] label.check.mode-function { display: flex; }
.danger-zone { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
code.wrap-code { word-break: break-all; }
body.embedded .topbar .brand { pointer-events: none; }

/* narrow screens (phones): nothing may widen the page; tables scroll inside their card */
@media (max-width: 700px) {
  main { padding: 12px 10px 24px; }
  .wrap { padding: 0 10px; }
  .card { padding: 12px 12px; }
  .table { min-width: 480px; }
  .card.narrow, .card.narrow-wide { margin-left: 0; margin-right: 0; }
  .progress { width: 90px; }
  .page-head { flex-wrap: wrap; }
  .page-head h1 { font-size: 1.05rem; }
  .item, .list li, .lib-item { flex-wrap: wrap; }
  .topbar nav { gap: 10px; font-size: .95rem; }
  .ex-title { font-size: 1.3rem; }
  .code-editor { max-width: 100%; }
}
/* bracket matching in the code editor */
.tok-match { background: #ffe8a3; box-shadow: inset 0 0 0 1px #e3b341; border-radius: 2px; }
.tok-unmatched { background: #ffd6d6; box-shadow: inset 0 0 0 1px #d64545; border-radius: 2px; }
