:root {
  --bg: #07090d;
  --bg-2: #0d1219;
  --panel: rgba(18, 24, 34, 0.92);
  --panel-solid: #121822;
  --line: rgba(148, 163, 184, 0.18);
  --line-strong: rgba(148, 163, 184, 0.32);
  --text: #eef3fb;
  --muted: #9aa8bd;
  --accent: #7dd3fc;
  --accent-2: #34d399;
  --accent-hot: #8adfff;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --glow: rgba(125, 211, 252, 0.22);
  --node-bg: rgba(18, 24, 34, 0.95);
  --node-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 14px;
  --panel-w: 320px;
  --grid-dot: rgba(148, 163, 184, 0.14);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
/* Author display rules must not bring back elements the app has hidden. */
[hidden] { display: none !important; }
kbd {
  display: inline-block;
  padding: 0.1em 0.4em;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  font-size: 0.78em;
  font-family: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  position: relative;
  background:
    radial-gradient(900px 500px at 8% -10%, rgba(125,211,252,.10), transparent 55%),
    radial-gradient(700px 420px at 95% 0%, rgba(52,211,153,.07), transparent 50%),
    var(--bg);
}

/* ——— Top bar ——— */
.topbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  gap: 0.4rem 0.65rem;
  padding:
    max(0.4rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    0.4rem
    max(0.75rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 13, 0.92);
  backdrop-filter: blur(16px);
  z-index: 40;
  min-height: 52px;
  height: auto;
  overflow: visible;
  container-type: inline-size;
  container-name: topbar;
}

.brand-block {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  min-width: 0;
}
.env-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.16rem 0.46rem;
  border-radius: 999px;
  background: #fbbf24;
  color: #78350f;
  border: 1px solid #d97706;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  line-height: 1.2;
  white-space: nowrap;
}
.auth-gate .env-badge { margin: 0.15rem auto 0.35rem; }
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
}
.mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 8px 24px var(--glow);
  display: grid;
  place-items: center;
  color: #041018;
  font-weight: 800;
  font-size: 0.95rem;
}
.brand-text {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.4rem;
  line-height: 1.25;
  white-space: nowrap;
}
.brand-text strong {
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}
.byline {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.25;
}
.byline strong,
.site-link strong,
.brand-credit strong {
  font-weight: 750;
  color: var(--text);
}
.brand-credit {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.25;
}

.toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.2rem;
  flex: 1 1 46rem;
  min-width: min(100%, 46rem);
  max-width: 100%;
  overflow: visible;
}

.tool-group {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.1rem;
  padding: 0.15rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.025);
  border: 1px solid transparent;
}

.tool-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 0.3rem;
}

.tool-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex-shrink: 0;
  padding: 0.38rem 0.48rem;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: visible;
  transition: background .12s ease, color .12s ease, border-color .12s ease, transform .12s ease;
}
.tool-btn svg {
  display: block;
  flex-shrink: 0;
}
.tool-btn:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}
.tool-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tool-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.tool-btn.active,
.tool-btn[aria-pressed="true"] {
  color: #041018;
  background: linear-gradient(135deg, #8adfff, #5eead4);
  box-shadow: 0 6px 20px var(--glow);
}
.tool-btn.tool-danger:hover:not(:disabled) {
  color: var(--danger);
  background: var(--danger-bg);
}
.tool-zoom {
  min-width: 3.4rem;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}
.tool-label { white-space: nowrap; }

.view-switch {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
}
.view-switch .tool-btn {
  border-radius: 0;
  padding: 0.38rem 0.62rem;
}
.view-switch .tool-btn + .tool-btn { border-left: 1px solid var(--line); }

.topbar-right {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem 0.45rem;
  flex: 0 1 auto;
  max-width: 100%;
  min-width: 0;
  margin-left: auto;
}
.status-pill {
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.25;
  color: var(--accent-2);
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.22);
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-pill.saving {
  color: var(--accent);
  background: rgba(125, 211, 252, 0.1);
  border-color: rgba(125, 211, 252, 0.22);
}
.admin-badge {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  line-height: 1.25;
  max-width: 16rem;
  min-width: 0;
}
.admin-badge .admin-email {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
  max-width: 9.5rem;
}
.admin-badge .admin-role {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.9;
  line-height: 1.25;
  flex-shrink: 0;
}
.admin-badge .admin-role.is-member { color: var(--accent-2); }
.ghost-chip {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  padding: 0.32rem 0.7rem;
  white-space: nowrap;
}
.ghost-chip:hover { border-color: var(--line-strong); background: rgba(255,255,255,0.06); }
.ghost-chip.has-pending {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.1);
}
.ghost-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.count-badge {
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: #fbbf24;
  color: #1c1403;
  font-size: 0.68rem;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
}
.count-badge[hidden] { display: none !important; }
.logout-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  padding: 0.32rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  opacity: 0.85;
  transition: opacity .15s, color .15s, border-color .15s;
}
.logout-btn:hover {
  opacity: 1;
  color: var(--text);
  border-color: var(--line);
}
.logout-btn:disabled { opacity: 0.4; cursor: default; }

