/* Botanical fonts (Cormorant display serif + IBM Plex Sans/Mono) — shared by both themes,
   so a light/dark toggle changes only colors, never the typography. */
@import url('https://fonts.googleapis.com/css2?family=Cormorant:wght@500;600&family=IBM+Plex+Sans:wght@300;400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --navy:   #1a222c;
  --accent: #5755d9;
  --head:   #333;
  --body:   #555;
  --line:   #e6e8ec;
  --bg:     #ffffff;
  --soft:   #f6f7f9;
  --topbar-h: 52px;
}
:root[data-theme="dark"] {
  /* Dark Botanical palette (matches the slide deck). */
  --navy:   #221b14;                    /* topbar / table headers / badge — warm charcoal */
  --accent: #d8a24a;                    /* gold */
  --head:   #f3ece1;                    /* ivory */
  --body:   #b0a48f;                    /* muted */
  --line:   rgba(243, 236, 225, 0.14);  /* faint ivory rule */
  --bg:     #0e0c0b;                    /* near-black, warm */
  --soft:   #16110d;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  color: var(--body); background: var(--bg);
  line-height: 1.6; font-size: 16px;
  height: 100vh; overflow: hidden;
  display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- smooth light/dark theme cross-fade ----------
   Universal rule kept at zero specificity (plain `*`) so every element-specific
   transition below (button hovers, TOC grid collapse, lightbox, etc.) still wins;
   only the token-driven colors animate when [data-theme] flips. */
*, *::before, *::after {
  transition: background-color .5s ease, border-color .5s ease, color .5s ease, fill .5s ease;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none; }
}

/* ---------- top bar ---------- */
.topbar { flex: 0 0 var(--topbar-h); background: var(--navy); color: #fff; z-index: 40; }
.topbar .inner {
  width: 100%; height: 100%; padding: 0 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.topbar .grp { display: flex; align-items: center; gap: 12px; }
.topbar a.home { color: #fff; font-weight: 600; font-size: .95rem; }
.topbar a.home:hover { color: #cfd0f5; text-decoration: none; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 1px solid rgba(255,255,255,.25);
  background: transparent; color: #fff; border-radius: 8px; cursor: pointer;
  font-size: 1.05rem; line-height: 1; transition: background .15s;
}
.iconbtn:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.iconbtn svg { width: 18px; height: 18px; fill: currentColor; }
.textbtn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px;
  border: 1px solid rgba(255,255,255,.25); background: transparent; color: #fff;
  border-radius: 8px; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600;
  transition: background .15s;
}
.textbtn:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.textbtn svg { width: 15px; height: 15px; fill: currentColor; }

/* narrow phones: keep the top bar to one clean row of 34px icon buttons.
   The view-toggle collapses to its icon; Home moves into the hamburger menu. */
@media (max-width: 700px) {
  .topbar .inner { padding: 0 10px; gap: 8px; }
  .topbar .grp   { gap: 8px; }
  .topbar a.home { display: none; }
  .textbtn       { width: 34px; padding: 0; gap: 0; justify-content: center; }
  .textbtn .btn-label { display: none; }
  .textbtn svg   { width: 17px; height: 17px; }
}

/* The two-column reader only lays out at >=1400px; below that both views render
   as a single column, so the whole view-toggle is meaningless -- hide it. */
@media (max-width: 1399px) {
  .textbtn--wideonly { display: none; }
}

/* ---------- reader (three columns) ---------- */
.reader { flex: 1 1 auto; min-height: 0; }
/* same-page anchor jumps (TOC + in-prose section links) animate on every scroll
   container: .reader scrolls below 1400px and on the article page, the others on wide. */
.reader, #toc, #col-text, #col-media { scroll-behavior: smooth; }

@media (min-width: 1400px) {
  .reader {
    display: grid;
    grid-template-columns: 248px minmax(440px, 0.82fr) minmax(0, 1.18fr);
    transition: grid-template-columns .28s ease;
  }
  body.toc-collapsed .reader {
    grid-template-columns: 0 minmax(440px, 0.82fr) minmax(0, 1.18fr);
  }
  #toc, #col-text, #col-media { height: 100%; overflow-y: auto; overflow-x: hidden; }
  #col-media { display: block; position: relative; overflow-x: hidden; border-left: 1px solid var(--line); }
  #toc {
    min-width: 0; border-right: 1px solid var(--line); overflow-x: hidden;
    transition: opacity .2s ease, padding .28s ease;
  }
  /* fully collapse: no width, padding, border, or visible content */
  body.toc-collapsed #toc {
    padding-left: 0; padding-right: 0; border-right: 0; opacity: 0; overflow: hidden;
  }
}
@media (max-width: 1399px) {
  .reader { height: 100%; overflow-y: auto; overflow-x: hidden; }
  #col-text { overflow: visible; height: auto; }
  #col-media { display: none; }        /* media stays inline in the text on narrow */
}

