:root {
  color-scheme: light;
  --ink: #18201f;
  --muted: #5f6e6b;
  --soft: #eef2ed;
  --panel: #fbfcf8;
  --line: #d7dfd8;
  --accent: #167c80;
  --accent-2: #b65d2e;
  --warn: #8f6b12;
  --shadow: rgba(24, 32, 31, 0.12);
  --font:
    "Satoshi", "Geist", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #f5f7f1;
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.brain-shell {
  height: 100svh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 248, 0.94);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(22, 124, 128, 0.24);
  border-radius: 50%;
  overflow: hidden;
  background: #061021;
  box-shadow: 0 8px 22px rgba(24, 32, 31, 0.12);
  flex: 0 0 auto;
}

.home-link img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

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

.brand h1 {
  font-size: clamp(22px, 2.4vw, 31px);
  line-height: 1.15;
  font-weight: 820;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.view-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-right {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: min(640px, 100%);
}

.site-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.wiki-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 780;
  white-space: nowrap;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    color 0.18s ease;
}

.wiki-switch:hover,
.wiki-switch:focus-visible {
  border-color: var(--accent);
  background: var(--accent);
  outline: none;
}

.wiki-switch svg {
  width: 16px;
  height: 16px;
  display: block;
}

.invite-status {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  z-index: 20;
}

.invite-status summary {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  padding: 0 9px;
}

.invite-status summary::-webkit-details-marker {
  display: none;
}

.invite-status-icon {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  flex: 0 0 auto;
}

.invite-status summary > span:nth-child(2) {
  font-size: 13px;
  font-weight: 780;
  white-space: nowrap;
}

.invite-status summary strong {
  border-radius: 999px;
  background: rgba(22, 124, 128, 0.1);
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  padding: 3px 7px;
  white-space: nowrap;
}

.invite-status-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(328px, calc(100vw - 28px));
  border: 1px solid rgba(24, 32, 31, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 46px rgba(24, 32, 31, 0.16);
  padding: 12px;
}

.invite-status dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.invite-status dl > div {
  display: grid;
  grid-template-columns: minmax(92px, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
  align-items: baseline;
}

.invite-status dd {
  font-weight: 700;
}

.invite-status-limit {
  color: var(--muted);
  font-weight: 500;
}

.invite-status-professional-note {
  margin-top: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.invite-status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.invite-status-refresh {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 760;
}

.invite-status-actions a {
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
  text-decoration: none;
}

.segmented,
.icon-button,
.color-mode-button,
.clear-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    color 0.18s ease;
}

.segmented.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.color-mode-button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.icon-button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr) 328px;
}

.left-rail,
.detail-panel {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}

.left-rail {
  border-right: 1px solid var(--line);
  padding: 18px 16px 22px;
}

.detail-panel {
  border-left: 1px solid var(--line);
  padding: 18px 16px 22px;
}

.canvas-panel {
  min-height: 0;
  position: relative;
  background:
    linear-gradient(rgba(24, 32, 31, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 32, 31, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 12% 18%, rgba(22, 124, 128, 0.055), transparent 28%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.82), rgba(239, 243, 237, 0.92)), #f7f8f3;
  background-size:
    28px 28px,
    28px 28px,
    auto,
    auto,
    auto;
}

.canvas-controls {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 7px;
  border: 1px solid rgba(24, 32, 31, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 14px 34px rgba(24, 32, 31, 0.1);
  backdrop-filter: blur(12px);
}

.canvas-controls[hidden] {
  display: none;
}

.canvas-controls .icon-button {
  width: auto;
  min-width: 54px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 760;
}

.canvas-controls .icon-button span:first-child {
  font-size: 15px;
  line-height: 1;
}

.speed-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 5px 0 8px;
  border-left: 1px solid rgba(24, 32, 31, 0.1);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.speed-control input {
  width: 104px;
  accent-color: var(--accent);
  cursor: pointer;
}

.speed-control output {
  min-width: 32px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.control-divider {
  width: 1px;
  height: 22px;
  background: rgba(24, 32, 31, 0.14);
}

#brainCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.search-wrap {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  height: 38px;
  padding: 0 11px;
  outline: none;
}

.search-wrap input:focus {
  border-color: rgba(22, 124, 128, 0.62);
  box-shadow: 0 0 0 3px rgba(22, 124, 128, 0.12);
}

.filter-group,
.legend-block {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.filter-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  margin-bottom: 8px;
}

.filter-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  margin: 10px 0;
}

.node-toggle,
.label-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.node-type-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.node-type-label > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-glyph {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  color: #4f5b66;
  display: block;
  overflow: visible;
}

.filter-option input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.label-toggle {
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
}

.label-toggle input {
  accent-color: var(--accent-2);
}

