/*
  essay-knowledge-graph.css
  Styles for the <essay-knowledge-graph> Shadow DOM custom element.
  This stylesheet is linked from *inside* the shadow root, so all selectors
  are scoped to the component automatically — they cannot leak to the page.
*/

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Lora:ital,wght@0,400;0,500;0,600;1,400&display=swap');

:host {
  display: block;
  --paper: #F1F1F1;
  --paper-dark: #F5F5F5;
  --ink: #444343;
  --ink-soft: #767676;
  --ink-faint: #A4A4A4;
  --accent: #42D97F;
  --accent-dim: #42D97F55;
  --gold: hsl(50deg 100% 45%);
  --line: #E3E3E3;
  --card-bg: #FFFFFF;
}

* { box-sizing: border-box; }

#app {
  display: flex;
  width: 100%;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

#sidebar {
  flex: 0 0 180px;
  width: 180px;
  height: 100%;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 1px 0 3px rgba(0,0,0,0.03);
  display: flex;
  flex-direction: column;
}

#header {
  padding: 16px 16px 12px 16px;
}
#header .eyebrow {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 5px 0;
}
#header h1 {
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 300;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--ink);
}
#header .sub {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Theme filter rail ───────────────────────────────────────────────────── */

#rail {
  padding: 12px 14px 16px 14px;
  border-top: 1px solid var(--line);
}
#rail .rail-label {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11.5px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  color: var(--ink);
  transition: background 0.15s;
  user-select: none;
}
.theme-toggle:hover { background: var(--paper-dark); }
.theme-toggle.selected {
  font-weight: 600;
  background: var(--accent-dim);
  box-shadow: inset 3px 0 0 var(--accent);
}
.theme-toggle.selected .theme-dot {
  border-width: 2.5px;
}

.theme-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid var(--ink);
}

#rail .reset-btn {
  margin-top: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-soft);
  background: none;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 5px 9px;
  cursor: pointer;
}
#rail .reset-btn:hover { background: var(--paper-dark); border-color: var(--ink-faint); }

/* ── Graph canvas ────────────────────────────────────────────────────────── */

#graph-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}
svg#graph {
  width: 100%;
  height: 100%;
  cursor: grab;
}
svg#graph:active { cursor: grabbing; }

.link {
  stroke: var(--line);
  stroke-width: 1.2px;
  fill: none;
  transition: stroke 0.2s, stroke-width 0.2s, opacity 0.2s;
}
.link.lit  { stroke: var(--accent); stroke-width: 2px; }
.link.faded { opacity: 0.08; }

/* ── Concept nodes ───────────────────────────────────────────────────────── */

.node-concept circle {
  fill: var(--card-bg);
  stroke-width: 1.75px;
  transition: opacity 0.2s, r 0.2s;
}
.node-concept text {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 10px;
  fill: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  pointer-events: none;
  /* Hidden by default; revealed on hover/select so labels never crowd the layout */
  opacity: 0;
  transition: opacity 0.15s;
}
.node-concept:hover text,
.node-concept.selected text,
.node-concept.theme-match text { opacity: 1; }
.node-concept.theme-match circle { stroke-width: 2.5px; }
.node-concept.faded { opacity: 0.15; }
.node-concept:hover circle,
.node-concept.selected circle { stroke-width: 2.5px; }

/* ── Essay nodes ─────────────────────────────────────────────────────────── */

.node-essay rect {
  fill: var(--card-bg);
  stroke: var(--ink);
  stroke-width: 1.25px;
  rx: 2;
  transition: opacity 0.2s, stroke-width 0.2s;
}
.node-essay .essay-year {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 9px;
  fill: var(--ink-soft);
}
.node-essay .essay-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 11px;
  fill: var(--ink);
  font-weight: 500;
}
.node-essay.faded { opacity: 0.15; }
.node-essay:hover rect,
.node-essay.selected rect {
  stroke-width: 2.25px;
  stroke: var(--accent);
}

.node-essay, .node-concept { cursor: pointer; }

/* ── Detail panel ────────────────────────────────────────────────────────── */

#panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 280px;
  height: 100%;
  background: var(--card-bg);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(0,0,0,0.05);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  z-index: 20;
  padding: 20px 18px;
  overflow-y: auto;
}
#panel.open { transform: translateX(0); }

#panel .panel-eyebrow {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
#panel.concept-mode .panel-eyebrow { color: var(--ink-soft); }

#panel h2 {
  font-family: 'Lora', Georgia, serif;
  font-weight: 600;
  font-size: 17px;
  line-height: 1.35;
  margin: 0 0 5px 0;
  color: var(--ink);
}
#panel .panel-year {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
#panel .panel-read-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--paper);
  background: var(--accent);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 4px;
  margin-bottom: 14px;
  transition: background 0.15s, transform 0.1s;
}
#panel .panel-read-link:hover { background: #36C06E; }
#panel .panel-read-link:active { transform: scale(0.98); }

#panel .panel-section-label {
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 14px 0 6px 0;
  border-top: 1px solid var(--line);
  padding-top: 11px;
}

#panel .panel-list { list-style: none; margin: 0; padding: 0; }
#panel .panel-list li {
  font-family: 'Lora', Georgia, serif;
  font-size: 12.5px;
  padding: 6px 0;
  cursor: pointer;
  color: var(--ink);
  border-bottom: 1px solid #00000008;
  transition: color 0.15s;
}
#panel .panel-list li:hover { color: var(--accent); }
#panel .panel-list li .concept-tag {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 9px;
  color: var(--ink-soft);
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#panel-close {
  position: absolute;
  top: 18px;
  right: 18px;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
}
#panel-close:hover { color: var(--ink); }

/* ── Sidebar footer note ─────────────────────────────────────────────────── */

#footnote {
  margin-top: auto;
  padding: 12px 14px 16px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  color: var(--ink-faint);
  line-height: 1.5;
  border-top: 1px solid var(--line);
}

/* ── Narrow mode (host width < 500px) ───────────────────────────────────── */

:host([narrow]) #sidebar { display: none; }
:host([narrow]) #narrow-toggle { display: flex; }
:host([narrow]) #sidebar.show { display: flex; position: absolute; z-index: 30; height: 100%; }

#narrow-toggle {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 25;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 9px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  cursor: pointer;
  color: var(--ink);
  align-items: center;
  gap: 5px;
}
