/* =====================================================================
   COLOURS — change these to restyle the whole site
   ===================================================================== */
:root {
  --bg: #1a1a2e;
  --ink: #f5f0e6;
  --gold: #e8c872;      /* topics side of the map */
  --teal: #5fc9b8;      /* projects side of the map */
  --wine: #8b1e3f;
  --muted: #9a98ad;

  /* chapter pages: printed-book look */
  --paper: #fbf7ee;
  --paper-ink: #22223a;
  --paper-muted: #6f6c80;
  --paper-rule: #e6dfcc;
  --paper-gold: #a8841f;
  --paper-teal: #23877a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: radial-gradient(ellipse at center, #232344 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* =====================================================================
   ORB — landing screen
   ===================================================================== */
#intro { position: fixed; inset: 0; outline: none; }
#orb { position: absolute; inset: 0; transition: opacity .5s ease; }

.intro-text {
  position: absolute; left: 0; right: 0; top: 78vh;
  text-align: center; pointer-events: none;
  transition: opacity .5s ease, transform .6s ease;
}
.intro-text h1 {
  font-size: clamp(30px, 5vw, 48px); font-weight: normal;
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold);
}
.intro-text p { margin-top: 8px; color: var(--muted); letter-spacing: .06em; font-size: 15px; }
.hint { display: inline-block; margin-top: 22px; font-size: 13px; color: var(--ink); opacity: .6; animation: pulse 2.4s infinite; }
@keyframes pulse { 50% { opacity: .2; } }

#intro.away { pointer-events: none; }
#intro.away .intro-text { opacity: 0; transform: translateY(14px); }

/* =====================================================================
   MIND MAP
   ===================================================================== */
#map {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  opacity: 0; pointer-events: none;
  transition: opacity .6s ease;
}
body.map-open #map { opacity: 1; pointer-events: auto; }

#map-hint {
  position: fixed; bottom: 16px; left: 0; right: 0;
  text-align: center; font-size: 13px; color: var(--muted);
  opacity: 0; transition: opacity .6s ease .8s; pointer-events: none;
}
body.map-open #map-hint { opacity: .8; }

.node { cursor: pointer; transition: filter .2s; }
.node text { fill: var(--ink); font-size: 15px; transition: fill .2s, opacity .2s; }
.node circle { stroke-width: 2; transition: opacity .2s; }

.node.centre .hit  { fill: #1c1c33; stroke: rgba(232, 200, 114, .35); stroke-width: 1; transition: stroke .2s; }
.node.centre .dot  { stroke: none; }
.node.centre:hover .hit { stroke: var(--gold); }
.node.centre text  { font-size: 18px; fill: var(--gold); letter-spacing: .12em; text-transform: uppercase; }

/* left half: notes */
.node.left circle        { fill: var(--bg); stroke: var(--gold); }
.node.branch circle      { fill: var(--gold); }
.node.branch text        { font-weight: bold; fill: var(--gold); paint-order: stroke; stroke: #1c1c33; stroke-width: 5px; stroke-linejoin: round; }
.node.branch.d1 text     { font-size: 19px; }
.node.branch.d2 text     { font-size: 15px; }
.node.branch.d3 text     { font-size: 14px; fill: #d9c48a; }
.node.leaf text .num     { fill: var(--gold); opacity: .75; font-size: 13px; }
.node.soon circle        { stroke-dasharray: 2 3; opacity: .6; }
.node.soon text          { fill: var(--muted); font-style: italic; }

/* right half: projects and their models */
.node.right circle       { fill: var(--bg); stroke: var(--teal); }
.node.project circle     { fill: var(--teal); }
.node.project text       { font-size: 18px; font-weight: bold; fill: var(--teal); paint-order: stroke; stroke: #1c1c33; stroke-width: 5px; stroke-linejoin: round; }
.node.model text         { font-size: 16px; }
.node.pending circle     { stroke-dasharray: 2 3; }
.node.pending text       { fill: var(--muted); font-style: italic; }

.node.left:hover text  { fill: var(--gold); }
.node.right:hover text { fill: var(--teal); }

/* the web behind everything */
.web .ring  { fill: none; stroke: rgba(232, 200, 114, .07); stroke-width: 1; stroke-dasharray: 2 5; }
.web .ring.right { stroke: rgba(95, 201, 184, .09); }
.web .spoke { stroke: rgba(232, 200, 114, .05); stroke-width: 1; }
.web .spoke.right { stroke: rgba(95, 201, 184, .06); }
.web { opacity: 0; transition: opacity 1.2s ease .6s; }
#map.settled .web, body.map-open #map .web { opacity: 1; }

/* edges */
.edge { fill: none; stroke: rgba(245, 240, 230, .22); stroke-width: 1.3; transition: stroke .2s, stroke-width .2s; }
.edge.cross { stroke: rgba(95, 201, 184, .055); stroke-dasharray: 3 6; }
.edge.cross.model { stroke: rgba(95, 201, 184, .11); }

/* hover: everything not connected fades back */
#map.focus .node:not(.lit) text,
#map.focus .node:not(.lit) circle { opacity: .22; }
#map.focus .edge:not(.hot) { stroke-opacity: .25; }
.edge.hot       { stroke: var(--gold); stroke-width: 2.2; }
.edge.cross.hot { stroke: var(--teal); stroke-width: 1.6; stroke-dasharray: 3 4; }

/* zoom and pan */
#map { cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#zoom {
  position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 6px;
  opacity: 0; pointer-events: none; transition: opacity .6s ease .8s;
}
body.map-open #zoom { opacity: 1; pointer-events: auto; }
#zoom button {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(26, 26, 46, .85); color: var(--gold);
  border: 1px solid rgba(232, 200, 114, .4); font-size: 18px; cursor: pointer;
}
#zoom button:hover { background: rgba(232, 200, 114, .15); }

/* =====================================================================
   READER — full-screen chapter / project page
   ===================================================================== */
#reader {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(14, 14, 28, .72);
  backdrop-filter: blur(3px);
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity .35s ease;
}
#reader.open { opacity: 1; pointer-events: auto; }

.reader-bar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid rgba(232, 200, 114, .25);
  flex-wrap: wrap;
}
#back {
  background: none; border: 1px solid rgba(232, 200, 114, .5); color: var(--gold);
  font-family: inherit; font-size: 15px; padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