.layer-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  margin-bottom: 8px;
}

.layer-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  margin: 10px 0;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.layer-toggle span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.layer-option .info-badge {
  flex: 0 0 auto;
}

.legend-block h2 {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 850;
  margin-bottom: 12px;
}

.legend-list {
  display: grid;
  gap: 9px;
}

.legend-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 8px;
  color: #2f3a38;
  font-size: 12px;
  line-height: 1.35;
}

.legend-item .swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(24, 32, 31, 0.14);
}

.info-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(24, 32, 31, 0.22);
  border-radius: 50%;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.82);
  font-size: 10px;
  font-weight: 850;
  line-height: 1;
  cursor: help;
  outline: none;
}

.info-badge:hover,
.info-badge:focus-visible {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.legend-floating-tooltip {
  position: fixed;
  z-index: 50;
  width: min(260px, 72vw);
  padding: 9px 10px;
  border: 1px solid rgba(24, 32, 31, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  color: #26312f;
  box-shadow: 0 14px 34px rgba(24, 32, 31, 0.16);
  font-size: 12px;
  font-weight: 520;
  line-height: 1.55;
  pointer-events: none;
}

.legend-list.compact {
  gap: 7px;
}

.color-mode-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.color-mode-button {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 760;
}

.hud {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}

.hud span {
  border: 1px solid rgba(24, 32, 31, 0.12);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  padding: 7px 10px;
  color: #33413f;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(24, 32, 31, 0.08);
}

.tooltip {
  position: absolute;
  transform: translate(12px, 12px);
  z-index: 5;
  max-width: 280px;
  border: 1px solid rgba(24, 32, 31, 0.14);
  background: rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  box-shadow: 0 16px 40px var(--shadow);
  padding: 10px 12px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}

.tooltip strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.detail-empty,
.detail-card {
  color: var(--muted);
}

.detail-empty {
  padding: 4px 2px;
}

.detail-empty h2,
.detail-card h2 {
  color: var(--ink);
  font-size: 21px;
  line-height: 1.22;
  margin-bottom: 10px;
}

.detail-empty p,
.detail-summary {
  font-size: 13px;
  line-height: 1.75;
}

.detail-card {
  position: relative;
}

.clear-button {
  float: right;
  height: 30px;
  min-height: 30px;
  padding: 0 10px;
  color: var(--muted);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
}

.classification-summary {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 10px;
}

.classification-summary h3 {
  color: var(--ink);
  font-size: 12px;
  margin-bottom: 6px;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0 20px;
}

.meta-grid div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  min-width: 0;
}

dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 5px;
}

dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 15px;
  margin-top: 16px;
}

.detail-section h3 {
  color: var(--ink);
  font-size: 13px;
  margin-bottom: 9px;
}

.detail-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 9px;
}

.detail-section li {
  color: #33413f;
  font-size: 12px;
  line-height: 1.55;
}

.data-source-row {
  border: 1px solid rgba(24, 32, 31, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  padding: 9px;
}

.data-source-row.primary {
  border-color: rgba(22, 124, 128, 0.26);
  background: rgba(22, 124, 128, 0.06);
}

.data-source-row p {
  margin-top: 4px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.detail-section a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 720;
  overflow-wrap: anywhere;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(24, 32, 31, 0.12);
  border-radius: 999px;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
  color: #33413f;
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.chip.role {
  border-color: rgba(22, 124, 128, 0.24);
  color: var(--accent);
  font-weight: 780;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 248px minmax(0, 1fr);
    grid-template-rows: minmax(520px, 1fr) auto;
  }

  .detail-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 42svh;
  }
}

@media (max-width: 760px) {
  .brain-shell {
    height: auto;
    overflow: visible;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 68svh auto;
  }

  .left-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .filter-group,
  .legend-block {
    margin-top: 16px;
    padding-top: 14px;
  }

  .color-mode-control {
    grid-template-columns: 1fr;
  }

  .view-controls {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    justify-content: stretch;
  }

  .topbar-right {
    width: 100%;
    justify-items: stretch;
  }

  .site-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    justify-content: flex-start;
  }

  .wiki-switch,
  .invite-status {
    width: 100%;
  }

  .invite-status summary {
    justify-content: space-between;
  }

  .invite-status-panel {
    position: static;
    width: 100%;
    margin-top: 8px;
  }

  .canvas-controls {
    top: 10px;
    gap: 6px;
  }

  .speed-control {
    order: 6;
    flex-basis: 100%;
    justify-content: center;
    border-left: 0;
    padding: 2px 4px 0;
  }

  .speed-control input {
    width: min(150px, 42vw);
  }

  .segmented {
    flex: 1 1 auto;
  }
}
