:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --node-bg: #ffffff;
  --node-text: #0f172a;
  --node-border: #38bdf8;
  --node-selected: #0ea5e9;
  --connector: #475569;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b 0%, var(--bg) 60%);
}

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.hidden { display: none !important; }

.topbar {
  border-bottom: 1px solid rgba(148,163,184,.15);
  background: rgba(15,23,42,.6);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { font-size: 18px; letter-spacing: .02em; }
.tree-picker { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.tree-picker select {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid rgba(148,163,184,.25);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  min-width: 200px;
}

.stage { flex: 1; overflow: auto; }
.diagram {
  min-height: 100%;
  padding: 50px 40px;
  display: flex;
  justify-content: center;
}
.empty-state { color: var(--muted); text-align: center; margin-top: 80px; font-size: 15px; }

.diagram-inner { display: inline-block; }

ul.tree, ul.tree ul { list-style: none; margin: 0; padding: 0; position: relative; }
ul.tree { display: flex; }
ul.tree li { position: relative; padding: 32px 14px 0; text-align: center; }
ul.tree li::before, ul.tree li::after {
  content: "";
  position: absolute;
  top: 0;
  height: 32px;
  border-top: 2px solid var(--connector);
  width: 50%;
}
ul.tree li::before { left: 0; }
ul.tree li::after { right: 0; border-left: 2px solid var(--connector); }
ul.tree li:only-child::after, ul.tree li:only-child::before { display: none; }
ul.tree li:first-child::before, ul.tree li:last-child::after { border: none; }
ul.tree li:last-child::before { border-right: 2px solid var(--connector); border-radius: 0 6px 0 0; }
ul.tree li:first-child::after { border-radius: 6px 0 0 0; }
ul.tree ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  height: 32px;
  border-left: 2px solid var(--connector);
}
ul.tree ul { padding-top: 32px; display: flex; }

.node-box {
  display: inline-block;
  min-width: 130px;
  max-width: 220px;
  background: var(--node-bg);
  color: var(--node-text);
  border: 2px solid var(--node-border);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.node-box:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(0,0,0,.45); }
.node-box.selected { border-color: var(--node-selected); box-shadow: 0 0 0 3px rgba(14,165,233,.4); }
.node-title { font-weight: 700; font-size: 14px; word-break: break-word; }
.node-line { font-size: 12px; color: #475569; word-break: break-word; margin-top: 2px; }
.node-empty { font-style: italic; color: #94a3b8; font-size: 12px; }

.detail {
  position: fixed;
  top: 72px;
  right: 20px;
  width: 300px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  color: var(--node-text);
  border-radius: 14px;
  padding: 18px 18px 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
  z-index: 20;
}
.detail h3 { margin: 0 28px 12px 0; font-size: 16px; word-break: break-word; }
.detail-close {
  position: absolute; top: 12px; right: 12px;
  border: none; background: none; font-size: 22px; line-height: 1;
  cursor: pointer; color: #94a3b8;
}
.detail-close:hover { color: #0f172a; }
.detail-fields { margin: 0; }
.detail-fields dt { font-size: 12px; color: #64748b; margin-top: 10px; }
.detail-fields dd { margin: 2px 0 0; font-size: 14px; word-break: break-word; }
.detail-empty { color: #94a3b8; font-size: 13px; }
