:root {
  --bg: #06090d;
  --panel: rgba(12, 18, 25, 0.82);
  --panel-strong: rgba(18, 27, 36, 0.94);
  --line: rgba(180, 208, 220, 0.72);
  --line-active: rgba(222, 190, 104, 0.96);
  --text: #edf5f7;
  --muted: #91a6ad;
  --accent: #62c7d8;
  --gold: #d9b45f;
  --danger: #e06b6b;
  --node-w: 260px;
  --node-h: 220px;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(80, 95, 100, 0.32), transparent 36%),
    linear-gradient(120deg, rgba(9, 22, 31, 0.92), rgba(3, 5, 8, 0.98)),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  height: 34px;
  border: 1px solid rgba(129, 170, 181, 0.34);
  color: var(--text);
  background: linear-gradient(180deg, rgba(29, 45, 54, 0.92), rgba(13, 20, 27, 0.92));
  cursor: pointer;
}

button:hover {
  border-color: rgba(216, 190, 108, 0.62);
  color: #fff8dc;
}

.topbar {
  position: relative;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(132, 176, 187, 0.22);
  background: rgba(5, 10, 15, 0.88);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(101, 215, 230, 0.7);
  background:
    linear-gradient(90deg, rgba(71, 205, 221, 0.8), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0));
  box-shadow: 0 0 20px rgba(65, 202, 218, 0.18);
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.toolbar button {
  padding: 0 12px;
}

.readonly-tools {
  display: none;
}

.workspace {
  height: calc(100% - 64px);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.side-panel {
  position: relative;
  z-index: 12;
  padding: 16px;
  border-right: 1px solid rgba(132, 176, 187, 0.2);
  background: var(--panel);
  backdrop-filter: blur(16px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(91, 126, 137, 0.65) rgba(3, 8, 12, 0.82);
}

.side-panel::-webkit-scrollbar {
  width: 9px;
}

.side-panel::-webkit-scrollbar-track {
  background: rgba(3, 8, 12, 0.82);
}

.side-panel::-webkit-scrollbar-thumb {
  border: 2px solid rgba(3, 8, 12, 0.82);
  background: rgba(91, 126, 137, 0.7);
}

.side-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(130, 172, 184, 0.82);
}

.panel-section {
  margin-bottom: 18px;
}

.panel-title,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: #c9dce0;
  font-size: 13px;
  font-weight: 700;
}

.text-input,
.editor-dialog input,
.editor-dialog textarea {
  width: 100%;
  border: 1px solid rgba(118, 157, 169, 0.36);
  color: var(--text);
  background: rgba(4, 9, 14, 0.78);
  outline: none;
}

.text-input,
.editor-dialog input {
  height: 36px;
  padding: 0 10px;
}

.editor-dialog textarea {
  resize: vertical;
  padding: 10px;
}

.node-list {
  display: grid;
  gap: 10px;
}

.node-list-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(118, 157, 169, 0.22);
  background: rgba(8, 14, 20, 0.7);
}

.node-list-item.active {
  border-color: rgba(217, 180, 95, 0.75);
  background: rgba(42, 33, 16, 0.62);
}

.node-list-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  gap: 8px;
}

.node-list-title {
  width: 100%;
  padding: 0;
  border: 0;
  color: #eef9fb;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-list-toggle {
  width: 28px;
  height: 26px;
  padding: 0;
  border: 1px solid rgba(118, 157, 169, 0.3);
  color: #cfe7eb;
  background: rgba(3, 8, 12, 0.72);
  font-size: 16px;
  line-height: 1;
}

.node-list-toggle:hover {
  border-color: rgba(217, 180, 95, 0.65);
  color: #ffe4a1;
}

.node-list-fields {
  display: grid;
  gap: 6px;
}

.node-list-input,
.node-list-textarea {
  width: 100%;
  border: 1px solid rgba(118, 157, 169, 0.26);
  color: #dcebed;
  background: rgba(3, 8, 12, 0.72);
  outline: none;
  font-size: 12px;
}

