/* ==========================================================================
   /catalogues — the catalogue library and the flipbook reader

   Everything scoped under `.cat`, per the house rule that page CSS never leaks
   globally. Logical properties throughout, so one set of rules serves fa (RTL)
   and en (LTR) — except inside the reader, where a few things are deliberately
   physical. Those are marked.
   ========================================================================== */

.cat {
  --cat-radius: 16px;
  --cat-shadow: 0 18px 44px rgba(14, 31, 39, 0.16);
}

/* ================================================================== head */

.cat-head {
  position: relative;
  background: linear-gradient(165deg, var(--c-primary-soft) 0%, var(--c-paper) 60%, var(--c-surface) 100%);
  border-block-end: 1px solid var(--c-line);
  padding-block: var(--s-12) var(--s-10);
  overflow: hidden;
}

/* There was a CSS-drawn graph-paper square in the corner here. It was removed
   on the user's call (2026-08-15): clipped to a hard 340px edge it read as an
   unfinished box rather than decoration — «یه grid خالیه». The gradient, the
   eyebrow chip and the green rule already carry this header; do not re-add it. */

.cat-head > .container {
  position: relative;
}

.cat-head__crumb {
  display: flex;
  gap: var(--s-2);
  font-size: var(--t-sm);
  color: var(--c-muted);
  margin-block-end: var(--s-6);
}
.cat-head__crumb a { color: var(--c-muted); }
.cat-head__crumb a:hover { color: var(--c-primary); }

.cat-head__eyebrow {
  display: inline-block;
  font-size: var(--t-sm);
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--c-primary-deep);
  background: #fff;
  padding: 4px var(--s-4);
  border-radius: 20px;
  margin: 0 0 var(--s-4);
}

.cat-head__title {
  font-size: var(--t-2xl);
  line-height: var(--lh-tight);
  color: var(--c-ink);
  margin: 0;
}

.cat-head__rule {
  display: block;
  inline-size: 56px;
  block-size: 3px;
  border-radius: 2px;
  background: var(--c-green);
  margin-block: var(--s-4) var(--s-5);
}

.cat-head__lede {
  max-inline-size: 60ch;
  font-size: var(--t-lg);
  line-height: var(--lh-snug);
  color: var(--c-body);
  margin: 0;
}

.cat-head__count {
  margin-block-start: var(--s-6);
  font-size: var(--t-sm);
  color: var(--c-muted);
}
.cat-head__count b {
  color: var(--c-ink);
  font-size: var(--t-lg);
  font-weight: 700;
}

/* ================================================================== tabs */

.cat-body {
  padding-block: var(--s-12) var(--sec-y);
}

.cat-tabs {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-block-end: var(--s-8);
  padding-block-end: var(--s-4);
  border-block-end: 1px solid var(--c-line);
}

.cat-tabs__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px var(--s-5);
  border: 1px solid var(--c-line);
  border-radius: 24px;
  background: var(--c-surface);
  color: var(--c-body);
  font: inherit;
  font-size: var(--t-sm);
  cursor: pointer;
  transition: border-color var(--dur-1, 0.15s), background-color var(--dur-1, 0.15s),
              color var(--dur-1, 0.15s);
}
.cat-tabs__btn:hover {
  border-color: var(--c-primary);
  color: var(--c-primary-deep);
}
.cat-tabs__btn.is-active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}
.cat-tabs__n {
  font-size: var(--t-xs);
  opacity: 0.72;
}

.cat-panel__title {
  font-size: var(--t-xl);
  color: var(--c-ink);
  margin: 0 0 var(--s-6);
}

/* ================================================================= grid */

.cat-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--s-6);
}

.cat-card {
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--cat-radius);
  overflow: hidden;
  transition: border-color var(--dur-1, 0.15s), box-shadow var(--dur-1, 0.15s),
              transform var(--dur-1, 0.15s);
}
.cat-card:hover {
  border-color: var(--c-line-strong);
  box-shadow: var(--shadow-1);
  transform: translateY(-2px);
}

.cat-card__face {
  display: block;
  color: inherit;
}
.cat-card__face:hover {
  text-decoration: none;
}

/* ⚠️ SQUARE, not portrait. Every one of the 18 covers is 1:1 (1080×1080 for
   most). A book-shaped 3/4 frame letterboxed all of them. Design to the data. */
.cat-card__shot {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  background: var(--c-wash);
  overflow: hidden;
}
.cat-card__shot img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--dur-2, 0.3s) ease;
}
.cat-card:hover .cat-card__shot img {
  transform: scale(1.04);
}
.cat-card__shot.is-empty {
  display: grid;
  place-items: center;
}
.cat-card__glyph {
  inline-size: 40px;
  block-size: 40px;
  color: var(--c-line-strong);
}

