/* CombsWiki layout + views, on the Combs house tokens.
   The grammar is the CombsEdge site's: a grid ground under an ambient
   glow, a glass bar over it, hairline-bordered surfaces that lift on
   hover, Inter for prose and JetBrains Mono for anything literal. */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

/* Ground: the 44px grid and the ambient orb, both inert. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-size: 44px 44px;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  mask-image: linear-gradient(to bottom, black 12%, transparent 82%);
  -webkit-mask-image: linear-gradient(to bottom, black 12%, transparent 82%);
  z-index: -3;
  pointer-events: none;
}
body::after {
  content: "";
  position: fixed;
  top: -15vh;
  left: 50%;
  transform: translateX(-50%);
  width: 90vw;
  height: 60vh;
  background: radial-gradient(ellipse at center,
    rgba(180, 180, 200, 0.06) 0%,
    rgba(100, 100, 140, 0.02) 35%,
    rgba(0, 0, 0, 0) 65%);
  filter: blur(100px);
  z-index: -2;
  pointer-events: none;
}

/* Era palette — the six constellations. */
:root {
  --era-foundations: 232 62% 62%;
  --era-attention: 286 58% 63%;
  --era-gpt: 152 48% 48%;
  --era-inference: 36 92% 56%;
  --era-multimodal: 340 68% 62%;
  --era-agents: 186 78% 47%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.65rem 1.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 8, 14, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.back-btn {
  background: hsl(var(--surface) / 0.8);
  border: 1px solid hsl(var(--border-visible));
  border-radius: 8px;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.32rem 0.62rem;
  transition: all 0.3s var(--ease-soft);
}
.back-btn:hover {
  color: hsl(var(--foreground));
  border-color: hsl(var(--border-hover));
  background: hsl(var(--surface-2));
}
/* Brand: the main site's treatment — a white rounded chip holding the
   mark, then the wordmark. */
.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}
.brand-mark img { width: 16px; height: 16px; display: block; }
.brand-word {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: hsl(var(--foreground));
}
.topbar nav { display: flex; gap: 0.9rem; align-items: center; }
.nav-sep {
  width: 1px;
  height: 14px;
  background: hsl(var(--border-visible));
  margin: 0 0.2rem;
}
.topbar nav a {
  color: hsl(var(--muted-foreground));
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.2s ease;
}
.topbar nav a:hover { color: hsl(var(--foreground)); }

.search { position: relative; flex: 0 1 320px; margin-left: auto; }
.search input {
  width: 100%;
  padding: 0.4rem 0.8rem;
  border-radius: 9px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--surface));
  color: hsl(var(--foreground));
  font-size: 0.85rem;
  font-family: var(--font-sans);
  transition: border-color 0.3s var(--ease-soft);
}
.search input::placeholder { color: hsl(var(--muted-foreground) / 0.75); }
.search input:focus { outline: none; border-color: hsl(var(--border-hover)); }
.search-results {
  position: absolute;
  top: 118%;
  left: 0;
  right: 0;
  background: hsl(var(--surface));
  border: 1px solid hsl(var(--border-visible));
  border-radius: 12px;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 24px 48px -20px rgba(0, 0, 0, 0.8);
}
.search-results a {
  display: block;
  padding: 0.45rem 0.7rem;
  text-decoration: none;
  color: hsl(var(--foreground));
  font-size: 0.85rem;
  border-bottom: 1px solid hsl(var(--border) / 0.5);
}
.search-results a:hover { background: hsl(var(--muted)); }
.search-results .hit-line { color: hsl(var(--muted-foreground)); font-size: 0.75rem; }

/* The shell splits the page: routed view on the left, persistent chat
   dock on the right. The chat lives outside the router deliberately. */