/* ——— Auth gate (unauthenticated) ——— */
body.gated {
  overflow: hidden;
}
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 8% -10%, rgba(125,211,252,.12), transparent 55%),
    radial-gradient(700px 420px at 95% 0%, rgba(52,211,153,.08), transparent 50%),
    var(--bg);
}
.auth-gate[hidden] { display: none !important; }
.auth-gate-card {
  width: min(100%, 24rem);
  padding: 2rem 1.75rem 1.85rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(18, 24, 34, 0.92);
  box-shadow: 0 24px 64px rgba(0,0,0,.45);
  text-align: center;
  backdrop-filter: blur(12px);
}
.auth-gate-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}
.auth-gate-brand .mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 1.15rem;
}
.auth-gate-brand strong {
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.auth-gate-brand .byline {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
.auth-gate-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.auth-gate-note {
  margin: 0 0 1.4rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.auth-google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  text-decoration: none;
  padding: 0.75rem 1rem;
  font-weight: 700;
}
.auth-google-btn svg { flex-shrink: 0; }

.status-pill.error {
  color: #fda4af;
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.28);
}
.status-pill.pending {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.28);
}

.site-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  flex-shrink: 0;
}
.site-link:hover { color: var(--accent); }

/* ——— Workspace ——— */
.workspace {
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.canvas-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  outline: none;
  background-color: #080b11;
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
  touch-action: none;
}
.canvas-viewport:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(125, 211, 252, 0.35);
}
.canvas-viewport.panning { cursor: grabbing; }
.canvas-viewport.connect-mode { cursor: crosshair; }
.canvas-viewport.space-pan { cursor: grab; }

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
  will-change: transform;
}

.generation-guides {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 0;
}
.generation-guide {
  position: absolute;
  height: 0;
  border-top: 1px dashed rgba(148, 163, 184, 0.38);
}
.generation-guide span {
  position: absolute;
  left: 0;
  top: -15px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.72);
}
.workspace.view-tree .generation-guide {
  border-top-color: rgba(186, 210, 170, 0.4);
}
.workspace.view-tree .generation-guide span {
  color: rgba(198, 214, 186, 0.78);
}

