:root {
  color-scheme: dark;
  --bg: #07090b;
  --glass: rgba(16, 20, 24, 0.82);
  --glass-strong: rgba(19, 25, 30, 0.94);
  --line: rgba(188, 216, 224, 0.18);
  --line-hot: rgba(103, 221, 236, 0.55);
  --text: #edf5f6;
  --muted: #91a1a8;
  --cyan: #67ddec;
  --pink: #f18db8;
  --green: #91daa0;
  --amber: #f1c76f;
  --black: #090d10;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.os-shell {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 28% 24%, rgba(103, 221, 236, 0.12), transparent 28%),
    radial-gradient(circle at 72% 68%, rgba(241, 141, 184, 0.1), transparent 32%),
    #07090b;
  background-size: 44px 44px, 44px 44px, auto, auto, auto;
}

.system-bar {
  position: fixed;
  z-index: 100;
  inset: 0 0 auto 0;
  height: 42px;
  display: grid;
  grid-template-columns: 220px 1fr 120px;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 14, 0.84);
  backdrop-filter: blur(16px);
}

.system-brand,
.system-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.system-brand {
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  background: #eef7f8;
  color: var(--black);
  font-size: 14px;
}

.system-center {
  justify-content: center;
  min-width: 0;
}

.system-chip,
#system-clock {
  border: 1px solid var(--line);
  color: var(--muted);
  min-height: 24px;
  padding: 3px 10px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.system-chip.online {
  color: var(--green);
  border-color: rgba(145, 218, 160, 0.45);
}

#system-clock {
  justify-self: end;
  color: var(--text);
}

.dock {
  position: fixed;
  z-index: 95;
  left: 14px;
  top: 64px;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(8, 11, 14, 0.7);
  backdrop-filter: blur(14px);
}

