/* ==========================================================================
   WikiPub Minimalist Reading Stylesheet
   Crafted for distraction-free reading on desktop, mobile, and e-ink browsers.
   ========================================================================== */

:root {
  --bg-primary: #fcfbf9;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f1eb;
  --border-color: #e5dfd5;
  --border-subtle: #eee9e0;
  --text-main: #23211e;
  --text-muted: #6a645b;
  --text-faint: #989186;
  --accent: #2c2925;
  --accent-link: #8c3b1e;
  --accent-link-hover: #5d2511;
  --accent-subtle: #efeae2;
  
  --font-serif: "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  
  --reading-max-width: 68ch;
  --reading-font-size: 1.18rem;
  --reading-line-height: 1.78;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #171615;
    --bg-surface: #1f1d1b;
    --bg-subtle: #292724;
    --border-color: #383430;
    --border-subtle: #2b2824;
    --text-main: #ede8e1;
    --text-muted: #aba398;
    --text-faint: #736c63;
    --accent: #f7f3ed;
    --accent-link: #e28059;
    --accent-link-hover: #fca07a;
    --accent-subtle: #302d29;
  }
}

/* Custom explicit theme attributes */
[data-theme="sepia"] {
  --bg-primary: #f4ecd8;
  --bg-surface: #fbf7ee;
  --bg-subtle: #eae1c8;
  --border-color: #dcd2b8;
  --border-subtle: #e5dbc2;
  --text-main: #342818;
  --text-muted: #6f5f4b;
  --text-faint: #988770;
  --accent: #2e2112;
  --accent-link: #8d3e1d;
  --accent-link-hover: #5d2511;
  --accent-subtle: #e9dec3;
}

[data-theme="dark"] {
  --bg-primary: #171615;
  --bg-surface: #1f1d1b;
  --bg-subtle: #292724;
  --border-color: #383430;
  --border-subtle: #2b2824;
  --text-main: #ede8e1;
  --text-muted: #aba398;
  --text-faint: #736c63;
  --accent: #f7f3ed;
  --accent-link: #e28059;
  --accent-link-hover: #fca07a;
  --accent-subtle: #302d29;
}

[data-theme="paper"] {
  --bg-primary: #fcfbf9;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f1eb;
  --border-color: #e5dfd5;
  --border-subtle: #eee9e0;
  --text-main: #23211e;
  --text-muted: #6a645b;
  --text-faint: #989186;
  --accent: #2c2925;
  --accent-link: #8c3b1e;
  --accent-link-hover: #5d2511;
  --accent-subtle: #efeae2;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

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

/* --------------------------------------------------------------------------
   Header & Layout Chrome
   -------------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  padding: 1.1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.site-logo span {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: 0.5rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.55rem 1.1rem;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  transition: background-color 0.15s, border-color 0.15s;
}

.btn:hover {
  background-color: var(--bg-subtle);
  border-color: var(--text-muted);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--bg-surface);
  border-color: var(--accent);
}

.btn-primary:hover {
  background-color: var(--text-muted);
  color: var(--bg-surface);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.btn-subtle {
  background-color: transparent;
  border-color: transparent;
}

.btn-subtle:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-color);
}

.btn-saved {
  background-color: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent-link);
  font-weight: 600;
}

.header-nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.nav-link {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.nav-link:hover {
  color: var(--text-main);
  text-decoration: underline;
}

.chip.active {
  background-color: var(--accent);
  color: var(--bg-surface);
  border-color: var(--accent);
}

/* --------------------------------------------------------------------------
   Home Page
   -------------------------------------------------------------------------- */
.home-hero {
  max-width: 720px;
  margin: 4.5rem auto 3rem auto;
  padding: 0 1.5rem;
  text-align: center;
}

.hero-tagline {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 1.25rem 0;
}

.hero-subtitle {
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 2.5rem 0;
  max-width: 580px;
  margin-left: auto;
  margin-right: auto;
}

.generator-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.75rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
  text-align: left;
}

.input-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.text-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.input-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quick-examples {
  margin-top: 2.5rem;
  text-align: center;
}

.quick-examples p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.example-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.chip {
  display: inline-block;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
}

.chip:hover {
  background-color: var(--bg-subtle);
  border-color: var(--text-muted);
}

.recent-editions-section {
  max-width: 860px;
  margin: 3.5rem auto;
  padding: 0 1.5rem;
}

.section-heading {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

.editions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.25rem;
}

.edition-card {
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  border-radius: 6px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, border-color 0.15s;
}

.edition-card:hover {
  transform: translateY(-2px);
  border-color: var(--text-muted);
}

.edition-card-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  line-height: 1.3;
}

.edition-card-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
}

