/* =============================================================================
   GAKHUR Philosophy Platform — Reading Environment
   assets/css/reader.css
   =============================================================================
   Contents:
     1.  Reading Progress Bar
     2.  Reader Controls Toolbar
     3.  Chapter Layout & Container
     4.  Chapter Header
     5.  Chapter Body Typography
     6.  Block Elements (blockquote, aphorism, question block, lists)
     7.  Chapter Navigation (prev/next)
     8.  Quiet Realisation — Reflection Box
     9.  Reflection List
     10. Chapter Completion Banner
     11. Volume Table of Contents (when ?v= only)
     12. Font Size Modifier Classes
     13. Responsive
   ============================================================================= */

/* =============================================================================
   1. Reading Progress Bar
   ============================================================================= */
.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;                        /* Driven by reader.js */
  height: var(--progress-height);
  background-color: var(--progress-color);
  z-index: calc(var(--z-header) + 1);
  transition: width 0.1s linear;
  transform-origin: left;
  pointer-events: none;
}

/* =============================================================================
   2. Reader Controls Toolbar
   ============================================================================= */
.reader-controls {
  position: sticky;
  top: 56px;                        /* Sits below the site header */
  z-index: calc(var(--z-header) - 1);
  background-color: var(--bg);
  border-bottom: 1px solid var(--border-faint);
  padding: 0.5rem var(--gutter);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  transition: background-color var(--transition-slow);
}

.reader-controls__group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-right: 1px solid var(--border-faint);
  padding-right: 0.75rem;
  margin-right: 0.25rem;
}

.reader-controls__group:last-child {
  border-right: none;
  padding-right: 0;
  margin-right: 0;
}

/* Theme buttons */
.theme-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.theme-btn:hover,
.theme-btn.active {
  border-color: var(--link);
  transform: scale(1.1);
}

.theme-btn--light  { background-color: #FAFAF7; border-color: #D8D4CE; }
.theme-btn--sepia  { background-color: #F4ECD8; }
.theme-btn--dark   { background-color: #1A1A2E; }

/* Font size buttons */
.font-size-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-family: var(--font-serif);
  line-height: 1;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.font-size-btn:hover {
  color: var(--text);
  background-color: var(--bg-alt);
}

.font-size-btn--sm  { font-size: 0.8rem; }
.font-size-btn--md  { font-size: 1rem;   }
.font-size-btn--lg  { font-size: 1.2rem; }

.font-size-btn.active {
  color: var(--link);
  background-color: var(--bg-alt);
}

/* Reading time display */
.reading-time-display {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-faint);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* =============================================================================
   3. Chapter Layout & Container
   ============================================================================= */
.chapter-page {
  min-height: 100vh;
}

.chapter-container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 3rem var(--gutter) 5rem;
}

/* =============================================================================
   4. Chapter Header
   ============================================================================= */
.chapter-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-faint);
}

.chapter-header__volume {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

.chapter-header__volume a {
  color: var(--text-faint);
  text-decoration: none;
}

.chapter-header__volume a:hover {
  color: var(--accent);
}

.chapter-header__title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
}

.chapter-header__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.chapter-header__meta-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* =============================================================================
   5. Chapter Body Typography
   ============================================================================= */
.chapter-body {
  font-family: var(--font-serif);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  color: var(--text);
}

/* Paragraph spacing */
.chapter-body p {
  font-family: var(--font-serif);
  font-size: inherit;
  line-height: inherit;
  color: var(--text);
  margin-bottom: 1.5em;
  max-width: 100%;
}

.chapter-body p:last-child {
  margin-bottom: 0;
}

/* Headings within content */
.chapter-body h2 {
  font-family: var(--font-display);
  font-size: 1.5em;
  font-weight: 700;
  color: var(--text);
  margin: 2.5em 0 1em;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.chapter-body h3 {
  font-family: var(--font-display);
  font-size: 1.25em;
  font-weight: 600;
  color: var(--text);
  margin: 2em 0 0.75em;
}

.chapter-body h4 {
  font-family: var(--font-ui);
  font-size: 1em;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 1.75em 0 0.5em;
}

/* Links */
.chapter-body a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.chapter-body a:hover {
  color: var(--link-hover);
}

/* Strong & em */
.chapter-body strong {
  font-weight: 600;
  color: var(--text);
}

.chapter-body em {
  font-style: italic;
  color: var(--text);
}

/* Horizontal rule */
.chapter-body hr {
  border: none;
  border-top: 1px solid var(--border-faint);
  margin: 2.5em auto;
  width: 40%;
}

/* Lists */
.chapter-body ul,
.chapter-body ol {
  padding-left: 1.5em;
  margin-bottom: 1.5em;
}

.chapter-body ul { list-style: disc; }
.chapter-body ol { list-style: decimal; }

.chapter-body li {
  font-family: var(--font-serif);
  font-size: inherit;
  line-height: var(--reader-line-height);
  margin-bottom: 0.5em;
  color: var(--text);
}

/* =============================================================================
   6. Block Elements
   ============================================================================= */

/* Standard blockquote */
.chapter-body blockquote {
  position: relative;
  margin: 2em 0;
  padding: 0.5em 0 0.5em 2em;
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--text-muted);
}

.chapter-body blockquote p {
  margin-bottom: 0.5em;
  font-size: 1.05em;
}

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

