:root {
  --bg: #030303;
  --panel: rgba(9, 9, 10, 0.88);
  --line: #1c1c1e;
  --line-hot: #4d0a14;
  --white: #ecebe9;
  --dim: #7b7876;
  --mute: #45423f;
  --red: #ff1a3c;
  --red-deep: #8c0a1e;
  --glow: rgba(255, 26, 60, 0.55);
  --level: 0;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --term: "Share Tech Mono", "JetBrains Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.32) 0 1px, transparent 1px 3px);
  animation: roll 7s linear infinite;
}

@keyframes roll {
  to {
    background-position: 0 300px;
  }
}

.matrix {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

button,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* Top bar */
.top {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-hot);
  background: linear-gradient(90deg, rgba(255, 26, 60, 0.1), rgba(3, 3, 3, 0.92) 40%);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.glyph {
  width: 36px;
  height: 36px;
  color: var(--red);
  filter: drop-shadow(0 0 8px var(--glow));
  animation: spin 14s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

h1 {
  margin: 0;
  font-family: var(--term);
  font-weight: 400;
  font-size: 24px;
  letter-spacing: 0.12em;
  line-height: 1;
}

.sub {
  margin: 4px 0 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--red);
  text-transform: uppercase;
}

.chips {
  flex: 1;
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.chip {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.6);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.chip b {
  padding: 4px 7px;
  background: var(--line);
  color: var(--dim);
  font-weight: 600;
}

.chip em {
  padding: 4px 9px;
  font-style: normal;
  color: var(--white);
  min-width: 70px;
}

body[data-mood="thinking"] #cState,
body[data-mood="speaking"] #cState {
  color: var(--red);
}

.controls {
  display: flex;
  gap: 6px;
}

select,
.btn {
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--line-hot);
  border-radius: 0;
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.btn:hover,
select:hover {
  border-color: var(--red);
  color: #fff;
  background: rgba(255, 26, 60, 0.14);
}

.btn[aria-pressed="true"] {
  color: var(--mute);
}

.btn.hot:hover {
  background: var(--red);
}

/* Glitch */
.glitch {
  position: relative;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.glitch::before {
  color: var(--red);
  animation: tearA 4.5s infinite steps(1);
}

.glitch::after {
  color: #fff;
  animation: tearB 4.5s infinite steps(1);
}

@keyframes tearA {
  0%,
  88%,
  100% {
    opacity: 0;
    transform: none;
    clip-path: none;
  }
  89% {
    opacity: 1;
    transform: translate(-4px, 0);
    clip-path: inset(0 0 62% 0);
  }
  91% {
    opacity: 1;
    transform: translate(3px, 1px);
    clip-path: inset(55% 0 10% 0);
  }
  93% {
    opacity: 1;
    transform: translate(-2px, -1px);
    clip-path: inset(30% 0 45% 0);
  }
}

@keyframes tearB {
  0%,
  90%,
  100% {
    opacity: 0;
    transform: none;
    clip-path: none;
  }
  90.5% {
    opacity: 0.7;
    transform: translate(3px, 0);
    clip-path: inset(70% 0 0 0);
  }
  92.5% {
    opacity: 0.7;
    transform: translate(-3px, 0);
    clip-path: inset(10% 0 70% 0);
  }
}

/* Grid */
.grid {
  position: relative;
  z-index: 5;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 320px;
  gap: 8px;
  padding: 8px;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px 12px 12px;
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid var(--red);
  pointer-events: none;
}

.panel::before {
  top: -1px;
  left: -1px;
  border-right: 0;
  border-bottom: 0;
}

.panel::after {
  bottom: -1px;
  right: -1px;
  border-left: 0;
  border-top: 0;
}

.panel.grow {
  flex: 1;
  min-height: 180px;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  margin: 0 0 10px;
  font-family: var(--term);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--dim);
}

.panel h2 span {
  color: var(--red);
  margin-right: 8px;
}

.panel h2 span::before {
  content: "[";
}

.panel h2 span::after {
  content: "]";
}

/* Segmented bars */
.seg {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  height: 7px;
}

.seg i {
  background: #161616;
}

.seg i.on {
  background: var(--red);
  box-shadow: 0 0 6px var(--glow);
}

.seg i.on.peak {
  background: #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

/* Gauges */
.gauges {
  display: grid;
  gap: 9px;
}

.gauge .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.gauge span {
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--dim);
}

.gauge b {
  font-family: var(--term);
  font-weight: 400;
  font-size: 16px;
  color: var(--white);
}

.gauge.alert b {
  color: var(--red);
  text-shadow: 0 0 8px var(--glow);
}

/* Spectrum + VU */
.spectrum,
.history {
  display: block;
  width: 100%;
  height: 86px;
  background: linear-gradient(transparent 49%, #120306 50%, transparent 51%), #050505;
  border: 1px solid var(--line);
}

.history {
  height: 74px;
}

.vu {
  display: grid;
  grid-template-columns: 30px 1fr 64px;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.1em;
}

.vubar {
  position: relative;
  height: 10px;
  background: repeating-linear-gradient(90deg, #161616 0 5px, transparent 5px 7px);
}

.vubar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: repeating-linear-gradient(90deg, var(--red) 0 5px, transparent 5px 7px);
  filter: drop-shadow(0 0 4px var(--glow));
}

.vubar b {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  left: 0;
  background: #fff;
}

.vu em {
  font-style: normal;
  text-align: right;
  color: var(--white);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 6px;
  font-size: 10px;
  color: var(--dim);
}

.legend i {
  width: 8px;
  height: 8px;
  display: inline-block;
}

.k-word,
.k-out {
  background: var(--red);
}

.k-voice,
.k-cached {
  background: #fff;
}

.k-fresh {
  background: var(--red-deep);
}

.stack {
  display: flex;
  height: 14px;
  background: #121212;
}

.stack i {
  display: block;
  width: 0;
  transition: width 0.4s;
}

.stack .cached {
  background: #fff;
}

.stack .fresh {
  background: var(--red-deep);
}

.stack .out {
  background: var(--red);
}

/* Center */
.center {
  overflow: hidden;
}

.core {
  height: 300px;
  flex: none;
  padding: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, rgba(255, 26, 60, calc(0.08 + var(--level) * 0.25)), transparent 60%), var(--panel);
}

.virus {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--dim);
}

