/* =====================================================================
   Boukhari Digital Library — Public Site Styles
   ===================================================================== */

:root {
  --color-primary: #0b6b45;
  --color-primary-dark: #07502f;
  --color-deep: #0b2545;
  --color-accent: #d4a537;
  --color-bg: #f4f7f6;
  --color-surface: #ffffff;
  --color-surface-alt: #e3efe9;
  --color-text: #13212e;
  --color-text-muted: #5b6b78;
  --color-border: #d6e2dc;
  --color-success: #4c7a3f;
  --color-error: #b8423a;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.10);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.14);
  --header-height: 72px;
  --max-width: 1200px;
  --transition: all 0.2s ease;
  --font-ar: 'Cairo', 'Segoe UI', system-ui, sans-serif;
  --font-en: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

html[dir="rtl"] body { font-family: var(--font-ar); }
html[dir="ltr"] body { font-family: var(--font-en); }

body {
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

a { color: var(--color-primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--color-primary-dark); }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------------------------------------------------------------------
   Header / Navigation
   --------------------------------------------------------------------- */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 10px rgba(15, 23, 42, 0.07);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--header-height);
  flex-wrap: nowrap;
  max-width: 1440px;
}
.main-nav a { white-space: nowrap; }
.header-search { flex-shrink: 1; min-width: 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  color: var(--color-text);
  font-weight: 600;
  white-space: nowrap;
}
.brand:hover { color: var(--color-primary); }
.brand__icon { font-size: 1.6rem; }
.brand__logo { height: 40px; width: auto; max-width: 160px; object-fit: contain; flex-shrink: 0; }
.footer-brand .brand__logo { height: 32px; }
.brand strong { color: var(--color-primary); }

.main-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-inline-start: auto;
}
.main-nav a {
  color: var(--color-text);
  font-weight: 500;
  padding: 8px 4px;
}
.main-nav a:hover { color: var(--color-primary); }
.nav-admin-link {
  background: var(--color-primary);
  color: #fff !important;
  padding: 8px 16px !important;
  border-radius: var(--radius-sm);
}
.nav-admin-link:hover { background: var(--color-primary-dark); }

.lang-switch {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 12px !important;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary) !important;
}
.lang-switch:hover { border-color: var(--color-primary); background: var(--color-surface-alt); }

.header-search {
  display: flex;
  align-items: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.header-search input {
  border: none;
  background: transparent;
  padding: 10px 12px;
  width: 190px;
  min-width: 0;
  font-size: 0.9rem;
  outline: none;
}
.header-search button {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 8px 12px;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.nav-toggle:hover { background: var(--color-surface-alt); }
.nav-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
}

.main-nav a.is-active { color: var(--color-primary); font-weight: 700; }

/* Drawer-only pieces, hidden while the nav is a horizontal bar. */
.drawer-head,
.drawer-search,
.nav-overlay { display: none; }

.drawer-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.drawer-close:hover { background: var(--color-surface-alt); }

/* ---------------------------------------------------------------------
   Slide-in sidebar navigation (tablets & phones)
   --------------------------------------------------------------------- */
@media (max-width: 1280px) {
  .site-header__inner { flex-wrap: nowrap; gap: 12px; }
  .brand { min-width: 0; }
  .brand__text { overflow: hidden; text-overflow: ellipsis; }
  .nav-toggle { display: flex; }
  .header-search { margin-inline-start: auto; }
  .header-search input { min-width: 0; width: 200px; }

  .main-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: min(300px, 85vw);
    margin: 0;
    background: var(--color-surface);
    box-shadow: var(--shadow-md);
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 0 0 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 100;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0.25s ease;
  }
  html[dir="rtl"] .main-nav { transform: translateX(100%); }
  .main-nav.is-open,
  html[dir="rtl"] .main-nav.is-open { transform: none; visibility: visible; }

  .drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 12px 14px 20px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 8px;
  }
  html[dir="rtl"] .drawer-head { padding: 14px 20px 14px 12px; }

  .main-nav .nav-link {
    padding: 12px 20px;
    border-inline-start: 3px solid transparent;
  }
  .main-nav .nav-link:hover { background: var(--color-surface-alt); }
  .main-nav .nav-link.is-active {
    background: var(--color-surface-alt);
    border-inline-start-color: var(--color-accent);
  }
  .main-nav .nav-upload-link,
  .main-nav .nav-admin-link,
  .main-nav .lang-switch {
    margin: 8px 16px 0;
    text-align: center;
  }

  .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }
  .nav-overlay.is-visible { opacity: 1; visibility: visible; }
  body.nav-open { overflow: hidden; }
  /* The sticky header is its own stacking context, so lift it above the overlay while the drawer is open. */
  body.nav-open .site-header { z-index: 110; }
}