.edges-layer {
  position: absolute;
  overflow: visible;
  pointer-events: none;
  left: -50000px;
  top: -50000px;
  width: 100000px;
  height: 100000px;
}
.edges-layer .edge-hit {
  pointer-events: stroke;
  cursor: pointer;
  stroke: transparent;
  stroke-width: 14;
  fill: none;
}
.edges-layer .edge-path {
  fill: none;
  stroke: rgba(148, 163, 184, 0.45);
  stroke-width: 2;
  pointer-events: none;
}
.edges-layer .edge-path.selected {
  stroke: var(--accent);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px var(--glow));
}
.edges-layer .edge-path.pending,
.edges-layer .edge-path.draft {
  stroke-dasharray: 5 4;
}
.edges-layer .edge-path.view-link-branch,
.edges-layer .edge-path.view-link-siblings,
.edges-layer .edge-path.view-link-spouse {
  stroke-width: 1.75;
}
.workspace.view-org .edges-layer .edge-path.view-link {
  stroke: rgba(125, 211, 252, 0.72);
}
.workspace.view-tree .edges-layer .edge-path.view-link {
  stroke: rgba(134, 176, 122, 0.92);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.workspace.view-tree .edges-layer .edge-path.view-link-branch {
  stroke: rgba(120, 168, 104, 0.95);
  stroke-width: 2.75;
}
.workspace.view-tree .edges-layer .edge-path.view-link-trunk {
  stroke: rgba(146, 106, 62, 0.95);
  stroke-width: 5;
  stroke-linecap: round;
}
.workspace.view-tree .canvas-viewport {
  background-color: #101610;
  background-image:
    radial-gradient(900px 460px at 50% 115%, rgba(62, 96, 52, 0.55), transparent 62%),
    radial-gradient(420px 220px at 50% 102%, rgba(98, 68, 36, 0.4), transparent 60%),
    radial-gradient(circle, rgba(148, 163, 184, 0.08) 1px, transparent 1px);
  background-size: auto, auto, 24px 24px;
}
.workspace.view-org .canvas-viewport {
  background-color: #0c1220;
  background-image:
    linear-gradient(rgba(125, 211, 252, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 211, 252, 0.05) 1px, transparent 1px);
  background-size: 48px 48px, 48px 48px;
}

.focus-bar {
  position: absolute;
  z-index: 6;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  padding: 0.4rem 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(12, 16, 24, 0.92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  max-width: 100%;
}
.focus-center {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 0;
}
.focus-center select {
  max-width: min(16rem, 70vw);
  padding: 0.32rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #121822;
  color: var(--text);
}
.focus-hint {
  margin: 0;
  flex: 1 1 12rem;
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}
.focus-bar .tool-btn { flex: 0 0 auto; }
.edges-layer .edge-path.pending { stroke: rgba(251, 191, 36, 0.85); }
.edges-layer .edge-path.draft { stroke: rgba(125, 211, 252, 0.85); }
.edges-layer .edge-label.pending { fill: #fbbf24; }
.edges-layer .edge-label.draft { fill: var(--accent); }
.edges-layer .edge-label-bg {
  fill: #0c1018;
  stroke: var(--line);
  stroke-width: 1;
  rx: 6;
  pointer-events: none;
}
.edges-layer .edge-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--sans);
  font-weight: 650;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  letter-spacing: 0.02em;
}
.edges-layer .edge-label.selected { fill: var(--accent); }
.temp-edge {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
  opacity: 0.85;
}

.nodes-layer {
  position: absolute;
  left: 0;
  top: 0;
}

/* ——— Person cards ——— */
.person-node {
  position: absolute;
  width: 200px;
  padding: 0.85rem 0.95rem 0.9rem;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05), transparent 40%),
    var(--node-bg);
  border: 1px solid var(--line);
  box-shadow: var(--node-shadow);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: box-shadow .15s ease, border-color .15s ease;
  z-index: 1;
}
.person-node:hover {
  border-color: var(--line-strong);
}
.person-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px rgba(125,211,252,0.15), var(--node-shadow);
  z-index: 5;
}
.person-node.is-focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.85), var(--node-shadow);
  z-index: 4;
}
.person-node.connect-source {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--accent-2), 0 0 0 4px rgba(52,211,153,0.18), var(--node-shadow);
}
.person-node.pending,
.person-node.draft {
  border-style: dashed;
}
.person-node.pending { border-color: rgba(251, 191, 36, 0.7); }
.person-node.draft { border-color: rgba(125, 211, 252, 0.75); }
.person-node.pending .node-name,
.person-node.draft .node-name { padding-right: 3.4rem; }
.person-node.pending::after,
.person-node.draft::after {
  content: "Pending";
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 999px;
  padding: 0.1rem 0.38rem;
}
.person-node.draft::after {
  content: "Draft";
  color: #7dd3fc;
  background: rgba(125, 211, 252, 0.1);
  border-color: rgba(125, 211, 252, 0.35);
}
.person-node.dragging {
  cursor: grabbing;
  opacity: 0.95;
  z-index: 10;
  transition: none;
}
.person-node:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.person-node::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--node-accent, var(--accent));
}

