/* ------------------------------------------------------------------
   SĪRA — category listings & article pages.
   Extends the tokens in global.css; loaded by CategoryLayout / ArticleLayout.
   ------------------------------------------------------------------ */

:root {
  --measure: 42rem; /* comfortable reading width for article prose */
}

/* ============================== Category band ============================== */

.band {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--paper-hair);
  padding: 2.4rem var(--gutter) 2.2rem;
}
.band__inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 5.5rem 1fr auto;
  align-items: center;
  gap: 1.6rem;
}
.band__numeral {
  font-family: var(--arabic);
  font-size: 3.4rem;
  line-height: 1;
  color: var(--numeral);
  text-align: center;
}
.band__head {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.band__title {
  font-size: clamp(2rem, 4vw, 2.9rem);
  font-weight: 500;
  line-height: 1.05;
}
.band__arabic {
  font-family: var(--arabic);
  font-size: 1.5rem;
  color: var(--green);
}
.band__blurb {
  margin-top: 0.5rem;
  color: var(--brown);
  max-width: 34rem;
}
.band__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
  color: var(--brown-soft);
  white-space: nowrap;
}
.band__back { color: var(--brown-soft); }
.band__back:hover { color: var(--green); }

/* The category's Arabic name, oversized and faint, as a ground for the band. */
.band__watermark {
  position: absolute;
  right: calc(var(--gutter) - 0.5rem);
  top: 50%;
  transform: translateY(-46%);
  font-family: var(--arabic);
  font-size: 11rem;
  line-height: 1;
  color: var(--numeral);
  opacity: 0.34;
  pointer-events: none;
  user-select: none;
}

@media (max-width: 760px) {
  .band__inner {
    grid-template-columns: 3.25rem 1fr;
  }
  .band__meta {
    grid-column: 2;
    align-items: flex-start;
  }
  .band__numeral { font-size: 2.4rem; align-self: start; }
  .band__watermark { display: none; }
}

/* ================================ Filter bar =============================== */

.filterbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1.5rem;
  padding: 0.75rem var(--gutter);
  border-bottom: 1px solid var(--paper-hair);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
}
/* Two blocks: the chips grow, the controls stay together and wrap as one. */
.filterbar__facets {
  flex: 1 1 20rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.9rem;
}
.filterbar__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.filterbar__controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
}

.chip {
  font-family: var(--serif);
  font-size: 0.76rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--brown);
  background: transparent;
  border: 1px solid var(--paper-hair);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--green-soft); color: var(--ink); }
.chip[aria-pressed='true'] {
  background: var(--green);
  border-color: var(--green);
  color: var(--paper);
}

.sorts {
  display: flex;
  border: 1px solid var(--paper-hair);
  border-radius: 999px;
  overflow: hidden;
}
.sort {
  font-family: var(--serif);
  font-size: 0.76rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--brown);
  background: transparent;
  border: 0;
  border-right: 1px solid var(--paper-hair);
  padding: 0.34rem 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.sort:last-child { border-right: 0; }
.sort[aria-pressed='true'] { background: var(--green); color: var(--paper); }

.findbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 12rem;
  padding: 0.32rem 0.8rem;
  border: 1px solid var(--paper-hair);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
}
.findbox:focus-within { border-color: var(--green); }
.findbox input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink);
}
.findbox input::placeholder { color: var(--brown-soft); opacity: 1; }
.findbox--wide { flex: 1 1 auto; min-width: 0; padding: 0.45rem 1rem; }
.findbox--wide input { font-size: 1.05rem; }

/* Search hits reuse the register row; the highlight marks the matched span. */
.view mark {
  background: rgba(118, 102, 52, 0.18);
  color: inherit;
  border-radius: 2px;
}

.counter {
  font-size: 0.76rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--brown-soft);
  white-space: nowrap;
}
.reset {
  font-size: 0.76rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--green);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.reset[hidden] { display: none; }

/* ================================ Jump rail =============================== */

/* On a phone the chip block is taller than the screen, so it stops being sticky
   and the chips become one horizontally scrollable row. */
