/* Reader-page layout. The page is full-height, with a sticky sidebar TOC
   on the left and a scrollable article column on the right. */

.reader-shell {
  display: grid;
  grid-template-columns: 22rem minmax(0, 1fr);
  min-height: calc(100vh - 4rem);
}

.reader-sidebar {
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
}

.reader-sidebar-inner {
  padding: 1.75rem 1.5rem 2.5rem;
}

.reader-content {
  min-width: 0;
}

.reader-content-inner {
  max-width: 56rem;
  padding: 2.5rem 2rem 6rem;
  margin: 0 auto;
}

/* Mobile: sidebar becomes a drawer toggled by the Contents button. */
@media (max-width: 900px) {
  .reader-shell {
    grid-template-columns: 1fr;
  }
  .reader-sidebar {
    position: fixed;
    top: 3.5rem;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    max-height: none;
    background: #fbf7ef;
    border-right: 0;
    border-bottom: 1px solid rgba(12, 18, 32, 0.08);
    transform: translateY(-100%);
    transition: transform 0.2s ease-out;
  }
  .reader-sidebar.open {
    transform: translateY(0);
  }
  .reader-content-inner {
    padding: 1.5rem 1.25rem 4rem;
  }
}

/* --- table of contents -------------------------------------------------- */
.toc .toc-group + .toc-group {
  margin-top: 1.25rem;
}

.toc .toc-group-label {
  font-family: 'Lora', ui-serif, Georgia;
  font-size: 0.95rem;
  font-weight: 600;
  color: #0c1220;
  margin-bottom: 0.35rem;
}

.toc .toc-group-blurb {
  font-size: 0.78rem;
  color: rgba(12, 18, 32, 0.6);
  line-height: 1.45;
  margin-bottom: 0.5rem;
}

.toc .toc-list {
  border-left: 1px solid rgba(12, 18, 32, 0.1);
  margin-left: 0.25rem;
}

.toc .toc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem 0.3rem 0.75rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: rgba(12, 18, 32, 0.75);
  cursor: pointer;
  font-size: 0.84rem;
  line-height: 1.35;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.toc .toc-item:hover {
  background: rgba(252, 211, 77, 0.18);
  color: #0c1220;
}

.toc .toc-item.active {
  border-left-color: #f5b642;
  color: #0c1220;
  font-weight: 600;
  background: rgba(252, 211, 77, 0.22);
}

.toc .toc-item .pdf-link {
  margin-left: auto;
  font-size: 0.72rem;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular;
  color: rgba(12, 18, 32, 0.5);
  text-decoration: none;
  padding: 0.05rem 0.35rem;
  border: 1px solid rgba(12, 18, 32, 0.15);
  border-radius: 3px;
}

.toc .toc-item .pdf-link:hover {
  color: #0c1220;
  border-color: rgba(12, 18, 32, 0.4);
  background: white;
}

/* --- article typography ------------------------------------------------- */
.prose-paper {
  color: #0c1220;
  font-family: 'Lora', ui-serif, Georgia;
  font-size: 1.07rem;
  line-height: 1.7;
}

.prose-paper > * + * { margin-top: 1rem; }

.prose-paper h1,
.prose-paper h2,
.prose-paper h3,
.prose-paper h4,
.prose-paper h5,
.prose-paper h6 {
  font-family: 'Lora', ui-serif, Georgia;
  color: #0c1220;
  line-height: 1.2;
  margin-top: 2.25rem;
  margin-bottom: 0.5rem;
}

.prose-paper h1 { font-size: 2.1rem; font-weight: 700; }
.prose-paper h2 { font-size: 1.75rem; font-weight: 700; }
.prose-paper h3 { font-size: 1.35rem; font-weight: 600; }
.prose-paper h4 { font-size: 1.15rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(12,18,32,0.75); }
.prose-paper h5,
.prose-paper h6 { font-size: 1rem; font-weight: 600; color: rgba(12,18,32,0.7); }

.prose-paper p { margin: 0.9rem 0; }

.prose-paper a {
  color: #1f4f8b;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.prose-paper a:hover { color: #d99528; }

.prose-paper ul,
.prose-paper ol {
  margin: 0.9rem 0 0.9rem 1.5rem;
}
.prose-paper ul { list-style: disc; }
.prose-paper ol { list-style: decimal; }
.prose-paper li + li { margin-top: 0.35rem; }

.prose-paper blockquote {
  border-left: 4px solid #f5b642;
  padding: 0.35rem 1rem;
  margin: 1rem 0;
  color: rgba(12,18,32,0.85);
  font-style: italic;
  background: rgba(252, 211, 77, 0.15);
  border-radius: 0 6px 6px 0;
}

.prose-paper code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular;
  font-size: 0.92em;
  background: rgba(12,18,32,0.06);
  padding: 0.06em 0.32em;
  border-radius: 3px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.prose-paper pre {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular;
  font-size: 0.85rem;
  line-height: 1.55;
  background: #0c1220;
  color: #fbf7ef;
  padding: 1rem 1.1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.2rem 0;
}
.prose-paper pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.prose-paper hr {
  border: 0;
  border-top: 1px solid rgba(12,18,32,0.15);
  margin: 2rem 0;
}

.prose-paper img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 6px;
}

.prose-paper table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.95rem;
}
.prose-paper th,
.prose-paper td {
  border: 1px solid rgba(12,18,32,0.12);
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.prose-paper thead { background: rgba(12,18,32,0.06); }

mjx-container:not([display="true"]) {
  display: inline;
  vertical-align: -0.15em;
  max-width: none;
}
mjx-container:not([display="true"]) svg {
  display: inline;
  vertical-align: inherit;
  max-width: none;
}

mjx-container[display="true"] {
  display: block;
  max-width: 100%;
  margin: 1rem 0 !important;
  overflow-x: auto;
  overflow-y: visible;
}

.reader-loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: rgba(12,18,32,0.55);
  font-style: italic;
}

.reader-loading::before {
  content: "";
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  border: 2px solid rgba(12,18,32,0.25);
  border-top-color: #d99528;
  animation: reader-spin 0.8s linear infinite;
}

@keyframes reader-spin {
  to { transform: rotate(360deg); }
}

.reader-error {
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.07);
  color: #7f1d1d;
  padding: 1rem 1.25rem;
  border-radius: 6px;
}
