
:root {
  /* Palette matched to socialmediamining.info brand */
  --bg: #ffffff;
  --bg-elev: #f0f5fa;        /* soft blue tint, used for sidebar/example boxes */
  --bg-warm: #f8f9fb;        /* near-white, for theorem/proof boxes */
  --ink: #333333;
  --ink-soft: #4a5568;
  --ink-muted: #6b7785;
  --accent: #0066CC;         /* primary blue (brand) */
  --accent-soft: #10659C;    /* hover / button border */
  --gold: #0066CC;           /* re-use brand blue for example labels */
  --rule: #eaeaea;
  --highlight: rgba(0, 102, 204, 0.08);
  /* Typography matched to brand: sans body, Georgia serif for display */
  --serif: 'Helvetica Neue', Arial, -apple-system, BlinkMacSystemFont, sans-serif;
  --display: Georgia, 'Times New Roman', serif;
  --sans: 'Helvetica Neue', Arial, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-elev);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* Top bar — matches socialmediamining.info Responsive theme exactly:
   white bg, 1px brand-blue bottom border, 1140px container, site title
   on left and inline menu on right, all inside a 28px-padded branding
   wrap. Position is sticky so the nav follows on scroll. */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: #ffffff;
  border-bottom: 1px solid var(--accent);
  font-family: var(--sans);
}
.topbar-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 15px;
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 32px;
  min-height: 76px;
  width: 100%;
}
.topbar .site-branding {
  flex: 0 0 auto;
}
.topbar .site-title {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 700;          /* bold like the live site */
  line-height: 1;
  color: var(--ink);
  letter-spacing: 0;
}
.topbar .title-link {
  text-decoration: none;
  color: inherit;
  border: none;
}
.topbar .title-link:hover .site-title {
  color: var(--accent-soft);
}
.topbar a {
  /* Override global a { border-bottom: 1px solid ... } rule */
  border-bottom: none;
}
.topbar .main-navigation {
  flex: 1 1 auto !important;
  display: flex !important;
  justify-content: flex-end !important;
  margin: 0 !important;
  padding: 0 !important;
}
.topbar .main-navigation .menu {
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  width: auto;
}
.topbar .main-navigation .menu > li {
  margin: 0 !important;
  padding: 0 !important;
  list-style: none !important;
  display: block;
  float: none !important;
}
.topbar .main-navigation .menu > li > a {
  display: block;
  padding: 14px 12px;        /* tighter horizontal padding so 7 items fit */
  color: var(--ink);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 15px;           /* slightly smaller than 16 to fit */
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  background: transparent;
  transition: color .15s, background .15s;
}
.topbar .main-navigation .menu > li > a:hover,
.topbar .main-navigation .menu > li > a:focus {
  color: var(--accent-soft);
  background: #ffffff;
}
.topbar .main-navigation .menu > li.current-menu-item > a {
  color: var(--accent);
}

/* Dark footer matching socialmediamining.info site footer */
.site-footer {
  background: #333333;
  color: #ffffff;
  font-family: var(--sans);
  font-size: 13px;
  padding: 28px 32px;
  text-align: center;
  margin-top: 0;
}
.site-footer a { color: #66a3d9; text-decoration: none; }
.site-footer a:hover { color: #ffffff; }

/* Buttons match site: square corners, brand blue, darker blue border */
button, .button, a.button {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent-soft);
  border-radius: 0;
  padding: 10px 18px;
  font-family: var(--sans); font-size: 14px; font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s;
}
button:hover, .button:hover, a.button:hover {
  background: var(--accent-soft);
}

/* Layout — matches socialmediamining.info theme container width (1140px),
   with white content area sitting on the soft blue page tint. */
.layout {
  display: grid; grid-template-columns: 260px minmax(0, 1fr);
  max-width: 1200px;
  margin: 24px auto;
  background: var(--bg);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  padding: 36px 22px 60px 28px;
  border-right: 1px solid var(--rule);
  background: var(--bg-elev);
  font-family: var(--sans); font-size: 14px; line-height: 1.55;
  height: calc(100vh - 50px); position: sticky; top: 60px; overflow-y: auto;
}
.sidebar h4 {
  font-family: var(--sans); font-size: 11px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-muted); margin: 0 0 14px 0;
}
.sidebar h4:not(:first-child) { margin-top: 32px; }
.sidebar ol { list-style: none; margin: 0 0 4px 0; padding: 0; }
.sidebar ol li a {
  display: flex; align-items: baseline; gap: 12px;
  padding: 6px 10px; color: var(--ink-soft); text-decoration: none;
  border-radius: 4px; transition: background .12s, color .12s;
}
.sidebar ol li a .n {
  font-size: 11px; color: var(--ink-muted);
  font-variant-numeric: tabular-nums; width: 18px; text-align: right; flex-shrink: 0;
}
.sidebar ol li a:hover { background: var(--bg-elev); color: var(--ink); }
.sidebar ol li a.active { background: var(--bg-elev); color: var(--accent); font-weight: 600; }
.sidebar ol li a.active .n { color: var(--accent); }
.subnav { list-style: none; margin: 4px 0 8px 30px; padding: 0 0 0 14px;
          border-left: 1px solid var(--rule); }
