/* =============================================================================
   Minimal, LaTeX-adjacent typography for academic HTML
   Vanilla CSS · No webfonts (prefers installed TeX families) · Print-aware
   ========================================================================== */

/* -------------------------------- Root Scale ------------------------------- */
:root {
  --page-max: 70ch;
  --page-pad: 2.5rem;
  --base-font: 18px;
  --line: 1.6;
  --ratio: 1.25;

  --bg: #ffffff;
  --ink: #111111;
  --muted: #545454;
  --rule: #dadada;
  --link: #0b3d91;
  --link-visited: #5a2ca0;

  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --serif: "Latin Modern Roman", "LM Roman 10", "Computer Modern", "CMU Serif",
           "New Computer Modern", "Libertinus Serif", "STIX Two Text",
           "TeX Gyre Termes", "Noto Serif", "Georgia", "Times New Roman",
           Times, serif;

  /* UI */
  --ui-bg: #f2f6ff;
  --ui-ink: #0b3d91;
  --ui-border: #c8d7ff;
  --ui-hover: #e6efff;
}

/* ------------------------------- Base Reset -------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--base-font); text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--serif);
  line-height: var(--line);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  font-variant-numeric: lining-nums;
  widows: 3; orphans: 3;
  font-size-adjust: 0.5;
}

.container {
  max-width: var(--page-max);
  padding: 0 var(--page-pad) 6rem;
  margin: 0 auto;
}

/* ------------------------- Typesetting (sane defaults) ---------------------- */
p { margin: 0 0 1rem; text-align: justify; hyphens: auto; }
a, code, kbd, samp, pre, td, th { overflow-wrap: break-word; }
.indent-on p + p { text-indent: 1.25em; }
li, blockquote, figcaption, td, th { text-align: start; }

/* ------------------------------ Topbar (button) ---------------------------- */
.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem var(--page-pad);
  background: var(--ui-bg);
  border-bottom: 1px solid var(--ui-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.toggle-link {
  display: inline-block;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--ui-border);
  border-radius: 0.35rem;
  background: #fff;
  color: var(--ui-ink);
  font-weight: 600;
  text-decoration: none;
}
.toggle-link:hover { background: var(--ui-hover); }
.toggle-link:focus-visible { outline: 2px solid var(--ui-ink); outline-offset: 2px; }

/* ------------------------------ Front matter ------------------------------- */
.front-matter {
  max-width: var(--page-max);
  padding: 3rem var(--page-pad) 1.5rem;
  margin: 0 auto 1rem;
  border-bottom: 1px solid var(--rule);
}
.title {
  margin: 0 0 0.35rem 0;
  line-height: calc(var(--line) * 0.95);
  font-weight: 700;
  font-size: calc(1rem * var(--ratio) * var(--ratio) * var(--ratio));
  letter-spacing: 0.003em;
  text-wrap: balance;
  text-align: start;
}
.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-weight: 400;
  font-size: calc(1rem * var(--ratio));
  text-wrap: balance;
  text-align: start;
}
.authors, .affiliation, .date { margin: 0.3rem 0; color: var(--muted); text-align: start; }
.authors .author { white-space: normal; }
.affil-sep { opacity: 0.6; }

/* -------------------------------- Abstract --------------------------------- */
.abstract {
  max-width: var(--page-max);
  margin: 1.5rem auto 2rem;
  padding: 0.9rem var(--page-pad) 1.1rem;
  background: #fafafa;
  border-inline-start: 3px solid #e6e6e6;
}
.abstract > h2 { margin: 0 0 0.25rem 0; font-size: 1.05rem; font-weight: 700; text-align: start; }
.keywords .sc { font-variant-caps: small-caps; letter-spacing: 0.02em; }

/* ------------------------------- Headings ---------------------------------- */
h2, h3, h4 {
  margin: 1.75rem 0 0.6rem;
  line-height: 1.25; font-weight: 700; text-align: start; text-wrap: balance;
}
h2 { font-size: calc(1rem * var(--ratio) * var(--ratio)); }
h3 { font-size: calc(1rem * var(--ratio)); }
h4 { font-size: 1rem; font-style: italic; color: var(--muted); }