/* The "read it" affordance. Always present for touch (where there is no
   hover), lifted on hover for pointers. */
.cat-card__open {
  position: absolute;
  inset-block-end: var(--s-3);
  inset-inline-start: var(--s-3);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px var(--s-4);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--c-primary-deep);
  font-size: var(--t-xs);
  font-weight: 500;
  box-shadow: 0 2px 10px rgba(14, 31, 39, 0.18);
  transition: transform var(--dur-1, 0.15s), opacity var(--dur-1, 0.15s);
}
@media (hover: hover) {
  .cat-card__open {
    opacity: 0;
    transform: translateY(6px);
  }
  .cat-card:hover .cat-card__open,
  .cat-card__face:focus-visible .cat-card__open {
    opacity: 1;
    transform: none;
  }
}
.cat-card__openIcon {
  inline-size: 14px;
  block-size: 14px;
}

.cat-card__name {
  display: block;
  padding: var(--s-4) var(--s-5) 0;
  color: var(--c-ink);
  font-weight: 500;
  line-height: var(--lh-snug);
  font-size: var(--t-sm);
}
.cat-card__face:hover .cat-card__name {
  color: var(--c-primary-deep);
}

.cat-card__foot {
  margin: auto 0 0;
  padding: var(--s-3) var(--s-5) var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  font-size: var(--t-xs);
  color: var(--c-muted);
}

.cat-card__dl {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  color: var(--c-primary-deep);
  font-weight: 500;
  white-space: nowrap;
}
.cat-card__dlIcon {
  inline-size: 14px;
  block-size: 14px;
}

.cat-empty {
  color: var(--c-muted);
  padding-block: var(--s-16);
  text-align: center;
}

/* =============================================================== reader */

/* Set on <html> while the overlay is up. */
.cat-locked,
.cat-locked body {
  overflow: hidden;
}

.cat-reader {
  position: fixed;
  inset: 0;
  z-index: 200;   /* above the sticky header (100) and the search scrim (95) */
  display: grid;
  place-items: center;
  padding: clamp(8px, 2vw, 28px);
}
.cat-reader[hidden] {
  display: none;
}

.cat-reader__scrim {
  position: absolute;
  inset: 0;
  background: rgba(8, 20, 28, 0.86);
  backdrop-filter: blur(3px);
}

.cat-reader__shell {
  position: relative;
  inline-size: min(1500px, 100%);
  block-size: min(96vh, 100%);
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--c-band-deep);
  border-radius: var(--cat-radius);
  overflow: hidden;
  box-shadow: var(--cat-shadow);
}
/* In the browser's own fullscreen the rounded corners float on black. */
.cat-reader__shell:fullscreen {
  inline-size: 100%;
  block-size: 100%;
  border-radius: 0;
}

.cat-reader__bar {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: rgba(255, 255, 255, 0.06);
  border-block-end: 1px solid rgba(255, 255, 255, 0.1);
}

.cat-reader__title {
  margin: 0;
  margin-inline-end: auto;
  font-size: var(--t-sm);
  font-weight: 500;
  color: #fff;

  /* Long Persian catalogue names must not push the tools off the bar. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-inline-size: 0;
}

.cat-reader__tools {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  flex: none;
}

.cat-reader__tool {
  inline-size: 36px;
  block-size: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  transition: background-color var(--dur-1, 0.15s), color var(--dur-1, 0.15s);
}
.cat-reader__tool:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
}
.cat-reader__tool svg {
  inline-size: 18px;
  block-size: 18px;
}
.cat-reader__glyph {
  font-size: 17px;
  line-height: 1;
}
.cat-reader__tool--close:hover {
  background: rgba(168, 56, 42, 0.9);
}

/* ---- stage ---- */

.cat-reader__stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: var(--s-4);
  min-block-size: 0;   /* lets the 1fr row actually shrink */
}

.cat-book {
  /* StPageFlip sets inline width/height on this node; it must not be
     stretched by the grid or the leaves and the shadows disagree. */
  align-self: center;
  justify-self: center;
}

.cat-page {
  background: #fff;
  overflow: hidden;
}
.cat-page canvas {
  display: block;
  inline-size: 100%;
  block-size: 100%;
}

/* Pages render on demand, so a leaf you have not reached yet has an empty
   canvas over a white ground — indistinguishable from a broken reader. This
   placeholder is removed in renderPage() only once real pixels have landed. */
