:root {
  --ink: #1c2118;
  --ink-soft: #3d4536;
  --muted: #6d7564;
  --paper: #f2f0ea;
  --paper-2: #e7e4db;
  --white: #fffcf7;
  --olive: #5f6a48;
  --olive-deep: #3f4730;
  --ochre: #b8923f;
  --ochre-deep: #8f6f2c;
  --mist: rgba(95, 106, 72, 0.1);
  --line: rgba(28, 33, 24, 0.1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --max: 1180px;
  --display: "Syne", "Cairo", sans-serif;
  --arabic: "Cairo", "Segoe UI", sans-serif;
  --serif: "Literata", "Amiri", serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--arabic);
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.65), transparent 28%),
    repeating-linear-gradient(
      -12deg,
      transparent,
      transparent 48px,
      rgba(95, 106, 72, 0.03) 48px,
      rgba(95, 106, 72, 0.03) 49px
    ),
    radial-gradient(ellipse 80% 50% at 100% 0%, rgba(184, 146, 63, 0.14), transparent 55%),
    radial-gradient(ellipse 60% 40% at 0% 80%, rgba(95, 106, 72, 0.12), transparent 50%),
    var(--paper);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

a { color: inherit; text-decoration: none; }

.wrap {
  width: min(100% - 1.5rem, var(--max));
  margin-inline: auto;
}

/* —— Hero logo (centered, transparent PNG) —— */
.hero-logo {
  display: block;
  width: min(82vw, 480px);
  max-width: 100%;
  margin: 0 auto 1.75rem;
  animation:
    logoIn 1.1s var(--ease) both,
    logoFloat 6s ease-in-out 1.1s infinite;
}

.hero-logo img {
  width: 100%;
  height: auto;
  background: transparent !important;
  mix-blend-mode: normal;
  filter: drop-shadow(0 18px 40px rgba(28, 33, 24, 0.08));
  transition: filter 0.4s var(--ease), transform 0.4s var(--ease);
}

.hero-logo:hover img {
  filter: drop-shadow(0 22px 48px rgba(95, 106, 72, 0.18));
  transform: scale(1.02);
}

.catalog-hero-logo {
  width: min(86vw, 520px);
}

/* —— Manuscript hero —— */
.hero {
  position: relative;
  padding: clamp(2rem, 7vw, 5rem) 0 clamp(1.75rem, 4vw, 3rem);
  overflow: hidden;
}

.hero-inner {
  position: relative;
  text-align: center;
}

.hero-copy {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 40rem;
  margin-inline: auto;
  padding-bottom: 0.5rem;
}

.ref-pill {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.45rem 0.55rem;
  margin-bottom: 1.1rem;
  max-width: 100%;
  animation: rise 0.85s var(--ease) 0.18s both;
}

.ref-pill .code {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 0.82rem;
  text-transform: uppercase;
  background: var(--olive);
  color: var(--white);
  padding: 0.45rem 0.8rem;
  position: relative;
  overflow: hidden;
}

.ref-pill .code::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.28) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: sheen 2.8s var(--ease) 1.2s infinite;
}

.ref-pill .tag {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(1.55rem, 5.5vw, 3rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 1rem;
  max-width: 18ch;
  margin-inline: auto;
  overflow-wrap: anywhere;
  animation: rise 1s var(--ease) 0.28s both;
}

.hero-lead {
  font-size: clamp(0.98rem, 2.8vw, 1.15rem);
  color: var(--muted);
  max-width: 34rem;
  margin-inline: auto;
  font-weight: 400;
  margin-bottom: 1.6rem;
  overflow-wrap: anywhere;
  animation: rise 1s var(--ease) 0.38s both;
}

.stat-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  width: 100%;
  max-width: 34rem;
  margin-inline: auto;
  text-align: start;
  animation: rise 1s var(--ease) 0.48s both;
}

.stat {
  background: var(--white);
  padding: 0.85rem 1rem;
  min-width: 0;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.6s var(--ease) var(--delay, 0ms), transform 0.6s var(--ease) var(--delay, 0ms);
}

.stat.in {
  opacity: 1;
  transform: translateY(0);
}

.stat strong {
  display: block;
  font-family: var(--display);
  font-size: clamp(1rem, 3.5vw, 1.15rem);
  font-weight: 700;
  color: var(--olive-deep);
  margin-bottom: 0.15rem;
  overflow-wrap: anywhere;
}

.stat span {
  font-size: 0.8rem;
  color: var(--muted);
}

