@namespace epub "http://www.idpf.org/2007/ops";

/*
 * ProseDown Default Stylesheet
 * Version: 0.7 draft
 *
 * Philosophy: classless for core prose, purposeful classes for
 * structural book elements. Yielding typography — don't fight
 * reading systems. Let the device and reader preferences win.
 *
 * Architecture:
 *   1. Custom properties (easy theming)
 *   2. Core prose (classless — element selectors only)
 *   3. Book structure (purposeful classes for TOC, frontmatter, etc.)
 *   4. Reading-system safety (what NOT to do)
 *
 * Inspired by: Sakura, Simple.css, Standard Ebooks core.css
 */


/* ============================================================
   1. CUSTOM PROPERTIES
   ============================================================
   Authors who export and customize this file can retheme
   their entire book by changing these variables.
   ------------------------------------------------------------ */

:root {
  /* Typography */
  --font-body: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --font-heading: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --font-size-base: 1rem;
  --line-height: 1.55;
  --measure: 38em;

  /* Spacing (vertical rhythm) */
  --space-xs: 0.5em;
  --space-sm: 1em;
  --space-md: 1.5em;
  --space-lg: 2.5em;
  --space-xl: 4em;

  /* Paragraph indent */
  --indent: 1.25em;
}


/* ============================================================
   2. CORE PROSE — Classless, element selectors only
   ============================================================
   This layer makes vanilla Markdown HTML look like a book.
   No classes needed. If your content is just headings,
   paragraphs, lists, blockquotes, images, and tables,
   this handles it.
   ------------------------------------------------------------ */

/* --- Base --- */

body {
  font-family: serif;
  font-family: var(--font-body);
  font-size: 1em;
  font-size: var(--font-size-base);
  line-height: 1.55;
  line-height: var(--line-height);
  max-inline-size: var(--measure);
  margin-inline: auto;
  padding-inline: var(--space-sm);
  -webkit-hyphens: auto;
  hyphens: auto;
  orphans: 2;
  widows: 2;
}


/* --- Headings --- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  line-height: 1.2;
  margin-block-start: var(--space-lg);
  margin-block-end: var(--space-sm);
  -webkit-hyphens: none;
  -epub-hyphens: none;
  hyphens: none;
}

h1 {
  font-size: 1.9em;
  text-align: start;
  margin-block-start: var(--space-lg);
  margin-block-end: var(--space-lg);
}

h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1.1em; }
h5 { font-size: 1em; font-style: italic; }
h6 { font-size: 1em; font-weight: normal; font-style: italic; }


/* --- Paragraphs — Book-style indentation --- */

p {
  margin-block: 0;
  text-indent: 0;
}

/* Continuous prose: indent paragraphs that follow another paragraph */
p + p {
  text-indent: var(--indent);
}

/* No indent after headings, breaks, figures, lists, blockquotes, tables */
h1 + p, h2 + p, h3 + p, h4 + p, h5 + p, h6 + p,
hr + p,
figure + p,
blockquote + p,
ol + p, ul + p,
dl + p,
table + p,
pre + p {
  text-indent: 0;
}


/* --- Blockquotes --- */

blockquote {
  margin-block: var(--space-md);
  margin-inline: var(--space-md);
  padding-inline-start: var(--space-sm);
  border-inline-start: 1px solid currentColor;
  font-style: normal;
}

blockquote p + p {
  text-indent: var(--indent);
}

blockquote footer,
blockquote cite {
  display: block;
  font-style: normal;
  margin-block-start: var(--space-xs);
  text-align: end;
  font-size: 0.9em;
}


/* --- Lists --- */

ol, ul {
  margin-block: var(--space-sm);
  padding-inline-start: var(--space-md);
}

li {
  margin-block-end: var(--space-xs);
}

li > p {
  text-indent: 0;
}


/* --- Definition Lists (glossaries) --- */

dl {
  margin-block: var(--space-md);
}

dt {
  font-weight: bold;
  margin-block-start: var(--space-sm);
}

dd {
  margin-inline-start: var(--space-md);
  margin-block-end: var(--space-xs);
}


/* --- Figures & Captions --- */

figure {
  margin-block: var(--space-md);
  margin-inline: 0;
  text-align: center;
}

figure img {
  max-inline-size: 100%;
  block-size: auto;
}

figcaption {
  font-size: 0.9em;
  font-style: italic;
  margin-block-start: var(--space-xs);

}


/* --- Images (outside figures) --- */

img {
  max-inline-size: 100%;
  block-size: auto;
}


