:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #57606a;
  --line: #d8dee4;
  --accent: #2f6f4f;       /* Cadence green */
  --accent-weak: #eaf3ee;
  --pink: #d90368;         /* Cadence logo pink */
  --pink-weak: #fde4ef;
  --stub: #b3261e;          /* unresolved link */
  --maxw: 820px;
  --topbar: 3.5rem;         /* sticky header height — rails/anchors offset by this */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--topbar);
  padding: 0 1.2rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
}
.brand img {
  height: 2.5rem;          /* matches the handbook (Starlight) logo size */
  width: auto;
  border-radius: 4px;
}
.search {
  min-width: 220px;
  max-width: 360px;
  flex: 1;
  /* Pagefind sizes everything off these vars — scale it down so the input
     fits the topbar instead of using Pagefind's chunky default. */
  --pagefind-ui-scale: 0.55;
  --pagefind-ui-border: var(--line);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: 6px;
  --pagefind-ui-font: inherit;
}

/* Layout */
.layout {
  display: grid;
  /* Always reserve the right rail column so pages don't shift width/position
     depending on whether they have an "On this page" outline. */
  grid-template-columns: 240px minmax(0, 1fr) 200px;
  gap: 2rem;
  max-width: 1380px;
  margin: 0 auto;
  padding: 1.5rem 1.2rem;
}

/* Jumping to a heading clears the sticky topbar instead of hiding under it. */
main article h2,
main article h3 { scroll-margin-top: calc(var(--topbar) + 1rem); }

/* Right-rail "On this page" outline */
.toc .toc-inner {
  position: sticky;
  top: calc(var(--topbar) + 1rem);
  font-size: 0.85rem;
  border-left: 1px solid var(--line);
  padding-left: 0.9rem;
}
.toc-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.toc-nav ul { list-style: none; margin: 0; padding: 0; }
.toc-nav li { margin: 0.15rem 0; }
.toc-nav ul ul { padding-left: 0.8rem; }
.toc-nav a {
  color: var(--muted);
  text-decoration: none;
  display: block;
  padding: 0.1rem 0;
  line-height: 1.3;
}
.toc-nav a:hover { color: var(--accent); }

/* Right-rail note telling readers they can select text to comment */
.comment-hint {
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}
/* When there's no "On this page" outline, the hint is the only rail content. */
.toc-inner > .comment-hint:first-child { margin-top: 0; }
.comment-hint-title {
  margin: 0 0 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg);
}
.comment-hint p { margin: 0; }

/* Clickable heading anchor (appears on hover) */
.heading-anchor {
  margin-left: 0.35rem;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.1s;
}
h2:hover .heading-anchor,
h3:hover .heading-anchor { opacity: 0.5; }
.heading-anchor:hover { opacity: 1 !important; }
.sidebar {
  font-size: 0.92rem;
  position: sticky;
  top: calc(var(--topbar) + 1rem);
  height: calc(100vh - var(--topbar) - 2rem);
  overflow-y: auto;
}
.sidebar .nav-section {
  margin: 1.1rem 0 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.sidebar .nav-section:first-child { margin-top: 0; }
.sidebar .nav-section a { color: inherit; text-decoration: none; }
.sidebar .nav-section a[aria-current="page"] { color: var(--accent); }

/* Collapsible folder (e.g. Marc's Notes) */
.sidebar .nav-folder > details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  color: var(--muted);
  user-select: none;
}
.sidebar .nav-folder > details > summary::-webkit-details-marker { display: none; }
.sidebar .nav-folder > details > summary::before {
  content: "▸";
  font-size: 0.7em;
  color: var(--muted);
}
.sidebar .nav-folder > details[open] > summary::before { content: "▾"; }
.sidebar .nav-folder > details > summary:hover { background: var(--accent-weak); color: var(--fg); }
.sidebar .nav-folder ul {
  margin: 0.1rem 0 0.4rem 0.65rem;
  padding-left: 0.4rem;
  border-left: 1px solid var(--line);
}
.sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav li { margin: 0.1rem 0; }
.sidebar nav a {
  display: block;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}
.sidebar nav a:hover { background: var(--accent-weak); color: var(--fg); }
.sidebar nav a[aria-current="page"] {
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 600;
}

/* Content */
main { max-width: var(--maxw); }
main article a { color: var(--accent); }
main h1 { margin-top: 0; }

