/* ==========================================================================
   kepler-prim — Johannes Kepler: Gesammelte Werke (KGW 1-22)
   ai-viewer schema-aware typography and layout stylesheet
   ========================================================================== */

:root {
  --kepler-ink: var(--ink);
  --kepler-oxford: var(--oxford);
  --kepler-gold: var(--gold);
  --kepler-hairline: var(--rule);
  --kepler-muted: var(--ink-faint);
  --kepler-bg-table: var(--paper-sunken);
  --kepler-font-serif: "Georgia", "Times New Roman", "Baskerville", serif;
  --kepler-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --kepler-font-mono: "SF Mono", "Menlo", "Courier New", monospace;
}

/* ── Container Reset & Typography ────────────────────────────────────────── */

.pdai-page-container,
.pdai-page-structured {
  font-family: var(--kepler-font-serif);
  color: var(--kepler-ink);
  line-height: 1.65;
  font-size: 0.98rem;
  max-width: 74ch;
  margin: 0 auto;
  padding: 2.2rem 4.5rem;
  background: var(--paper-sheet);
  position: relative;
}

.pdai-page-structured *,
.pdai-page-structured *::before,
.pdai-page-structured *::after {
  box-sizing: border-box;
}

/* ── Running Header ──────────────────────────────────────────────────────── */

.pdai-page-structured [data-el="header"],
.pdai-page-structured .page-header,
header, .pdai-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--kepler-font-serif);
  font-size: 0.85rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  padding-bottom: 0.4rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--kepler-oxford);
  font-weight: 500;
}

.pdai-page-structured .page-header-folio,
.pdai-page-structured .page-header-title {
  font-style: normal;
  font-weight: 500;
}

/* ── Paragraphs & Running Text ───────────────────────────────────────────── */

p,
.pdai-page-structured [data-el="p"],
.pdai-page-structured p {
  position: relative;
  margin: 0 0 1em 0;
  text-align: justify;
  text-justify: inter-word;
  line-height: 1.65;
}

/* ── Margins ─────────────────────────────────────────────────────────────
   Geometry, markers and notes come from pdai-page.css (the PDAI page
   language). KGW sets its measures: the author's glosses (Astronomia Nova,
   Mysterium) take about a quarter of the text measure beside the text. */
.page-sheet,
.pdai-page-structured {
  --pdai-note-width: 9.6rem;
  --pdai-note-gap: 1.2rem;
  --pdai-marker-gutter: 2.8rem;
}

.page-sheet span[data-el="marginal"][data-kind="note"] {
  font-family: var(--kepler-font-serif) !important;
}

/* ── Figures & Extracted Diagrams ────────────────────────────────────────── */

figure,
.pdai-page-structured [data-el="figure"],
figure.extracted-figure {
  margin: 1.4rem auto;
  text-align: center;
  max-width: 260px;
}

.fig-container,
.pdai-page-structured .fig-container {
  background: transparent;
  padding: 0;
  margin: 0 auto;
}

figure img,
.pdai-page-structured [data-el="figure"] img,
.extracted-figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--kepler-hairline);
  border-radius: 4px;
  background: var(--paper-sheet);
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.fig-desc,
.pdai-page-structured .fig-desc {
  display: none; /* Accessible description hidden from printed layout */
}

caption, figcaption,
.pdai-page-structured [data-el="caption"] {
  display: block;
  font-style: italic;
  font-size: 0.82rem;
  color: var(--kepler-muted);
  margin-top: 6px;
}

/* ── Correspondence Closings (KGW 13-18) ─────────────────────────────────── */

.pdai-page-structured [data-el="letter-closing"],
letter-closing {
  display: block;
  margin-top: 1.6rem;
  margin-bottom: 1.8rem;
}

/* letter-part / register layout: pdai-epistolary.css (page_letter.dtd v4.2). */

.pdai-page-structured [data-el="greeting"],
.pdai-page-structured [data-el="valediction"],
.pdai-page-structured [data-el="place-date"],
greeting {
  display: block;
  text-align: right;
  font-style: italic;
  color: var(--ink-muted);
  margin-bottom: 0.3rem;
  padding-right: 1.5rem;
}

.pdai-page-structured [data-el="signature"],
signature {
  display: block;
  text-align: right;
  font-weight: 600;
  color: var(--kepler-oxford);
  padding-right: 0.5rem;
  margin-bottom: 1.2rem;
}

.pdai-page-structured [data-el="address"],
address {
  display: block;
  margin-top: 1.2rem;
  margin-bottom: 1.2rem;
  padding: 0 0 0 1.5em;
  font-style: normal;
  font-size: 0.95rem;
  line-height: 1.6;
  position: relative;
}

/* ── Letter Heads (KGW 13-18) ────────────────────────────────────────────── */

.pdai-page-structured [data-el="letter-head"],
letter-head {
  display: block;
  margin: 2.4rem 0 1.2rem;
  padding: 0 0 0.8rem 0;
  border-bottom: 1px solid var(--kepler-hairline);
  position: relative;
}

.pdai-page-structured [data-el="reference"],
reference {
  display: block;
  font-family: var(--kepler-font-sans);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--kepler-oxford);
  letter-spacing: 0.02em;
  margin-bottom: 0.35rem;
  line-height: 1.4;
}

.pdai-page-structured [data-el="date"],
date {
  display: block;
  font-family: var(--kepler-font-serif);
  font-size: 0.92rem;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
  font-style: normal;
}

.pdai-page-structured [data-el="archive"],
archive {
  display: block;
  font-family: var(--kepler-font-serif);
  font-size: 0.82rem;
  color: var(--ink-faint);
  line-height: 1.45;
  margin-bottom: 0.4rem;
  font-style: normal;
}

