:root {
  --bg: #110f0d;
  --bg-2: #191613;
  --bg-3: #221e19;
  --bg-4: #2b261f;
  --line: rgba(243, 234, 220, 0.09);
  --line-2: rgba(243, 234, 220, 0.16);
  --ink: #f3eadc;
  --muted: #9a8f82;
  --faint: #6d645a;
  --token: #e4a574;
  --token-dim: rgba(228, 165, 116, 0.16);
  --net: #7dcdc8;
  --net-dim: rgba(125, 205, 200, 0.14);
  --gpu: #e35d4f;
  --gpu-dim: rgba(227, 93, 79, 0.16);
  --know: #b7c97a;
  --know-dim: rgba(183, 201, 122, 0.14);
  --skill: #c9a8e8;
  --skill-dim: rgba(201, 168, 232, 0.14);
  --file: #8eb6e0;
  --file-dim: rgba(142, 182, 224, 0.14);
  --user: #f3eadc;
  --think: #e6c15c;
  --think-dim: rgba(230, 193, 92, 0.16);
  --ok: #8fca8a;
  --warn: #e0a35b;
  --bad: #e35d4f;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --header: 58px;
  --inspector: 30vh;
  --levers: 268px;
  --window: 292px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
html { font-size: 15px; }
body {
  font-family: var(--sans);
  letter-spacing: 0.01em;
  overflow: hidden;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  opacity: 0.05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--header) minmax(0, 1fr) var(--inspector);
}

header {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(0, 1.6fr) auto;
  gap: 16px;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #161310 0%, var(--bg) 100%);
}