/* Page header row with the GitHub edit link */
.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.page-head-title {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.page-head-title h1 { margin: 0; }

/* Hypothesis status badge */
.status-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.status-badge.status-testing { color: #8a6d00; border-color: #e3d28a; background: #fdf8e3; }
.status-badge.status-supported { color: var(--accent); border-color: #bfe0cf; background: var(--accent-weak); }
.status-badge.status-refuted { color: var(--stub); border-color: #e7b7b3; background: #fcf3f2; }

/* Map (link graph) */
.map-intro { color: var(--muted); }
.map-graph {
  height: 70vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.edit-link {
  flex: none;
  font-size: 0.82rem;
  color: var(--muted) !important;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  white-space: nowrap;
}
.edit-link:hover { border-color: var(--accent); color: var(--accent) !important; }

/* Unresolved [[wikilinks]] point at /stubs/ until the page is created.
   Style them as draft stubs so it's obvious the page isn't written yet. */
main article a[href="/stubs/"],
main article a[href="/stubs"] {
  color: var(--stub);
  text-decoration: underline dashed;
  text-underline-offset: 2px;
}
main article a[href="/stubs/"]::after { content: " ✎"; font-size: 0.8em; opacity: 0.6; }

/* Unanchored (orphaned) comments — shown at the end when their anchor is gone */
.orphan-comments {
  margin-top: 2.5rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--stub);
  border-radius: 8px;
  background: #fcf7f6;
}
.orphan-comments h2 { margin-top: 0; font-size: 1rem; }
.orphan-note { color: var(--muted); font-size: 0.88rem; margin-top: 0; }
.orphan-comments ul { padding-left: 1.1rem; }
.orphan-comments li { margin: 0.5rem 0; }
.orphan-quote { color: var(--muted); font-style: italic; }
.orphan-author { color: var(--muted); font-size: 0.88rem; }

/* Backlinks */
.backlinks {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
}
.backlinks h2 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.backlinks ul { padding-left: 1.1rem; }

/* Drop the right-rail outline before the main column gets cramped. */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); max-width: 1200px; }
  .toc { display: none; }
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    order: 2;
    border-top: 1px solid var(--line);
    padding-top: 1rem;
    position: static;
    max-height: none;
    overflow: visible;
  }
}

/* ---- Inline comments (RecogitoJS) — themed to match the notebook ---- */

/* The highlighted, commented text */
.r6o-annotation,
mark.r6o-annotation {
  background: var(--pink-weak);
  border-bottom: 2px solid var(--pink);
  padding-bottom: 1px;
}

/* The popup editor card — bordered & compact */
.r6o-editor .r6o-arrow::before,
.r6o-editor-inner {
  border-color: var(--line) !important;
}
.r6o-editor,
.r6o-editor .r6o-editor-inner {
  border-radius: 14px !important;
}
.r6o-editor-inner {
  box-shadow: 0 6px 20px rgba(31, 35, 40, 0.14);
  overflow: hidden;
  background: var(--bg);
  padding: 0.55rem;
}
/* A posted (read-only) comment is NOT an input box — render it as plain text
   with its author/time line, set apart from the reply field below by a divider
   and space. Override Recogito's box/divider defaults. */
.r6o-editor .r6o-widget.comment:not(.editable),
.r6o-editor-inner .r6o-widget.comment:not(.editable):first-child {
  background: transparent !important;
  border: none !important;
  border-bottom: 1px solid var(--line) !important;
  border-radius: 0 !important;
  margin-bottom: 0.7rem;
  padding-bottom: 0.15rem;
}
.r6o-editor .r6o-readonly-comment {
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--fg);
}

/* The "who + when" line on a posted comment — quiet, no border chip. */
.r6o-editor .r6o-widget.comment .r6o-lastmodified {
  border: none !important;
  margin: 0 0 0.1rem 10px;
  padding: 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.r6o-editor .r6o-widget.comment .r6o-lastmodified-at {
  color: var(--muted);
}

/* The reply / new-comment field IS an input box — bordered, focusable. */
.r6o-editor .r6o-widget.comment.editable {
  background: var(--bg) !important;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  overflow: hidden;
}
.r6o-editor .r6o-widget.comment.editable:focus-within {
  border-color: var(--pink) !important;
}

/* The editable text sits transparent inside the bordered widget. */
.r6o-editor .r6o-editable-text {
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--fg);
  padding: 0.55rem 0.65rem;
  min-height: 5rem;
  max-height: 16rem;
}

/* Footer + buttons — divider above, tight spacing */
.r6o-editor .r6o-footer {
  padding: 0;
  margin-top: 0.25rem;
  gap: 0.4rem;
}
.r6o-editor .r6o-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.3rem 0.8rem;
  background: var(--pink);
  color: #fff;
  border: 1px solid var(--pink);
  cursor: pointer;
}
.r6o-editor .r6o-btn:hover { filter: brightness(1.06); }
.r6o-editor .r6o-btn.outline {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}
.r6o-editor .r6o-btn.outline:hover {
  background: var(--pink-weak);
  color: var(--fg);
}
