:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-border: #262b38;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #f97316;
  --static: #a855f7;
  --stack: #3b82f6;
  --heap: #10b981;
  --borrow-shared: #22c55e;
  --borrow-mut: #f59e0b;
  --error: #ef4444;
  --code-bg: #0b0d12;
  --sidenav-w: 280px;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must beat class-level `display` rules (e.g.
   `.app-shell { display: flex }`), otherwise hiding a view does nothing. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Slim Top Bar */
header {
  height: 52px;
  padding: 0 18px;
  border-bottom: 1px solid var(--panel-border);
  background: #13161f;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.btn-icon {
  background: #222736;
  color: var(--text);
  border: 1px solid #333a4d;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: #2c3347;
  border-color: var(--accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: rgba(249, 115, 22, 0.15);
  color: var(--accent);
  border: 1px solid rgba(249, 115, 22, 0.4);
  font-weight: 700;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
}

h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-switch {
  display: inline-flex;
  background: #0b0d12;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.mode-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  background: rgba(249, 115, 22, 0.18);
  color: var(--accent);
}

.card.code-card[hidden],
.card.lab-code-card[hidden] {
  display: none;
}

.card.lab-code-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.card.lab-code-card .card-header,
.card.lab-code-card .lab-toolbar,
.card.lab-code-card .lab-disclaimer,
.card.lab-code-card .controls,
.card.lab-code-card .kbd-hint {
  flex-shrink: 0;
}

.lab-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--panel-border);
  background: #13161f;
}

.lab-picker-btn {
  flex: 1;
  min-width: 150px;
  text-align: left;
  background: #0b0d12;
  color: var(--text);
  border: 1px solid #333a4d;
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-picker-btn:hover {
  border-color: var(--accent);
}

/* Unified Concepts / Examples Picker Modal */
.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 14, 0.74);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 24px;
}

.picker-backdrop[hidden] {
  display: none;
}

.picker-modal {
  width: min(880px, 100%);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: #13161f;
  border: 1px solid #30374a;
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
}

.picker-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.picker-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.picker-hint {
  font-size: 11px;
  color: var(--muted);
}

.picker-search-bar {
  padding: 12px 18px 8px;
}

.picker-search-bar input {
  width: 100%;
  background: #0b0d12;
  color: var(--text);
  border: 1px solid #333a4d;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--sans);
  outline: none;
}

.picker-search-bar input:focus {
  border-color: var(--accent);
}

.picker-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 18px 12px;
  border-bottom: 1px solid var(--panel-border);
}

.picker-grid {
  padding: 14px 18px 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 10px;
}

.picker-card {
  text-align: left;
  background: #171b26;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 11px 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 7px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.picker-card:hover {
  border-color: var(--accent);
  background: #1d2230;
  transform: translateY(-1px);
}

.picker-card.active {
  border-color: var(--accent);
  background: rgba(249, 115, 22, 0.1);
}

.picker-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.picker-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.picker-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.picker-pill {
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.14);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.picker-pill.err {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

.picker-pill.solved {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.45);
}

.picker-challenge-prompt {
  font-size: 12px;
  line-height: 1.45;
  color: #cbd5e1;
}

/* v1.3 "Fix the Borrow Error" Challenge Banner */
.challenge-banner {
  border: 1px solid rgba(249, 115, 22, 0.4);
  background: rgba(249, 115, 22, 0.08);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.challenge-banner.solved {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.1);
}

.challenge-banner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.challenge-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.challenge-prompt {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

.challenge-expected-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.challenge-expected {
  margin: 0;
  padding: 6px 9px;
  border-radius: 6px;
  background: #0b0d12;
  border: 1px solid var(--panel-border);
  font-family: var(--mono);
  font-size: 12px;
  color: #6ee7b7;
  white-space: pre-wrap;
}

.challenge-hint {
  font-size: 12.5px;
  color: #93c5fd;
}

.challenge-hint summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.challenge-hint div {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--text);
  line-height: 1.45;
}

.picker-preview {
  margin: 0;
  padding: 7px 9px;
  border-radius: 6px;
  background: #0b0d12;
  border: 1px solid #1f2433;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.45;
  color: #9ca3af;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

.picker-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 28px 12px;
  color: var(--muted);
  font-size: 13px;
}

