/* =====================================================================
   The page: colours, type, buttons, the layout (instructions on the left,
   workbench on the right), the instructions' parts (activities, tasks,
   questions), dialogs and small screens.
   ===================================================================== */
:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --panel-3: #eef1f5;
  --ink: #18212f;
  --ink-2: #384355;
  --muted: #647086;
  --line: #e0e5ec;
  --line-2: #cbd3de;
  --accent: #0b6b8a;
  --accent-2: #0a5a74;
  --accent-soft: #e2f1f6;
  --accent-ink: #ffffff;
  --act: #b8480b;
  --act-soft: #fff3e9;
  --good: #16794a;
  --good-soft: #e3f4eb;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fff6de;
  --ai: #6b3fa0;
  --ai-soft: #f3edfb;
  --sel: #39ff14;
  --radius: 10px;
  --radius-s: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-l: 0 10px 30px rgba(16, 24, 40, 0.18);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --tut-w: 42%;
  --header-h: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
a:hover { color: var(--accent-2); }
code, kbd, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--panel-3); padding: 0.05em 0.35em; border-radius: 4px; }
.kbd, kbd { border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 0.35em; background: #fff; font-size: 0.85em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.86em; margin: 0.4em 0; }
[hidden] { display: none !important; }
.ic { flex: none; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4em;
  border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  border-radius: var(--radius-s); padding: 0.38em 0.8em; cursor: pointer;
  font-size: 0.92em; font-weight: 550; line-height: 1.2; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn:hover { background: var(--panel-2); border-color: #b6c0ce; }
.btn:focus-visible, .wb-tab:focus-visible, .ch-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.small { padding: 0.25em 0.6em; font-size: 0.84em; }
.btn .ic { width: 16px; height: 16px; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0 0.2em; font-weight: 600; display: inline-flex; align-items: center; gap: 0.2em; }
.linkbtn .ic { width: 14px; height: 14px; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 3px; border-radius: 5px; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--panel-3); color: var(--ink); }
.icon-btn .ic { width: 16px; height: 16px; }
.chip { border: 1px solid var(--line-2); background: #fff; border-radius: 999px; padding: 0.15em 0.6em; cursor: pointer; font-size: 0.84em; white-space: nowrap; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.small { font-size: 0.78em; padding: 0.05em 0.5em; }
.chip small { color: var(--muted); }

/* ---------------- app shell ---------------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: var(--header-h); flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: #10263a; color: #eaf2f8; border-bottom: 1px solid #0a1a28;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-title { font-weight: 700; font-size: 1.02rem; letter-spacing: 0.01em; white-space: nowrap; }
.brand-sub { font-size: 0.78rem; color: #9fb6c8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.progress-wrap { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: #b9cad7; }
.progress { width: 140px; height: 8px; border-radius: 99px; background: #26435b; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3fb7a0, #7fd67a); transition: width 0.4s; }
.topbar .btn { background: #1c3a52; border-color: #2b5170; color: #eaf2f8; }
.topbar .btn:hover { background: #24496a; }
.main { flex: 1; min-height: 0; display: flex; }
.tut { width: var(--tut-w); min-width: 320px; max-width: 70%; overflow: auto; background: var(--panel); border-right: 1px solid var(--line); scroll-behavior: smooth; }
.splitter { width: 7px; flex: none; cursor: col-resize; background: var(--bg); border-right: 1px solid var(--line); position: relative; }
.splitter::after { content: ''; position: absolute; left: 2px; top: 50%; width: 3px; height: 38px; margin-top: -19px; border-radius: 3px; background: var(--line-2); }
.splitter:hover::after, .splitter.drag::after { background: var(--accent); }
.bench { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.wb-tabs { display: flex; gap: 2px; padding: 6px 8px 0; background: var(--bg); border-bottom: 1px solid var(--line); flex: none; }
.wb-tab {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-bottom: 0;
  background: transparent; padding: 7px 14px 8px; border-radius: 9px 9px 0 0; cursor: pointer;
  font-weight: 600; color: var(--muted); font-size: 0.92rem; position: relative; top: 1px;
}
.wb-tab:hover { color: var(--ink); background: rgba(255, 255, 255, 0.6); }
.wb-tab.on { background: var(--panel); border-color: var(--line); color: var(--ink); }
.wb-tab .ic { width: 17px; height: 17px; }
.wb-tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--act); display: none; }
.wb-tab.attn .dot { display: inline-block; }
.wb-body { flex: 1; min-height: 0; position: relative; }
.wb-pane { position: absolute; inset: 0; display: flex; flex-direction: column; }
.wb-pane[hidden] { display: none !important; }

/* ---------------- tutorial pane ---------------- */
.ch-nav { position: sticky; top: 0; z-index: 5; background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 8px 14px; display: flex; gap: 4px; flex-wrap: wrap; }
.ch-tab {
  border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px 3px 4px;
  font-size: 0.82rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 550;
}
.ch-tab .num { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--panel-3); font-size: 0.74rem; font-weight: 700; color: var(--muted); }
.ch-tab.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.ch-tab.on .num { background: var(--accent); color: #fff; }
.ch-tab.done .num { background: var(--good); color: #fff; }
.chapter { padding: 18px 26px 60px; max-width: 820px; }
.chapter[hidden] { display: none; }
.chapter h1 { font-size: 1.55rem; line-height: 1.25; margin: 0.2em 0 0.2em; letter-spacing: -0.01em; }
.chapter h2 { font-size: 1.18rem; margin: 1.7em 0 0.5em; padding-top: 0.2em; border-top: 1px solid var(--line); scroll-margin-top: 60px; }
.chapter h2:first-of-type { border-top: 0; }
.chapter h3 { font-size: 1.02rem; margin: 1.3em 0 0.4em; }
.chapter p, .chapter li { color: var(--ink-2); }
.chapter ul, .chapter ol { padding-left: 1.3em; }
.chapter li { margin: 0.25em 0; }
.lede { font-size: 1.04rem; color: var(--ink-2); }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0.6em 0 1em; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 600; border-radius: 99px; padding: 2px 9px; background: var(--panel-3); color: var(--ink-2); }
.pill.time { background: var(--accent-soft); color: var(--accent-2); }
.pill.ext { background: var(--ai-soft); color: var(--ai); }
.pill .ic { width: 14px; height: 14px; }
.callout { border-radius: var(--radius); padding: 10px 14px; margin: 1em 0; border: 1px solid var(--line); background: var(--panel-2); }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .co-t { font-weight: 700; font-size: 0.86rem; display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.callout.info { background: var(--accent-soft); border-color: #bfdfe9; }
.callout.info .co-t { color: var(--accent-2); }
.callout.ai { background: var(--ai-soft); border-color: #dccdf1; }
.callout.ai .co-t { color: var(--ai); }
.callout.warn { background: var(--warn-soft); border-color: #f0dca3; }
.callout.warn .co-t { color: var(--warn); }
.callout.concept { background: #f1f6ee; border-color: #d3e6c7; }
.callout.concept .co-t { color: #3f6b22; }

/* activity cards */
.activity { border: 1px solid #f1d2bb; border-left: 4px solid var(--act); background: #fffaf6; border-radius: var(--radius); padding: 12px 16px; margin: 1.1em 0; }
.activity > h3, .activity > .act-t { margin: 0 0 6px; font-size: 1rem; color: var(--act); display: flex; align-items: center; gap: 8px; }
.activity .act-t .ic { width: 18px; height: 18px; }
.steps { list-style: none; padding: 0; margin: 6px 0; counter-reset: st; }
.steps > li { counter-increment: st; position: relative; padding: 6px 0 6px 34px; margin: 0; border-top: 1px dashed #f0dccc; }
.steps > li:first-child { border-top: 0; }
.steps > li::before { content: counter(st); position: absolute; left: 0; top: 6px; width: 23px; height: 23px; border-radius: 50%; background: #fff; border: 1.5px solid var(--act); color: var(--act); font-weight: 700; font-size: 0.78rem; display: grid; place-items: center; }
.steps > li.task-done::before { content: '✓'; background: var(--good); border-color: var(--good); color: #fff; }
.steps > li.task-done { color: var(--muted); }
.steps .task-check { float: right; margin: 2px 0 0 10px; display: inline-flex; align-items: center; gap: 4px; font-size: 0.78rem; color: var(--muted); cursor: pointer; user-select: none; }
.steps .task-check input { accent-color: var(--good); }
.auto-tag { font-size: 0.72rem; color: var(--good); font-weight: 600; margin-left: 4px; }
.do {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid #cfe3ea; background: #fff; color: var(--accent-2);
  border-radius: 999px; padding: 1px 10px 1px 7px; font-size: 0.82rem; font-weight: 650; cursor: pointer; vertical-align: 1px; white-space: nowrap;
}
.do::before { content: '▶'; font-size: 0.7em; }
.do:hover { background: var(--accent-soft); border-color: var(--accent); }
.do.running { opacity: 0.6; pointer-events: none; }
.do.showme { border-style: dashed; color: var(--muted); }
.do.showme:hover { color: var(--accent-2); }
.goto { display: inline-flex; align-items: center; gap: 4px; border: 0; background: var(--panel-3); border-radius: 6px; padding: 0 7px; font-size: 0.82rem; font-weight: 650; cursor: pointer; color: var(--ink-2); }
.goto:hover { background: var(--accent-soft); color: var(--accent-2); }
.goto .ic { width: 14px; height: 14px; }

/* questions */
.q { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 1em 0; background: #fff; box-shadow: var(--shadow); }
.q-h { display: flex; gap: 10px; align-items: flex-start; }
.q-n { flex: none; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; color: #fff; background: var(--accent); border-radius: 6px; padding: 2px 7px; margin-top: 2px; }
.q-text { font-weight: 600; color: var(--ink); }
.q-body { margin-top: 8px; }
.q textarea, .q input[type='text'] { width: 100%; border: 1px solid var(--line-2); border-radius: var(--radius-s); padding: 7px 9px; background: var(--panel-2); resize: vertical; }
.q textarea { min-height: 60px; }
.q textarea:focus, .q input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); background: #fff; }
.q-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.q-feedback { font-size: 0.88rem; font-weight: 600; }
.q-feedback.ok { color: var(--good); }
.q-feedback.no { color: var(--bad); }
.q-answer { margin-top: 8px; border-radius: var(--radius-s); background: var(--good-soft); border: 1px solid #c3e4d0; padding: 8px 12px; font-size: 0.93rem; }
.q-answer > :first-child { margin-top: 0; }
.q-answer > :last-child { margin-bottom: 0; }
.q.answered { border-color: #bfe0cc; }
.mcq { display: grid; gap: 6px; }
.mcq label { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 10px; cursor: pointer; background: var(--panel-2); }
.mcq label:hover { border-color: var(--accent); }
.mcq label.right { border-color: var(--good); background: var(--good-soft); }
.mcq label.wrong { border-color: var(--bad); background: var(--bad-soft); }
.mcq input { margin-top: 4px; accent-color: var(--accent); }

.fig { margin: 1em 0; }
.fig img { max-width: 100%; border-radius: var(--radius-s); border: 1px solid var(--line); }
.fig figcaption { font-size: 0.84rem; color: var(--muted); margin-top: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 0.8em 0; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.table th { background: var(--panel-2); font-weight: 650; color: var(--ink-2); }
.next-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 2.2em; padding-top: 1em; border-top: 1px solid var(--line); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
.cardlet { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--panel-2); }
.cardlet h4 { margin: 0 0 4px; font-size: 0.95rem; }
.cardlet p { margin: 0; font-size: 0.9rem; }
.name-field { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.name-field input { border: 1px solid var(--line-2); border-radius: var(--radius-s); padding: 6px 9px; min-width: 240px; }
.pdbline { font-family: var(--mono); font-size: 0.78rem; white-space: pre; overflow-x: auto; background: #0f1b28; color: #d6e4f0; border-radius: var(--radius-s); padding: 10px 12px; line-height: 1.45; }
.pdbline .c1 { color: #ffd479; } .pdbline .c2 { color: #8fd3ff; } .pdbline .c3 { color: #a8f0b0; } .pdbline .c4 { color: #ffb3c7; } .pdbline .c5 { color: #d8b4fe; } .pdbline .c6 { color: #9ca3af; }

.ex-empty { color: var(--muted); padding: 30px 10px; text-align: center; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- modal, popmenu, toasts ---------------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 32, 0.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow-l); width: min(620px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; font-size: 1.05rem; }
.modal-b { padding: 12px 16px 16px; overflow: auto; font-size: 0.92rem; }
.helptable, .infotable { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.helptable th, .infotable th { text-align: left; width: 34%; padding: 5px 8px 5px 0; vertical-align: top; color: var(--ink-2); }
.helptable td, .infotable td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.prompt-form p { margin-top: 0; color: var(--muted); font-size: 0.88rem; }
.prompt-input { width: 100%; border: 1px solid var(--line-2); border-radius: 7px; padding: 7px 10px; }
.prompt-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
label.stack { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; font-weight: 600; font-size: 0.86rem; }
label.stack select { border: 1px solid var(--line-2); border-radius: 6px; padding: 5px; font-weight: 400; }
.popmenu { position: fixed; z-index: 120; background: #fff; border: 1px solid var(--line-2); border-radius: 9px; box-shadow: var(--shadow-l); padding: 4px; display: flex; flex-direction: column; min-width: 200px; }
.popmenu button { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; text-align: left; font-size: 0.86rem; }
.popmenu button:hover { background: var(--panel-3); }
.popmenu .ic { width: 16px; height: 16px; color: var(--muted); }
.toasts { position: fixed; right: 14px; bottom: 14px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow-l); font-size: 0.86rem; max-width: 440px; opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s; pointer-events: auto; line-height: 1.4; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #8e1f19; }
.toast.warn { background: #7a5200; }
.toast.ok { background: #10593a; }
.toast b { color: #fff; }

/* ---------------- responsive ---------------- */
.bench-fab, .bench-close { display: none; }
@media (max-width: 1000px) {
  .app { height: auto; min-height: 100vh; }
  .main { display: block; }
  .tut { width: 100% !important; max-width: none; min-width: 0; border-right: 0; overflow: visible; }
  .splitter { display: none; }
  .ch-nav { top: 0; }
  .bench { position: fixed; left: 0; right: 0; top: var(--header-h); bottom: 0; z-index: 60; transform: translateX(105%); transition: transform 0.25s ease; box-shadow: var(--shadow-l); }
  body.bench-open .bench { transform: none; }
  body.bench-open { overflow: hidden; }
  .bench-fab { display: inline-flex; position: fixed; right: 14px; bottom: 14px; z-index: 55; align-items: center; gap: 8px; border: 0; border-radius: 99px; padding: 11px 16px; background: var(--accent); color: #fff; font-weight: 700; box-shadow: var(--shadow-l); cursor: pointer; }
  .bench-fab .ic { width: 18px; height: 18px; }
  .bench-close { display: inline-flex; margin-left: auto; align-items: center; gap: 4px; border: 1px solid var(--line-2); background: #fff; border-radius: 8px; padding: 4px 10px; font-weight: 650; font-size: 0.85rem; cursor: pointer; align-self: center; }
  .brand-sub, .progress-wrap span { display: none; }
  .topbar { position: sticky; top: 0; z-index: 70; }
  .ch-nav { top: var(--header-h); }
}
@media (max-width: 620px) {
  .chapter { padding: 14px 14px 80px; }
  .topbar .btn span { display: none; }
  .progress { width: 70px; }
  .wb-tab { padding: 7px 10px 8px; font-size: 0.85rem; }
}
@media print {
  .topbar, .bench, .splitter, .ch-nav, .do, .q-actions { display: none !important; }
  .tut { width: 100% !important; overflow: visible; }
  .chapter[hidden] { display: block !important; }
}
.wb-pane > div { height: 100%; min-height: 0; }
.optional { border-top: 2px dashed var(--line); margin-top: 2em; }
.no-answers .q-model { display: none !important; }

@media (max-width: 620px) {
  .ch-nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ch-tab { flex: none; }
}
