:root {
  --bg: #0a0b0d;
  --surface: #16181c;
  --surface-2: #1e2126;
  --ink: #f2f1ec;
  --ink-muted: #9a9fa8;
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --border: #2a2d33;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 12px 32px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.preview-banner {
  background: #3d2c00;
  color: #ffd580;
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  padding: 8px 16px;
  letter-spacing: 0.01em;
}

header.site {
  padding: 22px 40px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

header.site::after {
  content: "";
  position: absolute;
  left: 40px;
  right: 40px;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 28%);
  opacity: 0.6;
}

header.site a.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  padding-left: 16px;
  border-left: 2px solid var(--accent);
}

header.site .brand-mark {
  width: 60px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

header.site .brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

header.site .brand-name {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 21px;
  font-weight: 600;
  font-style: italic;
  color: var(--ink);
  letter-spacing: -0.005em;
}

header.site .brand-tagline {
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
}

header.site .api-link {
  font-family: "Inter", -apple-system, "Segoe UI", sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  transition: border-color 0.14s ease, color 0.14s ease;
}

header.site .api-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

header.site .api-link-note {
  color: var(--ink-muted);
  font-weight: 400;
  opacity: 0.75;
}

@media (max-width: 640px) {
  header.site a.brand { flex-direction: column; align-items: flex-start; gap: 4px; }
}

nav.crumbs {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 40px 0;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--ink-muted);
}

nav.crumbs a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

nav.crumbs a:hover { text-decoration: underline; }

nav.crumbs .sep {
  margin: 0 8px;
  opacity: 0.4;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 40px 96px;
}

h1.page-title {
  font-size: 30px;
  font-weight: 700;
  margin: 6px 0 6px;
  line-height: 1.2;
  text-wrap: balance;
  letter-spacing: -0.015em;
  color: var(--ink);
}

p.collection-tag {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
  margin: 0 0 28px;
  font-weight: 700;
}

.uk-hidden-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  margin: 0 0 20px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.uk-hidden-banner .uk-hidden-count {
  color: var(--accent);
  font-weight: 700;
}

.uk-hidden-banner .uk-show-all {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 14px;
  cursor: pointer;
  transition: border-color 0.14s ease, color 0.14s ease;
}

.uk-hidden-banner .uk-show-all:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.uk-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

@media (max-width: 480px) {
  .uk-card-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
  }
}

/* Each card is a fixed 9:16 "playing card" - a 3D flip container so the
   front/back are two faces of one physical object, not a swap-in-place
   toggle. perspective lives on the outer wrapper (not .uk-card-flip
   itself) so the flip reads as a real rotation in 3D space. */
.uk-card {
  aspect-ratio: 9 / 16;
  perspective: 1400px;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.uk-card.is-hidden {
  display: none;
}

.uk-card-flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0.12, 0.2, 1);
}

.uk-card-flip.is-flipped {
  transform: rotateY(180deg);
}

.uk-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

/* backface-visibility:hidden only hides RENDERING - some engines (real-
   device Safari/WebKit in particular) still hit-test the face that's
   rotated away, so the front face's buttons can keep swallowing clicks
   meant for the back's unflip button ("flips over but won't flip back").
   Toggling pointer-events explicitly, in step with .is-flipped, is the
   robust fix regardless of any single engine's hit-testing quirks. */
.uk-card-front { pointer-events: auto; }
.uk-card-back { pointer-events: none; }
.uk-card-flip.is-flipped .uk-card-front { pointer-events: none; }
.uk-card-flip.is-flipped .uk-card-back { pointer-events: auto; }

.uk-card:hover .uk-card-flip:not(.is-flipped) {
  transform: translateY(-3px);
}

.uk-card:hover .uk-card-front {
  border-color: var(--accent);
}

.uk-card-link {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  text-decoration: none;
  color: var(--ink);
  min-height: 0;
}

.uk-card-art {
  height: 58%;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uk-card-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10,11,13,0) 55%, var(--surface) 100%);
}

/* A generated sigil, not a fabricated cover image - this project
   deliberately never invents or reuses real cover art (see
   reader_v2/app.py's card_color() docstring), so richness here comes
   from actual vector drawing (card_emblem_svg()), not a fake photo or
   a single repeated ring, which read as generic at ~85 cards' scale. */
.uk-card-emblem {
  width: 58%;
  height: 58%;
  position: relative;
  z-index: 1;
  overflow: visible;
}

.uk-card-emblem .emblem-outer,
.uk-card-emblem .emblem-inner {
  fill: none;
  stroke: rgba(242, 241, 236, 0.4);
  stroke-width: 1.4;
}

.uk-card-emblem .emblem-inner {
  stroke: rgba(242, 241, 236, 0.22);
}

.uk-card-emblem .emblem-dot {
  fill: rgba(242, 241, 236, 0.4);
}

.uk-card-emblem line {
  stroke: rgba(242, 241, 236, 0.22);
  stroke-width: 1;
}

.uk-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 14px;
  flex-grow: 1;
  min-height: 0;
}

.uk-card-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex-shrink: 0;
  min-height: 2.5em;
}

.uk-card-preview {
  font-size: 11.5px;
  font-style: italic;
  line-height: 1.4;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  flex-grow: 1;
}

.uk-card-count {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 700;
  margin-top: auto;
}

