:root {
  --bg: #eef4fa;
  --surface: rgba(255, 255, 255, 0.66);
  --surface-strong: rgba(255, 255, 255, 0.86);
  --ink: #172235;
  --ink-strong: #07111f;
  --muted: #657287;
  --line: rgba(88, 108, 138, 0.18);
  --signal: #0aa8ff;
  --signal-rgb: 10, 168, 255;
  --aqua: #64f4dc;
  --aqua-rgb: 100, 244, 220;
  --master: #385276;
  --master-rgb: 56, 82, 118;
  --xiayuan: #ff4d72;
  --xiayuan-rgb: 255, 77, 114;
  --sworn: #ff8f4d;
  --sworn-rgb: 255, 143, 77;
  --shadow: 0 30px 90px rgba(45, 63, 89, 0.18);
  --shadow-soft: 0 14px 42px rgba(45, 63, 89, 0.12);
  --radius: 30px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  overflow-x: hidden;
  font-family: "SF Pro Display", "Segoe UI Variable", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.98), transparent 28%),
    radial-gradient(circle at 78% 2%, rgba(var(--aqua-rgb), 0.42), transparent 28%),
    radial-gradient(circle at 84% 70%, rgba(var(--signal-rgb), 0.23), transparent 36%),
    radial-gradient(circle at 18% 86%, rgba(255, 196, 218, 0.5), transparent 32%),
    linear-gradient(135deg, #f9fcff 0%, #e6eef7 46%, #f4f7fb 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(31, 54, 84, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 54, 84, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at 50% 36%, #000 0%, transparent 74%);
}

.ambient-grid {
  position: fixed;
  inset: -16%;
  pointer-events: none;
  background:
    radial-gradient(circle at 35% 24%, rgba(255, 255, 255, 0.82), transparent 18%),
    conic-gradient(from 180deg at 58% 42%, transparent, rgba(var(--signal-rgb), 0.15), transparent 25%),
    radial-gradient(circle, rgba(43, 72, 110, 0.11) 0 1px, transparent 1.5px);
  background-size: auto, auto, 76px 76px;
  opacity: 0.56;
  animation: auraDrift 18s ease-in-out infinite alternate;
}

@keyframes auraDrift {
  from { transform: translate3d(0, 0, 0) rotate(0deg); }
  to { transform: translate3d(-18px, 14px, 0) rotate(2deg); }
}

.page-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 18px;
  gap: 14px;
}

.hero-panel,
.control-panel,
.graph-stage,
.detail-card,
.relation-list-panel {
  position: relative;
  isolation: isolate;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.38)),
    var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(28px) saturate(175%);
  -webkit-backdrop-filter: blur(28px) saturate(175%);
}

.hero-panel::before,
.control-panel::before,
.graph-stage::before,
.detail-card::before,
.relation-list-panel::before {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: -1;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.44);
  pointer-events: none;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 142px;
  padding: 20px;
  border-radius: calc(var(--radius) + 8px);
}

.title-block h1,
.panel-heading h2,
.graph-panel-header h2,
.detail-card h2,
.empty-graph h3 {
  margin: 5px 0 0;
  color: var(--ink-strong);
  letter-spacing: -0.03em;
}

.title-block h1 {
  font-size: clamp(36px, 4vw, 64px);
  line-height: 0.95;
}

.subtitle {
  max-width: 68ch;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.eyebrow,
.field span,
.hero-stats span {
  margin: 0;
  color: #0077c8;
  font-family: "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 104px);
  gap: 10px;
}

.hero-stats div,
.compose-preview,
.relation-item,
.person-relation-row,
.empty-list {
  border: 1px solid rgba(80, 101, 132, 0.13);
  background: rgba(255, 255, 255, 0.56);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.74);
}

.hero-stats div {
  min-height: 86px;
  padding: 14px;
  border-radius: 23px;
}

.hero-stats strong {
  display: block;
  margin-top: 6px;
  color: var(--ink-strong);
  font-size: 36px;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 0.58fr) minmax(0, 1.24fr) minmax(320px, 0.54fr);
  gap: 14px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.control-panel,
.detail-panel,
.graph-panel {
  min-height: 0;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: calc(var(--radius) + 4px);
}

.panel-heading.compact h2 {
  font-size: 22px;
}

.relation-form {
  display: grid;
  gap: 11px;
}

.field {
  display: grid;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(80, 101, 132, 0.18);
  border-radius: 17px;
  padding: 0 14px;
  color: var(--ink-strong);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.58)),
    rgba(255, 255, 255, 0.68);
  font: inherit;
  font-size: 14px;
  outline: none;
  box-shadow: inset 0 1px 2px rgba(30, 47, 73, 0.08);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

input:focus,
select:focus {
  border-color: rgba(var(--signal-rgb), 0.54);
  box-shadow:
    inset 0 1px 2px rgba(30, 47, 73, 0.07),
    0 0 0 5px rgba(var(--signal-rgb), 0.14),
    0 18px 38px rgba(var(--signal-rgb), 0.12);
  transform: translateY(-1px);
}

.primary-button,
.ghost-button {
  min-height: 46px;
  border-radius: 18px;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
}

.primary-button {
  border: 1px solid rgba(255, 255, 255, 0.78);
  color: #052438;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.96), transparent 38%),
    linear-gradient(135deg, rgba(var(--aqua-rgb), 0.82), rgba(202, 247, 255, 0.96) 44%, rgba(255, 255, 255, 0.72));
  box-shadow: 0 18px 44px rgba(var(--signal-rgb), 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.ghost-button {
  border: 1px solid rgba(80, 101, 132, 0.14);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.54);
}

.ghost-button.danger {
  color: #9c1232;
  background: rgba(var(--xiayuan-rgb), 0.08);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-2px);
  filter: brightness(1.02);
  box-shadow: var(--shadow-soft);
}