.pdai-page-structured [data-el="salutation"],
salutation {
  display: block;
  font-family: var(--kepler-font-serif);
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--ink);
  margin-top: 0.8rem;
  margin-bottom: 0.8rem;
  position: relative;
}

/* Illegal / leftover inline tags must stay in the text flow.
   <expan> is not in page.dtd; qwen used it for line-end hyphenation. */
.pdai-page-structured [data-el="p"] [data-el="expan"],
.pdai-page-structured [data-el="expan"],
expan {
  display: inline;
}

/* ── Typography & Inline Formatting ──────────────────────────────────────── */

.pdai-page-structured [data-el="hi"][data-rend="italic"],
hi[rend="italic"] {
  font-style: italic;
}

.pdai-page-structured [data-el="hi"][data-rend="bold"],
hi[rend="bold"] {
  font-weight: bold;
}

.pdai-page-structured [data-el="hi"][data-rend="spaced"],
hi[rend="spaced"] {
  letter-spacing: 0.15em;
  font-style: normal;
}

.pdai-page-structured [data-el="hi"][data-rend="superscript"],
hi[rend="superscript"] {
  vertical-align: super;
  font-size: 0.75em;
  line-height: 0;
}

.pdai-page-structured [data-el="hi"][data-rend="subscript"],
hi[rend="subscript"] {
  vertical-align: sub;
  font-size: 0.75em;
  line-height: 0;
}

.pdai-page-structured [data-el="hi"][data-rend="smallcaps"],
hi[rend="smallcaps"] {
  font-variant: small-caps;
}

parno, [data-el="parno"] {
  font-family: var(--kepler-font-sans);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--kepler-oxford);
  margin-right: 6px;
}

fn, [data-el="fn"] {
  font-family: var(--kepler-font-sans);
  font-size: 0.75em;
  vertical-align: super;
  color: var(--kepler-oxford);
  font-weight: 600;
  margin-right: 2px;
}

/* ── Tables & Astronomical/Mathematical Grids ────────────────────────────── */

table, .pdai-page-structured table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.86rem;
  line-height: 1.45;
  background-color: var(--kepler-bg-table);
  border-top: 1.5px solid var(--kepler-oxford);
  border-bottom: 1.5px solid var(--kepler-oxford);
}

th, td, .pdai-page-structured th, .pdai-page-structured td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--kepler-hairline);
  font-variant-numeric: tabular-nums lining-nums;
}

th, .pdai-page-structured th {
  font-family: var(--kepler-font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--kepler-oxford);
  border-bottom: 1.5px solid var(--kepler-oxford);
  background: var(--paper-sunken);
}

td, .pdai-page-structured td {
  text-align: right;
  font-family: var(--kepler-font-mono);
}

td:first-child, th:first-child {
  text-align: center;
}

td[align="left"], th[align="left"] {
  text-align: left;
}

td[align="center"], th[align="center"] {
  text-align: center;
}

td[align="right"], th[align="right"] {
  text-align: right;
}

/* ── Mathematical Equations ──────────────────────────────────────────────── */

equation, .equation, .pdai-page-structured [data-el="equation"] {
  display: block;
  text-align: center;
  margin: 1.2em 0;
  font-family: var(--kepler-font-serif);
  font-size: 1.05em;
}

/* ── Footnotes Apparatus ─────────────────────────────────────────────────── */

footnotes, .pdai-page-structured [data-el="footnotes"] {
  display: block;
  margin-top: 28px;
  padding-top: 12px;
  border-top: 1px solid var(--kepler-oxford);
  font-size: 0.82rem;
  color: var(--ink-muted);
}

footnote, .pdai-page-structured [data-el="footnote"] {
  display: block;
  margin-bottom: 6px;
  line-height: 1.45;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

footer, .pdai-page-structured [data-el="footer"] {
  font-family: var(--kepler-font-sans);
  font-size: 0.75rem;
  color: var(--kepler-muted);
  text-align: center;
  margin-top: 24px;
  padding-top: 8px;
}

/* ── KGW 19 archival document-entry (volume DTD extension) ───────────────── */
/* Pure typography. No cards, no borders as frames, no uppercase. */

.pdai-page-structured [data-el="document-entry"] {
  display: block;
  margin: 1.4em 0 1.6em 0;
}

.pdai-page-structured [data-el="doc-crossref"] {
  display: block;
  font-size: 0.88rem;
  color: var(--ink-muted);
  margin: 0 0 0.35em 0;
}

.pdai-page-structured [data-el="doc-headnote"] {
  display: block;
  font-style: italic;
  margin: 0 0 0.45em 0;
}

.pdai-page-structured [data-el="doc-archive"] {
  display: block;
  font-size: 0.86rem;
  color: var(--ink-muted);
  margin: 0 0 0.7em 0;
}

.pdai-page-structured [data-el="doc-body"] {
  display: block;
  margin: 0;
}

.pdai-page-structured [data-el="marginal"][data-attrname="type"][data-type="doc-id"],
.pdai-page-structured [data-el="marginal"][data-type="doc-id"] {
  font-variant-numeric: tabular-nums;
}

/* Letter head as printed: typography only, no card (overrides the shared
   pdai-page.css card for [data-el="letter-head"]). */
.pdai-page-structured [data-el="letter-head"] {
    background: none !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    font-family: var(--serif) !important;
    text-align: left;
}
.pdai-page-structured [data-el="letter-head"] [data-el="witness"],
.pdai-page-structured [data-el="letter-head"] [data-el="regest"] {
    text-align: left;
    background: none;
    border: none;
    padding-left: 0;
}

/* Addresses as printed: typography only, no frame. */
.pdai-page-structured [data-el="address"] {
    border: none !important;
    background: none !important;
    padding-left: 0 !important;
}
