/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #171717;
  --muted: #737373;
  --border: #e7e5e4;

  --accent: #10b981;
  --accent-dark: #059669;
  --accent-tint: #ecfdf5;

  --amber: #d97706;
  --amber-tint: #fef3c7;

  --gray-text: #57534e;
  --gray-tint: #f5f5f4;
  --gray-tint-2: #e7e5e4;

  --blue-gray: #475569;
  --blue-gray-tint: #eff6ff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-hover: 0 10px 30px rgba(23, 23, 23, 0.09);
  --max-width: 1200px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ==========================================================================
   Reset / base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body, h1, h2, h3, h4, p, ul, ol, li, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

@media (min-width: 768px) {
  body { font-size: 17px; }
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; }

.wrap {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

@media (min-width: 768px) {
  .wrap { padding-inline: 2rem; }
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  z-index: 200;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 1rem; }

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(250, 250, 249, 0.92);
  backdrop-filter: saturate(180%) blur(6px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding-block: 0.85rem;
}

.wordmark {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}

.wordmark span { color: var(--accent-dark); }

.jumpnav {
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
  margin-left: 0.25rem;
}

.jumpnav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.25rem 0.1rem;
  border-bottom: 2px solid transparent;
}

.jumpnav a:hover,
.jumpnav a:focus-visible {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

.search-wrap {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1 1 200px;
  max-width: 320px;
  min-width: 160px;
}

.search-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
}

.search-input:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 1px;
}

.search-count {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 3.5rem;
}

@media (max-width: 640px) {
  .topbar-inner { padding-block: 0.7rem; }
  .search-wrap { order: 3; max-width: none; flex-basis: 100%; }
  .jumpnav { order: 2; }
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero { padding-block: 2.5rem 2rem; }

@media (min-width: 768px) {
  .hero { padding-block: 3.5rem 2.5rem; }
}

.hero-title {
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  margin-top: 0.5rem;
  font-size: 1.15rem;
  color: var(--muted);
  font-weight: 600;
}

@media (min-width: 768px) {
  .hero-title { font-size: 2.75rem; }
  .hero-subtitle { font-size: 1.3rem; }
}

.hero-intro {
  margin-top: 1.1rem;
  max-width: 62ch;
  font-size: 1.05rem;
  color: var(--text);
}

.hero-image-frame {
  margin-top: 1.75rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
  background: var(--gray-tint);
}

@media (min-width: 768px) {
  .hero-image-frame { aspect-ratio: 3 / 1; }
}

.hero-image-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stats {
  margin-top: 1.75rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.9rem;
}

@media (min-width: 768px) {
  .stats { grid-template-columns: repeat(4, 1fr); gap: 1.1rem; }
}

.stat-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent-dark);
  letter-spacing: -0.02em;
}

.stat-label {
  margin-top: 0.15rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ==========================================================================
   Section shell
   ========================================================================== */
.section { padding-block: 3rem; border-top: 1px solid var(--border); }
.section-head { margin-bottom: 1.5rem; }
.section-title { font-size: 1.6rem; letter-spacing: -0.01em; }
.section-sub { margin-top: 0.4rem; color: var(--muted); font-size: 0.98rem; max-width: 60ch; }

/* ==========================================================================
   Map: toolbar + breadcrumb
   ========================================================================== */
.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--muted);
}