.giant-ref {
  position: absolute;
  inset-inline: 0;
  bottom: -4%;
  text-align: center;
  font-family: var(--display);
  font-size: clamp(3.5rem, 18vw, 11rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.8;
  color: transparent;
  -webkit-text-stroke: 1px rgba(95, 106, 72, 0.14);
  pointer-events: none;
  user-select: none;
  z-index: 0;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  will-change: transform;
  animation: watermarkIn 1.4s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes logoIn {
  from { opacity: 0; transform: translateY(28px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes sheen {
  0%, 55% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}

@keyframes watermarkIn {
  from { opacity: 0; letter-spacing: 0.2em; }
  to { opacity: 1; letter-spacing: -0.04em; }
}

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(-12px); }
}

/* —— Treatises —— */
.section-intro {
  font-family: var(--arabic);
  color: var(--muted);
  margin: -0.5rem 0 1.25rem;
  font-size: 1rem;
}

.qr-section {
  padding-top: 0;
}

.qr-block {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  padding: 1.35rem 1.5rem;
}

.qr-copy h2 {
  font-family: var(--serif);
  font-size: 1.35rem;
  margin-bottom: 0.45rem;
}

.qr-copy p {
  color: var(--muted);
  max-width: 34rem;
}

.qr-image {
  width: 140px;
  height: 140px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 0.35rem;
}

@media (max-width: 640px) {
  .qr-block {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
}

.section-head.in {
  opacity: 1;
  transform: translateY(0);
}

.section-head h2 {
  font-family: var(--serif);
  font-size: clamp(1.25rem, 4vw, 1.85rem);
  font-weight: 700;
}

.section-count {
  font-family: var(--display);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ochre-deep);
  font-weight: 700;
}

.treatise-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.treatise {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 1.15rem 1.1rem 1.25rem;
  position: relative;
  overflow: hidden;
  min-width: 0;
  opacity: 0;
  transform: translateY(28px);
  transition:
    opacity 0.75s var(--ease) var(--delay, 0ms),
    transform 0.75s var(--ease) var(--delay, 0ms),
    border-color 0.3s var(--ease),
    box-shadow 0.3s var(--ease);
}

.treatise.in {
  opacity: 1;
  transform: translateY(0);
}

.treatise:hover {
  border-color: rgba(95, 106, 72, 0.45);
  box-shadow: 0 18px 40px rgba(28, 33, 24, 0.07);
}

.treatise::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--ochre), var(--olive));
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.45s var(--ease);
}

.treatise:hover::before,
.treatise.in::before { transform: scaleY(1); }

.t-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.t-num {
  font-family: var(--display);
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--olive);
  background: var(--mist);
  padding: 0.3rem 0.55rem;
  flex-shrink: 0;
}

.t-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.t-body h3 {
  font-family: var(--serif);
  font-size: clamp(1.05rem, 3.2vw, 1.35rem);
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 1rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.t-fields {
  display: grid;
  gap: 0.55rem;
}

.field {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.15rem;
  font-size: 0.92rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed rgba(28, 33, 24, 0.08);
  min-width: 0;
}

.field:last-child { border-bottom: none; padding-bottom: 0; }

.field dt {
  color: var(--olive);
  font-weight: 600;
  font-size: 0.82rem;
}

.field dd {
  color: var(--ink-soft);
  overflow-wrap: anywhere;
  min-width: 0;
}

.note {
  margin-top: 1rem;
  padding: 0.8rem 0.9rem;
  background: linear-gradient(120deg, rgba(184, 146, 63, 0.12), rgba(95, 106, 72, 0.08));
  border-inline-start: 3px solid var(--ochre);
  font-size: 0.92rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* —— Catalog index —— */
.catalog-hero {
  position: relative;
  min-height: auto;
  display: grid;
  align-items: center;
  padding: 2.5rem 0 1.75rem;
  overflow: hidden;
  text-align: center;
}

.catalog-hero-inner {
  display: block;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 40rem;
  margin-inline: auto;
}

.catalog-intro h1 {
  font-family: var(--serif);
  font-size: clamp(1.7rem, 6vw, 3.4rem);
  line-height: 1.2;
  margin-bottom: 0.9rem;
  max-width: 12ch;
  margin-inline: auto;
  overflow-wrap: anywhere;
  animation: rise 0.9s var(--ease) 0.1s both;
}

.catalog-intro p {
  color: var(--muted);
  font-size: clamp(0.98rem, 2.8vw, 1.08rem);
  max-width: 28rem;
  margin-inline: auto;
  margin-bottom: 1.5rem;
  animation: rise 0.9s var(--ease) 0.16s both;
}

.catalog-intro .cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--ink);
  color: var(--white);
  padding: 0.85rem 1.25rem;
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.3s var(--ease), transform 0.3s var(--ease);
  animation: rise 0.9s var(--ease) 0.22s both;
}

.catalog-intro .cta:hover {
  background: var(--olive-deep);
  transform: translateY(-2px);
}