@media (max-width: 600px) {
  .header-search { display: none; }
  .nav-toggle { margin-inline-start: auto; }
  .drawer-search {
    display: flex;
    margin: 4px 16px 10px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
  }
  .drawer-search input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 10px 12px;
    outline: none;
  }
  .drawer-search button { border: none; background: transparent; padding: 8px 12px; cursor: pointer; }
}

/* ---------------------------------------------------------------------
   Flash messages
   --------------------------------------------------------------------- */
.flash-container { padding-top: 16px; }
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 0.95rem;
}
.alert--success { background: #e6f7ec; color: var(--color-success); border: 1px solid #b7e7c9; }
.alert--error { background: #fdecec; color: var(--color-error); border: 1px solid #f5c2c2; }
.alert--info { background: #eaf1ff; color: var(--color-primary-dark); border: 1px solid #c9d9ff; }

/* ---------------------------------------------------------------------
   Hero
   --------------------------------------------------------------------- */
.hero {
  position: relative;
  background:
    radial-gradient(circle at 18% 22%, color-mix(in srgb, var(--color-accent) 30%, transparent) 0%, transparent 45%),
    radial-gradient(circle at 82% 78%, color-mix(in srgb, var(--color-accent) 18%, transparent) 0%, transparent 42%),
    linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 55%, var(--color-deep) 100%);
  color: #fff;
  padding: 84px 0 76px;
  overflow: hidden;
  border-bottom: 3px solid var(--color-accent);
}
/* Subtle repeating "book spine" texture, drawn in CSS so there's no asset to load. */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0px,
    rgba(255, 255, 255, 0.05) 2px,
    transparent 2px,
    transparent 22px
  );
  opacity: 0.5;
  pointer-events: none;
}
.hero__inner { position: relative; z-index: 1; text-align: center; max-width: 760px; margin: 0 auto; }
.hero h1 {
  font-size: 2.7rem;
  margin: 0 0 14px;
  line-height: 1.25;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.hero p { font-size: 1.12rem; opacity: 0.94; margin: 0 0 30px; }
.hero .btn-accent { box-shadow: 0 6px 20px rgba(201, 151, 63, 0.35); }

.hero-search {
  display: flex;
  background: #fff;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.hero-search input {
  flex: 1;
  border: none;
  padding: 16px 20px;
  font-size: 1rem;
  outline: none;
}
.hero-search button {
  border: none;
  background: var(--color-accent);
  color: #1c2130;
  font-weight: 600;
  padding: 0 28px;
  cursor: pointer;
  transition: var(--transition);
}
.hero-search button:hover { filter: brightness(1.08); }

/* ---------------------------------------------------------------------
   Homepage slideshow (images designed at 1672×941)
   --------------------------------------------------------------------- */
/* Full-width slider. Exact image ratio so text baked into the artwork is never cropped. */
.slideshow__frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--color-deep);
}
.slideshow__track {
  display: flex;
  width: 100%;
  transition: transform 0.8s cubic-bezier(0.65, 0, 0.35, 1);
  will-change: transform;
}
.slide {
  flex: 0 0 100%;
  display: block;
  position: relative;
}
.slide img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1672 / 941;
  object-fit: cover;
}

