/* ---------- Buttons & chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none;
  font-weight: 600; font-size: 14px; line-height: 1.2;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line); box-shadow: var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--accent-soft); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-next { flex: 1; justify-content: space-between; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 500;
  padding: 3px 9px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface);
}
.chip svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chip-time { background: var(--c-hot-soft); }
.chip-level { background: var(--accent-soft); }
.chip-steps { background: var(--tag-insight-bg); }
.chip-soon { border-color: var(--line-soft); color: var(--ink-3); background: transparent; }
.chip-done { background: var(--accent-soft); color: var(--accent-ink); }

.tag {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; border: 1.5px solid currentColor;
}
.tag-problem { color: var(--tag-problem); background: var(--tag-problem-bg); }
.tag-brute { color: var(--tag-brute); background: var(--tag-brute-bg); }
.tag-insight { color: var(--tag-insight); background: var(--tag-insight-bg); }
.tag-walk { color: var(--tag-walk); background: var(--tag-walk-bg); }
.tag-edge { color: var(--tag-edge); background: var(--tag-edge-bg); }
.tag-complexity { color: var(--tag-complexity); background: var(--tag-complexity-bg); }
.tag-recap { color: var(--tag-recap); background: var(--tag-recap-bg); }

.eyebrow { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- Home pattern card ---------- */
.pcard { overflow: hidden; }
.pcard-head {
  width: 100%; display: grid; grid-template-columns: 34px minmax(0, 1fr) auto 22px; align-items: start; gap: 4px 10px;
  padding: 16px 18px; background: none; border: 0; text-align: left; cursor: pointer;
}
.pcard-num { font-family: var(--font-mono); font-size: 17px; font-weight: 500; color: var(--ink-3); padding-top: 1px; }
.pcard-title { font-size: 19px; font-weight: 600; letter-spacing: -0.015em; }
.pcard-summary { grid-column: 2 / 4; color: var(--ink-2); font-size: 14.5px; }
.pcard-badge { align-self: center; }
.pcard-chev { width: 20px; height: 20px; align-self: center; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; transition: transform .2s; }
.pcard.is-open .pcard-chev { transform: rotate(180deg); }
.pcard-body { padding: 0 18px 18px 62px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; }
.pcard-body h4 { font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; }
.pcard-body ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.pcard-body li { margin-bottom: 3px; }
.pcard-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pcard.is-ready .pcard-num { color: var(--accent); }
.pcard.is-done .pcard-num::after { content: " ✓"; }
.pcard:not(.is-ready) { box-shadow: none; border-color: var(--line-soft); }
.pcard:not(.is-ready) .pcard-title { color: var(--ink-2); }
.pcard.is-flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 4px var(--c-hot); } 100% { box-shadow: none; } }
@media (max-width: 640px) {
  .pcard-head { grid-template-columns: 28px minmax(0, 1fr) 22px; padding: 14px; }
  .pcard-badge { grid-column: 2; grid-row: 3; justify-self: start; }
  .pcard-chev { grid-column: 3; grid-row: 1; }
  .pcard-summary { grid-column: 2 / 3; }
  .pcard-body { padding: 0 14px 16px 52px; grid-template-columns: 1fr; }
}

/* ---------- Course sidebar ---------- */
.course-card { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.course-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.course-top b { font-size: 15px; }
.course-progress { height: 6px; margin: 0 14px 10px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.course-progress span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .4s ease; }
.course-tree { overflow-y: auto; padding: 0 8px 12px; scrollbar-width: thin; }
.ctree-week { margin-bottom: 4px; }
.ctree-week-btn {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 0; background: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); border-radius: 8px;
}
.ctree-week-btn:hover { background: var(--surface-3); }
.ctree-week-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; transition: transform .2s; }
.ctree-week-btn[aria-expanded="true"] svg { transform: rotate(90deg); }
.ctree-week-btn .count { margin-left: auto; font-weight: 500; letter-spacing: 0; color: var(--ink-3); }
.ctree-list { list-style: none; margin: 0 0 6px 15px; padding: 0 0 0 10px; border-left: 1.5px solid var(--line-soft); }
.ctree-item a, .ctree-item span {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 7px; font-size: 13.5px; text-decoration: none; color: var(--ink);
}
.ctree-item a:hover { background: var(--surface-3); }
.ctree-item span { color: var(--ink-3); }
.ctree-item .n { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); width: 18px; }
.ctree-item .ok { margin-left: auto; color: var(--accent); font-size: 12px; }
.ctree-item.is-current a { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; box-shadow: inset 0 0 0 1.5px var(--line); }