.node-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.node-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  color: #041018;
  background: var(--node-accent, var(--accent));
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.06);
}
.node-meta { min-width: 0; flex: 1; }
.node-name {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node-birth {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.8;
  margin-top: 0.35rem;
  padding-left: calc(40px + 0.7rem);
}
.more-chip {
  position: absolute;
  left: 50%;
  bottom: -11px;
  transform: translateX(-50%);
  z-index: 4;
  border: 1px solid rgba(125, 211, 252, 0.45);
  background: #102033;
  color: var(--accent);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
}
.more-chip:hover { background: #163044; }
.workspace.view-tree .more-chip {
  border-color: rgba(134, 176, 122, 0.55);
  background: #142016;
  color: #b7d7a8;
}

.node-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 2px solid var(--accent);
  opacity: 0;
  transition: opacity .12s ease, transform .12s ease;
  pointer-events: none;
  z-index: 2;
}
.person-node:hover .node-handle,
.person-node.selected .node-handle,
.connect-mode .person-node .node-handle {
  opacity: 1;
  pointer-events: auto;
}
.node-handle:hover { transform: scale(1.25); background: var(--accent); }
.node-handle.right { right: -7px; top: 50%; transform: translateY(-50%); }
.node-handle.right:hover { transform: translateY(-50%) scale(1.25); }
.node-handle.left { left: -7px; top: 50%; transform: translateY(-50%); }
.node-handle.left:hover { transform: translateY(-50%) scale(1.25); }
.node-handle.top { top: -7px; left: 50%; transform: translateX(-50%); }
.node-handle.top:hover { transform: translateX(-50%) scale(1.25); }
.node-handle.bottom { bottom: -7px; left: 50%; transform: translateX(-50%); }
.node-handle.bottom:hover { transform: translateX(-50%) scale(1.25); }

/* ——— Empty / mode banners ——— */
.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 15;
}
.empty-hint[hidden] { display: none !important; }
.empty-card {
  pointer-events: auto;
  text-align: center;
  padding: 2rem 2.2rem;
  max-width: 360px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent 40%), var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,.4);
}
.empty-icon {
  font-size: 1.8rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.empty-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.empty-card p {
  margin: 0 0 1.2rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.mode-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.55rem 0.7rem 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(12, 18, 28, 0.92);
  border: 1px solid rgba(125, 211, 252, 0.35);
  box-shadow: 0 12px 40px rgba(0,0,0,.35), 0 0 24px var(--glow);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.mode-banner[hidden] { display: none !important; }
.banner-cancel {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 650;
}
.banner-cancel:hover { background: rgba(255,255,255,0.08); }
.banner-cancel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ——— Side panel ——— */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--panel-w), 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(18px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: -16px 0 48px rgba(0,0,0,.35);
  animation: slideIn .18s ease;
}
.side-panel[hidden] { display: none !important; }

@keyframes slideIn {
  from { transform: translateX(12px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border-color: var(--line);
}
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panel-form {
  padding: 1rem 1.1rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow-y: auto;
}
.panel-note {
  margin: 0;
  padding: 0.7rem 0.75rem;
  border-radius: 10px;
  background: rgba(125, 211, 252, 0.08);
  border: 1px solid rgba(125, 211, 252, 0.22);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
}
.panel-note[hidden] { display: none !important; }
.field input:read-only,
.field textarea:read-only {
  opacity: 0.72;
  cursor: default;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.field em { color: var(--accent); font-style: normal; }
.field-hint {
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.35;
  color: var(--muted);
}
.field input,
.field textarea {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  padding: 0.65rem 0.75rem;
  color: var(--text);
  font-weight: 500;
  font-size: 0.92rem;
  letter-spacing: 0;
  resize: vertical;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(125, 211, 252, 0.55);
  box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.12);
}
.field input::placeholder,
.field textarea::placeholder { color: rgba(154, 168, 189, 0.55); }

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
  transition: transform .12s ease, box-shadow .12s ease;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.selected {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}
.color-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.color-swatch:disabled { cursor: default; opacity: 0.4; transform: none; }

.panel-actions {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.4rem;
}

/* ——— Buttons ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  font-weight: 650;
  font-size: 0.9rem;
  border: 1px solid transparent;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(135deg, #8adfff, #5eead4);
  color: #041018;
  box-shadow: 0 10px 30px var(--glow);
}
.btn-ghost {
  background: rgba(255,255,255,.04);
  border-color: var(--line);
  color: var(--text);
}
.btn-danger {
  background: var(--danger);
  color: #1a0505;
  font-weight: 700;
}
.btn-small {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
#btn-delete-person {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
  background: var(--danger-bg);
}

/* ——— Modal ——— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  width: min(400px, 100%);
  padding: 1.4rem 1.5rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent 40%), var(--panel-solid);
  box-shadow: 0 28px 80px rgba(0,0,0,.5);
}
.modal h3 {
  margin: 0 0 0.55rem;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.modal p {
  margin: 0 0 1.3rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

/* ——— Toast ——— */

/* ——— Quiet arrange control (bottom-right corner) ——— */
.arrange-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 6;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 18, 26, 0.55);
  color: rgba(148, 163, 184, 0.45);
  backdrop-filter: blur(8px);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity .15s ease, color .15s ease, border-color .15s ease, background .15s ease;
}
.arrange-btn:hover,
.arrange-btn:focus-visible {
  opacity: 1;
  color: rgba(203, 213, 225, 0.9);
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(22, 27, 38, 0.75);
  outline: none;
}
.arrange-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.35);
}
.arrange-btn:active {
  transform: translateY(1px);
}

