/* ==========================================================================
   Urdu Books Portal — "نادر کتابیں" design system
   A warm, paper-toned, reading-first theme. RTL by default, minimal palette:
   warm paper + neutral inks + one deep pine-green primary + a muted brass accent.
   Hand-written, dependency-free, tuned for shared hosting.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Font (self-hosted, single family)
   Only Noto Nastaliq Urdu is loaded. It carries the Urdu glyphs plus digits
   and punctuation; a generic sans stays at the end of the stack purely so
   Latin letters (which Nastaliq does not contain) still render. Latin &
   numerals that are set deliberately use --font-latin (see §3).

   The faces ship as WOFF2, subset to the Arabic, Arabic Presentation Forms
   and Latin ranges the site actually uses — about a quarter of the size of
   the original TTF, and a single file per weight instead of two formats.

   The face loads "blocked" — until it is ready the text is held invisible
   (space reserved) rather than swapping in a differently-sized fallback. The
   shell is then faded in once the font is ready (see the fade block below).
   -------------------------------------------------------------------------- */
@font-face {
  font-family: 'Noto Nastaliq Urdu';
  src: url('../fonts/NotoNastaliqUrdu-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Nastaliq Urdu';
  src: url('../fonts/NotoNastaliqUrdu-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------------------
   2. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces & paper — warm ivory, sage undertone */
  --paper:        #F7F4EC;
  --paper-2:      #EEF0E6;
  --surface:      #FFFDF8;
  --surface-2:    #F8F7F0;
  --surface-inset:#EDF1E7;

  /* Ink */
  --ink:          #262A25;
  --ink-soft:     #4E554D;
  --ink-faint:    #5E665B;
  --on-primary:   #FBF8F1;

  /* Lines */
  --line:         #DEE2D6;
  --line-strong:  #C9D0C3;
  --line-faint:   #E8EBE1;

  /* Brand — pine green balanced with warm brass */
  --primary:      #2E5B48;
  --primary-600:  #204634;
  --primary-tint: #E5EEE7;
  --accent:       #976330;
  --accent-tint:  #F4EBDC;

  /* Status (used sparingly, mostly admin) */
  --danger:       #9E473C;
  --danger-tint:  #F6E4E1;
  --success:      #3E6A4B;
  --success-tint: #E4EFE5;
  --warning:      #A9781F;
  --warning-tint: #F6ECCE;

  /* Single Urdu face; the trailing sans only catches Latin glyphs Nastaliq lacks. */
  --font-urdu:  'Noto Nastaliq Urdu', sans-serif;
  --font-ui:    var(--font-urdu);
  --font-latin: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono:  ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Type scale — balanced for Nastaliq. Base = 16px (1rem); a gentle
     ~1.07 progression keeps hierarchy clear without big jumps. */
  --text-2xs: 0.8125rem;   /* 13.0px */
  --text-xs:  0.875rem;    /* 14.0px */
  --text-sm:  0.9375rem;   /* 15.0px */
  --text-base:1rem;        /* 16.0px */
  --text-md:  1.0625rem;   /* 17.0px */
  --text-lg:  1.125rem;    /* 18.0px */
  --text-xl:  1.1875rem;   /* 19.0px */
  --text-2xl: 1.3125rem;   /* 21.0px */
  --text-3xl: 1.5rem;      /* 24.0px */
  --text-4xl: 1.75rem;     /* 28.0px */

  /* Line heights — one rhythm shared by the whole theme instead of
     per-component magic numbers. */
  --lh-flat:    1.2;   /* star glyphs, numerals */
  --lh-tight:   1.4;   /* display headings */
  --lh-snug:    1.45;  /* headings, buttons, UI microcopy */
  --lh-base:    1.6;   /* form fields */
  --lh-relaxed: 1.7;   /* body copy, long-form reading */
  --lh-loose:   1.85;  /* oversized prose */

  /* Space — compact scale */
  --space-1: 4px;
  --space-2: 6px;
  --space-3: 10px;
  --space-4: 14px;
  --space-5: 20px;
  --space-6: 26px;
  --space-7: 36px;
  --space-8: 52px;

  /* Radius & shadow */
  --r-sm: 8px;
  --r:    14px;
  --r-lg: 22px;
  --r-pill: 999px;
  --shadow-sm: 0 2px 8px rgba(52, 47, 37, .045);
  --shadow-md: 0 8px 24px rgba(52, 47, 37, .085);
  --shadow-lg: 0 16px 40px rgba(43, 38, 33, 0.12);

  --container: 1200px;
  --header-h: 72px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
  --ring-danger: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
}

/* --------------------------------------------------------------------------
   3. Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute has to win over the layout rules below it — a rule
   like ".pagination { display: flex }" would otherwise keep a hidden
   element on screen. */
[hidden] { display: none !important; }

html { background: var(--paper); -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }

::selection { background: var(--primary-tint); color: var(--primary-600); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-urdu);
  font-size: var(--text-base);
  line-height: var(--lh-relaxed);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* Font-ready fade ----------------------------------------------------------
   A tiny inline snippet in <head> sets .fonts-loading on <html> before first
   paint; portal-core.js drops it once document.fonts is ready. The shell is
   held transparent and fades in, so text resolves smoothly instead of
   blinking into place. The timed animation is a failsafe if JS never runs.

   font-display is "swap", so a slow connection shows the text in the fallback
   face instead of a blank page — the shell fades in either way. */
html.fonts-loading body { opacity: 0; }
html.fonts-loading body { animation: fonts-failsafe .45s ease 3s forwards; }
@keyframes fonts-failsafe { to { opacity: 1; } }
body { transition: opacity .45s ease; }

img, svg { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--primary-600); }
button { font: inherit; color: inherit; }

/* Every native control — and the text the browser generates for it — must use
   the application typeface instead of the OS/browser default. */
input, select, textarea, optgroup, option, output, datalist, progress, meter,
input::placeholder, textarea::placeholder,
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder,
input::file-selector-button, input::-webkit-file-upload-button,
input::-webkit-calendar-picker-indicator,
input::-webkit-search-cancel-button, input::-webkit-search-decoration,
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button,
select::-ms-expand {
  font-family: var(--font-ui);
}
/* Values repainted by the browser's autofill must keep our face too. */
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus,
textarea:-webkit-autofill, textarea:-webkit-autofill:hover, textarea:-webkit-autofill:focus,
select:-webkit-autofill, select:-webkit-autofill:hover, select:-webkit-autofill:focus {
  font-family: var(--font-ui);
}

h1, h2, h3, h4 { margin: 0 0 var(--space-3); font-weight: 700; line-height: var(--lh-snug); }
h1 { font-size: var(--text-3xl); line-height: var(--lh-tight); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
p { margin: 0 0 var(--space-4); }
ul { margin: 0; padding: 0; list-style: none; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Latin / numerals keep a clean sans for legibility inside Urdu flow */
.num, .en, code, kbd {
  font-family: var(--font-latin);
  font-feature-settings: "tnum" 1;
}
.num { direction: ltr; unicode-bidi: embed; }

/* --------------------------------------------------------------------------
   4. Layout primitives
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-4);
}
.section { padding-block: clamp(30px, 3.8vw, 48px); }
.section--tight { padding-block: var(--space-5); }
.section--paper2 { background: var(--paper-2); }

.stack > * + * { margin-top: var(--space-4); }
.stack--reviews { gap: var(--space-4); }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}
.section-head h2 { margin: 0; font-size: var(--text-2xl); }
.section-head .section-sub { color: var(--ink-faint); font-size: var(--text-sm); }
.section-head .section-more { font-size: var(--text-sm); white-space: nowrap; }

.grid { display: grid; gap: var(--space-4); }
.grid--books { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.grid--writings { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* --------------------------------------------------------------------------
   5. Header & navigation
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 14px rgba(52, 47, 37, .035);
}
.site-header__inner {
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--ink); }
.brand__mark-img { width: 40px; height: 40px; flex: none; border-radius: 13px; box-shadow: var(--shadow-sm); object-fit: cover; }
.brand__text { display: flex; flex-direction: column; line-height: var(--lh-tight); }
.brand__name { font-size: var(--text-lg); font-weight: 700; line-height: inherit; }
.brand__tag { font-size: var(--text-xs); color: var(--ink-faint); font-family: var(--font-latin); letter-spacing: .02em; }

.nav { margin-inline-start: auto; }
.nav { font-family: var(--font-latin); }
.nav__list { display: flex; align-items: center; gap: var(--space-1); }
/* Search lives inside the mobile dropdown menu; hidden on desktop where the
   header search field is always visible. */
.nav__search { display: none; }
.nav__search .header-search { width: 100%; }
.nav__link {
  display: inline-block;
  padding: 9px 17px;
  border-radius: var(--r-pill);
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: var(--lh-snug);
  white-space: nowrap;
  transition: background .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease);
}
.nav__link:hover { background: var(--primary-tint); color: var(--primary-600); }
.nav__link.is-active { background: var(--primary); color: var(--on-primary); font-weight: 700; box-shadow: var(--shadow-sm); }
.nav__link--accent { background: var(--primary-tint); color: var(--primary-600); font-weight: 700; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 20%, transparent); }
.nav__link--accent:hover { background: color-mix(in srgb, var(--primary-tint) 90%, var(--primary) 10%); color: var(--primary-600); }
.nav__link.is-active.nav__link--accent { background: var(--primary); color: var(--on-primary); }
/* Entries that are on display but not active yet — they never navigate. */
.nav__link--disabled {
  color: var(--ink-faint);
  opacity: .55;
  cursor: default;
  pointer-events: none;
}
.nav__link--disabled:hover { background: none; color: var(--ink-faint); }

/* Nested menu item (e.g. "زمرہ جات" under "کتابیں") */
.nav__item { position: relative; }
.nav__link--has-child { display: inline-flex; align-items: center; gap: 5px; }
.nav__caret { width: 14px; height: 14px; opacity: .65; transition: transform .18s var(--ease); }
.nav__item:hover > .nav__link--has-child .nav__caret,
.nav__item:focus-within > .nav__link--has-child .nav__caret,
.nav__item.is-open > .nav__link--has-child .nav__caret { transform: rotate(180deg); }
.nav__submenu {
  position: absolute; inset-inline-start: 0; top: calc(100% + 8px);
  min-width: 200px; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .15s var(--ease), transform .15s var(--ease), visibility .15s var(--ease);
  max-height: min(60vh, 420px); overflow-y: auto;
  z-index: 60;
}
.nav__item:hover > .nav__submenu,
.nav__item:focus-within > .nav__submenu,
.nav__item.is-open > .nav__submenu { opacity: 1; visibility: visible; transform: translateY(0); }
.nav__submenu-head {
  padding: 6px 12px 4px; font-size: var(--text-xs); font-weight: 700;
  color: var(--ink-faint); letter-spacing: .02em;
}
.nav__sublink {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink); font-size: var(--text-sm); font-weight: 600; white-space: nowrap;
}
.nav__sublink:hover { background: var(--primary-tint); color: var(--primary-600); }
.nav__sublink.is-active { background: var(--primary); color: var(--on-primary); }
.nav__subicon {
  width: 18px; height: 18px; flex: none;
  color: var(--primary-600); opacity: .85;
  transition: color .15s var(--ease), opacity .15s var(--ease);
}
.nav__sublink:hover .nav__subicon { color: var(--primary); opacity: 1; }
.nav__subname { flex: 1 1 auto; }
.nav__subcount {
  font-family: var(--font-latin); font-size: var(--text-xs); font-weight: 700;
  color: var(--ink-faint); background: var(--surface-inset);
  border-radius: var(--r-pill); padding: 1px 8px; min-width: 22px; text-align: center;
}
.nav__sublink:hover .nav__subcount { background: var(--primary); color: var(--on-primary); }

