/* ML Explorer Lab: lab framework, home launcher and shell additions.
   Builds on the tokens in style.css; nothing here introduces a new palette. */

/* Saturated series colours for the light theme so points and curves keep
   their contrast on a white canvas (the pastel set is tuned for dark). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --series-1: #0a84c6; --series-2: #d94848; --series-3: #1f9d55; --series-4: #c98a06;
    --series-5: #7c4ddb; --series-6: #cf3f8a; --series-7: #dd6a12;
  }
}
:root[data-theme="light"] {
  --series-1: #0a84c6; --series-2: #d94848; --series-3: #1f9d55; --series-4: #c98a06;
  --series-5: #7c4ddb; --series-6: #cf3f8a; --series-7: #dd6a12;
}

/* ---------- lab layout ---------- */
.lab .lab-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.lab .stage { min-height: 0; }
.stage-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.lab-svg { width: 100%; height: auto; display: block; touch-action: none; }
.stage .lab-svg { background: var(--bg-inset); border: 1px solid var(--border-soft); border-radius: 6px; }
.stage-body .sub-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.stage-body .sub-cap { font-size: 11px; color: var(--text-faint); margin: 2px 0 6px; }
.stage-body .html-stage { background: var(--bg-inset); border: 1px solid var(--border-soft); border-radius: 6px; padding: 12px; overflow: auto; }

.lab-axes .ax-frame { fill: none; stroke: var(--border-soft); }
.lab-axes .ax-grid { stroke: var(--border-soft); stroke-width: 0.7; }
.lab-axes .ax-zero { stroke: var(--border); stroke-dasharray: 3 3; }
.lab-axes .ax-base { stroke: var(--border); }
.lab-axes .ax-tick { fill: var(--text-faint); font-size: 9.5px; font-family: var(--mono); }
.lab-axes .ax-label { fill: var(--text-dim); font-size: 10.5px; font-family: var(--mono); }
.lab-svg text, .xy-svg text, .arch-svg text, .net-svg text, .mx-svg text { font-family: var(--mono); }
.lab-svg .lbl { fill: var(--text-dim); font-size: 10.5px; }
.lab-svg .lbl-strong { fill: var(--text); font-size: 11px; font-weight: 600; }
.lab-svg .halo { paint-order: stroke; stroke: var(--bg-inset); stroke-width: 3px; stroke-linejoin: round; }

circle.pt, circle.pt-edit { cursor: grab; transition: r 0.15s ease; }
circle.pt-edit:hover { stroke: var(--text); }
circle.dragging { cursor: grabbing; }

/* ---------- player ---------- */
.player {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
.player-btns { display: flex; gap: 4px; }
.player-btns button { padding: 6px 8px; display: inline-flex; align-items: center; justify-content: center; min-width: 32px; }
.player-btns .play-btn { min-width: 40px; }
.player-track { flex: 1; position: relative; min-width: 140px; padding: 6px 0; }
.player-track input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 5px; border-radius: 3px; margin: 0; display: block;
  background: linear-gradient(90deg, var(--accent) var(--pct, 0%), var(--border) var(--pct, 0%));
}
.player-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-raised); cursor: pointer;
}
.player-track input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-raised); cursor: pointer; }
.player-ticks { position: absolute; left: 0; right: 0; top: 13px; height: 6px; pointer-events: none; }
.player-ticks span { position: absolute; width: 1px; height: 6px; background: var(--text-faint); transform: translateX(-0.5px); }
.player-meta { display: flex; gap: 8px; align-items: center; }
.player-meta select { width: auto; padding: 4px 6px; font-size: 11.5px; }
.player-pos { font-size: 11.5px; color: var(--text-dim); min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.icon-toggle { padding: 5px 7px; display: inline-flex; align-items: center; color: var(--text-faint); }
.icon-toggle.on { color: var(--accent); border-color: var(--accent); }

/* ---------- lower cards ---------- */
.lab-lower { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.lab-card { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.lab-card.wide { grid-column: span 2; }
.lab-card-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-faint); margin-bottom: 8px;
}
.lab-card-sub { text-transform: none; letter-spacing: 0; font-size: 10.5px; }
.lab-card-note { font-size: 11px; color: var(--text-faint); margin-top: 6px; line-height: 1.5; }
.chart-legend { text-transform: none; letter-spacing: 0; display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); }
.chart-legend b { color: var(--text); font-weight: 600; }

