/* ================ Global ================= */
:root {
  --primary-color: #007BFF;
  --text-color: #333;
  --muted-color: #666;
  --bg-light: #fafafa;
  --bg-white: #fff;
  --border-color: #ddd;
  --font-sans: "Poppins", sans-serif;
  --font-ar: "El Messiri", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--text-color);
  background-color: var(--bg-white);
  line-height: 1.6;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ================ Pages ================= */
.page {
  width: 100vw;
  height: 100vh;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

#cover.page {
  display: flex;
  background-color: var(--bg-white);
}

/* Home button */
#home-button {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 8px 12px;
  background: var(--bg-light);
  border-radius: 4px;
  font-size: 0.9rem;
}

/* ================ Cover ================= */
#book-cover {
  width: 90%;
  max-width: 800px;
  padding: 20px;
  background: var(--bg-light);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
  position: relative;
}

/* Close icon */
#close-button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 24px;
  height: 24px;
  background: url("assets/images/close.svg") center/contain no-repeat;
}

/* Cover image */
#cover-image img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 4px;
}

/* Titles */
#book-title {
  margin: 16px 0;
}

#arabic-title {
  font-family: var(--font-ar);
  font-size: 2rem;
  margin: 0;
}

#english-title {
  font-size: 1.5rem;
  margin: 4px 0 0;
  font-weight: 500;
}

/* Description & version */
#book-description p {
  margin: 8px 0;
  font-size: 1rem;
  color: var(--text-color);
}

#version {
  font-size: 0.9rem;
  color: var(--muted-color);
}

/* Author */
#book-author p {
  margin: 4px 0;
  font-size: 0.9rem;
  color: var(--muted-color);
}

/* Open book button */
#book-actions {
  margin-top: 20px;
}

#enter-button {
  padding: 10px 20px;
  font-size: 1rem;
  background: var(--primary-color);
  color: #fff;
  border-radius: 4px;
}

/* ================ Content Page ================= */
#content-page.page {
  background-color: var(--bg-white);
}

#app {
  width: 95%;
  max-width: 800px;
  margin: 0 auto;
  padding: 10px;
}

/* Index header */
#index-header {
  position: sticky;
  top: 0;
  background: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 10;
}

#index-header.hidden {
  transform: translateY(-100%);
  opacity: 0;
}

#index-header span {
  font-size: 1.25rem;
  font-weight: 600;
}

/* Back/close-to-cover button */
#back-to-cover {
  width: 24px;
  height: 24px;
  background: url("assets/images/close.svg") center/contain no-repeat;
}

/* Index section */
#index {
  margin-top: 20px;
}

#index h1 {
  font-size: 1.5rem;
  margin-bottom: 10px;
}

/* Index list */
#index-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

#index-list li {
  margin: 5px 0;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
  background: #0000001c;
  text-align: center;
}

#index-list li:hover {
  background: var(--bg-light);
}

/* Content container */
#content-container {
  margin-top: 20px;
}

/* Review link */
.review-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
}

#review-link {
  display: inline-block;
  padding: 8px 12px;
  background: var(--primary-color);
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ================ Dynamic Content Styles ================= */
/* Fade-in for lazy-loaded sections */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.lazy-load {
  opacity: 0;
  animation: fadeIn 0.5s ease forwards;
  animation-delay: var(--delay, 0s);
  margin-bottom: 30px;
}

/* Metadata block */
.metadata-container {
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.metadata-title {
  font-size: 1.75rem;
  margin: 0 0 10px;
}

.metadata-author,
.metadata-translator {
  font-size: 1rem;
  margin: 0 0 5px;
  color: var(--muted-color);
}

.metadata-description {
  font-size: 1rem;
  margin: 10px 0 0;
}

/* Chapter header & controls */
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.text-container {
  display: flex;
  flex-direction: column;
}

.english-header {
  font-size: 1.25rem;
  margin: 0;
  color: var(--text-color);
}

.arabic-header {
  font-size: 1rem;
  margin: 0;
  color: var(--muted-color);
  direction: rtl;
  text-align: right;
}

.button-container {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 32px;
  height: 32px;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 24px 24px;
  border: none;
  cursor: pointer;
}

/* Chapter content */
.chapter-content {
  padding-left: 10px;
  margin-bottom: 20px;
}

.chapter-content.collapsed {
  display: none;
}

/* Intro & rows */
.introduction-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  margin-bottom: 10px;
}

.centered-text {
  text-align: center;
  font-size: 1.5rem;
  margin: 0;
}

.left-aligned-text {
  text-align: left;
  font-size: 1.25rem;
  margin: 0;
}

.styled-paragraph {
  font-size: 1rem;
  margin: 0 0 10px;
  line-height: 1.6;
}

/* Lists inside chapters */
.chapter-content ul {
  margin: 0 0 10px 20px;
  list-style: disc;
}

.chapter-content li {
  margin-bottom: 5px;
  line-height: 1.5;
}

/* ================ Responsive ================= */
@media (max-width: 600px) {
  #book-cover {
    padding: 10px;
  }

  #arabic-title {
    font-size: 1.5rem;
  }

  #english-title {
    font-size: 1.2rem;
  }

  #index-header span {
    font-size: 1rem;
  }

  .metadata-title {
    font-size: 1.5rem;
  }

  .english-header {
    font-size: 1.1rem;
  }

  .styled-paragraph {
    font-size: 0.95rem;
  }
}


/* ─── Sticky Chapter Headers ─────────────────────────────────────────── */
.block-header.sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-white);
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.block-header.sticky h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
}

/* English on the left, Arabic on the right */
.block-header.sticky h2:first-child {
  text-align: left;
}

