:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede5;
  --ink: #1d2522;
  --muted: #62706a;
  --line: #d8d3c6;
  --accent: #1f6f5b;
  --accent-2: #9a4f2a;
  --accent-3: #3b5f9a;
  --danger: #aa2f35;
  --shadow: 0 16px 40px rgba(46, 42, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.icon-button {
  width: 48px;
  height: 40px;
  font-weight: 800;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: rgba(246, 244, 239, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.topbar h1,
.summary-band h2,
.panel h2,
.agent-detail h3,
.institution-node h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.topbar-actions,
.button-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 20px;
  padding: 20px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 92px;
}

.workspace {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.panel,
.summary-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel.tight {
  padding: 16px;
}

.summary-band {
  display: grid;
  grid-template-columns: 1.3fr minmax(260px, 0.7fr);
  gap: 20px;
  padding: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-band p {
  max-width: 820px;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: grid;
  gap: 12px;
}

.control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  color: var(--muted);
  font-size: 13px;
}

.control input {
  grid-column: 1 / -1;
  min-width: 0;
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

.control input[type="range"] {
  padding: 0;
}

.control-value {
  color: var(--ink);
}

.button-row {
  margin-top: 16px;
}

.button-row button {
  flex: 1;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 72px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.tag,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e7f0eb;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.tag.muted {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.timeline,
.event-list {
  display: grid;
  gap: 10px;
  max-height: 640px;
  overflow: auto;
  padding-right: 4px;
}

.timeline-row,
.event-card,
.institution-node,
.agent-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.timeline-row {
  padding: 12px;
}

.timeline-row.is-emergent {
  border-color: rgba(31, 111, 91, 0.5);
  background: #f2faf6;
}

.timeline-row p,
.event-card p,
.institution-node p,
.agent-detail p {
  color: var(--muted);
  line-height: 1.55;
}

.round {
  color: var(--accent-3);
  font-weight: 800;
}

.event-card {
  padding: 14px;
}

.event-card ul,
.memory-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.agent-card {
  display: grid;
  gap: 4px;
  min-height: 88px;
  padding: 12px;
  text-align: left;
}

.agent-card.selected {
  border-color: var(--accent);
  background: #edf7f2;
}

.agent-card span,
.agent-card small {
  color: var(--muted);
}

.detail-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

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

.resource-grid div {
  padding: 10px;
  background: var(--surface-2);
  border-radius: 8px;
}

.resource-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.institution-map {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.institution-node {
  padding: 14px;
}

.report-output {
  max-height: 680px;
  overflow: auto;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161d1a;
  color: #edf7f2;
  white-space: pre-wrap;
  line-height: 1.55;
}

@media (max-width: 1080px) {
  .layout,
  .summary-band,
  .grid-two {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar,
  .layout {
    padding: 14px;
  }

  .topbar {
    align-items: start;
  }

  .topbar h1 {
    font-size: 23px;
  }

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