/* The Folk Network — warm editorial folk-songbook aesthetic */

:root {
  --bg: #f6f1e6;
  --surface: #fbf7ee;
  --surface-2: #f1ebdd;
  --ink: #2c2418;
  --ink-muted: #6f6455;
  --ink-faint: #a29681;
  --border: #ddd2bd;
  --accent: #7d2f1e;

  --font-display: 'Zodiak', Georgia, serif;
  --font-body: 'Satoshi', 'Helvetica Neue', Arial, sans-serif;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.83rem + 0.25vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.6vw, 1.375rem);

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;

  --shadow: 0 2px 10px rgba(44, 36, 24, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--bg);
}
input, button { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
h1, h2, h3 { line-height: 1.15; text-wrap: balance; }
p { text-wrap: pretty; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ---------- header ---------- */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-inner {
  max-width: none; display: flex; flex-wrap: wrap; gap: var(--space-4);
  align-items: center; justify-content: space-between;
  padding: var(--space-4, 1rem) var(--space-6, 1.5rem) var(--space-2, 0.5rem);
}
.brand h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: var(--text-lg); letter-spacing: 0.01em;
}
.brand .brand-logo { line-height: 0; }
.brand .brand-logo img {
  display: block; height: 44px; width: auto; max-width: 100%;
}
.tagline { color: var(--ink-muted); font-size: var(--text-xs); }
.topbar-tools { display: flex; gap: var(--space-3, 0.75rem); align-items: center; }
.topbar-meta {
  padding: 0 var(--space-6, 1.5rem) var(--space-3, 0.75rem);
  color: var(--ink-faint); font-size: var(--text-xs);
}

/* search */
.search { position: relative; }
#search-input {
  width: min(300px, 60vw); padding: 0.45rem 0.75rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); font-size: var(--text-sm);
}
#search-input::placeholder { color: var(--ink-faint); }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; display: none;
}
.search-results.open { display: block; }
.search-result {
  display: block; width: 100%; text-align: left; padding: 0.45rem 0.75rem;
  font-size: var(--text-sm); border-bottom: 1px solid var(--border);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--surface-2); }
.search-result .kind { color: var(--ink-faint); font-size: var(--text-xs); margin-left: 0.4em; }
.search-result .no-match { color: var(--ink-faint); cursor: default; }

.btn {
  padding: 0.45rem 0.9rem; font-size: var(--text-sm); font-weight: 500;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2); transition: background 180ms ease, border-color 180ms ease;
}
.btn:hover { background: var(--surface); border-color: var(--ink-faint); }

/* ---------- layout ---------- */
.main { display: flex; height: calc(100dvh - 118px); }
.canvas-wrap { position: relative; flex: 1 1 auto; min-width: 0; background: var(--bg); }
#graph { width: 100%; height: 100%; display: block; }
.hint {
  position: absolute; left: 50%; bottom: var(--space-3, 0.75rem); transform: translateX(-50%);
  color: var(--ink-muted); font-size: var(--text-xs); pointer-events: none; z-index: 5;
  background: var(--bg);
  padding: 3px 12px; border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  white-space: nowrap;
  max-width: calc(100% - 1.5rem);
  overflow: hidden; text-overflow: ellipsis;
}

/* tooltip */
.tooltip {
  position: absolute; z-index: 20; pointer-events: none; display: none;
  background: var(--ink); color: #f6f1e6; padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md); max-width: 260px; font-size: var(--text-xs);
  line-height: 1.45; box-shadow: var(--shadow);
}
.tooltip .tt-name { font-family: var(--font-display); font-size: var(--text-sm); font-weight: 700; }
.tooltip .tt-sub { opacity: 0.85; }
.tooltip .tt-label { margin-top: 0.35rem; font-weight: 700; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 300px; flex: 0 0 300px; overflow-y: auto;
  border-left: 1px solid var(--border); background: var(--surface);
  padding: var(--space-4, 1rem);
  display: flex; flex-direction: column; gap: var(--space-4, 1rem);
}
.panel-title {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-base);
  margin-bottom: var(--space-2, 0.5rem);
}
details.panel summary {
  cursor: pointer; list-style: none;
}
details.panel summary::-webkit-details-marker { display: none; }
details.panel summary::after { content: '▸'; float: right; color: var(--ink-faint); }
details.panel[open] summary::after { content: '▾'; }
.panel-note { color: var(--ink-muted); font-size: var(--text-xs); margin-top: var(--space-2, 0.5rem); }

