:root {
  --bg: #0a0a0c;
  --panel: #101014;
  --ink: #d7d7da;
  --dim: #85858c;
  --line: #23232a;
  --red: #a8173a; /* invalidation / cache miss / cost */
  --red-bright: #e23a5e;
  --green: #2f9e54; /* cache hit */
  --green-bright: #46c772;
  --amber: #c8922a; /* cache write */
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  padding: 0 clamp(14px, 4vw, 48px) 64px;
  max-width: 1180px;
  margin: 0 auto;
  position: relative;
}

/* CRT overlay: hairline scanlines + faint red vignette */
.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.014) 0 1px, transparent 1px 3px),
    radial-gradient(120% 90% at 50% 0%, transparent 60%, rgba(168, 23, 58, 0.07) 100%);
  mix-blend-mode: screen;
}

a { color: var(--red-bright); text-decoration: none; border-bottom: 1px solid rgba(226, 58, 94, 0.35); }
a:hover { color: #ff5e7f; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 28px 0 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  gap: 8px;
}
.brand { font-size: 15px; letter-spacing: 0.02em; }
.brand .word { color: var(--red-bright); font-weight: 600; }
.brand .sep { color: var(--dim); margin: 0 8px; }
.run-meta { color: var(--dim); font-size: 12px; }

.lede {
  color: var(--ink);
  max-width: 70ch;
  margin: 20px 0 8px;
}
.lede em { color: var(--red-bright); font-style: normal; }

/* controls */
.controls { display: flex; gap: 28px; flex-wrap: wrap; margin: 18px 0 8px; }
.ctl-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctl-label { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; margin-right: 2px; }
.seg {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--dim);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.16s ease;
}
.seg:hover { color: var(--ink); border-color: #34343d; }
.seg[aria-selected="true"] { color: var(--ink); border-color: #44444f; background: #16161c; }
.seg.danger[aria-selected="true"] { color: #ff8aa1; border-color: var(--red); box-shadow: inset 0 0 0 1px rgba(168, 23, 58, 0.4); }
.seg.good[aria-selected="true"] { color: var(--green-bright); border-color: var(--green); box-shadow: inset 0 0 0 1px rgba(47, 158, 84, 0.4); }

/* layout */
.grid { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr); gap: 18px; margin-top: 18px; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--line); padding: 16px 16px 18px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--dim); margin: 0 0 14px; font-weight: 500; }
.turn-counter { color: var(--green-bright); margin-left: 8px; letter-spacing: 0; text-transform: none; }

/* colour key */
.legend-key { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11px; color: var(--dim); margin: -4px 0 14px; }
.legend-key .sw { display: inline-block; width: 10px; height: 10px; border: 1px solid; margin-right: 5px; vertical-align: middle; }
.legend-key .sw-cached { background: rgba(47, 158, 84, 0.22); border-color: var(--green); }
.legend-key .sw-write { background: rgba(200, 146, 42, 0.22); border-color: var(--amber); }
.legend-key .sw-miss { background: rgba(168, 23, 58, 0.22); border-color: var(--red); }