.node-list-input {
  height: 28px;
  padding: 0 8px;
}

.node-list-textarea {
  min-height: 58px;
  max-height: 120px;
  padding: 7px 8px;
  resize: vertical;
  line-height: 1.45;
}

.node-list-input:focus,
.node-list-textarea:focus {
  border-color: rgba(217, 180, 95, 0.7);
}

.node-list-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

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

.chapter-tabs {
  position: absolute;
  left: 14px;
  top: 12px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 190px);
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(91, 126, 137, 0.65) rgba(3, 8, 12, 0.6);
}

.chapter-tabs::-webkit-scrollbar {
  height: 7px;
}

.chapter-tabs::-webkit-scrollbar-track {
  background: rgba(3, 8, 12, 0.6);
}

.chapter-tabs::-webkit-scrollbar-thumb {
  background: rgba(91, 126, 137, 0.7);
}

.chapter-tab {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(129, 170, 181, 0.32);
  color: #c9dce0;
  background: rgba(4, 9, 14, 0.74);
}

.chapter-tab.active {
  border-color: rgba(217, 180, 95, 0.82);
  color: #fff1bf;
  background: rgba(42, 33, 16, 0.72);
}

.canvas-status {
  position: absolute;
  right: 14px;
  top: 12px;
  z-index: 14;
  display: flex;
  gap: 8px;
}

.canvas-status span,
.canvas-status button {
  padding: 5px 9px;
  border: 1px solid rgba(130, 172, 184, 0.24);
  color: #bdd0d5;
  font-size: 12px;
  background: rgba(4, 9, 14, 0.7);
}

.canvas-status button {
  height: auto;
  cursor: pointer;
}

.canvas-status button:hover {
  border-color: rgba(217, 180, 95, 0.65);
  color: #fff1bf;
}

.canvas {
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  background:
    linear-gradient(rgba(120, 165, 176, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 165, 176, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 16% 45%, rgba(133, 150, 132, 0.1), transparent 22%),
    radial-gradient(circle at 66% 42%, rgba(68, 111, 132, 0.12), transparent 24%),
    linear-gradient(120deg, rgba(10, 23, 31, 0.92), rgba(2, 5, 8, 0.96));
  background-size:
    48px 48px,
    48px 48px,
    auto,
    auto,
    auto;
}

.canvas::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(205, 223, 224, 0.08) 42%, transparent 66%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 12px);
  opacity: 0.75;
}

.canvas.panning {
  cursor: grabbing;
}

.world {
  position: absolute;
  left: 0;
  top: 0;
  width: 5000px;
  height: 3000px;
  transform-origin: 0 0;
}

.edge-layer,
.node-layer {
  position: absolute;
  inset: 0;
}

.edge-layer {
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}

.node-layer {
  pointer-events: none;
  z-index: 2;
}

.edge-path {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
  pointer-events: none;
  filter: drop-shadow(0 0 5px rgba(130, 200, 218, 0.22));
}

.edge-arrow {
  fill: rgba(180, 208, 220, 0.92);
  pointer-events: none;
  filter: drop-shadow(0 0 5px rgba(130, 200, 218, 0.25));
}

.edge-hit {
  fill: none;
  stroke: rgba(255, 255, 255, 0.01);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 42;
  pointer-events: stroke;
  cursor: default;
}

.edge-label {
  pointer-events: auto;
  cursor: pointer;
}

.edge-label rect {
  fill: rgba(7, 13, 18, 0.92);
  stroke: rgba(122, 166, 178, 0.42);
}

.edge-label text {
  fill: #e6eff0;
  font-size: 12px;
}

.edge-bend {
  fill: rgba(217, 180, 95, 0.96);
  stroke: rgba(255, 245, 201, 0.96);
  stroke-width: 2;
  pointer-events: auto;
  cursor: move;
  filter: drop-shadow(0 0 8px rgba(217, 180, 95, 0.45));
}