.lab-narr { display: flex; flex-direction: column; }
.narr-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.phase-chip {
  --chip: var(--text-faint);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; padding: 2px 9px; border-radius: 10px;
  border: 1px solid var(--chip); color: var(--chip); background: color-mix(in srgb, var(--chip) 12%, transparent);
  white-space: nowrap;
}
.narr-step { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.narr-title { font-size: 14px; font-weight: 600; margin: 10px 0 5px; line-height: 1.4; }
.narr-text { font-size: 12.5px; color: var(--text-dim); line-height: 1.65; }
.narr-text b { color: var(--text); }
.narr-tex { margin-top: 6px; overflow-x: auto; overflow-y: hidden; color: var(--text); }
.narr-tex .katex-display, .narr-tex math[display="block"] { margin: 0.35em 0; }
.katex { font-size: 1.06em; }
math { font-size: 1.05em; }
.tex-fallback { font-size: 12px; color: var(--text-dim); }

/* ---------- architecture diagram ---------- */
.arch-wrap { position: relative; }
.arch-svg { width: 100%; height: auto; display: block; overflow: visible; }
.arch-node { cursor: pointer; outline: none; }
.arch-node rect { fill: var(--bg-inset); stroke: var(--border); stroke-width: 1.2; transition: stroke 0.2s ease, fill 0.2s ease; }
.arch-node .an-label { fill: var(--text); font-size: 10.5px; font-weight: 600; }
.arch-node .an-sub { fill: var(--text-faint); font-size: 8.6px; }
.arch-node.k-data rect { stroke-dasharray: 4 3; }
.arch-node.k-param rect { fill: color-mix(in srgb, var(--series-4) 11%, var(--bg-inset)); }
.arch-node.k-loss rect { fill: color-mix(in srgb, var(--series-2) 13%, var(--bg-inset)); }
.arch-node.k-out rect { fill: color-mix(in srgb, var(--series-3) 13%, var(--bg-inset)); }
.arch-node.k-op rect { fill: color-mix(in srgb, var(--series-1) 8%, var(--bg-inset)); }
.arch-node:hover rect, .arch-node:focus-visible rect { stroke: var(--text-dim); }
.arch-node.on rect { stroke: var(--accent); stroke-width: 2.2; }
.arch-node.on .an-sub { fill: var(--text-dim); }
.ae-line { fill: none; stroke: var(--text-faint); stroke-width: 1.2; opacity: 0.8; }
.arch-edge.dashed .ae-line { stroke-dasharray: 4 3; }
.ae-flow { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 10; opacity: 0; }
.arch-edge.on .ae-line { stroke: var(--accent); opacity: 1; }
.arch-edge.on .ae-flow { opacity: 0.9; animation: ae-flow 0.8s linear infinite; }
@keyframes ae-flow { to { stroke-dashoffset: -14; } }
.ae-label { fill: var(--text-faint); font-size: 8.6px; }
.arch-tip {
  position: absolute; z-index: 6; max-width: 240px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-size: 11.5px; color: var(--text-dim); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28); pointer-events: none; line-height: 1.5;
}
.arch-tip b { color: var(--text); display: block; margin-bottom: 2px; }
.arch-tip .tip-tex { margin-top: 5px; color: var(--text); }

/* ---------- network diagram ---------- */
.net-svg { width: 100%; height: auto; display: block; }
.net-node { stroke: var(--border); stroke-width: 1.3; fill: var(--bg-inset); transition: fill 0.25s ease; }
.net-node.on { stroke: var(--accent); }
.net-node.sel { stroke: var(--series-4); stroke-width: 2.6; }
.net-edge { stroke: var(--border); transition: stroke-width 0.3s ease, stroke-opacity 0.3s ease; }
.net-edge.on { stroke-dasharray: 3 3; }
.net-lab { fill: var(--text-faint); font-size: 9.5px; }