.subnav li a {
  display: block; padding: 4px 10px; color: var(--ink-muted);
  text-decoration: none; font-size: 12.5px; border-radius: 3px;
}
.subnav li a:hover { color: var(--ink); }

/* Main column. Wider than the prose itself so there's a right gutter
   where margin notes (\marginpar) can live without disrupting the text. */
main {
  padding: 56px 72px 120px 72px;
  max-width: 1040px;
  width: 100%;
  min-width: 0;
  position: relative;
}
/* Cap all direct children of main at the prose width, leaving the right
   gutter free for absolutely-positioned marginpars. Exceptions: the
   chapter header (eyebrow, h1, subtitle) and the prev/next nav, which
   can use the full main width. */
main > * { max-width: 620px; }
main > .chapter-eyebrow,
main > h1,
main > .chapter-subtitle,
main > .page-nav {
  max-width: none;
}
/* Equations stay within prose width. If a single equation is genuinely
   too wide to fit, it scrolls horizontally inside the box rather than
   sticking out into the margin gutter. */
main > .equation-block {
  overflow-x: auto;
  overflow-y: hidden;
}
.chapter-eyebrow {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-muted); margin-bottom: 18px;
}
h1 {
  font-family: var(--display); font-weight: 700; font-size: 44px;
  line-height: 1.15; letter-spacing: -0.5px;
  margin: 0 0 16px 0; color: var(--accent);
}
h1::after {
  content: ""; display: block;
  width: 60px; height: 3px; background: var(--accent);
  margin: 18px 0 0 0;
}
.chapter-subtitle {
  font-family: var(--display); font-style: italic; font-weight: 400;
  font-size: 22px; line-height: 1.4; color: var(--ink-soft);
  margin: 22px 0 56px 0;
  max-width: 580px;
}
h2 {
  font-family: var(--display); font-weight: 700; font-size: 28px;
  margin: 56px 0 16px 0; letter-spacing: -0.3px;
  color: var(--ink); scroll-margin-top: 80px;
}
h2 .num { color: var(--accent); font-weight: 400; margin-right: 14px;
          font-variant-numeric: tabular-nums; }
h3 {
  font-family: var(--display); font-weight: 700; font-size: 20px;
  margin: 36px 0 12px 0; color: var(--ink); scroll-margin-top: 80px;
}
h3 .num { color: var(--accent); font-weight: 400; margin-right: 12px;
          font-variant-numeric: tabular-nums; }

p { margin: 0 0 20px 0; }

.dropcap::first-letter {
  font-family: var(--display); font-weight: 400; font-size: 5em;
  float: left; line-height: .85; margin: 0.05em 0.08em -0.05em 0;
  color: var(--accent);
  font-variation-settings: "opsz" 144, "SOFT" 0;
}

a { color: var(--accent); text-decoration: none;
    border-bottom: 1px solid var(--accent-soft); transition: background .12s; }
a:hover { background: var(--highlight); }

strong { font-weight: 600; color: var(--ink); }
em { font-style: italic; }
ol, ul { padding-left: 24px; }
ol li, ul li { margin-bottom: 8px; }

/* Boxes */
.definition, .example, .theorem, .lemma, .proposition, .corollary,
.proof, .sidenote, .remark {
  margin: 32px 0; padding: 22px 26px; border-radius: 4px;
  background: var(--bg-elev); border-left: 3px solid var(--accent);
  font-size: 18px; line-height: 1.6;
}
.definition .label, .example .label, .theorem .label,
.lemma .label, .proposition .label, .corollary .label,
.proof .label, .sidenote .label, .remark .label {
  font-family: var(--sans); font-size: 10.5px; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent); display: block; margin-bottom: 8px;
}
.example { background: var(--bg-warm); border-left-color: var(--gold); }
.example .label { color: var(--gold); }
.proof { background: transparent; border-left: none; padding: 0 0 0 26px;
         border-left: 1px solid var(--rule); font-size: inherit; font-style: italic; }
