/* ==========================================================================
   wissenschaft.css – Stylesheet für wissenschaftliche Texte
   Abbildungen, Tabellen, Formeln, Inhaltsverzeichnis, Stichwortverzeichnis,
   Literaturverzeichnis.

   Bildschirm: lesbare Einspaltenansicht.
   Druck/PDF: A4, Seitenzahlen, Seitenverweise, Punktlinien (Leader).
   Seitenverweise (target-counter, leader) und Fußnoten funktionieren in
   Paged.js, WeasyPrint, Prince und Antenna House – nicht in normalen Browsern.
   ========================================================================== */

/* ---------- 1. Design-Token ---------- */
:root {
  --schrift-text: "Source Serif 4", "Literata", "Charis SIL", Georgia, "Times New Roman", serif;
  --schrift-ueberschrift: "Source Sans 3", "Inter", "Helvetica Neue", Arial, sans-serif;
  --schrift-mono: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;

  --tinte: #1c1f24;
  --tinte-leise: #5a606b;
  --linie: #c9ccd2;
  --flaeche: #f3f4f6;
  --akzent: #1f4e8c;          /* Verweise, Nummern */
  --papier: #ffffff;

  --schriftgroesse: 11pt;
  --zeilenhoehe: 1.55;
  --textbreite: 38rem;        /* Bildschirm: < 80 Zeichen pro Zeile */
}

/* ---------- 2. Grundlagen ---------- */
html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  padding: 2.5rem 1.25rem 5rem;
  max-width: var(--textbreite);
  background: var(--papier);
  color: var(--tinte);
  font-family: var(--schrift-text);
  font-size: 1.0625rem;
  line-height: var(--zeilenhoehe);
  text-align: justify;
  hyphens: auto;                    /* html lang="de" setzen! */
  -webkit-hyphens: auto;
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-feature-settings: "kern", "liga", "onum";
  text-rendering: optimizeLegibility;
  orphans: 3;
  widows: 3;

  /* Zähler für das gesamte Dokument */
  counter-reset: kap 0 abb 0 tab 0 gl 0 lit 0 fn 0;
}

p { margin: 0 0 0.9em; }
p + p { text-indent: 1.4em; margin-top: -0.9em; }   /* Einzug statt Leerzeile */
p.ohne-einzug, h1 + p, h2 + p, h3 + p, figure + p,
blockquote + p, .tabelle + p, .gleichung + p { text-indent: 0; margin-top: 0; }

a { color: var(--akzent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.15em; }
a:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }

