/* ================================================================
   Pāli Bhāsā Interactive Reader & Study Platform CSS
   Theravada Tipitaka Press
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400&family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Noto+Serif+Devanagari:wght@400;600&family=Noto+Serif+Myanmar:wght@400;600&family=Noto+Serif+Sinhala:wght@400;600&family=Noto+Serif+Thai:wght@400;600&display=swap');

:root {
  --ink: #150d09;
  --ink-2: #1d1310;
  --ink-card: #221713;
  --gold: #f4d875;
  --gold-dim: #c9ab63;
  --saffron: #f99d29;
  --ruby: #ab0a0f;
  --paper: #f8f3e8;
  --paper-2: #f2ebd9;
  --paper-card: #ede4ce;
  --paper-line: #dfd2b8;
  --text: #241c15;
  --text-dim: #6b5844;
  --text-faint: #96836c;
  --reader-font-size: 1.18rem;
  --font-pali: "EB Garamond", Georgia, serif;
}

[data-theme="dark"] {
  --paper: #120e0b;
  --paper-2: #191410;
  --paper-card: #201a14;
  --paper-line: #33271e;
  --text: #e6dacb;
  --text-dim: #b8a691;
  --text-faint: #7a6a57;
  --gold-dim: #d4b56b;
}

[data-theme="sepia"] {
  --paper: #eee4cc;
  --paper-2: #e4d7bb;
  --paper-card: #dbccab;
  --paper-line: #c8b794;
  --text: #2c2219;
  --text-dim: #6e5842;
  --text-faint: #8f775c;
}

[data-script="sinhala"] {
  --font-pali: "Noto Serif Sinhala", "EB Garamond", serif;
}
[data-script="thai"] {
  --font-pali: "Noto Serif Thai", "EB Garamond", serif;
}
[data-script="burmese"] {
  --font-pali: "Noto Serif Myanmar", "EB Garamond", serif;
}
[data-script="devanagari"] {
  --font-pali: "Noto Serif Devanagari", "EB Garamond", serif;
}

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

html, body.reader-body {
  max-width: 100%;
  overflow-x: hidden;
}

#readerContent img {
  max-width: 100%;
  height: auto;
}

.reader-intro {
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.95em;
  line-height: 1.7;
  color: var(--text-dim);
  background: var(--paper-card);
  border-left: 3px solid var(--gold-dim);
  padding: 0.9rem 1.1rem;
  border-radius: 0 8px 8px 0;
  margin: 0 0 2rem;
}

.grammar-section {
  overflow-x: auto;
}

body.reader-body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-pali);
  font-size: var(--reader-font-size);
  line-height: 1.7;
  transition: background 0.25s ease, color 0.25s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navigation Bar */
.reader-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--paper-2);
  border-bottom: 1px solid var(--paper-line);
  backdrop-filter: blur(8px);
  padding: 0.6rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.reader-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
}

.reader-nav-brand img {
  height: 28px;
  width: auto;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.control-btn, .script-select, .chapter-select {
  background: var(--paper-card);
  color: var(--text);
  border: 1px solid var(--paper-line);
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  font-family: var(--font-pali);
  font-size: 0.92rem;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.control-btn:hover, .script-select:hover, .chapter-select:hover {
  border-color: var(--gold-dim);
}

.auth-pill {
  background: linear-gradient(135deg, #b8590f, #ab0a0f);
  color: #fff;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.auth-pill.unlocked {
  background: #2a6136;
}

/* Reader Main Container */
.reader-container {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 6rem;
  flex: 1;
}

/* Chapter Title Header */
.chapter-header {
  text-align: center;
  margin-bottom: 2.8rem;
  padding-bottom: 1.8rem;
  border-bottom: 1px solid var(--paper-line);
}

.chapter-number-tag {
  font-size: 0.8rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: block;
  margin-bottom: 0.4rem;
}

.chapter-main-title {
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(2rem, 3.5vw, 3rem);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.5rem;
}

.chapter-meta-tag {
  font-size: 0.95rem;
  color: var(--text-dim);
  font-style: italic;
}

/* Story Section Dividers */
.section-banner {
  text-align: center;
  margin: 2.5rem 0 1.5rem;
  position: relative;
}

.section-banner::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--paper-line);
  z-index: 1;
}

.section-banner span {
  position: relative;
  z-index: 2;
  background: var(--paper);
  padding: 0 1.2rem;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--saffron-deep, #9c4c0c);
}

/* Story Grid - Two-Column Layout on Desktop */
.story-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 2.5rem;
  margin-bottom: 1.6rem;
  align-items: start;
}

.story-text {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  font-size: var(--reader-font-size);
  line-height: 1.85;
}

.story-text p {
  margin: 0 0 1rem;
  text-indent: 1.5rem;
}

.story-text p:first-of-type {
  text-indent: 0;
}

.margin-column {
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-dim);
  border-left: 2px solid var(--paper-line);
  padding-left: 1.2rem;
}

.margin-card {
  background: var(--paper-card);
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 0.85rem;
  border: 1px solid var(--paper-line);
}

.margin-card img {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin-bottom: 0.4rem;
}

.margin-card strong {
  color: var(--text);
}

/* Full-width Illustrations */
.story-illustration {
  margin: 2.5rem 0;
  text-align: center;
}

.story-illustration img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  margin: 0 auto;
  max-height: 480px;
  object-fit: contain;
}

/* Grammar Tables Section */
.grammar-section {
  margin-top: 4rem;
  background: var(--paper-card);
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  padding: 2rem;
}

.grammar-section h3 {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.8rem;
  margin-bottom: 1.2rem;
  color: var(--text);
  border-bottom: 1px solid var(--paper-line);
  padding-bottom: 0.5rem;
}

.pali-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 1.05rem;
}