.proof .label { font-style: normal; color: var(--ink-muted); }
.sidenote, .remark {
  background: #f9f5ec; border-left: 2px solid var(--accent-soft);
  font-family: var(--sans); font-size: 13.5px; line-height: 1.55;
  padding: 14px 18px;
}
.sidenote .label, .remark .label { color: var(--ink-muted); }

/* Figure */
figure { margin: 40px 0; padding: 0; text-align: center; }
figure img, figure svg {
  display: inline-block;
  max-width: 100%;
  height: auto;
  border-radius: 2px;
  vertical-align: top;
}
/* Constrain ALL figure images so 200dpi PDF rasterizations don't dominate
   the page. The pandoc-emitted style="width:N%" still applies when present. */
figure > img {
  max-width: 100%;
  max-height: 560px;
}
/* Bare images outside a <figure> wrapper */
main p > img:only-child {
  display: block;
  margin: 28px auto;
  max-width: 100%;
  max-height: 560px;
  width: auto;
  height: auto;
}
/* Side-by-side subfigures via flexbox so they reliably sit on one row.
   Use flex: 1 1 45% so subfigures share width equally rather than collapsing
   to image natural size. */
figure:has(.subfigblock) {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 12px 24px;
}
figure:has(.subfigblock) > figcaption {
  flex-basis: 100%;
  text-align: left;
}
figure .subfigblock {
  flex: 1 1 45%;
  min-width: 0;
  max-width: 48%;
  text-align: center;
}
/* Force subfigure images to FILL the flex slot so small-natural-pixel charts
   don't render as tiny thumbnails. Aspect ratio preserved via height: auto.
   This intentionally overrides any inline style="width:N%" pandoc emits — the
   subfigure layout dictates size, not the source \\includegraphics scale. */
figure .subfigblock img {
  display: block;
  margin: 0 auto;
  width: 100% !important;
  max-width: 100%;
  max-height: 420px;
  height: auto;
  object-fit: contain;
}
figure .subfig-caption {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 8px;
  font-style: italic;
}
figcaption {
  font-family: var(--sans); font-size: 13px; color: var(--ink-soft);
  margin-top: 14px; line-height: 1.5; max-width: 92%;
}
figcaption .label { font-weight: 600; color: var(--ink); margin-right: 6px; }

/* Margin notes (\marginpar / \marginnote) — sit in the right gutter,
   aligned to the top of their paragraph. Don't wrap into the prose. */
main p { position: relative; }  /* positioning context for the absolute aside */
aside.marginpar, .marginpar {
  display: block;
  position: absolute;
  left: calc(100% + 28px);
  top: 0;
  width: 170px;
  margin: 0;
  padding: 0 0 0 12px;
  border-left: 2px solid var(--accent-soft);
  background: transparent;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-muted);
  font-style: normal;
  text-align: left;
}
aside.marginpar p, .marginpar p {
  position: static;  /* override main p { position: relative } above */
  margin: 0;
}
aside.marginpar p + p, .marginpar p + p { margin-top: 4px; }

/* Tables */
table {
  border-collapse: collapse;
  margin: 28px auto;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  max-width: 100%;
}
table caption {
  caption-side: top;
  text-align: left;
  margin-bottom: 10px;
  font-family: var(--sans);
  color: var(--ink);
}
th, td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
thead th {
  border-top: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  font-weight: 600;
  font-family: var(--sans);
  letter-spacing: 0.01em;
  background: transparent;
}
tbody tr:last-child td {
  border-bottom: 1.5px solid var(--ink);
}
tbody tr:hover { background: var(--bg-elev); }

/* Code & math */
code { font-family: var(--mono); font-size: .85em;
       background: var(--bg-elev); padding: 1px 6px; border-radius: 3px; }
pre { background: var(--bg-elev); padding: 16px 20px; border-radius: 4px;
      overflow-x: auto; font-size: 14px; line-height: 1.5; }
pre code { background: none; padding: 0; }

