:root {
  --bg: #0b0d11;
  --panel: #12151c;
  --panel-2: #171b24;
  --line: #242a37;
  --text: #e3e7f0;
  --muted: #8a93a6;
  --a: #ef8e4f;
  --b: #3fd0c9;
  --hit: #5bd68a;
  --miss: #ff5d5d;
  --dirty: #f2c14e;
  --comp: #8a93a6;
  --cap: #c38bff;
  --conf: #ff7a59;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --display: 'Unbounded', var(--sans);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--text);
  font: 14px/1.5 var(--sans);
  min-height: 100vh;
}

a { color: var(--b); }
code { font-family: var(--mono); }
[hidden] { display: none !important; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(239,142,79,0.07), transparent);
}
.brand { display: flex; gap: 16px; align-items: center; }
.brand h1 {
  font: 700 26px/1 var(--display);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}
.brand h1 span { color: var(--a); }
.brand p { margin: 0; color: var(--muted); max-width: 640px; }
.logo {
  display: grid;
  grid-template-columns: repeat(2, 14px);
  gap: 3px;
  padding: 6px;
  border: 1.5px solid var(--a);
  border-radius: 6px;
  position: relative;
}
.logo::before, .logo::after {
  content: '';
  position: absolute;
  left: -7px; right: -7px;
  height: 0;
  border-top: 2px dotted var(--a);
}
.logo::before { top: 10px; }
.logo::after { bottom: 10px; }
.logo i { width: 14px; height: 14px; border-radius: 2px; background: #6f9bff; }
.logo i:nth-child(2) { background: #c38bff; }
.logo i:nth-child(3) { background: #ffad5c; }
.logo i:nth-child(4) { background: rgba(255,255,255,0.08); }
.gh {
  font: 600 13px var(--mono);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  white-space: nowrap;
}
.gh:hover { border-color: var(--a); }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 28px 28px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
h2 {
  font: 500 13px var(--display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 12px;
  color: var(--muted);
}
h3 {
  font: 600 12px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 18px 0 8px;
  display: flex;
  justify-content: space-between;
}
h3 small { font-weight: 400; }

/* ---------- side panel ---------- */
.side { grid-row: span 2; align-self: start; position: sticky; top: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.field output { color: var(--text); font-family: var(--mono); }
.field.inline { margin-top: 14px; }
select, input[type=number], textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  font: 13px var(--sans);
  width: 100%;
}
textarea { font: 12px/1.45 var(--mono); resize: vertical; }
select:focus, input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--a); outline-offset: 1px; }
input[type=range] { width: 100%; accent-color: var(--a); }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.params label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.range { display: flex; gap: 10px; align-items: center; }
.range output { font: 600 12px var(--mono); color: var(--text); min-width: 40px; text-align: right; }
.error, .cfg-error { color: var(--miss); font-size: 12.5px; margin: 6px 0; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: 600 13px var(--sans);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--a); border-color: var(--a); color: #1a0f07; }
.btn.primary.on { background: transparent; color: var(--a); }
.btn.wide { width: 100%; margin-top: 8px; }
.transport { display: grid; grid-template-columns: auto 1fr 1fr 1fr; gap: 6px; margin: 14px 0 12px; }

.progress { height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--a), var(--b)); }
.progress-text { font: 12px var(--mono); color: var(--muted); margin: 6px 0 0; text-align: right; }