/* --------------------------------------------------------------------------
   Generation In-Progress Screen
   -------------------------------------------------------------------------- */
.generation-container {
  max-width: 580px;
  margin: 6rem auto;
  padding: 2rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  text-align: center;
}

.generation-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 1.5rem auto;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.generation-title {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  margin: 0 0 0.5rem 0;
}

.generation-status-text {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.generation-steps {
  list-style: none;
  padding: 0;
  margin: 0 auto 2rem auto;
  text-align: left;
  max-width: 380px;
}

.generation-step-item {
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
  border-radius: 4px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
}

.generation-step-item.active {
  color: var(--text-main);
  font-weight: 600;
  background-color: var(--accent-subtle);
}

.generation-step-item.completed {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* --------------------------------------------------------------------------
   Web Reader Surface
   -------------------------------------------------------------------------- */
.reader-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.reader-toolbar {
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 59px;
  z-index: 90;
}

.reader-toolbar-inner {
  max-width: var(--reading-max-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
}

.reader-article-container {
  max-width: var(--reading-max-width);
  margin: 2.5rem auto 5rem auto;
  padding: 0 1.5rem;
  font-family: var(--font-serif);
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
  color: var(--text-main);
}

.book-masthead {
  text-align: center;
  margin-bottom: 3.5rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border-color);
}

.book-title {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 0.8rem 0;
}

.book-subtitle {
  font-size: 1.25rem;
  font-style: italic;
  font-weight: 400;
  color: var(--text-muted);
  margin: 0 0 1.75rem 0;
}

.book-meta {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
}

.reader-toc {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1.5rem;
  margin-bottom: 3.5rem;
  font-family: var(--font-sans);
}

.reader-toc h3 {
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.toc-list {
  list-style: decimal;
  padding-left: 1.5rem;
  margin: 0;
}

.toc-list li {
  margin-bottom: 0.6rem;
  font-size: 1rem;
}

.toc-list a {
  text-decoration: none;
  color: var(--text-main);
}

.toc-list a:hover {
  text-decoration: underline;
  color: var(--accent-link);
}

/* Reader Typography & Prose */
.chapter-block {
  margin-bottom: 4rem;
}

.chapter-number {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.4rem;
}

.chapter-title {
  font-size: 2rem;
  line-height: 1.25;
  margin-top: 0;
  margin-bottom: 1.5rem;
  letter-spacing: -0.015em;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

.chapter-takeaway {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  border-left: 3px solid var(--border-color);
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
  border-radius: 0 4px 4px 0;
}

.prose p {
  margin-top: 0;
  margin-bottom: 1.5rem;
  text-align: justify;
}

.prose p.first-p::first-letter {
  font-size: 3.2em;
  float: left;
  line-height: 0.75;
  margin-right: 0.12em;
  margin-bottom: -0.05em;
  font-weight: 700;
  color: var(--text-main);
}

.prose blockquote {
  font-style: italic;
  margin: 2rem 1.5rem;
  padding-left: 1.25rem;
  border-left: 3px solid var(--border-color);
  color: var(--text-muted);
}

.prose figure {
  margin: 2.5rem 0;
  text-align: center;
}

.prose figure img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.prose figcaption {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 0.6rem;
  padding: 0 1rem;
  line-height: 1.4;
}

/* Timeline & Key Figures Component */
.milestones-section {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2rem;
  margin: 4rem 0;
  font-family: var(--font-sans);
}

.milestones-section h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin-top: 0;
  margin-bottom: 1.5rem;
}

.timeline-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.timeline-item {
  display: flex;
  gap: 1.25rem;
  align-items: baseline;
}

.timeline-year {
  font-weight: 700;
  min-width: 70px;
  color: var(--accent-link);
}

.timeline-desc {
  font-size: 0.95rem;
  color: var(--text-main);
}

.key-figures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.figure-card {
  padding: 0.75rem;
  background-color: var(--bg-subtle);
  border-radius: 4px;
}

.figure-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.figure-role {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Sources & Legal Footer */
.attribution-section {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.attribution-section h4 {
  margin-top: 0;
  font-size: 0.95rem;
  color: var(--text-main);
}

.attribution-section ul {
  padding-left: 1.25rem;
}

.site-footer {
  border-top: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  background-color: var(--bg-primary);
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: auto;
}

.chapter-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  font-family: var(--font-sans);
}

/* Responsive tweaks */
@media (max-width: 640px) {
  .hero-title {
    font-size: 2.1rem;
  }
  .input-group {
    flex-direction: column;
  }
  .reader-article-container {
    padding: 0 1rem;
    font-size: 1.1rem;
  }
  .book-title {
    font-size: 2rem;
  }
}