.header-search { position: relative; width: min(280px, 34vw); }
.header-search input {
  width: 100%;
  height: 44px;
  line-height: var(--lh-snug);
  padding-inline: 40px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-base);
}
.header-search input::placeholder { color: var(--ink-faint); }
.header-search .icon { position: absolute; inset-inline-start: 14px; top: 50%; translate: 0 -50%; color: var(--ink-faint); }

.nav-toggle {
  display: none;
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-sm);
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   6. Hero
   -------------------------------------------------------------------------- */
.hero {
  position: relative;
  background:
    radial-gradient(ellipse at 50% -30%, rgba(169, 118, 53, .12), transparent 58%),
    radial-gradient(ellipse at 8% 100%, rgba(49, 89, 74, .08), transparent 42%),
    linear-gradient(180deg, #F3EFE5 0%, var(--paper-2) 100%);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.hero--home {
  background:
    radial-gradient(ellipse at 50% -20%, rgba(169, 118, 53, .16), transparent 62%),
    radial-gradient(ellipse at 10% 110%, rgba(49, 89, 74, .12), transparent 48%),
    linear-gradient(180deg, #f8f4ec 0%, var(--paper-2) 100%);
}
.hero--compact { padding-block: 0; }
.hero__inner { padding-block: clamp(38px, 5.2vw, 60px); text-align: center; max-width: 760px; margin-inline: auto; }
.hero__inner--compact { padding-block: var(--space-6); }
.hero__eyebrow {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: #684719;
  background: rgba(255, 254, 250, .72);
  border: 1px solid rgba(169, 118, 53, .24);
  padding: 2px 17px; border-radius: var(--r-pill);
  line-height: var(--lh-snug);
  margin-bottom: var(--space-4);
}
.hero h1 { max-width: 24ch; margin-inline: auto; font-size: var(--text-4xl); line-height: var(--lh-tight); margin-bottom: var(--space-3); }
.hero__lead { color: var(--ink-soft); font-size: var(--text-lg); line-height: var(--lh-relaxed); max-width: 54ch; margin: 0 auto var(--space-5); }
.hero__search { max-width: 620px; margin-inline: auto; margin-bottom: var(--space-4); }

/* Big search control (hero) */
.search-bar {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  padding: 6px 6px 6px 18px;
  box-shadow: var(--shadow-md);
}
.search-bar .icon { color: var(--ink-faint); flex: none; }
.search-bar input {
  flex: 1; min-width: 0; height: 46px;
  border: 0; background: transparent; color: var(--ink);
  font-size: var(--text-lg);
  line-height: var(--lh-snug);
}
.search-bar input:focus { outline: none; }

/* --------------------------------------------------------------------------
   7. Stats strip
   -------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-sm); }
.stat { text-align: center; padding: var(--space-2) var(--space-3); }
.stat__icon {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; margin-bottom: 6px;
  border-radius: 50%; background: var(--primary-tint); color: var(--primary-600);
}
.stat__icon .icon { width: 19px; height: 19px; }
.stat__num { font-family: var(--font-latin); font-size: var(--text-3xl); font-weight: 700; color: var(--primary-600); direction: ltr; }
.stat__label { color: var(--ink-faint); font-size: var(--text-sm); font-family: var(--font-ui); line-height: var(--lh-snug); }
@media (min-width: 761px) {
  .stat + .stat { border-inline-start: 1px solid var(--line); }
}

/* --------------------------------------------------------------------------
   7b. Quick navigation (home page)
   Three icon tiles, each with its own accent colour. The "کتابیں" tile opens
   the category panel; every chip opens the books page with that filter on.
   -------------------------------------------------------------------------- */
.quicknav {
  --qn-accent: var(--primary);
  --qn-accent-soft: var(--primary-tint);
  position: relative;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 16px 40px rgba(43, 38, 33, .07);
  overflow: hidden;
}
.quicknav::before {
  content: ""; position: absolute; inset-inline: 0; top: 0; height: 160px;
  background: radial-gradient(70% 100% at 50% 0%, color-mix(in srgb, var(--primary) 11%, transparent), transparent 72%);
  pointer-events: none;
}
.quicknav__item--writings { --qn-accent: #9A6A2F; --qn-accent-soft: #F7EDDD; }
.quicknav__item--facebook { --qn-accent: #1877F2; --qn-accent-soft: #E8F0FE; }
.quicknav__list { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); }
.quicknav__item { position: relative; }
.quicknav__item + .quicknav__item { border-inline-start: 1px solid var(--line); }
.quicknav__link {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  width: 100%; padding: 28px 22px 26px;
  background: none; border: 0; font: inherit; color: var(--ink);
  text-align: center; cursor: pointer;
  transition: transform .2s var(--ease);
}
.quicknav__link::after {
  content: ""; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(72% 78% at 50% 26%, color-mix(in srgb, var(--qn-accent) 13%, transparent), transparent 72%);
  transition: opacity .2s var(--ease); pointer-events: none;
}
.quicknav__link:hover,
.quicknav__link[aria-expanded="true"] { transform: translateY(-3px); }
.quicknav__link:hover::after,
.quicknav__link[aria-expanded="true"]::after { opacity: 1; }
.quicknav__icon {
  position: relative; z-index: 1;
  display: inline-grid; place-items: center; flex: none;
  width: 76px; height: 76px; border-radius: 24px;
  background: var(--qn-accent-soft); color: var(--qn-accent);
  box-shadow: 0 10px 22px color-mix(in srgb, var(--qn-accent) 16%, transparent);
  transition: transform .25s var(--ease), background .2s var(--ease),
              color .2s var(--ease), box-shadow .25s var(--ease);
}
.quicknav__icon .icon { width: 34px; height: 34px; }
.quicknav__link:hover .quicknav__icon,
.quicknav__link[aria-expanded="true"] .quicknav__icon {
  transform: translateY(-4px) scale(1.05);
  background: var(--qn-accent); color: #fff;
  box-shadow: 0 18px 32px color-mix(in srgb, var(--qn-accent) 32%, transparent);
}
.quicknav__text {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.quicknav__label {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--text-lg); font-weight: 700; line-height: var(--lh-snug);
  transition: color .2s var(--ease);
}
.quicknav__link:hover .quicknav__label,
.quicknav__link[aria-expanded="true"] .quicknav__label { color: var(--qn-accent); }
.quicknav__desc {
  font-size: var(--text-xs); color: var(--ink-faint);
  line-height: 1.6; max-width: 24ch;
}
.quicknav__arrow {
  display: inline-grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--qn-accent-soft); color: var(--qn-accent);
  opacity: 0; transform: translateX(-7px);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.quicknav__arrow .icon { width: 13px; height: 13px; }
.quicknav__link:hover .quicknav__arrow { opacity: 1; transform: translateX(0); }
.quicknav__caret {
  width: 15px; height: 15px; opacity: .6;
  transition: transform .18s var(--ease);
}
.quicknav__link[aria-expanded="true"] .quicknav__caret { transform: rotate(180deg); }
.quicknav__panel {
  position: relative;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  padding: var(--space-4) var(--space-4) var(--space-5);
  animation: quicknav-drop .2s var(--ease);
}
@keyframes quicknav-drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.quicknav__panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-4);
}
.quicknav__panel-title {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; color: var(--ink);
}
.quicknav__panel-title::before {
  content: ""; width: 18px; height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 30%, transparent));
}
.quicknav__panel-more { font-size: var(--text-sm); font-weight: 600; color: var(--primary-600); }
.quicknav__panel-more:hover { text-decoration: underline; }
.quicknav__cats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3); list-style: none; margin: 0; padding: 0;
}
.quicknav__cat-wrap { min-width: 0; }
.quicknav__cats > li:nth-child(4n+1) { --qn-accent: #2E5B48; --qn-accent-soft: #E5EEE7; }
.quicknav__cats > li:nth-child(4n+2) { --qn-accent: #9A6A2F; --qn-accent-soft: #F7EDDD; }
.quicknav__cats > li:nth-child(4n+3) { --qn-accent: #1F6F6B; --qn-accent-soft: #E1F0EE; }
.quicknav__cats > li:nth-child(4n)   { --qn-accent: #7A3E63; --qn-accent-soft: #F5E7EF; }
.quicknav__cat {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease),
              border-color .18s var(--ease), background .18s var(--ease);
}
.quicknav__cat:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--qn-accent) 35%, transparent);
  box-shadow: 0 16px 30px color-mix(in srgb, var(--qn-accent) 16%, transparent);
}
.quicknav__cat-icon {
  display: inline-grid; place-items: center; flex: none;
  width: 46px; height: 46px; border-radius: 15px;
  background: var(--qn-accent-soft); color: var(--qn-accent);
  transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.quicknav__cat-icon .icon { width: 24px; height: 24px; }
.quicknav__cat:hover .quicknav__cat-icon {
  background: var(--qn-accent); color: #fff; transform: translateY(-2px) scale(1.06);
}
.quicknav__cat-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.quicknav__cat-name {
  font-weight: 700; font-size: var(--text-base); line-height: var(--lh-snug);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.quicknav__cat-count { color: var(--ink-faint); font-size: var(--text-xs); }
.quicknav__cat-arrow {
  margin-inline-start: auto; flex: none;
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--qn-accent-soft); color: var(--qn-accent);
  opacity: 0; transform: translateX(-6px);
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.quicknav__cat-arrow .icon { width: 13px; height: 13px; }
.quicknav__cat:hover .quicknav__cat-arrow { opacity: 1; transform: translateX(0); }
.quicknav__empty { color: var(--ink-faint); font-size: var(--text-sm); }

/* --------------------------------------------------------------------------
   8. Buttons
   -------------------------------------------------------------------------- */
.btn {
  --_bg: var(--surface);
  --_fg: var(--ink);
  --_bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; height: auto; padding: 5px 20px;
  border: 1px solid var(--_bd);
  border-radius: var(--r-pill);
  background: var(--_bg); color: var(--_fg);
  font-family: var(--font-ui); font-size: var(--text-base); font-weight: 700; line-height: var(--lh-snug);
  cursor: pointer; white-space: nowrap;
  transition: transform .12s var(--ease), background .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn--primary { --_bg: var(--primary); --_fg: var(--on-primary); --_bd: var(--primary); }
.btn--primary:hover { --_bg: var(--primary-600); --_bd: var(--primary-600); }
.btn--ghost { --_bg: transparent; --_bd: transparent; --_fg: var(--primary-600); }
.btn--ghost:hover { --_bg: var(--primary-tint); box-shadow: none; }
.btn--outline { --_bg: transparent; --_bd: var(--primary); --_fg: var(--primary-600); }
.btn--outline:hover { --_bg: var(--primary-tint); }
.btn--sm { min-height: 40px; height: auto; padding-inline: 14px; font-size: var(--text-xs); }
.btn--block { width: 100%; }
.btn--danger { --_bg: var(--danger); --_fg: #fff; --_bd: var(--danger); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

/* --------------------------------------------------------------------------
   9. Cards & book covers
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card__body { padding: var(--space-4); }

.book-card, .writing-card, .fb-card { transition: transform .18s var(--ease), box-shadow .18s var(--ease); }
.book-card:hover, .writing-card:hover, .fb-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.book-card { display: flex; flex-direction: column; }
.book-card__cover { position: relative; display: block; overflow: hidden; }
.book-cover {
  aspect-ratio: 2 / 3;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--space-4);
  color: #fbf8f1;
  background: linear-gradient(150deg, #4a6a54, #2f4638);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: transform .35s var(--ease);
}
.book-cover::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(145deg, rgba(255,255,255,.14), transparent 56%);
  pointer-events: none;
}
.book-cover::after {
  content: ""; position: absolute; inset-inline-start: 14px; top: 0; bottom: 0;
  width: 2px; background: rgba(255,255,255,.2);
}
.book-cover__title { font-size: var(--text-lg); line-height: var(--lh-snug); text-shadow: 0 1px 2px rgba(0,0,0,.18); }
.book-cover__author { font-size: var(--text-sm); opacity: .88; font-family: var(--font-ui); }
.book-cover__img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.book-cover--clay { background: linear-gradient(150deg, #9a5b3f, #6f3f2b); }
.book-cover--plum { background: linear-gradient(150deg, #6a5478, #443249); }
.book-cover--ocean { background: linear-gradient(150deg, #3f6178, #2a4453); }
.book-cover--olive { background: linear-gradient(150deg, #6f7a3f, #4b532b); }
.book-cover--rose { background: linear-gradient(150deg, #9a4f5b, #6d353f); }
.book-card:hover .book-cover { transform: scale(1.035); }

/* ── CSS-drawn cover (no supplied artwork) ─────────────────────────────
   Generated with HTML/CSS instead of shipping a bitmap: title centred,
   author beneath, inside an ornamental frame — same layout and palette as
   the supplied cover images. */
.book-cover--generated {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
}
.book-cover--generated::before {
  background:
    linear-gradient(145deg, rgba(255,255,255,.16), transparent 58%),
    radial-gradient(circle at 50% 46%, rgba(255,255,255,.10), transparent 52%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.05) 0 2px, transparent 2px 8px);
}
.book-cover__frame {
  position: absolute; inset: 9px; z-index: 0;
  border: 1px solid rgba(255,255,255,.32);
  pointer-events: none;
}
.book-cover__frame::after {
  content: ""; position: absolute; inset: 3px;
  border: 1px solid rgba(255,255,255,.16);
}
.book-cover__ornament {
  position: relative; z-index: 1;
  width: 52px; height: 9px;
  color: rgba(255,255,255,.8);
  background:
    linear-gradient(currentColor, currentColor) left center / 17px 1px no-repeat,
    linear-gradient(currentColor, currentColor) right center / 17px 1px no-repeat;
}
.book-cover__ornament::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 8px; height: 8px;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 1px solid currentColor;
  background: rgba(255,255,255,.16);
}
.book-cover__rule {
  position: relative; z-index: 1;
  width: 54px; height: 1px;
  background: rgba(255,255,255,.55);
}
.book-cover--generated .book-cover__title {
  position: relative; z-index: 1;
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: var(--lh-snug);
}
.book-cover--generated .book-cover__author {
  position: relative; z-index: 1;
  font-size: var(--text-sm);
}

.book-card__meta { padding: 12px 13px 14px; }
.book-card__title { font-size: var(--text-md); line-height: var(--lh-snug); margin: 0 0 2px; }
.book-card__title a { color: var(--ink); }
.book-card__title a:hover { color: var(--primary-600); }
.book-card__author { color: var(--ink-faint); font-size: var(--text-sm); font-family: var(--font-ui); margin: 0; }
.book-card__tags { margin-top: var(--space-2); display: flex; align-items: center; flex-wrap: wrap; gap: 4px var(--space-2); min-width: 0; }

/* Category tile */
.cat-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--space-4);
  min-height: 94px;
  justify-content: center;
  padding-inline: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.cat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.cat-card__name { font-size: var(--text-md); font-weight: 700; color: var(--ink); }
.cat-card__count { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); }

