/* Run the CPU (computer-science/run-the-cpu.php). The page chrome is the one-screen layout in
   /css/resource.css; the setup, leaderboards, HUD and game-over overlay are the CS games' shared parts
   (cs-game.css). Before a game: the settings on the left, the high scores on the right. In a game: the
   HUD, then the diagram filling the height that's left, with the register transfer log beside it.
   Every colour comes from the theme tokens. */

.kbd{font-size:12px;background:var(--panel);padding:1px 6px;white-space:nowrap}

/* ---------- before a game ---------- */
.mode-sum{margin:0;font:500 13px/1.4 var(--font-mono);color:var(--muted)}
.howto{font-size:15px;color:var(--ink-soft);margin:4px 0 0;padding-left:20px}
.howto li{margin-bottom:8px}
.teach-note p{font-family:var(--font-body);font-size:13.5px;color:var(--ink-soft);margin:0 0 8px}
.teach-note p:last-child{margin-bottom:0}

/* ---------- the Explanation and the Instruction set (scrolling dialogs) ---------- */
.cpu-h{margin:18px 0 8px;font:700 15px/1.2 var(--font-display);color:var(--accent-deep)}
.objective code,.rtn-log code,.isa-table code{font-family:var(--font-mono);font-size:12.5px;background:var(--panel);border:1px solid var(--line);border-radius:3px;padding:0 5px;color:var(--ink);white-space:nowrap}
.reg-list{display:grid;grid-template-columns:max-content 1fr;gap:5px 12px;margin:0 0 10px;font-size:14px}
.reg-list dt{font-family:var(--font-mono);font-weight:700;color:var(--accent-deep)}
.reg-list dd{margin:0;color:var(--ink-soft)}
.rtn-steps{margin:0 0 10px;padding-left:22px;font-size:14px}
.rtn-steps li{margin-bottom:6px}
.rtn-steps li span{display:block;color:var(--ink-soft);font-size:13px}
.isa-table{font-size:13px}
.isa-table th,.isa-table td{padding:5px 8px}
.isa-table td.bin{font-family:var(--font-mono);white-space:nowrap}
.isa-table td.mn{font-family:var(--font-mono);font-weight:700;white-space:nowrap;color:var(--accent-deep)}
.isa-table.compact{font-size:12.5px}
.isa-table.compact th,.isa-table.compact td{padding:4px 7px}

/* ---------- the game ---------- */
.stage{padding:10px 12px 12px}
.stage:fullscreen{overflow:auto}
.teach-controls{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.teach-controls[hidden],[data-play-only][hidden]{display:none}
.hud-btn{padding:5px 12px}
.hud-select{font-family:var(--font-body);font-size:13px;color:var(--ink);background:var(--paper);border:1px solid var(--line);border-radius:4px;padding:4px 6px;max-width:220px}
.msg{flex:none;margin:8px 0;min-height:44px;font-family:var(--font-mono);font-size:13px;color:var(--ink);padding:5px 10px;border-left:3px solid var(--line-strong);background:var(--paper);border-radius:0 4px 4px 0}
.msg.ok{border-left-color:var(--ok)}
.msg.bad{border-left-color:var(--bad);color:var(--bad)}
.msg.teach{border-left-color:var(--accent);font-family:var(--font-body);font-size:14.5px;min-height:4.4em}
.msg.teach b{font-family:var(--font-mono);color:var(--accent-deep)}
.msg .hint{display:block;color:var(--accent-deep);margin-top:2px}
.msg.teach .hint{color:var(--ink-soft);font-size:14px}

/* the diagram fills what's left, with the log beside it */
.play{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) 250px;gap:10px}
.board{min-height:0;border-radius:8px;overflow:hidden;border:1px solid var(--line);background:var(--paper);display:flex;align-items:center;justify-content:center}
.board svg{display:block;width:100%;height:100%;touch-action:none;user-select:none;-webkit-user-select:none}
.side-panel{background:var(--paper);border:1px solid var(--line);border-radius:6px;padding:10px 12px;min-width:0;min-height:0;display:flex;flex-direction:column}
.side-panel h3{margin:0 0 6px;font-family:var(--font-display);font-size:14px;color:var(--ink);flex:none}
.rtn-log{flex:1;min-height:0;margin:0;padding-left:4px;list-style:none;counter-reset:step;overflow-y:auto;font-size:13px;color:var(--ink-soft)}
.rtn-log li{margin-bottom:3px}
.rtn-log li:not(.cycle){counter-increment:step}
.rtn-log li:not(.cycle)::before{content:counter(step) ". ";color:var(--muted);font-family:var(--font-mono);font-size:11px}
.rtn-log li.bad{color:var(--bad)}
.rtn-log li.cycle{counter-reset:step;font-family:var(--font-mono);font-size:11px;letter-spacing:.08em;text-transform:uppercase;color:var(--muted);border-top:1px solid var(--line);padding-top:4px;margin-top:6px}