.learn-card { padding: 14px; }
.learn-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.learn-list li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.learn-box { width: 16px; height: 16px; border: 1.5px solid var(--ink-3); border-radius: 4px; margin-top: 1px; display: grid; place-items: center; transition: background .2s, border-color .2s; }
.learn-box svg { width: 12px; height: 12px; fill: none; stroke: #fff; stroke-width: 3; opacity: 0; }
.learn-list li.is-done { color: var(--ink); }
.learn-list li.is-done .learn-box { background: var(--accent); border-color: var(--accent); }
.learn-list li.is-done .learn-box svg { opacity: 1; }

/* ---------- Stage ---------- */
.stage-top { display: flex; gap: 10px; padding: 12px; align-items: flex-start; flex-wrap: wrap; }
.metrics { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.metric {
  min-width: 96px; padding: 6px 10px; border-radius: 9px; border: 1.5px solid var(--line-soft); background: var(--surface-2);
  transition: border-color .3s, background .3s;
}
.metric-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); white-space: nowrap; }
.metric-value { font-family: var(--font-mono); font-size: 15px; font-weight: 700; white-space: nowrap; }
.metric.is-changed { border-color: var(--accent); background: var(--accent-soft); }
.stage-controls { display: flex; gap: 8px; }
.stage-canvas { position: relative; flex: 1; min-height: 240px; overflow: hidden; }
@media (max-width: 640px) {
  .stage-top { flex-direction: column; align-items: stretch; }
  .stage-controls { order: -1; justify-content: flex-end; }
  .metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .metric { min-width: 0; }
  .metric-value { overflow: hidden; text-overflow: ellipsis; }
}
.stage-legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 8px 14px 10px; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; border: 1.5px solid currentColor; }