.equation-block {
  margin: 28px 0; padding: 14px 0; text-align: center;
  overflow-x: auto; position: relative;
}
.equation-block .eq-num {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); color: var(--ink-muted); font-size: 13px;
}

/* Exercises */
.exercises { margin-top: 72px; padding-top: 36px; border-top: 1px solid var(--rule); }
.exercises h2 { margin-top: 0; }
.exercises ol { padding-left: 28px; }
.exercises li { margin-bottom: 16px; padding-left: 4px; }
.exercises li::marker { color: var(--accent); font-weight: 600; }

/* Page nav */
.pagenav {
  margin: 80px 0 0 0; padding-top: 32px; border-top: 1px solid var(--rule);
  display: flex; justify-content: space-between; gap: 24px; font-family: var(--sans);
}
.pagenav a {
  color: var(--ink-soft); text-decoration: none; border: none;
  display: flex; flex-direction: column; gap: 6px; max-width: 45%;
  padding: 14px 18px; border-radius: 6px; border: 1px solid var(--rule);
  transition: border-color .15s, background .15s;
}
.pagenav a:hover { background: none; border-color: var(--accent-soft); color: var(--accent); }
.pagenav .label {
  font-size: 10.5px; color: var(--ink-muted); letter-spacing: .14em;
  text-transform: uppercase; font-weight: 600;
}
.pagenav .ch-title { font-family: var(--display); font-size: 17px; font-weight: 500; }
.pagenav a.next { text-align: right; align-items: flex-end; margin-left: auto; }
.pagenav a.prev:only-child { margin-right: auto; }