#back:hover { background: rgba(232, 200, 114, .12); }
#crumbs { color: var(--muted); font-size: 14px; }
#crumbs i { margin: 0 8px; font-style: normal; opacity: .6; }
#crumbs span:last-child { color: var(--ink); }

.reader-scroll { flex: 1; overflow-y: auto; padding: 32px 16px 80px; }

.paper {
  max-width: 860px; margin: 0 auto;
  background: var(--paper); color: var(--paper-ink);
  border-radius: 6px;
  padding: 56px 64px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
  font-size: 17px; line-height: 1.7;
  transform: translateY(20px); transition: transform .4s ease;
}
#reader.open .paper { transform: none; }

@media (max-width: 700px) { .paper { padding: 32px 20px; font-size: 16px; } }

/* typography inside chapters */
.paper h1 { font-size: 36px; line-height: 1.2; margin-bottom: 8px; color: var(--paper-ink); }
.paper h2 { font-size: 25px; margin: 44px 0 12px; padding-top: 16px; border-top: 1px solid var(--paper-rule); color: var(--wine); }
.paper h3 { font-size: 19px; margin: 28px 0 8px; color: var(--paper-ink); }
.paper h4 { font-size: 16px; margin: 20px 0 6px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--paper-muted); }
.paper p  { margin: 0 0 14px; }
.paper ul, .paper ol { margin: 0 0 16px 24px; }
.paper li { margin-bottom: 4px; }
.paper a  { color: var(--paper-teal); }
.paper strong { color: #111126; }
.paper hr { border: none; border-top: 1px solid var(--paper-rule); margin: 32px 0; }

/* the one-line summary under the title */
.paper h1 + p { font-size: 19px; color: var(--paper-muted); font-style: italic; margin-bottom: 28px; }

/* callouts: any > quote */
.paper blockquote {
  margin: 20px 0; padding: 14px 20px;
  background: #f3ead2; border-left: 4px solid var(--paper-gold); border-radius: 0 6px 6px 0;
}
.paper blockquote p:last-child { margin-bottom: 0; }

/* tables */
.paper table { width: 100%; border-collapse: collapse; margin: 16px 0 24px; font-size: 15px; }
.paper th, .paper td { padding: 8px 10px; border-bottom: 1px solid var(--paper-rule); text-align: left; vertical-align: top; }
.paper th { background: #f1ead8; font-weight: bold; }

/* figures */
.paper figure { margin: 24px 0 28px; text-align: center; }
.paper figure img { max-width: 100%; height: auto; }
.paper figcaption { font-size: 14px; color: var(--paper-muted); font-style: italic; margin-top: 6px; }

/* code */
.paper pre { margin: 16px 0 22px; border-radius: 8px; overflow: auto; font-size: 14px; line-height: 1.5; }
.paper pre code.hljs { padding: 16px 18px; }
.paper :not(pre) > code {
  background: #eee6d1; padding: 1px 6px; border-radius: 4px; font-size: .88em;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
}

/* maths */
.paper .katex-display { margin: 18px 0 22px; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.paper .katex { font-size: 1.08em; }

/* footer of each chapter */
.chapter-foot { margin-top: 48px; padding-top: 20px; border-top: 2px solid var(--paper-rule); }
.chapter-foot h3 { margin-top: 0; }
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 24px; font-size: 15px; }

.soon-box { margin-top: 24px; padding: 32px; text-align: center; border: 2px dashed var(--paper-rule); border-radius: 8px; }

.muted { color: var(--paper-muted); }
.kicker { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--paper-muted); margin-bottom: 4px !important; }
.lead { font-size: 19px; }

.chip {
  display: inline-block; margin: 0 6px 8px 0; padding: 6px 14px;
  border-radius: 999px; border: 1px solid var(--paper-teal);
  background: transparent; color: var(--paper-ink) !important;
  font-family: inherit; font-size: 15px; text-decoration: none; cursor: pointer;
}
.chip:hover, .chip.active { background: rgba(35, 135, 122, .12); }

/* project pages */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--paper-rule); margin: 18px 0 24px; }
.tabs button {
  background: none; border: none; color: var(--paper-muted);
  font-family: inherit; font-size: 16px; padding: 10px 16px; cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tabs button.active { color: var(--paper-ink); border-bottom-color: var(--paper-gold); }
.repo-link { margin-top: 24px; }
.code-box { margin-top: 12px; }
.code-box pre { max-height: 70vh; }

table.metrics td, table.metrics th { text-align: right; }
table.metrics td:first-child, table.metrics th:first-child { text-align: left; }
table.metrics tr:last-child td { color: var(--paper-teal); font-weight: bold; }

/* =====================================================================
   PHONE VIEW — the map as a list on small screens
   ===================================================================== */
#index { display: none; }
body.map-open.list-mode #map, body.map-open.list-mode #zoom, body.map-open.list-mode #map-hint { display: none; }
body.map-open.list-mode #index {
  display: block; position: fixed; inset: 0; overflow-y: auto;
  padding: 16px 16px 60px; animation: fadein .5s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(10px); } }