/* ---------- Timeline ---------- */
.timeline { padding: 10px 14px 12px; }
.timeline-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.timeline-head span:last-child { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); }
.timeline-track { position: relative; display: flex; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px; }
.tl-step {
  position: relative; flex: 1 0 62px; display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 0 2px; background: none; border: 0; cursor: pointer; color: var(--ink-3);
}
.tl-step::before { content: ""; position: absolute; top: 12px; left: -50%; right: 50%; height: 2px; background: var(--line-soft); z-index: 0; }
.tl-step:first-child::before { display: none; }
.tl-step.is-past::before, .tl-step.is-current::before { background: var(--ink); }
.tl-dot {
  position: relative; z-index: 1; width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; background: var(--surface); border: 1.5px solid var(--ink-3);
  transition: background .2s, transform .2s;
}
.tl-dot::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid transparent; }
.tl-name { font-size: 11.5px; line-height: 1.2; text-align: center; max-width: 76px; }
.tl-step.is-past .tl-dot { background: var(--accent-soft); border-color: var(--ink); color: var(--accent-ink); }
.tl-step.is-current .tl-dot { background: var(--accent); border-color: var(--ink); color: #fff; transform: scale(1.08); }
.tl-step.is-current .tl-dot::after { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tl-step.is-current .tl-name { color: var(--ink); font-weight: 600; }
.tl-step:hover .tl-name { color: var(--ink); }

/* ---------- Narration ---------- */
.narration { display: flex; flex-direction: column; overflow: hidden; }
.narr-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 0; }
.narr-body { flex: 1; overflow-y: auto; padding: 10px 16px 12px; scrollbar-width: thin; }
.narr-body h2 { font-size: 19px; margin-bottom: 10px; letter-spacing: -0.02em; }
.narr-text { font-size: 14px; color: var(--ink-2); }
.narr-text p { margin-bottom: .7em; }
.narr-text strong { color: var(--ink); }
.narr-text ul, .narr-text ol { padding-left: 20px; margin: 0 0 .8em; }
.narr-text li { margin-bottom: 4px; }
.narr-text .practice { list-style: none; padding: 0; }
.narr-text .practice li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; border: 1px solid var(--line-soft); border-radius: 8px; margin-bottom: 6px; background: var(--surface-2); }
.diff { font-family: var(--font-mono); font-size: 11px; font-weight: 700; }
.diff-easy { color: var(--c-ok); } .diff-medium { color: var(--c-hot); } .diff-hard { color: var(--c-bad); }
.key-idea {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; margin: 12px 0; padding: 12px;
  background: var(--key-bg); border: 1.5px solid var(--key-line); border-radius: 10px; color: var(--key-ink); font-size: 13.5px;
}
.key-idea svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.key-idea .eyebrow { color: inherit; opacity: .75; margin-bottom: 2px; }
.key-idea p { margin: 0; }
.changed h3 { margin: 14px 0 6px; }
.changed ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.changed li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; font-size: 13px; color: var(--ink-2); }
.changed li::before { content: "+"; display: grid; place-items: center; width: 16px; height: 16px; margin-top: 2px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-ink); font-family: var(--font-mono); font-size: 12px; font-weight: 700; }
.narr-nav { display: flex; gap: 8px; padding: 12px 16px 6px; border-top: 1px solid var(--line-soft); }
.narr-keys { padding: 0 16px 10px; font-size: 11px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- Code panel ---------- */
.codepanel { overflow: hidden; display: flex; flex-direction: column; flex: none; }
.code-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--line-soft); }
.code-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.code-tabs { margin-left: auto; display: flex; padding: 2px; border-radius: 9px; background: var(--surface-3); border: 1px solid var(--line-soft); }
.code-tab { border: 0; background: none; padding: 3px 10px; border-radius: 7px; cursor: pointer; font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: var(--ink-2); }
.code-tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1.5px var(--line); }
.code-scroll { position: relative; overflow: auto; max-height: min(290px, 34vh); padding: 8px 0; scrollbar-width: thin; }
.code-lines { position: relative; margin: 0; font-size: 12.5px; line-height: 20px; min-width: max-content; font-variant-ligatures: none; }
.code-hl {
  position: absolute; left: 0; right: 0; height: 20px; background: var(--code-active);
  box-shadow: inset 3px 0 0 var(--code-active-line); transition: transform .28s cubic-bezier(.3,.7,.3,1), opacity .2s; pointer-events: none;
  opacity: 0;
}
.code-line { position: relative; display: block; padding: 0 14px 0 0; white-space: pre; }
.code-line .ln { display: inline-block; width: 38px; padding-right: 12px; text-align: right; color: var(--ink-3); user-select: none; }
.code-line.is-active .ln { color: var(--ink); font-weight: 700; }
.tok-kw { color: var(--syn-kw); } .tok-type { color: var(--syn-type); } .tok-fn { color: var(--syn-fn); }
.tok-str { color: var(--syn-str); } .tok-num { color: var(--syn-num); } .tok-com { color: var(--syn-com); font-style: italic; }
.vars { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 10px; border-top: 1px solid var(--line-soft); min-height: 42px; align-items: center; }
.vars-empty { font-size: 12px; color: var(--ink-3); }
.var { font-family: var(--font-mono); font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line-soft); background: var(--surface-2); transition: background .3s, border-color .3s; }
.var b { font-weight: 700; }
.var.is-changed { background: var(--c-hot-soft); border-color: var(--c-hot); }

/* ---------- Search dialog ---------- */
.search-dialog { position: fixed; inset: 0; z-index: 60; display: grid; place-items: start center; padding: 12vh 16px 16px; background: rgba(20,18,12,.35); }
.search-panel { width: min(560px, 100%); overflow: hidden; }
.search-input { width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; font: inherit; font-size: 16px; color: var(--ink); outline: none; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.search-results li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.search-results li[aria-selected="true"] { background: var(--accent-soft); }
.search-results .n { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); width: 22px; }
.search-results .w { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.search-empty { padding: 16px; color: var(--ink-3); font-size: 14px; }
