/* runglab.css - Rung Lab shared styles. Phone-first; dark by default with a light mirror.
   Adapts the control-bench look of the reference handoff. */
:root{
  --bg:#15181c; --panel:#1d2126; --panel2:#23282e; --line:#2f353c; --fg:#e6e8eb; --muted:#97a0aa;
  --wire:#7d8692; --sym:#d4d8dd; --power:#f2a81d; --power-soft:rgba(242,168,29,.16);
  /* live POWER FLOW (energized wires, rail, true contacts, energized coils/blocks, ON values)
     is GREEN, Studio 5000 style, matching /llw/showcase. Amber (--power) is accents only. */
  --flow:#2fae57; --flow-soft:rgba(47,174,87,.20);
  --alarm:#ff5b4e; --alarm-soft:rgba(255,91,78,.16); --ok:#45c08a;
  --f-disp:"IBM Plex Sans Condensed","Arial Narrow",system-ui,sans-serif;
  --f-body:"IBM Plex Sans",system-ui,-apple-system,"Segoe UI",sans-serif;
  --f-mono:"IBM Plex Mono",ui-monospace,"SFMono-Regular",Menlo,Consolas,monospace;
  color-scheme:dark;
}
@media (prefers-color-scheme:light){:root:not([data-theme=dark]){
  --bg:#eceef1;--panel:#fff;--panel2:#f5f6f8;--line:#d6dae0;--fg:#14171b;--muted:#5b646e;
  --wire:#8a929c;--sym:#20252b;--power:#c07a00;--power-soft:rgba(192,122,0,.13);--flow:#1d8a45;--flow-soft:rgba(29,138,69,.14);
  --alarm:#d3372c;--alarm-soft:rgba(211,55,44,.12);--ok:#1d8656;color-scheme:light;}}
*{box-sizing:border-box}
body{background:var(--bg);color:var(--fg);font:14px/1.5 var(--f-body);margin:0}
#rl{max-width:1180px;margin:0 auto;padding:14px 14px 120px;display:grid;gap:14px}
h1,h2{font-family:var(--f-disp);margin:0}
.rl-eyebrow{font:600 11px/1 var(--f-disp);letter-spacing:.12em;text-transform:uppercase;color:var(--muted)}
button{font:inherit;color:inherit}
.rl-top{border-bottom:1px solid var(--line);padding-bottom:12px}
.rl-brand{display:flex;gap:9px;align-items:center}
.rl-mark{width:10px;height:10px;background:var(--power);box-shadow:0 0 0 3px var(--power-soft)}
.rl-title{font-size:clamp(20px,3.2vw,28px);font-weight:700;margin-top:6px}
.rl-sub{color:var(--muted);margin:3px 0 0}
.rl-runbar{display:flex;flex-wrap:wrap;gap:7px;align-items:center;margin-top:10px}
.rl-clock{font:600 12px var(--f-mono);color:var(--muted);border:1px solid var(--line);background:var(--panel);padding:5px 9px}
.rl-clock b{color:var(--fg)}
.rl-seg{display:inline-flex;border:1px solid var(--line);background:var(--panel)}
.rl-seg button{border:0;background:none;padding:5px 10px;cursor:pointer;font:600 12px var(--f-disp);letter-spacing:.03em;color:var(--muted)}
.rl-seg button[aria-pressed=true]{background:var(--panel2);color:var(--fg);box-shadow:inset 0 -2px 0 var(--power)}
.rl-seg button:disabled{opacity:.4;cursor:not-allowed}
.rl-btn{border:1px solid var(--line);background:var(--panel);padding:5px 11px;cursor:pointer;font:600 12px var(--f-disp);letter-spacing:.04em;text-transform:uppercase}
.rl-btn:hover{border-color:var(--muted)}
.rl-grid{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(0,1fr);gap:14px;align-items:start}
.rl-panel{background:var(--panel);border:1px solid var(--line);min-width:0}
.rl-panel>header{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:9px 12px;border-bottom:1px solid var(--line)}
.rl-panel>header h2{font-size:14px;font-weight:600;letter-spacing:.03em;text-transform:uppercase}
.rl-side{display:grid;gap:14px;min-width:0}
.rl-ladder-scroll{overflow-x:auto;padding:10px 12px}
#rl-ladder{display:block;width:100%;min-width:560px;height:auto}
#rl-ladder text{font-family:var(--f-mono);text-rendering:geometricPrecision;paint-order:stroke fill;stroke:none}
#rl-ladder .w{stroke:var(--wire);stroke-width:1.4;stroke-linecap:square;transition:stroke .08s}
#rl-ladder .w.on{stroke:var(--flow);stroke-width:3.2}
#rl-ladder .rail{stroke:var(--sym);stroke-width:3}#rl-ladder .rail.l{stroke:var(--flow)}
#rl-ladder .bar{stroke:var(--sym);stroke-width:2}
#rl-ladder .cell-bg{fill:transparent}#rl-ladder .cell.true .cell-bg{fill:var(--flow-soft)}
#rl-ladder .tag{fill:var(--fg);font-size:11px}#rl-ladder .desc{fill:var(--muted);font-size:9px;font-family:var(--f-body)}
#rl-ladder .vb{fill:var(--panel2);stroke:var(--line)}#rl-ladder .vt{fill:var(--muted);font-size:9px;font-weight:600}
#rl-ladder .vb.v1{fill:var(--flow);stroke:var(--flow)}
#rl-ladder .coil{fill:none;stroke:var(--sym);stroke-width:2}#rl-ladder .cell.energized .coil{stroke:var(--flow);fill:var(--flow-soft);stroke-width:2.6}
#rl-ladder .letter{fill:var(--sym);font:700 10px var(--f-disp)}
#rl-ladder .band{fill:var(--panel2)}#rl-ladder .band.hot{fill:var(--alarm-soft)}#rl-ladder .band-acc{fill:var(--muted)}
#rl-ladder .sid{fill:var(--fg);font:600 10.5px var(--f-mono)}#rl-ladder .stitle{fill:var(--fg);font:600 11.5px var(--f-disp)}
#rl-ladder .scom{fill:var(--muted);font:italic 10.5px var(--f-body)}#rl-ladder .rno{fill:var(--muted);font:600 11px var(--f-disp)}
#rl-ladder .blk{fill:var(--panel);stroke:var(--sym);stroke-width:1.5}#rl-ladder .blk-h{fill:var(--panel2)}
#rl-ladder .mn{fill:var(--fg);font:600 11px var(--f-mono)}#rl-ladder .bn{fill:var(--muted);font:500 10px var(--f-disp)}
#rl-ladder .bl{fill:var(--muted);font:10px var(--f-body)}#rl-ladder .bv{fill:var(--fg);font-size:10px}#rl-ladder .bv.acc{font-weight:600}
#rl-ladder .dn{fill:var(--panel2);stroke:var(--line)}#rl-ladder .dn.done{fill:var(--flow);stroke:var(--flow)}
#rl-ladder .dn-t{fill:var(--muted);font:600 9px var(--f-disp)}#rl-ladder .cmpb{fill:var(--panel)}#rl-ladder .cmp.true .cmpb{fill:var(--flow-soft);stroke:var(--flow)}
#rl-ladder .cmpt{fill:var(--fg);font:600 10px var(--f-mono)}
#rl-ladder .resb{fill:#fff;stroke:var(--sym)}#rl-ladder .rest{fill:#111;font:700 7px var(--f-mono)}
#rl-ladder .seal{fill:var(--muted);font:italic 9.5px var(--f-body)}#rl-ladder .dot{fill:var(--sym)}
.rl-bugnote{margin:10px 12px 0;padding:9px 11px;border:1px solid var(--alarm);background:var(--alarm-soft);font-size:13px}
.rl-reveal{margin:0 12px 12px;padding:9px 11px;border:1px solid var(--line);background:var(--panel2);font-size:13px}
.rl-reveal-btn{margin:8px 12px}
/* I/O */
.rl-io{padding:10px 12px;display:grid;gap:9px}
.rl-iorow{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:center;background:var(--panel2);border:1px solid var(--line);padding:8px 10px}
.rl-ioname{font:600 12px var(--f-mono)}
.rl-switch{position:relative;width:58px;height:28px;border:1px solid var(--line);background:var(--panel);cursor:pointer}
.rl-switch::after{content:"";position:absolute;top:3px;left:3px;width:22px;height:20px;background:var(--muted);transition:transform .12s}
.rl-switch[aria-pressed=true]{border-color:var(--power);background:var(--power-soft)}.rl-switch[aria-pressed=true]::after{transform:translateX(28px);background:var(--power)}.rl-push{min-width:60px;width:auto;padding:0 8px;white-space:nowrap;height:30px;border-radius:50%/55%;border:2px solid var(--muted);background:var(--panel);cursor:pointer;font:700 10px var(--f-disp);color:var(--muted);user-select:none;touch-action:none}
.rl-push.down{background:var(--power);border-color:var(--power);color:#15181c}
.rl-num{width:84px;padding:5px 7px;background:var(--panel);border:1px solid var(--line);color:var(--fg);font:600 13px var(--f-mono)}
.rl-lamps{display:flex;flex-wrap:wrap;gap:7px;margin-top:2px}
.rl-lamp{padding:4px 9px;border:1px solid var(--line);background:var(--panel2);color:var(--muted);font:600 11px var(--f-mono)}
.rl-lamp.on{background:var(--flow);border-color:var(--flow);color:#0d1f14}
/* Watch demo: the input widgets mirror the replayed tags (display-only). Signal that the demo
   is driving them - dim slightly, show a not-allowed cursor, and a small "DEMO" badge on the
   I/O panel - so a reader doesn't think the static-looking toggle is wrong or try to fight it. */
.rl-demo-driven .rl-switch,.rl-demo-driven .rl-push,.rl-demo-driven .rl-num{cursor:not-allowed;opacity:.92}
.rl-demo-driven .rl-iorow{position:relative}
.rl-io.rl-demo-driven::before{content:"Demo is driving the inputs";display:block;font:600 11px var(--f-disp);color:var(--power);text-transform:uppercase;letter-spacing:.04em;margin-bottom:8px}
/* tags */
.rl-tags{padding:4px 12px 10px}.rl-tags table{border-collapse:collapse;width:100%;font-size:12px}
.rl-tags td{padding:4px 7px;border-bottom:1px solid var(--line)}.rl-tags .t{font-family:var(--f-mono)}.rl-tags .ty{color:var(--muted)}
.chip{display:inline-block;min-width:20px;text-align:center;padding:0 5px;font:600 11px var(--f-mono);border:1px solid var(--line);color:var(--muted)}
.chip.on{background:var(--flow);border-color:var(--flow);color:#0d1f14}
/* trend */
.rl-trend-scroll{overflow-x:auto;padding:8px 12px}#rl-trend{display:block;width:100%}
#rl-trend text{font:10px var(--f-mono);fill:var(--muted)}#rl-trend .sig{fill:var(--fg)}
#rl-trend .basel{stroke:var(--line)}#rl-trend .grid{stroke:var(--line);stroke-dasharray:2 4}
#rl-trend .tr{fill:var(--power-soft);stroke:var(--power);stroke-width:1.5}#rl-trend .numv{fill:var(--fg)}
/* tests */
.rl-tests{padding:10px 12px}#rl-tlist{list-style:none;margin:0;padding:0;display:grid;gap:6px}
#rl-tlist li{display:grid;grid-template-columns:20px 22px minmax(0,1fr) auto auto;gap:8px;align-items:start;background:var(--panel2);border:1px solid var(--line);padding:7px 9px}
#rl-tlist .box{width:15px;height:15px;border:1.5px solid var(--muted);margin-top:2px;position:relative}
#rl-tlist li.pass .box{background:var(--ok);border-color:var(--ok)}#rl-tlist li.pass .box::after{content:"";position:absolute;left:4px;top:0;width:4px;height:9px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg)}
#rl-tlist .num{font:600 12px var(--f-mono);color:var(--muted)}#rl-tlist .d b{font-weight:600}#rl-tlist .d span{display:block;color:var(--muted);font-size:12px}
#rl-tlist .when{color:var(--ok);font:11px var(--f-mono)}#rl-tlist .pr{font:600 11px var(--f-mono);color:var(--muted)}
.rl-mini{border:1px solid var(--line);background:var(--panel);padding:3px 8px;cursor:pointer;font:600 10px var(--f-disp);text-transform:uppercase;white-space:nowrap}
.rl-foot{color:var(--muted);font-size:12px;border-top:1px solid var(--line);padding-top:10px}
@media (prefers-reduced-motion:reduce){*{transition:none!important}}

/* ---- phone-first (MUST-FIX 4): a COMPACT bar is always visible at the bottom - one
   scrollable row of input widgets + an always-visible lamp strip + a tap-to-expand
   button. The full I/O panel (#rl-side, every input with its label + the Tags table)
   stays off-screen until expanded, so by default the ladder + lamps own most of the
   screen (target: >=55% of viewport height at 390x844 shows the ladder+lamps). ---- */
.rl-phonebar{display:none}
@media (max-width:860px){
  #rl{padding-bottom:84px}
  .rl-grid{grid-template-columns:minmax(0,1fr)}
  /* PHONE LADDER: fit the whole ladder to the screen width by default so the coils AND the
     timer/counter boxes on the right rail are visible on first load (they used to sit off-screen
     behind a 560px min-width + horizontal scroll). Pinch-zoom lets the reader enlarge any rung.
     Mirrors the live-machine kit. Desktop is unchanged (this is inside the phone media query). */
  .rl-ladder-scroll{overflow-x:hidden;touch-action:pinch-zoom}
  #rl-ladder{min-width:0;width:100%}
  .rl-runbar{position:sticky;top:0;background:var(--bg);z-index:10;padding:6px 0}

  /* the full panel: hidden by default, slides up as an overlay when expanded */
  .rl-side{position:fixed;left:0;right:0;bottom:84px;z-index:25;max-height:50vh;overflow-y:auto;
    background:var(--bg);border-top:2px solid var(--power);padding:8px;gap:8px;
    box-shadow:0 -6px 20px rgba(0,0,0,.35);
    transform:translateY(100%);visibility:hidden;transition:transform .15s ease}
  .rl-side.rl-side-open{transform:translateY(0);visibility:visible}

  /* the compact bar: always visible, fixed to the bottom, small and scrollable */
  .rl-phonebar{display:flex;align-items:center;gap:8px;position:fixed;left:0;right:0;bottom:0;z-index:30;
    height:84px;background:var(--panel);border-top:2px solid var(--power);padding:6px 8px;
    box-shadow:0 -4px 14px rgba(0,0,0,.3)}
  .rl-phonebar-inputs{display:flex;gap:8px;overflow-x:auto;flex:1 1 auto;min-width:0;height:100%;align-items:center;padding:2px}
  .rl-phonebar-cell{display:flex;flex-direction:column;align-items:center;gap:3px;flex:0 0 auto}
  .rl-phonebar-label{font:600 9px var(--f-mono);color:var(--muted);max-width:62px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .rl-push-sm{min-width:44px;width:auto;padding:0 5px;height:32px;font-size:8px}
  .rl-switch-sm{width:42px;height:22px}.rl-switch-sm::after{width:16px;height:16px}
  .rl-switch-sm[aria-pressed=true]::after{transform:translateX(20px)}
  .rl-phonebar-lamps{display:flex;gap:5px;flex:0 0 auto;align-items:center;max-width:34vw;overflow-x:auto;position:relative}
  /* SHOULD-FIX 5 (M2b): when the lamp strip overflows, show a right-edge fade + a "more"
     chevron so the reader knows it scrolls (Ch32 has 13 lamps and used to cut off mid-word).
     The .rl-scrollable class is toggled by the UI only when scrollWidth > clientWidth. */
  .rl-phonebar-lampwrap{position:relative;flex:0 0 auto;max-width:36vw;display:flex;align-items:center}
  .rl-phonebar-lampwrap.rl-scrollable::after{content:"›";position:absolute;right:0;top:0;bottom:0;
    display:flex;align-items:center;padding:0 2px 0 10px;font:700 14px var(--f-disp);color:var(--fg);
    pointer-events:none;background:linear-gradient(90deg,transparent,var(--panel) 55%)}
  .rl-lamp-sm{padding:3px 6px;font-size:9px;flex:0 0 auto}
  .rl-phonebar-toggle{flex:0 0 auto;border:1px solid var(--line);background:var(--panel2);color:var(--fg);
    padding:8px 10px;font:600 11px var(--f-disp);text-transform:uppercase;cursor:pointer;height:100%}
}
/* a short phone (<=700px tall) tightens the bar further so the ladder keeps its share */
@media (max-width:860px) and (max-height:700px){
  .rl-phonebar{height:72px}
  #rl{padding-bottom:72px}
  .rl-side{bottom:72px}
}

/* ---- intro panel: "What this program does" + "Try this" (text cut from the book's chapter
   data by runglab_intro.py). <details>: open on desktop, collapsed on phone. ---- */
.rl-intro[hidden]{display:none}
.rl-intro>summary{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:9px 12px;cursor:pointer;list-style:none}
.rl-intro>summary::-webkit-details-marker{display:none}
.rl-intro>summary h2{font-size:14px;font-weight:600;letter-spacing:.03em;text-transform:uppercase}
.rl-intro>summary h2::before{content:"\25B8";display:inline-block;margin-right:8px;color:var(--power);transition:transform .15s}
.rl-intro[open]>summary h2::before{transform:rotate(90deg)}
.rl-intro[open]>summary{border-bottom:1px solid var(--line)}
.rl-intro>summary:focus-visible{outline:2px solid var(--power);outline-offset:-2px}
/* stacked on desktop too: "what" across the full width, then "Try this" across the full width, so
   every step fits in at most TWO lines without cutting a word (the longest TEST IT row is 197
   characters; a side-by-side column would need three or more lines). */
.rl-intro-body{padding:8px 14px 10px;display:grid;grid-template-columns:minmax(0,1fr);gap:6px}
.rl-intro-col{min-width:0}
.rl-intro-col:first-child{display:contents}
.rl-intro-what{margin:0;font-size:14px;line-height:1.5}
.rl-intro-h{font:600 12px/1 var(--f-disp);letter-spacing:.1em;text-transform:uppercase;color:var(--muted);margin:2px 0 6px}
/* each step: action -> result (the arrow is CSS; the words are the book's). A long step wraps to a
   second line; nothing is ever cut. The compact view shows the first 3; "Show all steps" the rest. */
.rl-intro-try{margin:0;padding-left:0;list-style:none;counter-reset:rl-step;display:grid;gap:3px;line-height:1.45;font-size:14px}
.rl-intro-try li{counter-increment:rl-step;padding-left:1.4em;text-indent:-1.4em}
/* step numbers drawn as text, with a hanging indent so a wrapped second line lines up under the text */
.rl-intro-try li::before{content:counter(rl-step) ". ";display:inline-block;width:1.4em;text-indent:0;color:var(--fg);font-variant-numeric:tabular-nums}
.rl-intro-try:not(.all) .rl-intro-extra{display:none}
.rl-intro-do,.rl-intro-exp{display:inline}
.rl-intro-exp{color:var(--muted)}
.rl-intro-exp::before{content:" \2192  ";color:var(--power);font-weight:600}
.rl-intro-more{margin:4px 0 0;padding:2px 0;background:none;border:0;color:var(--power);font:600 12px var(--f-disp);letter-spacing:.06em;text-transform:uppercase;cursor:pointer}
.rl-intro-more:hover{text-decoration:underline}
.rl-intro-more:focus-visible{outline:2px solid var(--power);outline-offset:2px}
.rl-intro-foot{margin:0;color:var(--muted);font-size:13px;border-top:1px solid var(--line);padding-top:6px;order:3}
@media (prefers-reduced-motion:reduce){.rl-intro>summary h2::before{transition:none}}
@media (max-width:860px){
  .rl-intro-hint{display:none}
  .rl-intro-body{padding:10px 12px 12px}
  .rl-intro-foot{margin-top:4px}
}

/* small book back-link under each simulator (site rebuild 2026-10-30) */
.rl-booklink{max-width:1200px;margin:18px auto 24px;padding:0 16px;font:13px/1.4 var(--f-body);color:var(--muted);text-align:center}
.rl-booklink a{color:#A86B00}
@media (max-width:860px){.rl-booklink{margin-bottom:96px}}
