:root {
  --bg: #14110f;
  --bg-panel: #1c1815;
  --bg-raised: #241f1a;
  --border: #3a332a;
  --text: #e8e0d0;
  --text-dim: #a89a82;
  --text-faint: #7a6d5b;
  --accent: #c8963e;
  --accent-bright: #e8b458;
  --link: #d9a851;

  --cat-character: #c8963e;
  --cat-place: #4f9e8c;
  --cat-event: #b5474a;
  --cat-race: #8b6fc9;
  --cat-monster: #a24444;
  --cat-landmark: #5a89b8;
  --cat-mechanic: #4fa3a3;
  --cat-info: #8a8478;
  --cat-settlement: #d1885a;
  --cat-state: #c45f8a;
  --cat-geography: #5fa85e;
  --cat-organization: #6a7fc9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Georgia, "Palatino Linotype", serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(180deg, #201b16, #171310);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
}

.brand-glyph {
  color: var(--accent-bright);
  font-size: 22px;
}

.brand-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.brand-title em {
  font-style: italic;
  color: var(--text-dim);
  font-weight: 400;
  font-size: 16px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

#searchInput {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 20px;
  width: 260px;
  font-size: 14px;
  outline: none;
}

#searchInput:focus {
  border-color: var(--accent);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
}

.view-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 8px 18px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

.view-btn.active {
  background: var(--accent);
  color: #1a1510;
  font-weight: 600;
}

/* ---------- Category filter bar ---------- */