.dock-item {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.dock-item:hover,
.dock-item.active {
  border-color: var(--line-hot);
  background: rgba(103, 221, 236, 0.12);
}

.runtime-only {
  display: none;
}

.show-runtime .runtime-only {
  display: block;
}

.show-runtime .dock .runtime-only {
  display: grid;
}

.desktop {
  position: relative;
  min-height: 100vh;
  padding: 58px 24px 24px 82px;
}

.window {
  position: absolute;
  display: none;
  min-width: 300px;
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.window.active {
  display: block;
}

.window.focused {
  border-color: var(--line-hot);
}

.world-window {
  left: 96px;
  top: 70px;
  width: min(860px, calc(100vw - 130px));
}

.characters-window {
  right: 30px;
  top: 92px;
  width: 430px;
  max-width: calc(100vw - 120px);
  max-height: calc(100vh - 124px);
}

.factory-window {
  left: 116px;
  bottom: 28px;
  width: 680px;
  max-width: calc(100vw - 150px);
}

.assets-window {
  right: 34px;
  top: 56px;
  width: 760px;
  max-width: calc(100vw - 130px);
  max-height: calc(100vh - 96px);
}

.memory-window {
  right: 46px;
  bottom: 44px;
  width: 390px;
  max-width: calc(100vw - 120px);
}

.octopus-window {
  left: 148px;
  top: 120px;
  width: 760px;
  max-width: calc(100vw - 180px);
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  cursor: move;
  user-select: none;
}

.titlebar h1,
.titlebar h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.window-kicker,
.window-badge {
  color: var(--muted);
  font-size: 12px;
}

.window-badge {
  border: 1px solid var(--line);
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.18);
}

.window-actions button,
.forge-command {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  cursor: pointer;
}

.window-actions button {
  min-height: 32px;
  padding: 0 12px;
}

.window-actions button:hover,
.forge-command:hover {
  border-color: var(--line-hot);
}

.world-body {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 18px;
  padding: 18px;
}

.neural-core {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 320px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(103, 221, 236, 0.08), transparent),
    linear-gradient(315deg, rgba(241, 141, 184, 0.08), transparent),
    rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.core-ring {
  position: absolute;
  border: 1px solid rgba(103, 221, 236, 0.45);
  border-radius: 50%;
}

.ring-a {
  width: 230px;
  height: 230px;
}

.ring-b {
  width: 170px;
  height: 170px;
  border-color: rgba(241, 141, 184, 0.45);
}

.ring-c {
  width: 92px;
  height: 92px;
  border-color: rgba(145, 218, 160, 0.5);
}

.core-label {
  position: relative;
  display: grid;
  gap: 4px;
  text-align: center;
}

.core-label strong {
  font-size: 30px;
}

.core-label span {
  color: var(--muted);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 10px;
}

.metric {
  border: 1px solid var(--line);
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.metric strong {
  display: block;
  font-size: 28px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.law-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 18px;
}

.law-strip span,
.agent-tags span {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #d6e0e3;
  padding: 6px 8px;
  font-size: 12px;
}

.agent-grid {
  display: grid;
  gap: 10px;
  padding: 12px;
  max-height: calc(100vh - 196px);
  overflow: auto;
}

.agent-tile {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}

.agent-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.agent-head span {
  color: var(--cyan);
  font-size: 12px;
}

.agent-code {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.agent-tile p {
  color: #c8d4d8;
  line-height: 1.45;
  margin: 10px 0;
  font-size: 13px;
}

.agent-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  padding: 12px;
  max-height: calc(100vh - 170px);
  overflow: auto;
}

.asset-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.asset-preview {
  display: grid;
  place-items: center;
  height: 180px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent),
    rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

.asset-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.asset-info {
  display: grid;
  gap: 7px;
  padding: 10px;
}

.asset-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.asset-title span {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

.asset-title strong {
  font-size: 14px;
}

.asset-info p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.asset-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.asset-links a {
  border: 1px solid var(--line);
  color: #dce8ea;
  padding: 4px 6px;
  text-decoration: none;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.04);
}

.asset-links a:hover {
  border-color: var(--line-hot);
}

.forge-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 12px;
}

.forge-command {
  display: grid;
  gap: 8px;
  min-height: 74px;
  padding: 10px;
  text-align: left;
}

.forge-command.primary {
  background: rgba(103, 221, 236, 0.14);
  border-color: rgba(103, 221, 236, 0.55);
}

.forge-command span {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

.forge-command strong {
  font-size: 13px;
}

pre {
  margin: 0;
  padding: 14px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #dce8ea;
  line-height: 1.5;
  font-size: 13px;
}

.stream {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
  list-style: none;
  max-height: 390px;
  overflow: auto;
}

.stream li {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.stream strong {
  color: var(--cyan);
  font-size: 12px;
}

.stream span {
  color: #cbd7da;
  line-height: 1.4;
  font-size: 13px;
}

.stream-name strong {
  color: var(--pink);
}

.candidate-grid {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
  max-height: 360px;
  overflow: auto;
}

.candidate-card,
.empty-state {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.candidate-card {
  display: grid;
  gap: 9px;
  padding: 10px;
}

.candidate-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.candidate-head span,
.candidate-meta span {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

.candidate-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.candidate-card p {
  margin: 0;
  color: #cbd7da;
  line-height: 1.4;
  font-size: 13px;
}

.candidate-meta,
.candidate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.candidate-meta a,
.candidate-actions button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #dce8ea;
  padding: 5px 7px;
  text-decoration: none;
  font-size: 12px;
}

.candidate-actions button {
  cursor: pointer;
}

.candidate-actions button:hover:not(:disabled),
.candidate-meta a:hover {
  border-color: var(--line-hot);
}

.candidate-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.empty-state {
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .system-bar {
    grid-template-columns: 1fr;
    height: auto;
    gap: 8px;
    padding: 10px;
  }

  .system-center {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  #system-clock {
    justify-self: start;
  }

  .dock {
    position: fixed;
    left: 8px;
    top: auto;
    right: 8px;
    bottom: 8px;
    display: flex;
    justify-content: center;
  }

  .desktop {
    padding: 130px 10px 82px;
  }

  .window,
  .world-window,
  .characters-window,
  .factory-window,
  .assets-window,
  .memory-window,
  .octopus-window {
    position: static;
    width: auto;
    max-width: none;
    margin-bottom: 12px;
  }

  .world-body,
  .metric-grid,
  .asset-grid,
  .forge-controls {
    grid-template-columns: 1fr;
  }
}