/* prompt stack */
.stack { display: flex; flex-direction: column; gap: 4px; }
.layer {
  position: relative;
  border: 1px solid var(--line);
  padding: 9px 11px;
  background: #0d0d11;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.layer .lname { font-size: 12px; color: var(--ink); }
.layer .lmeta { font-size: 11px; color: var(--dim); float: right; }
.layer .ldesc { font-size: 11px; color: var(--dim); margin-top: 2px; }

.layer.cached { border-color: rgba(47, 158, 84, 0.5); background: linear-gradient(90deg, rgba(47, 158, 84, 0.1), rgba(47, 158, 84, 0.03)); }
.layer.cached::before { content: "✓ cached"; }
.layer.miss { border-color: rgba(168, 23, 58, 0.6); background: linear-gradient(90deg, rgba(168, 23, 58, 0.14), rgba(168, 23, 58, 0.04)); }
.layer.miss::before { content: "✗ recomputed"; }
.layer.write { border-color: rgba(200, 146, 42, 0.55); background: linear-gradient(90deg, rgba(200, 146, 42, 0.12), rgba(200, 146, 42, 0.03)); }
.layer.write::before { content: "↑ written"; }
.layer.fresh { border-color: #34343d; }
.layer.fresh::before { content: "• this turn"; }
.layer::before {
  position: absolute; top: -8px; right: 10px;
  font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 1px 6px; background: var(--bg); color: var(--dim);
}
.layer.cached::before { color: var(--green-bright); }
.layer.miss::before { color: var(--red-bright); }
.layer.write::before { color: var(--amber); }

/* the timestamp chip — the troublemaker */
.tschip {
  display: flex; align-items: center; gap: 8px;
  border: 1px dashed var(--red); background: rgba(168, 23, 58, 0.08);
  padding: 7px 11px; font-size: 12px; color: #ff8aa1;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.tschip.in-tail { border-style: solid; border-color: #34343d; background: #0d0d11; color: var(--dim); }
.tschip .clock { font-variant-numeric: tabular-nums; }

.cache-boundary {
  text-align: center; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--dim); padding: 3px 0; border-top: 1px dashed #2c2c34;
}
.boundary-note { margin-top: 12px; font-size: 12px; color: var(--dim); min-height: 2.6em; }
.boundary-note b { color: var(--ink); font-weight: 600; }

/* transcript */
.transcript { display: flex; flex-direction: column; gap: 10px; min-height: 196px; max-height: 300px; overflow-y: auto; padding-right: 4px; }
.msg { font-size: 13px; }
.msg .who { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); display: block; margin-bottom: 2px; }
.msg.player .body { color: var(--ink); }
.msg.player .who { color: var(--green-bright); }
.msg.dm .body { color: #b9b9bf; padding-left: 10px; border-left: 1px solid var(--line); }
.msg.dm .who { color: var(--red-bright); }
.transcript .empty { color: var(--dim); font-size: 12px; padding: 20px 0; }

/* stepper */
.stepper { display: flex; gap: 8px; margin: 14px 0 4px; flex-wrap: wrap; }
.step-btn {
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  background: #16161c; border: 1px solid var(--red); padding: 8px 14px; cursor: pointer;
  transition: all 0.16s ease;
}
.step-btn:hover { background: rgba(168, 23, 58, 0.18); }
.step-btn.ghost { border-color: var(--line); color: var(--dim); background: var(--panel); }
.step-btn.ghost:hover { color: var(--ink); border-color: #34343d; }
.step-btn:disabled { opacity: 0.4; cursor: default; }

/* meters */
.meters { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.meter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.meter-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); width: 64px; flex: none; }
.tokbar { flex: 1; height: 26px; display: flex; background: #0d0d11; border: 1px solid var(--line); position: relative; overflow: hidden; }
.tokbar .seg-fill { height: 100%; transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.tokbar .fill-cached { background: var(--green); }
.tokbar .fill-uncached { background: var(--red); }
.tokbar .fill-write { background: var(--amber); }
.legend { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 10px; color: var(--ink); text-shadow: 0 0 4px #000; pointer-events: none; }

.bill { display: flex; gap: 20px; flex-wrap: wrap; }
.bill-col { display: flex; flex-direction: column; gap: 2px; }
.bill-k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--dim); }
.bill-v { font-size: 19px; font-variant-numeric: tabular-nums; color: var(--ink); }
.bill-v.muted { color: var(--dim); }
.bill-v.save { color: var(--green-bright); }
.bill-v.cost { color: var(--red-bright); }

/* headline */
.headline {
  margin-top: 22px; padding: 18px 20px; border: 1px solid var(--line); background: #0d0d11;
  font-size: 15px; line-height: 1.6;
}
.headline b { color: var(--ink); }
.headline .hot { color: var(--red-bright); font-weight: 600; }
.headline .cool { color: var(--green-bright); font-weight: 600; }

.foot-note { color: var(--dim); font-size: 12px; margin-top: 18px; max-width: 76ch; }
