:root {
  color-scheme: dark;
  --bg: #081119;
  --panel: rgba(11, 21, 33, 0.92);
  --panel-strong: #101c29;
  --panel-soft: #132233;
  --muted: #93a7bb;
  --text: #f5f7fb;
  --edge: #445e7a;
  --edge-soft: rgba(124, 150, 178, 0.25);
  --imported: #67d3ca;
  --stub: #f2b267;
  --reviewed: #8ea1ff;
  --chip: #162334;
  --accent: #8ea1ff;
  --grid: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Inter", ui-sans-serif, system-ui, sans-serif;
  background:
    radial-gradient(circle at top, rgba(37, 65, 96, 0.3), transparent 38%),
    linear-gradient(180deg, #0a1520, #081119 60%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.topbar,
.sidebar,
.detail-panel,
.modal-card {
  background: var(--panel);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid #1f3146;
}

.brand h1,
.panel-header h2 {
  margin: 0;
  font-size: clamp(1.4rem, 2vw, 2rem);
}

.topbar p,
.panel-header p,
.meta,
.path,
.empty-state {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.actions,
.detail-actions,
.modal-controls,
.graph-legend {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  flex-wrap: wrap;
}

input,
button,
textarea {
  background: #0c1621;
  color: var(--text);
  border: 1px solid #29405a;
  border-radius: 0.9rem;
  padding: 0.7rem 0.9rem;
}

textarea {
  min-height: 420px;
  width: 100%;
  resize: vertical;
  line-height: 1.55;
}

button {
  cursor: pointer;
}

button.busy {
  opacity: 0.6;
  cursor: wait;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 420px;
  min-height: calc(100vh - 90px);
}

.sidebar,
.detail-panel {
  padding: 1rem;
  overflow: auto;
}

.sidebar {
  border-right: 1px solid #1f3146;
}

.detail-panel {
  border-left: 1px solid #1f3146;
}

.graph-panel {
  position: relative;
  padding: 1rem 1rem 1.1rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.9rem;
}

#graph {
  width: 100%;
  height: calc(100vh - 180px);
  min-height: 680px;
  border-radius: 1.3rem;
  background:
    radial-gradient(circle at top, rgba(28, 47, 68, 0.55), transparent 35%),
    radial-gradient(var(--grid) 1px, transparent 1px),
    #0c1520;
  background-size: auto, 18px 18px, auto;
  border: 1px solid rgba(70, 95, 120, 0.45);
}

.graph-tooltip {
  position: absolute;
  z-index: 10;
  max-width: 260px;
  display: grid;
  gap: 0.25rem;
  padding: 0.75rem 0.9rem;
  border-radius: 0.95rem;
  border: 1px solid rgba(111, 135, 164, 0.4);
  background: rgba(5, 11, 18, 0.94);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.year-guide {
  stroke: rgba(124, 150, 178, 0.18);
  stroke-width: 2;
  stroke-dasharray: 8 10;
}

.year-label {
  fill: #dce5f4;
  font-size: 22px;
  font-weight: 700;
  text-anchor: middle;
}

.edge {
  fill: none;
  stroke: var(--edge);
  stroke-width: 2.2;
  opacity: 0.88;
}

.edge.further_papers {
  stroke-dasharray: 8 6;
}

.graph-card {
  fill: rgba(15, 24, 37, 0.96);
  stroke: rgba(116, 143, 171, 0.38);
  stroke-width: 1.5;
  cursor: pointer;
}

.graph-card.imported { stroke: var(--imported); }
.graph-card.reviewed { stroke: var(--reviewed); }
.graph-card.stub { stroke: var(--stub); }
.graph-card.selected {
  stroke: #ffffff;
  stroke-width: 2.8;
  filter: drop-shadow(0 10px 22px rgba(125, 159, 255, 0.25));
}

.card-title {
  fill: #f5f7fb;
  font-size: 16px;
  font-weight: 700;
}

.card-meta {
  fill: var(--muted);
  font-size: 12px;
}

.dot {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
  margin-right: 0.35rem;
}

.dot.imported { background: var(--imported); }
.dot.reviewed { background: var(--reviewed); }
.dot.stub { background: var(--stub); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chip {
  background: var(--chip);
  color: var(--text);
  border: 1px solid #29405a;
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.chip.active {
  outline: 2px solid var(--accent);
}

#results {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

#results li {
  padding: 0.8rem;
  border: 1px solid #223248;
  border-radius: 0.9rem;
  background: #0d1623;
  cursor: pointer;
}

#results li.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(142, 161, 255, 0.2);
}

.path {
  word-break: break-all;
  font-size: 0.88rem;
}

.note-review {
  margin-top: 1rem;
}

.link-suggestions {
  margin-top: 1.2rem;
}

.section-card {
  margin-top: 0.8rem;
  border: 1px solid #223248;
  border-radius: 1rem;
  background: rgba(12, 22, 33, 0.72);
  overflow: hidden;
}

.section-card summary {
  cursor: pointer;
  list-style: none;
  padding: 0.9rem 1rem;
  font-weight: 700;
}

.section-card summary::-webkit-details-marker {
  display: none;
}

.section-body {
  padding: 0 1rem 1rem;
}

.section-body h4,
.section-body h5 {
  margin: 1rem 0 0.5rem;
}

.section-body p,
.section-body ul {
  margin: 0.45rem 0;
}

.section-body ul {
  padding-left: 1.2rem;
}

.inline-link {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin: 0;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(102, 122, 255, 0.12);
  border: 1px solid rgba(102, 122, 255, 0.24);
}

.asset-pill {
  margin-top: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 1px dashed rgba(143, 163, 184, 0.4);
  border-radius: 0.85rem;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(2, 7, 12, 0.6);
}

.modal-card {
  width: min(860px, 100%);
  max-height: 82vh;
  padding: 1.1rem;
  border: 1px solid #1f3146;
  border-radius: 1.2rem;
  overflow: auto;
}

.zotero-results {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.suggestion-list {
  display: grid;
  gap: 0.7rem;
}

.suggestion-card {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.8rem 0.9rem;
  border: 1px solid #223248;
  border-radius: 0.9rem;
  background: rgba(13, 22, 35, 0.72);
}

.suggestion-bucket + .suggestion-bucket {
  margin-top: 1rem;
}

.zotero-card {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.9rem 1rem;
  border: 1px solid #223248;
  border-radius: 0.9rem;
  background: rgba(13, 22, 35, 0.92);
}

@media (max-width: 1400px) {
  .layout {
    grid-template-columns: 260px 1fr 360px;
  }
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .detail-panel {
    border: 0;
    border-top: 1px solid #1f3146;
  }

  #graph {
    min-height: 520px;
    height: 60vh;
  }
}