.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand .mark {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--token);
  border: 1px solid var(--token);
  padding: 3px 6px 2px;
}
.brand h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scenarios { display: flex; gap: 6px; flex-wrap: wrap; }
.scenarios button, .transport button, .tab, .chip, .seg button, .toggle {
  font-family: var(--sans);
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.scenarios button {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
}
.scenarios button.on, .seg button.on {
  color: var(--bg);
  background: var(--ink);
  border-color: var(--ink);
}

.transport { display: flex; align-items: center; gap: 8px; }
.transport button {
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.transport button.primary {
  background: var(--token);
  border-color: var(--token);
  color: #1a120c;
  font-weight: 600;
}
.clock {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  min-width: 72px;
}

main {
  display: grid;
  grid-template-columns: var(--levers) minmax(0, 1fr) var(--window);
  min-height: 0;
}

.panel {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
}
.panel:last-child { border-right: 0; border-left: 1px solid var(--line); }

.panel h2, .inspector h2 {
  margin: 0;
  padding: 8px 14px 4px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
}

.levers { background: var(--bg-2); }
.lever {
  padding: 7px 14px 8px;
  border-top: 1px solid var(--line);
}
.lever .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.lever .name { font-size: 12.5px; }
.lever .hint { font-size: 11px; color: var(--muted); line-height: 1.35; margin: 4px 0 6px; }
.toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
}
.toggles .lever { padding: 8px 12px; }
.toggles .hint { display: none; }
.toggle[disabled] { opacity: 0.35; cursor: not-allowed; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { font-size: 11px; padding: 4px 8px; border-radius: 3px; }
.toggle {
  width: 36px; height: 20px; border-radius: 99px; position: relative; padding: 0;
  background: var(--bg-4);
}
.toggle.on { background: var(--token); border-color: var(--token); }
.toggle i {
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); display: block;
  transition: left 0.15s ease;
}
.toggle.on i { left: 18px; background: #1a120c; }

.meters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 12px 10px;
}
.meter {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 8px 10px;
}
.meter .k { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.meter .v { font-family: var(--mono); font-size: 13px; margin-top: 1px; color: var(--token); }
.meter .s { font-size: 10px; color: var(--muted); margin-top: 2px; }

.stage { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; background:
  radial-gradient(1200px 400px at 50% -10%, rgba(228,165,116,0.07), transparent 50%),
  var(--bg); }

.timeline {
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line);
}
.timeline button {
  flex: 1 0 auto;
  min-width: 64px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 6px 10px;
  cursor: pointer;
}
.timeline button .n { display: block; color: var(--faint); font-size: 9px; margin-bottom: 3px; }
.timeline button.on { color: var(--ink); border-bottom-color: var(--token); }
.timeline button.done { color: var(--muted); }
.timeline button.skip { opacity: 0.35; text-decoration: line-through; }

.canvas {
  min-height: 0;
  overflow: auto;
  padding: 18px 22px 8px;
}
.headline {
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.15;
  margin: 0 0 8px;
  max-width: 34ch;
  letter-spacing: -0.02em;
}
.subhead { color: var(--muted); font-size: 13.5px; line-height: 1.5; max-width: 68ch; margin: 0 0 16px; }

.scene {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: 16px;
  align-items: start;
}
.card {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  padding: 14px;
  min-height: 180px;
}
.card h3 {
  margin: 0 0 10px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
}

.stack { display: flex; flex-direction: column-reverse; gap: 4px; }
.strip {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  font-size: 12px;
  border-left: 3px solid;
  background: var(--bg-3);
  cursor: pointer;
}
.strip:hover { filter: brightness(1.08); }
.strip span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip .kind { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.strip .tok { font-family: var(--mono); color: var(--token); font-size: 11px; }
.strip.system { border-color: var(--muted); }
.strip.tools { border-color: var(--gpu); }
.strip.skill { border-color: var(--skill); background: var(--skill-dim); }
.strip.kb { border-color: var(--know); background: var(--know-dim); }
.strip.rag { border-color: var(--know); background: var(--know-dim); }
.strip.history { border-color: var(--token); background: var(--token-dim); }
.strip.file { border-color: var(--file); background: var(--file-dim); }
.strip.user { border-color: var(--user); }
.strip.think { border-color: var(--think); background: var(--think-dim); }
.strip.output { border-color: var(--gpu); background: var(--gpu-dim); }

.path {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.hop {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 10px;
}
.hop .rail {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hop .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg-4);
  border: 2px solid var(--faint);
}
.hop.on .dot { background: var(--token); border-color: var(--token); box-shadow: 0 0 12px var(--token); }
.hop.gpu .dot { border-color: var(--gpu); }
.hop.gpu.on .dot { background: var(--gpu); border-color: var(--gpu); box-shadow: 0 0 12px var(--gpu); }
.hop.net .dot { border-color: var(--net); }
.hop.net.on .dot { background: var(--net); border-color: var(--net); box-shadow: 0 0 12px var(--net); }
.hop .line { width: 1px; flex: 1; min-height: 18px; background: var(--line-2); }
.hop .body { padding-bottom: 12px; }
.hop .body strong { display: block; font-size: 13px; font-weight: 500; }
.hop .body span { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 2px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 99px;
  color: var(--ink);
}

.gpu-die {
  background: #16110f;
  border: 1px solid var(--gpu);
  padding: 12px;
  position: relative;
  overflow: hidden;
}
.gpu-die .hbm {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.hbm i {
  height: 18px;
  background: repeating-linear-gradient(-45deg, #3a201c, #3a201c 4px, #4a2a24 4px, #4a2a24 8px);
  border: 1px solid rgba(227,93,79,0.35);
  font-style: normal;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  color: #f3c2bb;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sms {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}
.sms b {
  display: block;
  height: 14px;
  background: #2a211c;
  border: 1px solid #3d332c;
}
.sms b.hot { background: var(--token); border-color: var(--token); }
.sms b.pulse { background: var(--gpu); border-color: var(--gpu); animation: pulse 0.7s ease infinite; }
.kvbar { height: 10px; background: #2a211c; position: relative; }
.kvbar span {
  display: block; height: 100%; background: var(--think);
  width: 0%; transition: width 0.4s ease;
}
.gpu-die .cap {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; color: var(--muted); margin-top: 6px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.stream {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--ink);
  min-height: 80px;
}
.caret { display: inline-block; width: 7px; height: 13px; background: var(--token); margin-left: 2px; animation: pulse 1s step-end infinite; vertical-align: -1px; }

.warns { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.warn {
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 10px;
  border-left: 3px solid var(--warn);
  background: rgba(224,163,91,0.08);
  color: #f0d3aa;
}
.warn.bad { border-color: var(--bad); background: var(--gpu-dim); color: #f3c2bb; }

.readout {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.readout div { padding: 8px 12px; border-right: 1px solid var(--line); }
.readout div:last-child { border-right: 0; }
.readout .k { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.readout .v { font-family: var(--mono); font-size: 13px; margin-top: 2px; }

.window { background: var(--bg-2); display: flex; flex-direction: column; }
.win-meta { padding: 0 16px 8px; font-size: 12px; color: var(--muted); }
.win-meta strong { color: var(--ink); font-weight: 500; }
.tape {
  margin: 0 16px 8px;
  border: 1px solid var(--line-2);
  background: #0c0b09;
  min-height: 120px;
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}
.tape .band {
  min-height: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: 10px;
  color: #1a120c;
  overflow: hidden;
}
.tape .free {
  flex: 1;
  background: repeating-linear-gradient(0deg, transparent, transparent 7px, rgba(243,234,220,0.04) 7px, rgba(243,234,220,0.04) 8px);
  color: var(--faint);
  display: flex;
  align-items: flex-end;
  padding: 8px;
  font-family: var(--mono);
  font-size: 10px;
}
.legend { padding: 8px 16px 16px; display: flex; flex-wrap: wrap; gap: 8px 12px; }
.legend span { font-size: 10px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sw { width: 8px; height: 8px; display: inline-block; }

.inspector {
  border-top: 1px solid var(--line-2);
  background: #141210;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
}
.tab.on { color: var(--ink); border-bottom-color: var(--token); }
.insp {
  min-height: 0;
  overflow: auto;
  padding: 14px 18px 18px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
pre, .excerpt {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 10px;
  margin: 0;
  color: #d9d0c3;
  max-height: 220px;
  overflow: auto;
}
.packet-list { display: flex; flex-direction: column; gap: 8px; }
.packet {
  border: 1px solid var(--line);
  background: var(--bg-2);
}
.packet header.ph {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
}
.packet .why { padding: 0 10px 10px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.bar {
  height: 8px;
  background: #2a261f;
  display: flex;
  overflow: hidden;
}
.bar i { display: block; height: 100%; }
.tiny { font-size: 11px; color: var(--muted); line-height: 1.45; }
.quality {
  height: 8px; background: #2a261f; margin-top: 6px;
}
.quality span { display: block; height: 100%; background: var(--ok); }

.myth { padding: 8px 0; border-bottom: 1px solid var(--line); }
.myth b { display: block; font-weight: 500; font-size: 13px; }
.myth span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.45; }

.delta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--net);
}

footer.note {
  display: none;
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app { height: auto; grid-template-rows: auto auto auto; }
  header { grid-template-columns: 1fr; padding: 12px 16px; gap: 10px; }
  main { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
  .panel:last-child { border-left: 0; }
  .scene, .grid-2, .grid-3, .readout { grid-template-columns: 1fr; }
  .readout div { border-right: 0; border-bottom: 1px solid var(--line); }
  .tape { min-height: 180px; }
  .inspector { height: auto; }
}

html.embed,
html.embed body {
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
html.embed .app {
  height: 100%;
  min-height: 640px;
  min-width: 0;
  max-width: 100%;
}
html.embed .grain {
  opacity: 0.035;
}
html.embed {
  --levers: 220px;
  --window: 248px;
  --inspector: 28vh;
  --header: 52px;
}
html.embed .brand p { display: none; }
html.embed .brand h1 { white-space: nowrap; font-size: 18px; }
html.embed .timeline button { min-width: 52px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