abbr[title] { text-decoration: none; }
sub, sup { line-height: 0; }
em, i, cite { font-style: italic; }
::selection { background: #cfe0f5; }

/* ---------- 3. Überschriften mit automatischer Gliederung ---------- */
h1, h2, h3, h4 {
  font-family: var(--schrift-ueberschrift);
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  hyphens: manual;
  break-after: avoid;
  page-break-after: avoid;
}

h1 {
  font-size: 1.75rem;
  margin: 3rem 0 1.25rem;
  counter-increment: kap;
  counter-reset: unterkap 0 unterunterkap 0;
}
h2 {
  font-size: 1.3rem;
  margin: 2.25rem 0 0.75rem;
  counter-increment: unterkap;
  counter-reset: unterunterkap 0;
}
h3 {
  font-size: 1.1rem;
  margin: 1.75rem 0 0.5rem;
  counter-increment: unterunterkap;
}
h4 {
  font-size: 1rem;
  font-style: italic;
  font-weight: 600;
  margin: 1.25rem 0 0.35rem;
}

h1::before { content: counter(kap) "\2003"; color: var(--akzent); }
h2::before { content: counter(kap) "." counter(unterkap) "\2003"; color: var(--akzent); }
h3::before { content: counter(kap) "." counter(unterkap) "." counter(unterunterkap) "\2003"; color: var(--akzent); }

/* Ohne Nummer: Titel, Zusammenfassung, Verzeichnisse, Anhang */
h1.ohne-nummer, h2.ohne-nummer, h3.ohne-nummer { counter-increment: none; }
h1.ohne-nummer::before, h2.ohne-nummer::before, h3.ohne-nummer::before { content: none; }

/* Dokumentkopf */
header.titel { margin-bottom: 3rem; text-align: left; }
header.titel h1 { font-size: 2.1rem; margin: 0 0 0.5rem; counter-increment: none; }
header.titel h1::before { content: none; }
header.titel .untertitel { font-size: 1.15rem; color: var(--tinte-leise); margin: 0 0 1.25rem; text-indent: 0; }
header.titel .autoren, header.titel .meta { font-family: var(--schrift-ueberschrift); font-size: 0.95rem; margin: 0; text-indent: 0; }
header.titel .meta { color: var(--tinte-leise); }

/* Zusammenfassung */
.abstract {
  margin: 0 0 2.5rem;
  padding: 1rem 1.25rem;
  background: var(--flaeche);
  border-left: 3px solid var(--akzent);
  font-size: 0.95em;
}
.abstract > :first-child { margin-top: 0; }
.abstract > :last-child { margin-bottom: 0; }
.abstract .schluesselwoerter { font-style: italic; text-indent: 0; margin-top: 0.75em; }

/* ---------- 4. Abbildungen ---------- */
figure {
  margin: 1.75rem 0;
  padding: 0;
  text-align: center;
  break-inside: avoid;
  page-break-inside: avoid;
  counter-increment: abb;
}
figure img, figure svg, figure canvas, figure video {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}
figure.breit { margin-left: -4rem; margin-right: -4rem; }   /* ragt in den Rand */
figure.klein img, figure.klein svg { max-width: 60%; }

figcaption {
  margin: 0.75rem auto 0;
  max-width: 34rem;
  font-family: var(--schrift-ueberschrift);
  font-size: 0.875rem;
  line-height: 1.45;
  text-align: left;
  hyphens: manual;
  color: var(--tinte);
}
figcaption::before {
  content: "Abbildung " counter(abb) ": ";
  font-weight: 600;
  color: var(--akzent);
}
figcaption .quelle {
  display: block;
  margin-top: 0.25rem;
  color: var(--tinte-leise);
  font-size: 0.8125rem;
}

/* Teilabbildungen (a), (b), … */
figure.mehrteilig .teile {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
  counter-reset: teil;
}
figure.mehrteilig .teil { counter-increment: teil; }
figure.mehrteilig .teil::after {
  content: "(" counter(teil, lower-alpha) ")";
  display: block;
  margin-top: 0.25rem;
  font-family: var(--schrift-ueberschrift);
  font-size: 0.8125rem;
  color: var(--tinte-leise);
}

/* ---------- 5. Tabellen ---------- */
.tabelle {
  margin: 1.75rem 0;
  counter-increment: tab;
  break-inside: avoid;
  page-break-inside: avoid;
  overflow-x: auto;
}
.tabelle > caption, .tabelle > .beschriftung {
  display: block;
  margin-bottom: 0.5rem;
  font-family: var(--schrift-ueberschrift);
  font-size: 0.875rem;
  text-align: left;
}
.tabelle > caption::before, .tabelle > .beschriftung::before {
  content: "Tabelle " counter(tab) ": ";
  font-weight: 600;
  color: var(--akzent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--schrift-ueberschrift);
  font-size: 0.875rem;
  font-variant-numeric: lining-nums tabular-nums;
  text-align: left;
  hyphens: manual;
}
table caption { caption-side: top; }
thead th {
  padding: 0.4rem 0.75rem;
  border-top: 1.5px solid var(--tinte);
  border-bottom: 0.75px solid var(--tinte);
  font-weight: 600;
}
tbody td, tbody th {
  padding: 0.35rem 0.75rem;
  border-bottom: 0.5px solid var(--linie);
  font-weight: 400;
}
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 1.5px solid var(--tinte); }
td.zahl, th.zahl { text-align: right; }
tfoot td { padding-top: 0.4rem; font-size: 0.8125rem; color: var(--tinte-leise); border: 0; }
.tabellen-notiz { font-family: var(--schrift-ueberschrift); font-size: 0.8125rem; color: var(--tinte-leise); text-indent: 0; margin-top: 0.4rem; }

/* ---------- 6. Formeln ---------- */
.gleichung {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin: 1.25rem 0;
  counter-increment: gl;
  break-inside: avoid;
}
.gleichung > :first-child { text-align: center; overflow-x: auto; }
.gleichung::after {
  content: "(" counter(gl) ")";
  padding-left: 1rem;
  font-variant-numeric: lining-nums;
}
math { font-size: 1.05em; }

/* ---------- 7. Zitate, Code, Hinweise ---------- */
blockquote {
  margin: 1.25rem 0;
  padding: 0 0 0 1.25rem;
  border-left: 2px solid var(--linie);
  font-size: 0.95em;
  color: var(--tinte);
}
blockquote > p { text-indent: 0; margin-bottom: 0.5em; }
blockquote footer, blockquote cite { font-size: 0.875em; color: var(--tinte-leise); font-style: normal; }
q { quotes: "„" "“" "‚" "‘"; }

pre, code, kbd, samp { font-family: var(--schrift-mono); font-size: 0.85em; hyphens: none; }
pre {
  margin: 1.25rem 0;
  padding: 0.85rem 1rem;
  background: var(--flaeche);
  border-radius: 3px;
  overflow-x: auto;
  text-align: left;
  line-height: 1.45;
  break-inside: avoid;
}
:not(pre) > code { padding: 0.08em 0.3em; background: var(--flaeche); border-radius: 2px; }