/* Writing card */
.writing-card { display: flex; flex-direction: column; }
.writing-card__body { padding: var(--space-4); }
.writing-card__title { font-size: var(--text-md); line-height: var(--lh-snug); margin-bottom: var(--space-2); }
.writing-card__excerpt {
  color: var(--ink-soft); font-size: var(--text-sm);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.writing-card__meta { margin-top: var(--space-3); display: flex; align-items: center; justify-content: space-between; font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); }

/* Facebook / wall card */
.fb-card { display: flex; flex-direction: column; }
.fb-card__head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-4) 0; color: var(--ink-soft); font-family: var(--font-ui); font-size: var(--text-xs); }
.fb-card__who { display: flex; flex-direction: column; line-height: var(--lh-snug); }
.fb-card__who strong { color: var(--ink); }
.fb-card__time { font-size: var(--text-xs); color: var(--ink-faint); }
.fb-card__avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-tint); display: grid; place-items: center; color: var(--primary-600); font-weight: 700; }
.fb-card__message { padding: var(--space-3) var(--space-4) var(--space-4); }
.fb-card__message--truncated {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fb-card__more {
  margin: 0 var(--space-4) var(--space-4);
  background: none;
  border: 0;
  color: var(--primary-600);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-align: start;
}
.fb-card__more:hover { text-decoration: underline; }
.fb-card__image { aspect-ratio: 16 / 10; object-fit: cover; width: 100%; border-block: 1px solid var(--line); }
.fb-card__foot { padding: 0 var(--space-4) var(--space-4); }
.fb-card__link { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--primary-600); text-decoration: none; font-weight: 600; }
.fb-card__link:hover, .fb-card__link:focus-visible { color: var(--primary-700); text-decoration: underline; }

