/*
 * Mönster av mening
 * Book stylesheet with Crimson Pro
 */

@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ========================================
   CSS Variables
   ======================================== */

:root {
  /* Colors */
  --color-text: #2c2c2c;
  --color-text-light: #5a5a5a;
  --color-text-muted: #888;
  --color-background: #fdfcfa;
  --color-background-alt: #f5f3ef;
  --color-accent: #8b4513;
  --color-accent-light: #d4a574;
  --color-border: #e0dcd4;

  /* Typography */
  --font-body: 'Crimson Pro', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  /* Sizing */
  --content-width: 38rem;
  --content-width-wide: 48rem;
  --line-height: 1.7;
  --line-height-tight: 1.4;
}

/* ========================================
   Base Styles
   ======================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-background);
  margin: 0 auto;
  padding: 2rem 5%;
  max-width: var(--content-width);
}

/* ========================================
   Layout
   ======================================== */

.book-container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.chapter {
  margin-bottom: 4rem;
}

/* ========================================
   Typography
   ======================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-body);
  font-weight: 600;
  line-height: var(--line-height-tight);
  color: var(--color-text);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.3rem;
  margin-top: 2.5rem;
  padding-top: 0;
  border-top: none;
}

h3 {
  font-size: 1.1rem;
}

h4 {
  font-size: 1rem;
  font-weight: 600;
}

p {
  margin: 0 0 1.25rem 0;
  text-align: left;
  hyphens: auto;
}

/* Lead paragraph / subtitle */
.subtitle,
h1 + p:first-of-type,
.lead {
  font-size: 1.15rem;
  font-style: italic;
  color: var(--color-text-light);
  margin-bottom: 2rem;
}

/* Block quotes */
blockquote {
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  border-left: 3px solid var(--color-accent-light);
  background-color: var(--color-background-alt);
  font-style: italic;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* Emphasis */
em {
  font-style: italic;
}

strong {
  font-weight: 600;
}

/* Links */
a {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-color: var(--color-accent-light);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--color-text);
  text-decoration-color: var(--color-accent);
}

/* ========================================
   Lists
   ======================================== */

ul, ol {
  margin: 1.25rem 0;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.5rem;
}

li > ul, li > ol {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

/* ========================================
   Code
   ======================================== */

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background-color: var(--color-background-alt);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  background-color: var(--color-background-alt);
  padding: 1rem 1.25rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

pre code {
  background: none;
  padding: 0;
}

/* ========================================
   Images
   ======================================== */

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
}

/* Cover image - full width with some breathing room */
body > p:first-of-type img,
img[src*="cover"] {
  max-width: 100%;
  width: 100%;
  margin: 0 auto 2rem;
}

/* Chapter images */
img[src*="chapter"] {
  max-width: 100%;
  width: 100%;
  margin: 1.5rem auto;
  border-radius: 4px;
}

/* ========================================
   Tables
   ======================================== */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-weight: 600;
  background-color: var(--color-background-alt);
}

tr:last-child td {
  border-bottom: none;
}

/* ========================================
   Horizontal Rules / Section Breaks
   ======================================== */

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 3rem auto;
  width: 30%;
}

/* Decorative section break */
.section-break {
  text-align: center;
  margin: 3rem 0;
  color: var(--color-text-muted);
}

.section-break::before {
  content: "• • •";
  letter-spacing: 0.5em;
}

/* ========================================
   Chapter Opening Page
   ======================================== */

/* Chapter title with .chapter class - style for ePUB splitting */
h1.chapter {
  text-align: center;
  font-size: 2.2rem;
  margin-top: 2rem;
  margin-bottom: 0;
  page-break-before: always;
}

.chapter-opening {
  text-align: center;
  min-height: 85vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  margin-top: 0;
}

.chapter-opening h1 {
  font-size: 2.2rem;
  margin-top: 0;
  margin-bottom: 1.5rem;
}

.chapter-opening img {
  max-width: 100%;
  width: 400px;
  height: auto;
  margin: 1.5rem auto;
  display: block;
  border-radius: 8px;
}

.chapter-number {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  font-weight: 400;
}

.chapter-ingress {
  background-color: var(--color-background-alt);
  border-left: 4px solid var(--color-accent-light);
  padding: 1.5rem 2rem;
  margin: 2rem auto;
  max-width: 90%;
  border-radius: 0 8px 8px 0;
}

.chapter-ingress em {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--color-text-light);
  display: block;
}

/* ========================================
   Chapter Header (legacy)
   ======================================== */

.chapter-header {
  text-align: center;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
}

.chapter-header h1 {
  margin-bottom: 0.75rem;
}

.chapter-header .subtitle {
  margin-bottom: 0;
}

/* Chapter illustration */
.chapter-image {
  width: 100%;
  max-width: 400px;
  margin: 0 auto 2rem;
  display: block;
  border-radius: 4px;
}

/* ========================================
   Summary Box
   ======================================== */

.summary {
  background-color: var(--color-background-alt);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1.5rem;
  margin: 2rem 0;
}

.summary h4 {
  margin-top: 0;
  margin-bottom: 1rem;
}

.summary ul {
  margin-bottom: 0;
}

/* ========================================
   Title Page
   ======================================== */

.title-page {
  text-align: center;
  padding: 4rem 2rem;
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.title-page h1 {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.title-page .subtitle {
  font-size: 1.4rem;
  margin-bottom: 4rem;
}

.title-page .author {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.title-page .publisher {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin-top: 3rem;
}

/* ========================================
   Table of Contents
   ======================================== */

.toc {
  margin: 2rem 0;
}

.toc-list {
  list-style: none;
  padding-left: 0;
}

.toc-list li {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: baseline;
}

.toc-number {
  min-width: 2rem;
  color: var(--color-text-muted);
}

.toc-title {
  flex-grow: 1;
}

.toc-page {
  color: var(--color-text-muted);
  margin-left: 1rem;
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
  html {
    font-size: 11pt;
  }

  body {
    background: white;
    color: black;
  }

  .book-container {
    max-width: none;
    padding: 0;
  }

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

  p, blockquote, li {
    orphans: 3;
    widows: 3;
  }

  .chapter {
    page-break-before: always;
  }

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

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  .book-container {
    padding: 1.5rem 1rem 3rem;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.4rem;
  }

  .title-page h1 {
    font-size: 2.2rem;
  }

  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 0.5rem;
  }
}
