/* ==========================================================================
   Library index (library.html, i18n/<lang>/library.html)

   Loaded after site.css. Page top on a dotted background (breadcrumb, title,
   search, category pills), the featured article, then the article grid.
   Phones: articles are list rows with a square thumbnail; from 768px they
   are cards, two then three across. js/library.js filters them.
   ========================================================================== */

.lib-feature[hidden],
.lib-grid[hidden],
.lib-card[hidden],
.lib-empty[hidden] {
  display: none;
}

/* ---------- Page top ---------- */

.lib-top {
  border-bottom: 1px solid var(--line);
  background-color: var(--bg-alt);
  background-image: radial-gradient(rgba(var(--gold-rgb), 0.13) 1px, transparent 1px);
  background-size: 18px 18px;
}

.lib-top__inner {
  padding-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lib-top__row,
.lib-top__heading {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lib-top__title {
  font-size: 36px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lib-top__lead {
  max-width: 600px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-5);
}

.lib-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid rgba(var(--gold-rgb), 0.28);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-6);
  transition: border-color 0.2s ease;
}

.lib-search:focus-within {
  border-color: rgba(var(--gold-rgb), 0.6);
}

.lib-search svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.lib-search input {
  flex-grow: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px keeps phones from zooming in on focus */
}

.lib-search input::placeholder {
  color: var(--text-6);
}

.lib-search input::-webkit-search-cancel-button {
  filter: sepia(1) saturate(2) hue-rotate(5deg);
}

.lib-kbd {
  min-width: 20px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(var(--gold-rgb), 0.3);
  border-radius: 5px;
  color: var(--text-5);
  font-family: var(--mono);
  font-size: 11px;
}

.lib-search .lib-kbd {
  display: none;
}

/* Pills: one row that scrolls sideways on phones. */
.lib-top__filters {
  margin-inline: calc(var(--pad) * -1);
}

.lib-pills {
  display: flex;
  gap: 8px;
  padding: 0 var(--pad) 22px;
  overflow-x: auto;
  scrollbar-width: none;
}

.lib-pills::-webkit-scrollbar {
  display: none;
}

.lib-pill {
  flex-shrink: 0;
  height: 38px;
  padding-block: 0;
  padding-inline: 16px 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(var(--gold-rgb), 0.3);
  border-radius: 19px;
  background: rgba(10, 9, 6, 0.6);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.lib-pill:hover {
  border-color: rgba(var(--gold-rgb), 0.6);
}

.lib-pill[aria-pressed="true"] {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
}

.lib-pill__n {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-6);
}

.lib-pill[aria-pressed="true"] .lib-pill__n {
  color: rgba(10, 9, 6, 0.62);
}

.lib-hint {
  display: none;
}

@media (min-width: 768px) {
  .lib-top__inner {
    padding-top: 44px;
  }

  .lib-top__title {
    font-size: 44px;
  }

  .lib-top__lead {
    font-size: 17px;
  }
}

@media (min-width: 992px) {
  .lib-top__inner {
    padding-top: 52px;
    gap: 32px;
  }

  .lib-top__row {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 48px;
  }

  .lib-top__title {
    font-size: 48px;
    letter-spacing: -0.025em;
  }

  .lib-search {
    flex-shrink: 0;
    width: 380px;
    padding: 0 14px;
  }

  .lib-search input {
    font-size: 14px;
  }

  .lib-search .lib-kbd {
    display: inline-flex;
  }

  .lib-top__filters {
    margin-inline: 0;
    padding-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }

  .lib-pills {
    padding: 0;
    overflow: visible;
    flex-wrap: wrap;
  }

  .lib-pill {
    padding-inline: 18px 16px;
    gap: 8px;
  }

  .lib-hint {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-6);
  }
}

/* ---------- Main ---------- */