.pali-table th, .pali-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--paper-line);
  text-align: left;
}

.pali-table th {
  font-weight: 600;
  color: var(--text-faint);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}

/* Interactive Drill Exercises */
.exercises-section {
  margin-top: 3.5rem;
}

.exercise-card {
  background: var(--paper-card);
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  padding: 1.8rem;
  margin-bottom: 2rem;
}

.exercise-card h4 {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.45rem;
  margin: 0 0 1.2rem;
  color: var(--text);
}

.exercise-item {
  margin-bottom: 1rem;
  line-height: 2;
  font-size: 1.1rem;
}

.drill-input {
  background: var(--paper);
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-pali);
  font-size: 1.05rem;
  padding: 0.2rem 0.5rem;
  width: 110px;
  text-align: center;
  outline: none;
  transition: all 0.2s ease;
}

.drill-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(244, 216, 117, 0.25);
}

.drill-input.correct {
  background: rgba(42, 97, 54, 0.15);
  border-color: #2a6136;
  color: #2a6136;
}

.drill-check-btn {
  margin-top: 1rem;
  background: var(--text);
  color: var(--paper);
  border: none;
  padding: 0.5rem 1.2rem;
  border-radius: 4px;
  font-family: var(--font-pali);
  cursor: pointer;
  font-size: 0.95rem;
}

/* Locked Overlay & Paywall Banner */
.locked-overlay {
  background: linear-gradient(180deg, rgba(248, 243, 232, 0) 0%, var(--paper) 60%);
  padding: 4rem 1.5rem 2rem;
  text-align: center;
  position: relative;
  margin-top: -100px;
  z-index: 10;
}

.unlock-box {
  background: var(--paper-card);
  border: 2px solid var(--gold-dim);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  max-width: 580px;
  margin: 0 auto;
  box-shadow: 0 16px 36px rgba(0,0,0,0.12);
}

.unlock-box h3 {
  font-family: "Cormorant Garamond", serif;
  font-size: 2rem;
  margin: 0 0 0.8rem;
}

.pricing-pills {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.price-card {
  border: 1px solid var(--paper-line);
  background: var(--paper);
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.price-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold);
}

.price-card .country { font-size: 0.8rem; color: var(--text-faint); display: block; }
.price-card .amount { font-size: 1.3rem; font-weight: 600; color: var(--text); }

.checkout-action-btn {
  background: linear-gradient(135deg, #b8590f, #ab0a0f);
  color: #fff;
  border: none;
  font-size: 1.15rem;
  font-weight: 600;
  padding: 0.85rem 2rem;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  margin-top: 1rem;
  box-shadow: 0 4px 14px rgba(171, 10, 15, 0.3);
  transition: transform 0.15s ease;
}

.checkout-action-btn:hover {
  transform: translateY(-1px);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop.active {
  display: flex;
}

.modal-dialog {
  background: var(--paper);
  border: 1px solid var(--paper-line);
  border-radius: 12px;
  padding: 2.2rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 48px rgba(0,0,0,0.3);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-dim);
  cursor: pointer;
}

/* Preview Callout Banner */
.preview-callout {
  background: linear-gradient(135deg, rgba(244, 216, 117, 0.18), rgba(249, 157, 41, 0.12));
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  padding: 0.85rem 1.25rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.95rem;
}

.preview-callout .callout-text {
  color: var(--text);
  line-height: 1.45;
}

.preview-callout .callout-btn {
  background: linear-gradient(135deg, #b8590f, #ab0a0f);
  color: #fff;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(171, 10, 15, 0.25);
  transition: transform 0.15s ease;
}

.preview-callout .callout-btn:hover {
  transform: translateY(-1px);
}

/* Mid-Chapter CTA Card */
.course-cta-card {
  background: var(--paper-card);
  border: 2px solid var(--gold-dim);
  border-radius: 12px;
  padding: 2.2rem 1.8rem;
  margin: 3.5rem 0 2rem;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0,0,0,0.08);
}

.course-cta-card h3 {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.85rem;
  margin: 0 0 0.6rem;
  color: var(--text);
}

.course-cta-card p {
  color: var(--text-dim);
  max-width: 580px;
  margin: 0 auto 1.4rem;
  font-size: 1.05rem;
  line-height: 1.55;
}

/* Sticky Bottom Bar on Mobile/Desktop */
.sticky-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  gap: 0.75rem;
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 45;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
  border-top: 1px solid var(--gold-dim);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sticky-bottom-bar .bar-info {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.95rem;
}

.sticky-bottom-bar .bar-badge {
  background: var(--saffron-deep, #b8590f);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}

.sticky-bottom-bar .bar-btn {
  background: linear-gradient(135deg, var(--gold, #f4d875), var(--saffron, #f99d29));
  color: #1a100a;
  border: none;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.5rem 1.25rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(249, 157, 41, 0.4);
}

/* Responsive Mobile Layout */
@media (max-width: 820px) {
  .story-row {
    grid-template-columns: 1fr;
    gap: 1.2rem;
  }
  
  .margin-column {
    border-left: none;
    border-top: 1px dashed var(--paper-line);
    padding-left: 0;
    padding-top: 0.8rem;
  }
  
  .reader-controls {
    justify-content: flex-end;
  }
  
  .chapter-select {
    max-width: 140px;
  }

  .preview-callout {
    flex-direction: column;
    align-items: flex-start;
  }

  .sticky-bottom-bar {
    padding: 0.6rem 0.9rem;
  }
  .sticky-bottom-bar .bar-info {
    min-width: 0;
    flex-wrap: wrap;
    gap: 0.4rem;
    font-size: 0.85rem;
  }
  .sticky-bottom-bar .bar-info span:last-child {
    display: none;
  }
  .sticky-bottom-bar .bar-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }
}