/* ---------- charts ---------- */
.xy-svg { width: 100%; height: auto; display: block; overflow: visible; }
.xy-cursor { stroke: var(--text-faint); stroke-dasharray: 2 3; }
.bar-val { fill: var(--text-dim); font-size: 8.6px; }
.mx-svg { width: 100%; height: auto; display: block; }
.mx-cell { stroke: none; }
.mx-cell.on { stroke: var(--accent); stroke-width: 1.6; }
.mx-val { fill: var(--text); font-size: 8.4px; pointer-events: none; }
.mx-lab { fill: var(--text-faint); font-size: 9px; }

/* ---------- controls ---------- */
.class-pick { display: inline-flex; gap: 4px; margin-left: 2px; }
.class-pick button { padding: 3px 8px; font-size: 11.5px; display: inline-flex; align-items: center; gap: 5px; }
.class-pick button.on { border-color: var(--accent); color: var(--text); }
.file-btn {
  font-family: var(--mono); background: var(--bg-inset); color: var(--text); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 5px; cursor: pointer; font-size: 12.5px; display: inline-block;
}
.file-btn:hover { border-color: var(--text-dim); }
.check { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--text-dim); margin: 4px 0 10px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.swatch.ring { background: transparent !important; border: 1.5px solid var(--text); border-radius: 50%; }
.swatch.line { height: 2px; width: 14px; border-radius: 1px; }
.swatch.dash { height: 0; width: 14px; border-top: 2px dashed var(--text); background: transparent !important; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 5px 10px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--bg); }
.readout table { border-collapse: collapse; width: 100%; }
.readout td { padding: 1px 0; }
.readout td:last-child { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 12px; color: var(--text-dim); }
.kv b { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }

/* small html widgets used inside stages */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tok {
  font-size: 12px; padding: 4px 9px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg-raised); cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.tok.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-raised)); }
.tok.dim { opacity: 0.45; }
.mini-table { border-collapse: collapse; font-size: 11.5px; width: 100%; }
.mini-table th, .mini-table td { border-bottom: 1px solid var(--border-soft); padding: 4px 6px; text-align: left; }
.mini-table th { color: var(--text-faint); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.mini-table tr.on td { background: color-mix(in srgb, var(--series-4) 14%, transparent); }
.mini-table tr.ok td:first-child { border-left: 2px solid var(--series-3); }
.mini-table tr.bad td { color: var(--text-faint); text-decoration: line-through; }
.pill { display: inline-block; font-size: 10.5px; padding: 1px 7px; border-radius: 9px; border: 1px solid var(--border); color: var(--text-dim); }
.pill.good { border-color: var(--series-3); color: var(--series-3); }
.pill.bad { border-color: var(--series-2); color: var(--series-2); }

/* ---------- status bar ---------- */
.statusbar {
  display: flex; align-items: center; gap: 16px; padding: 4px 14px; border-top: 1px solid var(--border); background: var(--bg);
  font-size: 11px; color: var(--text-faint); position: sticky; bottom: 0; z-index: 9; white-space: nowrap; overflow: hidden;
}
.statusbar .sb-item { display: inline-flex; gap: 6px; align-items: center; }
.statusbar .sb-item b { color: var(--text-dim); font-weight: 500; }
.statusbar .sb-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--pastel-green); display: inline-block; }
.statusbar .sb-right { margin-left: auto; display: inline-flex; gap: 14px; }
.statusbar kbd { font-family: var(--mono); font-size: 10px; border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }

/* ---------- home launcher ---------- */
.home-hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 22px; margin-bottom: 26px; align-items: stretch; }
.home-hero h1 { font-size: 28px; margin: 0 0 10px; letter-spacing: -0.3px; }
.home-hero p { color: var(--text-dim); font-size: 14.5px; line-height: 1.65; margin: 0 0 14px; max-width: 640px; }
.hero-stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 16px; }
.hero-stat { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; background: var(--bg-raised); min-width: 92px; }
.hero-stat b { display: block; font-size: 20px; color: var(--text); }
.hero-stat span { font-size: 11px; color: var(--text-faint); }
.hero-viz { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 10px; padding: 10px; position: relative; overflow: hidden; min-height: 220px; }
.hero-viz svg { width: 100%; height: 100%; display: block; }
.hero-viz .hv-cap { position: absolute; left: 14px; bottom: 10px; font-size: 11px; color: var(--text-faint); }
.home-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-faint); margin: 26px 0 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.paths { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.path-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--bg-raised); }
.path-card h4 { margin: 0 0 4px; font-size: 13.5px; }
.path-card p { margin: 0 0 8px; font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.path-steps { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 11.5px; }
.path-steps a { text-decoration: none; border: 1px solid var(--border-soft); border-radius: 4px; padding: 2px 6px; color: var(--text-dim); }
.path-steps a:hover { border-color: var(--text-dim); color: var(--text); }
.path-steps .arrow { color: var(--text-faint); }
.recent-row { display: flex; gap: 8px; flex-wrap: wrap; }
.recent-row a { text-decoration: none; font-size: 12px; border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; color: var(--text-dim); background: var(--bg-raised); }
.recent-row a:hover { color: var(--text); border-color: var(--text-dim); }
.algo-row .algo-badges { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.algo-row .new-badge { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--series-3); border: 1px solid var(--series-3); border-radius: 8px; padding: 0 6px; }
.nav-item .name .new-dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--series-3); margin-left: 6px; vertical-align: middle; }

/* compare matrix */
.cmp-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.cmp { border-collapse: collapse; width: 100%; font-size: 12px; min-width: 760px; }
.cmp th, .cmp td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); text-align: center; white-space: nowrap; }
.cmp th { background: var(--bg-raised); color: var(--text-faint); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; position: sticky; top: 0; cursor: pointer; user-select: none; }
.cmp th:first-child, .cmp td:first-child { text-align: left; position: sticky; left: 0; background: var(--bg-raised); }
.cmp td:first-child a { text-decoration: none; color: var(--text); }
.cmp td:first-child a:hover { text-decoration: underline; }
.cmp tbody tr:hover td { background: var(--bg-inset); }
.dots { letter-spacing: 1px; color: var(--text); }
.dots .off { color: var(--border); }
.cmp-filter { display: flex; gap: 6px; flex-wrap: wrap; }
.cmp-filter button { font-size: 11px; padding: 3px 9px; }
.cmp-filter button.on { border-color: var(--accent); }

/* reference additions */
.eq-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 14px; }
.eq-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; background: var(--bg-raised); min-width: 0; }
.eq-card .eq-name { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-faint); margin-bottom: 2px; }
.eq-card .eq-body { overflow-x: auto; overflow-y: hidden; }
.eq-card .eq-note { font-size: 12px; color: var(--text-dim); line-height: 1.55; }
.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 16px; display: flex; flex-direction: column; gap: 12px; }
.tl-item { position: relative; font-size: 13px; color: var(--text-dim); line-height: 1.55; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text-faint); }
.tl-item b { color: var(--text); }
.tl-year { font-size: 11px; color: var(--text-faint); margin-right: 8px; }
.related-row { display: flex; gap: 8px; flex-wrap: wrap; }
.related-row a { text-decoration: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 11px; font-size: 12.5px; color: var(--text-dim); background: var(--bg-raised); }
.related-row a:hover { color: var(--text); border-color: var(--text-dim); }
.cx-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.cx-card { border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; background: var(--bg-raised); }
.cx-card .cx-k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-faint); }
.cx-card .cx-v { font-size: 13.5px; color: var(--text); margin-top: 3px; }