.block-header.sticky h2:last-child {
  text-align: right;
}

/* If there’s only one header (<h2>), span both columns & center it */
.block-header.sticky h2:only-child {
  grid-column: 1 / -1;
  text-align: center;
}

/* Mobile: stack Arabic above English, both centered */
@media (max-width: 600px) {
  .block-header.sticky {
    grid-template-columns: 1fr;
    grid-row-gap: 0.25rem;
  }

  .block-header.sticky h2 {
    text-align: center;
  }

  /* reverse order so Arabic (last-child) comes first */
  .block-header.sticky h2:first-child {
    order: 2;
  }

  .block-header.sticky h2:last-child {
    order: 1;
  }
}

@media (max-width: 600px) {
  .block-parallel {
    flex-direction: column;
    align-items: stretch;
  }

  /* Arabic first, then English */
  .block-parallel .parallel-ar {
    order: 1;
  }

  .block-parallel .parallel-en {
    order: 2;
  }

  /* Footnotes always last */
  .block-parallel .footnotes-container {
    order: 3;
    /* ensure it sits below both panes */
    margin-top: 0.5rem;
    /* match your visible state spacing */
  }
}

/* ─── Parallel Text Blocks ───────────────────────────────────────────── */
.block-parallel {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.75rem 1rem;
}

/* alternating background colours */
.block-parallel:nth-of-type(odd) {
  background: #ededed;
}

.block-parallel:nth-of-type(even) {
  background: #ffffff;
}

/* English & Arabic panes */
.block-parallel .parallel-en {
  flex: 1;
  text-align: left;
  padding-right: 1rem;
}

.block-parallel .parallel-ar {
  flex: 1;
  text-align: right;
  padding-left: 1rem;
  direction: rtl;
}

/* ─── Parallel Text Blocks: Mobile stacking ─────────────────────────── */
@media (max-width: 600px) {
  .block-parallel {
    flex-direction: column;
    align-items: center;
  }

  .block-parallel .parallel-ar,
  .block-parallel .parallel-en {
    width: 100%;
    padding: 0.5rem 0;
  }

  /* Arabic first, then English */
  .block-parallel .parallel-ar {
    order: 1;
  }

  .block-parallel .parallel-en {
    order: 2;
  }
}

/* ─── Sticky Chapter Headers: Mobile stacking (ensure this is present) ─────────────────────────── */
@media (max-width: 600px) {
  .block-header.sticky {
    grid-template-columns: 1fr;
    grid-row-gap: 0.25rem;
  }

  .block-header.sticky h2 {
    text-align: center;
  }

  /* Arabic (last-child) first, then English */
  .block-header.sticky h2:last-child {
    order: 1;
  }

  .block-header.sticky h2:first-child {
    order: 2;
    text-align: center;
  }
}



/* ─── Footnote Toggle ────────────────────────────────────────────────── */
.footnotes-container {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  margin-top: 0;
}

/* make the footnotes box span beneath both columns */
.block-parallel .footnotes-container {
  flex: 1 1 100%;
  box-sizing: border-box;
  /* ensures padding/margins don’t overflow */
}

.footnotes-container.visible {
  /* allow it to expand to its full height */
  max-height: 500px;
  /* big enough to fit your notes */
  margin-top: 0.5rem;
}

.footnotes-container p {
  margin: 0.25rem 0;
  font-size: 0.9rem;
  color: var(--text-color);
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #e6e4dd;
  /* Deep navy */
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: white;
}

.english-header {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  text-align: left;
}

.arabic-header {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  text-align: right;
  direction: rtl;
}

.icon-button.collapse-button {
  width: 32px;
  height: 32px;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 24px 24px;
  border: none;
  cursor: pointer;
  margin-left: 1rem;
}

.footnote-sup {
  cursor: pointer;
  font-size: 0.8em;
  vertical-align: super;
  color: var(--primary-color);
}

/* make ◉ look like a button */
.footnote-sup {
  display: inline-block;
  cursor: pointer;
  font-size: 1.1em;
  line-height: 1;
  user-select: none;
  color: #333;
  /* default dot color */
  transition: color 0.2s ease;
  margin: 0 0.2em;
}

/* when active (note is visible), turn red */
.footnote-sup.active {
  color: red;
}

#index-header {
  position: sticky;
  top: 0;
  z-index: 9;
  /* lower */
  /* … */
}

.block-header.sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  /* higher than #index-header */
  /* … */
}

html {
  scroll-behavior: smooth;
}

#index {
  max-width: 600px;
  margin: 2rem auto;
  padding: 0 1rem;
}

#index h1 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 1rem;
}

#index-list {
  list-style: none;
  padding: 0;
}

#index-list li {
  margin-bottom: 0.75rem;
}

#index-list a {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  text-decoration: none;
  background: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  color: inherit;
  transition: background 0.2s;
}

#index-list a:hover {
  background: #f5f5f5;
}

#index-list .index-en {
  justify-self: start;
}

#index-list .index-ar {
  justify-self: end;
  direction: rtl;
}

@media (max-width: 600px) {
  #index-list a {
    grid-template-columns: 1fr;
    text-align: center;
  }

  #index-list .index-ar {
    order: 1;
  }

  #index-list .index-en {
    order: 2;
  }
}

/* ─── Responsive media: fill the full width of the book ───────────────── */
#content-container section img,
#content-container section video {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  /* or “cover” if you want them to crop to fill */
  margin: 0;
  /* removes any default spacing */
}

/* ─── RTL alignment for Arabic notes ─────────────────────────────────── */
.block-note:lang(ar) {
  direction: rtl;
  text-align: right;
  font-family: var(--font-ar);
}