:root {
  --bg: #0b0f16; --bg2: #0d1220; --panel: #161b22; --panel2: #0e1420;
  --border: #2a3340; --fg: #e6edf3; --muted: #8b949e; --faint: #5b6675;
  --accent: #58a6ff; --alu: #4c8dff; --mem: #f0883e; --branch: #a371f7;
  --idle: #1b222c; --diverge: #f85149; --ok: #3fb950;
  --radius: 10px; --shadow: 0 6px 24px rgba(0,0,0,0.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--fg);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(88,166,255,0.10), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(163,113,247,0.08), transparent 55%),
    var(--bg);
  font: 14px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

header {
  padding: 26px 28px 16px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(88,166,255,0.05), transparent);
}
h1 { margin: 0; font-size: 24px; letter-spacing: -0.01em; font-weight: 700; }
h1 .sub { color: var(--muted); font-weight: 400; font-size: 16px; }
.tagline { color: var(--muted); max-width: 940px; margin: 10px 0 0; }
.tagline a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted rgba(88,166,255,0.5); }
.tagline a:hover { border-bottom-style: solid; }

main {
  display: flex; gap: 20px; padding: 20px 28px; align-items: flex-start;
  flex-wrap: wrap; max-width: 1500px; margin: 0 auto;
}
.left { flex: 1 1 380px; min-width: 340px; }
.right { flex: 1 1 560px; min-width: 380px; }

.examples { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-bottom: 10px; }
.examples .label { color: var(--muted); margin-right: 4px; font-size: 12px; }
.examples button {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; cursor: pointer; font-size: 12px;
  transition: all .15s ease;
}
.examples button:hover { border-color: var(--accent); color: #fff; }
.examples button.active {
  background: rgba(88,166,255,0.15); border-color: var(--accent); color: #fff;
  box-shadow: 0 0 0 1px rgba(88,166,255,0.3) inset;
}

#editor {
  width: 100%; height: 300px; background: var(--panel2); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  font: 13px/1.6 "SF Mono", "JetBrains Mono", Consolas, ui-monospace, monospace;
  resize: vertical; box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
  transition: border-color .15s ease, box-shadow .15s ease;
}
#editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,0.15); }

.controls-row { display: flex; gap: 12px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.controls-row label { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.controls-row input[type=number] {
  width: 66px; background: var(--panel2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 7px;
}
.controls-row input[type=number]:focus { outline: none; border-color: var(--accent); }
button.run {
  background: linear-gradient(180deg, #46c463, var(--ok)); color: #05210f; border: none;
  border-radius: 8px; padding: 8px 20px; font-weight: 700; cursor: pointer; font-size: 14px;
  margin-left: auto; box-shadow: 0 2px 10px rgba(63,185,80,0.35); transition: filter .15s ease, transform .05s ease;
}
button.run:hover { filter: brightness(1.08); }
button.run:active { transform: translateY(1px); }
.error { color: var(--diverge); margin-top: 12px; font-family: ui-monospace, monospace; min-height: 18px; font-size: 13px; }

.stats { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.stats .stat {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 9px 15px; min-width: 92px; transition: border-color .15s ease;
}
.stats .stat:hover { border-color: var(--accent); }
.stats .stat b { display: block; font-size: 21px; color: var(--fg); font-variant-numeric: tabular-nums; }
.stats .stat span { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }

.viz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 12px; flex-wrap: wrap; }
.playback { display: flex; gap: 8px; align-items: center; }
.playback button {
  background: var(--panel); color: var(--fg); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 12px; cursor: pointer; transition: all .15s ease; font-size: 13px;
}
.playback button:hover { border-color: var(--accent); color: #fff; }
.playback label { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 4px; width: 110px;
  background: var(--border); border-radius: 3px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 0 0 3px rgba(88,166,255,0.2); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: none; border-radius: 50%;
  background: var(--accent); cursor: pointer; }
.cycle { font-family: ui-monospace, monospace; color: var(--accent); font-size: 15px; font-variant-numeric: tabular-nums; }

canvas {
  width: 100%; display: block; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; color: var(--muted); font-size: 12px; align-items: center; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.sw.alu { background: var(--alu); } .sw.mem { background: var(--mem); }
.sw.branch { background: var(--branch); } .sw.idle { background: var(--idle); border: 1px solid var(--border); }
.sw.diverge { background: var(--diverge); }
.legend .hint { flex-basis: 100%; color: var(--faint); line-height: 1.6; }
.legend .hint b { color: var(--muted); font-weight: 600; }
footer { padding: 16px 28px 28px; color: var(--muted); border-top: 1px solid var(--border); font-size: 12px; margin-top: 8px; }
footer code { color: var(--fg); background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
