  /* ── SITE TOKENS (matched to onlinecstutor.com) ─────── */
  :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;
    /* Shunting-Yard specific */
    --accent:          #00ff88;
    --idle-fill:       #1a2436;
    --idle-stroke:     #2a3547;
    --output-fill:     #12300e;
    --output-stroke:   #4fc431;
    --top-fill:        #003b22;
    --top-stroke:      #00ff88;
    --discard:         #ff6b6b;
    --discard-fill:    #331414;
  }

  [data-theme="light"] {
    --bg:              #dde4ef;
    --bg2:             #eaf0f8;
    --bg3:             #d0d9e8;
    --text:            #0f1a2e;
    --text-muted:      #3d5070;
    --border:          #b0bdd0;
    --idle-fill:       #c8d4e8;
    --idle-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: env(safe-area-inset-top, 0px);
    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: 960px;
    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 (token stream) ────────────────────────────── */
  .stage {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    margin-bottom: 16px;
  }
  .stage h2 {
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 16px;
    padding: 0 8px;
  }
  .tokens {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px;
  }
  .token {
    font-family: var(--mono);
    font-size: 1.3rem;
    font-weight: 700;
    min-width: 44px;
    text-align: center;
    padding: 10px 6px;
    border-radius: 10px;
    background: var(--idle-fill);
    border: 1.5px solid var(--idle-stroke);
    color: var(--text-muted);
    transition: color 0.3s, background 0.3s, border-color 0.3s, transform 0.3s;
  }
  .token.done { background: transparent; border-color: transparent; color: var(--text-muted); opacity: 0.5; }
  .token.current {
    background: var(--top-fill);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-3px);
  }

  /* ── DATA PANELS (stack + queue) ─────────────────────── */
  .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;
  }

  /* Stack can hold at most 4 operators for this expression, so its height is
     fixed to exactly 4 rows - it never needs to grow, shrink or scroll. */
  .stack-body {
    height: 196px; /* 4 cells (40px) + 3 gaps (8px) + 10px padding-top + 2px border-top */
    display: flex;
    flex-direction: column-reverse;
    align-items: stretch;
    justify-content: center;
    gap: 8px;
    border-top: 2px dashed var(--border);
    padding-top: 10px;
  }
  /* Queue is laid out as a single row (no wrapping), so its height is always
     exactly one cell tall; it scrolls sideways instead of growing vertically. */
  .queue-body {
    height: 40px;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .empty-note { font-size: 0.82rem; color: var(--text-muted); }

  .cell {
    font-family: var(--mono);
    font-size: 1.05rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    min-width: 44px;
    padding: 0 8px;
    border-radius: 8px;
    background: var(--idle-fill);
    border: 1px solid var(--idle-stroke);
    color: var(--text);
    flex-shrink: 0;
    box-sizing: border-box;
  }
  .stack-body .cell:last-child { background: var(--top-fill); border-color: var(--accent); color: var(--accent); }
  .cell.paren { color: var(--text-muted); }
  .queue-body .cell { background: var(--output-fill); border-color: var(--output-stroke); color: var(--green); }

  .panel-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 12px;
    line-height: 1.6;
  }
  .panel-note code {
    font-family: var(--mono);
    color: var(--accent);
    background: var(--bg3);
    padding: 1px 6px;
    border-radius: 5px;
  }

  /* ── MESSAGE ─────────────────────────────────────────── */
  .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;
    display: flex;
    align-items: center;
  }
  .msg b { color: var(--text); }

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

  /* ── 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(--top-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;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    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; }
  }