.uk-card-btn {
  position: absolute;
  z-index: 2;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(242, 241, 236, 0.18);
  background: rgba(10, 11, 13, 0.55);
  color: var(--ink);
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.uk-card-btn:hover,
.uk-card-btn:focus-visible {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
}

.uk-card-front .uk-flip { top: 8px; right: 8px; }
.uk-card-front .uk-hide { top: 8px; left: 8px; }
.uk-card-back .uk-unflip { bottom: 8px; right: 8px; }

/* Back face: deliberately plain (a real card-back pattern), so flipping
   a card reads as "put this away, keep just the key topics" rather than
   just another content view. */
.uk-card-back {
  transform: rotateY(180deg);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 14px;
  gap: 10px;
  background: var(--surface-2);
}

.uk-back-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image:
    repeating-linear-gradient(45deg, rgba(242,241,236,0.035) 0 2px, transparent 2px 14px),
    repeating-linear-gradient(-45deg, rgba(242,241,236,0.035) 0 2px, transparent 2px 14px);
}

.uk-back-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 82%;
  transform: translate(-50%, -50%);
  opacity: 0.16;
  pointer-events: none;
}

.uk-back-name {
  position: relative;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.uk-key-topics {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.uk-key-topics li {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 12px;
}

ul.listing {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

ul.listing li {
  border-bottom: 1px solid var(--border);
}

ul.listing li:last-child { border-bottom: none; }

ul.listing li a {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 20px;
  text-decoration: none;
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.45;
}

ul.listing li a:hover { background: var(--surface-2); }

ul.listing li a.dir { font-weight: 600; }

ul.listing li a .icon {
  font-size: 11px;
  color: var(--accent);
  width: 14px;
  flex-shrink: 0;
  text-align: center;
  margin-top: 0.5em;
}

article.reading {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  line-height: 1.75;
  max-width: 66ch;
  white-space: pre-wrap;
  color: var(--ink);
  margin-top: 8px;
}

.empty-note {
  color: var(--ink-muted);
  font-size: 14px;
  margin-top: 24px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

/* --- v2 additions: search, tags, lists, related/graph, source notice --- */

.search-box {
  flex: 1;
  max-width: 360px;
  margin: 0 24px;
}

.search-box input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  padding: 8px 12px;
  font-size: 14px;
}

.source-notice {
  background: #3d2c00;
  color: #ffd580;
  font-size: 13.5px;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 14px 0;
}

.source-notice a { color: #ffd580; text-decoration: underline; }

.tags { margin: 8px 0 0; }

.tag {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-muted);
  padding: 3px 10px;
  margin: 0 6px 6px 0;
}

/* A compact preview near the top of the page (unlike .related below,
   which is the full list at the bottom) - so a reader sees the
   connectivity brain's links before, not only after, reading a
   potentially very long chapter. */
.related-preview {
  margin: 18px 0 24px;
}

.related-preview-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.related-preview-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.related-preview-item {
  flex: 0 0 auto;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.14s ease;
}

.related-preview-item:hover {
  border-color: var(--accent);
}

.related-preview-title {
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.related-preview-meta {
  font-size: 10.5px;
  color: var(--ink-muted);
}

.muted { color: var(--ink-muted); font-size: 13px; }

.page-list { list-style: none; padding: 0; margin: 16px 0; }
.page-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.page-list a { color: var(--ink); text-decoration: none; font-weight: 500; }
.page-list a:hover { color: var(--accent); }

.result-snippet {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.pager { display: flex; gap: 16px; align-items: center; margin: 20px 0; }
.pager a { color: var(--accent); }

.sort-bar { display: flex; gap: 10px; align-items: center; margin: 14px 0; color: var(--ink-muted); font-size: 13px; }
.sort-bar a {
  color: var(--ink-muted);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
}
.sort-bar a.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.collection-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 20px; }
.collection-filter a {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--ink-muted);
  text-decoration: none;
}
.collection-filter a.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.related { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 20px; }
.related h2 { font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.graph-link { font-size: 13px; color: var(--accent); text-decoration: none; }
.related-list { list-style: none; padding: 0; }
.related-list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.related-list a { color: var(--ink); text-decoration: none; }
.related-list a:hover { color: var(--accent); }

#graph-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-muted);
  white-space: nowrap;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(242, 241, 236, 0.5);
  flex-shrink: 0;
}
.legend-line {
  width: 26px;
  background: #ccc;
  border-radius: 2px;
  flex-shrink: 0;
}

#graph-hops { margin: 10px 0; }
#graph-hops button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  border-radius: 6px;
  padding: 6px 14px;
  margin-right: 8px;
  cursor: pointer;
}
#graph-hops button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

#graph-svg { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-top: 12px; }
.graph-node text { pointer-events: none; user-select: none; }

/* Real report, 2026-09-16: every node's label showing at once made a
   hub-and-spoke graph unreadable - several titles share a long common
   prefix, so overlapping always-on labels were indistinguishable.
   Only the root (the page you're actually looking at) stays labeled;
   others reveal on hover/focus so you read one at a time. */
.graph-node-label {
  opacity: 0;
  transition: opacity 0.1s ease;
}
.graph-node-label.is-root {
  opacity: 1;
  font-weight: 700;
}
.graph-node:hover .graph-node-label,
.graph-node:focus .graph-node-label {
  opacity: 1;
}

@media (max-width: 640px) {
  header.site, nav.crumbs, main { padding-left: 20px; padding-right: 20px; }
  h1.page-title { font-size: 24px; }
  .search-box {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
    margin: 4px 0 0;
  }
  .search-box input {
    padding: 10px 14px;
    font-size: 16px;
  }
}