.hud p {
  margin: 0 0 3px;
}

.hud b {
  color: var(--white);
  font-weight: 600;
}

.hud.tl {
  top: 12px;
  left: 14px;
}

.hud.tr {
  top: 12px;
  right: 14px;
  text-align: right;
}

.hud.bl {
  bottom: 12px;
  left: 14px;
}

.hud.br {
  bottom: 12px;
  right: 14px;
  width: 190px;
}

.status {
  font-family: var(--term);
  font-size: 18px;
  letter-spacing: 0.3em;
  color: var(--white);
}

body[data-mood="thinking"] .status,
body[data-mood="speaking"] .status {
  color: var(--red);
  text-shadow: 0 0 10px var(--glow);
}

body[data-mood="thinking"] .status::after {
  content: "_";
  animation: blink 0.5s steps(2) infinite;
}

.payload .seg {
  margin-top: 4px;
}

/* Log */
.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-hot) transparent;
}

.msg {
  line-height: 1.65;
  font-size: 14px;
}

.msg .who {
  margin-right: 8px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.msg.user {
  color: var(--dim);
}

.msg.user .who {
  color: var(--mute);
}

.msg.user .who::before {
  content: "> ";
}

.msg.dark .who {
  color: var(--red);
}

.msg.dark .text {
  color: var(--white);
}

.msg.dark.live .text::after {
  content: "█";
  margin-left: 2px;
  color: var(--red);
  animation: blink 0.6s steps(2) infinite;
}

.msg.error {
  color: var(--red);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.empty {
  margin: auto 0;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.9;
}

.empty b {
  color: var(--red);
  font-weight: 600;
}

/* Composer */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid var(--line-hot);
  flex: none;
}

.composer:focus-within {
  border-color: var(--red);
  box-shadow: 0 0 0 1px rgba(255, 26, 60, 0.3), 0 0 22px rgba(255, 26, 60, 0.15);
}

.prompt {
  color: var(--red);
  font-weight: 600;
  white-space: nowrap;
}

textarea {
  flex: 1;
  resize: none;
  background: transparent;
  border: 0;
  outline: 0;
  padding: 8px 0;
  max-height: 140px;
  line-height: 1.5;
  caret-color: var(--red);
}

textarea::placeholder {
  color: var(--mute);
}

.mic {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line-hot);
  cursor: pointer;
  color: var(--dim);
}

