/* Apes Tree — matches the homoapes.com (Landed) palette */
:root {
  --bg: #1c1d26;
  --panel: #272833;
  --panel-2: #30313f;
  --line: #3b3d4f;
  --text: #f2f2f5;
  --muted: #9b9db2;
  --accent: #e44c65;
  --font: Roboto, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.4 var(--font);
}

button { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
/* Second bar under the site nav: title, stats, search, layout */
.topbar {
  position: relative;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  padding: 9px 20px;
  background: #21222c;
  border-bottom: 1px solid var(--line);
}

.page-title {
  margin: 0;
  color: var(--text);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: .3px;
  white-space: nowrap;
}

.stats { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; }
.stats b { color: var(--text); font-weight: 500; }

.tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px 0 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  transition: border-color .15s;
}
.search:focus-within { border-color: var(--accent); }
.search input {
  width: 170px;
  min-width: 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font: 400 14px var(--font);
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search .count { font-size: 12px; white-space: nowrap; }
.search .clear {
  width: 22px; height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.search .clear:hover { color: var(--text); }

.seg {
  display: flex;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.seg button {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle, rgba(255, 255, 255, .07) 1px, transparent 1.6px);
  background-size: 26px 26px;
}

#tree {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.stage.dragging #tree { cursor: grabbing; }

/* ---------- Tree: links ---------- */
.link {
  fill: none;
  stroke: var(--cl);
  stroke-width: 2;
  transition: opacity .2s, stroke .2s;
}
.link.chain { stroke: var(--c); stroke-width: 3; }
.link.dim { opacity: .18; }

/* ---------- Tree: nodes ---------- */
.node { cursor: pointer; outline: none; transition: opacity .2s; }
.node.dim { opacity: .28; }

.node .card {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 1;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .35));
  transition: fill .15s, stroke .15s;
}
.node:hover .card { fill: var(--panel-2); stroke: var(--c); }
.node:focus-visible .card { stroke: #fff; stroke-width: 2; }
.node.selected .card { fill: var(--panel-2); stroke: var(--c); stroke-width: 2; }
.node.match .card { stroke: var(--accent); stroke-width: 2.5; }
.node.is-root .card { stroke: var(--accent); stroke-width: 1.5; }

.node .avatar { fill: var(--c); fill-opacity: .16; stroke: var(--c); stroke-width: 1.5; }
.node .initial {
  fill: var(--c);
  font: 700 14px var(--font);
  text-anchor: middle;
  dominant-baseline: central;
}
.node .name { fill: var(--text); font: 500 14px var(--font); }
.node .date { fill: var(--muted); font: 400 11px var(--font); }

.badge { cursor: pointer; outline: none; }
.badge rect { fill: var(--bg); stroke: var(--c); stroke-width: 1.5; transition: fill .15s; }
.badge text {
  fill: var(--c);
  font: 700 11px var(--font);
  text-anchor: middle;
  dominant-baseline: central;
}
.badge:hover rect, .badge:focus-visible rect { stroke-width: 2.5; }
.badge.collapsed rect { fill: var(--c); }
.badge.collapsed text { fill: var(--bg); }

/* ---------- Floating controls ---------- */
.controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.controls button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  transition: border-color .15s, color .15s;
}
.controls button:hover { border-color: var(--accent); color: var(--accent); }
.controls hr { width: 24px; height: 1px; margin: 2px auto; border: 0; background: var(--line); }

.hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 1;
  margin: 0;
  padding: 6px 14px;
  transform: translateX(-50%);
  background: rgba(39, 40, 51, .9);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .8s;
}
.hint.faded { opacity: 0; }

/* ---------- Details panel ---------- */
.info {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 3;
  width: 330px;
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--c, var(--accent));
  border-radius: 16px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .5);
}
.info[hidden] { display: none; }

.info-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.info-close:hover { background: var(--bg); color: var(--text); }

.info-head { display: flex; align-items: center; gap: 12px; padding-right: 26px; }
.info-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  overflow: hidden;
  border: 2px solid var(--c);
  border-radius: 50%;
  color: var(--c);
  font-size: 19px;
  font-weight: 700;
}
.info-avatar img { width: 100%; height: 100%; object-fit: cover; }
.info h3 { margin: 0; font-size: 19px; font-weight: 500; overflow-wrap: anywhere; }
.info-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.info-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 4px; }
.info-stats div { padding: 8px 10px; background: var(--bg); border-radius: 10px; }
.info-stats dt { color: var(--muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
.info-stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 500; }

.info-label {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.info-discord { margin: 1px 0 0; color: var(--muted); font-size: 12px; opacity: .8; }

/* "How we met" bio; admins get an editor (apes-tree.js bioSection/bioEdit) */
.bio-label { display: flex; align-items: center; justify-content: space-between; }
.bio-text { margin: 0; color: var(--text); font-size: 14px; line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }
.bio-meta { margin: 6px 0 0; color: var(--muted); font-size: 11.5px; }
.bio-empty { margin: 0; color: var(--muted); font-size: 13.5px; font-style: italic; }
.bio-edit, .bio-save, .bio-cancel {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: 500 11.5px var(--font);
  letter-spacing: normal;
  text-transform: none;
  cursor: pointer;
}
.bio-edit:hover, .bio-cancel:hover { border-color: var(--c, var(--accent)); }
.bio-input {
  display: block;
  width: 100%;
  min-height: 120px;
  max-height: 40vh;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--font);
  resize: vertical;
}
.bio-input:focus { outline: none; border-color: var(--c, var(--accent)); }
.bio-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.bio-count { margin-right: auto; color: var(--muted); font-size: 11.5px; }
.bio-save, .bio-cancel { padding: 7px 14px; font-size: 13px; }
.bio-save { border-color: var(--accent); background: var(--accent); color: #fff; }
.bio-save:hover { background: #d43b55; }
.bio-save:disabled, .bio-cancel:disabled { opacity: .6; cursor: default; }
.bio-msg { margin: 6px 0 0; color: #ff8a9c; font-size: 12.5px; }
.bio-msg:empty { display: none; }
.chain, .chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chain .sep { color: var(--muted); }
.chain .me { font-size: 13px; font-weight: 500; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip:hover { border-color: var(--c); }

/* ---------- Loading / errors ---------- */
.status {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
.status[hidden] { display: none; }
.status.error { color: #ff9aaa; pointer-events: auto; user-select: text; }
.status code { color: var(--text); }

/* ---------- Phones ---------- */
@media (max-width: 720px) {
  .topbar { gap: 8px 12px; padding: 8px 12px; }
  .page-title { font-size: 17px; }
  .stats { margin-left: auto; font-size: 12px; }
  .tools { width: 100%; margin-left: 0; }
  .search { flex: 1; }
  .search input { width: 100%; }

  .info {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 55%;
  }
  .stage.has-info .controls,
  .stage.has-info .hint { display: none; }
  .controls { right: 10px; bottom: 10px; }
  .hint { bottom: 10px; }
}

/* ---------- Short screens (phones sideways) ---------- */
@media (max-height: 520px) {
  .topbar { flex-wrap: nowrap; gap: 12px; padding: 6px 12px; }
  .page-title { font-size: 17px; }
  .stats, .hint { display: none; }
  .tools { width: auto; margin-left: auto; }
  .search { height: 34px; }
  .search input { width: 150px; }
  .controls { flex-direction: row; right: 10px; bottom: 10px; }
  .controls hr { display: none; }
  .controls button { width: 38px; height: 38px; }
  .info { max-height: calc(100% - 16px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