.tape { list-style: none; margin: 0; padding: 0; font: 12px var(--mono); }
.tape li {
  display: grid;
  grid-template-columns: 44px 18px 1fr 18px 18px;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  border-radius: 5px;
  color: var(--muted);
}
.tape li.cur { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--a); }
.tape li.next { opacity: 0.5; }
.tape .n { text-align: right; opacity: 0.6; }
.tape .op.r { color: #6f9bff; }
.tape .op.w { color: var(--dirty); }
.tape em { font-style: normal; text-align: center; border-radius: 3px; font-weight: 700; }
.tape em.h { background: rgba(91,214,138,0.16); color: var(--hit); }
.tape em.m { background: rgba(255,93,93,0.16); color: var(--miss); }

.legend { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend code { font-size: 11px; opacity: 0.7; }
.legend i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.legend .dirty-mark { background: linear-gradient(225deg, var(--dirty) 40%, rgba(255,255,255,0.1) 40%); }
.legend .ring { border: 2px solid; background: none; }
.legend .ring.hit { border-color: var(--hit); }
.legend .ring.miss { border-color: var(--miss); }

/* ---------- cache chips ---------- */
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; min-width: 0; }
.chip { --accent: var(--a); border-top: 3px solid var(--accent); min-width: 0; }
.chip-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.chip-badge {
  font: 700 18px var(--display);
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: #0b0d11;
  background: var(--accent);
  flex: none;
}
.chip-title { display: flex; flex-direction: column; min-width: 0; }
.chip-title b { font: 600 15px var(--sans); }
.chip-title span { color: var(--muted); font-size: 12.5px; }
.chip-rate { margin-left: auto; text-align: right; }
.chip-rate span { font: 700 26px/1 var(--mono); color: var(--accent); display: block; }
.chip-rate small { color: var(--muted); font-size: 11px; }

.cfg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cfg label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.cfg select { padding: 6px 8px; font-size: 13px; }
.cfg .check { flex-direction: row; align-items: center; gap: 8px; text-transform: none; font: 13px var(--mono); color: var(--text); grid-column: span 3; }
.cfg .check input { accent-color: var(--accent); width: 15px; height: 15px; }

.bits {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: flex-start;
  margin: 14px 0 12px;
  font: 12px var(--mono);
}
.bits .addr { font-weight: 700; padding: 4px 8px 0 0; color: var(--text); }
.bits > span:not(.addr) { display: flex; flex-direction: column; border-radius: 5px; padding: 3px 6px; }
.bits code { letter-spacing: 0.08em; font-size: 12px; }
.bits small { font-size: 10px; opacity: 0.85; }
.b-tag { background: rgba(111,155,255,0.13); color: #9db8ff; }
.b-idx { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.b-off { background: rgba(255,255,255,0.06); color: var(--muted); }

.grid-wrap { position: relative; background: #0d1016; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
canvas.grid { display: block; width: 100%; cursor: crosshair; }
.tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: #050608;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  font: 12px/1.5 var(--mono);
  width: max-content;
  max-width: 230px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.muted { color: var(--muted); }
.dirty { color: var(--dirty); }
.event { min-height: 42px; font-size: 13px; margin: 10px 0; color: var(--muted); }
.event b.ok { color: var(--hit); }
.event b.bad { color: var(--miss); }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.tile span { font-size: 11px; color: var(--muted); }
.tile b { font: 600 15px var(--mono); }
.threec { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--panel-2); margin: 14px 0 8px; }
.threec i { display: block; height: 100%; transition: width .2s; }
.c-comp { background: var(--comp); }
.c-cap { background: var(--cap); }
.c-conf { background: var(--conf); }
.threec-legend { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--muted); }
.threec-legend li { display: flex; align-items: center; gap: 6px; }
.threec-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.threec-legend b { font: 600 12px var(--mono); color: var(--text); }

/* ---------- comparison ---------- */
.compare { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 24px; grid-column: 2; }
#chart { width: 100%; height: 230px; display: block; }
.verdict { font-size: 14px; margin: 0 0 12px; min-height: 42px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
tbody th { text-align: left; font-weight: 500; color: var(--text); }
tbody tr.sub th { padding-left: 18px; color: var(--muted); font-weight: 400; }
td { font-family: var(--mono); text-align: right; color: var(--muted); }
td.win { color: var(--text); font-weight: 700; }
thead th { font: 700 13px var(--display); text-align: right; }
.ca { color: var(--a); }
.cb { color: var(--b); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0 28px; }
.foot a { color: var(--muted); }

@media (max-width: 1180px) {
  .chips { grid-template-columns: 1fr; }
  .compare { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .top { flex-direction: column; align-items: flex-start; padding: 18px 16px; }
  .layout { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  .side { position: static; grid-row: auto; }
  .compare { grid-column: auto; }
  .cfg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cfg .check { grid-column: span 2; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