.mic svg {
  width: 18px;
  height: 18px;
}

.mic.on {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 16px var(--glow);
}

.exec {
  height: 38px;
  padding: 0 18px;
  background: var(--red);
  border: 0;
  color: #fff;
  font-family: var(--term);
  font-size: 15px;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.exec:hover {
  background: #fff;
  color: #000;
}

.exec:disabled {
  opacity: 0.35;
  cursor: wait;
}

/* Modules */
.organs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.organs li .row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
}

.organs .led {
  width: 7px;
  height: 7px;
  background: #222;
}

.organs li.fired .led {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

.organs li.failed .led {
  background: #fff;
}

.organs li b {
  font-weight: 600;
  letter-spacing: 0.06em;
}

.organs li b small {
  margin-left: 6px;
  color: var(--mute);
  font-weight: 400;
}

.organs li .val {
  color: var(--dim);
  font-size: 10px;
}

/* Counters */
.counters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.counters div {
  background: #070707;
  padding: 8px 10px;
}

.counters b {
  display: block;
  font-family: var(--term);
  font-weight: 400;
  font-size: 24px;
  color: var(--white);
}

.counters span {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Process log */
.trace {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 11px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-hot) transparent;
}

.trace li {
  display: grid;
  grid-template-columns: 52px 76px 1fr auto;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid #111;
  animation: drop 0.2s ease-out;
}

.trace .ts {
  color: var(--mute);
}

.trace .k {
  color: var(--red);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace .v {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--white);
}

.trace .ms {
  color: var(--dim);
}

.trace li.bad .k,
.trace li.bad .v {
  color: var(--mute);
  text-decoration: line-through;
}

.trace li.turn .v {
  color: var(--red);
}

@keyframes drop {
  from {
    opacity: 0;
    background: rgba(255, 26, 60, 0.25);
  }
}

/* Ticker */
.ticker {
  position: relative;
  z-index: 10;
  height: 24px;
  overflow: hidden;
  border-top: 1px solid var(--line-hot);
  background: rgba(0, 0, 0, 0.9);
  font-size: 11px;
  color: var(--dim);
}

.tape {
  display: inline-flex;
  gap: 28px;
  padding: 5px 0 0 100%;
  white-space: nowrap;
  animation: tape 60s linear infinite;
}

.tape b {
  color: var(--red);
  font-weight: 600;
}

@keyframes tape {
  to {
    transform: translateX(-100%);
  }
}

/* Charter */
.charter {
  max-width: 640px;
  width: calc(100% - 32px);
  padding: 30px 34px 24px;
  background: #050505;
  color: var(--white);
  border: 1px solid var(--red);
  box-shadow: 0 0 80px rgba(255, 26, 60, 0.25);
  font-family: var(--mono);
}

.charter::backdrop {
  background: rgba(0, 0, 0, 0.85);
}

.charter .kicker {
  margin: 0;
  color: var(--red);
  font-size: 11px;
  letter-spacing: 0.2em;
}

.charter h2 {
  margin: 8px 0 20px;
  font-family: var(--term);
  font-weight: 400;
  font-size: 30px;
  letter-spacing: 0.1em;
}

.charter ol {
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.charter li {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  line-height: 1.6;
}

.charter li .num {
  color: var(--red);
  font-weight: 800;
}

.charter li b {
  display: block;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--dim);
}

@media (max-width: 1200px) {
  html,
  body {
    height: auto;
  }
  body {
    overflow: auto;
  }
  .grid {
    flex: none;
    grid-template-columns: 250px minmax(0, 1fr);
  }
  .grid > .col:first-child,
  .center {
    height: calc(100vh - 64px);
  }
  .grid > .col:last-child {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }
  .grid > .col:last-child > .panel {
    min-height: 220px;
  }
  .chips {
    display: none;
  }
}

@media (max-width: 760px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .grid > .col:first-child {
    order: 2;
    height: auto;
    overflow: visible;
  }
  .grid > .col:last-child {
    order: 3;
    grid-template-columns: 1fr;
  }
  .center {
    height: 92vh;
  }
  .core {
    height: 220px;
  }
  .sub,
  .controls select {
    display: none;
  }
}

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