/* Modal (public pages) */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  padding: var(--space-4);
  background: rgba(0,0,0,.35);
}
.modal.is-open { display: flex; }
.modal__backdrop { position: absolute; inset: 0; cursor: pointer; }
.modal__dialog {
  width: min(680px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: modal-pop .16s var(--ease);
}
@keyframes modal-pop { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal__title { margin: 0; font-size: var(--text-xl); }
.modal__body { padding: var(--space-4); }
.modal__foot { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; }
.modal__close { width: 40px; height: 40px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); cursor: pointer; display: grid; place-items: center; color: var(--ink-soft); }
.modal__close:hover { background: var(--surface-2); color: var(--ink); }
.modal__dialog--lg { width: min(840px, 100%); }

.fb-modal__content {
  font-size: var(--text-base);
  line-height: var(--lh-relaxed);
  white-space: pre-wrap;
}
.fb-modal__link {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-ui); font-size: var(--text-sm); color: var(--primary-600);
  text-decoration: none; font-weight: 600;
}
.fb-modal__link:hover { color: var(--primary-700); text-decoration: underline; }

/* --------------------------------------------------------------------------
   10. Ratings, badges, pills
   -------------------------------------------------------------------------- */
.stars {
  position: relative; display: inline-block; direction: ltr; unicode-bidi: isolate;
  font-size: var(--text-lg); line-height: var(--lh-flat); color: var(--line-strong); white-space: nowrap;
}
.stars__fill {
  position: absolute; top: 0; left: 0;
  color: var(--accent); white-space: nowrap;
  clip-path: inset(0 var(--stars-clip, 100%) 0 0);
}
.rating-num { font-family: var(--font-latin); font-size: var(--text-xs); color: var(--ink-faint); }

