:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --surface: #11151c;
  --surface-2: #151b24;
  --surface-3: #1b2330;
  --ink: #f6f8fb;
  --ink-soft: #d8dee8;
  --muted: #8b96a8;
  --faint: #667184;
  --line: rgba(219, 226, 236, 0.12);
  --line-strong: rgba(219, 226, 236, 0.22);
  --active: #5ed7bd;
  --dormant: #7a8493;
  --contradiction: #ef6b7f;
  --revised: #d9a856;
  --restored: #85a8e6;
  --violet: #a991df;
  --focus: rgba(94, 215, 189, 0.2);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(94, 215, 189, 0.08), transparent 31rem),
    radial-gradient(circle at 86% 12%, rgba(133, 168, 230, 0.08), transparent 34rem),
    linear-gradient(180deg, #10141b 0%, #0b0e13 48%, #090b10 100%);
  background-size:
    auto,
    auto,
    auto;
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 2.35rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  padding: 0.58rem 0.86rem;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

button:hover {
  border-color: rgba(244, 247, 251, 0.34);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
  transform: none;
}

button.primary {
  background: linear-gradient(180deg, rgba(94, 215, 189, 0.2), rgba(94, 215, 189, 0.08));
  border-color: rgba(94, 215, 189, 0.42);
}

button.secondary {
  background: rgba(255, 255, 255, 0.035);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(5, 7, 10, 0.74);
  color: var(--ink);
  outline: none;
  padding: 0.72rem 0.78rem;
}

textarea {
  resize: vertical;
  min-height: 5.4rem;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: rgba(99, 230, 190, 0.72);
  box-shadow: 0 0 0 3px var(--focus);
}

label,
.signal-label,
.eyebrow,
.panel-heading span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.11rem;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  padding: clamp(0.8rem, 1.5vw, 1.35rem);
}

.command-bar {
  min-height: 4.6rem;
  display: grid;
  grid-template-columns: minmax(14rem, 1fr) minmax(18rem, auto) auto;
  gap: 1rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 19, 26, 0.9);
  box-shadow: var(--shadow);
  padding: 0.82rem 1rem;
}

.brand {
  display: flex;
  gap: 0.84rem;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  width: 2.28rem;
  height: 2.28rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(94, 215, 189, 0.36);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(94, 215, 189, 0.13), transparent),
    #0e141a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.brand-mark span {
  width: 1.08rem;
  height: 1.08rem;
  border: 1px solid rgba(246, 248, 251, 0.34);
  border-radius: 3px;
  background:
    linear-gradient(135deg, rgba(94, 215, 189, 0.88), rgba(133, 168, 230, 0.72)),
    var(--active);
  box-shadow: inset 0 0 0 3px rgba(11, 14, 19, 0.4);
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 760;
  letter-spacing: 0.24rem;
}

.brand p,
.system-state,
.signal-card span,
#beliefTableMeta,
.revision-detail,
.muted {
  color: var(--muted);
}

.system-state,
.top-actions,
.inline-fields,
.legend,
.decay-form {
  display: flex;
  align-items: center;
  gap: 0.64rem;
}

.system-state {
  justify-content: center;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 0.84rem;
  white-space: nowrap;
}

.system-divider {
  width: 1px;
  height: 1.1rem;
  background: var(--line);
}

.top-actions {
  justify-content: flex-end;
}

.status-dot,
.life,
.row-life {
  display: inline-block;
  width: 0.58rem;
  height: 0.58rem;
  border-radius: 50%;
  background: currentColor;
}

.status-dot.active,
.life.active,
.row-life.active {
  color: var(--active);
  box-shadow: 0 0 12px rgba(94, 215, 189, 0.26);
}

.status-dot.dormant,
.life.dormant,
.row-life.dormant {
  color: var(--dormant);
}

.life.contradiction,
.row-life.contradiction {
  color: var(--contradiction);
  box-shadow: 0 0 12px rgba(239, 107, 127, 0.28);
}

.life.revised,
.row-life.revised {
  color: var(--revised);
}

.life.restored,
.row-life.restored {
  color: var(--restored);
}

.signal-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.82rem;
  margin-top: 0.82rem;
}

.signal-card {
  min-height: 6.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(246, 248, 251, 0.04), transparent),
    rgba(17, 21, 28, 0.86);
  box-shadow: var(--shadow);
  padding: 0.86rem 0.92rem;
}

.signal-card strong {
  display: block;
  margin: 0.32rem 0 0.18rem;
  font-size: clamp(1.55rem, 3vw, 2.24rem);
  line-height: 1;
  letter-spacing: -0.02rem;
}

.signal-card-accent {
  border-color: rgba(133, 168, 230, 0.34);
  background:
    linear-gradient(180deg, rgba(133, 168, 230, 0.1), transparent),
    rgba(17, 21, 28, 0.86);
}

