:root {
  --bg: #eef2f7;
  --panel: #fbfdff;
  --line: #d6dfec;
  --text: #162033;
  --muted: #5e6b82;
  --accent: #0f6a7b;
  --accent-soft: #e5f3f7;
  --error: #b91c1c;
  --shadow: 0 14px 36px rgba(20, 38, 67, 0.08);
  --flow-line: #7187b8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(1000px 500px at 95% -5%, #dfe9ff 0%, transparent 58%),
    radial-gradient(900px 420px at -10% 100%, #d6ede6 0%, transparent 55%),
    var(--bg);
  color: var(--text);
}

body.canvas-fullscreen-active {
  overflow: hidden;
}

.app {
  max-width: 1220px;
  margin: 0 auto;
  padding: 28px 18px 40px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.app-header h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0.2px;
  text-align: center;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(2px);
}

label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: left;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 14px;
  font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #0f172a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.input-panel textarea {
  display: block;
  width: min(100%, 980px);
  height: 280px;
  min-height: 280px;
  margin-inline: auto;
}

.input-panel label,
.input-panel .actions,
.input-panel .error {
  max-width: 980px;
  margin-inline: auto;
}

.input-panel label {
  text-align: center;
}

.actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  border: none;
  border-radius: 10px;
  padding: 8px 13px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #1f7d90 0%, #136a7b 100%);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  box-shadow: 0 4px 12px rgba(19, 106, 123, 0.2);
}

button.ghost {
  background: #edf2fa;
  color: #253552;
  box-shadow: none;
  border: 1px solid #d5deed;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.error {
  margin: 8px 0 0;
  color: var(--error);
  min-height: 20px;
  text-align: left;
}

.panel-title-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.panel-title-row h2 {
  margin: 0 0 10px;
  font-size: 21px;
  letter-spacing: 0.2px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.zoom-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 12px;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid #d8e1ef;
  border-radius: 12px;
  background: #f7faff;
}

.zoom-btn {
  min-width: 46px;
  padding: 6px 11px;
}

.zoom-toolbar .ghost {
  background: #eef2fa;
  color: #2e3f62;
}

.view-switch {
  display: inline-flex;
  border: 1px solid #c6d1e7;
  border-radius: 10px;
  overflow: hidden;
  background: #edf2fb;
}

.view-btn {
  border-radius: 0;
  min-width: 76px;
  background: transparent;
  color: #33435f;
  box-shadow: none;
}

.view-btn.active,
.filter-btn.active {
  background: #1f4f8c;
  color: #fff;
  box-shadow: 0 4px 12px rgba(31, 79, 140, 0.24);
  border-color: #1f4f8c;
}

#zoomRange {
  width: 190px;
}

.zoom-label {
  min-width: 52px;
  font-weight: 700;
  color: #344467;
}

.tree-root {
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(90deg, rgba(28, 53, 96, 0.03) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(0deg, rgba(28, 53, 96, 0.03) 1px, transparent 1px) 0 0 / 22px 22px,
    #f9fbff;
  padding: 16px;
  min-height: 520px;
  overflow: auto;
  cursor: grab;
}

.tree-panel {
  display: flex;
  flex-direction: column;
  min-height: 620px;
}

.tree-panel .tree-canvas-wrap {
  flex: 1;
}

.tree-canvas-wrap {
  position: relative;
  min-height: 0;
}

.canvas-fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid #c6d1e7;
  background: #ffffff;
  color: #1f3f74;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}

.canvas-fullscreen-btn.active {
  background: #2b4b87;
  color: #ffffff;
  border-color: #2b4b87;
}

.tree-panel.canvas-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 999;
  margin: 0;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  padding: 14px;
  display: flex;
  flex-direction: column;
  background: #f5f7fc;
}

.tree-panel.canvas-fullscreen .tree-canvas-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tree-panel.canvas-fullscreen .tree-root {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-top: 48px;
}

.tree-root.is-panning {
  cursor: grabbing;
  user-select: none;
}

.viz-canvas {
  min-width: max-content;
  display: inline-block;
  position: relative;
}

.flow-tree ul {
  margin: 0;
  padding: 24px 0 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0;
  position: relative;
}

.flow-tree li {
  list-style: none;
  text-align: center;
  position: relative;
  padding: 24px 10px 0;
}

.flow-tree li::before,
.flow-tree li::after {
  content: "";
  position: absolute;
  top: 0;
  width: 50%;
  height: 20px;
  border-top: 2px solid var(--flow-line);
}

.flow-tree li::before {
  left: 0;
  border-right: 2px solid var(--flow-line);
}

.flow-tree li::after {
  right: 0;
  border-left: 2px solid var(--flow-line);
}

.flow-tree li:only-child::before,
.flow-tree li:only-child::after {
  display: none;
}