@media (max-width: 760px) {
  .filterbar {
    position: static;
    backdrop-filter: none;
  }
  .filterbar__facets {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 0.15rem;
  }
  .filterbar__facets::-webkit-scrollbar { display: none; }
  .filterbar__group { flex-wrap: nowrap; }
  .filterbar__controls { flex: 1 1 100%; }
  .findbox { flex: 1 1 8rem; min-width: 0; }
}

.rail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.55rem;
  padding: 0.6rem var(--gutter);
  border-bottom: 1px solid var(--paper-hair);
}
.rail a {
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--brown-soft);
  padding: 0.1rem 0.28rem;
}
.rail a:hover { color: var(--green); }
.rail a[data-empty='true'] { opacity: 0.32; pointer-events: none; }

/* ================================== Lists ================================= */

.listing { padding-bottom: 3rem; }
.view[hidden] { display: none; }

.group { scroll-margin-top: 5.5rem; }
.group[hidden] { display: none; }
.group__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 1rem;
  padding: 1.9rem var(--gutter) 0.55rem;
}
.group__label {
  font-family: var(--arabic);
  font-size: 1.9rem;
  line-height: 1;
  color: var(--numeral);
}
.group__label--latin {
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 500;
  color: var(--brown-soft);
}
.group__note {
  font-size: 0.74rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brown-soft);
}
.group__rule {
  flex: 1;
  height: 1px;
  background: var(--paper-hair);
}

/* Register row — the encyclopedia line */
.entry {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 0.4rem 1.5rem;
  padding: 0.85rem var(--gutter);
  border-bottom: 1px solid var(--paper-hair);
}
.entry[hidden] { display: none; }
.entry:hover { background: rgba(47, 107, 87, 0.045); }
.entry__title {
  grid-column: 1;
  font-size: 1.22rem;
  font-weight: 500;
  color: var(--ink);
}
.entry:hover .entry__title { color: var(--green); }
.entry__blurb {
  grid-column: 1;
  color: var(--brown);
  font-size: 0.99rem;
  line-height: 1.5;
  max-width: 52rem;
}
.entry__meta {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  color: var(--brown-soft);
  white-space: nowrap;
}
.entry__date { font-size: 0.95rem; }
.entry__links {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brown-soft);
  opacity: 0.8;
}
.entry__arrow { color: var(--brown-soft); }
.entry:hover .entry__arrow { color: var(--green); }

/* Chronicle — the date rail on the left */
.entry--chronicle {
  grid-template-columns: 8.5rem 1fr auto;
}
.entry--chronicle .entry__title { grid-column: 2; }
.entry--chronicle .entry__rail {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: start;
  text-align: right;
  padding-top: 0.15rem;
  border-right: 1px solid var(--paper-hair);
  padding-right: 1rem;
  margin-right: 0.4rem;
  min-height: 2.6rem;
}
.entry--chronicle .entry__hijri {
  display: block;
  font-size: 1rem;
  color: var(--brown);
}
.entry--chronicle .entry__ce {
  display: block;
  font-size: 0.82rem;
  color: var(--brown-soft);
}
.entry--chronicle .entry__blurb { grid-column: 2; }
.entry--chronicle .entry__meta { grid-column: 3; }

/* Timeline rows are not links themselves — the links live inside the sentence. */
.entry--static { cursor: default; }
.entry--static:hover { background: rgba(47, 107, 87, 0.03); }
.entry__event {
  grid-column: 2;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.55;
  max-width: 58rem;
}
.entry__event .wikilink { color: var(--green); }
.entry__event strong { font-weight: 600; color: var(--ink); }

/* A vault note that belongs to the page rather than to any one entry. */
.pagenote {
  padding: 1.5rem var(--gutter);
  color: var(--brown);
  max-width: 52rem;
  line-height: 1.6;
}
.pagenote--foot {
  padding-top: 2.5rem;
  color: var(--brown-soft);
  font-size: 0.95rem;
}
.pagenote__sources {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--brown-soft);
}
.pagenote p + p { margin-top: 0.6rem; }