/* keyboard help overlay */
.kb-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.kb-box { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; max-width: 420px; width: 100%; }
.kb-box h3 { margin: 0 0 12px; font-size: 14px; }
.kb-box table { width: 100%; font-size: 12.5px; color: var(--text-dim); border-collapse: collapse; }
.kb-box td { padding: 5px 0; }
.kb-box td:first-child { width: 120px; }
.kb-box kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; background: var(--bg-inset); color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .lab-lower { grid-template-columns: 1fr; }
  .lab-card.wide { grid-column: span 1; }
}
@media (max-width: 900px) {
  .home-hero { grid-template-columns: 1fr; }
  .hero-viz { min-height: 200px; }
}
@media (max-width: 780px) {
  .player { gap: 8px; padding: 8px; }
  .player-track { order: 3; flex-basis: 100%; }
  .player-meta { margin-left: auto; }
  .statusbar .sb-hide-m { display: none; }
  .home-hero h1 { font-size: 22px; }
  .class-pick { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .arch-edge.on .ae-flow { animation: none; }
}
@media print {
  .statusbar, .player, .lab-lower, .kb-overlay { display: none !important; }
}

/* ---------- algorithm header + tab bar ---------- */
.algo-crumbs { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.crumb-cat { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--cat-color, var(--text-faint)); }
.new-badge { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--series-3); border: 1px solid var(--series-3); border-radius: 8px; padding: 0 6px; }
.tabs { align-items: flex-end; }
.tabs-right { margin-left: auto; display: flex; gap: 12px; align-items: center; padding-bottom: 6px; }
.tabs-right .print-btn { margin-bottom: 0; }
.nav-arrow { font-size: 11.5px; color: var(--text-faint); text-decoration: none; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-arrow:hover { color: var(--text); }
@media (max-width: 780px) {
  .nav-arrow { display: none; }
}
.xy-svg .ax-label, .lab-svg .ax-label, .xy-svg .note-text { fill: var(--text-dim); font-size: 10.5px; font-family: var(--mono); }
.thr-line { stroke: var(--series-4); stroke-dasharray: 3 3; }
.home-categories .algo-desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* native controls and scrollbars follow the active palette */
:root { color-scheme: dark; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { color-scheme: light; } }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
.topbar { top: env(safe-area-inset-top, 0px); }
.statusbar { padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px)); }
/* embedded preview: the host frame cannot print or download */
.embed .print-btn, .embed [data-ds="export"] { display: none !important; }

/* =====================================================================
   Polish pass: kicker, launcher paths, category accordion, fixed status
   bar, viewport-fitted lab stage and a full-width lower section.
   ===================================================================== */
:root { --kicker-fg: #86efac; --kicker-bg: #86efac; --kicker-ink: #0f2418; --sb-h: 27px; }

/* ---------- kicker: shrink-wrapped, dark ink on green in dark mode ---------- */
.guide-kicker {
  display: inline-flex; align-items: center; width: fit-content; max-width: 100%;
  background: var(--kicker-bg); color: var(--kicker-ink); border-color: transparent;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --kicker-bg: var(--pastel-green-soft); --kicker-ink: #1f6b42; }
}
:root[data-theme="light"] { --kicker-bg: var(--pastel-green-soft); --kicker-ink: #1f6b42; }
:root[data-theme="dark"] { --kicker-bg: #86efac; --kicker-ink: #0f2418; }
.home-hero .guide-kicker { margin-bottom: 12px; }

/* ---------- fixed status bar, no page-level scroll on desktop ---------- */
html, body { height: 100%; }
html { overflow: hidden; }
body { position: relative; min-height: 0; height: 100%; overflow: hidden; padding-bottom: var(--sb-h); }
/* KaTeX's visually-hidden MathML is position:absolute; anchor it to its formula so it
   can never stretch the document (that was the phantom whitespace below the status bar) */
.katex { position: relative; }
.layout { min-height: 0; }
.main, .sidebar { overscroll-behavior: contain; }
.statusbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--sb-h); z-index: 20;
  padding: 0 14px env(safe-area-inset-bottom, 0px);
}
@media (max-width: 780px) {
  html { overflow: visible; height: auto; }
  body { height: auto; min-height: 100%; overflow: visible; }
  .statusbar .sb-right { display: none; }
}

/* ---------- learning paths: coloured cards with a numbered stepper ---------- */
.paths { grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 14px; }
.path-card {
  --pc: var(--series-1);
  display: flex; flex-direction: column; padding: 0; overflow: hidden;
  border-color: color-mix(in srgb, var(--pc) 35%, var(--border));
  background: color-mix(in srgb, var(--pc) 4%, var(--bg-raised));
}
.path-head { display: flex; gap: 11px; align-items: flex-start; padding: 13px 15px 11px; background: color-mix(in srgb, var(--pc) 11%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--pc) 22%, var(--border-soft)); }
.path-glyph { flex-shrink: 0; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: color-mix(in srgb, var(--pc) 22%, var(--bg-raised)); color: var(--pc); }
.path-glyph svg { width: 17px; height: 17px; }
.path-card h4 { margin: 0 0 3px; font-size: 13.5px; }
.path-card p { margin: 0; font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
.path-meta { font-size: 10.5px; color: var(--pc); margin-left: auto; white-space: nowrap; padding-top: 2px; }
.path-steps { list-style: none; margin: 0; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 0; }
.path-steps li { position: relative; }
.path-steps li + li::before { content: ""; position: absolute; left: 17px; top: -5px; height: 10px; width: 2px; background: color-mix(in srgb, var(--pc) 40%, var(--border)); }
.path-steps a {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-dim);
  padding: 5px 6px; border-radius: 6px; font-size: 12.5px; border: none;
}
.path-steps a:hover, .path-steps a:focus-visible { background: color-mix(in srgb, var(--pc) 13%, transparent); color: var(--text); outline: none; }
.path-steps .step-n {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700; color: var(--pc); border: 1.5px solid var(--pc); background: var(--bg-raised);
  font-variant-numeric: tabular-nums;
}
.path-steps a:hover .step-n { background: var(--pc); color: var(--bg); }
.path-steps .step-name { flex: 1; min-width: 0; }
.path-steps .step-seen { font-size: 9.5px; color: var(--text-faint); }