/* the diagram (run-the-cpu.js draws it): every colour and font a theme token */
#cpuSvg .bg{fill:var(--paper)}
#cpuSvg .cpu{fill:var(--panel);stroke:var(--ink);stroke-width:2.5}
#cpuSvg .cu{fill:var(--accent-tint);stroke:var(--accent-deep);stroke-width:2}
#cpuSvg .box{fill:var(--panel);stroke:var(--ink);stroke-width:1.6}
#cpuSvg .alu{fill:var(--accent-b-tint);stroke:var(--accent-b-deep);stroke-width:2.2;stroke-linejoin:round}
#cpuSvg .acc{fill:var(--panel);stroke:var(--accent-b-deep);stroke-width:2}
#cpuSvg .mem{fill:var(--panel-2);stroke:var(--ink);stroke-width:2.5}
#cpuSvg .row0{fill:var(--panel);stroke:var(--line);stroke-width:1}
#cpuSvg .row1{fill:var(--paper);stroke:var(--line);stroke-width:1}
#cpuSvg .memhead{fill:var(--accent-deep)}
#cpuSvg .memheadtxt{fill:var(--on-accent);font-family:var(--font-display);font-weight:700;font-size:13px}
#cpuSvg .lcdbg{fill:var(--ink)}
#cpuSvg .lcd{font-family:var(--font-mono);font-weight:700;fill:var(--panel)}
#cpuSvg .t{font-family:var(--font-display);font-weight:700;fill:var(--ink)}
#cpuSvg .s{font-family:var(--font-body);font-size:10.5px;fill:var(--ink-soft)}
#cpuSvg .ab{font-family:var(--font-display);font-size:15px;font-weight:700;fill:var(--ink)}
#cpuSvg .mono{font-family:var(--font-mono);fill:var(--ink)}
#cpuSvg .note{font-family:var(--font-body);font-size:11px;font-style:italic;fill:var(--muted)}
#cpuSvg .pcmark{font-family:var(--font-mono);font-size:10px;font-weight:700;fill:var(--accent)}
#cpuSvg .wire{fill:none;stroke:var(--muted);stroke-width:2.5}
#cpuSvg .wire-thin{fill:none;stroke:var(--ink-soft);stroke-width:1.6}
#cpuSvg .dash{fill:none;stroke:var(--ink-soft);stroke-width:1.6;stroke-dasharray:5 3}
#cpuSvg .sysbus{fill:var(--paper);stroke:var(--line-strong);stroke-width:1.5}
#cpuSvg .sysbus-t{font-family:var(--font-display);font-size:12px;font-weight:700;fill:var(--ink)}
#cpuSvg .bus-addr{fill:none;stroke:var(--accent);color:var(--accent);stroke-width:4}
#cpuSvg .lbl-addr{fill:var(--accent-deep)}
#cpuSvg .bus-data{fill:none;stroke:var(--accent-b);color:var(--accent-b);stroke-width:4}
#cpuSvg .lbl-data{fill:var(--accent-b-deep)}
#cpuSvg .bus-ctrl{fill:none;stroke:var(--ink-soft);color:var(--ink-soft);stroke-width:4}
#cpuSvg .lbl-ctrl{fill:var(--ink-soft)}
#cpuSvg .bl{font-family:var(--font-body);font-size:11px;font-weight:700}
#cpuSvg .btn-inc rect{fill:var(--accent)}
#cpuSvg .btn-dec rect{fill:var(--accent-deep)}
#cpuSvg .btn-run rect{fill:var(--accent-b-deep)}
#cpuSvg .btn-svg rect{stroke:var(--ink);stroke-width:1.2}
#cpuSvg .btxt{font-family:var(--font-display);font-size:12px;font-weight:700;fill:var(--on-accent);pointer-events:none}
#cpuSvg .opchip{fill:var(--ink-soft)}
#cpuSvg .opdchip{fill:var(--accent);stroke:var(--ink);stroke-width:1}
#cpuSvg .opdtxt{fill:var(--on-accent)}
#cpuSvg .flagbg{fill:var(--ink)}
#cpuSvg .flaglbl{font-family:var(--font-body);font-size:8.5px;fill:var(--muted)}
#cpuSvg .clockpanel{fill:var(--panel-2);stroke:var(--ink);stroke-width:1.8}
#cpuSvg .clockface{fill:var(--paper);stroke:var(--ink);stroke-width:2.5}
#cpuSvg .clockwave{fill:none;stroke:var(--accent-b);stroke-width:3.5;stroke-linecap:round}
#cpuSvg .tickwave{fill:none;stroke:var(--accent);stroke-width:2.5}
#cpuSvg .animchip{fill:var(--accent);stroke:var(--ink);stroke-width:1.5}
#cpuSvg .animtxt{font-family:var(--font-mono);font-size:13px;font-weight:700;fill:var(--on-accent)}
#cpuSvg .mem-divider{stroke:var(--line)}
#cpuSvg .mem-frame{fill:none;stroke:var(--ink);stroke-width:1.5}
#cpuSvg #anim{pointer-events:none}

