  /* ── SITE TOKENS ───────────────────────────────────── */
  :root {
    --green:           #4fc431;
    --green-dark:      #3aad1f;
    --bg:              #0f1620;
    --bg2:             #18202e;
    --bg3:             #222c3c;
    --text:            #e8edf4;
    --text-muted:      #8fa0b8;
    --border:          #2a3547;
    --radius:          16px;
    --mono:            'JetBrains Mono', monospace;
    --sans:            'DM Sans', sans-serif;
    /* DFS-specific */
    --accent:          #00ff88;
    --unvisited-fill:  #1a2436;
    --unvisited-stroke:#2a3547;
    --visited-fill:    #12300e;
    --visited-stroke:  #4fc431;
    --current-fill:    #003b22;
    --current-stroke:  #00ff88;
  }

  [data-theme="light"] {
    --bg:              #dde4ef;
    --bg2:             #eaf0f8;
    --bg3:             #d0d9e8;
    --text:            #0f1a2e;
    --text-muted:      #3d5070;
    --border:          #b0bdd0;
    --unvisited-fill:  #c8d4e8;
    --unvisited-stroke:#8fa0b8;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }
  html { scroll-behavior: smooth; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  /* ── NAV ───────────────────────────────────────────── */
  nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15,22,32,0.92);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    display: flex;
    align-items: center;
    height: 64px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    gap: 16px;
    flex-shrink: 0;
  }
  [data-theme="light"] nav { background: rgba(234,240,248,0.95); }

  .nav-back {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
  }
  .nav-back:hover { color: var(--green); border-color: var(--green); }

  .nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
  }
  .nav-logo img { height: 32px; width: auto; }
  .nav-brand {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--green);
    font-weight: 700;
  }
  .nav-title {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .theme-btn {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    transition: 0.2s;
    line-height: 1;
    flex-shrink: 0;
  }
  .theme-btn:hover { color: var(--text); }

  /* ── PAGE CONTENT ──────────────────────────────────── */
  .page-wrap {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 40px 24px 56px;
    flex: 1;
  }

  .page-label {
    font-family: var(--mono);
    font-size: 0.73rem;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 10px;
  }

  h1 {
    font-family: var(--mono);
    font-size: clamp(1.3rem, 3vw, 1.8rem);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    margin-bottom: 10px;
    line-height: 1.2;
  }

  h1 .accent { color: var(--accent); }

  .subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 28px;
    max-width: 680px;
    line-height: 1.7;
  }

  /* ── STAGE ──────────────────────────────────────────── */
  .stage {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
  }

  svg { width: 100%; height: auto; display: block; }

  /* ── NODES & EDGES ──────────────────────────────────── */
  .node circle { stroke-width: 1.5; transition: fill 0.3s, stroke 0.3s; }
  .node text {
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 700;
    fill: var(--text-muted);
    transition: fill 0.3s;
  }
  .node.unvisited circle { fill: var(--unvisited-fill); stroke: var(--unvisited-stroke); }
  .node.visited   circle { fill: var(--visited-fill);   stroke: var(--visited-stroke); }
  .node.visited   text   { fill: var(--green); }
  .node.current   circle { fill: var(--current-fill);   stroke: var(--current-stroke); stroke-width: 2.5; }
  .node.current   text   { fill: var(--accent); }

  .edge { stroke: var(--border); stroke-width: 1.5; transition: stroke 0.3s, stroke-width 0.3s; }
  .edge.traversed { stroke: var(--green); stroke-width: 2.5; }

  .svg-label {
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    fill: var(--text-muted);
  }

  /* ── STACK CELLS ─────────────────────────────────────── */
  .stack-cell rect { fill: var(--unvisited-fill); stroke: var(--unvisited-stroke); stroke-width: 1; }
  .stack-cell.top rect { fill: var(--current-fill); stroke: var(--accent); }
  .stack-cell text {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 500;
    fill: var(--text);
  }
  .stack-cell.top text { fill: var(--accent); }
  .stack-cell .top-tag { font-size: 10px; font-weight: 400; fill: var(--text-muted); }
  .stack-cell.top .top-tag { fill: var(--accent); opacity: 0.7; }
  .legend-dot { stroke-width: 1.5; }

  /* ── DATA PANELS ─────────────────────────────────────── */
  .data-panels {
    display: grid;
    grid-template-columns: 1fr 1.35fr;
    gap: 16px;
    margin-bottom: 16px;
  }
  @media (max-width: 700px) { .data-panels { grid-template-columns: 1fr; } }

  .data-panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    overflow-x: auto;
  }
  .data-panel h2 {
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 12px;
  }

  .adj-list {
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.9;
    color: var(--text-muted);
  }
  .adj-row {
    padding: 0 8px;
    border-radius: 6px;
    border-left: 3px solid transparent;
    transition: background 0.2s;
    white-space: nowrap;
  }
  .adj-row.active { background: var(--current-fill); border-left-color: var(--accent); }
  .adj-key { color: var(--text); }
  .adj-row.active .adj-key { color: var(--accent); }
  .nb { transition: color 0.2s; }
  .nb.v   { color: var(--green); }
  .nb.cur { color: var(--accent); font-weight: 700; }

  .matrix { border-collapse: collapse; font-family: var(--mono); font-size: 0.75rem; }
  .matrix th, .matrix td { width: 24px; height: 24px; text-align: center; padding: 0; }
  .matrix th { color: var(--text-muted); font-weight: 500; }
  .matrix td { color: var(--bg3); border: 1px solid var(--border); }
  .matrix td.one { color: var(--text); }
  .matrix td.one.v   { color: var(--green); }
  .matrix td.one.cur { color: var(--accent); font-weight: 700; }
  .matrix tr.active td { background: rgba(0,255,136,0.07); }
  .matrix tr.active th { color: var(--accent); }

  .panel-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 12px;
    line-height: 1.6;
  }

  /* ── MESSAGE + ORDER ─────────────────────────────────── */
  .msg {
    min-height: 52px;
    font-size: 0.95rem;
    line-height: 1.6;
    padding: 14px 18px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 12px;
  }

  .order-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 0 4px;
  }
  .order-row code { font-family: var(--mono); color: var(--green); font-size: 0.9rem; }
  .order-row.pops { margin-bottom: 20px; }
  .order-row.pops code { color: var(--accent); }

  /* ── CONTROLS ────────────────────────────────────────── */
  .controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }

  button {
    font-family: var(--sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 18px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
  }
  button:hover { border-color: var(--accent); color: var(--accent); }
  button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  button.play-active { background: var(--current-fill); border-color: var(--accent); color: var(--accent); }

  .step-lbl {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-muted);
  }

  .speed-ctl {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
  }
  .speed-ctl input[type="range"] {
    -webkit-appearance: none; appearance: none;
    width: 110px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none; cursor: pointer;
  }
  .speed-ctl input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--accent); border: none;
  }
  .speed-ctl input[type="range"]::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--accent); border: none;
  }
  .speed-val { font-family: var(--mono); color: var(--text); min-width: 78px; }

  .hint { margin-top: 16px; font-size: 0.78rem; color: var(--text-muted); text-align: center; }
  kbd {
    font-family: var(--mono);
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.75rem;
  }

  /* ── FOOTER ──────────────────────────────────────────── */
  footer {
    background: var(--bg2);
    border-top: 1px solid var(--border);
    padding: 28px 32px;
    text-align: center;
    flex-shrink: 0;
  }
  footer p { font-family: var(--mono); font-size: 0.78rem; color: var(--text-muted); }
  footer span { color: var(--green); }

  @media (max-width: 520px) {
    .step-lbl { margin-left: 0; width: 100%; text-align: center; }
    nav { padding: 0 16px; }
    .nav-title { display: none; }
  }