.pill, .badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 700;
}
.pill { background: var(--surface-inset); color: var(--ink-soft); }
.badge--cat { background: var(--accent-tint); color: #7d551f; }
.badge--ok { background: var(--success-tint); color: var(--success); }
.badge--warn { background: var(--warning-tint); color: var(--warning); }
.badge--danger { background: var(--danger-tint); color: var(--danger); }

/* --------------------------------------------------------------------------
   11. Forms
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field > label { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 700; color: var(--ink-soft); }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font-size: var(--text-base);
  font-family: var(--font-ui);
  line-height: var(--lh-base);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.textarea { min-height: 130px; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}
.field__hint { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); }
.field__hint--spaced { margin-top: var(--space-3); }

/* --------------------------------------------------------------------------
   12. Breadcrumb, pagination, empty state
   -------------------------------------------------------------------------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: var(--space-2); font-family: var(--font-ui); font-size: var(--text-sm); color: var(--ink-faint); padding-block: var(--space-3); }
.breadcrumb a { color: var(--ink-soft); }
.breadcrumb span[aria-current] { color: var(--ink); }

.pagination { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-5); }
.pagination a, .pagination button, .pagination span {
  min-width: 40px; height: 40px; padding-inline: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-soft);
  font-family: var(--font-ui); font-size: var(--text-sm); line-height: var(--lh-snug);
}
.pagination .num { font-family: var(--font-latin); }
.pagination .is-active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.pagination .is-disabled { opacity: .5; pointer-events: none; }

/* تراجم و تعارف — inline paged reader (book.html) */
.writing-index { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.writing-index:empty { display: none; }
.writing-index__item {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-soft);
  font-family: var(--font-ui); font-size: var(--text-sm); line-height: var(--lh-snug);
  cursor: pointer;
}
.writing-index__item:hover { border-color: var(--primary); color: var(--primary-600); }
.writing-index__item.is-active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.writing-index__type { font-size: var(--text-xs); opacity: .75; }
.writing-index__item.is-active .writing-index__type { opacity: .9; }

.writing-reader__head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.writing-reader__title { margin: 0; }

/* Hidden on screen; assets/css/print.css reveals it while printing. */
#print-book { display: none; }

.empty { display: grid; place-items: center; gap: var(--space-2); text-align: center; padding: var(--space-6) var(--space-4); color: var(--ink-faint); }
.empty__mark { font-size: var(--text-4xl); margin-bottom: var(--space-3); }

/* --------------------------------------------------------------------------
   13. Alerts
   -------------------------------------------------------------------------- */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); font-family: var(--font-ui); font-size: var(--text-sm); }