/* ---------- category accordion: full-width horizontal rows ---------- */
.cat-accordion { display: flex; flex-direction: column; gap: 10px; }
.cat-row { --cat-color: var(--text); border: 1px solid var(--border); border-radius: 10px; background: var(--bg-raised); overflow: hidden; transition: border-color 0.15s ease; }
.cat-row.open { border-color: color-mix(in srgb, var(--cat-color) 45%, var(--border)); }
.cat-head {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; cursor: pointer;
  padding: 12px 16px; border: none; border-radius: 0; background: color-mix(in srgb, var(--cat-color) 6%, transparent); font-family: var(--mono);
}
.cat-head:hover { background: color-mix(in srgb, var(--cat-color) 11%, transparent); border: none; }
.cat-head:focus-visible { outline: 2px solid var(--cat-color); outline-offset: -2px; }
.cat-head .category-icon { flex-shrink: 0; }
.cat-title { display: flex; flex-direction: column; gap: 2px; min-width: 150px; }
.cat-title b { font-size: 14px; color: var(--text); font-weight: 600; }
.cat-title span { font-size: 11px; color: var(--text-faint); }
.cat-chips { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; mask-image: linear-gradient(90deg, #000 85%, transparent); }
.cat-chips span { flex-shrink: 0; font-size: 11px; color: var(--text-dim); border: 1px solid var(--border-soft); border-radius: 12px; padding: 2px 9px; background: var(--bg-inset); }
.cat-row.open .cat-chips { visibility: hidden; }
.cat-chev { flex-shrink: 0; color: var(--text-faint); transition: transform 0.2s ease; font-size: 16px; }
.cat-row.open .cat-chev { transform: rotate(90deg); color: var(--cat-color); }
.cat-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.25s ease; }
.cat-row.open .cat-body { grid-template-rows: 1fr; }
.cat-body > .algo-grid { min-height: 0; overflow: hidden; }
.algo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.cat-row.open .algo-grid { border-top: 1px solid var(--border-soft); }
.algo-grid .algo-row { border-bottom: 1px solid var(--border-soft); border-right: 1px solid var(--border-soft); height: 100%; }
.algo-grid .algo-desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 640px) {
  .cat-chips { display: none; }
  .cat-title { min-width: 0; flex: 1; }
}
@media (prefers-reduced-motion: reduce) { .cat-body, .cat-chev { transition: none; } }