.timeline-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
  min-height: 3.6rem;
  margin-top: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(94, 215, 189, 0.035), transparent 42%),
    rgba(17, 21, 28, 0.78);
  box-shadow: var(--shadow);
  padding: 0.74rem 0.9rem;
}

.timeline-strip strong {
  display: block;
  margin-top: 0.16rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.event-bars {
  display: grid;
  grid-template-columns: repeat(24, minmax(0.24rem, 1fr));
  gap: 0.28rem;
  align-items: end;
  min-height: 2.1rem;
}

.event-bar {
  min-height: 0.36rem;
  height: var(--bar-height, 1rem);
  border-radius: 999px;
  background: var(--bar-color, var(--dormant));
  opacity: var(--bar-opacity, 0.38);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(16rem, 20rem) minmax(42rem, 1fr) minmax(18rem, 24rem);
  gap: 0.82rem;
  margin-top: 0.82rem;
  min-height: calc(100vh - 18rem);
}

.command-panel,
.cortex-panel,
.ledger-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(246, 248, 251, 0.028), transparent),
    rgba(17, 21, 28, 0.9);
  box-shadow: var(--shadow);
}

.command-panel,
.ledger-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}

.panel-heading,
.panel-toolbar,
.belief-table header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.panel-heading strong,
.belief-table header span:last-child {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 650;
}

.operation-form {
  display: flex;
  flex-direction: column;
  gap: 0.58rem;
}

.inline-fields {
  align-items: stretch;
}

.inline-fields input {
  min-width: 0;
}

.decay-form {
  margin-top: auto;
  display: grid;
  grid-template-columns: minmax(6rem, auto) minmax(4.2rem, 1fr) auto;
}

.cortex-panel {
  display: grid;
  grid-template-rows: auto minmax(34rem, 1fr) auto minmax(10rem, 0.34fr);
  overflow: hidden;
}

.panel-toolbar {
  padding: 1rem 1rem 0.82rem;
  border-bottom: 1px solid var(--line);
}

.panel-toolbar h2,
.belief-table h3 {
  margin-top: 0.15rem;
  font-size: 1rem;
  font-weight: 740;
}

.legend {
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.72rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
}

.graph-stage {
  position: relative;
  min-height: clamp(34rem, 62vh, 52rem);
  overflow: hidden;
  background:
    linear-gradient(rgba(226, 232, 240, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(226, 232, 240, 0.03) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, rgba(94, 215, 189, 0.075), transparent 24rem),
    linear-gradient(180deg, rgba(14, 18, 25, 0.92), rgba(7, 10, 15, 0.98));
  background-size:
    48px 48px,
    48px 48px,
    auto,
    auto;
  isolation: isolate;
}

.graph-stage::before,
.graph-stage::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  content: "";
  pointer-events: none;
}

.graph-stage::before {
  background: linear-gradient(90deg, transparent, rgba(246, 248, 251, 0.035) 50%, transparent);
  opacity: 0.48;
}

.graph-stage::after {
  border-top: 1px solid rgba(244, 247, 251, 0.07);
  border-bottom: 1px solid rgba(244, 247, 251, 0.07);
  background: linear-gradient(180deg, rgba(244, 247, 251, 0.03), transparent 18%, transparent 82%, rgba(244, 247, 251, 0.026));
}

#memoryGraph {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#memoryGraph.is-dragging {
  cursor: grabbing;
}

#memoryGraph.has-hit {
  cursor: pointer;
}

#memoryGraph.scene-unavailable {
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    #0b0d11;
}

.scene-hud {
  position: absolute;
  z-index: 2;
  left: 1rem;
  top: 1rem;
  display: grid;
  gap: 0.2rem;
  border: 1px solid rgba(226, 232, 240, 0.14);
  border-radius: 8px;
  background: rgba(10, 14, 20, 0.72);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  padding: 0.72rem 0.82rem;
  backdrop-filter: blur(14px);
}

.scene-hud span {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 760;
  letter-spacing: 0.13rem;
  text-transform: uppercase;
}

.scene-hud strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04rem;
  text-transform: uppercase;
}

.graph-readout {
  position: absolute;
  z-index: 2;
  right: 1rem;
  bottom: 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 14, 20, 0.78);
  color: var(--ink-soft);
  font: 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04rem;
  padding: 0.48rem 0.62rem;
  text-transform: uppercase;
  backdrop-filter: blur(14px);
}

.memory-inspector {
  min-height: 4.8rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(13, 15, 19, 0.86);
  padding: 0.9rem 1rem;
}

.memory-inspector strong {
  display: block;
  margin-bottom: 0.32rem;
  color: var(--ink);
  font-size: 0.94rem;
}

.memory-inspector dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0.64rem 0 0;
}

.memory-inspector dt {
  color: var(--faint);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
}

.memory-inspector dd {
  margin: 0.18rem 0 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.belief-table {
  min-height: 0;
  padding: 0.9rem 1rem 1rem;
}

.table-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.46rem;
}