.catalog-panel {
  background: var(--white);
  border: 1px solid var(--line);
  margin-bottom: 3rem;
  overflow: hidden;
}

.catalog-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.85rem 1rem;
  align-items: center;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--line);
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity 0.65s var(--ease) var(--delay, 0ms),
    transform 0.65s var(--ease) var(--delay, 0ms),
    background 0.3s var(--ease);
}

.catalog-item.in {
  opacity: 1;
  transform: translateY(0);
}

.catalog-item:last-child { border-bottom: none; }

.catalog-item:hover {
  background: rgba(95, 106, 72, 0.06);
}

.catalog-ref {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--olive);
  font-size: 0.9rem;
  grid-column: 1;
}

.catalog-title {
  font-family: var(--serif);
  font-size: clamp(1rem, 3.2vw, 1.12rem);
  font-weight: 700;
  color: var(--ink);
  grid-column: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.catalog-class {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--arabic);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

.catalog-arrow {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  color: var(--olive);
  grid-column: 2;
  grid-row: 1 / span 2;
  flex-shrink: 0;
  transition: background 0.3s var(--ease), color 0.3s var(--ease), transform 0.3s var(--ease);
}

.catalog-item:hover .catalog-arrow {
  background: var(--olive);
  color: var(--white);
  transform: translateX(-3px);
}

footer {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

footer .en {
  font-family: var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--olive);
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
}

/* —— Larger phones / tablets —— */
@media (min-width: 640px) {
  .wrap {
    width: min(100% - 2.5rem, var(--max));
  }

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

  .field {
    grid-template-columns: 7rem minmax(0, 1fr);
    gap: 0.65rem;
  }

  .catalog-item {
    grid-template-columns: 7.5rem minmax(0, 1fr) auto;
  }

  .catalog-ref {
    grid-column: 1;
    grid-row: 1;
  }

  .catalog-title {
    grid-column: 2;
    grid-row: 1;
  }

  .catalog-arrow {
    grid-column: 3;
    grid-row: 1;
  }

  .catalog-hero {
    min-height: min(72svh, 580px);
    padding: 3rem 0 2rem;
  }
}

/* —— Desktop —— */
@media (min-width: 900px) {
  .treatise-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }

  .treatise {
    padding: 1.35rem 1.35rem 1.45rem;
  }

  .treatise:nth-child(3n) {
    grid-column: 1 / -1;
  }

  .hero-logo {
    width: min(48vw, 480px);
  }

  .catalog-hero-logo {
    width: min(52vw, 520px);
  }
}

/* —— 404 / error page —— */
.error-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.error-hero {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  padding: clamp(2.5rem, 8vw, 5rem) 0 clamp(2rem, 5vw, 3.5rem);
  overflow: hidden;
}

.error-inner {
  position: relative;
  text-align: center;
  width: 100%;
}

.error-code {
  bottom: auto;
  top: 8%;
  inset-inline: 0;
  font-size: clamp(5rem, 28vw, 14rem);
  -webkit-text-stroke: 1.5px rgba(95, 106, 72, 0.16);
  animation: watermarkIn 1.2s var(--ease) both, drift 12s ease-in-out 1.2s infinite alternate;
}

.error-logo {
  width: min(72vw, 360px);
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1;
}

.error-copy {
  position: relative;
  z-index: 1;
  max-width: 28rem;
  margin-inline: auto;
}

.error-badge {
  display: inline-block;
  font-family: var(--display);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ochre-deep);
  background: rgba(184, 146, 63, 0.14);
  border: 1px solid rgba(184, 146, 63, 0.28);
  padding: 0.35rem 0.75rem;
  margin-bottom: 1rem;
  animation: rise 0.8s var(--ease) both;
}

.error-copy h1 {
  font-family: var(--arabic);
  font-size: clamp(1.55rem, 5vw, 2.15rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
  margin-bottom: 0.75rem;
  animation: rise 0.85s var(--ease) 0.08s both;
}

.error-copy p {
  color: var(--muted);
  font-size: clamp(0.95rem, 2.6vw, 1.05rem);
  margin-bottom: 1.75rem;
  animation: rise 0.85s var(--ease) 0.14s both;
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  animation: rise 0.85s var(--ease) 0.2s both;
}

.error-actions .cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--ink);
  color: var(--white);
  padding: 0.85rem 1.25rem;
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.3s var(--ease), transform 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease);
}

.error-actions .cta:hover {
  background: var(--olive-deep);
  transform: translateY(-2px);
}

.error-actions .cta-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.error-actions .cta-ghost:hover {
  background: var(--white);
  border-color: var(--olive);
  color: var(--olive-deep);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .treatise,
  .catalog-item,
  .section-head,
  .stat {
    opacity: 1;
    transform: none;
  }
  .hero-logo { animation: none !important; }
}