/* Custom Right-Click Context Menu */
.ctx-menu {
  position: fixed;
  z-index: 200;
  min-width: 210px;
  background: #13161f;
  border: 1px solid #30374a;
  border-radius: 10px;
  padding: 5px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ctx-menu[hidden],
.ctx-item[hidden],
.ctx-sep[hidden] {
  display: none;
}

.ctx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: var(--sans);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}

.ctx-item:hover {
  background: rgba(249, 115, 22, 0.16);
  color: var(--accent);
}

.ctx-kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}

.ctx-sep {
  height: 1px;
  background: var(--panel-border);
  margin: 3px 6px;
}

.lab-link-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.lab-disclaimer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(249, 115, 22, 0.06);
  border-bottom: 1px solid var(--panel-border);
}

.lab-status {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 2px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.lab-status:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--panel-border);
}

.lab-status.ok {
  color: var(--heap);
}

.lab-status.err {
  color: var(--error);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
}

.tab-badge.ok {
  background: rgba(16, 185, 129, 0.18);
  color: var(--heap);
}

.tab-badge.err {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.lab-editor-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  overflow: visible;
  background: var(--code-bg);
}

.lab-gutter {
  padding: 10px 8px 10px 10px;
  text-align: right;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  color: #555e73;
  background: #0e1118;
  border-right: 1px solid var(--panel-border);
  user-select: none;
  flex-shrink: 0;
}

.lab-gutter-line {
  padding: 0 4px;
  border-radius: 3px;
}

.lab-gutter-line.active {
  color: var(--accent);
  background: rgba(249, 115, 22, 0.16);
  font-weight: 700;
}

.lab-gutter-line.error {
  color: var(--error);
  background: rgba(239, 68, 68, 0.18);
  font-weight: 700;
}

.lab-editor-stack {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 180px;
}

.lab-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  font-variant-ligatures: none;
  letter-spacing: normal;
  word-spacing: normal;
  tab-size: 4;
  white-space: pre;
  color: var(--text);
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.hl-line {
  min-height: 1.55em;
  margin: 0 -12px;
  padding: 0 12px;
}

.hl-line.active {
  background: rgba(249, 115, 22, 0.11);
}

.hl-line.error {
  background: rgba(239, 68, 68, 0.16);
}

.hl-err-span {
  text-decoration: underline wavy var(--error);
  text-underline-offset: 3px;
}