.segment-control {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(5, 7, 10, 0.52);
  padding: 0.2rem;
}

.segment-control button {
  min-height: 1.72rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  padding: 0.3rem 0.48rem;
}

.segment-control button:hover,
.segment-control button.is-active {
  background: rgba(99, 230, 190, 0.12);
  color: var(--ink);
  transform: none;
}

.belief-rows {
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
  max-height: 16rem;
  margin-top: 0.72rem;
  overflow: auto;
  padding-right: 0.2rem;
}

.belief-row {
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr) minmax(7rem, 0.75fr) minmax(4.5rem, auto);
  gap: 0.62rem;
  align-items: center;
  min-height: 3.05rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  color: inherit;
  text-align: left;
  width: 100%;
}

.belief-row:hover,
.belief-row.is-selected {
  background: rgba(99, 230, 190, 0.055);
  border-color: rgba(99, 230, 190, 0.34);
}

.belief-row-main,
.belief-row-value {
  min-width: 0;
}

.belief-row-main strong,
.belief-row-value strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.84rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.belief-row-main span,
.belief-row-value span,
.belief-row-score {
  color: var(--muted);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.belief-row-score {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: right;
}

.query-result,
.revision-panel,
.event-log {
  min-width: 0;
}

#queryResult {
  min-height: 8.6rem;
  max-height: 15rem;
  margin: 0.72rem 0 0;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(5, 7, 10, 0.58);
  padding: 0.78rem;
  font: 0.82rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.revision-detail {
  margin-top: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  padding: 0.82rem;
  font-size: 0.84rem;
  line-height: 1.45;
}

.revision-detail strong {
  color: var(--ink);
}

.health-panel {
  min-width: 0;
}

.health-stack {
  display: flex;
  flex-direction: column;
  gap: 0.58rem;
  margin-top: 0.7rem;
}

.health-row {
  display: grid;
  grid-template-columns: minmax(6.4rem, 1fr) auto;
  gap: 0.54rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.health-row strong {
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
}

.health-row i {
  grid-column: 1 / -1;
  display: block;
  height: 0.42rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5, 7, 10, 0.62);
}

.health-row b {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--active);
}

#driftBar {
  background: var(--revised);
}

.event-log {
  flex: 1;
  display: flex;
  min-height: 0;
  flex-direction: column;
}

#eventList {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
  margin: 0.72rem 0 0;
  overflow: auto;
  padding: 0 0.18rem 0 0;
  list-style: none;
}

#eventList li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.56rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  padding: 0.66rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

#eventList li strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.76rem;
  letter-spacing: 0.05rem;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

#eventList time {
  display: block;
  margin-top: 0.22rem;
  color: var(--faint);
  font-size: 0.72rem;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 4rem;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

[data-life="active"] {
  border-color: rgba(99, 230, 190, 0.28);
}

[data-life="dormant"] {
  border-color: rgba(115, 128, 147, 0.3);
}

[data-life="contradiction"] {
  border-color: rgba(255, 94, 116, 0.34);
}

[data-life="revised"] {
  border-color: rgba(241, 189, 91, 0.34);
}

[data-life="restored"] {
  border-color: rgba(119, 167, 255, 0.34);
}

@media (max-width: 1280px) {
  .signal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workbench {
    grid-template-columns: minmax(17rem, 22rem) minmax(28rem, 1fr);
  }

  .ledger-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(18rem, 0.82fr) minmax(18rem, 0.72fr) minmax(20rem, 1fr);
  }
}

@media (max-width: 900px) {
  .command-bar,
  .workbench,
  .ledger-panel,
  .signal-grid,
  .timeline-strip {
    grid-template-columns: 1fr;
  }

  .system-state,
  .top-actions,
  .legend {
    justify-content: flex-start;
  }

  .workbench {
    min-height: auto;
  }

  .cortex-panel {
    order: -1;
    grid-template-rows: auto minmax(28rem, 62svh) auto auto;
  }

  .memory-inspector dl,
  .belief-row {
    grid-template-columns: 1fr;
  }

  .belief-row-score {
    text-align: left;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 0.55rem;
  }

  .command-bar,
  .command-panel,
  .ledger-panel {
    padding: 0.78rem;
  }

  .signal-grid,
  .workbench {
    gap: 0.6rem;
    margin-top: 0.6rem;
  }

  .panel-toolbar,
  .belief-table header,
  .panel-heading {
    flex-direction: column;
    gap: 0.38rem;
  }

  .decay-form {
    grid-template-columns: 1fr;
  }

  .table-actions {
    align-items: stretch;
    width: 100%;
  }

  .segment-control {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scene-hud {
    left: 0.72rem;
    top: 0.72rem;
    padding: 0.58rem 0.64rem;
  }

  .graph-readout {
    right: 0.72rem;
    bottom: 0.72rem;
    max-width: calc(100% - 1.44rem);
    white-space: normal;
  }
}
