:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef1ed;
  --text: #202321;
  --muted: #606660;
  --line: #d9ded7;
  --line-strong: #aeb8ad;
  --accent: #276b5d;
  --accent-2: #9b5d1d;
  --red: #9d3f3f;
  --blue: #355f8c;
  --yellow: #b38a1f;
  --shadow: 0 14px 34px rgba(23, 31, 27, 0.10);
  font-family: Aptos, Satoshi, Geist, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.topbar {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.72) inset;
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 22px;
  line-height: 1.1;
  font-weight: 720;
  letter-spacing: 0;
}

.eyebrow,
.norm-status span,
.stats small,
.visible-meta,
.node-type {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 5px;
}

.norm-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 270px;
}

.norm-status strong {
  font-size: 14px;
  line-height: 1.25;
}

.app-shell {
  height: calc(100dvh - 78px);
  display: grid;
  grid-template-columns: 320px minmax(520px, 1fr) 380px;
}

.panel {
  background: var(--surface);
  min-height: 0;
  overflow: auto;
}

.controls {
  border-right: 1px solid var(--line);
  padding: 18px;
}

.inspector {
  border-left: 1px solid var(--line);
  padding: 18px;
}

label {
  display: block;
  margin: 16px 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

input,
select,
button {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #fbfcfa;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(39, 107, 93, 0.25);
  border-color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

button {
  height: 38px;
  cursor: pointer;
  font-weight: 680;
}

button:hover {
  background: var(--surface-2);
}

button:active {
  transform: translateY(1px);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0;
}

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.stats span {
  display: block;
  font-size: 24px;
  font-weight: 760;
  line-height: 1;
  margin-bottom: 5px;
}

.source-note,
.detail-section,
.results,
.use-cases,
.bibliography,
.glossary {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.source-note h2,
.inspector h2,
.detail-panel h2 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.25;
}

.source-note p,
.detail-panel p,
.empty-detail,
.source-item,
.use-cases .glossary-item,
.glossary-item {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0 0 10px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #f9faf7;
}

.workspace-bar {
  min-height: 58px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
}

.workspace-bar > div:first-child {
  min-width: 0;
}

.workspace-bar p {
  margin: 0;
  font-size: 15px;
  line-height: 1.18;
  font-weight: 760;
}

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

.workspace-bar small {
  display: block;
  max-width: 620px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

#graphStage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background: #f9faf7;
}

#graphCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#graphCanvas:active {
  cursor: grabbing;
}

#labelLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.graph-label {
  position: absolute;
  max-width: 240px;
  padding: 5px 8px;
  color: #202321;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(174, 184, 173, 0.7);
  border-radius: 7px;
  box-shadow: 0 4px 12px rgba(23, 31, 27, 0.09);
  font-size: 11px;
  line-height: 1.2;
  opacity: 0;
  white-space: normal;
  overflow: hidden;
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 140ms ease, transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  transform: translate(-50%, -50%);
}

.graph-label.selected {
  border-color: #202321;
  font-weight: 700;
  opacity: 1;
}

.graph-label.visible {
  opacity: 1;
}

.graph-label.hovered {
  z-index: 4;
  border-color: var(--accent);
  box-shadow: 0 10px 26px rgba(23, 31, 27, 0.16);
  opacity: 1;
}

.attractor-label {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(39, 107, 93, 0.34);
  box-shadow: 0 8px 20px rgba(23, 31, 27, 0.12);
}

.hover-tooltip {
  position: absolute;
  z-index: 8;
  max-width: 260px;
  padding: 7px 9px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(174, 184, 173, 0.85);
  border-radius: 7px;
  box-shadow: 0 10px 24px rgba(23, 31, 27, 0.14);
  font-size: 11px;
  line-height: 1.25;
  pointer-events: none;
  opacity: 0;
  transform: translate(12px, 12px);
  transition: opacity 100ms ease, transform 100ms ease;
}

.hover-tooltip.visible {
  opacity: 1;
}

.label-title {
  display: block;
  font-weight: 700;
  line-height: 1.22;
}

.label-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}

#interactionState {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: min(460px, calc(100% - 28px));
  padding: 8px 10px;
  color: #404640;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.detail-title {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.18;
  letter-spacing: 0;
}

.node-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfa;
  margin-bottom: 12px;
}

.kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.35;
}

.kv b {
  color: var(--muted);
  font-weight: 650;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #fbfcfa;
  font-size: 12px;
  line-height: 1.2;
}

.result-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.result-row:hover {
  background: transparent;
}

.result-row strong {
  font-size: 13px;
  line-height: 1.25;
  font-weight: 680;
}

.result-row span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.source-item,
.glossary-item {
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.source-item:first-child,
.glossary-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.source-item strong,
.glossary-item strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 4px;
}

.source-item a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 286px minmax(420px, 1fr) 330px;
  }
}

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

  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 14px 16px;
  }

  .norm-status {
    min-width: 0;
  }

  .app-shell {
    height: auto;
    min-height: calc(100dvh - 76px);
    grid-template-columns: 1fr;
  }

  .controls,
  .inspector {
    border: 0;
  }

  .workspace {
    order: -1;
    height: 72dvh;
    min-height: 520px;
  }
}

@media (max-width: 620px) {
  .topbar {
    flex-direction: column;
    gap: 10px;
  }

  .norm-status {
    align-items: flex-start;
  }

  .workspace-bar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    padding: 10px 14px;
    flex-direction: column;
  }

  .workspace {
    grid-template-rows: auto 1fr;
    height: 74dvh;
  }

  .legend {
    justify-content: flex-start;
  }

  .graph-label {
    max-width: 150px;
  }
}