/* ------------------------------ Lists & Links ------------------------------ */
ul, ol { margin: 0 0 1rem 1.25rem; }
li { margin: 0.25rem 0; }
a { color: var(--link); text-decoration: underline; text-underline-offset: 0.14em; text-decoration-thickness: from-font; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
sup a { text-decoration: underline; }

/* -------------------------------- Code ------------------------------------- */
code, kbd, samp {
  font-family: var(--mono);
  font-size: 1em;
  background: #f6f6f6;
  padding: 0.05em 0.25em;
  border-radius: 2px;
  border: 1px solid #eee;
}

/* -------------------------------- Quotes ----------------------------------- */
blockquote { margin: 1rem 0 1rem; padding: 0.25rem 1rem; border-inline-start: 3px solid #e6e6e6; color: #2a2a2a; font-style: italic; }

/* ------------------------------ Figures/Tables ----------------------------- */
.figure, figure.equation { margin: 1.25rem 0 1rem; text-align: center; }
.figure img { max-width: 100%; height: auto; border: 1px solid #e9e9e9; background: #fff; }
.figure { counter-increment: figCounter; }
figure.equation { counter-increment: eqCounter; }
.figure figcaption, figure.equation figcaption, .table caption {
  margin: 0.5rem 0 0.25rem; font-size: 0.95rem; color: var(--muted); text-align: center;
}
.figure figcaption::before { content: "Figure " counter(figCounter) ". "; font-weight: 700; color: #333; }
figure.equation figcaption::before { content: "Equation " counter(eqCounter) ". "; font-weight: 700; color: #333; }

/* Tables (classed) */
.table {
  width: 100%; border-collapse: collapse; margin: 1rem 0 1rem;
  counter-increment: tblCounter; font-variant-numeric: tabular-nums lining-nums; text-align: start;
}
.table caption::before { content: "Table " counter(tblCounter) ". "; font-weight: 700; color: #333; }
.table thead th { background: #fbfbfb; color: #1b1b1b; }
.table th, .table td { padding: 0.55rem 0.6rem; border: 1px solid #e6e6e6; text-align: start; vertical-align: top; }

/* Native tables */
table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
th, td { padding: 0.5rem 0.6rem; border: 1px solid #e6e6e6; text-align: start; vertical-align: top; }

/* ------------------------------- References -------------------------------- */
.references { padding-left: 1.25rem; }
.references li { margin: 0.4rem 0; text-align: start; }
.sc { font-variant-caps: small-caps; letter-spacing: 0.02em; }

/* ---------------------------------- TOC ------------------------------------ */
.toc { max-width: var(--page-max); margin: 1rem auto 1.5rem; padding: 0 var(--page-pad); }
.toc h2 { margin-top: 0; }
.toc ol { margin-left: 1.25rem; text-align: start; }

/* -------------------------------- Footnotes -------------------------------- */
.footnotes {
  max-width: var(--page-max); margin: 2rem auto 4rem; padding: 0 var(--page-pad);
  border-top: 1px solid var(--rule);
}
.footnotes ol { margin-left: 1.25rem; }
.footnotes li { margin: 0.4rem 0; text-align: start; }

/* Placeholder utility */
.placeholder { margin: 0.75rem 0; padding: 0.75rem 0.9rem; border: 1px dashed var(--ui-border); background: #fafcff; color: #2a2a2a; font-style: italic; }

/* --------------------------------- Print ----------------------------------- */
@media print {
  :root { --base-font: 11.5pt; --page-pad: 0; --page-max: 42em; }
  a { color: inherit; text-decoration: underline; }
  .topbar { display: none; }
  .front-matter, .abstract, .toc, .container, .footnotes { padding-left: 0; padding-right: 0; max-width: none; }
  h2 { page-break-after: avoid; }
  figure, table, .table { page-break-inside: avoid; }
  p { orphans: 3; widows: 3; }
  @page { margin: 2.5cm 2.2cm; }
}

/* -------------------------- Reduced Motion & Wraps ------------------------- */
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }
@supports (text-wrap: pretty) { p, li, blockquote { text-wrap: pretty; } }
@supports (text-wrap: balance) { .title, .subtitle, h2, h3 { text-wrap: balance; } }

/* ------------------------------- Responsive -------------------------------- */
@media (max-width: 42rem) {
  p { text-align: start; hyphens: auto; }
  .container { padding-bottom: 4rem; }
}

/* ------------------------------- Media: Images ----------------------------- */
.figure img, .figure-img {
  display: block;
  max-width: var(--page-max);
  width: 100%;
  height: auto;
  margin: 1rem auto;
  border: 1px solid #e9e9e9;
  background: #fff;
}

/* ------------------------------- Media: Video ------------------------------ */
/* Fully responsive and centered with text column */
figure.video {
  max-width: var(--page-max);
  margin: 1.25rem auto 1rem;
  padding: 0 var(--page-pad);
  text-align: center;
}
figure.video > figcaption {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
}
.video video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border: 1px solid #e9e9e9;
  background: #000;
}

/* Cap height on very short viewports without overflowing */
@media (max-height: 540px) {
  .video video { max-height: 80vh; }
}