/* Index page */
.toc-page main { max-width: 860px; }
.toc-part { margin: 48px 0 24px 0; }
.toc-part h3 {
  font-family: var(--sans); font-size: 11px; font-weight: 700;
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-muted); border-bottom: 1px solid var(--rule);
  padding-bottom: 8px; margin: 0 0 20px 0;
}
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list > li { margin: 0 0 4px 0; }
.toc-list > li > a {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: baseline;
  gap: 16px; padding: 14px 16px; color: var(--ink); text-decoration: none;
  border: none; border-radius: 6px; transition: background .12s;
}
.toc-list > li > a:hover { background: var(--bg-elev); }
.toc-list .ch-num {
  font-family: var(--mono); font-size: 13px; color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.toc-list .ch-title {
  font-family: var(--display); font-size: 22px; font-weight: 500;
  letter-spacing: -0.01em;
}
.toc-list .ch-arrow { color: var(--ink-muted); font-family: var(--sans); }

/* Algorithm blocks */
.algorithm-block {
  margin: 28px 0;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fdfcf6;
  overflow: hidden;
}
.algo-header {
  background: #f3eedd;
  padding: 10px 16px;
  font-family: var(--sans);
  font-size: 13px;
  border-bottom: 1px solid var(--rule);
  letter-spacing: 0.02em;
}
.algo-label {
  color: var(--accent);
  font-weight: 600;
}
.algo-num { font-weight: 600; color: var(--accent); margin-right: 0.25em; }
.algo-caption { color: var(--ink); }
.algo-body {
  list-style-type: decimal;
  list-style-position: outside;
  padding: 14px 16px 14px 50px;
  margin: 0;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
}
.algo-body li {
  padding: 1px 0;
  color: var(--ink);
}
.algo-body li b { color: var(--accent); font-weight: 600; }

/* Cross-reference links */
a.xref-fig, a.xref-tab, a.xref-eq, a.xref-alg, a.xref-sec {
  color: var(--accent);
  border-bottom: 1px dotted var(--accent);
  text-decoration: none;
}
a.xref-fig:hover, a.xref-tab:hover, a.xref-eq:hover,
a.xref-alg:hover, a.xref-sec:hover {
  background: var(--highlight);
  border-bottom-style: solid;
}

/* Figure and table caption labels */
.fig-label, .tab-label {
  color: var(--accent);
  font-weight: 600;
  font-family: var(--sans);
  letter-spacing: 0.01em;
}

/* Footnote markers (pandoc emits <sup><a href="#fn1">1</a></sup>) */
sup a, a.footnote-ref {
  color: var(--accent);
  text-decoration: none;
  font-variant-numeric: oldstyle-nums;
  font-size: 0.8em;
  margin: 0 0.1em 0 0.05em;
  border: none;
}
sup a:hover, a.footnote-ref:hover {
  background: var(--highlight);
}
/* Footnote section at the bottom of the chapter */
section.footnotes, .footnotes {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
  color: var(--ink-muted);
  line-height: 1.55;
}
.footnotes ol { padding-left: 24px; }
.footnotes li { margin-bottom: 8px; }
.footnotes a.footnote-back {
  color: var(--accent);
  text-decoration: none;
  margin-left: 4px;
}

/* Cross-reference links to theorem-like envs */
a.xref-thm, a.xref-lem, a.xref-def, a.xref-ex,
a.xref-prop, a.xref-cor, a.xref-rem {
  color: var(--accent);
  border-bottom: 1px dotted var(--accent);
  text-decoration: none;
}
a.xref-thm:hover, a.xref-lem:hover, a.xref-def:hover, a.xref-ex:hover,
a.xref-prop:hover, a.xref-cor:hover, a.xref-rem:hover {
  background: var(--highlight);
}

/* Citations (rendered by --citeproc when bib parses; styled fallback when not) */
.citation {
  color: var(--accent);
  font-variant-numeric: oldstyle-nums;
}
.citation a {
  color: inherit;
  border-bottom: none;
}
.citation a:hover { background: var(--highlight); }

/* Missing figures show a hint instead of a broken image */
img[alt^="[missing"] {
  display: inline-block;
  padding: 14px 18px;
  background: repeating-linear-gradient(45deg, #f4f0e3, #f4f0e3 6px, #ebe6d4 6px, #ebe6d4 12px);
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: 12px;
  border-radius: 4px;
  width: auto;
  height: auto;
  min-height: 80px;
}

/* Responsive — three tiers of fallback as viewport shrinks */
@media (max-width: 1100px) {
  /* Below the gutter threshold: drop max-width caps, marginpars become inline */
  main { max-width: 100%; }
  main > * { max-width: 100%; }
  .marginpar {
    position: static;
    float: right;
    clear: right;
    width: 150px;
    margin: 4px 0 8px 24px;
    padding: 8px 12px;
    background: var(--bg-elev);
    border-radius: 0 3px 3px 0;
  }
}

@media (max-width: 992px) {
  /* Match WP: nav menu wraps below title on tablet/mobile, smaller padding */
  .topbar-inner {
    flex-wrap: wrap;
    padding: 0 18px;
    min-height: 60px;
    gap: 0;
  }
  .topbar .main-navigation {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--rule);
    margin-top: 8px;
  }
  .topbar .main-navigation .menu {
    flex-wrap: nowrap;
    white-space: nowrap;
    padding-bottom: 4px;
  }
  .topbar .main-navigation .menu > li > a {
    padding: 10px 12px;
    font-size: 14px;
  }
}

@media (max-width: 960px) {
  /* Tablet: collapse the layout grid, hide the sidebar */
  .layout {
    grid-template-columns: 1fr;
    margin: 16px;
    border-radius: 6px;
  }
  .sidebar { display: none; }
  main { padding: 36px 28px 80px 28px; }
  h1 { font-size: 36px; }
  .chapter-subtitle { font-size: 18px; margin-bottom: 36px; }
}

@media (max-width: 720px) {
  /* Phone: tighter padding, smaller type, marginpars become inline blocks */
  .layout { margin: 0; border-radius: 0; box-shadow: none; }
  main { padding: 28px 18px 60px 18px; }
  body { font-size: 15px; line-height: 1.7; }
  h1 { font-size: 28px; }
  h2 { font-size: 22px; margin-top: 40px; }
  h3 { font-size: 18px; margin-top: 28px; }
  .chapter-eyebrow { font-size: 11px; }
  .chapter-subtitle { font-size: 16px; }
  .topbar-inner { min-height: 54px; padding: 0 14px; }
  .topbar .site-title { font-size: 18px; }
  .marginpar {
    float: none;
    width: auto;
    margin: 12px 0;
    padding: 10px 12px;
    border-left: 2px solid var(--accent-soft);
  }
  /* Wide content scrolls horizontally inside its box rather than overflowing */
  figure, table, .equation-block, .algorithm-block {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  figure img { max-width: 100%; height: auto; }
  table { font-size: 13px; }
  th, td { padding: 6px 10px; }
  pre { font-size: 12px; }
  .math.inline {
    display: inline-block;
    max-width: 100%;
    vertical-align: middle;
  }
  .math.display { font-size: 14px; }
  main p { overflow-wrap: break-word; word-break: break-word; }
}
