/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bio:     #4CAF50;
  --chem:    #FF9800;
  --phys:    #2196F3;
  --ks3:     #9E9E9E;
  --cross:   #e040fb;
  --bg:      #0f1117;
  --surface: #1a1d27;
  --border:  #2e3146;
  --text:    #e8eaf6;
  --muted:   #7986cb;
  --panel-w: 320px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header .subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Controls bar ─────────────────────────────────────────── */
#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 2px;
}

.filter-btn {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.filter-btn:hover {
  background: var(--border);
}

.filter-btn.active {
  background: var(--muted);
  border-color: var(--muted);
  color: #fff;
}

/* Thread buttons get strand-ish colours when active */
.filter-btn[data-value="literacy"].active    { background: #26a69a; border-color: #26a69a; }
.filter-btn[data-value="numeracy"].active    { background: #ab47bc; border-color: #ab47bc; }
.filter-btn[data-value="working_scientifically"].active { background: #ef5350; border-color: #ef5350; }

/* ── Main area ────────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Graph ────────────────────────────────────────────────── */
#graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--muted);
  pointer-events: none;
}

#loading.hidden { display: none; }

/* ── Node & link styles (applied via D3 / SVG) ────────────── */
.node circle {
  stroke: #fff;
  stroke-width: 1.5px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.node circle:hover { stroke-width: 3px; }
.node.dimmed circle { opacity: 0.15; }

.node text {
  font-size: 10px;
  fill: var(--text);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

.link {
  fill: none;
  stroke-width: 1.2;
  transition: opacity 0.2s;
}
.link.dimmed { opacity: 0.05; }
.link.same-strand { stroke: #444; }
.link.cross-strand { stroke: var(--cross); stroke-dasharray: 5,3; opacity: 0.6; }

/* ── Detail panel ─────────────────────────────────────────── */
#detail-panel {
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px 18px;
  overflow-y: auto;
  flex-shrink: 0;
  position: relative;
  transition: transform 0.25s ease;
}

#detail-panel.hidden {
  display: none;
}

#close-panel {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

#close-panel:hover { color: var(--text); }

#panel-strand-badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
  font-weight: 600;
}

#panel-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

#panel-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-tag {
  background: var(--border);
  padding: 2px 8px;
  border-radius: 12px;
}

#panel-description {
  font-size: 0.85rem;
  line-height: 1.6;
  color: #ccc;
  margin-bottom: 14px;
}

#panel-threads {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.thread-tag {
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 12px;
  font-weight: 500;
}

.thread-tag.literacy           { background: #00695c; color: #fff; }
.thread-tag.numeracy           { background: #6a1b9a; color: #fff; }
.thread-tag.working_scientifically { background: #b71c1c; color: #fff; }

#panel-links h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

#panel-links-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#panel-links-list li {
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: background 0.15s;
}

#panel-links-list li:hover {
  background: var(--border);
  color: var(--text);
}

/* ── Legend ───────────────────────────────────────────────── */
#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  padding: 8px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
  align-items: center;
}

.legend-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-title {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  margin-right: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-item svg { flex-shrink: 0; }

/* ── Strand badge colours ─────────────────────────────────── */
.badge-biology    { background: var(--bio);  color: #fff; }
.badge-chemistry  { background: var(--chem); color: #fff; }
.badge-physics    { background: var(--phys); color: #fff; }
.badge-ks3        { background: var(--ks3);  color: #fff; }