/* ---------- index panel ---------- */
#toc { background: var(--bg); padding: 22px 18px; }
#toc .toc-head {
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase; letter-spacing: .18em; font-size: .72rem;
  font-weight: 700; color: var(--accent); margin: 0 0 12px;
}
#toc a {
  display: block; padding: 5px 10px; margin: 1px 0; border-radius: 6px;
  color: var(--body); font-size: .86rem; line-height: 1.35; text-align: left;
  border-left: 2px solid transparent;
}
#toc a:hover { background: var(--soft); text-decoration: none; }
/* ---- collapsible Contents tree (h2 -> h3 -> h4) ---- */
#toc .toc-row { display: flex; align-items: center; }
#toc .toc-link { flex: 1 1 auto; min-width: 0; margin: 0; }   /* the <a>; inherits #toc a styling */
#toc .toc-children { padding-left: 13px; }                    /* one indent step per nesting level */
#toc .toc-item.collapsed > .toc-children { display: none; }
#toc .toc-item.toc-lvl2 { margin-top: 6px; }
#toc-list > .toc-item.toc-lvl2:first-child { margin-top: 0; }
#toc a.toc-h2 { font-weight: 600; color: var(--head); }
#toc a.toc-h3 { font-size: .82rem; }
#toc a.toc-h4 { font-size: .78rem; opacity: .82; }
/* caret: right-pointing triangle that rotates down when the node is expanded */
#toc .toc-toggle {
  flex: 0 0 15px; width: 15px; height: 22px; padding: 0; margin: 0;
  border: 0; background: none; cursor: pointer; color: var(--body);
  display: inline-flex; align-items: center; justify-content: center;
}
#toc .toc-toggle::before {
  content: ""; width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 3.5px solid transparent; border-bottom: 3.5px solid transparent;
  transition: transform .15s ease;
}
#toc .toc-item:not(.collapsed) > .toc-row > .toc-toggle::before { transform: rotate(90deg); }
#toc .toc-toggle:hover { color: var(--accent); }
#toc .toc-item.toc-leaf > .toc-row > .toc-toggle { visibility: hidden; }
#toc a.active {
  color: var(--accent); font-weight: 600;
  border-left-color: var(--accent); background: var(--soft);
}
/* narrow: index becomes a slide-in overlay toggled by the hamburger */
@media (max-width: 1399px) {
  #toc {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: 264px; z-index: 30;
    border-right: 1px solid var(--line); overflow-y: auto;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  body.toc-open #toc { transform: translateX(0); box-shadow: 0 0 32px rgba(0,0,0,.22); }
}