/* ---------- lab: compact header, viewport-fitted stage ---------- */
.main-header.algo-head { margin-bottom: 12px; padding-bottom: 12px; }
.algo-head .algo-title-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.algo-head h1 { font-size: 22px; margin: 0 0 6px; }
.algo-head p { font-size: 13.5px; line-height: 1.6; margin: 0; max-width: 900px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.algo-head p.expanded { -webkit-line-clamp: unset; display: block; }
.algo-head + .tabs { margin-bottom: 14px; }
.lab .stage { padding: 12px; }
.lab .stage-toolbar { margin-bottom: 8px; }
.lab .stage-body > svg.lab-svg:only-child { width: 100%; }
.lab .stage-body > .html-stage { overflow: auto; }
.lab .stage-hint { margin-top: 6px; }

/* the lower section spans the full width under stage + controls */
.panel.lab { align-items: start; }
.panel.lab > .lab-lower { grid-column: 1 / -1; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); grid-auto-flow: row dense; align-items: stretch; }
.panel.lab > .lab-lower .lab-card { display: flex; flex-direction: column; }
.panel.lab > .lab-lower .lab-card.wide { grid-column: span 2; }
/* controls never set the row height: they fill the stage's height and scroll inside it,
   so the lower section starts right under the player with no gap */
.panel.lab > .controls { align-self: stretch; height: 0; min-height: 100%; overflow-y: auto; overscroll-behavior: contain; padding-right: 2px; }
.panel.lab > .controls.more-below { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 36px), transparent); }
.panel.lab > .controls.more-above { -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28px); mask-image: linear-gradient(to bottom, transparent, #000 28px); }
.panel.lab > .controls.more-above.more-below { -webkit-mask-image: linear-gradient(to bottom, transparent, #000 28px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to bottom, transparent, #000 28px, #000 calc(100% - 36px), transparent); }
@media (max-width: 1100px) {
  .panel.lab > .lab-lower .lab-card.wide { grid-column: auto; }
}
@media (max-width: 900px) {
  .panel.lab > .controls { height: auto; min-height: 0; overflow: visible; -webkit-mask-image: none; mask-image: none; }
}
.paths { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.path-steps { align-items: stretch; flex-wrap: nowrap; }
.arch-svg .lbl, .xy-svg .lbl, .net-svg .lbl { fill: var(--text-dim); font-size: 10.5px; font-family: var(--mono); }
.nav-item .name .nw { white-space: nowrap; }

/* =====================================================================
   Polish pass 2: scrollbars, custom select, collapsible sidebar,
   docked player, chart labels, print
   ===================================================================== */

/* ---------- minimal scrollbars ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; background: transparent; }
::-webkit-scrollbar-track { background: transparent; margin: 8px; }
::-webkit-scrollbar-thumb { background: transparent; border-radius: 6px; }
*:hover::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--text-faint) 45%, transparent); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint) !important; }
::-webkit-scrollbar-corner { background: transparent; }
/* desktop: native vertical bars are replaced by the short overlay thumb (js/ui.js);
   horizontal bars stay native but thin and hover-only */
html.oscroll-on ::-webkit-scrollbar { width: 0; }
@supports not selector(::-webkit-scrollbar) {
  html.oscroll-on * { scrollbar-width: none; }
  html:not(.oscroll-on) * { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--text-faint) 45%, transparent) transparent; }
}
.oscroll { position: fixed; z-index: 60; width: 12px; top: 0; left: -40px; height: 0; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.oscroll.show { opacity: .55; }
.oscroll.show.near, .oscroll.drag { opacity: 1; pointer-events: auto; }
.oscroll-thumb { position: absolute; right: 3px; top: 0; width: 4px; border-radius: 4px; background: var(--text-faint); transition: width .15s ease, background .15s ease; cursor: grab; }
.oscroll.near .oscroll-thumb, .oscroll.drag .oscroll-thumb { width: 6px; background: var(--text-dim); }
.oscroll.drag .oscroll-thumb { cursor: grabbing; }

/* ---------- custom select ---------- */
select.msel-native { display: none !important; }
.msel-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  background: var(--bg-inset); border: 1px solid var(--border); color: var(--text);
  font-family: var(--mono); font-size: 12.5px; padding: 6px 8px 6px 10px; border-radius: 5px; text-align: left; min-width: 0;
}
.msel-btn .msel-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.msel-btn .msel-chev { display: inline-flex; color: var(--text-faint); transition: transform .15s ease; flex-shrink: 0; }
.msel-btn:hover { border-color: var(--text-dim); }
.msel-btn.open { border-color: var(--text-dim); }
.msel-btn.open .msel-chev { transform: rotate(180deg); color: var(--text); }
.msel-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.msel-btn.compact { width: auto; padding: 4px 6px 4px 8px; font-size: 11.5px; gap: 6px; }
.msel-pop {
  position: fixed; z-index: 70; display: flex; flex-direction: column;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,.28), 0 2px 6px rgba(0,0,0,.12);
  opacity: 0; transform: translateY(-4px); transition: opacity .12s ease, transform .12s ease;
}
.msel-pop.up { transform: translateY(4px); }
.msel-pop.show { opacity: 1; transform: none; }
.msel-title { display: none; }
.msel-list { overflow-y: auto; outline: none; overscroll-behavior: contain; }
.msel-group { font-size: 10px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-faint); padding: 8px 10px 4px; }
.msel-opt { display: flex; align-items: center; gap: 6px; padding: 7px 10px 7px 6px; border-radius: 5px; font-size: 12.5px; cursor: pointer; color: var(--text-dim); white-space: nowrap; }
.msel-opt .msel-tick { width: 14px; display: inline-flex; justify-content: center; color: var(--text); flex-shrink: 0; }
.msel-opt .msel-txt { overflow: hidden; text-overflow: ellipsis; }
.msel-opt.active { background: var(--bg-inset); color: var(--text); }
.msel-opt.selected { color: var(--text); font-weight: 600; }
.msel-opt.disabled { opacity: .4; cursor: not-allowed; }
.msel-backdrop { position: fixed; inset: 0; z-index: 69; display: none; background: rgba(0,0,0,.42); }
.msel-backdrop.on { display: block; }
/* phones: the list opens as a bottom-sheet modal */
.msel-pop.sheet {
  left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); top: auto; max-height: 62vh; padding: 6px;
  border-radius: 14px; transform: translateY(16px);
}
.msel-pop.sheet.show { transform: none; }
.msel-pop.sheet .msel-title { display: block; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-faint); padding: 8px 10px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.msel-pop.sheet .msel-opt { padding: 12px 10px; font-size: 14px; white-space: normal; }