.edge-bend:hover {
  fill: rgba(255, 238, 160, 1);
  stroke: #fff;
}

.node {
  position: absolute;
  pointer-events: auto;
  width: var(--node-w);
  min-height: var(--node-h);
  border: 1px solid rgba(104, 210, 226, 0.52);
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(30, 187, 206, 0.65) 0 16px, transparent 16px),
    linear-gradient(180deg, rgba(33, 47, 56, 0.9), rgba(7, 11, 16, 0.92));
  box-shadow:
    0 16px 32px rgba(0, 0, 0, 0.45),
    inset 0 1px rgba(255, 255, 255, 0.12);
  user-select: none;
}

.node.selected {
  border-color: rgba(224, 190, 101, 0.9);
  box-shadow:
    0 0 0 1px rgba(224, 190, 101, 0.32),
    0 18px 38px rgba(0, 0, 0, 0.5),
    0 0 26px rgba(224, 190, 101, 0.12);
}

.node-header {
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 8px 0 24px;
  color: #d7f6fa;
  font-size: 24px;
  font-weight: 700;
  background: rgba(5, 11, 15, 0.5);
  border-bottom: 1px solid rgba(124, 170, 183, 0.18);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-image {
  margin: 8px 8px 0 24px;
  aspect-ratio: 1334 / 750;
  border: 1px solid rgba(157, 190, 198, 0.25);
  background:
    linear-gradient(120deg, rgba(20, 30, 36, 0.92), rgba(3, 6, 9, 0.96)),
    radial-gradient(circle at 35% 40%, rgba(220, 230, 220, 0.2), transparent 34%);
  overflow: hidden;
}

.node-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.node-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: rgba(229, 241, 242, 0.58);
  font-size: 12px;
}

.node-body {
  padding: 8px 8px 10px 24px;
}

.node-desc {
  min-height: 34px;
  color: #c9d8dc;
  font-size: 12px;
  line-height: 1.45;
}

.node-note {
  margin-top: 7px;
  color: var(--gold);
  font-size: 12px;
}

.port {
  position: absolute;
  top: 108px;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(226, 245, 247, 0.9);
  background: #0b1820;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(101, 205, 222, 0.44);
  cursor: crosshair;
}

.port.input {
  left: -8px;
}

.port.output {
  right: -8px;
}

.context-menu {
  position: fixed;
  z-index: 60;
  min-width: 170px;
  padding: 6px;
  border: 1px solid rgba(126, 169, 181, 0.38);
  background: rgba(7, 12, 17, 0.96);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.46);
}

.context-menu button {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  text-align: left;
  background: transparent;
}

.context-menu button:hover {
  background: rgba(45, 77, 88, 0.72);
}

.context-menu .danger {
  color: #ffb3b3;
}

.hidden {
  display: none !important;
}

.editor-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid rgba(132, 176, 187, 0.38);
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
}

.small-dialog {
  width: min(360px, calc(100vw - 32px));
}

.editor-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.editor-dialog h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.editor-dialog label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: #c9dce0;
  font-size: 13px;
  font-weight: 700;
}

.image-preview {
  height: 110px;
  margin-bottom: 16px;
  border: 1px solid rgba(118, 157, 169, 0.28);
  background: rgba(4, 9, 14, 0.6);
  overflow: hidden;
}

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

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions button {
  min-width: 86px;
}

body.readonly .side-panel,
body.readonly #editorToolbar {
  display: none;
}

body.readonly .readonly-tools {
  display: flex;
}

body.readonly .workspace {
  grid-template-columns: minmax(0, 1fr);
}

body.readonly .node,
body.readonly .edge-hit,
body.readonly .edge-label {
  cursor: default;
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .workspace {
    height: calc(100% - 112px);
    grid-template-columns: 1fr;
  }

  .side-panel {
    display: none;
  }
}