.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  padding: 0.7rem 1.15rem;
  border-radius: 999px;
  background: rgba(18, 24, 34, 0.95);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  font-size: 0.88rem;
  font-weight: 600;
  pointer-events: none;
  animation: toastIn .2s ease;
}
.toast[hidden] { display: none !important; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ——— Relation picker (floating) ——— */
.rel-picker {
  position: fixed;
  z-index: 90;
  min-width: 180px;
  padding: 0.4rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.rel-picker button {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
}
.rel-picker button:hover,
.rel-picker button:focus-visible {
  background: rgba(125, 211, 252, 0.12);
  color: var(--accent);
  outline: none;
}
.rel-picker .rel-custom {
  border-top: 1px solid var(--line);
  margin-top: 0.2rem;
  padding-top: 0.45rem;
}
.rel-picker input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.3);
  padding: 0.5rem 0.65rem;
  font-size: 0.85rem;
}

/* ——— Member banner ——— */
.member-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: min(640px, calc(100% - 24px));
  padding: 0.45rem 0.55rem 0.45rem 0.9rem;
  border-radius: 999px;
  background: rgba(12, 18, 28, 0.94);
  border: 1px solid rgba(52, 211, 153, 0.35);
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}
.member-banner[hidden] { display: none !important; }
.member-banner span { line-height: 1.35; }
.workspace.has-member-banner .mode-banner { top: 64px; }