.breadcrumb .crumb { color: var(--text); font-weight: 600; }
.breadcrumb .sep { color: var(--muted); white-space: pre; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn:hover { border-color: var(--accent); }

.btn[aria-pressed="true"] {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ==========================================================================
   Map: roots (level 1)
   ========================================================================== */
/* The map is always exactly three roots (Kindly, Epex, Home), so each card
   and its pillars panel gets a named grid area. Panels are direct children
   of .roots, appended after all three cards (see app.js renderTree). On
   this single mobile column a panel sits right under its own root card; on
   the wider grid below, every panel is reassigned into one shared
   full-width row so the tree never gets squeezed into a single column. */
.roots {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "r1"
    "p1"
    "r2"
    "p2"
    "r3"
    "p3";
  gap: 1.25rem;
}

.roots > .root-card:nth-child(1) { grid-area: r1; }
.roots > .root-card:nth-child(2) { grid-area: r2; }
.roots > .root-card:nth-child(3) { grid-area: r3; }
.roots > .pillars-panel:nth-child(4) { grid-area: p1; }
.roots > .pillars-panel:nth-child(5) { grid-area: p2; }
.roots > .pillars-panel:nth-child(6) { grid-area: p3; }

@media (min-width: 860px) {
  .roots {
    grid-template-columns: repeat(3, 1fr);
    grid-template-areas:
      "r1 r2 r3"
      "panel panel panel";
    gap: 1.5rem;
  }
  .roots > .pillars-panel:nth-child(4),
  .roots > .pillars-panel:nth-child(5),
  .roots > .pillars-panel:nth-child(6) {
    grid-area: panel;
  }
}

.root-card {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.root-card:hover,
.root-card:focus-within,
.root-card.is-open {
  box-shadow: var(--shadow-hover);
  border-color: var(--root-color, var(--accent));
}

/* short stub dropping from the open root card into its pillars panel */
.root-card.is-open::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1.25rem;
  width: 2px;
  height: 1.25rem;
  background: var(--root-color, var(--accent));
  transform: translateX(-50%);
}

@media (min-width: 860px) {
  .root-card.is-open::after { bottom: -1.5rem; height: 1.5rem; }
}

.card-head {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: var(--radius);
}

.root-card .card-image {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--gray-tint);
  border-bottom: 1px solid var(--border);
}

.root-card .card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body { padding: 1.1rem 1.2rem 1.3rem; }

.card-eyebrow {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--root-color, var(--accent-dark));
  margin-bottom: 0.35rem;
}

.card-name {
  font-size: 1.25rem;
  font-weight: 700;
}