/* interactive parts of the diagram */
#cpuSvg [data-src]{cursor:grab}
#cpuSvg .btn-svg{cursor:pointer}
#cpuSvg .btn-svg:hover rect{filter:brightness(1.15)}
#cpuSvg .btn-svg.hidden{display:none}
#cpuSvg .selected > .frame{stroke:var(--accent);stroke-width:3.5}
#cpuSvg .drop-hover > .frame{stroke:var(--ok);stroke-width:3.5}
#cpuSvg .flash-ok > .frame{stroke:var(--ok);stroke-width:4}
#cpuSvg .flash-bad > .frame{stroke:var(--bad);stroke-width:4}
#cpuSvg .alu-zone > .frame{fill:transparent;stroke:transparent}
#cpuSvg .alu-zone.drop-hover > .frame,#cpuSvg .alu-zone.flash-ok > .frame{fill:var(--ok-tint);stroke:var(--ok)}
#cpuSvg .alu-zone.flash-bad > .frame{fill:var(--bad-tint);stroke:var(--bad)}
#cpuSvg .mem-row.at-mar > .frame{fill:var(--accent-tint);stroke:var(--accent);stroke-width:2.5}
#cpuSvg .opd-chip{cursor:grab}
#cpuSvg .op-chip{cursor:help}
#cpuSvg .phase-on{fill:var(--accent);font-weight:700}
#cpuSvg .bus-on{stroke-width:7;filter:drop-shadow(0 0 4px currentColor)}
#cpuSvg .teach-src > .frame,#cpuSvg .teach-src.frame{stroke:var(--accent);stroke-width:3.5;stroke-dasharray:7 4}
#cpuSvg .teach-dst > .frame,#cpuSvg .teach-dst.frame{stroke:var(--ok);stroke-width:3.5}
@keyframes tick-pulse{from{opacity:1}to{opacity:.3}}
#cpuSvg .tick-pulse{animation:tick-pulse .25s ease-out}

.stage-toast{position:absolute;left:50%;top:42%;transform:translate(-50%,-50%);z-index:8;display:none;background:var(--panel);border:2px solid var(--accent);border-radius:8px;padding:18px 26px;text-align:center;color:var(--ink);font-family:var(--font-display);box-shadow:var(--shadow)}
.stage-toast.visible{display:block}
.stage-toast b{display:block;font-size:22px;color:var(--accent-b-deep);margin-bottom:4px}
.stage-toast span{display:block;font-family:var(--font-mono);font-size:13px;color:var(--ink-soft)}

.stage-overlay{gap:14px}

/* drag ghost and tooltip sit inside whatever is fullscreen (see the fullscreenchange handler) */
.ghost{position:fixed;z-index:1000;pointer-events:none;display:none;transform:translate(-50%,-140%);font-family:var(--font-mono);font-size:13px;font-weight:700;color:var(--on-accent);background:var(--accent);border-radius:5px;padding:4px 9px;box-shadow:var(--shadow);white-space:nowrap}
.tip{position:fixed;z-index:1001;pointer-events:none;display:none;max-width:340px;background:var(--ink);color:var(--panel);border-radius:6px;padding:9px 12px;font-size:13px;line-height:1.45;box-shadow:var(--shadow)}
.tip b{color:var(--paper)}
.tip code{font-family:var(--font-mono);font-size:12px;color:var(--accent-tint)}
.tip ol{margin:4px 0 0;padding-left:18px}

/* ---------- smaller screens: stack, and let the page scroll ---------- */
@media (max-width:900px),(max-height:560px){
  .play{grid-template-columns:1fr}
  .board svg{height:auto}
  .rtn-log{max-height:190px}
}
@media (prefers-reduced-motion:reduce){
  .btn{transition-duration:.001ms !important}
  #cpuSvg .tick-pulse{animation:none}
}
@media (max-width:560px){.setup{padding:24px 26px}}   /* the shared setup is narrower on a phone; this game kept its padding (until its review) */
