:root {
  --bg: #0e0f13;
  --bg-elev: #15171d;
  --bg-elev-2: #1c1f27;
  --border: #2a2e38;
  --border-strong: #3a4050;
  --text: #e6e8ee;
  --text-dim: #9aa1b1;
  --text-faint: #6c7385;
  --accent: #f5c518;
  --accent-dim: #b89610;
  --movie: #4ea1ff;
  --tv: #a47bff;
  --person: #c8ced8;
  --circle: #ff7a45;
  --danger: #ff5a5a;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}

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

button { font-family: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar {
  min-height: 56px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.btn-toggle-sidebar svg {
  width: 18px;
  height: 18px;
  display: block;
}
.brand h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand-sub {
  color: var(--text-faint);
  font-size: 12px;
}
.brand-dot {
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(245, 197, 24, 0.6);
}
.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.header-controls {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 2px;
}

.header-controls::-webkit-scrollbar {
  height: 6px;
}
.header-controls::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}

.inline-field,
.inline-checkbox,
.overlay-toggle,
button {
  flex: 0 0 auto;
}

.inline-field {
  white-space: nowrap;
}
/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100% - 56px);
  transition: grid-template-columns 0.25s ease;
}
.layout.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  transition: opacity 0.15s ease, padding 0.25s ease;
}
.layout.sidebar-collapsed .sidebar {
  opacity: 0;
  padding-left: 0;
  padding-right: 0;
  pointer-events: none;
  border-right-width: 0;
}