.slideshow__btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.8);
  color: var(--color-deep);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  z-index: 2;
  opacity: 0.85;
}
.slideshow__frame:hover .slideshow__btn { opacity: 1; }
.slideshow__btn:hover { background: #fff; }
.slideshow__btn:focus-visible,
.slideshow__dot:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.slideshow__btn--prev { inset-inline-start: 20px; }
.slideshow__btn--next { inset-inline-end: 20px; }
.slideshow__btn span { display: inline-block; margin-top: -4px; }
html[dir="rtl"] .slideshow__btn span { transform: scaleX(-1); }

.slideshow__dots {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 2;
}
.slideshow__dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: var(--transition);
}
.slideshow__dot.is-active { background: var(--color-accent); border-color: var(--color-accent); width: 28px; }

@media (max-width: 600px) {
  .slideshow__btn { width: 34px; height: 34px; font-size: 1.4rem; }
  .slideshow__btn--prev { inset-inline-start: 8px; }
  .slideshow__btn--next { inset-inline-end: 8px; }
  .slideshow__dots { bottom: 8px; }
  .slideshow__dot { width: 8px; height: 8px; }
  .slideshow__dot.is-active { width: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .slideshow__track { transition: none; }
}

/* ---------------------------------------------------------------------
   Sections / headings
   --------------------------------------------------------------------- */
.section { padding: 48px 0; }
.section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
/* Gold accent rule under each section title, mirrored automatically in RTL. */
.section__header h2 {
  margin: 0;
  font-size: 1.5rem;
  position: relative;
  padding-bottom: 10px;
}
.section__header h2::after {
  content: "";
  position: absolute;
  bottom: 0;
  inset-inline-start: 0;
  width: 52px;
  height: 3px;
  background: var(--color-accent);
  border-radius: 2px;
}
.section__header .link-more { font-weight: 600; }

/* ---------------------------------------------------------------------
   Category chips
   --------------------------------------------------------------------- */
.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.category-chip {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 500;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}
.category-chip:hover { border-color: var(--color-primary); color: var(--color-primary); }
.category-chip .count { color: var(--color-text-muted); font-size: 0.85em; margin-inline-start: 4px; }

/* ---------------------------------------------------------------------
   Book grid & cards
   --------------------------------------------------------------------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px;
}

.book-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}
.book-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent);
}
.book-card__cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.28), transparent 55%);
  pointer-events: none;
}

.book-card__cover {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  background: #eef1f8;
  overflow: hidden;
}
.book-card__cover img { width: 100%; height: 100%; object-fit: cover; }
.book-card__badge {
  position: absolute;
  bottom: 8px;
  inset-inline-end: 8px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
}

.book-card__body { padding: 14px 16px 18px; flex: 1; display: flex; flex-direction: column; }
.book-card__category {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
  font-weight: 700;
  margin-bottom: 4px;
}
.book-card__title { margin: 0 0 4px; font-size: 1rem; line-height: 1.35; }
.book-card__title a { color: var(--color-text); }
.book-card__title a:hover { color: var(--color-primary); }
.book-card__author { margin: 0; color: var(--color-text-muted); font-size: 0.88rem; }
.book-card__meta {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.book-card__actions { margin-top: 12px; }
.book-card__actions .btn { width: 100%; justify-content: center; }

.star-rating {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  font-size: 0.85rem;
}
.star-rating .star { color: var(--color-border); }
.star-rating .star.is-filled { color: var(--color-accent); }
.star-rating__count { color: var(--color-text-muted); font-size: 0.78rem; margin-inline-start: 4px; }
.star-rating__count--empty { font-style: italic; }

.star-rating--form { gap: 6px; font-size: 1.6rem; cursor: pointer; }
.star-rating--form .star { transition: var(--transition); }
.star-rating--form label:hover ~ label .star,
.star-rating--form:hover .star { color: var(--color-border); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
}
.empty-state .icon { font-size: 2.5rem; display: block; margin-bottom: 12px; }

/* ---------------------------------------------------------------------
   Filters bar (books.php)
   --------------------------------------------------------------------- */
.filters-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 12px;
  margin-bottom: 28px;
  align-items: end;
}
.filters-bar label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text-muted);
}
.filters-bar input,
.filters-bar select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
}
.filters-bar button {
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}
.filters-bar button:hover { background: var(--color-primary-dark); }

