  /* ── 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;
    /* BNF derivation specific */
    --nt:              #5aa9ff;
    --nt-fill:         #10233d;
    --term:            #f5c542;
    --term-fill:       #2e2610;
    --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;
    --nt:              #1d5fb8;
    --nt-fill:         #d6e6fb;
    --term:            #8a6400;
    --term-fill:       #f6ebc8;
    --top-fill:        #c9f0db;
    --accent:          #0a8a4e;
    --output-fill:     #d4f0cc;
    --discard-fill:    #f8dcdc;
    --discard:         #c0392b;
  }

  * { 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;
  }

  /* ── 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; }
  }

  /* ── BNF DERIVATION ──────────────────────────────────── */
  .picker {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
    background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 18px; margin-bottom: 16px;
  }
  .picker label { font-size: 0.85rem; color: var(--text-muted); }
  .picker input[type="text"] {
    font-family: var(--mono); font-size: 1rem; width: 120px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
  }
  .picker input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
  .presets { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; align-items: center; }
  .presets span { font-size: 0.78rem; color: var(--text-muted); margin-right: 2px; }
  .presets button { font-family: var(--mono); padding: 5px 11px; font-size: 0.8rem; }
  .picker-err { width: 100%; font-size: 0.8rem; color: var(--discard); min-height: 0; }
  .picker-err:empty { display: none; }

  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
  @media (max-width: 960px) { .grid2 { grid-template-columns: 1fr; } }

  .panel {
    background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; min-width: 0;
  }
  .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;
  }
  .panel + .panel { margin-top: 0; }
  .stacked { display: flex; flex-direction: column; gap: 16px; }

  /* rules */
  .rule {
    font-family: var(--mono); font-size: 0.92rem; line-height: 2.1; white-space: nowrap; overflow-x: auto;
    padding: 6px 10px; border-radius: 10px; border: 1px solid transparent;
    transition: background 0.25s, border-color 0.25s;
  }
  .rule + .rule { margin-top: 6px; }
  .rule.active { background: var(--bg3); border-color: var(--border); }
  .r-nt { color: var(--nt); }
  .r-def { color: var(--green); margin: 0 6px; }
  .r-or { color: var(--text-muted); margin: 0 2px; }
  #rule-integer { padding-bottom: 16px; }
  .r-t { color: var(--term); }
  .opt {
    position: relative; display: inline-block; padding: 0 3px; border-radius: 6px; border: 1.5px solid transparent;
    transition: background 0.25s, border-color 0.25s;
  }
  .opt.chosen { background: var(--top-fill); border-color: var(--accent); }
  .opt-tag {
    position: absolute; top: 100%; left: 50%; transform: translate(-50%, -4px);
    font-family: var(--sans); font-size: 0.66rem; line-height: 1; color: var(--text-muted); white-space: nowrap;
  }

  /* order of events */
  .events { list-style: none; display: flex; flex-direction: column; gap: 8px; }
  .events li {
    display: flex; gap: 10px; align-items: flex-start; font-size: 0.88rem; color: var(--text-muted);
    padding: 7px 10px; border-radius: 10px; border: 1px solid transparent;
    transition: background 0.25s, border-color 0.25s, color 0.25s;
  }
  .events .num {
    flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--mono); font-size: 0.75rem; font-weight: 700;
    background: var(--bg3); color: var(--text-muted);
  }
  .events li.on { color: var(--text); background: var(--top-fill); border-color: var(--accent); }
  .events li.on .num { background: var(--accent); color: var(--bg); }

  /* target + working string */
  .target, .work { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; align-content: flex-start; padding-top: 4px; }
  .tchar {
    font-family: var(--mono); font-size: 1.15rem; font-weight: 700;
    min-width: 40px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; background: var(--idle-fill); border: 1.5px solid var(--idle-stroke); color: var(--text-muted);
    transition: all 0.25s;
  }
  .tchar.done { background: var(--output-fill); border-color: var(--output-stroke); color: var(--green); }
  .tchar.next { border-color: var(--term); color: var(--term); transform: translateY(-3px); }
  .tchar.bad { background: var(--discard-fill); border-color: var(--discard); color: var(--discard); }
  .target-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 10px; }

  .sym {
    font-family: var(--mono); font-size: 1.05rem; font-weight: 700;
    height: 46px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; border: 1.5px solid transparent; transition: all 0.3s;
  }
  .sym.nt { background: var(--nt-fill); color: var(--nt); border-color: var(--nt); }
  .sym.t { background: var(--term-fill); color: var(--term); border-color: var(--term-fill); min-width: 40px; }
  .sym.focus { box-shadow: 0 0 0 3px var(--accent); transform: translateY(-4px); }
  .sym.new { animation: pop 0.45s ease-out; box-shadow: 0 0 0 3px var(--green); }
  .sym.fail { box-shadow: 0 0 0 3px var(--discard); }
  @keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  @media (prefers-reduced-motion: reduce) { .sym.new { animation: none; } .sym, .tchar { transition: none; } }

  .key { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 0.75rem; color: var(--text-muted); }
  .key i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; font-style: normal; }
  .key .k-nt { background: var(--nt); } .key .k-t { background: var(--term); }

  /* history */
  /* Fixed height (7 lines, exactly a 3-digit derivation); longer derivations scroll inside the box. */
  .history {
    font-family: var(--mono); font-size: 0.92rem; display: flex; flex-direction: column; gap: 4px;
    height: 260px; overflow-y: auto; scroll-behavior: smooth;
  }
  .hrow { flex-shrink: 0; }
  .hrow { display: flex; gap: 12px; align-items: baseline; padding: 4px 10px; border-radius: 8px; color: var(--text-muted); }
  .hrow .arrow { width: 18px; color: var(--text-muted); flex-shrink: 0; }
  .hrow.latest { background: var(--bg3); color: var(--text); }
  .hrow .h-nt { color: var(--nt); } .hrow .h-t { color: var(--term); }

  .msg .m-nt { font-family: var(--mono); color: var(--nt); }
  .msg .m-t { font-family: var(--mono); color: var(--term); font-weight: 700; }
  .msg.ok { border-left-color: var(--green); }
  .msg.fail { border-left-color: var(--discard); }
  .verdict { font-weight: 700; }
  .verdict.ok { color: var(--green); } .verdict.fail { color: var(--discard); }
  .msg { display: block; }
  .grid2 > * { min-width: 0; }
  @media (max-width: 520px) {
    .rule { font-size: 0.78rem; padding: 6px 4px; }
    .r-def { margin: 0 3px; } .r-or { margin: 0 1px; } .opt { padding: 0 1px; }
    .panel { padding: 14px 12px; }
  }
  @media (max-width: 380px) { .rule { font-size: 0.72rem; } }

  /* ── CHECKER (your own rules) ─────────────────────────── */
  .checker {
    display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px;
    background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; margin-bottom: 16px;
  }
  @media (max-width: 860px) { .checker { grid-template-columns: 1fr; } }
  .checker .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .checker .field label { font-family: var(--mono); font-size: 0.7rem; font-weight: 600; color: var(--green); text-transform: uppercase; letter-spacing: 0.1em; }
  .checker .side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .checker textarea {
    width: 100%; min-height: 190px; resize: vertical;
    font-family: var(--mono); font-size: 0.86rem; line-height: 1.7;
    color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 12px; white-space: pre; overflow-x: auto;
  }
  .checker select, .checker input[type="text"] {
    width: 100%; font-size: 0.92rem; color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  }
  .checker select { font-family: var(--sans); }
  .checker input[type="text"] { font-family: var(--mono); font-size: 1rem; }
  .checker textarea:focus, .checker select:focus, .checker input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
  .checker .check { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--text-muted); cursor: pointer; }
  .checker .check input { accent-color: var(--green); }
  .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
  .btn-row button { flex: 1; }
  button.small { align-self: flex-start; padding: 5px 11px; font-size: 0.78rem; }
  .issues { display: flex; flex-direction: column; gap: 6px; }
  .issues:empty { display: none; }
  .issue { font-size: 0.8rem; line-height: 1.5; padding: 7px 10px; border-radius: 8px; }
  .issue.err { background: var(--discard-fill); color: var(--discard); }
  .issue.warn { background: var(--bg3); color: var(--text-muted); }
  .issue code, .verdict-box code { font-family: var(--mono); }
  .verdict-box { font-size: 0.9rem; line-height: 1.5; padding: 10px 12px; border-radius: 10px; }
  .verdict-box:empty { display: none; }
  .verdict-box.pass { background: var(--output-fill); color: var(--green); border: 1px solid var(--output-stroke); }
  .verdict-box.fail { background: var(--discard-fill); color: var(--discard); border: 1px solid var(--discard); }
  #rules .rule + .rule { margin-top: 6px; }
