:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-card: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #e23636;        /* Marvel red */
  --accent-2: #518cca;      /* hero blue */
  --link: #58a6ff;

  /* 陣營配色 */
  --f-avenger: #518cca;
  --f-villain: #b23a48;
  --f-shield: #2a9d8f;
  --f-civilian: #8b949e;
  --f-military: #6a7f4f;
  --f-mixed: #b08968;
  --f-work: #c9a227;        /* 作品節點金色 */

  /* 關係配色 */
  --r-blood: #d16ba5;
  --r-mentor: #86a8e7;
  --r-lover: #e23636;
  --r-enemy: #8b0000;
  --r-team: #518cca;
  --r-friend: #57cc99;
  --r-hier: #9b8816;
  --r-create: #a367dc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  height: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 頂部導覽 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
  color: var(--text);
  white-space: nowrap;
}
.brand .mark { color: var(--accent); }
.nav { display: flex; gap: 6px; }
.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 14px;
}
.nav a:hover { background: var(--bg-card); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--bg-card); }

.search-wrap { margin-left: auto; position: relative; }
.search-wrap input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 12px;
  width: 240px;
  font-size: 14px;
}
.search-wrap input:focus { outline: none; border-color: var(--accent-2); }
.search-results {
  position: absolute;
  top: 40px;
  right: 0;
  width: 300px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.search-results.show { display: block; }
.search-results .item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.search-results .item:last-child { border-bottom: none; }
.search-results .item:hover { background: var(--bg-soft); }
.search-results .item .sub { color: var(--text-dim); font-size: 12px; }

/* ---------- 頭像圓 ---------- */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex: 0 0 auto;
}
.avatar.work { border-radius: 6px; }

/* ---------- 圖譜頁 ---------- */
.graph-layout { display: flex; height: calc(100vh - 53px); }
.graph-stage { position: relative; flex: 1; height: 100%; overflow: hidden; }
#cy {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 40%, #131a24 0%, var(--bg) 70%);
  opacity: 0;
  transition: opacity 0.5s ease;
}
#cy.ready { opacity: 1; }

/* 點節點才從右側滑出的抽屜（平常不佔空間，覆蓋在圖上） */
.drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 88%;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
  overflow-y: auto;
  padding: 16px 18px 24px;
  transform: translateX(105%);
  transition: transform 0.28s ease;
  z-index: 60;
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.drawer-close:hover { color: var(--text); background: var(--border); }


.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head .avatar { width: 44px; height: 44px; font-size: 16px; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head .hero-name { font-size: 13px; font-weight: 600; color: var(--f-work); margin-top: 2px; }
.panel-head .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  margin-right: 4px;
}
.panel-bio { font-size: 13.5px; line-height: 1.7; color: var(--text); margin: 10px 0 16px; }
.panel-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin: 16px 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.rel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
  font-size: 13.5px;
}
.rel-item:hover { color: var(--link); }
.rel-item .badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 8px;
  color: #fff;
  flex: 0 0 auto;
}
.panel-actions { margin-top: 16px; }
.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  border: none;
  cursor: pointer;
}
.btn:hover { background: #c92c2c; text-decoration: none; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn.ghost:hover { background: var(--bg-card); }

/* ---------- 圖譜控制列 ---------- */
.graph-controls {
  position: absolute;
  top: 68px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.graph-controls .ctl {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.graph-controls .ctl:hover { border-color: var(--accent-2); }

.legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: rgba(22,27,34,0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11.5px;
  z-index: 50;
  max-width: 260px;
}
.legend h4 { margin: 0 0 6px; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.legend .row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.legend .line { width: 16px; height: 3px; border-radius: 2px; flex: 0 0 auto; }
.legend-cols { display: flex; gap: 16px; }

/* ---------- 時間線頁 ---------- */
.page { max-width: 1000px; margin: 0 auto; padding: 28px 20px 60px; }
.page h1 { font-size: 24px; margin: 0 0 6px; }
.page .lead { color: var(--text-dim); margin: 0 0 28px; font-size: 14px; }

.timeline { position: relative; margin-left: 20px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.tl-item { position: relative; padding: 0 0 26px 32px; }
.tl-item::before {
  content: "";
  position: absolute;
  left: -7px; top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--f-work);
  border: 3px solid var(--bg);
}
.tl-phase-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 1px;
  margin: 8px 0 14px -32px;
  padding-left: 0;
}
.tl-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.tl-card:hover { border-color: var(--accent-2); }
.tl-card .yr { color: var(--f-work); font-weight: 700; font-size: 13px; }
.tl-card h3 { margin: 4px 0 6px; font-size: 17px; }
.tl-card .en { color: var(--text-dim); font-size: 12px; font-weight: 400; }
.tl-card p { margin: 6px 0 0; font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.tl-card .cast { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.tl-card .cast .mini {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-dim);
}

/* ---------- 詳情頁 ---------- */
.detail-head { display: flex; align-items: center; gap: 18px; margin-bottom: 10px; }
.detail-head .avatar { width: 64px; height: 64px; font-size: 24px; }
.detail-head h1 { margin: 0; font-size: 26px; }
.detail-head .en { color: var(--text-dim); font-size: 15px; margin-top: 4px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 24px; }
@media (max-width: 720px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.detail-section h3 { margin: 0 0 12px; font-size: 14px; color: var(--text); }
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 14px;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { color: var(--link); }
.list-row .badge { font-size: 11px; padding: 1px 8px; border-radius: 8px; color: #fff; flex: 0 0 auto; }
.list-row .note { color: var(--text-dim); font-size: 12px; margin-left: auto; }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--text-dim); font-size: 13px; }

.report-box {
  margin-top: 28px;
  padding: 14px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.loading { color: var(--text-dim); padding: 40px; text-align: center; }

/* ---------- 頁尾 disclaimer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.6;
  padding: 16px 20px;
  text-align: center;
}
.site-footer a { color: var(--text-dim); text-decoration: underline; }
/* 圖譜頁（全螢幕）用浮在角落的小字版 */
.footer-float {
  position: absolute;
  bottom: 8px;
  right: 14px;
  max-width: 46%;
  text-align: right;
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 1.5;
  opacity: 0.7;
  z-index: 40;
  pointer-events: none;
}