/* ---------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------- */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 36px;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  min-width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 0.9rem;
  background: var(--color-surface);
}
.pagination a:hover { border-color: var(--color-primary); color: var(--color-primary); }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* ---------------------------------------------------------------------
   Book detail page
   --------------------------------------------------------------------- */
.book-detail {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 40px;
  align-items: start;
}
.book-detail__cover {
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: #eef1f8;
}
.book-detail__cover img { width: 100%; }

.book-detail__category {
  display: inline-block;
  background: #eaf1ff;
  color: var(--color-primary-dark);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.book-detail h1 { margin: 0 0 6px; font-size: 2rem; }
.book-detail__author { color: var(--color-text-muted); font-size: 1.05rem; margin: 0 0 20px; }

.book-detail__stats {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.book-detail__stats div {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.88rem;
  color: var(--color-text-muted);
}
.book-detail__stats strong { color: var(--color-text); display: block; font-size: 1.1rem; }

.book-detail__actions { display: flex; gap: 12px; margin-bottom: 28px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.95rem;
  transition: var(--transition);
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); color: #fff; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-accent { background: var(--color-accent); color: #1c2130; }
.btn-accent:hover { filter: brightness(1.08); }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:hover { background: #b83636; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.book-detail__meta-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 28px;
  font-size: 0.92rem;
}
.book-detail__meta-table td { padding: 8px 0; border-bottom: 1px solid var(--color-border); }
.book-detail__meta-table td:first-child { color: var(--color-text-muted); width: 160px; }

.book-detail__description h2,
.book-detail__video h2,
.book-detail__reader h2 { font-size: 1.15rem; margin: 0 0 12px; }

.video-embed {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
  margin-bottom: 32px;
}
.video-embed iframe,
.video-embed video {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.pdf-reader {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #525659;
}

/* ---------------------------------------------------------------------
   Videos grid (homepage + videos.php)
   --------------------------------------------------------------------- */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}
.video-tile { display: block; color: var(--color-text); }
.video-tile__thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow-sm);
}
.video-tile__thumb img { width: 100%; height: 100%; object-fit: cover; opacity: 0.85; }
.video-tile__play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: #fff;
  background: rgba(15, 23, 42, 0.25);
  transition: var(--transition);
}
.video-tile:hover .video-tile__play { background: rgba(15, 23, 42, 0.45); }
.video-tile__title { margin-top: 10px; font-weight: 600; font-size: 0.92rem; }

/* ---------------------------------------------------------------------
   Community teaser (homepage)
   --------------------------------------------------------------------- */
.community-teaser {
  background: var(--color-surface-alt);
  border-radius: var(--radius-lg);
  padding: 40px;
}
.community-teaser__inner {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 40px;
  align-items: center;
}
.community-teaser h2 { margin: 0 0 10px; }
.community-teaser p { color: var(--color-text-muted); margin: 0 0 20px; }
.community-teaser__stats { display: flex; gap: 28px; margin-bottom: 24px; flex-wrap: wrap; }
.community-teaser__stats strong { display: block; font-size: 1.5rem; color: var(--color-primary); }
.community-teaser__stats div { font-size: 0.85rem; color: var(--color-text-muted); }
.community-teaser__reviewers {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.community-teaser__reviewers h3 { margin: 0 0 14px; font-size: 1rem; }
.community-teaser__reviewers ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.community-teaser__reviewers li { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }

.avatar { border-radius: 50%; object-fit: cover; background: var(--color-surface-alt); }
.avatar--sm { width: 32px; height: 32px; }
.avatar--md { width: 48px; height: 48px; }
.avatar--lg { width: 88px; height: 88px; }

/* ---------------------------------------------------------------------
   Comment preview grid (homepage)
   --------------------------------------------------------------------- */
.comment-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.comment-preview {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--color-text);
}
.comment-preview:hover { border-color: var(--color-primary); }
.comment-preview__head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.comment-preview__head div { display: flex; flex-direction: column; font-size: 0.85rem; line-height: 1.3; }
.comment-preview p { margin: 0; font-size: 0.88rem; color: var(--color-text-muted); }

