:root {
  --bg-0: #05060a;
  --ink: #dbdff5;
  --muted: #7a7fa0;
  --accent: #9adfff;
  --panel: rgba(14, 16, 28, 0.82);
  --border: rgba(255, 255, 255, 0.06);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #05060a;
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }

header {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  gap: 10px;
  z-index: 10; pointer-events: none;
}
header > * { pointer-events: auto; }
.brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.icon-btn {
  display: none;
  padding: 6px 8px;
  color: var(--ink);
}
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 4; opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.backdrop.open { opacity: 1; pointer-events: auto; }
.brand {
  font-weight: 600; letter-spacing: 0.02em; font-size: 13.5px;
  color: #c4c9ea;
}
.brand .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  margin-right: 8px; vertical-align: middle;
}
.brand .sub { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px;}

.tools { display: flex; gap: 8px; align-items: center; }
.search-wrap { position: relative; }
.results {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: 320px; max-height: 420px; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 6px;
  display: none;
  z-index: 12;
  box-shadow: 0 12px 36px rgba(0,0,0,0.5);
}
.results.open { display: block; }
.results .r-row {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: background .1s;
}
.results .r-row:hover, .results .r-row.focus {
  background: rgba(255,255,255,0.06);
}
.results .r-title {
  font-size: 12.5px; color: var(--ink); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.results .r-meta {
  font-size: 10.5px; color: var(--muted); margin-top: 3px;
  display: flex; gap: 6px; align-items: center;
}
.results .r-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.results .r-empty {
  padding: 16px 12px; font-size: 12px; color: var(--muted); text-align: center;
}
.results .r-count {
  padding: 6px 10px 2px; font-size: 10px; color: var(--muted);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.search {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 7px 14px; font-size: 12.5px;
  border-radius: 999px; width: 220px;
  outline: none;
  transition: border-color .15s, background .15s, width .2s;
}
.search::placeholder { color: #595d7a; }
.search:focus {
  border-color: rgba(154,223,255,0.35);
  background: rgba(154,223,255,0.04);
  width: 260px;
}
.btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 6px 12px; font-size: 12px; border-radius: 999px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.15); }
.help-btn { font-weight: 700; padding: 4px 10px; font-size: 13px; line-height: 1; }

.modal {
  position: fixed; inset: 0; z-index: 30;
  display: none; align-items: center; justify-content: center;
  background: rgba(3, 4, 10, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 32px 20px;
  overflow-y: auto;
}
.modal.open { display: flex; }
.modal-card {
  position: relative; max-width: 620px; width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px 24px;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.modal-card h2 {
  margin: 0 0 10px; font-size: 18px; font-weight: 600;
}
.modal-card h3 {
  margin: 18px 0 8px; font-size: 11px; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.modal-card .lede {
  font-size: 13px; line-height: 1.6; color: #bfc3de; margin: 0 0 4px;
}
.modal-card .lede strong { color: var(--ink); font-weight: 600; }
.modal-card ol.flow, .modal-card ul.flow {
  font-size: 12.5px; line-height: 1.65; color: #bfc3de;
  padding-left: 20px; margin: 0;
}
.modal-card ol.flow li, .modal-card ul.flow li { margin-bottom: 4px; }
.modal-card code {
  font-family: "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 11.5px; padding: 1px 5px; border-radius: 4px;
  background: rgba(255,255,255,0.05); color: var(--accent);
}
.modal-card .foot {
  font-size: 11.5px; color: var(--muted); margin: 20px 0 0;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.modal-card .close {
  position: absolute; top: 14px; right: 18px; cursor: pointer;
  color: var(--muted); font-size: 16px; background: none; border: none;
}
.modal-card .close:hover { color: var(--ink); }

#stage { position: absolute; inset: 0; }
canvas { display: block; }

.legend {
  position: fixed; left: 16px; top: 64px; bottom: 16px;
  width: 252px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 14px 12px 10px;
  overflow-y: auto;
  z-index: 5;
}
.legend h3 {
  margin: 2px 8px 10px; font-size: 10.5px; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.mode-toggle { margin: 0 0 12px; padding: 0 2px 10px; border-bottom: 1px solid var(--border); }
.mode-row { display: flex; gap: 6px; padding: 0 6px; }
.mode-opt {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 8px; font-size: 11.5px; cursor: pointer;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); transition: background .12s, color .12s, border-color .12s;
}
.mode-opt input { accent-color: var(--accent); margin: 0; }
.mode-opt:has(input:checked) { color: var(--ink); background: rgba(154,223,255,0.08); border-color: rgba(154,223,255,0.35); }
.cluster {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 10px;
  cursor: pointer; user-select: none;
  transition: background .12s, opacity .12s;
}
.cluster:hover { background: rgba(255,255,255,0.04); }
.cluster.dim { opacity: 0.28; }
.swatch {
  width: 10px; height: 10px; border-radius: 3px; flex: none;
}
.cluster .label {
  font-size: 12px; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis;
}
.cluster .label .cnt {
  color: var(--muted); font-size: 10.5px; margin-left: 5px;
}
.legend .hint-text {
  font-size: 10.5px; color: var(--muted); padding: 10px 12px 2px;
  line-height: 1.5;
}

.info {
  position: fixed; top: 64px; right: 16px; bottom: 16px;
  width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 20px 22px;
  overflow-y: auto;
  transform: translateX(calc(100% + 24px));
  transition: transform .24s cubic-bezier(.2,.7,.2,1);
  z-index: 5;
}
.info.open { transform: translateX(0); }
.info .close {
  position: absolute; top: 14px; right: 16px; cursor: pointer;
  color: var(--muted); font-size: 16px; background: none; border: none;
}
.info .close:hover { color: var(--ink); }
.info h2 {
  margin: 0 0 8px; font-size: 15.5px; line-height: 1.4; padding-right: 22px;
  font-weight: 600;
}
.info .meta {
  font-size: 11px; color: var(--muted); margin-bottom: 14px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.info .meta .tag {
  border-radius: 999px; padding: 2px 9px; font-size: 10.5px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  text-decoration: none;
}
.info .meta .tag.link { color: var(--accent); border-color: rgba(154,223,255,0.35); }
.info .meta .tag.link:hover { background: rgba(154,223,255,0.08); }
.info .body {
  font-size: 12.5px; line-height: 1.65; color: #bfc3de;
  white-space: pre-wrap;
}

.tip {
  position: fixed; pointer-events: none;
  max-width: 300px;
  background: rgba(8, 9, 18, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 11.5px;
  line-height: 1.45;
  opacity: 0; transition: opacity .12s;
  z-index: 8;
  backdrop-filter: blur(10px);
}
.tip.show { opacity: 1; }
.tip .t-title { font-weight: 600; margin-bottom: 3px; color: var(--ink); font-size: 12px; word-break: break-word; }
.tip .t-team { color: var(--muted); font-size: 10px; margin-bottom: 5px; display: flex; align-items: center; gap: 5px; }
.tip .t-team .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.tip .t-prev { color: #a7acce; font-size: 11px; }

.hint {
  position: fixed; bottom: 18px; right: 18px;
  font-size: 10.5px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 999px;
  z-index: 3;
  transition: opacity .3s;
}
.hint.hidden { opacity: 0; pointer-events: none; }

.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12.5px; letter-spacing: 0.04em;
  z-index: 20; background: #05060a;
  transition: opacity .4s;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading .pulse {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
  margin-right: 10px; vertical-align: middle;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.5; }
}

@media (max-width: 900px) {
  .legend { width: 200px; }
  .info { width: calc(100% - 32px); }
  .search { width: 140px; }
  .search:focus { width: 180px; }
}

@media (max-width: 720px) {
  header { padding: 10px 12px; }
  .brand { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand .sub { display: none; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .search { width: 130px; padding: 6px 12px; font-size: 12px; }
  .search:focus { width: 150px; }
  .btn { padding: 6px 10px; font-size: 11.5px; }

  .legend {
    top: 0; left: 0; bottom: 0; width: 80vw; max-width: 320px;
    border-radius: 0 14px 14px 0;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.2,.7,.2,1);
    padding-top: 54px;
  }
  .legend.open { transform: translateX(0); }

  .info {
    top: 0; right: 0; bottom: 0; width: 100%;
    border-radius: 14px 0 0 14px;
    transform: translateX(100%);
    padding-top: 54px;
  }

  .results { width: calc(100vw - 24px); right: -60px; max-height: 60vh; }
  .hint { display: none; }
}