ul, ol { margin: 0 0 0.9em; padding-left: 1.6em; }
li { margin-bottom: 0.25em; }
dl dt { font-weight: 600; }
dl dd { margin: 0 0 0.6em 1.5em; }

hr { border: 0; border-top: 0.5px solid var(--linie); margin: 2.5rem 0; }

/* ---------- 8. Querverweise im Text ---------- */
/* Leere Anker werden von Druck-Engines automatisch gefüllt:
   <a class="verweis-abb" href="#abb-druck"></a>  →  „Abbildung 3“            */
a.verweis-abb:empty::after { content: "Abbildung " target-counter(attr(href), abb); }
a.verweis-tab:empty::after { content: "Tabelle " target-counter(attr(href), tab); }
a.verweis-gl:empty::after  { content: "(" target-counter(attr(href), gl) ")"; }
a.verweis-kap:empty::after { content: "Kapitel " target-counter(attr(href), kap); }
a.verweis-seite:empty::after { content: "Seite " target-counter(attr(href), page); }

/* Literaturzitate im Text: <a class="zitat" href="#lit-meier2019"></a> → [3] */
a.zitat:empty::after { content: "[" target-counter(attr(href), lit) "]"; }
a.zitat { white-space: nowrap; }

/* ---------- 9. Fußnoten (Druck-Engines) ---------- */
.fussnote {
  float: footnote;
  counter-increment: fn;
  font-size: 0.8125rem;
  line-height: 1.4;
  text-align: left;
}
.fussnote::footnote-call { content: counter(footnote); font-size: 0.7em; vertical-align: super; line-height: 0; }
.fussnote::footnote-marker { content: counter(footnote) "  "; font-weight: 600; }

/* ---------- 10. Inhaltsverzeichnis ---------- */
nav.inhalt, nav.abbildungsverzeichnis, nav.tabellenverzeichnis { margin: 0 0 3rem; text-align: left; }
nav.inhalt ol, nav.abbildungsverzeichnis ol, nav.tabellenverzeichnis ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
nav.inhalt li { margin: 0; }
nav.inhalt a, nav.abbildungsverzeichnis a, nav.tabellenverzeichnis a {
  display: block;
  padding: 0.2rem 0;
  color: var(--tinte);
}
nav.inhalt a:hover { color: var(--akzent); text-decoration: none; }

nav.inhalt > ol { counter-reset: v1; }
nav.inhalt > ol > li { counter-increment: v1; counter-reset: v2; margin-top: 0.5rem; font-weight: 600; }
nav.inhalt > ol > li > a::before { content: counter(v1) "\2003"; }
nav.inhalt > ol > li > ol > li { counter-increment: v2; margin: 0; font-weight: 400; padding-left: 1.6rem; }
nav.inhalt > ol > li > ol > li > a::before { content: counter(v1) "." counter(v2) "\2003"; }

/* Seitenzahl mit Punktlinie */
nav.inhalt a::after,
nav.abbildungsverzeichnis a::after,
nav.tabellenverzeichnis a::after {
  content: leader(".") target-counter(attr(href), page);
  float: none;
}

nav.abbildungsverzeichnis ol { counter-reset: v-abb; }
nav.abbildungsverzeichnis li { counter-increment: v-abb; }
nav.abbildungsverzeichnis a::before { content: "Abbildung " counter(v-abb) ":\00a0"; font-weight: 600; }
nav.tabellenverzeichnis ol { counter-reset: v-tab; }
nav.tabellenverzeichnis li { counter-increment: v-tab; }
nav.tabellenverzeichnis a::before { content: "Tabelle " counter(v-tab) ":\00a0"; font-weight: 600; }

/* ---------- 11. Stichwortverzeichnis (Index) ---------- */
section.stichwortverzeichnis { text-align: left; hyphens: manual; }
.stichwortverzeichnis .register {
  column-count: 2;
  column-gap: 2rem;
  font-size: 0.9rem;
  line-height: 1.4;
}
.stichwortverzeichnis .buchstabe {
  break-after: avoid;
  margin: 1rem 0 0.25rem;
  padding-bottom: 0.15rem;
  border-bottom: 0.5px solid var(--linie);
  font-family: var(--schrift-ueberschrift);
  font-weight: 600;
  color: var(--akzent);
}
.stichwortverzeichnis ul { list-style: none; margin: 0; padding: 0; }
.stichwortverzeichnis li {
  margin: 0;
  padding-left: 1.25rem;
  text-indent: -1.25rem;               /* hängender Einzug */
  break-inside: avoid;
}
.stichwortverzeichnis li ul { margin-top: 0.1rem; padding-left: 1rem; }  /* Unterbegriffe */
.stichwortverzeichnis li ul li { font-size: 0.95em; }
.stichwortverzeichnis .siehe { font-style: italic; color: var(--tinte-leise); }