.shell { flex: 1; display: flex; min-height: 0; }
#view { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ── graph view ── */
.graph-wrap { flex: 1; position: relative; min-height: 0; min-width: 0; }
.graph-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
.graph-legend {
  position: absolute;
  bottom: 1.1rem;
  left: 1.1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  background: rgba(17, 17, 21, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid hsl(var(--border-visible));
  border-radius: 12px;
  padding: 0.5rem 0.85rem;
}
.graph-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.graph-tip {
  position: absolute;
  pointer-events: none;
  background: rgba(17, 17, 21, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid hsl(var(--border-visible));
  border-radius: 10px;
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
  box-shadow: 0 4px 12px hsl(var(--foreground) / 0.15);
  max-width: 260px;
}
.graph-tip .tip-summary { color: hsl(var(--muted-foreground)); font-size: 0.72rem; }

/* ── timeline view ── */
.timeline { max-width: 780px; margin: 0 auto; padding: 2rem 1.2rem 4rem; width: 100%; overflow-y: auto; }
.timeline h2.era-head {
  margin: 2.4rem 0 0.9rem;
  font-size: 0.82rem;
  font-family: var(--font-mono);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.timeline .rail { border-left: 2px solid hsl(var(--border)); padding-left: 1.4rem; }
.tl-item {
  position: relative;
  padding: 0.7rem 1rem;
  margin-bottom: 0.6rem;
  border: 1px solid hsl(var(--border));
  border-radius: 14px;
  background: hsl(var(--surface));
  cursor: pointer;
  transition: all 0.3s var(--ease-soft);
}
.tl-item:hover {
  transform: translateY(-2px);
  background: hsl(var(--surface-2));
  box-shadow: 0 24px 48px -20px rgba(0, 0, 0, 0.7);
}
.tl-item::before {
  content: "";
  position: absolute;
  left: -1.75rem;
  top: 1rem;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: hsl(var(--era, var(--primary)));
}

.tl-item .tl-year { font-size: 0.72rem; color: hsl(var(--muted-foreground)); }
.tl-item .tl-title { font-weight: 600; }
.tl-item .tl-summary { font-size: 0.85rem; color: hsl(var(--muted-foreground)); }
.tl-item.stub { opacity: 0.55; }
.tl-item.stub .tl-title::after { content: " · stub"; font-weight: 400; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

/* ── article view ── */
.article { max-width: 760px; margin: 0 auto; padding: 2rem 1.2rem 4rem; width: 100%; overflow-y: auto; }
.article .meta { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.6rem; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--surface));
  color: hsl(var(--muted-foreground));
}
.badge.era { border-color: hsl(var(--era, var(--border))); color: hsl(var(--era, var(--muted-foreground))); }
.article h1 {
  margin: 0.2rem 0 1rem;
  font-size: 2.3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  background: linear-gradient(180deg, #ffffff 0%, #d4d4dc 55%, #b8b8c2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.article-body { line-height: 1.65; font-size: 0.98rem; }
.article-body h2 { margin-top: 2rem; border-bottom: 1px solid hsl(var(--border)); padding-bottom: 0.3rem; }
.article-body blockquote {
  margin: 1rem 0;
  padding: 0.6rem 1rem;
  border-left: 3px solid hsl(var(--primary));
  background: hsl(var(--muted) / 0.5);
  border-radius: 0 8px 8px 0;
}
.article-body pre {
  background: hsl(var(--terminal));
  border: 1px solid hsl(var(--border-visible));
  border-radius: 14px;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  position: relative;
}
.article-body code { font-family: var(--font-mono); font-size: 0.86em; }
.article-body :not(pre) > code {
  background: hsl(var(--surface-2));
  border: 1px solid hsl(var(--border));
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
}
.article-body table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.article-body th, .article-body td { border: 1px solid hsl(var(--border)); padding: 0.4rem 0.7rem; font-size: 0.9rem; }
.article-body a { color: hsl(var(--primary)); }
.article-body a.wikilink { text-decoration: none; border-bottom: 1px dashed hsl(var(--primary) / 0.6); }
.article-body a.wikilink.stub { color: hsl(var(--muted-foreground)); border-bottom-style: dotted; }
.article-body .mermaid { display: flex; justify-content: center; margin: 1.2rem 0; overflow-x: auto; }
.article-body .mermaid svg { max-width: 100%; height: auto; }
.backlinks { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid hsl(var(--border)); }
.backlinks .label { font-size: 0.8rem; color: hsl(var(--muted-foreground)); margin-right: 0.5rem; }
.backlinks a {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  margin: 0.15rem 0.3rem 0.15rem 0;
  padding: 0.15rem 0.6rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  text-decoration: none;
  color: hsl(var(--foreground));
}
.backlinks a { background: hsl(var(--surface)); transition: all 0.25s var(--ease-soft); }
.backlinks a:hover { border-color: hsl(var(--border-hover)); background: hsl(var(--surface-2)); }

/* prev/next through the reading order */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.2rem;
  border-top: 1px solid hsl(var(--border));
}
.pager a {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-width: 46%;
  padding: 0.75rem 1.05rem;
  border: 1px solid hsl(var(--border));
  border-radius: 14px;
  text-decoration: none;
  color: hsl(var(--foreground));
  background: hsl(var(--surface));
  transition: all 0.3s var(--ease-soft);
}
.pager a:hover {
  border-color: hsl(var(--border-hover));
  background: hsl(var(--surface-2));
  transform: translateY(-2px);
}
.pager-next { text-align: right; }
.pager-dir { font-size: 0.72rem; color: hsl(var(--muted-foreground)); }
.pager-title { font-weight: 600; font-size: 0.9rem; }

.loading { padding: 3rem; text-align: center; color: hsl(var(--muted-foreground)); }

/* ── ask-the-wiki panel ────────────────────────────────────────────
   Sits beside the brain, never over it. The model runs on the
   reader's machine; this is only the conversation with it. */
.chat-panel {
  width: 370px;
  flex-shrink: 0;
  border-left: 1px solid hsl(var(--border));
  background: hsl(var(--surface) / 0.7);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: width 0.35s var(--ease);
}
.chat-panel.hidden-panel { width: 44px; }
.chat-panel.hidden-panel > *:not(.chat-head) { display: none; }
.chat-panel.hidden-panel .chat-status-text { display: none; }

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid hsl(var(--border));
  flex-shrink: 0;
}
.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
  letter-spacing: 0.02em;
}
.chat-status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: hsl(240 6% 45%);
  flex-shrink: 0;
  transition: all 0.3s var(--ease);
}
.chat-status[data-state="found"] i { background: #34d399; box-shadow: 0 0 9px rgba(52, 211, 153, 0.65); }
.chat-status[data-state="ready"] i { background: #34d399; box-shadow: 0 0 12px rgba(52, 211, 153, 0.9); }
.chat-collapse {
  background: none;
  border: none;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.15rem 0.3rem;
}
.chat-collapse:hover { color: hsl(var(--foreground)); }

.chat-setup { padding: 0.9rem; overflow-y: auto; }
.chat-setup.collapsed { display: none; }
.chat-lede {
  margin: 0 0 0.9rem;
  font-size: 0.82rem;
  line-height: 1.55;
  color: hsl(var(--muted-foreground));
}
.chat-steps { list-style: none; margin: 0 0 0.9rem; padding: 0; display: flex; flex-direction: column; gap: 0.8rem; }
.chat-steps li { display: flex; gap: 0.6rem; }
.chat-steps p { margin: 0 0 0.3rem; font-size: 0.78rem; font-weight: 600; }
.chat-hint { font-weight: 400; font-family: var(--font-mono); font-size: 0.62rem; color: hsl(var(--muted-foreground)); margin-left: 0.4rem; }
.chat-step-n {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid hsl(var(--border-visible));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: hsl(var(--muted-foreground));
  flex-shrink: 0;
}
.chat-steps code {
  display: block;
  position: relative;
  background: hsl(var(--terminal));
  border: 1px solid hsl(var(--border));
  border-radius: 9px;
  padding: 0.5rem 3.1rem 0.5rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.665rem;
  line-height: 1.5;
  color: hsl(var(--muted-light));
  word-break: break-all;
}
.chat-copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: hsl(var(--surface-2));
  border: 1px solid hsl(var(--border-visible));
  border-radius: 5px;
  color: hsl(var(--muted-foreground));
  font-family: var(--font-mono);
  font-size: 0.6rem;
  padding: 0.15rem 0.35rem;
  cursor: pointer;
}
.chat-copy:hover { color: hsl(var(--foreground)); border-color: hsl(var(--border-hover)); }

.chat-addr { display: block; margin: 0 0 0.6rem; }
.chat-addr span {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.25rem;
}
.chat-addr-input {
  width: 100%;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--muted-light));
  font-family: var(--font-mono);
  font-size: 0.68rem;
}
.chat-addr-input:focus { outline: none; border-color: hsl(var(--border-hover)); }

