/* fedi-map. Dark by default: a force graph is mostly empty space, and light
   backgrounds wash out the thin edges that carry most of the structure. */

:root {
  --bg: #0b0e14;
  --panel: #141a24;
  --line: #232c3b;
  --fg: #dfe6f0;
  --dim: #8794a8;
  --accent: #4fc3f7;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#graph {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* The highlight layer sits over the WebGL canvas and carries the selection
   halo and live-activity ripples. It never takes input: clicks belong to the
   map underneath. The z-index matters: cosmos.gl re-appends its canvas when
   its device finishes initialising, which would otherwise lift that opaque
   canvas back over this one. */
#highlight-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ---------------------------------------------------------------- top bar */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(11, 14, 20, 0.92), rgba(11, 14, 20, 0));
  pointer-events: none;
  z-index: 5;
}
#topbar > * { pointer-events: auto; }

#topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#search-wrap { position: relative; }

#search {
  width: 260px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(20, 26, 36, 0.9);
  color: var(--fg);
  font: inherit;
}
#search:focus { outline: none; border-color: var(--accent); }

#results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
#results li {
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
#results li:hover, #results li[aria-selected="true"] { background: #1d2634; }
#results .meta { color: var(--dim); font-variant-numeric: tabular-nums; }

#stats { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ detail panel */

#panel {
  position: fixed;
  top: 56px;
  right: 14px;
  width: 300px;
  max-height: calc(100vh - 190px);
  overflow-y: auto;
  padding: 14px 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 6;
}
#panel h2 { margin: 0 26px 10px 0; font-size: 15px; word-break: break-all; }
#panel h3 { margin: 16px 0 6px; font-size: 11px; text-transform: uppercase;
            letter-spacing: 0.08em; color: var(--dim); }

#panel-close {
  position: absolute; top: 8px; right: 8px;
  width: 24px; height: 24px;
  border: 0; border-radius: 4px;
  background: transparent; color: var(--dim);
  font-size: 18px; line-height: 1; cursor: pointer;
}
#panel-close:hover { background: #1d2634; color: var(--fg); }

#panel-meta { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
#panel-meta dt { color: var(--dim); }
#panel-meta dd { margin: 0; font-variant-numeric: tabular-nums; }

#panel-edges { margin: 0; padding-left: 18px; }
#panel-edges li { cursor: pointer; word-break: break-all; }
#panel-edges li:hover { color: var(--accent); }
#panel-edges .w { color: var(--dim); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- timeline */

#timeline {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 8px 14px 12px;
  background: linear-gradient(0deg, rgba(11, 14, 20, 0.95), rgba(11, 14, 20, 0.75) 70%, rgba(11, 14, 20, 0));
  z-index: 5;
}

#spark-wrap { position: relative; height: 46px; margin-bottom: 6px; }
#spark { width: 100%; height: 100%; display: block; }
#spark-cursor {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--accent); pointer-events: none;
}

#controls { display: flex; align-items: center; gap: 10px; }

#controls button, #controls select {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
#controls button:hover:not(:disabled), #controls select:hover { border-color: var(--accent); }
#controls button:disabled { opacity: 0.4; cursor: default; }
#play { width: 36px; }

#slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

#date {
  min-width: 92px;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

/* ----------------------------------------------------------------- loading */

#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
  color: var(--dim);
  z-index: 20;
}
#loading[hidden] { display: none; }

.spin {
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 3s; }
}

/* ------------------------------------------------------------- live feed */

/* The badge is the only place the live layer says anything in words. It has
   to distinguish three states an idle map cannot: connected and quiet,
   connected but scrubbed into the past, and not connected at all. */
#activity {
  margin-left: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  white-space: nowrap;
  max-width: 26ch;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--dim);
}

#activity.on {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}

/* Scrubbed away from the present: the feed is fine, the map just is not
   showing now, and the badge should not look like an error. */
#activity.paused { color: var(--dim); }

#activity.off {
  color: #d98c8c;
  border-color: #4a2c2c;
}

/* ---------------------------------------------------- control popovers */

.control-popover {
  position: absolute;
  right: 12px;
  bottom: 46px;
  width: 220px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Author display rules outrank the browser's built-in [hidden] rule. Without
   this, toggling HTMLElement.hidden changes state but leaves a flex popover
   painted on screen. */
.control-popover[hidden] { display: none; }

#settings label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--dim);
}

#settings output { color: var(--fg); float: right; }

#settings input[type="range"] { width: 100%; accent-color: var(--accent); }

#settings button {
  margin-top: 2px;
  padding: 4px;
  font-size: 11px;
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

#settings button:hover { color: var(--fg); }

#legend { width: 260px; }

#legend strong { font-size: 12px; }

#legend-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin: 7px 0;
}

#legend-mode button {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font: inherit;
}

#legend-mode button[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--fg);
}

#legend p {
  margin: 0;
  color: var(--dim);
  font-size: 11px;
  line-height: 1.35;
  min-height: 3em;
}

#legend-items {
  margin: 0;
  padding: 0;
  max-height: min(42vh, 320px);
  overflow-y: auto;
  list-style: none;
}

#legend-items li {
  margin: 0;
  padding: 0;
}

#legend-items li button {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 2px 3px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

#legend-items li button:hover,
#legend-items li button:focus-visible {
  background: color-mix(in srgb, var(--fg) 8%, transparent);
  outline: none;
}

#legend-items li button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

#legend-items.filtering li button[aria-pressed="false"] {
  opacity: 0.42;
}

#legend-items .swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

#legend-items .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#legend-items .count {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