.card-tagline {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.card-meta {
  margin-top: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.card-meta .chevron {
  margin-left: auto;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.card-head[aria-expanded="true"] .chevron { transform: rotate(-135deg); }

/* ==========================================================================
   Map: connector + pillars (level 2)
   ========================================================================== */
.pillars-panel {
  border: 1px solid var(--border);
  border-top: 3px solid var(--root-color, var(--accent));
  border-radius: var(--radius);
  padding: 1.5rem 1.2rem 1.75rem;
  background: var(--surface);
}

.pillars-panel[hidden] { display: none; }

.connector {
  position: relative;
  height: 1.1rem;
  margin-bottom: 0.5rem;
}

.connector::before {
  content: "";
  position: absolute;
  left: 3%;
  right: 3%;
  top: 0;
  height: 1px;
  background: var(--border);
}

.pillars-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
}

.pillar-card {
  position: relative;
  flex: 1 1 220px;
  min-width: 200px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.pillar-card::before {
  content: "";
  position: absolute;
  top: -0.5rem;
  left: 50%;
  width: 1px;
  height: 0.5rem;
  background: var(--border);
}

@media (max-width: 640px) {
  .pillars-row { flex-direction: column; }
  .pillar-card { flex-basis: auto; }
  .pillar-card::before { top: 50%; left: -1.1rem; width: 0.7rem; height: 1px; }
}

.pillar-card:hover,
.pillar-card:focus-within {
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.pillar-card .card-image {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--gray-tint);
  border-bottom: 1px solid var(--border);
}

.pillar-card .card-image img { width: 100%; height: 100%; object-fit: cover; }

.pillar-card .card-body { padding: 0.9rem 1rem 1.05rem; }

.pillar-card .card-name { font-size: 1.05rem; }

.pillar-card .card-tagline { font-size: 0.88rem; }

/* ==========================================================================
   Map: items (level 3)
   ========================================================================== */
.items-panel {
  border-top: 1px dashed var(--border);
  margin-top: 1.1rem;
  padding-top: 1.1rem;
}

.items-panel[hidden] { display: none; }

.item-list { display: flex; flex-direction: column; gap: 0.6rem; }

.item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.item-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
  background: none;
  border: none;
  padding: 0.7rem 0.85rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.item-toggle:hover { background: var(--gray-tint); }

.item-name { font-weight: 600; font-size: 0.96rem; }

.item-date { color: var(--muted); font-size: 0.85rem; margin-left: auto; }

.item-toggle .chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.item-toggle[aria-expanded="true"] .chevron { transform: rotate(-135deg); }

.item-panel {
  padding: 0 0.9rem 0.9rem 0.9rem;
  font-size: 0.93rem;
}

.item-panel[hidden] { display: none; }

.item-what { font-weight: 600; }

.item-detail { margin-top: 0.4rem; color: var(--muted); }

.item-link {
  display: inline-block;
  margin-top: 0.6rem;
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
}

.item-link:hover { color: var(--text); }

.no-match-note {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.5rem 0.1rem;
}

/* ==========================================================================
   Status pills
   ========================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}

.pill-live { background: var(--accent-tint); color: var(--accent-dark); }
.pill-in-progress { background: var(--amber-tint); color: var(--amber); }
.pill-retired { background: var(--gray-tint); color: var(--muted); }
.pill-paused { background: var(--gray-tint-2); color: var(--gray-text); }
.pill-researched { background: var(--blue-gray-tint); color: var(--blue-gray); }

/* ==========================================================================
   Timeline
   ========================================================================== */
.timeline { position: relative; padding-block: 0.5rem; }

.timeline::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

@media (min-width: 768px) {
  .timeline::before { left: 50%; transform: translateX(-50%); }
}

.timeline-item {
  position: relative;
  width: 100%;
  padding: 0 0 1.9rem 2.2rem;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-item .dot {
  position: absolute;
  top: 0.35rem;
  left: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}

@media (min-width: 768px) {
  .timeline-item { width: 50%; padding: 0 2.2rem 2.2rem; left: 0; text-align: right; }
  .timeline-item:nth-child(even) { left: 50%; text-align: left; }
  .timeline-item .dot { left: auto; right: -6px; }
  .timeline-item:nth-child(even) .dot { right: auto; left: -6px; }
}

.timeline-date {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-dark);
  background: var(--accent-tint);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
}

.timeline-event { font-size: 0.98rem; }

/* ==========================================================================
   Borrow
   ========================================================================== */
.borrow-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .borrow-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 960px) {
  .borrow-grid { grid-template-columns: repeat(3, 1fr); }
}

.borrow-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem;
  transition: box-shadow 0.2s ease;
}

.borrow-card:hover { box-shadow: var(--shadow-hover); }

.borrow-card h3 { font-size: 1.02rem; }

.borrow-card p { margin-top: 0.5rem; color: var(--muted); font-size: 0.93rem; }

.borrow-callout {
  margin-top: 1.1rem;
  border: 1px solid var(--accent);
  background: var(--accent-tint);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
}

.borrow-callout h3 { color: var(--accent-dark); font-size: 1.1rem; }
.borrow-callout p { margin-top: 0.5rem; color: var(--text); font-size: 0.96rem; }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 1.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ==========================================================================
   Back to top
   ========================================================================== */
.back-to-top {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 90;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 1.05rem;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-hover);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ==========================================================================
   Reveal on scroll
   ========================================================================== */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.reveal.is-revealed {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .back-to-top { transition: none; }
  .card-head .chevron, .item-toggle .chevron { transition: none; }
}

/* ==========================================================================
   Print
   ========================================================================== */
@media print {
  .topbar, .back-to-top, .map-toolbar .btn, .search-wrap { display: none !important; }
  .pillars-panel[hidden],
  .items-panel[hidden],
  .item-panel[hidden] { display: block !important; }
  /* Escape the grid areas entirely for print: once every panel is forced
     visible above, a shared "panel" area (or three roots sharing one grid
     row) would stack them on top of each other. Plain block flow puts
     each card and its panel, in DOM order, one after another instead. */
  .roots { display: block; }
  .root-card.is-open::after { display: none; }
  body { background: #fff; color: #000; }
  .section { border-top: 1px solid #ccc; }
  .root-card, .pillar-card, .item, .stat-card, .borrow-card, .pillars-panel {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }
  .reveal { opacity: 1 !important; transform: none !important; }
  a[href]:not([href=""])::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
  .hero-image-frame { aspect-ratio: auto; max-height: 3in; }
}