.lib-main {
  padding-top: 22px;
  padding-bottom: 44px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Category: an outlined chip on phones, gold capitals on cards. */
.lib-cat {
  align-self: flex-start;
  height: 22px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(var(--gold-rgb), 0.35);
  border-radius: 11px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 500;
}

.lib-badge {
  height: 24px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  border-radius: 12px;
  background: var(--gold);
  color: var(--bg);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* Featured article */
.lib-feature {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(var(--gold-rgb), 0.2);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.lib-feature__media {
  height: 170px;
  overflow: hidden;
  background: var(--surface-hi);
}

.lib-feature__media img,
.lib-card__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.lib-feature__body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lib-feature__tags {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lib-feature__title {
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
}

.lib-feature__excerpt,
.lib-feature__cta {
  display: none;
}

.lib-feature__meta,
.lib-card__meta {
  font-size: 12px;
  color: var(--text-6);
}

/* Section label and count */
.lib-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0 10px;
  border-bottom: 1px solid rgba(var(--gold-rgb), 0.18);
}

.lib-head__label {
  font-size: 16px;
  font-weight: 600;
}

.lib-head__count {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-6);
}

/* Articles: list rows on phones */
.lib-grid {
  display: flex;
  flex-direction: column;
  margin-top: -8px;
}

.lib-card__link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  grid-template-areas: "body media";
  gap: 14px;
  align-items: start;
  padding: 18px 0;
  border-bottom: 1px solid rgba(var(--gold-rgb), 0.12);
  color: var(--text);
}

.lib-card__media {
  grid-area: media;
  width: 84px;
  height: 84px;
  overflow: hidden;
  border: 1px solid rgba(var(--gold-rgb), 0.14);
  border-radius: 10px;
  background: var(--surface-hi);
}

.lib-card__body {
  grid-area: body;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.lib-card__title {
  font-size: 16px;
  line-height: 1.4;
  font-weight: 600;
}

.lib-card__excerpt {
  display: none;
}

.lib-card.is-soon .lib-card__media img {
  opacity: 0.55;
}

.lib-card.is-soon .lib-card__meta {
  color: var(--gold);
  font-weight: 500;
}

/* Hover: lift and zoom (cards that link only) */
.lib-feature:hover img,
a.lib-card__link:hover img {
  transform: scale(1.03);
}

.lib-feature:focus-visible,
a.lib-card__link:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* Empty state */
.lib-empty {
  padding: 36px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  border: 1px dashed rgba(var(--gold-rgb), 0.3);
  border-radius: 14px;
  text-align: center;
}

.lib-empty__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.lib-empty__text {
  max-width: 420px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-5);
}

.lib-empty__btn {
  height: 40px;
  padding: 0 18px;
  border: 1px solid rgba(var(--gold-rgb), 0.45);
  border-radius: 20px;
  background: transparent;
  color: var(--gold-hi);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.lib-empty__btn:hover {
  border-color: var(--gold);
}

/* ---------- Tablet: cards ---------- */

@media (min-width: 768px) {
  .lib-main {
    padding-top: 40px;
    padding-bottom: 72px;
    gap: 28px;
  }

  .lib-feature__media {
    height: 300px;
  }

  .lib-feature__body {
    padding: 28px;
    gap: 14px;
  }

  .lib-feature__title {
    font-size: 26px;
    line-height: 1.22;
  }

  .lib-feature__excerpt {
    display: block;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-4);
  }

  .lib-feature__meta {
    font-size: 13px;
  }

  .lib-feature__cta {
    align-self: flex-start;
    margin-top: 8px;
    height: 44px;
    padding: 0 22px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(var(--gold-rgb), 0.5);
    border-radius: 22px;
    color: var(--gold-hi);
    font-size: 14px;
    font-weight: 500;
    transition: border-color 0.2s ease;
  }

  .lib-feature:hover {
    border-color: rgba(var(--gold-rgb), 0.45);
    transform: translateY(-2px);
  }

  .lib-feature:hover .lib-feature__cta {
    border-color: var(--gold);
  }

  .lib-cat {
    height: auto;
    padding: 0;
    border: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }

  .lib-head {
    padding: 0 0 14px;
    border-bottom-color: var(--line);
  }

  .lib-head__label {
    font-size: 20px;
  }

  .lib-head__count {
    font-size: 13px;
  }

  .lib-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    margin-top: 0;
  }

  .lib-card {
    display: flex;
  }

  .lib-card__link {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(var(--gold-rgb), 0.16);
    border-radius: 14px;
    background: #0E0D0A;
    transition: border-color 0.2s ease, transform 0.2s ease;
  }

  a.lib-card__link:hover {
    border-color: rgba(var(--gold-rgb), 0.45);
    transform: translateY(-2px);
  }

  .lib-card__media {
    width: auto;
    height: auto;
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: 0;
  }

  .lib-card__body {
    flex-grow: 1;
    padding: 20px 22px 22px;
    gap: 10px;
  }

  .lib-card__title {
    font-size: 19px;
    line-height: 1.35;
  }

  .lib-card__excerpt {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-5);
  }

  .lib-card__meta {
    margin-top: auto;
    padding-top: 8px;
  }

  .lib-empty {
    padding: 56px 24px;
  }
}

/* ---------- Desktop ---------- */

@media (min-width: 992px) {
  .lib-main {
    padding-top: 48px;
    padding-bottom: 88px;
    gap: 36px;
  }

  .lib-feature {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    border-radius: 18px;
  }

  /* The image fills the card's full height beside the text (no gap
     beneath it), cropped to cover. */
  .lib-feature__media {
    position: relative;
    height: auto;
    min-height: 420px;
  }

  .lib-feature__media img {
    position: absolute;
    inset: 0;
  }

  .lib-feature__body {
    padding: 44px;
    justify-content: center;
    gap: 16px;
  }

  .lib-feature__tags {
    gap: 12px;
  }

  .lib-feature__title {
    font-size: 32px;
    line-height: 1.2;
    letter-spacing: -0.015em;
    text-wrap: balance;
  }

  .lib-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lib-card__title {
    text-wrap: pretty;
  }
}

@media (min-width: 992px) and (max-width: 1199px) {
  .lib-feature__media {
    min-height: 360px;
  }

  .lib-feature__body {
    padding: 32px;
  }

  .lib-feature__title {
    font-size: 26px;
  }
}

/* ---------- Arabic ---------- */

/* Arabic has no capitals to carry the small labels; set them larger. */
:lang(ar) .lib-cat,
:lang(ar) .lib-badge {
  font-size: 12px;
}

@media (min-width: 768px) {
  :lang(ar) .lib-cat {
    font-size: 13px;
  }
}
