:root {
  --bg: #0a0d14;
  --bg-2: #0f1420;
  --bg-3: #141b2b;
  --line: #232c40;
  --text: #e6ecf7;
  --muted: #8b98b3;
  --accent: #8b5cf6;
  --ok: #22c55e;
  --radius: 14px;
  --radius-sm: 10px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 38px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.6 -apple-system, "Segoe UI", system-ui, sans-serif; }
a { color: inherit; text-decoration: none; }
#app { display: grid; grid-template-columns: 300px 1fr; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 6px 8px 16px; }
.brand .cube { font-size: 26px; }
.brand b { display: block; font-size: 17px; letter-spacing: .2px; }
.brand small { color: var(--muted); font-size: 11px; }
.search input { width: 100%; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); padding: 9px 12px; border-radius: 10px; outline: none; font-size: 13px; }
.search input:focus { border-color: var(--accent); }
.tree { margin-top: 14px; }
.tree details { margin: 2px 0; }
.tree summary { cursor: pointer; padding: 6px 8px; border-radius: 8px; font-size: 13px; color: var(--text); display: flex; gap: 8px; align-items: center; }
.tree summary:hover { background: var(--bg-3); }
.tree summary .dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }
.tree summary .cnt { color: var(--muted); font-size: 11px; margin-left: auto; }
.tree a.item { display: block; padding: 5px 8px 5px 26px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.tree a.item:hover { background: var(--bg-3); color: var(--text); }
.tree a.item.active { background: var(--bg-3); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.tree a.item .done { color: var(--ok); font-size: 11px; margin-left: 4px; }
.tree .sec { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; padding: 14px 8px 6px; }
.sidebar-foot { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.foot-link { display: block; padding: 8px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.foot-link:hover { background: var(--bg-3); color: var(--text); }

/* ---------- main ---------- */
.main { padding: 34px 44px 80px; max-width: 1080px; width: 100%; margin: 0 auto; }
.hero h1 { font-size: 44px; margin: 0 0 6px; letter-spacing: -1px; }
.hero p.tag { color: var(--muted); font-size: 17px; margin: 0 0 22px; }
.stats { display: flex; gap: 26px; flex-wrap: wrap; margin: 22px 0 34px; }
.stat b { font-size: 26px; display: block; }
.stat span { color: var(--muted); font-size: 12px; }
.bar { height: 10px; border-radius: 6px; background: var(--bg-3); overflow: hidden; margin: 10px 0 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #8b5cf6, #22c55e); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-top: 18px; }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: block; transition: transform .12s ease, border-color .12s ease; }
.card:hover { transform: translateY(-2px); border-color: #33405e; }
.card .top { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.card .top b { font-size: 15px; }
.card .meta { color: var(--muted); font-size: 12px; }
.card .facebar { height: 4px; border-radius: 3px; margin: -16px -16px 12px; border-radius: var(--radius) var(--radius) 0 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 38px 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip { background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 12px; color: var(--muted); }
.chip.face { color: var(--text); }
.chip.done { border-color: #1f6b3a; color: #7ee2a7; }

/* ---------- lesson ---------- */
.lesson-head { border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 26px; }
.lesson-head h1 { font-size: 34px; margin: 8px 0 10px; letter-spacing: -.5px; }
.lesson-head .meta { color: var(--muted); font-size: 13px; display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--bg-3); color: var(--text); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: #3a4b6d; }
.btn.ok { border-color: #1f6b3a; background: #0e2718; color: #7ee2a7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button { font-family: inherit; }
.md { font-size: 15.5px; }
.md h1, .md h2, .md h3 { margin: 28px 0 10px; line-height: 1.25; }
.md h2 { font-size: 24px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.md h3 { font-size: 18px; }
.md p { margin: 12px 0; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 5px 0; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--bg-3); padding: 2px 6px; border-radius: 6px; }
.md pre { background: #070a10; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); margin: 14px 0; padding: 2px 0 2px 16px; color: var(--muted); }
.md table { border-collapse: collapse; width: 100%; margin: 16px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.md th { background: var(--bg-3); }
.md a { color: #9db4ff; border-bottom: 1px solid #33406e; }
.md a:hover { border-color: #9db4ff; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- canvas ---------- */
.cv-wrap { position: relative; height: calc(100vh - 140px); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #070a10 radial-gradient(#141b2b 1px, transparent 1px) 0 0/26px 26px; cursor: grab; }
.cv-wrap.dragging { cursor: grabbing; }
.cv-stage { position: absolute; inset: 0; transform-origin: 0 0; }
.cv-group { position: absolute; border: 1.5px solid; border-radius: 10px; }
.cv-group-label { position: absolute; top: -11px; left: 10px; font-size: 11px; padding: 1px 8px; border-radius: 6px; background: var(--bg); border: 1px solid; white-space: nowrap; }
.cv-card { position: absolute; background: var(--bg-2); border: 1.5px solid; border-radius: 8px; padding: 8px 10px; font-size: 11.5px; line-height: 1.4; overflow: hidden; }
.cv-card h1, .cv-card h2, .cv-card h3 { font-size: 13px; margin: 0 0 4px; }
.cv-card p { margin: 3px 0; }
.cv-card ul { margin: 2px 0; padding-left: 14px; }
.cv-card .cv-note { color: #9db4ff; font-size: 11px; border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 4px; display: flex; gap: 6px; align-items: center; }
.cv-card.note { cursor: pointer; }
.cv-card.note:hover { background: var(--bg-3); }
.cv-file { position: absolute; background: var(--bg-2); border: 1.5px dashed; border-radius: 8px; padding: 6px; font-size: 11px; overflow: hidden; cursor: pointer; }
.cv-file img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cv-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.cv-controls { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; }
.cv-controls .btn { background: var(--bg-2); }
.cv-hint { position: absolute; left: 14px; bottom: 14px; color: var(--muted); font-size: 11px; }

/* ---------- progress ---------- */
.prog-row { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 6px; background: var(--bg-2); }
.prog-row:hover { border-color: #33405e; }
.prog-row input { accent-color: var(--ok); width: 16px; height: 16px; }
.prog-row .t { flex: 1; }
.prog-row .t small { display: block; color: var(--muted); font-size: 11px; }
.prog-group { margin-bottom: 26px; }
.prog-group h3 { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.prog-group h3 .cnt { color: var(--muted); font-size: 12px; font-weight: 400; }
.kbd { font-family: var(--mono); font-size: 11px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.empty { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
mark { background: #3b2d00; color: #ffd500; border-radius: 3px; padding: 0 2px; }
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 22px 18px 60px; }
  .hero h1 { font-size: 30px; }
}

/* ---------- app chrome v2 ---------- */
.topbar { display:flex; align-items:center; gap:14px; justify-content:flex-end; margin-bottom:26px; }
.userchip { display:flex; align-items:center; gap:10px; background:var(--bg-2); border:1px solid var(--line); border-radius:999px; padding:6px 8px 6px 14px; font-size:13px; }
.userchip .avatar { width:26px; height:26px; border-radius:50%; background:linear-gradient(135deg,#8b5cf6,#22c55e); display:grid; place-items:center; font-size:12px; font-weight:700; color:#fff; }
.modal-back { position:fixed; inset:0; background:rgba(3,6,12,.72); display:grid; place-items:center; z-index:50; backdrop-filter:blur(3px); }
.modal { width:min(420px,92vw); background:var(--bg-2); border:1px solid var(--line); border-radius:18px; padding:26px; box-shadow:0 30px 80px rgba(0,0,0,.5); }
.modal h2 { margin:0 0 6px; font-size:22px; }
.modal p.sub { color:var(--muted); font-size:13px; margin:0 0 18px; }
.modal label { display:block; font-size:12px; color:var(--muted); margin:12px 0 5px; }
.modal input { width:100%; background:var(--bg-3); border:1px solid var(--line); color:var(--text); padding:10px 12px; border-radius:10px; outline:none; font-size:14px; }
.modal input:focus { border-color:var(--accent); }
.modal .row { display:flex; gap:10px; margin-top:20px; }
.modal .err { color:#ff8b8b; font-size:12px; margin-top:10px; }
.link-btn { background:none; border:none; color:#9db4ff; cursor:pointer; font-size:13px; padding:0; }
.link-btn:hover { text-decoration:underline; }
.search-results { display:grid; gap:8px; margin-top:18px; }
.sr-item { background:var(--bg-2); border:1px solid var(--line); border-radius:10px; padding:12px 14px; }
.sr-item:hover { border-color:#33405e; }
.sr-item b { font-size:14px; }
.sr-item small { color:var(--muted); display:block; margin-top:2px; }
.admin-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap:14px; margin:18px 0 26px; }
.admin-card { background:var(--bg-2); border:1px solid var(--line); border-radius:14px; padding:16px; }
.admin-card b { font-size:24px; display:block; }
.admin-card span { color:var(--muted); font-size:12px; }
table.tbl { width:100%; border-collapse:collapse; font-size:13px; }
table.tbl th, table.tbl td { border-bottom:1px solid var(--line); padding:9px 10px; text-align:left; }
table.tbl th { color:var(--muted); font-weight:500; font-size:11px; text-transform:uppercase; letter-spacing:.6px; }
.pill { display:inline-block; padding:2px 9px; border-radius:999px; font-size:11px; border:1px solid var(--line); color:var(--muted); }
.pill.ok { border-color:#1f6b3a; color:#7ee2a7; }
.pill.warn { border-color:#6b3a1f; color:#ffb27e; }

/* ---------- course UI ---------- */
.next-card { display:flex; align-items:center; justify-content:space-between; gap:18px; border-color:#3b4d78; background:linear-gradient(135deg,#121a2b,#0f1420); margin:26px 0 8px; padding:20px 22px; }
.next-card:hover { transform:none; border-color:#8b5cf6; }
.next-eyebrow { font-size:10px; letter-spacing:1.4px; color:#9db4ff; margin-bottom:8px; }
.next-card .top { margin:0; align-items:flex-start; }
.modgrid { display:grid; grid-template-columns:repeat(auto-fill,minmax(270px,1fr)); gap:12px; margin-top:14px; }
.modcard { background:var(--bg-2); border:1px solid var(--line); border-radius:12px; padding:14px 16px; display:block; }
.modcard:hover { border-color:#3a4b6d; }
.modcard.done { border-color:#1f6b3a; background:#0d1f15; }
.modcard.locked { opacity:.55; }
.modcard.wip { border-color:#6b5b1f; }
.modhead { display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.modhead b { font-size:14px; flex:1; }
.mem { font-size:18px; }
.mstate { font-size:11px; color:var(--muted); }
.modbar { height:5px; border-radius:4px; background:var(--bg-3); overflow:hidden; }
.modbar > i { display:block; height:100%; background:linear-gradient(90deg,#8b5cf6,#22c55e); }
.modmeta { color:var(--muted); font-size:11px; margin-top:8px; line-height:1.4; }
.item.mod { display:flex; align-items:center; gap:8px; padding-left:8px; }
.item.mod .mt { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.item.mod .mc { font-size:10px; color:var(--muted); }
.exlist { display:grid; gap:8px; }
.exrow { display:flex; gap:10px; align-items:flex-start; background:var(--bg-2); border:1px solid var(--line); border-radius:10px; padding:11px 13px; font-size:13px; }
.exrow input { width:16px; height:16px; margin-top:2px; accent-color:var(--ok); }
.exrow small { display:block; color:var(--muted); font-size:10.5px; margin-bottom:2px; }
.cert { position:relative; margin:26px 0; border:2px dashed var(--line); border-radius:18px; padding:42px 34px; text-align:center; background:var(--bg-2); }
.cert.ready { border-color:#22c55e; background:radial-gradient(circle at 50% 0%,#0e2a1a,#0f1420 70%); }
.cert-cube { font-size:44px; margin-bottom:10px; }
.cert-title { font-size:13px; letter-spacing:2px; text-transform:uppercase; color:var(--muted); }
.cert-name { font-size:34px; font-weight:700; margin:10px 0 6px; letter-spacing:-.5px; }
.cert-line { color:var(--muted); }
.cert-meta { margin-top:18px; font-size:11px; color:var(--muted); }
.cert-seal { position:absolute; right:26px; bottom:18px; width:46px; height:46px; border-radius:50%; border:2px solid #22c55e; display:grid; place-items:center; color:#22c55e; font-size:22px; opacity:0; }
.cert.ready .cert-seal { opacity:1; }

/* ---------- lead integration ---------- */
.menu-btn { display:none; background:none; border:1px solid var(--line); color:var(--text); border-radius:10px; padding:6px 10px; font-size:16px; cursor:pointer; position:absolute; right:14px; top:14px; }
.backdrop { display:none; }
.ob-banner { display:flex; align-items:center; gap:14px; flex-wrap:wrap; background:#121a2b; border:1px solid #3b4d78; border-radius:12px; padding:14px 18px; margin:22px 0 6px; font-size:13.5px; }
.ob-banner .btn { margin-left:auto; }
.quizbox .quizcard { display:flex; align-items:center; justify-content:space-between; gap:16px; background:var(--bg-2); border:1px solid var(--line); border-radius:12px; padding:16px 18px; }
@media (max-width: 900px) {
  .menu-btn { display:block; }
  body.sidebar-open .sidebar { display:block; position:fixed; inset:0 auto 0 0; width:86%; z-index:70; height:100vh; overflow:auto; }
  body.sidebar-open .backdrop { display:block; position:fixed; inset:0; background:rgba(3,6,12,.6); z-index:65; }
}

/* ==========================================================================
   ICON SYSTEM (v1.1) — Lucide, vendored offline
   Sprite: /icons/sprite.svg · helper: js/icons.js · docs: docs/design.md
   Rules: one icon language, stroke 2, currentColor, decorative = aria-hidden.
   ========================================================================== */
:root {
  /* icon sizes — the only sizes allowed in the UI */
  --icon-sm: 16px;   /* inline: pills, table rows, chips, inline text */
  --icon: 18px;      /* default UI: buttons, links, list rows, module rows */
  --icon-lg: 20px;   /* emphasis: primary buttons, card headers, nav toggle */
  --icon-xl: 24px;   /* accents: empty states, hero meta, section marks */
  --icon-gap-sm: 6px;
  --icon-gap: 8px;
  --ring: var(--accent);
}

.ic {
  display: inline-block;
  flex: none;
  vertical-align: -0.18em;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.ic-sm { width: var(--icon-sm) !important; height: var(--icon-sm) !important; }
.ic-lg { width: var(--icon-lg) !important; height: var(--icon-lg) !important; }
.ic-xl { width: var(--icon-xl) !important; height: var(--icon-xl) !important; }

/* brand mark — the cube logo (own drawing, same visual language) */
.brand-mark { display: block; flex: none; border-radius: 9px; }
.brand .brand-mark { width: 32px; height: 32px; border-radius: 9px; }

/* cube-face chip (DB square emojis) — the colour is brand data, not an emoji */
.face-chip {
  display: inline-block;
  flex: none;
  border-radius: 4px;
  background: var(--face, #8b98b3);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
  vertical-align: -0.16em;
}

/* icon + label spacing (6–8px) */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--icon-gap-sm); line-height: 1.35; }
.foot-link { display: flex; align-items: center; gap: var(--icon-gap); }
.foot-link .ic { color: var(--muted); }
.foot-link:hover .ic { color: var(--text); }
.pill { display: inline-flex; align-items: center; gap: 5px; }
.pill .ic { width: var(--icon-sm); height: var(--icon-sm); }
.tree summary .ic { color: var(--muted); }
.tree summary:hover .ic { color: var(--text); }
.tree a.item .done .ic { color: var(--ok); }
.card .top > .ic, .card .top > .face-chip { color: var(--accent); }
.card:hover .top > .ic { color: #c4b5fd; }
.ob-banner .ic { color: #a78bfa; }
.lesson-head .meta .ic { color: var(--muted); }
.lesson-head .meta .btn .ic { color: currentColor; }

/* semantic icon colours for state */
.mic { display: inline-flex; align-items: center; justify-content: center; width: 16px; }
.mic .ic { width: 15px; height: 15px; }
.mic.done { color: var(--ok); }
.mic.wip { color: var(--accent); }
.mic.locked { color: #5b6b8c; }
.mic.todo { color: var(--muted); }
.mstate .ic { width: var(--icon-sm); height: var(--icon-sm); }
.modcard.done .mstate { color: var(--ok); }
.modcard.done .mstate .ic { color: var(--ok); }
.modcard.locked .mstate .ic { color: var(--muted); }
.item.mod .mic + .mt { margin-left: 1px; }
.item.mod .mt .face-chip { margin-right: 6px; }
.pill.ok .ic { color: var(--ok); }
.pill.warn .ic { color: #ffb27e; }
.cert-cube .brand-mark { width: 54px; height: 54px; margin: 0 auto 4px; border-radius: 14px; }
.cert-seal .ic { width: 22px; height: 22px; }

/* search field with leading icon */
.search { position: relative; }
.search > .ic-search {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.search input { padding-left: 34px; }
.search:focus-within > .ic-search { color: var(--text); }

/* empty states: icon + calm copy */
.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; line-height: 1.55; }
.empty > .ic { width: var(--icon-xl); height: var(--icon-xl); color: #5b6b8c; stroke-width: 1.75; }
.empty > b { color: var(--text); font-weight: 600; }
.empty .btn { margin-top: 2px; }

/* canvas controls: icon buttons stay square */
.cv-controls .btn { min-width: 34px; padding: 6px 9px; }
.cv-controls .ic { width: var(--icon-sm); height: var(--icon-sm); }

/* a11y ring — accent, 2px, offset 2 */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn.primary:focus-visible, .modcard:focus-visible, .next-card:focus-visible { outline-color: #c4b5fd; }

/* ---------- page-specific icon placement (v1.1 polish) ---------- */
.hero h1 .brand-mark { display: inline-block; vertical-align: -.12em; margin-right: 12px; border-radius: 10px; }
.hero h1 .hero-ic { color: var(--accent); margin-right: 10px; vertical-align: -.08em; }
.next-emoji { display: inline-flex; align-items: center; justify-content: center; }
.next-emoji .face-chip { width: 26px; height: 26px; border-radius: 6px; }
.prog-group h3 .face-chip { width: 16px; height: 16px; }
.locked-note { border-color: #6b3a1f; color: #ffb27e; }
.locked-note > .ic { color: #ffb27e; }
.cv-open { color: #9db4ff; margin-top: 6px; font-size: 10.5px; display: flex; align-items: center; gap: 3px; }
.admin-card { display: flex; flex-direction: column; gap: 2px; }
.admin-card > .ic { color: var(--accent); margin-bottom: 6px; }
.userchip .link-btn { display: inline-flex; align-items: center; gap: 4px; }
.tree summary .ic, .tree summary .face-chip { margin-right: 2px; }
.tree a.item .face-chip { width: 12px; height: 12px; margin-right: 5px; }
.sr-item b .face-chip { width: 12px; height: 12px; margin-right: 5px; }
.lesson-head h1 .face-chip { width: 24px; height: 24px; border-radius: 6px; vertical-align: -.06em; }
.exrow small { display: flex; align-items: center; gap: 5px; }
@keyframes rk-spin { to { transform: rotate(360deg); } }
.ic-spin { animation: rk-spin 1.15s linear infinite; transform-origin: 50% 50%; }
@media (prefers-reduced-motion: reduce) { .ic-spin { animation: none; } }
.search .kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: 10.5px; }
.search input { padding-right: 52px; }
/* sidebar module row: flex must win over `.tree a.item { display:block }` */
.tree a.item.mod { display: flex; align-items: center; gap: 8px; padding-top: 5px; padding-bottom: 5px; }
.tree a.item.mod .mt { display: flex; align-items: center; min-width: 0; }
.tree a.item.mod .mt .face-chip { flex: 0 0 auto; }
.tree a.item.mod .mc { flex: 0 0 auto; margin-left: 2px; }
/* icon + label gap inside sidebar module titles */
.tree a.item.mod .mt > .ic, .tree a.item.mod .mt > .face-chip { margin-right: 6px; }