.chat-actions { display: flex; gap: 0.5rem; }
.chat-btn {
  flex: 1;
  padding: 0.45rem 0.7rem;
  border-radius: 9px;
  border: 1px solid hsl(var(--border-visible));
  background: hsl(var(--surface-2));
  color: hsl(var(--foreground));
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s var(--ease-soft);
}
.chat-btn:hover:not(:disabled) { border-color: hsl(var(--border-hover)); transform: translateY(-1px); }
.chat-btn:disabled { opacity: 0.5; cursor: default; }
.chat-btn.primary { background: #ffffff; color: #08080d; border-color: transparent; font-weight: 600; }
.chat-note {
  margin: 0.7rem 0 0;
  font-size: 0.72rem;
  line-height: 1.5;
  color: hsl(var(--muted-foreground));
}

.chat-log { flex: 1; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.7rem; min-height: 0; }
.chat-msg {
  font-size: 0.82rem;
  line-height: 1.6;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-user { background: hsl(var(--surface-3)); border: 1px solid hsl(var(--border)); align-self: flex-end; max-width: 90%; }
.chat-assistant { background: hsl(var(--surface) / 0.85); border: 1px solid hsl(var(--border)); }
.chat-system { font-size: 0.74rem; color: hsl(var(--muted-foreground)); padding: 0; }
.chat-assistant.streaming::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 0.95em;
  background: hsl(var(--muted-light));
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: chat-blink 1s step-end infinite;
}
@keyframes chat-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.chat-meta {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: hsl(var(--muted-foreground) / 0.8);
}
.chat-assistant.is-thinking { color: hsl(var(--muted-foreground)); font-style: italic; }
.chat-sources { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chat-sources a {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.12rem 0.45rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  color: hsl(var(--muted-foreground));
  text-decoration: none;
}
.chat-sources a:hover { color: hsl(var(--foreground)); border-color: hsl(var(--border-hover)); }

.chat-form { display: flex; gap: 0.5rem; padding: 0.75rem 0.9rem; border-top: 1px solid hsl(var(--border)); flex-shrink: 0; }
.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border-radius: 9px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 0.82rem;
}
.chat-input:focus { outline: none; border-color: hsl(var(--border-hover)); }
.chat-send {
  padding: 0.45rem 0.9rem;
  border-radius: 9px;
  border: none;
  background: #ffffff;
  color: #08080d;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}
.chat-send:disabled { opacity: 0.35; cursor: default; }
.chat-stop {
  padding: 0.45rem 0.8rem;
  border-radius: 9px;
  border: 1px solid hsl(var(--border-visible));
  background: hsl(var(--surface-2));
  color: hsl(var(--muted-light));
  font-size: 0.78rem;
  cursor: pointer;
}
.chat-stop:hover { border-color: hsl(var(--border-hover)); color: hsl(var(--foreground)); }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .chat-panel { width: auto; border-left: none; border-top: 1px solid hsl(var(--border)); max-height: 46%; }
  .chat-panel.hidden-panel { width: auto; height: 46px; max-height: 46px; }
}