/* nation chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 0.28rem 0.7rem; font-size: var(--text-xs); font-weight: 500;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  color: var(--ink-muted);
  transition: all 180ms ease;
}
.chip:hover { border-color: var(--ink-faint); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { opacity: 0.6; margin-left: 0.3em; }

/* timeline */
#timeline-slider { width: 100%; accent-color: var(--accent, #b45309); cursor: pointer; }
.timeline-status {
  font-size: var(--text-xs); color: var(--ink-muted); margin-top: 0.35rem;
}
.timeline-actions { display: flex; gap: 6px; margin-top: 0.55rem; }

/* genre legend */
.genre-legend { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.genre-item {
  display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left;
  padding: 0.24rem 0.45rem; border-radius: var(--radius-sm); font-size: var(--text-sm);
  color: var(--ink); transition: background 150ms ease;
}
.genre-item:hover { background: var(--surface-2); }
.genre-item .swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 12px; }
.genre-item .gname { flex: 1 1 auto; }
.genre-item .gcount { color: var(--ink-faint); font-size: var(--text-xs); }
.genre-item.focused { background: var(--surface-2); font-weight: 700; }
.genre-item.dimmed { opacity: 0.45; }

/* artist details */
.details .empty { color: var(--ink-faint); font-size: var(--text-sm); }
.d-name { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); line-height: 1.2; }
.d-meta { color: var(--ink-muted); font-size: var(--text-xs); margin: 0.35rem 0 0.6rem; }
.d-desc { font-size: var(--text-sm); line-height: 1.55; margin-bottom: 0.7rem; }
.d-genres { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 0.7rem; }
.d-sptags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 0.7rem; }
.d-splabel { font-size: var(--text-xs); color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.d-sp-chip {
  font-size: var(--text-xs); padding: 2px 8px; border-radius: 999px;
  color: #0e7a3c; background: rgba(29, 185, 84, 0.14);
  border: 1px solid rgba(14, 122, 60, 0.45); font-weight: 500;
}
.d-genre {
  padding: 0.22rem 0.6rem; border-radius: 999px; font-size: var(--text-xs);
  color: #fff; font-weight: 500;
}
.d-link { font-size: var(--text-xs); color: var(--accent); }

.about p { font-size: var(--text-sm); line-height: 1.55; margin-bottom: 0.6rem; }

/* ---------- graph element styles ---------- */
.link { stroke: #b9ad93; stroke-opacity: 0.35; stroke-width: 1; }
.link.faded { stroke-opacity: 0.05; }
.link.lit { stroke: #7d2f1e; stroke-opacity: 0.8; stroke-width: 1.6; }
.member-link { stroke: #8a7d63; stroke-opacity: 0.5; stroke-width: 1; stroke-dasharray: 4 3; }
.member-link.faded { stroke-opacity: 0.05; }
.member-link.lit { stroke: #5a4a33; stroke-opacity: 0.9; stroke-width: 1.5; }
.family-link { stroke: #9c5a52; stroke-opacity: 0.55; stroke-width: 1.2; stroke-dasharray: 0.1 4; stroke-linecap: round; }
.family-link.faded { stroke-opacity: 0.05; }
.family-link.lit { stroke: #7d2f1e; stroke-opacity: 0.95; stroke-width: 1.8; }
.alumni-link { stroke: #6b8a5a; stroke-opacity: 0.5; stroke-width: 1; stroke-dasharray: 9 4; }
.alumni-link.faded { stroke-opacity: 0.05; }
.alumni-link.lit { stroke: #3f5e2f; stroke-opacity: 0.9; stroke-width: 1.5; }
.collab-link { stroke: #7a5f8a; stroke-opacity: 0.55; stroke-width: 1.1; stroke-dasharray: 2 3 9 3; }
.collab-link.faded { stroke-opacity: 0.05; }
.collab-link.lit { stroke: #533a66; stroke-opacity: 0.95; stroke-width: 1.6; }
.influence-link { stroke: #56718e; stroke-opacity: 0.6; stroke-width: 1.2; stroke-dasharray: 7 3 1.5 3; marker-end: url(#infl-arrow); }
.influence-link.faded { stroke-opacity: 0.05; marker-end: none; }
.influence-link.lit { stroke: #2f4a6b; stroke-opacity: 0.95; stroke-width: 1.8; }
.d-member .rel { opacity: 0.55; font-style: italic; }
.member-row .chip { margin-right: 6px; }
.member-row { margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px solid var(--ink-faint, #c9bfa8); }
.member-row .panel-note { margin-top: 0.4rem; }
.d-members { margin-bottom: 0.7rem; }
.d-members h3 {
  font-size: var(--text-xs, 0.75rem); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-muted); margin: 0 0 0.35rem; font-weight: 700;
}
.d-member {
  display: inline-block; margin: 0 4px 4px 0; padding: 2px 10px;
  border: 1px solid var(--ink-faint, #c9bfa8); border-radius: 999px;
  background: transparent; color: var(--ink); font-size: var(--text-xs, 0.75rem);
  cursor: pointer; font-family: inherit;
}
.d-member:hover { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.node { cursor: pointer; }
.node .halo { fill: none; stroke: var(--accent); stroke-width: 2; stroke-opacity: 0; }
.node.selected .halo { stroke-opacity: 1; }
.node.dimmed { opacity: 0.15; }
.node .artist-dot { stroke: rgba(44,36,24,0.35); stroke-width: 0.75; }
.genre-label {
  font-family: var(--font-display); font-weight: 700; fill: var(--ink);
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none;
}
.genre-label.dimmed { opacity: 0.25; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .main { flex-direction: column; height: auto; }
  .canvas-wrap { height: 62vh; min-height: 420px; flex: none; }
  .sidebar { width: 100%; flex: none; border-left: none; border-top: 1px solid var(--border); }
  .topbar-inner { padding: var(--space-3, 0.75rem) var(--space-4, 1rem); }
  .topbar-tools { flex-wrap: wrap; }
  .topbar-meta { padding-bottom: var(--space-2, 0.5rem); }
  .hint { white-space: normal; text-align: center; max-width: calc(100% - 1.5rem); }
}

/* ---------- guided tour: pinned stage + scroll runway ---------- */
body.touring .sidebar { display: none; }
body.touring .hint { display: none; }
body.touring .main {
  position: sticky; top: 0; height: 100dvh; z-index: 5;
  background: var(--bg);
}
/* tour runway height is set inline by app.js (100vh per chapter) */
.tour-card {
  position: absolute; left: 28px; top: 50%; transform: translateY(-50%);
  width: min(350px, calc(100% - 56px)); z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: 0 12px 34px rgba(44, 36, 24, 0.16);
  padding: 1.15rem 1.3rem 1rem;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.55s cubic-bezier(0.25, 0.1, 0.25, 1);
}
.tour-card.active { opacity: 1; visibility: visible; }
.tour-card.active .tour-card-actions { pointer-events: auto; }
.tour-kicker {
  font-size: var(--text-xs); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent); font-weight: 700; margin-bottom: 0.35rem;
}
.tour-card h3 { font-family: var(--font-display); font-size: var(--text-lg); margin-bottom: 0.45rem; }
.tour-card p { font-size: var(--text-sm); color: var(--ink-muted); line-height: 1.5; }
.tour-dots { display: flex; gap: 6px; margin-top: 0.8rem; }
.tour-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--border);
  transition: background 0.3s ease;
}
.tour-card.active .tour-dots span.on { background: var(--accent); }
.tour-card-actions { margin-top: 0.75rem; display: flex; align-items: center; gap: 0.75rem; }
.tour-scroll-hint { font-size: var(--text-xs); color: var(--ink-faint); }
.tour-exit-btn {
  font: inherit; font-size: var(--text-sm); font-weight: 700;
  background: var(--accent); color: #fbf7ee; border: none; border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem; cursor: pointer;
}
.tour-exit-btn:hover { filter: brightness(1.1); }

@media (max-width: 900px) {
  body.touring .main { height: 100dvh; flex-direction: column; }
  body.touring .canvas-wrap { height: 100dvh; min-height: 0; flex: 1 1 auto; }
  .tour-card { left: 12px; right: 12px; width: auto; top: auto; bottom: 18px; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tour-card { transition: none; }
}