/* Series — summaries in reading order */
.entry--series { grid-template-columns: 3.5rem 1fr auto; }
.entry--series .entry__title { grid-column: 2; }
.entry--series .entry__numeral {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: center;
  font-family: var(--arabic);
  font-size: 1.9rem;
  line-height: 1;
  color: var(--numeral);
  text-align: center;
}
.entry--series .entry__blurb { grid-column: 2; }
.entry--series .entry__meta { grid-column: 3; }

@media (max-width: 640px) {
  .entry,
  .entry--chronicle,
  .entry--series {
    grid-template-columns: 1fr;
  }
  /* every child back into the single column, or the explicit grid-column values
     above would conjure implicit columns and re-create the desktop layout */
  .entry > *,
  .entry--chronicle .entry__title,
  .entry--chronicle .entry__meta,
  .entry--chronicle .entry__rail,
  .entry--series .entry__title,
  .entry--series .entry__meta,
  .entry--series .entry__numeral {
    grid-column: 1;
  }
  .entry__meta {
    grid-row: auto;
    grid-column: 1;
    justify-content: flex-start;
    gap: 0.9rem;
  }
  .entry__arrow { display: none; }
  .entry--chronicle .entry__rail {
    grid-row: auto;
    text-align: left;
    border-right: 0;
    padding: 0;
    margin: 0;
    min-height: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0 0.6rem;
    align-items: baseline;
  }
  .entry--chronicle .entry__blurb,
  .entry--series .entry__blurb { grid-column: 1; }
  .entry--series .entry__numeral { grid-row: auto; grid-column: 1; text-align: left; }
}

/* ================================== Cards ================================= */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: 1px;
  background: var(--paper-hair);
  border-bottom: 1px solid var(--paper-hair);
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1.5rem var(--gutter);
  background: var(--paper);
}
.card[hidden] { display: none; }
.card:hover { background: rgba(47, 107, 87, 0.045); }
.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.card__head .entry__links { white-space: nowrap; }
.card__title {
  font-size: 1.3rem;
  font-weight: 500;
}
.card:hover .card__title { color: var(--green); }
.card__blurb {
  color: var(--brown);
  font-size: 0.99rem;
  line-height: 1.5;
}
.card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.5rem;
}
.tagpill {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brown-soft);
  border: 1px solid var(--paper-hair);
  border-radius: 999px;
  padding: 0.16rem 0.6rem;
}
.card__links {
  font-size: 0.9rem;
  color: var(--brown-soft);
  line-height: 1.5;
}
.card__links a { color: var(--green); }
.card__links a:hover { box-shadow: inset 0 -1px 0 var(--green); }

/* ================================= Empty ================================== */

.empty {
  padding: 3.5rem var(--gutter);
  color: var(--brown-soft);
  font-style: italic;
}
.empty[hidden] { display: none; }

/* ================================= Article ================================ */

.article {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 17rem;
  gap: 0 3.5rem;
  align-items: start;
  padding: 0 var(--gutter) 4rem;
  max-width: 78rem;
  margin: 0 auto;
}
.article__head {
  grid-column: 1 / -1;
  padding: 2.6rem 0 1.4rem;
  border-bottom: 1px solid var(--paper-hair);
  margin-bottom: 2rem;
}
.crumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--brown-soft);
  margin-bottom: 0.9rem;
}
.crumbs a { color: var(--brown-soft); }
.crumbs a:hover { color: var(--green); }
.article__title {
  font-size: clamp(2.1rem, 4.4vw, 3.1rem);
  font-weight: 500;
  line-height: 1.06;
}
.article__blurb {
  margin-top: 0.85rem;
  font-style: italic;
  color: var(--green);
  font-size: 1.18rem;
  max-width: var(--measure);
}
.article__dates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 1.15rem;
  color: var(--brown-soft);
}
.article__dates span { display: inline-flex; gap: 0.5rem; align-items: baseline; }
.article__dates b { font-weight: 500; color: var(--brown); }