.cat-page.is-loading {
  background:
    linear-gradient(100deg, #f4f6f7 30%, #e9edef 48%, #f4f6f7 66%) 0 0 / 300% 100%,
    #fff;
  animation: cat-sheen 1.3s ease-in-out infinite;
}
@keyframes cat-sheen {
  from { background-position: 150% 0; }
  to   { background-position: -50% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .cat-page.is-loading {
    animation: none;
    background: #f4f6f7;
  }
}

/* ---- loading / error ---- */

.cat-reader__state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s-4);
  text-align: center;
  padding: var(--s-6);
  color: rgba(255, 255, 255, 0.82);
  background: var(--c-band-deep);
}
.cat-reader__state[hidden] {
  display: none;
}

.cat-reader__spinner {
  inline-size: 34px;
  block-size: 34px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-block-start-color: var(--c-green);
  border-radius: 50%;
  animation: cat-spin 0.8s linear infinite;
}
@keyframes cat-spin {
  to { transform: rotate(360deg); }
}

.cat-reader__errTitle {
  color: #fff;
  font-size: var(--t-lg);
  margin: 0;
}
.cat-reader__errText {
  margin: 0;
  color: rgba(255, 255, 255, 0.7);
}

/* ---- foot ---- */

.cat-reader__foot {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
  justify-content: center;
  padding: var(--s-3) var(--s-4);
  background: rgba(255, 255, 255, 0.06);
  border-block-start: 1px solid rgba(255, 255, 255, 0.1);
}

.cat-reader__nav {
  display: flex;
  align-items: center;
  gap: var(--s-2);

  /* ⚠️ PHYSICAL on purpose. « ‹ › » is a spatial control, and the buttons must
     keep their left-to-right arrangement in both locales — the JS decides which
     one advances the book. Mirroring the row would move the glyphs without
     changing their meaning, which is the worst of both. */
  direction: ltr;
}

.cat-reader__step {
  inline-size: 34px;
  block-size: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--dur-1, 0.15s);
}
.cat-reader__step:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.cat-reader__count {
  min-inline-size: 11ch;
  text-align: center;
  font-size: var(--t-sm);
  color: rgba(255, 255, 255, 0.82);

  /* The label itself is prose ("صفحه ۲ از ۲۴") and belongs to the page's
     direction, even though the button row around it is forced LTR. */
  direction: rtl;
}
[dir="ltr"] .cat-reader__count {
  direction: ltr;
}

.cat-reader__hint {
  margin: 0;
  font-size: var(--t-xs);
  color: rgba(255, 255, 255, 0.5);
}

/* ============================================================ responsive */

@media (max-width: 900px) {
  .cat-head__title { font-size: var(--t-xl); }
  .cat-head__lede  { font-size: var(--t-md); }
}

@media (max-width: 760px) {
  .cat-tabs {
    flex-wrap: nowrap;
    gap: var(--s-2);
  }
  .cat-tabs__btn {
    flex: 1 1 0;
    min-inline-size: 0;
    justify-content: center;
    padding: 9px var(--s-2);
    font-size: var(--t-xs);
    white-space: nowrap;
  }
  .cat-tabs__n {
    display: none;
  }
  .cat-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--s-4);
  }
  .cat-reader__shell {
    block-size: 100%;
    border-radius: 0;
  }
  .cat-reader {
    padding: 0;
  }
  /* Zoom and fullscreen are pointer-and-desktop affordances; on a phone the
     book already fills the screen and the bar needs the room for the title. */
  .cat-reader__tool[data-reader-zoom],
  .cat-reader__tool[data-reader-full] {
    display: none;
  }
  .cat-reader__hint {
    display: none;
  }
}

@media (max-width: 380px) {
  .cat-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cat-card,
  .cat-card__shot img,
  .cat-card__open {
    transition: none;
  }
  .cat-card:hover {
    transform: none;
  }
  .cat-card:hover .cat-card__shot img {
    transform: none;
  }
  .cat-reader__spinner {
    animation-duration: 2s;
  }
}

/* ---- justified body copy · centred blocks keep their centring ------------
   The `:where(p, blockquote, dd)` rule in hitco.css declares alignment ON the
   paragraph, and a direct declaration outranks the `text-align: center` these
   containers pass DOWN to it by inheritance. Re-inheriting restores them.
   Add a centred container that holds a paragraph and it belongs in this list. */
.cat-empty :where(p, blockquote, dd),
.cat-reader__state :where(p, blockquote, dd) {
  text-align: inherit;
}