/* Zero-dependency Rust syntax highlighting tokens */
.tok-kw      { color: #ff7b72; font-weight: 600; }
.tok-type    { color: #79c0ff; }
.tok-str     { color: #a5d6ff; }
.tok-char    { color: #a5d6ff; }
.tok-num     { color: #ffa657; }
.tok-comment { color: #6e7681; font-style: italic; }
.tok-macro   { color: #d2a8ff; }
.tok-op      { color: #ff9e64; }
.tok-life    { color: #f2cc60; }

.lab-editor {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 180px;
  border: none;
  outline: none;
  resize: none;
  padding: 10px 12px;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  font-variant-ligatures: none;
  letter-spacing: normal;
  word-spacing: normal;
  tab-size: 4;
  white-space: pre;
  overflow-y: hidden;
  overflow-x: auto;
}

.lab-editor::selection {
  background: rgba(59, 130, 246, 0.35);
}

.output-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.output-banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
}

.output-banner.ok {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: var(--heap);
}

.output-banner.err {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.output-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ownership-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ownership-pill {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
}

.ownership-pill.static { border-color: rgba(168, 85, 247, 0.4); color: #d8b4fe; }
.ownership-pill.heap   { border-color: rgba(16, 185, 129, 0.4); color: #6ee7b7; }
.ownership-pill.mut    { border-color: rgba(245, 158, 11, 0.4); color: #fcd34d; }
.ownership-pill.shared { border-color: rgba(34, 197, 94, 0.4); color: #86efac; }
.ownership-pill.moved  { border-color: rgba(148, 163, 184, 0.4); color: #cbd5e1; }

.ownership-current-card {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ownership-current-head {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

.ownership-timeline {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ownership-step {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.35);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ownership-step:hover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.ownership-step.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}

.ownership-step-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.ownership-step-num {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.16);
  padding: 1px 6px;
  border-radius: 4px;
}

.ownership-step-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.ownership-step-body {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 6px;
}

.ownership-step-body code {
  color: #e2e8f0;
  font-family: var(--mono);
  font-size: 11.5px;
}

.ownership-step-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ownership-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.1);
  color: var(--text);
}

.diag-card {
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.diag-card:hover {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.13);
}

.diag-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.diag-code {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.2);
  padding: 2px 7px;
  border-radius: 4px;
}

.diag-loc {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.diag-msg {
  color: var(--text);
  line-height: 1.45;
}

.diag-fix {
  margin-top: 6px;
  font-size: 12px;
  color: #93c5fd;
}

.diag-solution {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.diag-solution-label {
  font-size: 11px;
  font-weight: 700;
  color: #6ee7b7;
  margin-bottom: 5px;
}

.diag-solution-code {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: #e6edf3;
  white-space: pre-wrap;
}

.diag-tour-btn {
  margin-top: 8px;
  background: rgba(249, 115, 22, 0.14);
  color: var(--accent);
  border: 1px solid rgba(249, 115, 22, 0.35);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.lab-stdout {
  padding: 12px 14px;
  border-radius: 8px;
  background: #0b0d12;
  border: 1px solid var(--panel-border);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}

.lab-stdout-empty {
  color: var(--muted);
  font-style: italic;
}

/* Phase 6: Side-by-side Teaching Model vs Real rustc verification */
.rustc-verify-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.rustc-card {
  border-radius: 8px;
  padding: 12px 14px;
  background: #111520;
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rustc-compare-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-family: var(--mono);
}

.rustc-pill {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.rustc-pill.ok {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.rustc-pill.err {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.rustc-pill.match {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.rustc-pill.warn {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.rustc-pre {
  margin: 0;
  padding: 9px 11px;
  border-radius: 6px;
  background: #0b0d12;
  border: 1px solid #1f2433;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 220px;
  overflow-y: auto;
}

/* Predict-before-reveal checkpoint (Guided Tour tryError steps) */
.predict-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.predict-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #93c5fd;
}

.predict-actions {
  display: flex;
  gap: 8px;
}

.predict-feedback {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
}

.predict-feedback.correct {
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.predict-feedback.wrong {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.active-concept-pill {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--accent);
  background: rgba(249, 115, 22, 0.1);
  border: 1px solid rgba(249, 115, 22, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
}

/* App Shell: Sidenav + Center Workspace */
.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.sidenav {
  width: var(--sidenav-w);
  background: #13161f;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.24s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
  z-index: 20;
}

.app-shell.nav-collapsed .sidenav {
  margin-left: calc(-1 * var(--sidenav-w));
  opacity: 0;
  pointer-events: none;
}

.sidenav-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.btn-close-nav {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-close-nav:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.sidenav-search {
  padding: 8px 12px 0;
}

.sidenav-search input {
  width: 100%;
  background: #0b0d12;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-family: var(--sans);
  outline: none;
  transition: border-color 0.15s ease;
}

.sidenav-search input:focus {
  border-color: var(--accent);
}

.level-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-border);
}

.filter-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--panel-border);
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: all 0.15s ease;
}

.filter-btn:hover {
  color: var(--text);
  border-color: #3d4558;
}

.filter-btn.active {
  background: var(--accent);
  color: #0b0d12;
  border-color: var(--accent);
}

.concept-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.concept-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 8px 4px;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #cbd5e1;
  border: 1px solid transparent;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-item.active {
  background: rgba(249, 115, 22, 0.14);
  color: var(--accent);
  border-color: rgba(249, 115, 22, 0.45);
  font-weight: 600;
}

/* Maximized Center Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(360px, 430px) 1fr;
  gap: 16px;
  padding: 16px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

@media (max-width: 960px) {
  body { height: auto; overflow: auto; }
  header {
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .brand h1 { display: none; }
  .app-shell { overflow: visible; }
  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
    padding: 12px;
    gap: 12px;
  }
  .code-container { max-height: 46vh; }
  .memory-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }
  .memory-stage {
    min-width: 680px;
    grid-template-columns: repeat(3, minmax(200px, 1fr));
  }
  .stage-tabs {
    overflow-x: auto;
    scrollbar-width: thin;
  }
  .stage-tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

@media (max-width: 640px) {
  .active-concept-pill { display: none; }
  .brand-badge { font-size: 10px; padding: 2px 6px; }
  .mode-btn { padding: 4px 8px; font-size: 11px; }
  .workspace { padding: 8px; gap: 10px; }
  .controls { padding: 8px 10px; gap: 5px; }
  .btn { padding: 5px 8px; font-size: 11.5px; }
  .kbd-hint { display: none; }
  .picker-grid { grid-template-columns: 1fr; }
  .picker-backdrop { padding: 2vh 8px 12px; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.card-header {
  padding: 11px 16px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Code Panel */
.code-container {
  background: var(--code-bg);
  padding: 10px 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  overflow: auto;
  flex: 1;
  min-height: 0;
  position: relative;
}

.code-line {
  display: flex;
  align-items: center;
  padding: 1px 16px 1px 10px;
  border-left: 3px solid transparent;
  transition: background 0.18s ease, border-color 0.18s ease;
  white-space: pre;
}

.code-line.clickable { cursor: pointer; }
.code-line.clickable:hover { background: rgba(255, 255, 255, 0.04); }

.code-line.active {
  background: rgba(249, 115, 22, 0.14);
  border-left-color: var(--accent);
}

.code-line.error-line {
  background: rgba(239, 68, 68, 0.18);
  border-left-color: var(--error);
}

.line-num {
  width: 24px;
  color: #4b5563;
  user-select: none;
  text-align: right;
  margin-right: 8px;
  font-size: 11px;
}

.scope-tracks {
  display: flex;
  gap: 3px;
  margin-right: 8px;
  min-width: 14px;
}

.scope-tick {
  width: 4px;
  height: 18px;
  border-radius: 2px;
  opacity: 0.85;
}

/* Controls & Narration */
.controls {
  padding: 10px 14px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.btn {
  background: #222736;
  color: var(--text);
  border: 1px solid #333a4d;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #2c3347;
  border-color: #47516b;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: #0b0d12;
  border-color: var(--accent);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn.danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.5);
}

.btn.danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.28); }

.speed-select {
  background: #222736;
  color: var(--text);
  border: 1px solid #333a4d;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--mono);
  cursor: pointer;
}

.step-counter {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.kbd-hint {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--panel-border);
  background: #11141c;
}

kbd {
  background: #222736;
  border: 1px solid #333a4d;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text);
}

.narration {
  padding: 14px 16px;
  border-top: 1px solid var(--panel-border);
  background: #13161f;
  font-size: 14px;
  line-height: 1.55;
  flex: 1;
}

.narration-title {
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.compiler-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  display: none;
  animation: shake 0.35s ease;
}

.compiler-box.show { display: block; }

.compiler-box.err {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.compiler-box.ok {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #a7f3d0;
}

/* Memory Stage */
.memory-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
}

.memory-stage {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 16px;
  min-height: 100%;
}

.mem-illustrative {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-dim, #8b93a7);
  text-align: center;
  opacity: 0.85;
}

.mem-col {
  background: #12151e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.mem-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--panel-border);
}

.mem-title {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.mem-sub {
  font-size: 11px;
  color: var(--muted);
}

.mem-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.stack-frame {
  border: 1px dashed rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.04);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: popIn 0.25s ease;
}

.frame-label {
  font-family: var(--mono);
  font-size: 11px;
  color: #93c5fd;
  font-weight: 600;
}

.mem-block {
  background: #1b202e;
  border: 1px solid #2e364d;
  border-radius: 8px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 12px;
  transition: all 0.28s ease;
  animation: popIn 0.28s ease;
  position: relative;
}

.mem-block.static-block { border-left: 3px solid var(--static); }
.mem-block.stack-block  { border-left: 3px solid var(--stack); }
.mem-block.heap-block   { border-left: 3px solid var(--heap); }

.mem-block.moved {
  opacity: 0.38;
  border-style: dashed;
  border-color: #4b5563;
  background: #141720;
}

.mem-block.frozen {
  border-color: var(--borrow-shared);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
}

.mem-block.mut-locked {
  border-color: var(--borrow-mut);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.45);
}

.mem-block.conflict {
  border-color: var(--error);
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.4);
  animation: shake 0.35s ease;
}

.mem-block.dropped {
  opacity: 0.22;
  transform: scale(0.96);
  border-color: var(--error);
  border-style: dashed;
}

/* v1.1 Memory Step-Diff Highlighting ("What Changed") */
.mem-block.block-diff-new {
  border-color: var(--accent);
  animation: diffPulseNew 0.75s ease;
}

.mem-block.block-diff-changed {
  border-color: #60a5fa;
  animation: diffPulseChanged 0.75s ease;
}

.mem-block.block-diff-moved {
  animation: diffPulseTransition 0.65s ease;
}

.mem-block.block-diff-dropped {
  animation: diffPulseDrop 0.65s ease;
}

.block-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.diff-chip {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.diff-chip.new {
  background: rgba(249, 115, 22, 0.22);
  color: #fdba74;
  border: 1px solid rgba(249, 115, 22, 0.45);
}

.diff-chip.changed {
  background: rgba(59, 130, 246, 0.22);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.45);
}

.block-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.var-name { font-weight: 700; color: #f8fafc; }

.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.own     { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
.badge.copy    { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.badge.moved   { background: rgba(107, 114, 128, 0.25); color: #9ca3af; }
.badge.shared  { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.badge.mut     { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.badge.static  { background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }
.badge.dropped { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.badge.frozen  { background: rgba(34, 197, 94, 0.22); color: #86efac; }

.block-val {
  color: #cbd5e1;
  font-size: 12px;
  word-break: break-word;
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.field-cell {
  background: #12151f;
  border: 1px solid #283044;
  border-radius: 5px;
  padding: 4px 6px;
  text-align: center;
  font-size: 11px;
}

.field-cell span {
  display: block;
  font-size: 9px;
  color: var(--muted);
}

.char-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 6px;
}

.char-cell {
  width: 22px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #12151f;
  border: 1px solid #2e364d;
  border-radius: 4px;
  font-size: 12px;
  transition: all 0.25s ease;
}

.char-cell.sliced {
  background: rgba(34, 197, 94, 0.22);
  border-color: var(--borrow-shared);
  color: #86efac;
  font-weight: 700;
}

#arrow-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

.arrow-path {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 6 4;
  animation: flow 1.1s linear infinite;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 16px;
  border-top: 1px solid var(--panel-border);
  font-size: 12px;
  color: var(--muted);
  background: #13161f;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Stage Tabs & Notes Panel */
.stage-header {
  padding: 8px 14px;
}

.stage-tabs {
  display: flex;
  gap: 6px;
}

.stage-tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s ease;
}

.stage-tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.stage-tab-btn.active {
  background: rgba(249, 115, 22, 0.16);
  color: var(--accent);
  border-color: rgba(249, 115, 22, 0.45);
}

.notes-panel {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.memory-scroll[hidden],
.notes-panel[hidden],
.step-notes-panel[hidden],
.stage-toast[hidden],
.memory-stage[hidden],
.legend[hidden] {
  display: none;
}

.step-notes-panel {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-notes-card {
  background: #12151e;
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 18px 20px;
  font-size: 15px;
  line-height: 1.65;
}

.step-notes-body {
  color: #cbd5e1;
  margin-top: 8px;
}

.stage-toast {
  margin: 0 16px 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  animation: shake 0.35s ease;
}

.stage-toast.err {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.stage-toast.ok {
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #a7f3d0;
}

.notes-summary {
  background: #12151e;
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.notes-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 10px;
}

.keywords-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.keyword-card {
  background: #12151e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keyword-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.keyword-token {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: #f8fafc;
  background: #1b202e;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid #2e364d;
}

.mut-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.mut-badge.immutable    { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.mut-badge.mutable      { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.mut-badge.owned        { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
.mut-badge.compile-time { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }

.keyword-role {
  font-size: 13px;
  line-height: 1.5;
  color: #cbd5e1;
}

.keyword-doc-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.keyword-doc-link:hover { text-decoration: underline; }

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule-item {
  background: #12151e;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.rule-item strong {
  font-family: var(--mono);
  color: #f8fafc;
  margin-right: 6px;
}

.docs-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-link-chip {
  background: #12151e;
  border: 1px solid #2e364d;
  color: var(--text);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.doc-link-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes flow {
  from { stroke-dashoffset: 20; }
  to   { stroke-dashoffset: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes diffPulseNew {
  0%   { opacity: 0.35; transform: translateY(4px) scale(0.98); box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.6); }
  50%  { opacity: 1; transform: translateY(0) scale(1); box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.22); }
  100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0); }
}

@keyframes diffPulseChanged {
  0%   { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.65); background: rgba(59, 130, 246, 0.2); }
  55%  { box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.22); }
  100% { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0); }
}

@keyframes diffPulseTransition {
  0%   { box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(148, 163, 184, 0); }
}

@keyframes diffPulseDrop {
  0%   { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.5); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .mem-block,
  .mem-block.block-diff-new,
  .mem-block.block-diff-changed,
  .mem-block.block-diff-moved,
  .mem-block.block-diff-dropped,
  .stack-frame,
  .arrow-path,
  .compiler-box,
  .stage-toast {
    animation: none !important;
    transition: none !important;
  }
}

/* ===========================================================================
   Review-driven additions: keyword "when" + current-step highlight, expanded
   mutability badges, Common Errors cards, Step Notes try-error/fix boxes,
   and the global Glossary panel.
   =========================================================================== */

/* Highlight the keyword card(s) relevant to the current step (N3). */
.keyword-card.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.35);
}

.keyword-when {
  font-size: 12px;
  line-height: 1.45;
  color: #94a3b8;
  padding-top: 6px;
  border-top: 1px dashed var(--panel-border);
}

.keyword-when span {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 10px;
  color: var(--accent);
  margin-right: 4px;
}

/* Expanded mutability enum (N6): moved / consumed / runtime. */
.mut-badge.moved        { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.mut-badge.consumed     { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }
.mut-badge.runtime      { background: rgba(14, 165, 233, 0.18); color: #7dd3fc; }

/* Common Errors reference (N4 / P0). */
.common-errors-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.common-error-card {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-left: 3px solid var(--error);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.common-error-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.error-code {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: #fecaca;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}

.error-trigger {
  font-size: 13px;
  color: #fca5a5;
}

.error-fix {
  font-size: 13px;
  line-height: 1.5;
  color: #cbd5e1;
}

.error-fix span,
.step-try-fix span,
.step-try-error span {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  margin-right: 6px;
}

.error-fix span {
  color: #86efac;
  background: rgba(16, 185, 129, 0.16);
}

/* Step Notes try-error / fix boxes (N1). */
.step-try-error {
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  font-family: var(--mono);
  color: #fecaca;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
}

.step-try-error span {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.2);
}

.step-try-fix {
  margin-top: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #bbf7d0;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 8px;
}

.step-try-fix span {
  color: #86efac;
  background: rgba(16, 185, 129, 0.16);
}

/* Global Glossary panel (N7 / P2). */
.glossary-search {
  margin-bottom: 14px;
}

.glossary-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: #0b0d12;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.glossary-search input:focus {
  outline: none;
  border-color: var(--accent);
}

.glossary-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.glossary-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 8px;
}

.glossary-entry {
  background: #12151e;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 8px;
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.glossary-entry a {
  color: var(--accent);
  text-decoration: none;
}

.glossary-entry a:hover { text-decoration: underline; }

.glossary-term {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: #f8fafc;
  white-space: nowrap;
}

.glossary-def {
  font-size: 12px;
  line-height: 1.45;
  color: #cbd5e1;
}

.glossary-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 0;
}

/* ===========================================================================
   Richer Step Notes: focused source line + plain-language ownership summary.
   =========================================================================== */

.step-lead {
  font-size: 15px;
  line-height: 1.6;
  color: #d7dee8;
}

.step-focus {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 9px 12px;
  background: var(--code-bg);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-x: auto;
  white-space: pre;
}

.step-focus-label {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.35);
  border-radius: 999px;
  padding: 2px 8px;
}

.step-focus code {
  color: #e6edf3;
}

.step-state {
  margin-top: 18px;
  padding-top: 4px;
  border-top: 1px dashed var(--panel-border);
}

.state-group {
  margin-top: 10px;
}

.state-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.state-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 12.5px;
}

.state-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.state-name {
  font-family: var(--mono);
  font-weight: 600;
  color: #f8fafc;
}

.state-val {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  text-align: right;
}

/* Global Glossary layout (populated by render_glossary). */
.glossary-group {
  margin-bottom: 20px;
}

.glossary-entry {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  margin-bottom: 8px;
}

.glossary-entry-text {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}