/* =====================================================
   scholar.css — unified layout with scholar2.css colors + delayed note reveal
   ===================================================== */

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #222;
  --muted: #555;
  --link: #1661de;
  --maxw: 1200px;
  --gap: 2rem;
  --border: #e6e6e6;
}

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

/* --- Body --- */
body {
  font-family: "Work Sans", "Helvetica Neue", "Segoe UI", sans-serif;
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  background-attachment: fixed;
}

/* --- Headings --- */
h1, h2, h3, h4 {
  font-family: "Source Serif 4", "Georgia", serif;
  color: var(--text);
  line-height: 1.25;
  margin-top: 1.6em;
  margin-bottom: 0.4em;
}
h1 { font-size: 1.9rem; margin-top: 0; letter-spacing: 0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }

/* --- Paragraphs and lists --- */
p, ul, ol { margin-top: 0.8em; margin-bottom: 0.8em; }

/* --- Links --- */
a {
  color: var(--link);
  text-decoration: none;
}
a:hover, a:focus { text-decoration: underline; }

/* --- Header (aligned with main text box) --- */
.site-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  max-width: var(--maxw);
  margin: 2rem auto 1rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.site-header .header-image img {
  width: 100%;
  height: auto;
  max-height: 200px;
  object-fit: contain;
  filter: contrast(95%) brightness(102%) saturate(85%);
}

.site-header h1,
.site-header h2,
.site-header h3 {
  margin: 0.5rem 0;
  text-align: left;
}

.site-nav {
  font-family: "Work Sans", "Helvetica Neue", sans-serif;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  background: transparent;
  padding: 0.4rem 0 0;
  text-align: left;
}
.site-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 0 0.3rem 0 0;
}
.site-nav a:hover { text-decoration: underline; }

html { scroll-behavior: auto; }

/* --- Layout grid (main + sidebar) --- */
.wrap {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--gap);
  max-width: var(--maxw);
  margin: 2rem auto;
  padding: 0 1.5rem;
  align-items: flex-start;
}

.wrap > article,
.wrap > .aside-notes {
  margin-top: 0;
  align-self: start;
}

@media (max-width: 900px) {
  .wrap { display: block; }
}

/* --- Sidebar notes (compact + delayed reveal) --- */
.aside-notes {
  position: sticky;
  top: 1rem;
  align-self: flex-start;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding-left: 1rem;
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: #bbb var(--bg);
  font-size: 0.88rem;
  line-height: 1.45;
  scroll-behavior: smooth;
  overscroll-behavior: contain;

  /* Hidden by default */
  opacity: 0;
  transform: translateX(1rem);
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.aside-notes.visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.aside-notes ol {
  list-style: none;
  padding-left: 0;
  margin: 0;
  counter-reset: note;
}

.aside-notes li {
  counter-increment: note;
  margin-bottom: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1em;
}

.aside-notes li::before {
  content: "[" counter(note) "]";
  color: #666;
  font-size: 0.8rem;
  line-height: 1.1;
  margin-bottom: 0.1rem;
}

.aside-notes li.active {
  background: #f2f6fc;
  border-left: 3px solid #b3c8f9;
  padding-left: 0.4rem;
  transition: background 0.3s ease, border-color 0.3s ease;
  border-radius: 3px;
}

/* --- Table of Contents --- BASIC
.table-of-contents {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem 1.2rem;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}
.table-of-contents a { color: var(--link); }
.table-of-contents a:hover { text-decoration: underline; }*/

/* Table of Contents styling */
#toc {
  background: #f9fafb;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
}

#toc ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

#toc li {
  margin: 0.3rem 0;
}

#toc a {
  text-decoration: none;
  color: #1e40af;
  transition: color 0.2s;
}

#toc a:hover {
  color: #2563eb;
  text-decoration: underline;
}

/* Indentation for hierarchy */
#toc ul ul {
  margin-left: 1rem;
  border-left: 1px solid #e5e7eb;
  padding-left: 0.8rem;
}

#toc ul ul ul {
  margin-left: 1rem;
  border-left: 1px dashed #d1d5db;
  padding-left: 0.8rem;
}


/* --- Blockquotes --- */
blockquote {
  font-family: "Source Serif 4", "Georgia", serif;
  border-left: 3px solid var(--border);
  margin: 1.2rem 0;
  padding: 0.4rem 1rem;
  font-style: italic;
  color: var(--muted);
  background: #fafafa;
}

/* --- Footer --- */
footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  padding: 1rem 2rem;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  background: var(--surface);
}
footer a { color: inherit; text-decoration: underline; }

/* --- Responsive refinements --- */
@media (max-width: 700px) {
  body { font-size: 1rem; }
  .wrap { padding: 0 1rem; }
  h1 { font-size: 1.6rem; }
  .aside-notes {
    position: static;
    border-left: none;
    height: auto;
    font-size: 0.86rem;
    line-height: 1.4;
  }
  .site-header {
    padding: 0 1rem;
    margin: 1.5rem auto 1rem;
  }
  .site-nav { text-align: left; }
}

/* --- Optional layout variants --- */
body.wide-notes .wrap { grid-template-columns: 2fr 1fr; }
body.wide-notes .aside-notes { font-size: 0.9rem; line-height: 1.45; }
body.no-sidebar .wrap {
  display: block;
  max-width: 800px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}
body.no-sidebar .aside-notes { display: none; }
body.no-sidebar article { margin: 0 auto; }

/* --- JS trigger comment --- */
/* Paste this near the end of your HTML:
<script>
document.addEventListener("DOMContentLoaded", () => {
  const notes = document.querySelector(".aside-notes");
  const firstNoteRef = document.querySelector("sup[id^='fnref'], a[href*='#note'], a[href*='#fn']");

  if (notes && firstNoteRef) {
    const observer = new IntersectionObserver(entries => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          notes.classList.add("visible");
          observer.disconnect();
        }
      });
    }, { threshold: 0.5 });

    observer.observe(firstNoteRef);
  }
});
</script>
*/


.wrap article figure {
  display: block;
  max-width: 90%;
  margin: 1.5rem auto;
  text-align: center;
}

.wrap article figure img {
  display: block;
  height: auto;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.wrap article figcaption {
  font-family: "Source Serif 4", "Georgia", serif;
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 0.4rem;
  line-height: 1.4;
}

/* --- Figures (natural size, never stretched, grid-safe) --- */
.wrap article figure {
  display: block;
  width: 100%;
  margin: 1.5rem auto;
  text-align: center;
}

.wrap article figure img {
  display: block;
  max-width: 90%;
  height: auto;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.wrap article figcaption {
  font-family: "Source Serif 4", "Georgia", serif;
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 0.4rem;
  line-height: 1.4;
}