/* --- Tables --- */

table {
  border-collapse: collapse;
  inline-size: 100%;
  margin-block: var(--space-md);
  font-size: 0.9em;
}

th, td {
  padding: var(--space-xs) var(--space-sm);
  text-align: start;
  border-block-end: 1px solid currentColor;

}

th {
  font-weight: bold;
  opacity: 1;
  border-block-end-width: 2px;
}

td {
  opacity: 1;
}

/* Subtle row striping */
tbody tr:nth-child(even) {
  opacity: 0.95;
}


/* --- Horizontal Rules (Scene Breaks) --- */

hr {
  border: none;
  text-align: center;
  margin-block: var(--space-lg);
}

hr::after {
  content: "* * *";
  letter-spacing: 0.5em;
  font-size: 0.85em;
  opacity: 0.5;
}


/* --- Code --- */

/* Neutral shading works with reader-selected light, dark, and sepia colors.
   Monospace and the border still distinguish code on monochrome screens. */
code {
  font-family: monospace;
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-style: normal;
  color: inherit;
  background-color: rgba(127, 127, 127, 0.12);
  border: 1px solid rgba(127, 127, 127, 0.3);
  border-radius: 0.2em;
  padding: 0.05em 0.25em;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

pre {
  box-sizing: border-box;
  max-inline-size: 100%;
  margin-block: var(--space-md);
  padding: var(--space-sm);
  color: inherit;
  background-color: rgba(127, 127, 127, 0.06);
  border: 1px solid rgba(127, 127, 127, 0.3);
  border-inline-start: 2px solid currentColor;
  border-radius: 0.2em;
  font-size: 0.9em;
  line-height: 1.5;
  text-align: start;
  text-indent: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  overflow-x: auto;
  tab-size: 4;
}

/* A code block is one surface, never a stack of inline-code boxes. */
pre code {
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  white-space: inherit;
  overflow-wrap: inherit;
  -webkit-box-decoration-break: slice;
  box-decoration-break: slice;
}


/* --- Links --- */

a {
  color: inherit;
  text-decoration: underline;
}


/* --- Superscript (footnote refs, verse numbers) --- */

sup {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: -0.4em;
}

/* Footnote backlinks */
sup a {
  text-decoration: none;
}


/* --- Footnotes (end of chapter) --- */

aside[epub|type~="footnote"],
aside[role~="doc-footnote"] {
  font-size: 0.85em;
  margin-block-start: var(--space-lg);
  padding-block-start: var(--space-sm);
  border-block-start: 1px solid currentColor;

}

/* Highlight targeted footnotes without boxing linked chapter headings. */
aside[role="doc-footnote"]:target {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}


/* ============================================================
   3. BOOK STRUCTURE — Purposeful classes for non-prose
   ============================================================
   These classes are emitted by the compiler for structural
   elements that need specific treatment. Core prose content
   never needs these.
   ------------------------------------------------------------ */

/* --- Title Page --- */

.title-page {
  text-align: center;
  margin-block-start: 20%;
}

.title-page h1 {
  font-size: 2.5em;
  margin-block-end: var(--space-xs);
}

.title-page .subtitle {
  font-size: 1.3em;
  font-style: italic;
  font-weight: normal;
}

.title-page .author {
  font-size: 1.1em;
  margin-block-start: var(--space-lg);
  font-family: var(--font-heading);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}


/* --- Copyright / Imprint --- */

.copyright {
  font-size: 0.85em;
  margin-block-start: 30%;
  line-height: 1.8;
}

.copyright p {
  text-indent: 0;
}

.copyright p + p {
  text-indent: 0;
  margin-block-start: var(--space-sm);
}


/* --- Dedication --- */

.dedication {
  text-align: center;
  font-style: italic;
  margin-block-start: 25%;
}

.dedication p {
  text-indent: 0;
}


/* --- Part Divider --- */

.part-title {
  text-align: center;
  margin-block-start: 30%;
}

.part-title h1 {
  font-size: 2em;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}


/* --- Table of Contents --- */

nav[epub|type~="toc"],
nav[role~="doc-toc"] {
  margin-block: var(--space-lg);
}

nav[epub|type~="toc"] ol,
nav[role~="doc-toc"] ol {
  list-style: none;
  padding-inline-start: 0;
}

nav[epub|type~="toc"] li,
nav[role~="doc-toc"] li {
  margin-block-end: var(--space-xs);
}

nav[epub|type~="toc"] a,
nav[role~="doc-toc"] a {
  text-decoration: none;
}

/* Nested (part > chapter) */
nav[epub|type~="toc"] ol ol,
nav[role~="doc-toc"] ol ol {
  padding-inline-start: var(--space-md);
  margin-block-start: var(--space-xs);
}


/* ============================================================
   4. READING-SYSTEM SAFETY
   ============================================================
   What NOT to do. Respect the device. Respect the reader.
   ------------------------------------------------------------ */

/*
 * DO NOT force body background color — breaks dark mode
 * DO NOT force body text color globally — disappears on inverted themes
 * DO NOT set fixed font-family on body text if shipping as EPUB
 *   (the vars above are for browser preview; EPUB compilers
 *    SHOULD strip or soften font-family for device compatibility)
 * DO NOT use !important — reader preferences must win
 * DO NOT use px for font sizes — use em/rem
 * DO NOT use physical properties (margin-left) — use logical (margin-inline-start)
 *   (Already done throughout this file)
 */


/* --- Dark Mode (for browser preview / modern readers) --- */

/* Reading systems own foreground, background, and image appearance. */

/* --- Extended Markdown and semantic inline HTML --- */
strong, b { font-weight: bold; }
em, i { font-style: italic; }
del, s { text-decoration: line-through; }
sub { font-size: 0.75em; line-height: 0; vertical-align: sub; }
kbd, samp { font-family: var(--font-mono); font-size: 0.875em; }
kbd { border: 1px solid currentColor; border-radius: 0.2em; padding: 0.1em 0.3em; }
abbr[title] { text-decoration: underline dotted; }
mark { background: transparent; color: inherit; font-weight: bold; text-decoration: underline; }
small { font-size: 0.875em; }

/* Keep nested blocks compact, while retaining list hierarchy. */
li > ul, li > ol { margin-block: var(--space-xs); }
li p + p, dd p + p { text-indent: 0; margin-block-start: var(--space-xs); }
li pre, dd pre { margin-inline: 0; }
pre, code, kbd, samp { hyphens: none; -webkit-hyphens: none; }
caption { text-align: start; font-weight: bold; margin-block-end: var(--space-xs); }
thead { display: table-header-group; }
th, td { vertical-align: top; overflow-wrap: anywhere; }

/* Useful in paginated readers as well as print. */
h1, h2, h3, h4, h5, h6 { break-after: avoid; page-break-after: avoid; }
figure, tr { break-inside: avoid; page-break-inside: avoid; }
figcaption { break-before: avoid; }
a:focus-visible { outline: 2px solid currentColor; outline-offset: 0.15em; }

/* Match the semantic sections actually emitted by the compiler. */
section[epub|type~="titlepage"] { text-align: center; margin-block-start: 15%; }
section[epub|type~="dedication"] { text-align: center; font-style: italic; }
section[epub|type~="imprint"] { font-size: 0.875em; }
section[epub|type~="part"] h1 { margin-block-start: 20%; }
section[epub|type~="titlepage"] p,
section[epub|type~="dedication"] p,
section[epub|type~="imprint"] p { text-indent: 0; }

/* --- Print --- */

@media print {
  body {
    max-inline-size: none;
    padding: 0;
    font-size: 11pt;
  }

  h1, h2, h3 {
    page-break-after: avoid;
  }

  figure, tr {
    page-break-inside: avoid;
  }
}

/* Extended Markdown: readable reference material within a book. */
pre, code, kbd, samp { font-variant-numeric: normal; font-style: normal; }
ins { text-decoration: underline; text-underline-offset: 0.15em; }
mark { text-decoration-style: double; text-underline-offset: 0.15em; }
dt { break-after: avoid; page-break-after: avoid; }
dd > :first-child { margin-block-start: 0; }
dd > :last-child { margin-block-end: 0; }
dd { margin-block-end: var(--space-sm); }
table { font-variant-numeric: lining-nums tabular-nums; line-height: 1.45; }
thead th { vertical-align: bottom; }
blockquote em { font-style: italic; }
blockquote blockquote { margin-inline-end: 0; }
aside[role="doc-footnote"] { font-size: 0.9em; line-height: 1.5; }
aside[role="doc-footnote"] + aside[role="doc-footnote"] {
  border-block-start: 0;
  padding-block-start: 0;
  margin-block-start: var(--space-sm);
}
aside[role="doc-footnote"] p + p { text-indent: 0; margin-block-start: var(--space-xs); }
a[role="doc-noteref"] { text-decoration: none; }
a[role="doc-backlink"] { font-variant-numeric: lining-nums; }