/* Aphorism block — TinyMCE custom style class */
.chapter-body .aphorism,
.chapter-body .aphorism-block {
  display: block;
  margin: 2.5em auto;
  padding: 1.5em 2em;
  max-width: 90%;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.2em;
  font-style: italic;
  line-height: 1.5;
  color: var(--text);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Question block — TinyMCE custom style class */
.chapter-body .question-block {
  display: block;
  margin: 2em 0;
  padding: 1.25em 1.5em;
  background-color: var(--bg-alt);
  border-left: 4px solid var(--link);
  border-radius: 0 4px 4px 0;
  font-style: italic;
  color: var(--text);
}

/* Section divider (three em-dashes style) */
.chapter-body .section-break {
  display: block;
  text-align: center;
  color: var(--text-faint);
  font-size: 1.2rem;
  letter-spacing: 0.5em;
  margin: 2.5em 0;
  user-select: none;
}

/* =============================================================================
   7. Chapter Navigation (prev / next)
   ============================================================================= */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-faint);
}

.chapter-nav__link {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  flex: 1;
  max-width: 48%;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background-color var(--transition-fast);
  background-color: var(--bg-raised);
}

.chapter-nav__link:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  background-color: var(--bg-raised);
}

.chapter-nav__link--next {
  text-align: right;
  margin-left: auto;
}

.chapter-nav__label {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.chapter-nav__title {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  color: var(--link);
  line-height: 1.4;
}

.chapter-nav__arrow {
  font-size: 1.1rem;
  color: var(--text-faint);
  line-height: 1;
}

.chapter-nav__placeholder {
  flex: 1;
  max-width: 48%;
}

/* =============================================================================
   8. Quiet Realisation — Reflection Box
   ============================================================================= */
.reflection-section {
  margin-top: 4rem;
  padding-top: 3rem;
  border-top: 1px solid var(--border-faint);
}

.reflection-section__heading {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
  font-style: italic;
}

.reflection-section__sub {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 1.75rem;
}

.reflection-form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.reflection-textarea {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--text);
  background-color: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  width: 100%;
  min-height: 140px;
  resize: vertical;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.reflection-textarea:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(45,53,97,0.1);
}

.reflection-textarea::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

.reflection-form__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.reflection-private-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.reflection-private-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--link);
  cursor: pointer;
}

.reflection-char-count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.reflection-char-count.over-limit {
  color: #C84B31;
  font-weight: 600;
}

.reflection-message {
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  font-style: italic;
  padding: 0.75rem 0;
  min-height: 2rem;
}

.reflection-message--success { color: #2E7D32; }
.reflection-message--error   { color: #C84B31; }

/* =============================================================================
   9. Reflection List
   ============================================================================= */
.reflections-list {
  margin-top: 2.5rem;
}

.reflections-list__heading {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-faint);
}

.reflection-item {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-faint);
}

.reflection-item:last-child {
  border-bottom: none;
}

.reflection-item__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.reflection-item__name {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.reflection-item__date {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.reflection-item__private-badge {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--link);
  background: var(--bg-alt);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.reflection-item__content {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--text-muted);
  font-style: italic;
}

.reflections-empty {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  color: var(--text-faint);
  font-style: italic;
  padding: 1rem 0;
  text-align: center;
}

/* =============================================================================
   10. Chapter Completion Banner
   ============================================================================= */
.chapter-completion {
  text-align: center;
  padding: 2rem 1rem;
  margin: 2rem 0;
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  color: var(--text-faint);
  font-style: italic;
}

/* =============================================================================
   11. Volume Table of Contents (read/index.php with ?v=slug)
   ============================================================================= */
.volume-toc {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 3rem var(--gutter);
}

.volume-toc__header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-faint);
}

.volume-toc__label {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.volume-toc__title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.2;
}

.volume-toc__summary {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  line-height: 1.75;
  color: var(--text-muted);
  font-style: italic;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chapter-list-item {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-faint);
  text-decoration: none;
  color: inherit;
  transition: color var(--transition-fast);
}

.chapter-list-item:hover {
  text-decoration: none;
  color: inherit;
}

.chapter-list-item:hover .chapter-list-item__title {
  color: var(--link);
}

.chapter-list-item:last-child {
  border-bottom: none;
}

.chapter-list-item__number {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  min-width: 2rem;
  flex-shrink: 0;
}

.chapter-list-item__title {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  color: var(--text);
  flex: 1;
  transition: color var(--transition-fast);
  line-height: 1.4;
}

.chapter-list-item__meta {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Back to all volumes link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-faint);
  text-decoration: none;
  margin-bottom: 2rem;
  transition: color var(--transition-fast);
}

.back-link:hover {
  color: var(--text);
  text-decoration: none;
}

/* =============================================================================
   12. Font Size Modifier Classes
   (Applied to <body> by reader.js, affects only .chapter-body)
   ============================================================================= */
body.font-small  .chapter-body { font-size: 1rem;       }  /* 16px */
body.font-medium .chapter-body { font-size: 1.125rem;   }  /* 18px — default */
body.font-large  .chapter-body { font-size: 1.3125rem;  }  /* 21px */

/* =============================================================================
   13. Responsive
   ============================================================================= */
@media (max-width: 480px) {
  .reader-controls {
    top: 52px;
    padding: 0.4rem 1rem;
    gap: 0.25rem;
  }

  .chapter-container {
    padding: 1.75rem 1rem 4rem;
  }

  .chapter-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
  }

  .chapter-header__title {
    font-size: 1.6rem;
  }

  .chapter-nav {
    flex-direction: column;
  }

  .chapter-nav__link,
  .chapter-nav__placeholder {
    max-width: 100%;
  }

  .chapter-nav__link--next {
    text-align: left;
    margin-left: 0;
  }

  .reflection-form__footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (min-width: 768px) {
  .chapter-container {
    padding: 4rem var(--gutter) 6rem;
  }

  .chapter-header {
    margin-bottom: 3.5rem;
  }

  .reader-controls {
    padding: 0.5rem 2rem;
  }
}