#index header { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
#index header h1 { font-size: 20px; font-weight: normal; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
#index-back {
  background: none; border: 1px solid rgba(232, 200, 114, .5); color: var(--gold);
  font-family: inherit; font-size: 14px; padding: 5px 12px; border-radius: 999px;
}
#index h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin: 26px 0 6px; }
#index h3 { font-size: 15px; color: var(--gold); margin: 14px 0 4px; font-weight: bold; }
#index h3.top { font-size: 18px; margin-top: 18px; }
#index ol { list-style: none; padding-left: 0; }
#index ol ol { padding-left: 12px; border-left: 1px solid rgba(232, 200, 114, .2); }
#index li a {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 0;
  color: var(--ink); text-decoration: none; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,.05);
}
#index li .num { color: var(--gold); opacity: .7; font-size: 13px; min-width: 20px; text-align: right; }
#index li.soon a { color: var(--muted); }
#index li em { font-size: 12px; }
#index .proj {
  display: block; padding: 12px 14px; margin: 8px 0; border-radius: 10px;
  border: 1px solid rgba(95, 201, 184, .35); color: var(--ink); text-decoration: none;
}
#index .proj a { text-decoration: none; }
#index .proj strong { color: var(--teal); display: block; font-size: 17px; }
#index .proj span { color: var(--muted); font-size: 14px; }
#index .proj span a { color: var(--ink); text-decoration: underline; text-decoration-color: rgba(255,255,255,.25); }
.status { font-size: 13px; vertical-align: middle; padding: 2px 8px; border-radius: 99px; background: rgba(200,150,40,.15); color: #9a6b10; font-family: sans-serif; }
.paper.model ul { margin-top: 8px; }
#crumbs a { color: inherit; text-decoration: underline; text-decoration-color: rgba(255,255,255,.3); }

.paper blockquote.def  { border-left-color: var(--paper-teal, #23877a); background: rgba(35,135,122,.08); }
.paper blockquote.warn { border-left-color: #8b1e3f; background: rgba(139,30,63,.06); }
.paper blockquote.say  { border-left-color: #3a6ea5; background: rgba(58,110,165,.07); }
.paper p.ok { border-left: 3px solid #23877a; padding-left: 12px; margin: 6px 0; }
.paper p.no { border-left: 3px solid #8b1e3f; padding-left: 12px; margin: 6px 0; color: #5a5668; }
