:root{
  --bg: #0F1B1E;
  --bg-2: #0B1517;
  --surface: #16262A;
  --surface-2: #1D2E32;
  --surface-3: #24373B;
  --ink: #E8E2D0;
  --ink-dim: #9FB0AC;
  --ink-faint: #6B7C7A;
  --accent: #4FB3A9;
  --accent-soft: rgba(79,179,169,0.14);
  --accent-2: #D9A441;
  --accent-2-soft: rgba(217,164,65,0.16);
  --danger: #C1554A;
  --danger-soft: rgba(193,85,74,0.14);
  --line: rgba(232,226,208,0.12);
  --line-strong: rgba(232,226,208,0.22);
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}
*{ box-sizing: border-box; }
html,body{ margin:0; padding:0; }
body{
  background:
    radial-gradient(circle at 15% 0%, rgba(79,179,169,0.08), transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(217,164,65,0.06), transparent 40%),
    var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
}
::selection{ background: var(--accent); color: var(--bg-2); }
a{ color: inherit; }
button{ font-family: inherit; }
::-webkit-scrollbar{ height: 10px; width: 10px; }
::-webkit-scrollbar-track{ background: transparent; }
::-webkit-scrollbar-thumb{ background: var(--surface-3); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover{ background: var(--accent); }

.app-shell{ display:flex; flex-direction:column; height:100vh; }

.app-header-sticky{
  position: sticky; top: 0; z-index: 30;
  background: var(--bg); flex-shrink: 0;
}

/* ---------- header ---------- */
.top-bar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 22px 32px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap; gap: 16px;
}
.brand{ display:flex; align-items:center; gap:14px; }
.brand-mark{
  width:38px; height:38px; border-radius: 8px;
  background: linear-gradient(155deg, var(--accent), #2f7a72);
  display:flex; align-items:center; justify-content:center;
  box-shadow: 0 4px 14px rgba(79,179,169,0.35);
  flex-shrink: 0;
}
.brand-mark svg{ width:20px; height:20px; }
.brand h1{
  font-family:'Fraunces', serif; font-weight:600; font-size: 22px;
  margin:0; letter-spacing: 0.2px;
}
.brand p{ margin:2px 0 0; font-size: 12.5px; color: var(--ink-dim); letter-spacing:0.3px; }

.header-actions{ display:flex; align-items:center; gap:10px; flex-wrap: wrap; }
.conn-dot{
  width:8px; height:8px; border-radius:50%; background: var(--ink-faint); flex-shrink:0;
}
.conn-dot.online{ background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.conn-dot.offline{ background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.conn-chip{ display:flex; align-items:center; gap:7px; font-size:11.5px; color: var(--ink-dim); padding: 0 4px; }
.user-chip{
  display:flex; align-items:center; gap:8px;
  background: var(--surface); border:1px solid var(--line);
  padding:7px 12px 7px 8px; border-radius: 999px; cursor:pointer;
  font-size: 13px; transition: border-color .15s ease;
}
.user-chip:hover{ border-color: var(--line-strong); }
.user-dot{
  width:22px; height:22px; border-radius:50%;
  background: var(--accent-2); color:#241a05; font-weight:700; font-size:11px;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.btn{
  border-radius: 8px; border:1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 15px; font-size: 13.5px; font-weight:600;
  cursor:pointer; display:inline-flex; align-items:center; gap:7px;
  transition: all .15s ease; white-space: nowrap;
}
.btn:hover{ border-color: var(--line-strong); background: var(--surface-2); }
.btn-primary{ background: var(--accent); border-color: var(--accent); color:#08201d; }
.btn-primary:hover{ background:#5fc0b6; border-color:#5fc0b6; }
.btn-admin{ background: var(--accent-2-soft); border-color: rgba(217,164,65,0.4); color: var(--accent-2); }
.btn-admin:hover{ background: rgba(217,164,65,0.25); }
.btn-admin.is-active{ background: var(--accent-2); color:#241a05; }
.btn-ghost{ background:transparent; border-color: transparent; }
.btn-ghost:hover{ background: var(--surface); border-color: var(--line); }
.btn-danger{ color: var(--danger); }
.btn-danger:hover{ background: var(--danger-soft); border-color: rgba(193,85,74,0.4); }
.btn:disabled{ opacity:.45; cursor:not-allowed; }
.btn-sm{ padding: 5px 10px; font-size: 12px; }

/* ---------- toolbar ---------- */
.toolbar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 32px; gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.search-wrap{ position:relative; flex: 1 1 260px; max-width: 360px; }
.toolbar-nav{ display:flex; align-items:center; gap:12px; flex:1; min-width:0; }
.search-wrap input{
  width:100%; background: var(--surface); border:1px solid var(--line);
  border-radius: 8px; padding: 9px 12px 9px 34px; color: var(--ink); font-size: 13.5px;
}
.search-wrap input:focus{ outline:none; border-color: var(--accent); }
.search-wrap svg{ position:absolute; left:11px; top:50%; transform:translateY(-50%); width:14px; height:14px; color: var(--ink-faint); }
.search-nav{ display:flex; align-items:center; gap:6px; flex-shrink:0; }
.search-count{ font-size:12px; color: var(--ink-dim); white-space:nowrap; font-variant-numeric: tabular-nums; }
.search-nav .icon-btn{ width:26px; height:26px; }
.legend{ display:flex; align-items:center; gap:18px; font-size:12px; color:var(--ink-dim); flex-wrap:wrap; }
.legend-item{ display:flex; align-items:center; gap:6px; }

.persist-banner{
  margin: 14px 32px 0; padding: 10px 14px; border-radius: 8px;
  background: var(--danger-soft); border: 1px solid rgba(193,85,74,0.35);
  color: #f0a89f; font-size: 12.5px; display:flex; align-items:center; justify-content:space-between; gap:10px;
}
.persist-banner button{
  background:transparent; border:1px solid rgba(240,168,159,0.4); color:#f0a89f;
  border-radius:6px; padding:4px 9px; font-size:11.5px; cursor:pointer; flex-shrink:0;
}

/* ---------- forest / tree canvas ---------- */
.canvas{
  flex:1; min-height:0; overflow: auto; padding: 56px 32px 90px;
  display:flex; justify-content:center;
}
.canvas-list{ align-items:flex-start; align-items: safe center; }
.empty-state{
  max-width: 420px; margin: 60px auto; text-align:center; color: var(--ink-dim);
}
.empty-state h2{ font-family:'Fraunces', serif; color: var(--ink); font-weight:600; font-size:20px; margin-bottom:8px;}

.path-grid{
  width: 100%; max-width: 1120px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 260px));
  justify-content: center; align-content: center;
  gap: 22px;
}
.path-card{
  background: var(--surface); border:1px solid var(--line); border-radius: var(--radius);
  padding: 30px 20px; cursor:pointer; position:relative;
  box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease;
  display:flex; align-items:center; justify-content:center; text-align:center;
  height: 440px;
}
.path-card:hover{ transform: translateY(-3px); border-color: var(--accent); }
.path-admin-actions{
  position:absolute; top:14px; right:14px;
  display:flex; gap:6px;
}
.path-title{
  font-family:'Fraunces', serif; font-weight:600; font-size: 18px; margin: 0;
  word-break: break-word;
}

/* Path detail view is rendered by PathGraph using computed positions from
   dagre (a real graph layout, not nested CSS boxes) — this is what makes
   genuine convergence (two edges into one card) possible. Nodes are
   absolutely positioned divs inside a canvas sized to the full layout;
   edges are drawn as SVG paths underneath.

   Card heights vary (e.g. the admin-only button row appears/disappears),
   so layout re-measures and repositions after a height change. Animating
   position/size turns that into a smooth glide instead of a visible
   gap-then-snap. */
.graph-canvas{ position:relative; transition: width .25s ease, height .25s ease; }
.graph-edges{ position:absolute; top:0; left:0; pointer-events:none; }
.graph-node{ position:absolute; transition: left .25s ease, top .25s ease; }
.graph-lane{
  position:absolute; border-radius:12px; background: var(--surface); opacity:0.5;
  border:1px solid var(--line); pointer-events:none;
  transition: left .25s ease, top .25s ease, width .25s ease, height .25s ease;
}
.graph-lane-label{
  position:absolute; top:10px; left:14px; font-family:'JetBrains Mono', monospace;
  font-size:20px; font-weight:700; letter-spacing:0.4px; color: var(--accent);
  text-transform:uppercase; background: var(--accent-soft);
  padding:5px 14px; border-radius:8px;
}
.graph-canvas.no-transition,
.graph-node.no-transition,
.graph-lane.no-transition{ transition: none !important; }

/* ---------- node card ---------- */
.node-card{
  width: 236px; background: var(--surface); border:1px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 12px; text-align:left;
  box-shadow: var(--shadow); position:relative; transition: opacity .2s ease, border-color .15s ease, transform .15s ease;
}
.node-card:hover{ border-color: var(--line-strong); transform: translateY(-2px); }
.node-card.dimmed{ opacity: 0.28; }
.node-card.matched{ border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.node-card.pending{ opacity: 0.6; }
.node-card.is-root{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
  margin-top: 8px; /* room for the badge above */
}

.root-badge{
  position:absolute; top:-14px; left:50%; transform: translateX(-50%);
  display:flex; align-items:center; gap:4px;
  background: var(--accent); color:#08201d; font-weight:700; font-size:10px;
  letter-spacing:0.5px; text-transform:uppercase; white-space:nowrap;
  padding: 4px 10px; border-radius: 999px;
  box-shadow: 0 3px 10px rgba(79,179,169,0.45);
}
.root-badge svg{ width:10px; height:10px; }

.type-badge{
  position:absolute; top:-12px; left:50%; transform: translateX(-50%);
  background: var(--surface-3); color: var(--ink-dim); font-weight:700; font-size:10px;
  letter-spacing:0.5px; text-transform:uppercase; white-space:nowrap;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line-strong);
}

.link-candidate-list{
  max-height: 260px; overflow-y:auto; display:flex; flex-direction:column; gap:6px;
  margin-bottom: 4px;
}
.link-candidate{
  display:flex; align-items:center; gap:10px; text-align:left;
  background: var(--surface-2); border:1px solid var(--line); border-radius:8px;
  padding: 9px 12px; cursor:pointer; color: var(--ink); font-size:13px;
  transition: border-color .15s ease;
}
.link-candidate:hover{ border-color: var(--accent); }
.link-candidate:disabled{ opacity:.5; cursor:not-allowed; }
.link-candidate-type{
  font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:0.3px;
  color: var(--ink-faint); background: var(--surface-3); padding:3px 7px; border-radius:999px; flex-shrink:0;
}
.link-candidate-title{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.node-extra-fields{
  margin: 0 0 10px; padding-top: 8px; border-top: 1px dashed var(--line);
  display:flex; flex-direction:column; gap:4px;
}
.extra-field-row{ font-size: 12px; color: var(--ink-dim); line-height:1.4; word-break: break-word; }
.extra-field-label{ color: var(--ink-faint); font-weight:600; margin-right: 4px; }

.stamp{
  position:absolute; top:-0px; right:0px; width:34px; height:34px;
  display:flex; align-items:center; justify-content:center;
}
.stamp svg{ width:16px; height:16px; }

.node-title{
  font-family:'Fraunces', serif; font-weight:600; font-size: 15.5px;
  line-height:1.3; margin: 0 0 6px; word-break: break-word;
}
.node-content{
  font-size: 12.5px; color: var(--ink-dim); line-height:1.5; margin: 0 0 10px;
  display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden;
  word-break: break-word; white-space: pre-wrap; cursor:pointer;
}
.node-content.expanded{ -webkit-line-clamp: unset; }
.node-meta{
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  font-family:'JetBrains Mono', monospace; font-size: 10.5px; color: var(--ink-faint);
  margin-bottom: 10px;
}
.node-meta .author{ color: var(--accent); }
.node-actions{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.vote-btn{
  display:flex; align-items:center; gap:5px; background: var(--surface-2);
  border:1px solid var(--line); border-radius: 999px; padding: 5px 10px;
  font-size: 12px; font-weight:600; color: var(--ink-dim); cursor:pointer;
  transition: all .15s ease;
}
.vote-btn svg{ width:13px; height:13px; }
.vote-btn.up.voted{ background: var(--accent-soft); border-color: rgba(79,179,169,0.5); color: var(--accent); }
.vote-btn.up:hover{ border-color: var(--accent); }
.vote-btn.down.voted{ background: var(--danger-soft); border-color: rgba(193,85,74,0.5); color: var(--danger); }
.vote-btn.down:hover{ border-color: var(--danger); }
.icon-btn{
  width:28px; height:28px; border-radius:7px; display:flex; align-items:center; justify-content:center;
  background: var(--surface-2); border:1px solid var(--line); color: var(--ink-dim); cursor:pointer;
}
.icon-btn:hover{ color: var(--ink); border-color: var(--line-strong); }
.icon-btn svg{ width:13px; height:13px; }
.admin-row{ display:flex; gap:6px; margin-top:8px; padding-top:8px; border-top: 1px dashed var(--line); }

/* ---------- modals ---------- */
.overlay{
  position:fixed; inset:0; background: rgba(6,11,12,0.65); backdrop-filter: blur(3px);
  display:flex; align-items:center; justify-content:center; z-index: 100; padding:20px;
}
.modal{
  background: var(--surface); border:1px solid var(--line-strong); border-radius: 14px;
  width: 100%; max-width: 520px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h3{ font-family:'Fraunces', serif; font-size:19px; margin:0 0 4px; font-weight:600; }
.modal .sub{ font-size:12.5px; color: var(--ink-dim); margin: 0 0 18px; }
.field{ margin-bottom: 14px; }
.field label{ display:block; font-size:12px; color: var(--ink-dim); margin-bottom:6px; font-weight:600; letter-spacing:0.2px; }
.field input, .field textarea, .field select, .themed-input{
  width:100%; background: var(--surface-2); border:1px solid var(--line);
  border-radius:8px; padding: 10px 12px; color: var(--ink); font-size:13.5px; font-family:inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus, .themed-input:focus{ outline:none; border-color: var(--accent); }
.field select{
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239FB0AC' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
  padding-right: 34px; cursor: pointer;
}
.field select option{ background: var(--surface-2); color: var(--ink); }
.field .hint{ font-size:11px; color: var(--ink-faint); margin-top:5px; }
.source-combo-list{
  position:absolute; left:0; right:0; top:calc(100% + 4px); z-index:20;
  background: var(--surface-2); border:1px solid var(--line-strong); border-radius:8px;
  max-height:180px; overflow-y:auto; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.source-combo-list button{
  display:block; width:100%; text-align:left; padding:8px 12px; background:none; border:none;
  color: var(--ink); font-size:13px; font-family:inherit; cursor:pointer;
}
.source-combo-list button:hover, .source-combo-list button:focus{ background: var(--accent-soft); color: var(--accent); outline:none; }
.link-btn{
  background:none; border:none; padding:0; margin:0; cursor:pointer;
  font-size:11px; font-weight:600; color: var(--accent); white-space:nowrap;
}
.link-btn:hover{ text-decoration:underline; }
.color-swatch{
  width:34px; height:34px; border-radius:8px; border:1px solid var(--line-strong);
  flex-shrink:0; transition: background .1s ease;
}
.type-tabs{ display:flex; flex-wrap:wrap; gap:6px; }
.type-tab{
  border-radius: 999px; border:1px solid var(--line); background: var(--surface-2);
  color: var(--ink-dim); padding: 7px 13px; font-size: 12.5px; font-weight:600;
  cursor:pointer; transition: all .15s ease;
}
.type-tab:hover{ border-color: var(--line-strong); color: var(--ink); }
.type-tab.active{ background: var(--accent); border-color: var(--accent); color:#08201d; }
.modal-actions{ display:flex; justify-content:flex-end; gap:8px; margin-top: 18px; }
.modal-error{ background: var(--danger-soft); color: #f0a89f; border:1px solid rgba(193,85,74,0.4); border-radius:8px; padding:8px 10px; font-size:12.5px; margin-bottom:12px; }

/* ---------- toast ---------- */
.toast-stack{ position:fixed; bottom:24px; right:24px; display:flex; flex-direction:column; gap:8px; z-index: 200; }
.toast{
  background: var(--surface-2); border:1px solid var(--line-strong); color: var(--ink);
  padding: 10px 16px; border-radius:8px; font-size:13px; box-shadow: var(--shadow);
  animation: toast-in .2s ease;
}
.toast.toast-error{ border-color: rgba(193,85,74,0.5); background: var(--danger-soft); color:#f0a89f; }
@keyframes toast-in{ from{ opacity:0; transform: translateY(8px);} to{opacity:1; transform:translateY(0);} }

@media (max-width: 640px){
  .top-bar, .toolbar, .canvas{ padding-left:16px; padding-right:16px; }
  .persist-banner{ margin-left:16px; margin-right:16px; }
  .node-card{ width: 210px; }

  /* The toolbar (back button + search + legend hints/actions) was cramming
     everything into one row on narrow screens, causing it to overlap
     instead of wrapping cleanly. Stack it into clear full-width rows
     instead, and drop the purely informational hint text (what "verified"
     means, how thumbs up/down works) — useful context on desktop, but not
     worth the space when it crowds out tapping "All paths" or the search
     box, which are the controls that actually matter here. */
  .toolbar{ flex-direction: column; align-items: stretch; }
  .toolbar-nav{ width: 100%; flex-wrap: wrap; }
  .search-wrap{ flex: 1 1 auto; max-width: none; }
  .legend{ width: 100%; justify-content: flex-start; }
  .legend-item{ display: none; }
}