.category-bar {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.cat-chip {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  padding: 5px 13px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cat-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.cat-chip.active {
  color: var(--text);
  border-color: var(--accent);
  background: #2c2419;
}

/* ---------- Views ---------- */

.view {
  flex: 1;
  min-height: 0;
  display: flex;
}

.view.hidden {
  display: none;
}

/* ---------- Browse: sidebar ---------- */

.sidebar {
  width: 340px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
}

.sidebar-count {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}

.entity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.entity-item {
  padding: 10px 16px;
  border-bottom: 1px solid #2a2520;
  cursor: pointer;
}

.entity-item:hover {
  background: var(--bg-raised);
}

.entity-item.selected {
  background: #2c2419;
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.entity-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.entity-item-desc {
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.entity-item-badge {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 7px;
  border-radius: 8px;
  margin-bottom: 5px;
  color: #14110f;
  font-weight: 700;
}

/* ---------- Detail panel ---------- */

.detail {
  flex: 1;
  overflow-y: auto;
  padding: 30px 44px;
}

.empty-state {
  color: var(--text-faint);
  font-style: italic;
  margin-top: 60px;
  text-align: center;
}

.detail-header {
  margin-bottom: 18px;
}

.detail-badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 3px 10px;
  border-radius: 10px;
  color: #14110f;
  font-weight: 700;
  margin-bottom: 10px;
}

.detail-title {
  font-size: 30px;
  margin: 0 0 6px 0;
  color: var(--accent-bright);
  font-weight: 600;
}

.detail-folder {
  color: var(--text-faint);
  font-size: 13px;
}

.detail-description {
  font-size: 16px;
  color: var(--text-dim);
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 20px 0;
  font-style: italic;
}

.character-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 18px 0 26px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--border);
}

.character-facts-title {
  color: var(--text);
  font-size: 18px;
  margin: 24px 0 10px;
}

.character-fact {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 13px 15px;
  background: var(--bg-panel);
}

.character-fact-label {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
}

.character-fact-value {
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.source-facts {
  margin: 24px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

.source-facts summary {
  cursor: pointer;
  color: var(--accent-bright);
  font-weight: 600;
}

.detail-content p {
  line-height: 1.7;
  font-size: 15px;
  margin: 0 0 14px 0;
}

.detail-content h2,
.detail-content h3,
.detail-content h4 {
  color: var(--text);
  margin: 24px 0 10px;
  line-height: 1.3;
}

.detail-content h3 { font-size: 17px; }
.detail-content h4 { font-size: 15px; }

.detail-content ul,
.detail-content ol {
  margin: 0 0 18px;
  padding-left: 26px;
  line-height: 1.65;
}

.detail-content li { margin-bottom: 8px; }

.article-table-wrap {
  overflow-x: auto;
  margin: 16px 0 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.detail-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.detail-content th,
.detail-content td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.detail-content th { color: var(--text); background: var(--bg-panel); }
.detail-content tr:last-child td { border-bottom: 0; }

.family-tree-note {
  margin: -2px 0 12px;
  color: var(--text-faint);
  font-size: 12px;
}

.family-chart-shell {
  height: min(620px, 68vh);
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel);
}

.family-chart-shell .f3 {
  width: 100%;
  height: 100%;
  color: var(--text);
  background: var(--bg-panel);
  --background-color: var(--bg-panel);
  --text-color: var(--text);
  --male-color: #243b45;
  --female-color: #45303b;
  --genderless-color: #333743;
}

.family-chart-shell .f3 .card-main-outline {
  stroke: var(--accent-bright);
}

.family-chart-shell .f3 .card-male,
.family-chart-shell .f3 .card-female,
.family-chart-shell .f3 .card-genderless .card-body-rect {
  stroke: var(--border);
  stroke-width: 1.5px;
}

.family-chart-shell .f3 .card-inner {
  cursor: pointer;
}

.section-block {
  margin: 26px 0;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  margin: 0 0 10px 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.attr-list {
  margin: 0;
  padding-left: 20px;
}

.attr-list li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.attr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.attr-table th, .attr-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}

.attr-table th {
  background: var(--bg-raised);
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
}

.attr-table tr:nth-child(even) td {
  background: #201c17;
}

.entity-link {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dotted var(--link);
  cursor: pointer;
}

.entity-link:hover {
  color: var(--accent-bright);
}

.connections-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.connection-chip {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.connection-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.connection-chip:hover {
  border-color: var(--accent);
}

/* ---------- Global docked chronicle ---------- */

.timeline-dock {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  height: 286px;
  border-top: 1px solid #5a4830;
  background: linear-gradient(180deg, #201b16 0%, #15120f 100%);
  box-shadow: 0 -12px 36px #0009;
  transition: transform 260ms cubic-bezier(.2,.75,.25,1);
}

.timeline-dock.is-collapsed { transform: translateY(calc(100% - 46px)); }

.timeline-dock-bar {
  display: flex;
  min-height: 52px;
  align-items: center;
  gap: 12px;
  padding: 7px 14px 7px 20px;
  border-bottom: 1px solid var(--border);
}

.timeline-dock-toggle {
  display: flex;
  min-width: 300px;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.timeline-dock-chevron {
  display: grid;
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--accent-bright);
  transition: transform 220ms ease;
}

.timeline-dock.is-collapsed .timeline-dock-chevron { transform: rotate(180deg); }

.timeline-dock-brand {
  color: var(--accent-bright);
  font-size: 12px;
  letter-spacing: 1.4px;
  white-space: nowrap;
}

.timeline-dock-brand b { color: var(--text); font-weight: 600; }

.timeline-dock-count,
.timeline-dock-hint,
.timeline-window {
  color: var(--text-faint);
  font-size: 11px;
  white-space: nowrap;
}

.timeline-dock-count { font-variant-numeric: tabular-nums; }
.timeline-dock-hint { overflow: hidden; text-overflow: ellipsis; }

.timeline-controls {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.timeline-controls input,
.timeline-controls select,
.timeline-controls button {
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #211c17;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
}

.timeline-controls input,
.timeline-controls select { padding: 0 9px; }
.timeline-controls select { max-width: 150px; }
.timeline-controls input[type="search"] { width: 174px; }
.timeline-controls input[type="number"] { width: 82px; }

.timeline-controls button {
  min-width: 31px;
  padding: 0 9px;
  cursor: pointer;
}

.timeline-controls button:hover,
.timeline-controls input:focus,
.timeline-controls select:focus {
  border-color: var(--accent);
  color: var(--accent-bright);
  outline: none;
}

.timeline-controls #timelineFit { white-space: nowrap; }
.timeline-control-divider { width: 1px; height: 22px; margin: 0 3px; background: var(--border); }
.timeline-window { margin-left: 6px; font-variant-numeric: tabular-nums; }

.timeline-canvas {
  min-height: 0;
  flex: 1;
  padding: 0 10px 6px;
  background: #171411;
}

.timeline-dock.is-collapsed .timeline-canvas,
.timeline-dock.is-collapsed .timeline-controls { visibility: hidden; }

.timeline-canvas .vis-timeline {
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: "Segoe UI", Georgia, serif;
}

.timeline-canvas .vis-panel.vis-center,
.timeline-canvas .vis-panel.vis-background,
.timeline-canvas .vis-panel.vis-left,
.timeline-canvas .vis-panel.vis-right {
  background: #171411;
}

.timeline-canvas .vis-time-axis .vis-text { color: var(--text-faint); }
.timeline-canvas .vis-time-axis .vis-grid.vis-minor { border-color: #302a22; }
.timeline-canvas .vis-time-axis .vis-grid.vis-major { border-color: #554630; }
.timeline-canvas .vis-labelset .vis-label { border-color: #302a22; color: var(--text-dim); }
.timeline-canvas .vis-foreground .vis-group { border-color: #302a22; }
.timeline-canvas .vis-item { border-radius: 4px; font-size: 10px; box-shadow: 0 2px 7px #0006; }
.timeline-canvas .vis-item .vis-item-content { padding: 2px 5px; }
.timeline-canvas .vis-item.gaia-event-character { border-color: #c8963e; background: #4a351c; color: #f5d28d; }
.timeline-canvas .vis-item.gaia-event-event { border-color: #b5474a; background: #4b2527; color: #f0a4a0; }
.timeline-canvas .vis-item.gaia-event-place,
.timeline-canvas .vis-item.gaia-event-settlement,
.timeline-canvas .vis-item.gaia-event-geography,
.timeline-canvas .vis-item.gaia-event-landmark { border-color: #4f9e8c; background: #1c3934; color: #a6d8ce; }
.timeline-canvas .vis-item.gaia-event-state,
.timeline-canvas .vis-item.gaia-event-organization { border-color: #6a7fc9; background: #252d4b; color: #bbc8ff; }
.timeline-canvas .vis-item.gaia-event-race,
.timeline-canvas .vis-item.gaia-event-culture { border-color: #8b6fc9; background: #33284a; color: #d0bfff; }
.timeline-canvas .vis-item.gaia-event-monster { border-color: #a24444; background: #462020; color: #ffb2a8; }
.timeline-canvas .vis-item.gaia-event-info,
.timeline-canvas .vis-item.gaia-event-mechanic { border-color: #7a8b84; background: #28332e; color: #c2d3cb; }
.timeline-canvas .vis-item.vis-cluster { border: 1px solid var(--accent-bright); background: #4a351c; color: #ffe0a0; font-weight: 700; }
.timeline-canvas .vis-item.vis-selected { border-width: 2px; box-shadow: 0 0 0 2px #e8b45888, 0 3px 12px #0009; }

@media (prefers-reduced-motion: reduce) {
  .timeline-dock, .timeline-dock-chevron { transition: none; }
}

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

@media (max-width: 760px) {
  .sidebar { width: 100%; }
  main#browseView { flex-direction: column; }
  .detail { padding: 20px; }
  .timeline-dock { height: 300px; }
  .timeline-dock-bar { flex-wrap: wrap; gap: 5px 10px; padding: 5px 9px; }
  .timeline-dock-toggle { min-width: 0; width: auto; flex: 1; }
  .timeline-dock-hint { display: none; }
  .timeline-controls { min-width: 100%; justify-content: flex-start; }
  .timeline-controls input[type="search"] { width: min(34vw, 174px); }
  .timeline-window { display: none; }
  .timeline-canvas { padding: 0 4px 4px; }
}

@media (max-width: 1100px) {
  .timeline-dock-hint { display: none; }
  .timeline-window { display: none; }
}