/* ---------- text column ---------- */
.col-inner { max-width: 720px; margin: 0 auto; padding: 0 30px 8px; }
header.masthead { text-align: center; padding: 44px 0 30px; border-bottom: 1px solid var(--line); }
.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase; letter-spacing: .18em; font-size: .72rem;
  font-weight: 700; color: var(--accent); margin: 0 0 12px;
}
header.masthead h1 {
  margin: 0 0 12px; color: var(--head);
  font-family: 'Cormorant', Georgia, serif;
  font-size: 2.35rem; line-height: 1.2; font-weight: 600; letter-spacing: .01em;
}
header.masthead p.sub { margin: 0 auto 22px; color: var(--body); font-size: 1.04rem; max-width: 620px; }
.repo-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: .95rem;
  padding: 11px 20px; border-radius: 8px; transition: background .15s, color .3s ease;
}
.repo-btn:hover { background: #4442c4; text-decoration: none; }
:root[data-theme="dark"] .repo-btn:hover { background: #e6b463; }
.repo-btn svg { width: 18px; height: 18px; fill: currentColor; }
/* primary (GitHub) + secondary (Slides) buttons sit side by side, centered */
.cta-row { display: inline-flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.slides-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; color: var(--accent); border: 1.5px solid var(--accent);
  font-weight: 600; font-size: .95rem; padding: 10px 20px; border-radius: 8px;
  transition: background .15s, color .15s, border-color .3s ease;
}
.slides-btn:hover { background: var(--accent); color: #fff; text-decoration: none; }
:root[data-theme="dark"] .slides-btn:hover { color: #1a1410; }   /* dark ink on gold fill */
.slides-btn svg { width: 18px; height: 18px; fill: currentColor; }

.text-body { padding-top: 22px; text-align: left; }
.text-body h1, .text-body h2, .text-body h3, .text-body h4 {
  font-family: 'Cormorant', Georgia, serif;
  color: var(--head); font-weight: 600; line-height: 1.25; letter-spacing: .01em;
  margin: 1.6em 0 .5em; scroll-margin-top: 16px;
}
.text-body h1 { font-size: 1.95rem; }
.text-body h2 { font-size: 1.6rem; padding-top: .5em; border-top: 1px solid var(--line); }
.text-body h3 { font-size: 1.28rem; }
.text-body h4 { font-size: 1rem; }
.text-body p { margin: 0 0 1em; text-align: justify; }
.text-body ul, .text-body ol { padding-left: 1.6rem; margin: 0 0 1em; text-align: left; }
.text-body li { margin: .3em 0; }
.text-body blockquote {
  margin: 1em 0; padding: .5em 1.2em;
  border-left: 3px solid var(--accent); background: var(--soft); color: var(--body); text-align: left;
}
.text-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .88em; background: var(--soft); padding: 1px 5px; border-radius: 4px;
}
.anchor-link { display: none; }
.media-anchor { display: block; height: 0; margin: 0; }
/* a wide display equation scrolls within its own box, never the whole page */
mjx-container[display="true"] { max-width: 100%; overflow-x: auto; overflow-y: hidden; }

/* ---------- media (figures + tables) ---------- */
#col-media { padding: 26px 30px; }
.media-block {
  margin: 0 0 34px; padding: 10px; border-radius: 10px; scroll-margin-top: 18px;
  overflow-x: auto;   /* extra-wide tables scroll within their own block */
  transition: box-shadow .2s ease, background .2s ease, opacity .3s ease;
}
#col-media .media-block.active { background: var(--soft); box-shadow: 0 0 0 1px var(--line); }
/* focus effect: dim the non-active blocks; disabled while hovering the panel */
#col-media.focus-mode .media-block { opacity: .3; }
#col-media.focus-mode .media-block.active { opacity: 1; }
/* space between several tables stacked inside one block */
.media-block .jp-OutputArea-child + .jp-OutputArea-child,
.media-block .jp-OutputArea-output + .jp-OutputArea-output,
.media-block .output_area + .output_area { margin-top: 20px; }
/* subtle scrollbar for the per-block horizontal scroll */
.media-block::-webkit-scrollbar { height: 8px; }
.media-block::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.media-block img {
  display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px;
}
:root[data-theme="dark"] .media-block img { background: #fff; padding: 8px; box-shadow: 0 1px 10px rgba(0,0,0,.4); }
table, table.dataframe {
  border-collapse: collapse; margin: 0 auto; font-size: .84rem; width: auto; max-width: 100%;
}
table.dataframe th, table.dataframe td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: right; color: var(--body);
}
table.dataframe th { background: var(--navy); color: #fff; font-weight: 600; }
table.dataframe tbody tr:nth-child(even) { background: var(--soft); }
table.dataframe thead th:first-child, table.dataframe tbody th { text-align: left; }
/* inline media (narrow screens) get breathing room within the prose column */
@media (max-width: 1399px) { .media-block { margin: 1.4em 0; } }

/* ---------- footer ---------- */
footer.site { border-top: 1px solid var(--line); margin-top: 36px; padding: 26px 0 40px; }
footer.site .inner { color: var(--body); font-size: .9rem; text-align: center; }
footer.site .badge {
  display: inline-block; background: var(--navy); color: #fff; font-weight: 600;
  font-size: .78rem; padding: 4px 12px; border-radius: 20px; margin-bottom: 12px;
}

/* ---------- scroll-to-top ---------- */
#scroll-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 45;
  width: 46px; height: 46px; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.3rem; cursor: pointer;
  box-shadow: 0 3px 14px rgba(0,0,0,.25);
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s, background-color .3s ease, color .3s ease;
}
#scroll-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
#scroll-top:hover { background: #4442c4; }
:root[data-theme="dark"] #scroll-top:hover { background: #e6b463; }

/* ---------- image zoom (single-column mode) ---------- */
@media (max-width: 1399px) { .media-block img { cursor: zoom-in; } }
#lightbox {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.82); padding: 24px; cursor: zoom-out;
  opacity: 0; visibility: hidden;
  transition: opacity .28s ease, visibility .28s ease;
}
#lightbox.open { opacity: 1; visibility: visible; }
#lightbox img {
  max-width: 96vw; max-height: 92vh; border-radius: 8px; background: #fff;
  box-shadow: 0 12px 48px rgba(0,0,0,.55);
  transform: scale(.82); transition: transform .28s cubic-bezier(.2,.7,.3,1);
}
#lightbox.open img { transform: scale(1); }

/* ---------- Dark-mode control color overrides ----------
   Typography (Cormorant + IBM Plex) is shared by both themes above, so switching theme is
   a pure color cross-fade with no font swap or reflow. Only colors differ per theme. */
/* Gold buttons need dark ink, not white, for legibility. */
:root[data-theme="dark"] .repo-btn,
:root[data-theme="dark"] #scroll-top { color: #1a1410; }
/* Keep the topbar home-link hover on-palette (was periwinkle). */
:root[data-theme="dark"] .topbar a.home:hover { color: #e6b463; }

/* ---------- print / PDF export: single-column, LNCS-like ---------- */
@page { size: A4; margin: 2cm; }
@page wide { size: A4 landscape; margin: 1.5cm; }
@media print {
  :root { --bg:#fff; --body:#000; --head:#000; --soft:#f2f2f2; --line:#bbb; --accent:#000; }
  html, body {
    height: auto; overflow: visible; display: block; background: #fff; color: #000;
    font-family: "Times New Roman", Times, serif; font-size: 10pt; line-height: 1.2;
  }
  .topbar, #toc, #scroll-top, #export-pdf, #lightbox { display: none !important; }
  .reader { display: block !important; height: auto; overflow: visible; }
  #col-text, #col-media { display: block; height: auto; overflow: visible; }
  #col-media { border: none; padding: 0; }
  .col-inner { max-width: none; padding: 0; }

  /* LNCS-style title block + headings (serif, bold, numbered) */
  header.masthead { border: none; padding: 0 0 6pt; }
  header.masthead .eyebrow { display: none; }
  header.masthead .repo-btn, header.masthead .slides-btn { display: none; }
  header.masthead h1 { font-family: "Times New Roman", Times, serif; font-size: 15pt; margin: 0 0 6pt; }
  header.masthead p.sub { font-size: 10pt; font-style: italic; color: #000; max-width: none; }
  .text-body { padding-top: 8pt; }
  .text-body h1, .text-body h2, .text-body h3, .text-body h4 {
    font-family: "Times New Roman", Times, serif; color: #000; border: none; padding: 0;
    margin: 12pt 0 4pt; break-after: avoid;
  }
  .text-body h2 { font-size: 12pt; } .text-body h3 { font-size: 11pt; } .text-body h4 { font-size: 10pt; }
  .text-body p { text-align: justify; margin: 0 0 6pt; }
  .text-body code { background: none; font-size: 9pt; }
  a { color: #000; text-decoration: none; }

  /* figures + tables: centered, small, kept whole */
  .media-block {
    opacity: 1 !important; background: none !important; box-shadow: none !important;
    overflow: visible; margin: 10pt auto; padding: 0; text-align: center; break-inside: avoid;
  }
  .media-block table { font-size: 8.5pt; margin: 0 auto; }
  .media-block img, table, tr { break-inside: avoid; }

  /* extra-wide tables print sideways on their own landscape page */
  .media-block.wide-table { page: wide; break-before: page; break-after: page; overflow: visible; }
  .media-block.wide-table table { font-size: 9pt; }
}