/* ---------- Modern scrollbars (sidebar, detail panel, suggestions) ---------- */
.sidebar,
.detail-panel,
.suggestions {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.sidebar::-webkit-scrollbar,
.detail-panel::-webkit-scrollbar,
.suggestions::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.sidebar::-webkit-scrollbar-track,
.detail-panel::-webkit-scrollbar-track,
.suggestions::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb,
.detail-panel::-webkit-scrollbar-thumb,
.suggestions::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background 0.15s;
}
.sidebar:hover::-webkit-scrollbar-thumb,
.detail-panel:hover::-webkit-scrollbar-thumb,
.suggestions:hover::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  background-clip: padding-box;
}
.sidebar::-webkit-scrollbar-thumb:hover,
.detail-panel::-webkit-scrollbar-thumb:hover,
.suggestions::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
  background-clip: padding-box;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elev-2);
  padding: 4px;
  border-radius: var(--radius);
}
.tab {
  flex: 1;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel.hidden { display: none; }

.panel-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.search-box {
  position: relative;
}
.search-box input {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s;
}
.search-box input:focus { border-color: var(--accent); }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow);
  display: none;
}
.suggestions.open { display: block; }
.suggestions-header {
  padding: 6px 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.suggestions-header button {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 10.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
}
.suggestions-header button:hover { color: var(--accent); }
.suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.suggestion:last-child { border-bottom: none; }
.suggestion:hover, .suggestion.focused { background: rgba(255,255,255,0.04); }
.suggestion img {
  width: 32px;
  height: 48px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}
.suggestion-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.suggestion-title {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggestion-sub {
  font-size: 11.5px;
  color: var(--text-faint);
}

.chips {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 4px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.chip img {
  width: 28px;
  height: 42px;
  border-radius: 3px;
  object-fit: cover;
  background: var(--bg);
}
.chip-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-sub {
  color: var(--text-faint);
  font-size: 11.5px;
  margin-left: 6px;
}
.chip-remove {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}
.chip-remove:hover { color: var(--danger); }

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.inline-field input {
  width: 56px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  outline: none;
}
.inline-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.primary-btn {
  background: var(--accent);
  color: #1a1300;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.primary-btn:hover:not(:disabled) { background: #ffd633; }
.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: all 0.15s;
}
.ghost-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.legend {
  margin-top: auto;
  padding: 12px;
  background: var(--bg-elev-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.legend h3 {
  margin: 0 0 8px 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  font-weight: 600;
}
.legend h3.legend-sub { margin-top: 12px; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--text-dim);
}
.legend-note {
  font-size: 11.5px;
  color: var(--text-faint);
  font-style: italic;
  margin-top: 4px;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-movie { background: var(--movie); }
.dot-tv { background: var(--tv); }
.dot-person { background: var(--person); }
.dot-circle {
  background: var(--circle);
  box-shadow: 0 0 0 2px rgba(255, 122, 69, 0.25);
}
.dash {
  width: 18px;
  height: 2px;
  border-radius: 2px;
  flex-shrink: 0;
}
.dash-cast            { background: rgba(200, 206, 216, 0.45); }
.dash-director        { background: rgba(78, 161, 255, 0.9); }
.dash-writer          { background: rgba(164, 123, 255, 0.9); }
.dash-producer        { background: rgba(255, 170, 80, 0.9); }
.dash-composer        { background: rgba(80, 200, 160, 0.9); }
.dash-cinematographer { background: rgba(255, 120, 180, 0.9); }

/* ---------- Canvas ---------- */
.canvas-wrap {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 20%, rgba(78, 161, 255, 0.04), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(164, 123, 255, 0.04), transparent 50%),
    var(--bg);
}

/* ---------- Welcome overlay ---------- */
.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
  padding: 24px;
}
.welcome.hidden { display: none; }
.welcome-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 580px;
  width: 100%;
  pointer-events: auto;
  box-shadow: var(--shadow);
}
.welcome-card h2 {
  margin: 0 0 6px 0;
  font-size: 19px;
  font-weight: 600;
}
.welcome-sub {
  margin: 0 0 18px 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.5;
}
.samples {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sample-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sample-card:hover {
  border-color: var(--accent);
  background: rgba(245, 197, 24, 0.05);
}
.sample-card strong {
  font-size: 13.5px;
  font-weight: 600;
}
.sample-card span {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}
.sample-card .sample-mode {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  margin-top: 4px;
}
#graph {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#graph:active { cursor: grabbing; }

.canvas-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.status {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  min-height: 16px;
  pointer-events: auto;
  max-width: 60%;
}
.status.busy {
  color: var(--accent);
  border-color: var(--accent-dim);
}
.status.error {
  color: var(--danger);
  border-color: var(--danger);
}
.hint {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--text-faint);
  pointer-events: auto;
}
.overlay-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}
.overlay-controls .primary-btn {
  padding: 6px 14px;
  font-size: 12.5px;
}
.overlay-toggle {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-dim);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.overlay-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.overlay-toggle input {
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Hide solo cast — graph filter. Person nodes that are NOT recurring collaborators
   and the links to them are hidden. Title nodes always stay. */
#graph.hide-solo .node-person:not(.circle-member) { display: none; }
#graph.hide-solo .link.solo-link { display: none; }

/* graph node/link styles */
.node-title circle, .node-person circle {
  stroke: rgba(255,255,255,0.12);
  stroke-width: 1.5;
  cursor: pointer;
  transition: stroke-width 0.15s, stroke 0.15s;
}
/* color fills act as fallbacks — overridden by inline pattern fill when a photo exists */
.node-title.movie circle { fill: var(--movie); }
.node-title.tv circle { fill: var(--tv); }
.node-person circle { fill: var(--person); }
.node-person.circle-member circle {
  fill: var(--circle);
  stroke: rgba(255, 122, 69, 0.5);
  stroke-width: 2.5;
}
/* photo nodes get a colored ring matching their type */
.node.has-image circle { stroke-width: 2.5; }
.node-title.has-image.movie circle { stroke: var(--movie); }
.node-title.has-image.tv circle { stroke: var(--tv); }
.node-person.has-image circle { stroke: rgba(255,255,255,0.3); }
.node-person.has-image.circle-member circle {
  stroke: var(--circle);
  stroke-width: 3.5;
}
.node:hover circle {
  stroke: var(--text);
  stroke-width: 3.5;
}
/* Multi-select: bright accent ring on selected nodes. Sits on top of the
   per-type stroke so the role/type signal is preserved. */
.node.selected circle {
  stroke: var(--accent) !important;
  stroke-width: 4.5 !important;
  filter: drop-shadow(0 0 6px rgba(245, 197, 24, 0.55));
}
/* While a selection is active, fade out every node that is neither selected
   nor a direct neighbor of the selection. Selected nodes get the bright
   accent ring (above); their immediate neighbors keep full brightness too so
   the user can see the local circle. Everything further out dims to 0.18.
   Hovering any faded node temporarily restores it for peeking. */
.graph-has-selection .node:not(.selected):not(.neighbor) {
  opacity: 0.18;
  transition: opacity 0.12s ease;
}
.graph-has-selection .node:not(.selected):not(.neighbor):hover {
  opacity: 1;
}
.node text {
  fill: var(--text);
  font-size: 11px;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 4px rgba(0,0,0,0.6);
}
.node-title text {
  font-size: 12px;
  font-weight: 600;
}

/* Role-specific link colors. The default (cast) is a faint neutral; the others
   are saturated so creative roles read at a glance. Multi-role pairs render as
   parallel offset lines, one per role. */
.link {
  stroke: rgba(200, 206, 216, 0.25);
  stroke-width: 1;
  fill: none;
}
.link[data-role="cast"]            { stroke: rgba(200, 206, 216, 0.22); }
.link[data-role="director"]        { stroke: rgba(78, 161, 255, 0.65); stroke-width: 1.3; }
.link[data-role="writer"]          { stroke: rgba(164, 123, 255, 0.65); stroke-width: 1.3; }
.link[data-role="producer"]        { stroke: rgba(255, 170, 80, 0.65); stroke-width: 1.3; }
.link[data-role="composer"]        { stroke: rgba(80, 200, 160, 0.65); stroke-width: 1.3; }
.link[data-role="cinematographer"] { stroke: rgba(255, 120, 180, 0.65); stroke-width: 1.3; }

/* Click-emphasis. Stroke color is left alone so the per-role color stays visible
   — we only thicken the line and force full opacity. */
.link.highlight {
  stroke-width: 2.6 !important;
  stroke-opacity: 1 !important;
}
.link.dimmed {
  stroke-opacity: 0.12 !important;
}

/* ---------- Detail panel ---------- */
.detail-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 300px;
  max-height: calc(100% - 24px);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 10;
  overflow-y: auto;
}
.detail-panel.hidden { display: none; }
.detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
}
.detail-close:hover { color: var(--text); }
.detail-poster {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  display: block;
}
.detail-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px 0;
  padding-right: 24px;
}
.detail-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.detail-body {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 14px;
}
.detail-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  margin: 12px 0 6px 0;
}
.detail-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chip.clickable {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.chip.clickable:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-strong);
}
.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-card h2 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.help-list {
  margin: 0 0 16px 0;
  padding-left: 18px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
}
.help-list li { margin-bottom: 8px; }
.help-list strong { color: var(--text); }

/* ---------- Tooltip ---------- */
.tooltip {
  position: absolute;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  z-index: 200;
  max-width: 260px;
  box-shadow: var(--shadow);
}
.tooltip.hidden { display: none; }
.tooltip strong { color: var(--text); display: block; margin-bottom: 2px; }
.tooltip .tip-sub { color: var(--text-faint); font-size: 11px; }

.hidden { display: none !important; }
