:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --paper: #ffffff;
  --ink: #18201c;
  --muted: #667169;
  --soft: #eef1ed;
  --line: #d9dfd8;
  --line-strong: #b9c3ba;
  --green: #2b7a5b;
  --teal: #287d8e;
  --blue: #476fa8;
  --gold: #a46d1d;
  --red: #bd5b4b;
  --violet: #725f9d;
  --shadow: 0 14px 34px rgba(32, 44, 37, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(247, 248, 246, 0) 260px),
    var(--bg);
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(190px, auto) 1fr auto;
  align-items: center;
  gap: 24px;
  min-height: 62px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(217, 223, 216, 0.86);
  background: rgba(247, 248, 246, 0.9);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-weight: 750;
  font-size: 16px;
  letter-spacing: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 1px solid #2b7a5b;
  border-radius: 7px;
  background:
    linear-gradient(90deg, transparent 48%, rgba(43, 122, 91, 0.22) 48% 52%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(43, 122, 91, 0.22) 48% 52%, transparent 52%),
    #f8fbf8;
  box-shadow: inset 0 0 0 5px rgba(43, 122, 91, 0.08);
}

.topbar nav {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.topbar nav a,
.icon-button,
.filter-button {
  min-height: 34px;
  border-radius: 7px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
}

.topbar nav a {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
}

.topbar nav a:hover,
.icon-button:hover,
.filter-button:hover {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  padding: 0;
  cursor: pointer;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  display: grid;
  grid-template-columns: 210px minmax(440px, 1fr) minmax(300px, 420px);
  gap: 18px;
  min-height: calc(100vh - 62px);
  padding: 18px;
}

.control-rail,
.map-panel,
.reader-panel,
.lower-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow);
}

.control-rail {
  align-self: start;
  position: sticky;
  top: 80px;
  display: grid;
  gap: 18px;
  padding: 16px;
}

.control-rail section {
  display: grid;
  gap: 10px;
}

h1,
h2,
p {
  margin: 0;
}

.control-rail h2,
.lower-panel h2 {
  font-size: 12px;
  line-height: 1.25;
  font-weight: 760;
  color: #38443d;
}

.filter-stack {
  display: grid;
  gap: 6px;
}

.filter-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 9px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.25;
}

.filter-button.active {
  border-color: rgba(43, 122, 91, 0.35);
  color: var(--ink);
  background: rgba(43, 122, 91, 0.09);
}

.filter-count {
  color: var(--muted);
  font-size: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.switch-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.map-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  gap: 12px;
  padding: 16px;
}

.panel-heading {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 340px);
  align-items: start;
  gap: 16px;
}

.panel-heading h1 {
  font-size: clamp(23px, 2.7vw, 34px);
  line-height: 1.05;
  font-weight: 820;
  letter-spacing: 0;
}

.panel-heading p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.search-box {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.search-box svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.map-canvas-wrap {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(217, 223, 216, 0.45) 1px, transparent 1px),
    linear-gradient(0deg, rgba(217, 223, 216, 0.45) 1px, transparent 1px),
    radial-gradient(circle at 58% 44%, rgba(40, 125, 142, 0.09), transparent 34%),
    #fbfcfb;
  background-size: 46px 46px, 46px 46px, auto, auto;
}

#essayMap {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.node {
  cursor: pointer;
  stroke: #fff;
  stroke-width: 1.2;
  transition: opacity 0.18s ease, r 0.18s ease;
}

.node.dimmed {
  opacity: 0.22;
}

.node.selected {
  stroke: #18201c;
  stroke-width: 2.2;
}

.axis-label {
  fill: #69756d;
  font-size: 11px;
  font-weight: 650;
}

.cluster-label {
  fill: rgba(24, 32, 28, 0.56);
  font-size: 12px;
  font-weight: 720;
}

.word-cloud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 8px 13px;
  padding: 42px;
  background: rgba(251, 252, 251, 0.91);
  pointer-events: none;
}

.word-cloud span {
  color: rgba(24, 32, 28, 0.72);
  font-weight: 760;
  line-height: 1;
}

.theme-river {
  display: grid;
  gap: 8px;
}

.river-row {
  display: grid;
  grid-template-columns: 72px 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.river-bar {
  display: flex;
  height: 18px;
  overflow: hidden;
  border: 1px solid rgba(217, 223, 216, 0.7);
  border-radius: 5px;
  background: var(--soft);
}

.river-seg {
  min-width: 1px;
}

.reader-panel {
  min-width: 0;
  overflow: hidden;
  align-self: stretch;
}

.reader-empty,
.essay-article {
  padding: 18px;
}

.reader-empty {
  display: grid;
  align-content: center;
  min-height: 360px;
  gap: 10px;
  color: var(--muted);
}

.reader-empty h2,
.essay-article h2 {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}

.reader-empty p,
.lower-panel p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.article-meta span,
.tag-row span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fbfcfb;
  font-size: 12px;
  font-weight: 650;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.structure-bars {
  display: grid;
  gap: 8px;
  margin: 14px 0 16px;
}

.structure-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.structure-track {
  height: 7px;
  overflow: hidden;
  border-radius: 5px;
  background: var(--soft);
}

.structure-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.essay-text {
  max-height: calc(100vh - 285px);
  overflow: auto;
  padding-right: 6px;
  font-size: 14px;
  line-height: 1.86;
  color: #26312a;
}

.essay-text p {
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.essay-text .essay-heading {
  margin: 18px 0 8px;
  font-size: 15px;
  line-height: 1.45;
  font-weight: 780;
  color: var(--ink);
}

.lower-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
  padding: 0 18px 18px;
}

.lower-panel {
  padding: 16px;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.legend-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #39453e;
  background: #fbfcfb;
  font-size: 12px;
  font-weight: 650;
}

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

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

  .reader-panel {
    grid-column: 1 / -1;
  }

  .essay-text {
    max-height: 520px;
  }
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    padding: 0 14px;
  }

  .topbar nav {
    display: none;
  }

  .app-shell,
  .lower-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .control-rail {
    position: static;
    grid-template-columns: 1fr;
  }

  .panel-heading {
    grid-template-columns: 1fr;
  }

  .map-panel {
    min-width: 0;
  }

  .legend-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .brand {
    font-size: 14px;
  }

  .brand-mark {
    width: 24px;
    height: 24px;
  }

  .panel-heading h1 {
    font-size: 24px;
  }

  .control-rail,
  .map-panel,
  .reader-panel,
  .lower-panel {
    border-radius: 7px;
  }

  .legend-grid {
    grid-template-columns: 1fr;
  }
}