/* Prose */
.prose {
  grid-column: 1;
  max-width: var(--measure);
  color: var(--ink-soft);
  font-size: 1.06rem;
  line-height: 1.68;
}
.prose > * + * { margin-top: 1.05rem; }
.prose h2 {
  margin-top: 2.6rem;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--ink);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--paper-hair);
  scroll-margin-top: 1.5rem;
}
.prose h3 {
  margin-top: 1.9rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--ink);
  scroll-margin-top: 1.5rem;
}
.prose strong { font-weight: 600; color: var(--ink); }
.prose em { color: inherit; }
.prose ul,
.prose ol { padding-left: 1.35rem; }
.prose li + li { margin-top: 0.5rem; }
.prose li::marker { color: var(--numeral); }
.prose blockquote {
  border-left: 2px solid var(--green);
  padding-left: 1.1rem;
  color: var(--brown);
  font-style: italic;
}
.prose hr {
  border: 0;
  border-top: 1px solid var(--paper-hair);
  margin: 2.2rem 0;
}
.prose code {
  font-size: 0.92em;
  background: rgba(138, 124, 96, 0.12);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
/* The timeline is a three-column table; the reading measure would crush it. */
.article--wide .prose { max-width: none; }
/* Keep the Hijri and CE columns on one line so the event text gets the room. */
.article--wide .prose td:nth-child(-n + 2),
.article--wide .prose th:nth-child(-n + 2) { white-space: nowrap; }

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.97rem;
}
/* Wide tables scroll inside themselves rather than pushing the page sideways. */
@media (max-width: 720px) {
  .prose table {
    display: block;
    overflow-x: auto;
    white-space: normal;
  }
}
.prose thead th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brown-soft);
  font-weight: 500;
  padding: 0 0.7rem 0.5rem 0;
  border-bottom: 1px solid var(--paper-hair);
}
.prose tbody td {
  vertical-align: top;
  padding: 0.6rem 0.7rem 0.6rem 0;
  border-bottom: 1px solid var(--paper-hair);
}
.prose tbody tr:hover { background: rgba(47, 107, 87, 0.045); }

/* Cross-reference links inside prose */
.wikilink {
  color: var(--green);
  box-shadow: inset 0 -1px 0 rgba(22, 76, 69, 0.28);
}
.wikilink:hover { box-shadow: inset 0 -1px 0 var(--green); }
.wikilink--dead {
  color: var(--brown-soft);
  box-shadow: none;
  border-bottom: 1px dotted var(--brown-soft);
  cursor: help;
}
.prose a:not(.wikilink) {
  color: var(--green);
  box-shadow: inset 0 -1px 0 rgba(22, 76, 69, 0.28);
}

/* Sidebar */
.aside {
  grid-column: 2;
  position: sticky;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  font-size: 0.95rem;
}
.aside__block { display: flex; flex-direction: column; gap: 0.55rem; }
.aside__title {
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brown-soft);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--paper-hair);
}
.aside__list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 22rem;
  overflow-y: auto;
}
.aside__list a { color: var(--brown); line-height: 1.35; }
.aside__list a:hover { color: var(--green); }
.aside__tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.aside__note { color: var(--brown-soft); font-size: 0.88rem; }

@media (max-width: 980px) {
  .article {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  .prose { grid-column: 1; }
  .aside {
    grid-column: 1;
    position: static;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--paper-hair);
  }
  .aside__list { max-height: none; }
}

/* Backlinks — the inbound half of the cross-reference web */
.backlinks {
  padding: 2.5rem var(--gutter) 3.5rem;
  border-top: 1px solid var(--paper-hair);
  max-width: 78rem;
  margin: 0 auto;
}
.backlinks__head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.1rem;
}
.backlinks__title {
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brown-soft);
}
.backlinks__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.5rem 1.6rem;
}
.backlinks__list a {
  color: var(--brown);
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  line-height: 1.4;
}
.backlinks__list a:hover { color: var(--green); }
.backlinks__kind {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--numeral);
  flex: none;
}