.flow-tree li:only-child {
  padding-top: 0;
}

.flow-tree li:first-child::before,
.flow-tree li:last-child::after {
  border: 0;
}

.flow-tree li:last-child::before {
  border-radius: 0 7px 0 0;
}

.flow-tree li:first-child::after {
  border-radius: 7px 0 0 0;
}

.flow-level > li::before,
.flow-level > li::after {
  display: none;
}

.flow-children::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 24px;
  border-left: 2px solid var(--flow-line);
  transform: translateX(-50%);
}

.flow-box {
  min-width: 220px;
  width: max-content;
  max-width: none;
  background: #ffffff;
  border: 1px solid #9eb4da;
  border-radius: 12px;
  padding: 10px 12px 11px;
  box-shadow: 0 10px 24px rgba(44, 72, 124, 0.1);
  text-align: left;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
  margin: 0 auto;
}

.flow-box:hover {
  border-color: #6f8fc2;
}

.flow-box.dragging {
  opacity: 0.45;
}

.flow-box.drag-target {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.flow-top {
  display: flex;
  align-items: center;
  gap: 9px;
}

.flow-toggle,
.flow-field-toggle,
.classic-toggle {
  width: 22px;
  height: 22px;
  border: 1px solid #6f84b4;
  border-radius: 6px;
  padding: 0;
  background: #ffffff;
  color: #16325d;
  line-height: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px #d6e0f5;
}

.flow-toggle:hover,
.flow-field-toggle:hover,
.classic-toggle:hover {
  background: #eaf0ff;
  border-color: #2b4b87;
}

.flow-toggle:focus-visible,
.flow-field-toggle:focus-visible,
.classic-toggle:focus-visible {
  outline: 2px solid #2b4b87;
  outline-offset: 1px;
}

.flow-toggle-spacer {
  width: 22px;
  height: 22px;
}

.flow-key {
  font-weight: 700;
  color: #213353;
  word-break: break-all;
  letter-spacing: 0.15px;
}

.flow-meta {
  margin-top: 7px;
  color: #0c7662;
  font-size: 12px;
  font-weight: 700;
}

.flow-fields {
  margin-top: 8px;
  border-top: 1px solid #e0e6f3;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.flow-field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #f7faff;
  cursor: grab;
  width: max-content;
  max-width: 100%;
}

.flow-field-row:hover {
  background: #eef3fd;
}

.flow-field-row.dragging {
  opacity: 0.45;
}

.flow-field-row.drag-target {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.flow-field-key {
  font-weight: 700;
  color: #2b3b5e;
}

.flow-field-type {
  color: #0a7a64;
  font-size: 12px;
  font-weight: 600;
}

.flow-field-value {
  color: #4f2e90;
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-word;
}

.flow-field-row-leaf {
  white-space: nowrap;
}

.flow-field-row-object {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  width: max-content;
}

.flow-field-row-object:hover {
  background: transparent;
}

.flow-field-toggle {
  margin-left: auto;
}

.flow-mini-box {
  min-width: 210px;
  width: max-content;
  max-width: none;
  border: 1px solid #bfd0ec;
  border-radius: 9px;
  background: #ffffff;
  padding: 5px 6px;
}

.flow-mini-top {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid #e1e9f7;
  padding-bottom: 5px;
}

.flow-mini-key {
  font-weight: 700;
  color: #27406b;
}

.flow-mini-type {
  color: #0a7a64;
  font-size: 11px;
  font-weight: 600;
}

.flow-mini-fields {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.flow-value {
  margin-top: 5px;
  color: #4f2e90;
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-word;
}

.flow-h-tree {
  padding: 6px 6px 10px;
}

.h-root {
  position: relative;
}

.h-node {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 32px;
  margin: 8px 0;
}

.h-box {
  position: relative;
  z-index: 2;
}

.h-children {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  min-width: max-content;
}

.h-edge {
  position: relative;
}

.h-child-wrap {
  position: relative;
}

.h-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.classic-tree {
  padding: 4px 2px;
}

.classic-node {
  margin: 3px 0;
}

.classic-node-content {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.classic-node-content:hover {
  background: #eef3fb;
}

.classic-node-content.dragging {
  opacity: 0.45;
}

.classic-node-content.drag-target {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.classic-toggle-spacer {
  width: 22px;
  height: 22px;
}

.classic-key {
  color: #213353;
  font-weight: 700;
}

.classic-type {
  color: #0c7662;
  font-weight: 600;
}

.classic-value {
  color: #5b1ca5;
}

.classic-children {
  margin-left: 26px;
  border-left: 1px dashed #aeb8cf;
  padding-left: 8px;
}

@media (max-width: 919px) {
  .panel-title-row {
    flex-direction: column;
    align-items: center;
  }
}

@media (min-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }
}