.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.compose-preview {
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 13px 14px;
  border-radius: 18px;
  color: var(--ink-strong);
  font-weight: 850;
  line-height: 1.45;
}

.relation-list-panel {
  flex: 1;
  min-height: 0;
  padding: 14px;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.relation-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: 42vh;
  margin-top: 12px;
  overflow: auto;
  padding-right: 4px;
}

.relation-item,
.person-relation-row,
.empty-list {
  border-radius: 17px;
  padding: 11px;
}

.relation-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.relation-item strong,
.person-relation-row strong {
  display: block;
  margin-top: 7px;
  color: var(--ink-strong);
  font-size: 13px;
  line-height: 1.45;
}

.relation-item button {
  border: 0;
  border-radius: 12px;
  padding: 8px 9px;
  color: #9c1232;
  background: rgba(var(--xiayuan-rgb), 0.08);
  cursor: pointer;
}

.empty-list {
  display: grid;
  gap: 4px;
  color: var(--muted);
}

.empty-list strong {
  color: var(--ink-strong);
}

.graph-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.graph-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  padding: 0 4px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.key,
.relation-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.key {
  padding: 8px 10px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.relation-pill {
  padding: 6px 9px;
}

.key-master,
.relation-pill.edge-master {
  color: #243c5c;
  background: rgba(var(--master-rgb), 0.085);
  border-color: rgba(var(--master-rgb), 0.17);
}

.key-xiayuan,
.relation-pill.edge-xiayuan {
  color: #a91639;
  background: rgba(var(--xiayuan-rgb), 0.1);
  border-color: rgba(var(--xiayuan-rgb), 0.22);
}

.key-sworn,
.relation-pill.edge-sworn {
  color: #9c4a0d;
  background: rgba(var(--sworn-rgb), 0.12);
  border-color: rgba(var(--sworn-rgb), 0.24);
}

.graph-stage {
  position: relative;
  flex: 1;
  min-height: 72vh;
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 255, 255, 0.9), transparent 34%),
    radial-gradient(circle at 54% 48%, rgba(var(--signal-rgb), 0.12), transparent 46%),
    linear-gradient(rgba(45, 70, 102, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45, 70, 102, 0.055) 1px, transparent 1px),
    rgba(255, 255, 255, 0.62);
  background-size: auto, auto, 32px 32px, 32px 32px, auto;
}

.graph-stage::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(var(--signal-rgb), 0.13);
  border-radius: 24px;
  pointer-events: none;
}

#graph-svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
}

.empty-graph {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(360px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  z-index: 2;
  text-align: center;
  color: var(--muted);
}

.empty-graph h3 {
  font-size: 28px;
}

.empty-graph p {
  line-height: 1.7;
}

.builder-edge {
  stroke-width: 3;
  fill: none;
  vector-effect: non-scaling-stroke;
}

.builder-edge.edge-master {
  stroke: var(--master);
}

.builder-edge.edge-xiayuan {
  stroke: var(--xiayuan);
}

.builder-edge.edge-sworn {
  stroke: var(--sworn);
}

.builder-edge.dimmed,
.builder-edge-label.dimmed {
  opacity: 0.16;
}

.builder-edge-label {
  fill: rgba(28, 39, 57, 0.82);
  font-size: 13px;
  font-weight: 850;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 5px;
  stroke-linejoin: round;
}

.builder-node {
  cursor: pointer;
  will-change: transform;
}

.builder-node rect {
  fill: rgba(255, 255, 255, 0.86);
  stroke: rgba(80, 101, 132, 0.2);
  stroke-width: 1.5;
  filter: drop-shadow(0 10px 16px rgba(45, 63, 89, 0.15));
}

.builder-node text {
  fill: var(--ink-strong);
  font-size: 15px;
  font-weight: 900;
}

.builder-node.node-master rect {
  fill: #dce8f7;
  stroke: rgba(var(--master-rgb), 0.34);
}

.builder-node.node-xiayuan rect {
  fill: #ffe3ea;
  stroke: rgba(var(--xiayuan-rgb), 0.36);
}

.builder-node.node-sworn rect {
  fill: #ffeadb;
  stroke: rgba(var(--sworn-rgb), 0.36);
}

.builder-node.selected rect {
  stroke: var(--signal);
  stroke-width: 3;
  filter: drop-shadow(0 0 16px rgba(var(--signal-rgb), 0.42));
}

.builder-node.muted {
  opacity: 0.22;
}

.detail-panel {
  min-height: 0;
}

.detail-card {
  height: 100%;
  min-height: 72vh;
  padding: 20px;
  border-radius: calc(var(--radius) + 4px);
  overflow: auto;
}

.detail-card h2 {
  font-size: 34px;
  line-height: 1.04;
}

.detail-card p {
  color: var(--muted);
  line-height: 1.75;
}

.person-relation-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.hidden {
  display: none !important;
}

.admin-hidden {
  display: none !important;
}

.hero-panel,
.control-panel,
.graph-panel,
.detail-panel {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .detail-card,
  .graph-stage {
    min-height: 56vh;
  }

  .relation-list {
    max-height: 280px;
  }
}

@media (max-width: 760px) {
  .page-shell {
    padding: 12px;
  }

  .hero-panel {
    grid-template-columns: 1fr;
    border-radius: 28px;
  }

  .hero-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .title-block h1 {
    font-size: 38px;
  }

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

  .graph-panel-header {
    align-items: start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@supports not ((backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px))) {
  .hero-panel,
  .control-panel,
  .graph-stage,
  .detail-card,
  .relation-list-panel {
    background: rgba(255, 255, 255, 0.94);
  }
}