/* Seitenzahlen: <a href="#idx-entropie-1"></a><a href="#idx-entropie-2"></a> → „12, 18“ */
.stichwortverzeichnis a:empty::after { content: target-counter(attr(href), page); }
.stichwortverzeichnis a:empty + a:empty::before { content: ", "; }
.stichwortverzeichnis a:empty:first-of-type::before { content: "\2002"; }

/* Marker im Text: unsichtbarer Anker an der Fundstelle */
a.idx { display: inline; width: 0; height: 0; overflow: hidden; color: inherit; }

/* ---------- 12. Literaturverzeichnis ---------- */
section.literatur { text-align: left; hyphens: manual; }
.literatur ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.literatur li {
  position: relative;
  margin: 0 0 0.6em;
  padding-left: 2.6rem;                /* Platz für [n] */
  line-height: 1.45;
  font-size: 0.95em;
  counter-increment: lit;
  break-inside: avoid;
  overflow-wrap: anywhere;
}
.literatur li::before {
  content: "[" counter(lit) "]";
  position: absolute;
  left: 0;
  color: var(--akzent);
  font-variant-numeric: lining-nums tabular-nums;
}

/* Variante Autor-Jahr (alphabetisch, hängender Einzug, ohne Nummern) */
.literatur.autor-jahr li {
  padding-left: 1.5rem;
  text-indent: -1.5rem;
  counter-increment: none;
}
.literatur.autor-jahr li::before { content: none; }

/* Auszeichnung der Bestandteile (optional, mit <span class="…">) */
.literatur .autor  { font-variant-caps: small-caps; font-feature-settings: "smcp"; }
.literatur .titel  { font-style: italic; }
.literatur .doi, .literatur .url { font-family: var(--schrift-mono); font-size: 0.82em; color: var(--akzent); }
.literatur a { word-break: break-all; }

/* ---------- 13. Anhang ---------- */
section.anhang { counter-reset: anh; }
section.anhang h2 { counter-increment: anh; counter-reset: none; }
section.anhang h2::before { content: "Anhang " counter(anh, upper-alpha) "\2003"; }

/* ---------- 14. Bildschirm: kleine Geräte ---------- */
@media screen and (max-width: 40rem) {
  body { text-align: left; padding-top: 1.5rem; }
  figure.breit { margin-left: 0; margin-right: 0; }
  .stichwortverzeichnis .register { column-count: 1; }
  .gleichung { grid-template-columns: 1fr; }
  .gleichung::after { text-align: right; padding: 0; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* ---------- 15. Druck / PDF ---------- */
@page {
  size: A4;
  margin: 25mm 22mm 28mm 28mm;      /* innen etwas mehr für die Bindung */

  @top-center {
    content: string(kapitel);
    font: 8.5pt var(--schrift-ueberschrift);
    color: var(--tinte-leise);
  }
  @bottom-center {
    content: counter(page);
    font: 9.5pt var(--schrift-ueberschrift);
  }
}
@page :first {
  @top-center { content: none; }
  @bottom-center { content: none; }
}
@page :right { margin-left: 28mm; margin-right: 22mm; }
@page :left  { margin-left: 22mm; margin-right: 28mm; }

h1 { string-set: kapitel content(text); }

@media print {
  :root { --textbreite: none; }

  html { font-size: var(--schriftgroesse); }
  body {
    max-width: none;
    padding: 0;
    font-size: 1rem;
    line-height: 1.5;
    background: none;
  }

  h1 { break-before: page; margin-top: 0; }
  header.titel h1, h1.ohne-umbruch { break-before: auto; }

  a { color: inherit; }
  a[href^="http"]:not(.url):not(.doi)::after { content: none; }

  figure.breit { margin-left: 0; margin-right: 0; }
  .abstract { background: none; border: 0.5pt solid var(--linie); border-left: 2pt solid var(--tinte); }
  pre { background: none; border: 0.5pt solid var(--linie); white-space: pre-wrap; }
  :not(pre) > code { background: none; }

  /* Verzeichnisse beginnen auf neuer Seite */
  nav.inhalt, nav.abbildungsverzeichnis, nav.tabellenverzeichnis,
  section.stichwortverzeichnis, section.literatur, section.anhang { break-before: page; }

  figure, .tabelle, .gleichung, blockquote, pre { break-inside: avoid; }
  table { font-size: 8.5pt; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
}
