:root {
  color-scheme: light dark;
  --bg: #f4f7f8;
  --panel: #fcfdfd;
  --text: #192a36;
  --muted: #536775;
  --accent: #106c75;
  --edge: #435e70;
  --hue-0: 210;
  --hue-1: 150;
  --hue-2: 30;
  --hue-3: 280;
  --hue-4: 0;
  --hue-5: 180;
  --sat: 28%;
  --tag-brief: #427d76;
  --tag-expand: #4264a0;
  --tag-later: #85673b;
  --annot-bg: #fff3cc;
  --annot-text: #614911;
  --danger: #9e3232;
  --rule: color-mix(in srgb, var(--muted) 22%, var(--panel));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121d25;
    --panel: #19252e;
    --text: #e5eef4;
    --muted: #a3b7c4;
    --accent: #75ccd1;
    --edge: #b0c4d2;
    --tag-brief: #84cac0;
    --tag-expand: #a0bafb;
    --tag-later: #d8b47a;
    --annot-bg: #3c311b;
    --annot-text: #f2d991;
    --danger: #ffa39b;
  }
}

* {
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

[hidden] {
  display: none !important;
}

.toolbar,
.field,
.visibility-controls,
.edge-filters,
.edge-labels,
.check {
  display: flex;
  align-items: center;
}

.toolbar {
  z-index: 1;
  flex-wrap: wrap;
  gap: 12px 24px;
  min-height: 64px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}

.brand {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.field {
  gap: 8px;
  color: var(--muted);
}

.visibility-controls,
.edge-filters,
.edge-labels {
  flex-wrap: wrap;
  gap: 8px 16px;
}

.edge-filters {
  min-width: 0;
  padding-inline-start: 18px;
  border-inline-start: 1px solid var(--rule);
}

.edge-filters .field {
  min-width: 0;
}

.edge-filters .field > span {
  flex: none;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--panel);
}

.segmented label {
  position: relative;
  padding: 4px 9px;
  border-radius: 4px 0 0 4px;
  cursor: pointer;
}

.segmented label + label {
  border-inline-start: 1px solid var(--rule);
  border-radius: 0 4px 4px 0;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.segmented label:has(input:checked) {
  background: var(--accent);
  color: var(--panel);
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check {
  gap: 5px;
  color: var(--text);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

select {
  max-width: min(48vw, 300px);
  min-height: 33px;
  padding: 3px 6px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel-layout {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 0;
}

.canvas {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#map-view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

#map-view:active {
  cursor: grabbing;
}

svg:focus {
  outline: none;
}

svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.map-state,
.error-state {
  position: absolute;
  margin: 0;
  padding: 8px 14px;
  color: var(--muted);
}

.map-state {
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.map-location {
  position: absolute;
  inset: 12px 12px auto;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.map-location-hint {
  margin-inline-start: 0.9em;
  font-size: 11px;
}

.error-state {
  inset: auto 14px 14px;
  width: fit-content;
  max-width: calc(100% - 28px);
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  overflow-wrap: anywhere;
}

.node .body {
  fill: color-mix(in srgb, var(--point-fill) var(--point-mix), var(--circle-fill));
  stroke: none;
}

.node.clickable .body {
  cursor: pointer;
}

.node.clickable:not(.selected, .hl):hover .body {
  stroke: var(--node-hover);
}

.node:is(.selected, .hl, .focus-center) .body {
  stroke: var(--accent);
}

.node .tag {
  fill: none;
  pointer-events: none;
}

.edges,
.labels {
  pointer-events: none;
}

.edges path {
  fill: none;
  stroke: var(--edge);
}

.center-label,
.edges text {
  text-anchor: middle;
  dominant-baseline: middle;
}

.center-label {
  fill: var(--text);
  font-weight: 600;
}

.point-label {
  font-weight: 400;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-linejoin: round;
}

.muted-label {
  fill: var(--muted);
}

.arc-label {
  font-weight: 700;
  letter-spacing: 0.08em;
}

.labels .node-credibility {
  fill: var(--text);
}

.labels .node-credibility.explained {
  fill: none;
  stroke: var(--text);
}

.edges text {
  fill: var(--edge);
  stroke: var(--bg);
  stroke-linejoin: round;
  paint-order: stroke;
}

#detail {
  min-width: 0;
  overflow: auto;
  padding: 25px 24px;
  border-inline-start: 1px solid var(--rule);
  background: var(--panel);
  overflow-wrap: anywhere;
}

.detail-placeholder {
  margin: 0;
  color: var(--muted);
}

.breadcrumb {
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 12px;
}

.link-button {
  appearance: none;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

#detail-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.3;
}

.detail-heading,
.review-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-heading > button,
.review-heading > button {
  flex: none;
}

.credibility,
.reading-tag {
  display: inline-block;
  margin: 0 8px 8px 0;
  padding: 2px 8px;
  border: 1px solid var(--muted);
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.5;
}

.reading-tag {
  border-color: var(--tag-color);
}

.tag-brief {
  --tag-color: var(--tag-brief);
}

.tag-expand {
  --tag-color: var(--tag-expand);
}

.tag-later {
  --tag-color: var(--tag-later);
}

.node-content {
  margin: 10px 0 0;
  white-space: pre-wrap;
}

.detail-group {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}

.detail-group h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

.edge-word {
  margin-inline-end: 8px;
  color: var(--muted);
  font-size: 12px;
}

.edge-note {
  display: block;
}

.edge-note,
.chat-summary {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
}

.chat-question {
  font-weight: 600;
}

.chat-star {
  color: var(--muted);
}

.chat-star.starred {
  color: var(--accent);
}

.action-button {
  padding: 4px 9px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.action-button:hover:not(:disabled),
.action-button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.action-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.action-primary,
.action-primary:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--panel);
}

.action-danger,
.action-error,
.review-error {
  color: var(--danger);
}

.chat-actions,
.editor-actions,
.review-actions,
.review-verdicts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-actions {
  margin-top: 6px;
}

.tag-menu {
  position: fixed;
  z-index: 2;
  display: grid;
  gap: 2px;
  min-width: min(140px, calc(100vw - 16px));
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow: auto;
  padding: 5px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--text) 18%, transparent);
}

.tag-option {
  display: flex;
  align-items: center;
  gap: 5px;
  border-color: transparent;
  text-align: start;
}

.tag-check {
  min-width: 1em;
  color: var(--accent);
}

.node-editor,
.form-field,
.review-reason {
  display: grid;
  gap: 5px;
}

.node-editor {
  gap: 12px;
}

.form-field,
.review-reason {
  font-size: 13px;
  color: var(--muted);
}

.form-field > input,
.form-field > textarea,
.review-reason > textarea {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.form-field > textarea,
.review-reason > textarea {
  resize: vertical;
}

.review-heading h2 {
  margin: 0;
  font-size: 20px;
}

.review-cards {
  display: grid;
  gap: 14px;
}

.review-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--rule);
  border-radius: 7px;
}

.review-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
}

.review-meta,
.review-stale,
.review-progress {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.review-stale {
  color: var(--accent);
}

.review-ops {
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.review-op {
  display: grid;
  gap: 7px;
  padding: 10px 0;
  border-top: 1px solid var(--rule);
}

.review-op:last-child {
  border-bottom: 1px solid var(--rule);
}

.review-op-title,
.review-annotation,
.action-error,
.review-error {
  margin: 0;
  white-space: pre-wrap;
}

.review-number {
  color: var(--muted);
}

.review-annotation {
  padding: 5px 7px;
  border-radius: 4px;
  background: var(--annot-bg);
  color: var(--annot-text);
  font-size: 13px;
}

.review-error {
  margin-top: 8px;
}

@media (max-width: 760px) {
  body {
    min-height: 100dvh;
    height: auto;
  }

  .toolbar {
    padding-inline: 14px;
  }

  .edge-filters {
    padding-inline-start: 0;
    border-inline-start: 0;
  }

  .panel-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(320px, 58dvh) auto;
  }

  #detail {
    border-inline-start: 0;
    border-top: 1px solid var(--rule);
  }
}