/* ---------- collapsible sidebar ---------- */
.side-toggle { display: inline-flex; align-items: center; justify-content: center; padding: 5px 7px; color: var(--text-dim); background: transparent; }
.side-toggle:hover { color: var(--text); }
.side-toggle .st-arrow { transition: transform .2s ease; transform-origin: 14px 12px; }
body.side-collapsed .side-toggle .st-arrow { transform: scaleX(-1); }
.sidebar { transition: width .2s ease, padding .2s ease, opacity .15s ease; }
@media (min-width: 781px) {
  body.side-collapsed .sidebar { width: 0; padding-left: 0; padding-right: 0; border-right-width: 0; opacity: 0; overflow: hidden; pointer-events: none; }
}
@media (max-width: 780px) { .side-toggle { display: none; } }

/* ---------- player docked to the stage ---------- */
.lab .lab-main { gap: 0; }
.lab .lab-main > .stage:not(:last-child) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom-style: dashed; }
.lab .lab-main > .player {
  border-top: none; border-top-left-radius: 0; border-top-right-radius: 0; background: var(--bg-raised);
}

/* ---------- chart axis labels stay readable over lines ---------- */
.xy-svg .halo { paint-order: stroke; stroke: var(--bg-raised); stroke-width: 3px; stroke-linejoin: round; }

.lab-card svg { max-width: 100%; }

/* ---------- print: undo the app-shell scroll locking ---------- */
@media print {
  html, body { height: auto !important; overflow: visible !important; padding-bottom: 0 !important; display: block !important; }
  .statusbar, .oscroll, .msel-pop, .msel-backdrop, .side-toggle, .nav-arrow, .print-btn { display: none !important; }
  .algo-head p { -webkit-line-clamp: unset !important; display: block !important; overflow: visible !important; }
  .main { height: auto !important; overflow: visible !important; }
  .katex { position: static; }
  .eq-grid { grid-template-columns: 1fr !important; }
  .eq-card { break-inside: avoid; }
  .eq-card .eq-body { overflow: visible !important; font-size: 0.86em; }
  .eq-card .eq-body .katex-display { margin: 0.4em 0; }
}