@media (max-width: 900px) {
  .community-teaser__inner { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------
   Novel summary
   --------------------------------------------------------------------- */
.novel-summary {
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  padding: 28px 32px;
  margin: 32px 0;
}
.novel-summary h2 { margin: 0 0 14px; font-size: 1.15rem; }
.novel-summary__body { line-height: 1.85; white-space: pre-line; }

/* ---------------------------------------------------------------------
   Rating widget
   --------------------------------------------------------------------- */
.rating-widget { margin: 0 0 32px; }
.rating-widget h2 { font-size: 1.15rem; margin: 0 0 12px; }
.rating-widget__form { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.rating-widget__form .star-rating--form { direction: ltr; }
.rating-widget__form label { cursor: pointer; }

/* ---------------------------------------------------------------------
   Comments section
   --------------------------------------------------------------------- */
.comments-section { margin-top: 8px; }
.comments-section h2 { font-size: 1.25rem; margin: 0 0 18px; }
.comment-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 28px; }
.comment-form textarea {
  width: 100%;
  min-height: 90px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
}
.comment-form .btn { align-self: flex-start; }

.comment-list { display: flex; flex-direction: column; gap: 22px; }
.comment { display: flex; gap: 12px; }
.comment__body { flex: 1; }
.comment__head { display: flex; align-items: baseline; gap: 10px; }
.comment__head strong { font-size: 0.95rem; }
.comment__date { font-size: 0.78rem; color: var(--color-text-muted); }
.comment__body p { margin: 4px 0 8px; }
.comment__actions { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.link-btn:hover { color: var(--color-primary); }
.link-btn.is-active { color: var(--color-primary); font-weight: 700; }
.comment__like-count { font-size: 0.85rem; color: var(--color-text-muted); }

.reply-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.reply-form textarea {
  width: 100%;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}
.reply-form__actions { display: flex; }

.reply-list { margin-top: 16px; padding-inline-start: 20px; border-inline-start: 2px solid var(--color-border); display: flex; flex-direction: column; gap: 16px; }
.comment--reply .comment__body p { font-size: 0.92rem; }

/* ---------------------------------------------------------------------
   Auth pages (login / register)
   --------------------------------------------------------------------- */
.auth-section { display: flex; justify-content: center; }
.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-sm);
}
.auth-card h1 { font-size: 1.4rem; margin: 0 0 20px; text-align: center; }
.auth-card form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 14px 0 6px;
}
.auth-card form input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
}
.auth-card form button { margin-top: 22px; }
.auth-card__switch { text-align: center; margin: 18px 0 0; font-size: 0.9rem; color: var(--color-text-muted); }

/* ---------------------------------------------------------------------
   Profile quick links
   --------------------------------------------------------------------- */
.profile-quicklinks { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

/* ---------------------------------------------------------------------
   Community page
   --------------------------------------------------------------------- */
.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
}
.member-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.member-card .avatar { margin-bottom: 6px; }

/* ---------------------------------------------------------------------
   Member documents
   --------------------------------------------------------------------- */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.doc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.doc-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--color-accent); }

.doc-card__icon {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.doc-card__body { flex: 1; min-width: 0; }
.doc-card__title { margin: 0 0 4px; font-size: 1rem; line-height: 1.35; }
.doc-card__title a { color: var(--color-text); }
.doc-card__title a:hover { color: var(--color-primary); }
.doc-card__desc { margin: 0 0 8px; font-size: 0.86rem; color: var(--color-text-muted); }
.doc-card__meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  flex-wrap: wrap;
}
.doc-card__author { margin-top: 6px; font-size: 0.8rem; color: var(--color-text-muted); }
.doc-card__actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }

.doc-chip {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
}

.doc-detail {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 36px;
  align-items: start;
}
.doc-detail h1 { margin: 8px 0 10px; font-size: 1.9rem; }
.doc-detail__byline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.doc-detail__image {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}
.doc-detail__filecard {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: calc(var(--header-height) + 20px);
}
.doc-detail__ext {
  background: var(--color-surface-alt);
  color: var(--color-primary);
  font-weight: 800;
  font-size: 1.4rem;
  text-align: center;
  padding: 20px 0;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  letter-spacing: 0.06em;
}
.doc-detail__filecard .book-detail__meta-table { margin-bottom: 18px; }

