:root {
  --bg: #f3f1ea;
  --paper: #fffdf8;
  --ink: #1c1b18;
  --muted: #6b665c;
  --line: #d7d0c2;
  --accent: #0b5d5c;
  --accent-2: #b0522f;
  --danger: #b32424;
  --gold: #c99500;
  --blue: #2563eb;
  --orange: #dd6b20;
  --gray: #8b8b8b;
  --red: #c53030;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at 10% 10%, #fff6dc, transparent 38%),
    radial-gradient(circle at 90% 0%, #dff1ee, transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
}

body {
  min-height: 100vh;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.6vw, 2.2rem);
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
}

h3 {
  font-size: 1.05rem;
  line-height: 1.25;
}

p {
  margin: 0;
}

button,
input,
a {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

button.secondary {
  background: #ece7da;
  color: var(--ink);
  border-color: var(--line);
}

input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  background: #fff;
  color: var(--ink);
}

input[type="text"]:focus,
input[type="number"]:focus,
button:focus,
a:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, white);
  outline-offset: 2px;
}

a {
  color: var(--accent);
}

.app-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 0.8rem;
}

.topbar {
  display: grid;
  gap: 0.8rem;
  align-items: end;
}

.tagline {
  color: var(--muted);
  margin-top: 0.2rem;
}

.search-form {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: minmax(0, 1fr) auto;
  background: color-mix(in srgb, var(--paper) 92%, white);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.75rem;
  box-shadow: var(--shadow);
}

.global-status,
.global-error,
.global-notices {
  min-height: 0;
}

.global-status,
.global-error {
  font-size: 0.92rem;
}

.global-status {
  color: var(--muted);
}

.global-error {
  color: var(--danger);
  font-weight: 600;
}

.global-notices {
  display: grid;
  gap: 0.4rem;
}

.notice {
  background: #fff7d7;
  border: 1px solid #f0d07b;
  color: #6b5414;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(280px, 1fr);
  gap: 1rem;
  min-height: calc(100vh - 190px);
}

.graph-panel,
.panel-card {
  background: color-mix(in srgb, var(--paper) 94%, white);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.graph-panel {
  position: relative;
  padding: 0.7rem;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.6rem;
  min-height: 560px;
}

.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  justify-content: space-between;
}

.graph-toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.graph-toolbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.graph-toolbar button {
  background: #efe9db;
  color: var(--ink);
  border-color: var(--line);
}

.toolbar-control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f6f1e5;
  color: var(--ink);
  font-size: 0.88rem;
}

.toolbar-select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0.25rem 0.4rem;
  min-height: 32px;
}

.toolbar-number-input {
  width: 5rem;
  min-height: 32px;
  padding: 0.25rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.toolbar-select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, white);
  outline-offset: 2px;
}

.toolbar-hint {
  color: #6d675c;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid color-mix(in srgb, var(--line) 80%, white);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
}

#graph-summary {
  color: var(--muted);
  font-size: 0.9rem;
}

.graph-svg {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.65) 35%, transparent 70%),
    linear-gradient(180deg, #faf8f0 0%, #f2efe6 100%);
  border: 1px solid color-mix(in srgb, var(--line) 80%, white);
}

.graph-empty {
  position: absolute;
  inset: auto 1.4rem 1.2rem 1.4rem;
  background: rgba(255, 255, 255, 0.78);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  color: var(--muted);
  pointer-events: none;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 1rem;
}

.panel-card {
  padding: 0.9rem;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #ece7da;
  border: 1px solid var(--line);
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.sidecar-content {
  display: grid;
  gap: 0.7rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.meta-chip {
  background: #f7f3e8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.5rem;
  font-size: 0.88rem;
}

.meta-chip strong {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}

.authors,
.abstract {
  font-size: 0.93rem;
  line-height: 1.45;
}

.abstract {
  max-height: 11rem;
  overflow: auto;
  padding-right: 0.25rem;
}

.sidecar-actions,
.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.review-sort-control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.review-sort-control .toolbar-select {
  min-width: 7.5rem;
}

#sidecar-source-link {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f9f6ed;
  text-decoration: none;
}

.review-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  max-height: 16rem;
  overflow: auto;
}

.review-item {
  border: 1px solid var(--line);
  background: #faf7ef;
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  display: grid;
  gap: 0.15rem;
}

.review-item-title {
  font-size: 0.9rem;
  line-height: 1.25;
}

.review-item-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.review-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.review-draft-status {
  margin-top: 0.7rem;
  font-size: 0.9rem;
}

.review-draft-error {
  color: var(--danger);
  font-weight: 600;
}

.review-warnings {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.review-warning {
  background: #fff7d7;
  border: 1px solid #f0d07b;
  color: #6b5414;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  font-size: 0.84rem;
}

.review-draft {
  display: grid;
  gap: 0.9rem;
  margin-top: 0.75rem;
}

.review-draft-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbf8f1;
  padding: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.review-draft-section-title {
  font-size: 0.96rem;
}

.review-draft-copy {
  font-size: 0.92rem;
  line-height: 1.45;
}

.review-draft-list,
.review-reference-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.review-draft-item,
.review-reference-item {
  border-top: 1px dashed color-mix(in srgb, var(--line) 90%, white);
  padding-top: 0.55rem;
}

.review-draft-item:first-child,
.review-reference-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.review-draft-item-body {
  display: grid;
  gap: 0.35rem;
}

.review-draft-item-heading {
  font-size: 0.9rem;
}

.review-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.review-citation {
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #efe9db;
  color: var(--ink);
  font-size: 0.78rem;
}

.review-reference-button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.review-reference-meta {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.8rem;
  word-break: break-word;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.link-line {
  stroke: #b9b1a2;
  stroke-opacity: 0.7;
  stroke-width: 1.4;
  marker-end: url(#arrowhead);
}

.link-line.is-faded {
  stroke-opacity: 0.16;
}

.link-line.is-highlighted {
  stroke: #7c5b16;
  stroke-opacity: 0.95;
  stroke-width: 2.2;
}

.node-circle {
  stroke: #fff;
  stroke-width: 1.5;
  cursor: pointer;
  transition: r 120ms ease, filter 120ms ease;
}

.node-circle.is-selected {
  stroke: #1d1b18;
  stroke-width: 2.5;
}

.node-circle.is-faded {
  opacity: 0.2;
}

.node-label {
  pointer-events: none;
  font-size: 11px;
  fill: #3f3b34;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 2px;
  stroke-linejoin: round;
}

.node-label.is-faded {
  opacity: 0.25;
}

.year-guide {
  stroke: rgba(107, 102, 92, 0.22);
  stroke-width: 1;
  stroke-dasharray: 4 5;
}

.year-guide-label {
  fill: rgba(80, 75, 68, 0.75);
  font-size: 10px;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.75);
  stroke-width: 2px;
  stroke-linejoin: round;
}

.year-bar {
  fill: rgba(11, 93, 92, 0.18);
  stroke: rgba(11, 93, 92, 0.38);
  stroke-width: 1;
}

.year-bar.is-unknown {
  fill: rgba(107, 102, 92, 0.16);
  stroke: rgba(107, 102, 92, 0.34);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .graph-panel {
    min-height: 460px;
  }

  .meta-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0.65rem;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .graph-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .graph-toolbar-meta {
    justify-content: flex-start;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .graph-panel {
    min-height: 360px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