.alert--ok { background: var(--success-tint); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }
.alert--danger { background: var(--danger-tint); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.alert--info { background: var(--primary-tint); border-color: color-mix(in srgb, var(--primary) 22%, transparent); color: var(--primary-600); }

/* --------------------------------------------------------------------------
   14. Footer
   -------------------------------------------------------------------------- */
.site-footer { background: #25382F; color: #d8cfc0; padding-block: var(--space-6) var(--space-4); margin-top: var(--space-7); }
.site-footer a { color: #e9e1d4; line-height: var(--lh-snug); }
.site-footer a:hover { color: #fff; }
.footer-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: var(--space-5); }
.footer-brand__name { font-size: var(--text-lg); color: #fff; }
.footer-brand p { color: #b4a997; font-size: var(--text-sm); max-width: 42ch; }
.footer-col h4 { color: #fff; font-family: var(--font-ui); font-size: var(--text-sm); }
.footer-col a { display: block; padding-block: 4px; font-size: var(--text-sm); color: #c8bfae; }
.footer-col__disabled { display: block; padding-block: 4px; font-size: var(--text-sm); color: #8d877c; }
.footer-bottom { margin-top: var(--space-5); padding-top: var(--space-3); border-top: 1px solid rgba(255,255,255,.10); display: flex; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; font-family: var(--font-ui); font-size: var(--text-xs); line-height: var(--lh-snug); color: #b8c0b9; }
.footer-screens { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }

/* --------------------------------------------------------------------------
   15. Reading article (writings & book intro)
   -------------------------------------------------------------------------- */
.prose { max-width: 68ch; margin-inline: auto; font-size: var(--text-md); line-height: var(--lh-loose); }
.prose h2 { font-size: var(--text-2xl); margin-top: var(--space-5); }
.prose p { margin-bottom: var(--space-4); }
.text-soft { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); } .mb-0 { margin-bottom: 0; }
.hide { display: none !important; }
.icon { width: 20px; height: 20px; flex: none; }

/* --------------------------------------------------------------------------
   17. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 980px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .header-search { width: 210px; }
}
/* The header carries six menu entries now, so the links tighten up before the
   navigation collapses into the drawer (see the 1100px block below). */
@media (max-width: 1200px) {
  .nav__link { padding: 8px 12px; font-size: var(--text-sm); }
  .header-search { width: 200px; }
}
/* Below this width the navigation (and the search box) move into the drawer. */
@media (max-width: 1100px) {
  .header-search { width: 200px; }
  .nav-toggle { display: grid; place-items: center; }
  .nav {
    position: fixed; inset-inline: 0; top: var(--header-h);
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: var(--space-3) var(--space-4) var(--space-4);
    margin: 0;
    display: none;
    box-shadow: var(--shadow-lg);
    max-height: calc(100dvh - var(--header-h));
    overflow-y: auto;
    animation: nav-drop .18s var(--ease);
  }
  @keyframes nav-drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
  .nav.is-open { display: block; }
  .nav__list { direction: ltr; text-align: left; }
  .nav__list { flex-direction: column; align-items: stretch; gap: var(--space-1); }
  .nav__link { padding: 12px 16px; border-radius: var(--r-sm); font-size: var(--text-md); }
  /* The drawer has no hover, so nested items are always visible and indented. */
  .nav__item { width: 100%; }
  .nav__submenu {
    position: static; min-width: 0; margin: 0;
    padding: 0 0 4px; padding-inline-start: 16px;
    background: transparent; border: 0; box-shadow: none;
    opacity: 1; visibility: visible; transform: none;
    max-height: none; overflow: visible;
  }
  .nav__sublink { padding: 9px 12px; }
  .nav__search { display: block; padding: 0 0 var(--space-3); margin-bottom: var(--space-2); border-bottom: 1px solid var(--line); }
  .nav__search .header-search { display: block; width: 100%; }
  .header-search { display: none; }
}
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); padding: 8px; }
  .stat { padding: 8px 6px; }
  .quicknav__list { grid-template-columns: 1fr; }
  .quicknav__item + .quicknav__item { border-inline-start: 0; border-top: 1px solid var(--line); }
  .quicknav__link {
    flex-direction: row; justify-content: flex-start; text-align: start;
    padding: var(--space-3) var(--space-4); gap: var(--space-3);
  }
  .quicknav__text { align-items: flex-start; }
  .quicknav__icon { width: 50px; height: 50px; border-radius: 16px; }
  .quicknav__icon .icon { width: 25px; height: 25px; }
  .quicknav__label { font-size: var(--text-base); }
  .quicknav__desc { max-width: none; }
  .quicknav__cats { grid-template-columns: repeat(2, 1fr); }
  .quicknav__cat { padding: 10px 12px; gap: 10px; }
  .quicknav__cat-icon { width: 40px; height: 40px; border-radius: 13px; }
  .quicknav__cat-icon .icon { width: 21px; height: 21px; }
  .quicknav__cat-arrow { display: none; }
  .grid--books { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .footer-grid { grid-template-columns: 1fr; }
  .section { padding-block: 30px; }
  .hero__inner { padding-block: 36px 40px; }
  .hero h1 { max-width: 16ch; }
  .filter-bar { padding: var(--space-3); }
  .filter-bar .field { flex: 1 1 100%; }
  .filter-bar .btn { flex: 1 1 100%; }
  .page-head { align-items: flex-start; }
  .result-count { white-space: normal; }
}

@media (max-width: 420px) {
  .quicknav__cats { grid-template-columns: 1fr; }
  .grid--books { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
  .book-card__tags { gap: 3px var(--space-2); }
  .book-card__tags .stars { font-size: var(--text-base); }
  .book-card__meta { padding: 10px 11px 12px; }
  /* Hero search stacks so the button never crushes the field */
  .search-bar { flex-wrap: wrap; border-radius: var(--r); padding: 10px; gap: var(--space-2); }
  .search-bar .icon { display: none; }
  .search-bar input { flex: 1 1 100%; height: 42px; padding-inline: 6px; }
  .search-bar .btn { flex: 1 1 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .pagination a, .pagination button, .pagination span { min-width: 36px; height: 36px; padding-inline: 10px; }
  .footer-bottom { gap: var(--space-2); }
  .footer-screens { gap: var(--space-3); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* --------------------------------------------------------------------------
   18. Book detail (reading page)
   -------------------------------------------------------------------------- */
.book-detail { display: grid; grid-template-columns: 300px 1fr; gap: var(--space-5); align-items: start; }
.book-detail__cover .book-cover { border-radius: var(--r); box-shadow: var(--shadow-lg); }
.book-detail__cover .book-cover__title { font-size: var(--text-2xl); }
.book-detail__info h1 { margin-top: var(--space-3); font-size: var(--text-3xl); }
.book-detail__byline { font-size: var(--text-lg); color: var(--ink-soft); }
.book-detail__reviews { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--ink-faint); }
.book-detail__rating { display: flex; align-items: center; gap: var(--space-3); margin-block: var(--space-3); }
.book-detail__rating .stars { font-size: var(--text-lg); }
.book-detail__actions { margin-top: var(--space-3); }
.review-form-title { font-size: var(--text-lg); }

.meta-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4); margin-block: var(--space-4); padding-block: var(--space-3);
  border-block: 1px solid var(--line);
}
.meta-list__label { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); }

.split { display: grid; grid-template-columns: 1fr 340px; gap: var(--space-5); align-items: start; }

.review-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.review-date { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); margin: 4px 0 var(--space-2); }

@media (max-width: 860px) {
  .book-detail { grid-template-columns: 1fr; }
  .book-detail__cover { max-width: 260px; }
  .split { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   19. Interaction details
   Focus and hover states use the same brand colors and restrained motion.
   -------------------------------------------------------------------------- */
a { text-underline-offset: 3px; }
.prose a { text-decoration: underline; }

.btn:focus-visible,
.nav__link:focus-visible,
.cat-card:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.search-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent), var(--shadow-md);
}
.header-search input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

/* "view all" affordance */
.section-more { color: var(--primary-600); font-family: var(--font-ui); }
.section-more:hover { color: var(--primary); }

/* Extra alert/badge variants */
.alert--warn { background: var(--warning-tint); border-color: color-mix(in srgb, var(--warning) 30%, transparent); color: var(--warning); }
.badge--info { background: var(--primary-tint); color: var(--primary-600); }

/* Nicer scrollbars (subtle, optional) */
@supports (scrollbar-width: thin) {
  html { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
}

/* Template-specific components. */
.sg-page-title { font-size: var(--text-3xl); }
.sg-section { margin-bottom: var(--space-7); }
.sg-swatch { border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.sg-swatch__chip { height: 68px; }
.sg-swatch__chip--paper { background: var(--paper); }
.sg-swatch__chip--paper-2 { background: var(--paper-2); }
.sg-swatch__chip--surface { background: var(--surface); }
.sg-swatch__chip--ink { background: var(--ink); }
.sg-swatch__chip--ink-soft { background: var(--ink-soft); }
.sg-swatch__chip--ink-faint { background: var(--ink-faint); }
.sg-swatch__chip--line { background: var(--line); }
.sg-swatch__chip--primary { background: var(--primary); }
.sg-swatch__chip--primary-tint { background: var(--primary-tint); }
.sg-swatch__chip--accent { background: var(--accent); }
.sg-swatch__chip--danger { background: var(--danger); }
.sg-swatch__chip--success { background: var(--success); }
.sg-swatch__meta { padding: 8px 10px; background: var(--surface); font-family: var(--font-ui); font-size: var(--text-xs); }
.sg-swatch__meta b { display: block; color: var(--ink); }
.sg-swatch__meta code { color: var(--ink-faint); direction: ltr; display: block; font-family: var(--font-latin); }
.sg-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.sg-token { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: var(--space-3) var(--space-4); font-family: var(--font-ui); font-size: var(--text-sm); }
.sg-token code { color: var(--primary-600); direction: ltr; font-family: var(--font-latin); }
.sg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--space-4); }
.sg-grid--form { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.stat-card__delta--warning { color: var(--warning); }
.admin-list-meta { font-family: var(--font-ui); font-size: var(--text-xs); }
.pagination--inline { margin: 0; }

/* --------------------------------------------------------------------------
   20. List pages (catalog, categories, authors, writings, feed)
   -------------------------------------------------------------------------- */
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-5);
}
.page-head h1 { margin: 0; font-size: var(--text-3xl); }
.page-head__sub { margin: 4px 0 0; color: var(--ink-faint); font-family: var(--font-ui); font-size: var(--text-sm); }
.result-count { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--ink-faint); white-space: nowrap; }

.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
}
.filter-bar .field { margin-bottom: 0; flex: 1 1 170px; }

@media (max-width: 560px) {
  .page-head { align-items: flex-start; }

  /* Forms — roomier fields and larger, easier-to-read labels on phones.
     Nastaliq has deep descenders, so inputs get extra height and padding
     and the text scale is nudged up one step. */
  .field { gap: 8px; }
  .field > label { font-size: var(--text-base); line-height: var(--lh-tight); }
  .field__hint { font-size: var(--text-sm); line-height: var(--lh-snug); }
  .input, .select, .textarea,
  .cselect__button { min-height: 52px; padding: 11px 14px; }
  .textarea { min-height: 150px; }
  .cselect__search input { min-height: 44px; }
  .cselect__list { font-size: var(--text-md); }
  .cselect__option { padding: 11px 14px; }
  .filter-bar .field { flex-basis: 100%; }

  /* Search fields */
  .search-bar input, .header-search input { min-height: 46px; }
}

/* --------------------------------------------------------------------------
   21. Custom select (font-safe dropdown)
   Native <select> popups are drawn by the OS and ignore CSS fonts on some
   platforms.  portal-controls.js replaces each .select with this listbox,
   which the app renders itself, so option text always uses the Urdu face.
   The original <select> stays in the DOM (visually hidden) for form data.
   -------------------------------------------------------------------------- */
.cselect { position: relative; }
.cselect__native {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: 0;
  border: 0; opacity: 0; overflow: hidden; pointer-events: none;
}
.cselect__button {
  appearance: none; -webkit-appearance: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-1); width: 100%; text-align: start; cursor: pointer;
}
.cselect__value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect__arrow {
  flex: none; width: 0; height: 0; margin-top: 2px;
  border-inline: 5px solid transparent; border-top: 6px solid var(--ink-faint);
  transition: transform .15s var(--ease);
}
.cselect[data-open="true"] .cselect__arrow { transform: translateY(2px) rotate(180deg); }
.cselect__panel {
  position: absolute; z-index: 40; inset-inline: 0; top: calc(100% + 4px);
  min-width: 100%; width: max-content; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
  display: none;
}
.cselect[data-open="true"] .cselect__panel { display: block; }
.cselect__search { padding: 8px; border-bottom: 1px solid var(--line); }
.cselect__search input {
  width: 100%; min-height: 38px; padding: 6px 12px;
  font-family: var(--font-ui); font-size: var(--text-base); color: var(--ink);
  background: var(--surface-inset); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.cselect__search input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.cselect__list {
  max-height: 260px; overflow-y: auto; overflow-x: hidden; margin: 0; padding: 6px;
  list-style: none;
  font-family: var(--font-ui); font-size: var(--text-base); line-height: var(--lh-snug);
}
.cselect__option {
  padding: 8px 12px; border-radius: var(--r-sm); cursor: pointer;
  font-family: var(--font-ui); line-height: var(--lh-snug);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cselect__option.is-active, .cselect__option:hover { background: var(--surface-inset); }
.cselect__option.is-selected { background: var(--primary-tint); color: var(--primary-600); font-weight: 700; }
.cselect__option[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.cselect__empty {
  padding: 12px; text-align: center; color: var(--ink-faint);
  font-family: var(--font-ui); font-size: var(--text-sm);
}

/* Keep footer at bottom even if page content is short */
body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