.nav-upload-link {
  background: var(--color-accent);
  color: var(--color-deep) !important;
  padding: 8px 14px !important;
  border-radius: var(--radius-sm);
  font-weight: 700;
}
.nav-upload-link:hover { filter: brightness(0.93); }

@media (max-width: 900px) {
  .doc-detail { grid-template-columns: 1fr; }
  .doc-detail__filecard { position: static; }
}

/* ---------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------- */
.site-footer {
  background: linear-gradient(135deg, var(--color-deep) 0%, var(--color-primary-dark) 100%);
  color: rgba(255, 255, 255, 0.78);
  margin-top: 60px;
  padding: 36px 0;
  border-top: 3px solid var(--color-accent);
}
.site-footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.footer-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: #fff; }
.site-footer p { margin: 0; font-size: 0.85rem; }
.footer-nav { display: flex; gap: 18px; }
.footer-nav a { color: rgba(255, 255, 255, 0.78); font-size: 0.88rem; }
.footer-nav a:hover { color: var(--color-accent); }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: clip; }
iframe, video { max-width: 100%; }
.comment__body p,
.comment-preview p,
.doc-card__title,
.doc-card__desc,
.book-card__title,
.book-detail h1,
.doc-detail h1,
.book-detail__meta-table td { overflow-wrap: anywhere; }

/* Grids never force a column wider than the screen on very small phones. */
.book-grid { grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); }
.video-grid { grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); }
.comment-preview-grid { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.member-grid { grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr)); }
.doc-grid { grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
.footer-nav { flex-wrap: wrap; }

@media (max-width: 900px) {
  .book-detail { grid-template-columns: 1fr; gap: 28px; }
  .book-detail__cover { max-width: 260px; margin: 0 auto; }
  .filters-bar { grid-template-columns: 1fr 1fr; }
  .filters-bar > :first-child { grid-column: 1 / -1; }
}

@media (max-width: 768px) {
  .hero { padding: 56px 0 48px; }
  .hero h1 { font-size: 1.8rem; }
  .hero p { font-size: 1rem; margin-bottom: 22px; }
  .section { padding: 32px 0; }
  .section__header h2 { font-size: 1.3rem; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
  .book-detail h1, .doc-detail h1 { font-size: 1.5rem; }
  .community-teaser { padding: 24px; }
  .community-teaser__inner { gap: 24px; }
  .novel-summary { padding: 20px; margin: 24px 0; }
  .pdf-reader { height: 70vh; }
  .site-footer__inner { flex-direction: column; text-align: center; }
  .footer-nav { justify-content: center; gap: 10px 16px; }
}

@media (max-width: 600px) {
  .filters-bar { grid-template-columns: 1fr; padding: 16px; }
  .hero-search input { padding: 14px 14px; }
  .hero-search button { padding: 0 16px; }
  .auth-card { padding: 28px 20px; }
  .book-detail__meta-table td:first-child { width: 40%; }
  .book-detail__actions .btn { flex: 1 1 100%; justify-content: center; }
  .doc-card { flex-wrap: wrap; }
  .doc-card__actions { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .reply-list { padding-inline-start: 12px; }
  .comment-form .btn { align-self: stretch; justify-content: center; }
  /* 16px stops iOS Safari from zooming into focused fields. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select,
  textarea { font-size: 16px !important; }
}

@media (max-width: 480px) {
  .container { padding: 0 16px; }
  .hero h1 { font-size: 1.55rem; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .book-card__body { padding: 10px 12px 14px; }
  .book-card__meta { flex-wrap: wrap; gap: 6px 12px; }
  .book-detail__stats { width: 100%; gap: 10px; }
  .book-detail__stats div { flex: 1 1 40%; }
  .community-teaser { padding: 18px; border-radius: var(--radius-md); }
  .community-teaser__stats { gap: 16px; }
  .btn { padding: 11px 16px; }
}
