:root {
  color-scheme: light;
  --ink: #20201d;
  --muted: #706d66;
  --line: #d8d0c2;
  --paper: #f7f4ee;
  --panel: #fffaf1;
  --panel-strong: #ffffff;
  --teal: #167c76;
  --teal-soft: #d8efea;
  --rose: #b24a60;
  --amber: #b8751f;
  --graphite: #33383a;
  --shadow: 0 18px 54px rgba(44, 42, 38, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(32, 32, 29, 0.03) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.12fr) minmax(280px, 0.72fr);
  gap: 18px;
  width: min(1480px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 0;
}

.life-panel,
.turn-panel,
.inspect-panel {
  display: flex;
  height: calc(100vh - 32px);
  min-height: 640px;
  border: 1px solid rgba(52, 48, 41, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 250, 241, 0.92);
  box-shadow: var(--shadow);
}

.life-panel,
.turn-panel {
  flex-direction: column;
}

.life-panel {
  overflow: auto;
}

.inspect-panel {
  flex-direction: column;
  overflow: hidden;
}

.topbar,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 760;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.8rem);
  line-height: 0.9;
}

h2 {
  font-size: 1.28rem;
}

.runtime-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 112px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--graphite);
  font-size: 0.8rem;
  font-weight: 680;
}

.runtime-pill.live .status-dot {
  background: var(--teal);
}

.runtime-pill.fallback .status-dot {
  background: var(--amber);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
}

.life-stage {
  position: relative;
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 300px;
  padding: 14px;
  overflow: hidden;
}

#life-canvas {
  width: min(100%, 350px);
  aspect-ratio: 1;
  height: auto;
}

.life-readout {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
}

.control-grid {
  display: grid;
  gap: 10px;
  padding: 14px 18px 16px;
  border-top: 1px solid var(--line);
}

.field-block {
  display: grid;
  gap: 8px;
}

.field-block > label,
.identity-row label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 680;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segment,
.quick-row button,
.inspect-actions button,
.icon-button,
.send-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--ink);
}

.segment {
  min-height: 38px;
  padding: 0 10px;
  color: var(--muted);
  font-weight: 680;
}

.segment.is-active {
  border-color: rgba(22, 124, 118, 0.42);
  background: var(--teal-soft);
  color: #0f5954;
}

.toggles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--graphite);
  font-size: 0.85rem;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
}

.icon-button svg,
.send-button svg,
.inspect-actions svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.1;
}

.turn-panel {
  background: rgba(255, 255, 255, 0.94);
}

.identity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  padding: 14px 18px 0;
}

.identity-row label {
  display: grid;
  gap: 6px;
}

.identity-row input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--ink);
}

.identity-row input {
  height: 38px;
  padding: 0 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.quick-row {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  overflow-x: auto;
}

.quick-row button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  color: var(--graphite);
  font-size: 0.85rem;
}

.transcript {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 6px 18px 18px;
  overflow-y: auto;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(560px, 92%);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.message.user {
  align-self: flex-end;
  border-color: rgba(22, 124, 118, 0.24);
  background: #eef8f4;
}

.message.numa {
  align-self: flex-start;
  border-color: rgba(178, 74, 96, 0.24);
  background: #fff5f5;
}

.message.silent {
  align-self: center;
  width: min(360px, 88%);
  border-style: dashed;
  background: #fffdf8;
  text-align: center;
}

.message-meta {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
}

.message-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}

.composer textarea {
  min-height: 74px;
  max-height: 180px;
  padding: 12px;
  resize: vertical;
}

.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 104px;
  min-height: 44px;
  padding: 0 16px;
  background: var(--graphite);
  color: white;
  font-weight: 720;
}

.send-button:disabled {
  cursor: progress;
  opacity: 0.58;
}

.inspect-panel {
  background: rgba(247, 244, 238, 0.94);
}

.metrics {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 18px;
}

.metrics div {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  min-height: 34px;
  align-items: center;
  border-bottom: 1px solid rgba(216, 208, 194, 0.74);
}

.metrics dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 720;
}

.metrics dd {
  margin: 0;
  overflow: hidden;
  color: var(--graphite);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspect-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 18px 14px;
}

.inspect-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  font-weight: 700;
}

.inspect-actions button:disabled {
  cursor: default;
  opacity: 0.48;
}

.json-box,
.memory-list {
  margin: 0 18px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.82);
}

.json-box {
  min-height: 160px;
  max-height: 310px;
  padding: 12px;
  overflow: auto;
  color: var(--graphite);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  white-space: pre-wrap;
}

.memory-list {
  display: grid;
  gap: 8px;
  max-height: 250px;
  padding: 10px;
  overflow: auto;
}

.memory-item {
  display: grid;
  gap: 4px;
  padding: 9px;
  border: 1px solid rgba(216, 208, 194, 0.78);
  border-radius: 7px;
  background: var(--panel-strong);
}

.memory-item strong {
  color: var(--teal);
  font-size: 0.78rem;
}

.memory-item span {
  color: var(--muted);
  font-size: 0.74rem;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  }

  .inspect-panel {
    grid-column: 1 / -1;
    height: auto;
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 18px, 720px);
    grid-template-columns: minmax(0, 1fr);
    padding: 9px 0;
  }

  .life-panel,
  .turn-panel,
  .inspect-panel {
    height: auto;
    min-height: auto;
  }

  .life-stage {
    min-height: 280px;
  }

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

  .identity-row,
  .composer {
    grid-template-columns: minmax(0, 1fr);
  }

  .send-button {
    min-height: 44px;
  }
}