/* ——— Review / invite sheets ——— */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(8px);
}
.sheet[hidden] { display: none !important; }
.sheet-card {
  width: min(680px, 100%);
  max-height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent 28%), var(--panel-solid);
  box-shadow: 0 28px 80px rgba(0,0,0,.5);
  overflow: hidden;
}
.sheet-card-narrow { width: min(480px, 100%); }
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.1rem 1.15rem 0.85rem;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  margin: 0 0 0.3rem;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.sheet-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}
.sheet-body {
  overflow: auto;
  padding: 0.9rem 1.15rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.sheet-status { margin: 0; color: var(--muted); font-size: 0.9rem; }
.sheet-empty h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.sheet-empty p { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.review-group { display: flex; flex-direction: column; gap: 0.55rem; }
.review-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.who { display: flex; flex-direction: column; min-width: 0; }
.who-name { font-size: 0.92rem; }
.who-email {
  color: var(--muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who-count {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.change-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.9rem 0.9rem;
  background: rgba(255,255,255,0.02);
}
.change-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.type-pill {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.16rem 0.45rem;
}
.type-pill.is-node { color: #7dd3fc; background: rgba(125, 211, 252, 0.12); }
.type-pill.is-edge { color: #34d399; background: rgba(52, 211, 153, 0.12); }
.change-time { color: var(--muted); font-size: 0.72rem; }
.change-summary { margin: 0.55rem 0 0.25rem; font-size: 1rem; letter-spacing: -0.02em; }
.change-by { margin: 0 0 0.55rem; color: var(--muted); font-size: 0.8rem; }
.change-by strong { color: var(--text); font-weight: 700; }
.change-detail { display: flex; gap: 0.65rem; align-items: flex-start; }
.change-swatch {
  width: 14px;
  height: 14px;
  margin-top: 0.2rem;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}
.change-name { font-weight: 700; }
.change-meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.change-rel {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
}
.rel-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: lowercase;
  color: #041018;
  background: linear-gradient(135deg, #8adfff, #5eead4);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
}
.change-error {
  margin: 0.55rem 0 0;
  color: #fda4af;
  font-size: 0.8rem;
  font-weight: 650;
}
.change-error[hidden] { display: none !important; }
.change-actions { display: flex; gap: 0.45rem; margin-top: 0.75rem; }
.invite-form {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  padding: 0.9rem 1.15rem 0;
}
.invite-form .field { flex: 1; }
.invite-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.invite-id { display: flex; flex-direction: column; min-width: 0; }
.invite-id strong { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; }
.invite-id span { color: var(--muted); font-size: 0.75rem; }

@container topbar (max-width: 1580px) {
  .byline { display: none; }
}

/* ——— Responsive ——— */
@media (max-width: 900px) {
  .member-banner {
    border-radius: 16px;
    align-items: stretch;
    flex-direction: column;
    top: 8px;
  }
}

@media (max-width: 860px) {
  .toolbar {
    flex: 1 0 100%;
    order: 3;
    min-width: 0;
    flex-wrap: wrap;
    row-gap: 0.35rem;
  }
  .tool-group { flex-wrap: wrap; }
  .topbar-right {
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
  .admin-badge { max-width: 100%; }
  .admin-badge .admin-email { max-width: min(11rem, 46vw); }
}

@media (max-width: 640px) {
  .topbar {
    padding:
      max(0.4rem, env(safe-area-inset-top))
      max(0.55rem, env(safe-area-inset-right))
      0.45rem
      max(0.55rem, env(safe-area-inset-left));
  }
  .side-panel { width: 100%; }
  .person-node { width: 170px; }
  .sheet { padding: 0; align-items: stretch; }
  .sheet-card { width: 100%; max-height: 100%; border-radius: 0; }
  .invite-form { flex-direction: column; align-items: stretch; }
  .guide { padding: 0; align-items: stretch; }
  .guide-card { width: 100%; max-height: 100%; border-radius: 0; }
}

body.role-member .node-handle,
.workspace.view-org .node-handle,
.workspace.view-tree .node-handle { display: none !important; }

.guide {
  position: absolute;
  inset: 0;
  z-index: 28;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(8px);
}
.guide[hidden] { display: none !important; }
.guide-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(86vh, 760px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent 24%), var(--panel-solid);
  box-shadow: 0 28px 80px rgba(0,0,0,.5);
  padding: 1.15rem 1.2rem 1.25rem;
}
.guide-head { padding-right: 2.4rem; }
.guide-kicker {
  margin: 0 0 0.3rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.guide-head h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.guide-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}
.guide-close { position: absolute; top: 0.85rem; right: 0.85rem; }
.guide-steps {
  display: flex;
  gap: 0.4rem;
  list-style: none;
  margin: 0.9rem 0 0;
  padding: 0;
}
.guide-steps li {
  flex: 1;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 2px solid var(--line);
  padding-bottom: 0.35rem;
}
.guide-steps li.is-current { color: var(--text); border-color: var(--accent); }
.guide-steps li.is-done { color: var(--accent-2); border-color: var(--accent-2); }
.guide-body { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.9rem; }
.guide-card .brand-credit { margin-top: 0.85rem; }
.guide-people, .guide-rels { display: flex; flex-direction: column; gap: 0.45rem; }
.guide-person, .guide-rel {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  padding: 0.7rem 0.8rem;
}
.guide-rel { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
.guide-person:hover, .guide-rel:hover, .guide-person:focus-visible, .guide-rel:focus-visible {
  border-color: rgba(125, 211, 252, 0.55);
  background: rgba(125, 211, 252, 0.08);
  outline: none;
}
.guide-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #041018;
  font-weight: 800;
  flex-shrink: 0;
}
.guide-person-text { display: flex; flex-direction: column; min-width: 0; }
.guide-person-text span, .guide-rel span { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.guide-who { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.guide-who-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 650;
}
.guide-actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }
.guide-note { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.guide-error { margin: 0.7rem 0 0; color: #fda4af; font-size: 0.85rem; font-weight: 650; }
.guide-error[hidden] { display: none !important; }
.guide-form { display: flex; flex-direction: column; gap: 0.75rem; }
