/* =========================================================
   Thaqalayn Library — fonts and design tokens
   Site font: GE SS Two (bold text uses Noto Kufi Arabic Bold).
   Book text: the reader's choice (Naskh by default).
   ========================================================= */
@font-face { font-family: "GE SS Two"; src: url("../fonts/GESSTwoLight-Light.otf") format("opentype"); font-weight: 100 600; font-display: swap; }
@font-face { font-family: "GE SS Two"; src: url("../fonts/NotoKufiArabic-Bold.ttf") format("truetype"); font-weight: 700 900; font-display: swap; }
@font-face { font-family: "Thq Naskh"; src: url("../fonts/NotoNaskhArabic-VariableFont_wght.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Thq Amiri"; src: url("../fonts/Amiri-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Thq Amiri"; src: url("../fonts/Amiri-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Thq Scheherazade"; src: url("../fonts/ScheherazadeNew-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Thq Sans"; src: url("../fonts/NotoSansArabic-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Thq Sans"; src: url("../fonts/NotoSansArabic-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Thq Mosawi"; src: url("../fonts/Mosawi-Bold.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }

:root {
  /* Warm sand, cream and bronze (inspired by rafed.net) */
  --bg: #FDFCF9;
  --band: #F4E8DA;
  --surface: #FFFFFF;
  --surface-2: #F8F1E7;
  --surface-3: #EFE3D2;
  --ink: #1D2032;
  --ink-2: #4A4E5E;
  --ink-3: #62667A;
  --border: #EADFCD;
  --border-strong: #D8C7AC;
  --primary: #7F6444;
  --primary-hover: #6B5438;
  --on-primary: #FFFFFF;
  --primary-soft: #F3EADD;
  --accent: #8B6F4D;
  --bronze: #8B6F4D;
  --gold: #A88A5E;
  --gold-light: #C8AD84;
  --gold-text: #735A3C;
  --navy-950: #070E1C;
  --navy-900: #0A1426;
  --navy-800: #0F1D36;
  --navy-700: #172A4D;
  --mark: #F3DDB5;
  --danger: #B91C1C;
  --ring: #8B6F4D;
  --shadow-sm: 0 1px 2px rgb(92 70 42 / .06);
  --shadow-md: 0 8px 24px rgb(92 70 42 / .10);
  --shadow-lg: 0 18px 44px rgb(92 70 42 / .16);
  --scrim: rgb(29 32 50 / .5);

  /* The whole site uses GE SS Two; only book text follows the reader's font choice. */
  --font-ui: "GE SS Two", "Noto Kufi Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --font-read: var(--font-ui);
  --font-book: "Thq Naskh", "Noto Naskh Arabic", "Traditional Arabic", serif;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px;
  --radius-sm: 8px; --radius: 12px; --radius-lg: 16px; --radius-pill: 999px;
  --header-h: 64px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 180ms;
  --read-size: 22px;

  --z-sticky: 20; --z-drawer: 40; --z-toast: 100;
  color-scheme: light;
}

/* The book reader keeps its own paper-and-ink palette (light theme). */
body.is-reading {
  --bg: #FBF8F1; --surface: #FFFFFF; --surface-2: #F4EFE4; --surface-3: #EDE6D6;
  --ink: #1C1917; --ink-2: #57534E; --ink-3: #6B645C;
  --border: #E6DECE; --border-strong: #D5CAB4;
  --primary: #92400E; --primary-hover: #7C360C; --on-primary: #FFFFFF; --primary-soft: #F8EBDD;
  --mark: #FCE3B0; --ring: #B45309;
}

/* Book font chosen in the reader (stored in localStorage "thq.readFont"). */
:root[data-read-font="amiri"] { --font-book: "Thq Amiri", serif; }
:root[data-read-font="scheherazade"] { --font-book: "Thq Scheherazade", serif; }
:root[data-read-font="sans"] { --font-book: "Thq Sans", sans-serif; }
:root[data-read-font="mosawi"] { --font-book: "Thq Mosawi", serif; }


/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + var(--tabs-h) + 16px); }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 400 16px/1.65 var(--font-ui);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
main { flex: 1; outline: none; }
h1, h2, h3, h4 { font-family: var(--font-read); font-weight: 700; line-height: 1.35; margin: 0; color: var(--ink); }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
img, svg { display: block; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--mark); color: var(--ink); }
.muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Fluid layout: content runs edge to edge; side gutters grow with the screen. */
.container { width: 100%; margin-inline: auto; padding-inline: clamp(16px, 3vw, 56px); }

.skip-link { position: absolute; inset-inline-start: 12px; top: -60px; z-index: var(--z-toast); background: var(--primary); color: var(--on-primary); padding: 8px 16px; border-radius: var(--radius-sm); }
.skip-link:focus { top: 12px; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-row { height: var(--header-h); display: flex; align-items: center; gap: var(--space-5); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
/* Calligraphic wordmark (img/logo-wordmark.png?v=f178ca72, 960×391, transparent) */
.brand-logo { height: 46px; width: auto; }
@media (max-width: 640px) { .brand-logo { height: 38px; } }
.hero-title { display: flex; justify-content: center; }
.hero-logo { height: clamp(80px, 10vw, 150px); width: auto; }
.main-nav { display: none; gap: 4px; margin-inline-start: var(--space-4); }
.main-nav a {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding-inline: 14px;
  border-radius: var(--radius-pill); color: var(--ink-2); font-weight: 500; font-size: 15px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.main-nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.main-nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.header-actions { margin-inline-start: auto; display: flex; gap: 8px; }
@media (min-width: 1024px) { .main-nav { display: flex; } }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-pill);
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn[aria-pressed="true"] { color: var(--primary); background: var(--primary-soft); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

body.is-reading .site-footer { display: none; }

/* ---------- buttons, inputs, chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field-label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.input, .select {
  width: 100%; min-height: 44px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder { color: var(--ink-3); }
.input:focus, .select:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }

.search-box { position: relative; display: flex; align-items: center; }
.search-box .icon { position: absolute; inset-inline-start: 16px; color: var(--ink-3); pointer-events: none; }
.search-box .input { padding-inline-start: 46px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border-radius: var(--radius-pill); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink-2); font-size: 14px; font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.chip[aria-pressed="true"], .chip.is-active { background: var(--bronze); border-color: var(--bronze); color: #FFFFFF; }
.chip .count { font-size: 12px; opacity: .75; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--ink-2); font-size: 13px; font-weight: 500; }
.badge-ok { background: color-mix(in srgb, #15803D 14%, var(--surface)); color: #166534; }

/* ---------- page scaffolding ---------- */
.page { padding-block: var(--space-6) var(--space-7); }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.page-title { font-size: clamp(26px, 4vw, 34px); }
.page-sub { color: var(--ink-2); margin-top: 6px; }
.section { margin-top: var(--space-7); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: var(--space-4); }
.section-title { font-size: 22px; }
.link-more { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 15px; }
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-3); margin-bottom: var(--space-4); }
.breadcrumb a { color: var(--ink-2); }

/* ---------- home ---------- */
.hero { padding-block: clamp(40px, 8vw, 88px) var(--space-6); text-align: center; }
.hero h1 { font-size: clamp(34px, 6vw, 56px); letter-spacing: 0; }
.hero p.lead { max-width: clamp(320px, 48vw, 860px); margin: 14px auto 0; color: var(--ink-2); font-size: 18px; }
.hero-search { max-width: clamp(320px, 56vw, 1100px); margin: var(--space-6) auto 0; }
.hero-search .search-row {
  display: flex; gap: 8px; padding: 8px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-md);
}
.hero-search .search-row:focus-within { border-color: var(--ring); }
.hero-search .search-box { flex: 1; }
.hero-search .input { border: 0; min-height: 48px; font-size: 17px; background: transparent; box-shadow: none; }
.hero-search .btn { min-height: 48px; border-radius: var(--radius); }
.scope { display: inline-flex; margin-top: 14px; padding: 4px; border-radius: var(--radius-pill); background: var(--surface-2); }
.scope button { min-height: 36px; padding: 0 16px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--ink-2); font-weight: 500; font-size: 14px; }
.scope button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 40px; margin-top: var(--space-6); }
.stat strong { display: block; font-family: var(--font-read); font-size: 28px; color: var(--ink); }
.stat span { font-size: 14px; color: var(--ink-3); }

.continue-card {
  display: flex; align-items: center; gap: 16px; padding: 16px 20px; border-radius: var(--radius-lg);
  background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent); color: var(--ink);
}
.continue-card:hover { text-decoration: none; border-color: var(--primary); }
.continue-card .grow { flex: 1; min-width: 0; }
.continue-card small { color: var(--ink-2); display: block; }
.continue-card strong { font-family: var(--font-read); font-size: 18px; }

.cat-grid { display: grid; gap: clamp(10px, 1vw, 20px); grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 13vw, 260px), 1fr)); }
.cat-card {
  display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.cat-card:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.cat-card .cat-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.cat-card strong { font-size: 16px; }
.cat-card span { font-size: 13px; color: var(--ink-3); }

/* ---------- book cards ---------- */
.book-grid { display: grid; gap: clamp(16px, 1.6vw, 32px) clamp(12px, 1.2vw, 28px); grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 11vw, 240px), 1fr)); }
.book-card { display: flex; flex-direction: column; gap: 10px; color: var(--ink); }
.book-card:hover { text-decoration: none; }
.book-card:hover .cover { box-shadow: var(--shadow-lg); transform: translateY(-3px); }
.book-card h3 { font-size: 16px; line-height: 1.45; }
.book-card .meta { font-size: 13px; color: var(--ink-3); }

.cover {
  --c1: #7C2D12; --c2: #9A3412;
  position: relative; aspect-ratio: 3 / 4; border-radius: 6px 12px 12px 6px; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; padding: 16px 14px 14px 18px;
  background: linear-gradient(160deg, var(--c1), var(--c2)); color: #FBF3E4;
  box-shadow: var(--shadow-md); transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.cover::before { content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; width: 8px; background: rgb(0 0 0 / .18); }
.cover::after { content: ""; position: absolute; inset: 10px 18px 10px 10px; border: 1px solid rgb(251 243 228 / .28); border-radius: 4px; pointer-events: none; }
.cover .cover-title { position: relative; font-family: var(--font-read); font-weight: 700; font-size: 19px; line-height: 1.45; text-wrap: balance; }
.cover .cover-author { position: relative; font-size: 12px; opacity: .85; }
.cover .cover-ornament { position: relative; width: 28px; height: 28px; opacity: .6; }
.cover[data-tone="1"] { --c1: #14532D; --c2: #166534; }
.cover[data-tone="2"] { --c1: #1E3A5F; --c2: #1E40AF; }
.cover[data-tone="3"] { --c1: #581C87; --c2: #6B21A8; }
.cover[data-tone="4"] { --c1: #3F3F46; --c2: #52525B; }
.cover[data-tone="5"] { --c1: #134E4A; --c2: #115E59; }
.cover[data-tone="6"] { --c1: #713F12; --c2: #854D0E; }

/* list view */
.book-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.book-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 14px; padding: 12px 16px; color: var(--ink); border-top: 1px solid var(--border); transition: background var(--dur) var(--ease); }
.book-row:first-child { border-top: 0; }
.book-row:hover { background: var(--surface-2); text-decoration: none; }
.book-row .mini-cover { width: 44px; aspect-ratio: 3/4; padding: 0; border-radius: 3px 6px 6px 3px; box-shadow: var(--shadow-sm); }
.book-row .mini-cover::after { inset: 4px 8px 4px 4px; }
.book-row h3 { font-size: 16px; }
.book-row .meta { font-size: 13px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.book-row .side { display: flex; align-items: center; gap: 8px; color: var(--ink-3); font-size: 13px; }
@media (max-width: 560px) { .book-row .side .badge:not(.badge-ok) { display: none; } }

/* ---------- catalog layout ---------- */
.catalog { display: grid; gap: var(--space-5); }
@media (min-width: 1024px) { .catalog { grid-template-columns: clamp(240px, 18vw, 340px) 1fr; align-items: start; } }
.filters { display: flex; flex-direction: column; gap: var(--space-5); padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
@media (min-width: 1024px) { .filters { position: sticky; top: calc(var(--header-h) + var(--tabs-h) + 16px); } }
.filter-group { display: flex; flex-direction: column; gap: 10px; }
.filter-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.filter-list button {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 12px; border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--ink-2); text-align: start; font-size: 15px;
}
.filter-list button:hover { background: var(--surface-2); color: var(--ink); }
.filter-list button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.filter-list .count { font-size: 12px; color: var(--ink-3); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; cursor: pointer; font-size: 15px; color: var(--ink-2); }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 99px; background: var(--border-strong); position: relative; cursor: pointer; transition: background var(--dur) var(--ease); flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(-18px); }
.filters-toggle { display: inline-flex; }
@media (min-width: 1024px) { .filters-toggle { display: none; } }
@media (max-width: 1023px) {
  .filters { position: fixed; inset: auto 0 0 0; z-index: var(--z-drawer); max-height: 85dvh; overflow: auto; border-radius: var(--radius-lg) var(--radius-lg) 0 0; transform: translateY(100%); transition: transform 240ms var(--ease); padding-bottom: calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow-lg); visibility: hidden; }
  .filters.is-open { transform: none; visibility: visible; }
}
.filters-head { display: flex; align-items: center; justify-content: space-between; }
@media (min-width: 1024px) { .filters-head .icon-btn { display: none; } }

.results-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: var(--space-4); }
.results-bar .count { color: var(--ink-2); font-size: 15px; }
.results-tools { display: flex; align-items: center; gap: 8px; }
.results-tools .select { width: auto; min-height: 40px; }
/* Phones: toolbar takes the full row and the sort menu shrinks, so nothing overflows. */
@media (max-width: 560px) {
  .results-tools { width: 100%; }
  .results-tools label { flex: 1; min-width: 0; }
  .results-tools .select { width: 100%; }
  .results-tools .btn { padding: 0 14px; }
}
.seg { display: inline-flex; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-2); }
.seg button { width: 38px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--ink-3); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: var(--space-6); }
.pagination .info { font-size: 14px; color: var(--ink-2); min-width: 110px; text-align: center; }

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: calc(var(--z-drawer) - 1); opacity: 0; visibility: hidden; transition: opacity 200ms var(--ease); }
.scrim.is-open { opacity: 1; visibility: visible; }

/* ---------- book detail ---------- */
.book-hero { display: grid; gap: var(--space-5); align-items: start; }
@media (min-width: 768px) { .book-hero { grid-template-columns: clamp(200px, 18vw, 320px) 1fr; gap: clamp(24px, 3vw, 56px); } }
.book-hero .cover { max-width: clamp(200px, 18vw, 320px); }
/* Real cover from the API (when the volume has one) sits over the generated cover. */
.cover-wrap { position: relative; max-width: clamp(200px, 18vw, 320px); }
.cover-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 6px 12px 12px 6px; box-shadow: var(--shadow-md); }
.book-hero .cover .cover-title { font-size: 24px; }
.book-hero h1 { font-size: clamp(28px, 4vw, 40px); }
.book-hero .byline { margin-top: 8px; font-size: 17px; color: var(--ink-2); }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 11vw, 220px), 1fr)); gap: 12px; margin-top: var(--space-5); }
.meta-item { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.meta-item dt { font-size: 13px; color: var(--ink-3); }
.meta-item dd { margin: 2px 0 0; font-weight: 600; }
.book-desc { margin-top: var(--space-5); font-family: var(--font-read); font-size: 18px; line-height: 1.9; color: var(--ink-2); max-width: 68ch; }
.book-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: var(--space-5); }

.vol-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: var(--space-4); scrollbar-width: thin; }
.vol-tabs .chip { flex: none; }
.toc { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.toc li + li { border-top: 1px solid var(--border); }
.toc a { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; color: var(--ink); font-family: var(--font-read); font-size: 17px; transition: background var(--dur) var(--ease); }
.toc a:hover { background: var(--surface-2); text-decoration: none; }
.toc .pg { font-family: var(--font-ui); font-size: 13px; color: var(--ink-3); flex: none; }

/* ---------- states ---------- */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: var(--space-7) var(--space-4); color: var(--ink-2); }
.state .state-icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-3); }
.state h3 { font-size: 20px; }
.state p { max-width: 420px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast { position: fixed; inset-inline: 0; bottom: calc(16px + env(safe-area-inset-bottom)); margin-inline: auto; width: max-content; max-width: calc(100% - 32px); z-index: var(--z-toast); padding: 12px 20px; border-radius: var(--radius-pill); background: var(--ink); color: var(--bg); font-weight: 500; box-shadow: var(--shadow-lg); animation: toast-in 200ms var(--ease); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- search ---------- */
.search-head { display: grid; gap: 12px; }
@media (min-width: 768px) { .search-head { grid-template-columns: 1fr auto; align-items: end; } }
.hint { font-size: 13px; color: var(--ink-3); }
.result-list { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.result { display: block; padding: 18px 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--ink); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.result:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.result-head strong { font-family: var(--font-read); font-size: 17px; }
.result-head .where { font-size: 13px; color: var(--ink-3); }
.result p { font-family: var(--font-book); font-size: 17px; line-height: 2; color: var(--ink-2); white-space: pre-line; }
.result p.result-section { font-family: var(--font-ui); font-size: 14px; line-height: 1.6; color: var(--primary); margin-bottom: 4px; white-space: normal; }
mark { background: var(--mark); color: var(--ink); border-radius: 3px; padding: 0 2px; }

/* ---------- reader ---------- */
.reader { display: grid; min-height: calc(100dvh - var(--header-h)); }
@media (min-width: 1100px) { .reader.has-sidebar { grid-template-columns: clamp(300px, 22vw, 420px) 1fr; } }
/* open books as tabs, like a browser */
/* Stays pinned under the site header; the reader toolbar sits right below it. */
:root { --tabs-h: 0px; }
body.has-book-tabs { --tabs-h: 48px; }
.book-tabs {
  position: sticky; top: var(--header-h); z-index: var(--z-sticky); height: var(--tabs-h);
  display: flex; align-items: stretch; gap: 2px; padding: 0 8px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.book-tabs::-webkit-scrollbar { display: none; }
.book-tabs[hidden] { display: none; }
.book-tab {
  flex: none; display: inline-flex; align-items: center; gap: 2px; padding-inline: 12px 4px;
  border-bottom: 2px solid transparent; color: var(--ink-2); font-size: 14px; white-space: nowrap;
}
.book-tab a { color: inherit; padding-block: 12px; }
.book-tab a:hover { text-decoration: none; color: var(--ink); }
.book-tab.is-active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.book-tab button { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: inherit; }
.book-tab button:hover { background: var(--surface-2); }
.book-tab-home { gap: 6px; padding-inline: 12px; color: var(--ink); font-weight: 600; border-inline-end: 1px solid var(--border); margin-inline-end: 4px; }
.book-tab-home:hover { text-decoration: none; background: var(--surface-2); }

.reader-bar {
  position: sticky; top: calc(var(--header-h) + var(--tabs-h)); z-index: calc(var(--z-sticky) - 1);
  display: flex; align-items: center; gap: 8px; min-height: 58px; padding: 6px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.bar-group { display: flex; align-items: center; gap: 2px; flex: none; }
.bar-title { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.bar-title strong { font-family: var(--font-read); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title .vol-chip { flex: none; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); font-size: 13px; color: var(--ink-2); }
.bar-title .vol-select { width: auto; min-height: 34px; padding-inline: 10px; font-size: 13px; }
/* Author beside the title, shown in full (wraps rather than being cut off) */
.bar-author { min-width: 0; font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.bar-author::before { content: "· "; }
.page-counter { flex: none; display: flex; align-items: center; gap: 2px; }
.page-counter .input { width: 58px; min-height: 38px; padding: 0 4px; text-align: center; }
.page-counter .total { padding-inline: 6px 2px; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
@media (max-width: 640px) { .bar-title { display: none; } .reader-bar { justify-content: space-between; } }
@media (max-width: 640px) { .reader-bar .hide-sm { display: none; } }

.reader-side {
  background: var(--surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
@media (min-width: 1100px) {
  .reader-side { position: sticky; top: calc(var(--header-h) + var(--tabs-h)); height: calc(100dvh - var(--header-h) - var(--tabs-h)); }
  .reader:not(.has-sidebar) .reader-side { display: none; }
}
@media (max-width: 1099px) {
  .reader-side { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(360px, 88vw); z-index: var(--z-drawer); transform: translateX(100%); transition: transform 240ms var(--ease); visibility: hidden; box-shadow: var(--shadow-lg); }
  .reader.has-sidebar .reader-side { transform: none; visibility: visible; }
}
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 12px 8px; border-bottom: 1px solid var(--border); }
.side-head h2 { font-size: 17px; padding-inline-start: 8px; }
.side-tabs { display: flex; gap: 4px; padding: 10px 12px 0; }
.side-tabs button { flex: 1; min-height: 38px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--ink-3); font-weight: 600; font-size: 14px; }
.side-tabs button[aria-selected="true"] { color: var(--primary); border-color: var(--primary); }
.side-body { flex: 1; overflow: auto; padding: 12px; }
.side-toc { list-style: none; margin: 0; padding: 0; }
.side-toc a { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--ink-2); font-family: var(--font-read); font-size: 15px; line-height: 1.6; }
.side-toc a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.side-toc a[aria-current="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-toc .pg { font-family: var(--font-ui); font-size: 12px; color: var(--ink-3); flex: none; padding-top: 3px; }
.side-results { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.side-results a { display: block; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--ink-2); font-family: var(--font-book); font-size: 15px; line-height: 1.8; }
.side-results a:hover { background: var(--surface-2); text-decoration: none; }
.side-results .pg { display: block; font-family: var(--font-ui); font-size: 12px; color: var(--ink-3); }

.reader-main { min-width: 0; display: flex; flex-direction: column; }
/* pages stacked in one continuous scroll, each spanning the full reading width */
.page-stack { display: flex; flex-direction: column; gap: 16px; padding: 16px; }
/* The reader pins the page being read itself (see reader.js); native anchoring would double-correct. */
body.is-reading, body.is-reading * { overflow-anchor: none; }
.sheet {
  width: 100%; padding: clamp(18px, 3vw, 36px) clamp(18px, 3.5vw, 48px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
@media (max-width: 640px) {
  .page-stack { padding: 0; gap: 8px; background: var(--surface-2); }
  .sheet { border-radius: 0; border-inline: 0; box-shadow: none; }
}
.stack-edge { height: 1px; }
.stack-edge.is-loading { height: 56px; border-radius: var(--radius-lg); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 10px; margin-bottom: 16px; border-bottom: 1px solid var(--border); color: var(--ink-3); font-size: 14px; }
.sheet-head .page-no { font-family: var(--font-read); font-weight: 700; font-size: 16px; color: var(--primary); }
.sheet-actions { display: flex; gap: 2px; }
.sheet-actions .icon-btn { width: 40px; height: 40px; }
.page-text { font-family: var(--font-book); font-size: var(--read-size); line-height: 2.1; color: var(--ink); text-align: justify; hyphens: none; }
.page-text p + p { margin-top: .6em; }
.page-text .page-heading { font-family: var(--font-book); font-size: 1.05em; font-weight: 700; color: var(--primary); text-align: center; margin: .4em 0 .7em; line-height: 1.8; }
.page-text .page-heading + p { margin-top: 0; }
.page-text .blank-page { color: var(--ink-3); text-align: center; font-size: .8em; }
.page-text .saying { display: inline-grid; place-items: center; min-width: 2.2em; height: 1.6em; padding: 0 .4em; margin-inline-end: .35em; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-family: var(--font-ui); font-size: .62em; font-weight: 700; vertical-align: .25em; }
.page-text .quran { color: var(--primary); }
.page-text .aside { color: var(--ink-2); }
.fn-ref { font-family: var(--font-ui); font-size: .55em; font-weight: 700; vertical-align: super; line-height: 0; padding: 0 2px; color: var(--primary); }
.fn-ref:hover { text-decoration: none; background: var(--primary-soft); border-radius: 4px; }
.notes { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); }
.notes h2 { font-family: var(--font-ui); font-size: 13px; font-weight: 700; color: var(--ink-3); margin-bottom: 10px; }
.notes ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.notes li { font-family: var(--font-book); font-size: calc(var(--read-size) * .74); line-height: 1.95; color: var(--ink-2); display: flex; gap: 8px; scroll-margin-top: 140px; }
.notes li .n { flex: none; font-family: var(--font-ui); font-size: 12px; font-weight: 700; color: var(--primary); min-width: 22px; padding-top: .35em; }
.notes li:target { background: var(--primary-soft); border-radius: var(--radius-sm); }
.notes li.cont .n { color: var(--ink-3); font-weight: 500; }


/* ---------- saved ---------- */
.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.saved-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.saved-item a.grow { flex: 1; min-width: 0; color: var(--ink); }
.saved-item a.grow:hover { text-decoration: none; }
.saved-item strong { font-family: var(--font-read); font-size: 17px; }
.saved-item p { font-family: var(--font-book); color: var(--ink-2); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item small { color: var(--ink-3); font-size: 13px; }

/* view transitions */
.fade-in { animation: fade-in 220ms var(--ease); }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* late additions */
.btn.is-disabled { opacity: .45; pointer-events: none; }
button.fn-ref { border: 0; background: none; margin: 0; cursor: pointer; font-family: var(--font-ui); }

/* Poetry: each verse on its own row, صدر on the right and عجز on the left, lined up in two columns */
.page-text .verse { display: grid; grid-template-columns: 1fr 1fr; gap: .1em 2em; margin-block: .15em; text-align: center; color: var(--ink); }
.page-text p:not(.verse) + .verse, .page-text .verse + p:not(.verse) { margin-top: .8em; }
.page-text .verse span:only-child { grid-column: 1 / -1; }
@media (max-width: 520px) {
  .page-text .verse { grid-template-columns: 1fr; gap: 0; margin-block: .45em; }
  .page-text .verse span:first-child { text-align: start; }
  .page-text .verse span:last-child:not(:only-child) { text-align: end; }
}

/* ---------- reader: font panel (size + book font) ---------- */
.reading-menu-wrap { position: relative; }
.reading-menu {
  position: absolute; top: calc(100% + 8px); inset-inline-start: 0; z-index: var(--z-drawer);
  width: min(300px, calc(100vw - 24px)); padding: 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.reading-menu[hidden] { display: none; }
.rm-size { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 10px; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--ink-2); }
.rm-size-controls { display: flex; align-items: center; gap: 2px; }
.rm-size output { min-width: 32px; text-align: center; font-weight: 700; color: var(--ink); }
.rm-fonts { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.rm-fonts button {
  display: grid; grid-template-columns: 1fr auto 20px; align-items: center; gap: 10px;
  min-height: 48px; padding: 6px 10px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink); text-align: start;
}
.rm-fonts button:hover { background: var(--surface-2); }
.rm-fonts button[aria-checked="true"] { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.rm-sample { font-size: 19px; line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm-name { font-size: 12px; color: var(--ink-3); }
.rm-check { color: var(--primary); visibility: hidden; }
.rm-fonts button[aria-checked="true"] .rm-check { visibility: visible; }

/* ---------- home: categories as a book's contents page ---------- */
:root { --toc-num: #B08D57; }
.rule-title { display: flex; align-items: center; gap: 16px; margin: 0 0 var(--space-4); color: var(--primary); font-size: 22px; }
.rule-title::before, .rule-title::after { content: ""; flex: 1; height: 1px; background: var(--border-strong); }
.toc-cats {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(260px, 30vw, 460px), 1fr)); column-gap: clamp(24px, 4vw, 72px);
}
.toc-cat {
  display: flex; align-items: baseline; gap: 14px; padding: 14px 4px;
  border-bottom: 1px solid var(--border); color: var(--ink);
  transition: color var(--dur) var(--ease);
}
.toc-cat:hover { text-decoration: none; color: var(--primary); }
.toc-cat .toc-t { transition: transform var(--dur) var(--ease); }
.toc-cat:hover .toc-t { transform: translateX(-6px); }
.toc-n { flex: none; min-width: 1.6em; font-size: 20px; color: var(--toc-num); }
.toc-t { flex: 1; font-size: 17px; line-height: 1.6; }
.toc-c { flex: none; font-size: 13px; color: var(--ink-3); }


/* =========================================================
   Warm library design (inspired by rafed.net): sand + cream bands,
   bronze accents, light photographic hero. The reader keeps its own palette.
   ========================================================= */
/* Header: light, original brown logo, bronze for the current page */
.site-header { background: color-mix(in srgb, var(--bg) 94%, transparent); border-bottom: 1px solid var(--border); }
.main-nav a { position: relative; color: var(--ink-2); background: transparent; border-radius: var(--radius-sm); }
.main-nav a:hover { color: var(--bronze); background: var(--surface-2); }
.main-nav a[aria-current="page"] { color: #FFFFFF; background: var(--bronze); font-weight: 700; }
.site-header .icon-btn { color: var(--ink); border: 1.5px solid var(--ink-2); width: 42px; height: 42px; }
.site-header .icon-btn:hover { background: var(--surface-2); }

/* Side menu (phones and tablets): slides in from the right edge */
.drawer { position: fixed; inset: 0; z-index: var(--z-drawer); visibility: hidden; transition: visibility 0s linear 260ms; }
.drawer.is-open { visibility: visible; transition: none; }
.drawer-scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity 220ms var(--ease); }
.drawer.is-open .drawer-scrim { opacity: 1; }
.drawer-panel {
  position: absolute; inset-block: 0; inset-inline-start: 0; width: min(320px, 86vw);
  display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform 260ms var(--ease);
}
.drawer.is-open .drawer-panel { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.drawer-logo { height: 44px; width: auto; }
.drawer-nav { display: flex; flex-direction: column; gap: 4px; }
.drawer-nav a {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding-inline: 14px; border-radius: var(--radius);
  color: var(--ink); font-size: 17px; font-weight: 500;
}
.drawer-nav a .icon { color: var(--bronze); }
.drawer-nav a:hover { background: var(--surface-2); text-decoration: none; }
.drawer-nav a[aria-current="page"] { background: var(--bronze); color: #FFFFFF; font-weight: 700; }
.drawer-nav a[aria-current="page"] .icon { color: #FFFFFF; }
.drawer-title { margin-top: 8px; font-size: 14px; font-weight: 700; color: var(--bronze); padding-inline: 14px; }
.drawer-cats { display: flex; flex-direction: column; }
.drawer-cats a { display: flex; align-items: center; min-height: 44px; padding-inline: 14px; color: var(--ink-2); border-bottom: 1px solid var(--border); }
.drawer-cats a:hover { color: var(--bronze); text-decoration: none; }
body.drawer-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .drawer, .drawer-scrim, .drawer-panel { transition: none; } }

/* Footer */
.site-footer { background: var(--band); color: var(--ink-2); border-top: 3px solid var(--bronze); font-size: 15px; }
.footer-grid {
  display: grid; gap: 32px clamp(24px, 4vw, 72px); padding-block: clamp(36px, 4vw, 56px);
  grid-template-columns: 1fr 1fr;
}
.footer-about { grid-column: 1 / -1; }
@media (min-width: 1024px) { .footer-grid { grid-template-columns: 1.6fr 1fr 1fr 1.2fr; } .footer-about { grid-column: auto; } }
.footer-app { grid-column: 1 / -1; }
@media (min-width: 1024px) { .footer-app { grid-column: auto; } }
.footer-app p { margin-bottom: 12px; }
.footer-app .store-badges { flex-direction: column; align-items: flex-start; }

/* Phones and tablets: no top bar. A floating glass button on the right opens the side menu. */
.menu-fab { display: none; }
@media (max-width: 1023px) {
  :root { --header-h: 0px; }
  .site-header { display: none; }
  .menu-fab {
    position: fixed; top: calc(14px + env(safe-area-inset-top)); inset-inline-start: 14px; z-index: calc(var(--z-drawer) - 1);
    display: grid; place-items: center; width: 50px; height: 50px; border-radius: 16px; color: var(--bronze);
    background: linear-gradient(160deg, rgb(255 255 255 / .82), rgb(244 232 218 / .62));
    border: 1px solid rgb(255 255 255 / .9);
    backdrop-filter: blur(10px) saturate(1.3); -webkit-backdrop-filter: blur(10px) saturate(1.3);
    box-shadow: inset 1px 1px 0 rgb(255 255 255 / .9), 0 8px 22px rgb(92 70 42 / .22);
    transition: transform 240ms var(--ease), opacity 240ms var(--ease), box-shadow var(--dur) var(--ease);
  }
  .menu-fab.is-away { transform: translateY(calc(-100% - 24px)); opacity: 0; pointer-events: none; }
  .menu-fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
  .menu-fab:hover { transform: translateY(-1px); box-shadow: inset 1px 1px 0 rgb(255 255 255 / .9), 0 12px 26px rgb(92 70 42 / .28); }
  .menu-fab:active { transform: scale(.95); }
  /* Keep page content and sticky bars clear of the button. */
  body:not(.is-home):not(.has-book-tabs) main > div > :first-child { padding-top: 78px; }
  body:not(.is-home) .book-tabs, body:not(.has-book-tabs) .reader-bar { padding-inline-start: 74px; }
  body.has-book-tabs .menu-fab { top: calc(2px + env(safe-area-inset-top)); width: 44px; height: 44px; border-radius: 14px; }
}
@media (prefers-reduced-motion: reduce) { .menu-fab { transition: none; } }

/* App download section and store buttons */
.app-promo { display: grid; gap: clamp(24px, 4vw, 64px); align-items: center; grid-template-columns: 1fr; }
@media (min-width: 900px) { .app-promo { grid-template-columns: 1fr 1.1fr; } }
.app-promo-text p { margin-top: 12px; max-width: 520px; font-size: clamp(16px, 1.3vw, 18px); line-height: 1.9; color: var(--ink-2); }
/* Home: a short text about the library (also read by search engines). */
.about-site { max-width: 820px; }
.about-site p { margin-top: 12px; font-size: clamp(16px, 1.3vw, 18px); line-height: 1.9; color: var(--ink-2); }
.app-promo-img { width: 100%; height: auto; border-radius: 24px; box-shadow: 0 14px 34px rgb(92 70 42 / .18); }
.store-badges { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.footer-app .store-badges { margin-top: 0; }
.store-badge {
  display: inline-flex; align-items: center; gap: 10px; min-width: 190px; min-height: 56px; padding: 8px 18px;
  border-radius: 14px; background: #1D2032; color: #FFFFFF; border: 1px solid #1D2032;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
a.store-badge:hover { text-decoration: none; background: #000000; transform: translateY(-2px); }
.store-icon { width: 26px; height: 26px; flex: none; }
.store-text { display: flex; flex-direction: column; line-height: 1.25; text-align: start; }
.store-text small { font-size: 12px; opacity: .85; }
.store-text strong { font-size: 18px; font-weight: 700; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; }
.store-badge.is-soon { background: transparent; color: var(--ink-2); border: 1.5px dashed var(--border-strong); cursor: default; }
.footer-logo { height: 64px; width: auto; margin-bottom: 14px; }
.footer-about p { max-width: 560px; line-height: 1.9; }
.footer-col h2 { font-size: 17px; font-weight: 700; color: var(--bronze); margin-bottom: 12px; }
.footer-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.footer-col a { display: inline-flex; align-items: center; min-height: 36px; color: var(--ink-2); }
.footer-col a:hover { color: var(--bronze); }
.footer-bottom { border-top: 1px solid var(--border-strong); font-size: 14px; color: var(--ink-3); }
.footer-bottom-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 24px; padding-block: 16px; }

/* Buttons */
.btn-gold { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-gold:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline-gold { background: rgb(255 255 255 / .6); border-color: var(--bronze); color: var(--gold-text); }
.btn-outline-gold:hover { background: var(--surface-2); }

/* ---------- home: banner (layout of rafed.net) ---------- */
.rf-banner {
  position: relative; isolation: isolate; overflow: hidden;
  display: flex; align-items: center;
  background: var(--band) url("../img/news/hero-hall.jpg?v=b0e4a3e7") center / cover no-repeat;
  text-align: center;
}
.rf-banner::before { content: ""; position: absolute; inset: 0; z-index: -1; background: radial-gradient(ellipse 46% 42% at 50% 34%, rgb(253 252 249 / .7), transparent), linear-gradient(to bottom, rgb(253 252 249 / .25), rgb(244 232 218 / .55)); }
/* One spacing value for everything in the hero: top edge, logo, tagline, search, panel, bottom edge. */
.rf-banner { --hero-gap: clamp(16px, 1.8vw, 24px); }
.rf-banner-inner { display: flex; flex-direction: column; align-items: center; gap: var(--hero-gap); padding-block: var(--hero-gap); }
.rf-title { display: flex; flex-direction: column; align-items: center; gap: var(--hero-gap); font-size: clamp(15px, 1.3vw, 18px); font-weight: 700; line-height: 1.5; color: var(--ink); }
.rf-logo { height: clamp(72px, 8vw, 116px); width: auto; }
.rf-stats { margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--ink-2); min-height: 1.6em; }

/* Glass search bar */
.rf-search {
  display: flex; align-items: stretch; width: min(600px, 100%); height: 58px; margin: 0;
  border-radius: 999px; overflow: hidden;
  background: rgb(255 255 255 / .38); border: 1px solid rgb(255 255 255 / .75);
  backdrop-filter: blur(6px) saturate(1.2); -webkit-backdrop-filter: blur(6px) saturate(1.2);
  box-shadow: -1px -1px 0 rgb(255 255 255 / .6), 0 10px 30px rgb(92 70 42 / .12);
}
.rf-search-field { flex: 1; display: flex; }
.rf-search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 24px; font-size: 16px; color: var(--ink); outline: none; }
.rf-search input::placeholder { color: var(--ink-2); }
.rf-search:focus-within { border-color: var(--bronze); }
.rf-search button {
  display: grid; place-items: center; width: 64px; border: 0; background: transparent; color: var(--ink);
}
.rf-search button .icon { width: 26px; height: 26px; stroke-width: 2; }
.rf-search button:hover { background: rgb(255 255 255 / .6); color: var(--bronze); }

/* Glass panel with glossy category tiles (drag or swipe sideways) */
.rf-panel {
  width: min(940px, 100%); margin: 0; padding: 12px 16px;
  border-radius: 26px; background: rgb(255 255 255 / .28); border: 1px solid rgb(255 255 255 / .75);
  backdrop-filter: blur(6px) saturate(1.2); -webkit-backdrop-filter: blur(6px) saturate(1.2);
  box-shadow: -1px -1px 0 rgb(255 255 255 / .6), 0 14px 34px rgb(92 70 42 / .12);
}
.rf-tiles {
  display: grid; grid-auto-flow: column; grid-auto-columns: 124px; gap: 4px;
  overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; overscroll-behavior-x: contain;
}
.rf-tiles::-webkit-scrollbar { display: none; }
.rf-tile { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 4px; scroll-snap-align: start; color: #000; border-radius: 16px; }
.rf-tile:hover { text-decoration: none; background: rgb(255 255 255 / .35); }
.rf-tile-icon {
  width: 72px; height: 72px; display: grid; place-items: center; border-radius: 18px; color: var(--bronze);
  background: linear-gradient(160deg, rgb(255 255 255 / .85), rgb(244 232 218 / .7));
  border: 1px solid rgb(255 255 255 / .3);
  box-shadow: -1px -1px 0 rgb(255 255 255 / .75), .8px .8px 0 rgb(255 255 255 / .25), 0 6px 14px rgb(92 70 42 / .14);
  transition: transform var(--dur) var(--ease);
}
.rf-tile-icon .icon { width: 34px; height: 34px; stroke-width: 1.5; }
.rf-tile:hover .rf-tile-icon { transform: translateY(-2px); }
.rf-tile-label { font-size: clamp(13px, 1.05vw, 16px); font-weight: 600; line-height: 1.5; }

/* ---------- sideways rows (like the site's sliders) ---------- */
.rf-head { display: flex; align-items: center; gap: clamp(12px, 2vw, 28px); margin-bottom: var(--space-5); }
.rf-head .section-title { flex: none; white-space: nowrap; }
.rf-head-line { flex: 1; height: 3px; border-radius: 3px; background: var(--bronze); opacity: .75; }
.rf-head .link-more { flex: none; font-size: clamp(16px, 1.3vw, 19px); font-weight: 700; color: var(--bronze); }
.rf-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: clamp(140px, 12vw, 186px); gap: clamp(16px, 2vw, 30px);
  overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; overscroll-behavior-x: contain;
  padding: 6px 2px 18px; cursor: grab;
  margin-inline-end: calc(-1 * clamp(16px, 3vw, 56px)); padding-inline-end: clamp(16px, 3vw, 56px);
}
.rf-row::-webkit-scrollbar { display: none; }
.rf-row > * { scroll-snap-align: start; }
.rf-row.is-dragging { cursor: grabbing; scroll-snap-type: none; }
.rf-row.is-dragging * { pointer-events: none; }
.rf-row.is-wide { grid-auto-columns: clamp(240px, 21vw, 290px); }
.rf-row .book-card .cover { box-shadow: 8px 8px 8.3px rgb(0 0 0 / .25); border-radius: 12px; }
.rf-row .book-card:hover .cover { transform: translateY(-3px); box-shadow: 10px 12px 14px rgb(0 0 0 / .25); }
.rf-row .book-card h3 { font-size: 16px; font-weight: 300; min-height: 3.2em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rf-row .book-card .meta { color: #0076A8; }
/* News cards */
.rf-news {
  display: flex; flex-direction: column; gap: 14px; padding: 0 0 16px; scroll-snap-align: start;
  background: var(--surface); border-radius: 24px; overflow: hidden; box-shadow: 0 8px 22px rgb(92 70 42 / .10);
}
.rf-news-img { display: block; aspect-ratio: 16 / 10; overflow: hidden; background: var(--surface-3); }
.rf-news-img img { width: 100%; height: 100%; object-fit: cover; transition: transform 400ms var(--ease); }
.rf-news:hover .rf-news-img img { transform: scale(1.04); }
.rf-news h3 { padding-inline: 18px; font-size: 17px; font-weight: 700; line-height: 1.7; text-align: center; min-height: 3.4em; }
.rf-news h3 a { color: var(--ink); }
.rf-news h3 a:hover { color: var(--bronze); text-decoration: none; }
.rf-news h3 + .rf-news-date { margin-top: -8px; }
.rf-news-date { text-align: center; font-size: 13px; color: var(--ink-3); }
.rf-news-ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--bronze); background: linear-gradient(160deg, var(--surface-2), var(--surface-3)); }

/* News list and post page */
.news-tabs { margin-bottom: var(--space-5); }
.news-grid { display: grid; gap: clamp(16px, 2vw, 30px); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.post-page { max-width: 860px; padding-block: clamp(24px, 4vw, 48px); }
.post-crumbs { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-3); margin-bottom: 16px; }
.post-crumbs a { color: var(--gold-text); }
.post-head h1 { font-size: clamp(24px, 3vw, 34px); line-height: 1.6; color: var(--ink); }
.post-head p { margin-top: 6px; }
.post-image { width: 100%; max-height: 480px; object-fit: cover; border-radius: 24px; margin-top: 24px; box-shadow: 0 8px 22px rgb(92 70 42 / .12); }
.post-summary { margin-top: 24px; font-size: 19px; font-weight: 700; line-height: 1.9; color: var(--ink-2); }
.post-body { margin-top: 16px; font-size: 18px; line-height: 2; }
.post-body p + p { margin-top: 1em; }
.post-actions { margin-top: 28px; }
.rf-news-foot { display: flex; align-items: center; gap: 12px; padding-inline: 18px; margin-top: auto; }
.rf-pill { flex: 1; display: grid; place-items: center; height: 44px; border-radius: 999px; background: var(--surface-3); color: var(--gold-text); font-weight: 700; font-size: 15px; }
.rf-go { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--bronze); color: #FFFFFF; }
.rf-go:hover { background: var(--primary-hover); }
.band .continue-card { margin-bottom: var(--space-6); }

@media (max-width: 767px) {
  .rf-banner { background-position: center; background-image: url("../img/news/hero-hall-sm.jpg?v=2f116a6b"); }
  .rf-search { height: 54px; }
  .rf-panel { padding: 10px 8px; border-radius: 20px; }
  .rf-tiles { grid-auto-columns: 96px; }
  .rf-tile-icon { width: 60px; height: 60px; border-radius: 16px; }
  .rf-tile-icon .icon { width: 28px; height: 28px; }
}
@media (prefers-reduced-motion: reduce) { .rf-news-img img { transition: none; } }

/* ---------- home: full-width bands alternating sand and cream ---------- */
.band { background: var(--band); padding-block: clamp(32px, 4vw, 56px); }
.band-alt { background: var(--bg); }
.band .section:first-child { margin-top: 0; }
.section-head { margin-bottom: var(--space-5); }
.section-title { color: var(--bronze); font-size: clamp(20px, 1.6vw, 24px); font-weight: 700; }
.link-more { color: var(--gold-text); font-weight: 600; }
.rule-title { color: var(--bronze); }
.rule-title::before, .rule-title::after { background: var(--border-strong); }
.continue-card { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.continue-card .icon-lg { color: var(--bronze); }
.toc-cat { border-bottom-color: var(--border); }
:root { --toc-num: var(--bronze); }

/* Book covers: large, rounded, titles underneath (like a shelf row) */
.book-grid { grid-template-columns: repeat(auto-fill, minmax(clamp(130px, 11.5vw, 186px), 1fr)); gap: 28px clamp(14px, 1.4vw, 22px); }
.book-card .cover { border-radius: 13px; box-shadow: 0 6px 16px rgb(92 70 42 / .16); }
.book-card:hover .cover { box-shadow: 0 14px 30px rgb(92 70 42 / .24); transform: translateY(-4px); }
.book-card h3 { font-size: 16px; font-weight: 400; color: var(--ink); line-height: 1.6; }
.book-card .meta { color: var(--ink-3); }
.book-card > div { text-align: center; }
.cover::after { border-color: rgb(232 214 180 / .45); border-radius: 8px; }
.cover .cover-ornament { color: #E8D6B4; opacity: .8; }
/* Leather tones that sit well on sand */
.cover { --c1: #5C3A22; --c2: #7A5030; color: #F6EAD2; }
.cover[data-tone="1"] { --c1: #2F4A3A; --c2: #40634E; }
.cover[data-tone="2"] { --c1: #2B3A55; --c2: #3C4F72; }
.cover[data-tone="3"] { --c1: #6B2E26; --c2: #8A4034; }
.cover[data-tone="4"] { --c1: #3E3A36; --c2: #58524B; }
.cover[data-tone="5"] { --c1: #245052; --c2: #316A6B; }
.cover[data-tone="6"] { --c1: #8B6F4D; --c2: #A88A5E; }

/* Search: the result you opened last, and the reader's way back to the list */
.result-list a.result.is-last { border-color: var(--bronze); box-shadow: 0 0 0 2px color-mix(in srgb, var(--bronze) 30%, transparent); }
.back-results { min-height: 40px; padding: 0 12px 0 14px; gap: 4px; font-size: 14px; border-color: var(--bronze); color: var(--gold-text); background: var(--surface); margin-inline-end: 4px; }
.back-results:hover { background: var(--surface-2); }
@media (max-width: 360px) { .back-results span { display: none; } .back-results { padding: 0 10px; } }

/* iPhone Safari zooms into any field whose text is smaller than 16px: keep fields at 16px on touch screens. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px !important; }
}

/* Desktop menu has 7 items: on smaller laptops drop the icons to keep one line. */
@media (min-width: 1024px) and (max-width: 1279px) {
  .main-nav a { padding-inline: 10px; font-size: 14px; }
  .main-nav a .icon { display: none; }
}

/* Authors */
.author-search { max-width: 560px; margin-bottom: 8px; }
.author-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 0 32px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.author-item { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px; border-bottom: 1px solid var(--border); color: var(--ink); }
.author-item:hover { text-decoration: none; color: var(--bronze); }
.author-name { flex: 1; min-width: 0; font-weight: 600; line-height: 1.6; }
.author-death { flex: none; font-size: 13px; color: var(--ink-3); }
.author-item .icon { flex: none; color: var(--ink-3); }
.load-more { display: flex; justify-content: center; margin-top: 24px; }

/* Search: text / table-of-contents tabs, and more options */
.search-modes { margin-bottom: 16px; }
.search-more { grid-column: 1 / -1; }
.search-more summary { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; color: var(--gold-text); font-weight: 600; }
.search-more-fields { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); padding-top: 4px; }
.result-heading { font-size: 18px; font-weight: 700; color: var(--bronze); margin-top: 6px; }
.search-head .search-more { order: 4; }
.search-head > .btn-primary { order: 5; }
@media (min-width: 768px) { .search-head .search-more, .search-head > .btn-primary { order: 0; } }

/* ---------- reading themes (page colour), chosen in the reader's font menu ---------- */
:root[data-read-theme="paper"] body.is-reading {
  --bg: #FFFFFF; --surface: #FFFFFF; --surface-2: #F4F4F2; --surface-3: #EAEAE6;
  --ink: #111111; --ink-2: #3F3F3F; --ink-3: #5F5F5F; --border: #E4E4E0; --border-strong: #CFCFC9;
  --primary: #7A4A12; --primary-hover: #633B0D; --primary-soft: #F5ECE0; --mark: #FBE3A6;
}
:root[data-read-theme="focus"] body.is-reading {
  --bg: #E9E6DF; --surface: #F6F4EF; --surface-2: #E2DED5; --surface-3: #D8D3C8;
  --ink: #000000; --ink-2: #2E2E2E; --ink-3: #4F4B45; --border: #D5D0C5; --border-strong: #BEB7A9;
  --primary: #5A3B12; --primary-hover: #452D0E; --primary-soft: #E8DFD0; --mark: #F2D98C;
}
:root[data-read-theme="calm"] body.is-reading {
  --bg: #1E1A16; --surface: #28231E; --surface-2: #312B25; --surface-3: #3B342D;
  --ink: #E9DDC8; --ink-2: #CDBFA7; --ink-3: #A99B85; --border: #3E372F; --border-strong: #52483D;
  --primary: #D9A864; --primary-hover: #E6BC80; --on-primary: #1E1A16; --primary-soft: #3A2E20; --mark: #6A5021; --ring: #D9A864;
  color-scheme: dark;
}
:root[data-read-theme="dark"] body.is-reading {
  --bg: #000000; --surface: #0A0A0A; --surface-2: #121212; --surface-3: #1B1B1B;
  --ink: #B9B9B9; --ink-2: #999999; --ink-3: #7A7A7A; --border: #202020; --border-strong: #2E2E2E;
  --primary: #C49A5E; --primary-hover: #D6B07A; --on-primary: #000000; --primary-soft: #1F190F; --mark: #4B3A16; --ring: #C49A5E;
  color-scheme: dark;
}
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading .site-header { background: color-mix(in srgb, var(--bg) 94%, transparent); }
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading .main-nav a:not([aria-current]) { color: var(--ink-2); }
.rm-themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 12px; }
.rm-themes button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 2px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; font-size: 11px; color: var(--ink-2); line-height: 1.3;
}
.rm-themes button[aria-checked="true"] { border-color: var(--primary); color: var(--ink); font-weight: 700; }
.rm-swatch { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-book); font-size: 16px; border: 1px solid rgb(0 0 0 / .15); }
.rm-swatch-original { background: #FBF8F1; color: #1C1917; }
.rm-swatch-paper { background: #FFFFFF; color: #111111; }
.rm-swatch-focus { background: #E9E6DF; color: #000000; }
.rm-swatch-calm { background: #28231E; color: #E9DDC8; }
.rm-swatch-dark { background: #000000; color: #B9B9B9; }

/* ---------- highlights and notes in the reader ---------- */
.hl { border-radius: 3px; cursor: pointer; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hl-yellow { background: rgb(250 214 90 / .55); }
.hl-green { background: rgb(134 212 150 / .5); }
.hl-blue { background: rgb(128 190 240 / .5); }
.hl-pink { background: rgb(242 150 190 / .5); }
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) .hl { color: #111111; }
.hl.has-note { text-decoration: underline dotted; text-decoration-thickness: 2px; text-underline-offset: .35em; }
.hl.is-flash { animation: hl-flash 1.6s var(--ease) 2; }
@keyframes hl-flash { 50% { box-shadow: 0 0 0 4px var(--ring); } }
.hl-bar {
  position: fixed; z-index: calc(var(--z-drawer) + 1); display: flex; align-items: center; gap: 4px; padding: 6px;
  border-radius: 999px; background: #1D2032; color: #FFFFFF; box-shadow: 0 10px 28px rgb(0 0 0 / .28);
}
.hl-bar[hidden] { display: none; }
.hl-bar button { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 10px; border: 0; border-radius: 999px; background: transparent; color: inherit; font-size: 13px; }
.hl-bar button:hover { background: rgb(255 255 255 / .12); }
.hl-bar .hl-dot { width: 30px; min-height: 30px; padding: 0; border: 2px solid rgb(255 255 255 / .85); }
.hl-bar .hl-yellow { background: #F5CE4A; } .hl-bar .hl-green { background: #6CC486; } .hl-bar .hl-blue { background: #6DAEE6; } .hl-bar .hl-pink { background: #EE8DB7; }
.hl-sep { width: 1px; height: 22px; background: rgb(255 255 255 / .25); margin-inline: 2px; }
@media (max-width: 420px) { .hl-bar button span { display: none; } .hl-bar button { padding: 0 8px; } }
.note-dialog { border: 0; border-radius: 20px; padding: 24px; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.note-dialog::backdrop { background: var(--scrim); }
.note-dialog h2 { font-size: 20px; color: var(--primary); margin-bottom: 10px; }
.note-quote { margin: 0 0 14px; padding: 10px 14px; border-inline-start: 4px solid var(--primary); background: var(--surface-2); border-radius: 8px; font-family: var(--font-book); font-size: 17px; line-height: 1.9; max-height: 9em; overflow: auto; }
.note-dialog textarea.input { padding-block: 12px; line-height: 1.8; resize: vertical; }
.note-dialog .editor-actions { display: flex; gap: 10px; margin-top: 14px; }

/* Contents list filter */
.toc-filter { display: flex; margin-bottom: 10px; }
.side-toc li[hidden] { display: none; }

/* Search: recent searches and opened results */
.recent-searches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.recent-searches .field-label { margin-inline-end: 4px; }
.recent-searches .chip small { color: var(--ink-3); margin-inline-start: 4px; }
.result.is-opened { background: var(--surface-2); }
.opened-tag { display: inline-flex; align-items: center; gap: 4px; margin-inline-start: 8px; padding: 0 8px; height: 22px; border-radius: 999px; background: var(--primary-soft); color: var(--gold-text); font-size: 12px; font-weight: 700; vertical-align: middle; }

/* Saved: highlights and notes list */
.saved-hl { border-inline-start: 4px solid #F5CE4A; }
.saved-hl.c-green { border-inline-start-color: #6CC486; } .saved-hl.c-blue { border-inline-start-color: #6DAEE6; } .saved-hl.c-pink { border-inline-start-color: #EE8DB7; }
.saved-hl blockquote { margin: 6px 0 0; font-family: var(--font-book); font-size: 17px; line-height: 1.9; color: var(--ink); }
.saved-hl .saved-note { margin-top: 6px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); font-size: 15px; white-space: pre-wrap; }
/* Touch screens: the highlight bar sits under the reading toolbar, away from the phone's own menu. */
.hl-bar.is-docked { animation: hl-dock-in 180ms var(--ease); }
@keyframes hl-dock-in { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .hl-bar.is-docked { animation: none; } }

/* ---------- glass: popups and floating buttons share the look of the home page's category panel ---------- */
:root {
  --glass-bg: linear-gradient(160deg, rgb(255 255 255 / .78), rgb(244 232 218 / .6));
  --glass-border: rgb(255 255 255 / .9);
  --glass-ink: var(--ink);
  --glass-shadow: inset 1px 1px 0 rgb(255 255 255 / .9), 0 14px 34px rgb(92 70 42 / .2);
  --glass-blur: blur(14px) saturate(1.3);
}
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading {
  --glass-bg: linear-gradient(160deg, rgb(60 52 44 / .72), rgb(30 26 22 / .62));
  --glass-border: rgb(255 255 255 / .14);
  --glass-shadow: inset 1px 1px 0 rgb(255 255 255 / .12), 0 14px 34px rgb(0 0 0 / .45);
}
.toast, .hl-bar, .reading-menu, .note-dialog, .drawer-panel, .back-results, .admin-dialog {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--glass-ink);
  box-shadow: var(--glass-shadow);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.toast { font-weight: 700; }
.hl-bar button:hover { background: rgb(255 255 255 / .5); }
.hl-bar .hl-dot { border-color: rgb(255 255 255 / .95); box-shadow: 0 1px 3px rgb(0 0 0 / .18); }
.hl-sep { background: var(--border-strong); }
.hl-bar button:not(.hl-dot) .icon { color: var(--primary); }
.drawer-panel { border-block: 0; border-inline-end: 0; }
.rm-fonts button:hover, .rm-themes button:hover { background: rgb(255 255 255 / .45); }
.rm-fonts button[aria-checked="true"] { background: rgb(255 255 255 / .6); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .toast, .hl-bar, .reading-menu, .note-dialog, .drawer-panel, .back-results, .admin-dialog { background: var(--surface); }
}

/* "عع" text-size button (big and small ʿayn), and ع small / ع big for making text smaller / larger.
   Same size as the 20px icons beside it, in the site's interface font. */
.ain-icon { display: inline-flex; align-items: baseline; justify-content: center; gap: 1px; height: 20px; color: currentColor; font-family: var(--font-ui); font-weight: 400; line-height: 20px; }
.ain-icon .ain-big { font-size: 20px; }
.ain-icon .ain-small { font-size: 14px; }
.ain { color: currentColor; font-family: var(--font-ui); font-weight: 400; line-height: 20px; height: 20px; }
.ain.ain-small { font-size: 14px; }
.ain.ain-big { font-size: 20px; }

/* Home: keep "المكتبة الحسينية" on one line in its tile; smaller tagline on phones */
.rf-tile-label-long { white-space: nowrap; font-size: clamp(12px, .92vw, 14px); }
@media (max-width: 767px) {
  .rf-tile-label-long { font-size: 11.5px; }
  .rf-title { font-size: clamp(11px, 3.3vw, 13px); }
}

/* Quick filters: language of the books and Shia books only (search page and books page) */
.search-quick { grid-column: 1 / -1; order: 3; }
@media (min-width: 768px) { .search-quick { order: 0; } }
.catalog-search { display: grid; gap: 14px; margin: 12px 0 20px; }
/* Same pill as the home page search, with more glass since it sits on plain paper here */
.catalog-search .rf-search { width: min(720px, 100%); margin: 0; background: var(--glass-bg); border-color: var(--border-strong); box-shadow: var(--glass-shadow); }
.catalog-search .rf-search:focus-within { border-color: var(--bronze); }
/* Masked filled icons (e.g. المكتبة الحسينية): no outline, a touch larger so the dome reads like the line icons */
.icon.icon-masked { stroke: none; transform: scale(1.12); }

/* ---------- feedback page ---------- */
.main-nav .nav-extra { display: none; }
.feedback-page { max-width: 820px; }
.feedback-form { display: grid; gap: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: clamp(18px, 3vw, 32px); box-shadow: var(--shadow-sm); }
.feedback-form .field b, .pick-group legend b { color: var(--danger); }
.pick-group { border: 0; margin: 0; padding: 0; }
.pick-group legend { font-size: 15px; font-weight: 700; color: var(--ink); margin-bottom: 10px; }
.picks { display: flex; flex-wrap: wrap; gap: 8px; }
.pick { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; background: var(--surface); }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick:has(input:checked) { background: var(--bronze); border-color: var(--bronze); color: #FFFFFF; font-weight: 700; }
.pick:has(input:focus-visible) { outline: 3px solid var(--ring); outline-offset: 2px; }
.stars { display: inline-flex; gap: 4px; }
.star { cursor: pointer; font-size: 30px; line-height: 1; color: var(--border-strong); min-width: 40px; min-height: 44px; display: grid; place-items: center; }
.star input { position: absolute; opacity: 0; pointer-events: none; }
/* The checked star and the ones before it light up */
.stars:has(.star:nth-child(1) input:checked) .star:nth-child(-n+1),
.stars:has(.star:nth-child(2) input:checked) .star:nth-child(-n+2),
.stars:has(.star:nth-child(3) input:checked) .star:nth-child(-n+3),
.stars:has(.star:nth-child(4) input:checked) .star:nth-child(-n+4),
.stars:has(.star:nth-child(5) input:checked) .star:nth-child(-n+5) { color: #E0A93B; }
.star:has(input:focus-visible) { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 8px; }
.feedback-form textarea.input { padding-block: 12px; line-height: 1.8; resize: vertical; }
.feedback-form .field-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.feedback-form .btn-primary { justify-self: start; min-width: 160px; }
.hp { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.feedback-done { background: var(--surface); border: 1px solid var(--border); border-radius: 24px; }
/* Top bar, far left: feedback button (the top bar only shows on computers) */
.header-feedback { min-height: 40px; padding: 0 16px; gap: 6px; font-size: 14px; border: 1.5px solid var(--bronze); color: var(--bronze); background: var(--glass-bg); box-shadow: var(--glass-shadow); white-space: nowrap; }
.header-feedback:hover { background: var(--bronze); color: #FFFFFF; text-decoration: none; }
.header-feedback[aria-current] { background: var(--bronze); color: #FFFFFF; }

/* ---------- every search box: the home page's glass pill (text on the right, magnifier on the left) ---------- */
.search-box .input {
  min-height: 58px; border-radius: 999px; padding-inline: 24px 58px; font-size: 16px;
  background: var(--glass-bg); border: 1px solid var(--border-strong); box-shadow: var(--glass-shadow);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.search-box .input:focus { border-color: var(--bronze); box-shadow: var(--glass-shadow), 0 0 0 3px color-mix(in srgb, var(--bronze) 22%, transparent); }
.search-box .input::placeholder { color: var(--ink-2); }
.search-box .icon { inset-inline-start: auto; inset-inline-end: 22px; z-index: 1; width: 24px; height: 24px; stroke-width: 2; color: var(--ink); }
/* Smaller pill inside the reader's side panel */
.reader-side .search-box .input { min-height: 46px; padding-inline: 18px 48px; }
.reader-side .search-box .icon { inset-inline-end: 16px; width: 20px; height: 20px; }

/* Text options menu: fully opaque (no glass) so the options read clearly over the page */
.reading-menu { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; border-color: var(--border-strong); }

/* Hover tooltips: the button's name, in a small paper pill with a bronze edge */
.tooltip {
  position: fixed; z-index: calc(var(--z-toast) + 1); max-width: min(240px, calc(100vw - 16px));
  padding: 5px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap;
  background: var(--surface); color: var(--bronze); border: 1px solid var(--border-strong);
  box-shadow: 0 6px 16px rgb(92 70 42 / .14);
  font: 700 13px/1.5 var(--font-ui);
  animation: tip-in 120ms var(--ease);
}
.tooltip[hidden] { display: none; }
@keyframes tip-in { from { opacity: 0; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .tooltip { animation: none; } }

/* Search boxes: the magnifier always sits vertically centred at the left end */
.search-box .icon { top: 50%; transform: translateY(-50%); }

/* ---------- top bar: liquid glass (computers; phones have no top bar) ---------- */
.site-header {
  background: linear-gradient(180deg, rgb(255 255 255 / .62), rgb(255 255 255 / .34));
  backdrop-filter: blur(22px) saturate(1.8); -webkit-backdrop-filter: blur(22px) saturate(1.8);
  border-bottom: 1px solid rgb(255 255 255 / .75);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / .95),        /* bright top edge */
    inset 0 -1px 0 rgb(176 141 87 / .18),         /* soft bronze underline */
    0 10px 30px rgb(92 70 42 / .10);
}
.site-header::after { /* a faint sheen across the glass */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 20%, rgb(255 255 255 / .28) 45%, transparent 60%);
}
.site-header .header-row { position: relative; z-index: 1; }
.main-nav a:not([aria-current]):hover { background: rgb(255 255 255 / .55); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header { background: color-mix(in srgb, var(--bg) 96%, transparent); }
}
/* Home: the photo runs up under the glass bar so the effect shows */
@media (min-width: 1024px) {
  body.is-home main { margin-top: calc(-1 * var(--header-h)); }
  body.is-home .rf-banner-inner { padding-top: calc(var(--hero-gap) + var(--header-h)); }
}
/* Reading themes that darken the page keep a dark glass bar */
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading .site-header {
  background: linear-gradient(180deg, rgb(40 35 30 / .72), rgb(20 18 15 / .55));
  border-bottom-color: rgb(255 255 255 / .12);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .12), 0 10px 30px rgb(0 0 0 / .35);
}
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading .site-header::after { opacity: .25; }

/* ---------- one glass for the whole site: 4px blur, 15% white (no extra colour boost) ---------- */
:root { --glass-bg: rgb(255 255 255 / .15); --glass-blur: blur(4px); }
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading { --glass-bg: rgb(20 18 15 / .15); }
.site-header,
.rf-search, .rf-panel, .catalog-search .rf-search,
.rf-tile-icon, .menu-fab {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
}
.site-header::after { content: none; } /* no extra sheen on top of the glass */
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading .site-header { background: var(--glass-bg); }

/* ---------- page colours taken from the hero photo (warm sand), so the page continues it ---------- */
:root {
  --bg: #F5ECE0;          /* cream band */
  --band: #E8D8C3;        /* sand band, a lighter step of the photo's wall #CFB598 */
  --surface-2: #F1E5D4;
  --surface-3: #E6D5BF;
  --border: #DFCDB5;
  --border-strong: #CDB696;
}
/* Safari takes its toolbar colour from the page background: use the sand of the hero so its bars match the page
   (in the reader, the reading theme's colour stays). */
html:not(:has(body.is-reading)) { background: var(--band); }
/* Hero: 20% white haze over the photo */
.rf-banner::before { content: none; } /* no haze: the photo shows as it is */

/* ---------- book covers: leather with gold tooling, no text (title and author sit underneath) ---------- */
.cover { padding: 0; color: #D9BE86; border-radius: 4px 10px 10px 4px;
  background: radial-gradient(ellipse 80% 60% at 40% 35%, rgb(255 255 255 / .10), transparent 70%), linear-gradient(150deg, var(--c2), var(--c1)); }
.cover::before, .cover::after { content: none; }
.cover .cover-art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cover { --c1: #182246; --c2: #2B3A6B; }                 /* navy */
.cover[data-tone="1"] { --c1: #1D3B27; --c2: #2E5A3C; }   /* green */
.cover[data-tone="2"] { --c1: #3E3B1D; --c2: #5E5A2E; }   /* olive */
.cover[data-tone="3"] { --c1: #1A3C42; --c2: #2B5B62; }   /* teal */
.cover[data-tone="4"] { --c1: #5A3818; --c2: #84562C; }   /* brown */
.cover[data-tone="5"] { --c1: #4A1C22; --c2: #6E2E35; }   /* maroon */
.cover[data-tone="6"] { --c1: #2B2724; --c2: #48413A; }   /* charcoal */
/* List view: the small covers carry the same gold design, a little larger and with bolder lines */
.book-row .mini-cover { width: 52px; }
.book-row .mini-cover .cover-art g { stroke-width: 1.8; }

/* Top bar: 15% glass at the top of the page, 80% white once the page scrolls */
.site-header { transition: background-color 200ms var(--ease); }
body.is-scrolled .site-header { background: rgb(255 255 255 / .8); }
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) body.is-reading.is-scrolled .site-header { background: rgb(20 18 15 / .8); }

/* Grid view: plain gold frame, the book's title in the middle of the cover */
.cover-titled { container-type: inline-size; }
.cover-titled .cover-name {
  position: absolute; top: 14%; bottom: 14%; left: 14%; right: 22.4%; /* centred in the gold frame (x 8–102 of 120), clear of the braided spine */
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: var(--font-read); font-weight: 700; font-size: clamp(11px, 9.2cqw, 20px); line-height: 1.55;
  color: #E8D6B4; text-shadow: 0 1px 2px rgb(0 0 0 / .35);
}
.cover-titled .cover-name > span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; overflow: hidden; text-wrap: balance; }


/* Hero a little taller at the bottom (the sections below move down with it) */
.rf-banner-inner { padding-bottom: calc(var(--hero-gap) + clamp(32px, 4.5vw, 64px)); }

/* هامش (page footnotes): keep line breaks inside one note */
.notes li > span:last-child { white-space: pre-line; }

/* هامش: small and quiet — a thin rule, a tiny label, small text, numbers inline */
.notes { margin-top: 18px; padding-top: 8px; border-top: 1px solid var(--border); width: 55%; border-top-width: 1px; }
.notes h2 { display: none; }
.notes ol { gap: 3px; }
.notes li { font-size: calc(var(--read-size) * .6); line-height: 1.75; color: var(--ink-3); gap: 5px; }
.notes li .n { font-size: .85em; font-weight: 600; min-width: 0; padding-top: 0; color: var(--ink-3); }
.notes li .n::after { content: "-"; margin-inline-start: 3px; }
.notes li:target { background: none; color: var(--ink); }
.notes li.cont .n::after { content: ""; }
@media (max-width: 640px) { .notes { width: 70%; } }

/* هامش text is always 2px smaller than the main text (it follows the reader's font size) */
.notes li { font-size: calc(var(--read-size) - 2px); }
.notes, .notes li { /* at this size the notes use the full page width */ }
.notes { width: auto; }
@media (max-width: 640px) { .notes { width: auto; } }

/* هامش text: the deep teal of the app's footnotes (#1A514E), lighter in the two dark reading themes */
.notes li, .notes li .n { color: #1A514E; }
.notes li:target { color: #1A514E; }
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) .notes li,
:root:is([data-read-theme="calm"], [data-read-theme="dark"]) .notes li .n { color: #7FC4BE; }

/* Phones: the book's info (title, volume, author) shows in the reading bar, on its own row under the buttons */
@media (max-width: 640px) {
  .reader-bar { flex-wrap: wrap; row-gap: 2px; }
  .reader-bar .bar-title {
    display: flex; order: 3; flex: 1 0 100%; justify-content: flex-start; flex-wrap: nowrap;
    padding-top: 4px; border-top: 1px solid var(--border);
  }
  .reader-bar .bar-title strong { font-size: 15px; flex: 0 1 auto; min-width: 0; }
  .reader-bar .bar-title .vol-select { min-height: 30px; }
  .reader-bar .bar-title .bar-author.hide-sm { display: inline; flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; }
}

/* Side menu (phones and tablets): 50% see-through white */
.drawer-panel { background: rgb(255 255 255 / .5); }
@media (max-width: 640px) {
  .reader-bar .bar-title { flex-wrap: wrap; row-gap: 0; }
  .reader-bar .bar-title .bar-author.hide-sm { flex: 1 0 100%; white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.5; }
  .reader-bar .bar-title .bar-author::before { content: none; }
}

/* «رأيك يهمنا» in the top bar: always 80% opaque */
.header-feedback, .header-feedback:hover, .header-feedback[aria-current] { opacity: .8; }

/* News cards: one fixed size on every screen — the size they have on a laptop (290px wide, image 290×181) */
.rf-row.is-wide { grid-auto-columns: 290px; }
.news-grid { grid-template-columns: repeat(auto-fill, 290px); justify-content: start; }
.rf-news { width: 290px; }
.rf-news-img { width: 290px; height: 181px; aspect-ratio: auto; }
@media (max-width: 767px) { .news-grid { justify-content: center; } }

/* ---------- search scope («نطاق البحث») ---------- */
.scope { margin-top: 16px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; display: grid; gap: 10px; }
.scope-title { font-size: 15px; font-weight: 700; color: var(--bronze); }
.scope-row { align-items: center; }
.scope-btn { min-height: 40px; gap: 8px; }
.scope-btn.has-value { background: var(--bronze); border-color: var(--bronze); color: #FFFFFF; }
.scope-btn.has-value:hover { background: var(--primary-hover); }
.scope-count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--bronze); color: #FFFFFF; font-size: 12px; font-weight: 700; }
.scope-btn.has-value .scope-count { background: #FFFFFF; color: var(--bronze); }
/* a chosen filter is filled bronze; «كل اللغات» (no language filter) stays a soft tint */
.scope .chip[aria-pressed="true"] { background: var(--bronze); border-color: var(--bronze); color: #FFFFFF; }
.scope .chip.is-default[aria-pressed="true"] { background: var(--surface-3); border-color: var(--border-strong); color: var(--ink-2); }
.scope-count[hidden] { display: none; }
.scope-count-row { font-size: 14px; color: var(--ink-2); }
.scope-count-row strong { color: var(--bronze); }
.scope-count-row strong.is-zero { color: #A3282A; }
.scope-summary { margin-top: 12px; align-items: center; }
.scope-summary:empty { display: none; }
.scope-chip { gap: 2px; padding-inline-end: 4px; }
.scope-chip .icon-btn { width: 28px; height: 28px; color: inherit; }
.scope-clear { min-height: 36px; padding: 0 12px; }

.picker {
  border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100% - 24px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
.picker::backdrop { background: var(--scrim); }
.picker-form { display: flex; flex-direction: column; gap: 12px; padding: 18px; max-height: min(82dvh, 720px); }
.picker-head { display: flex; align-items: center; justify-content: space-between; }
.picker-head h2 { font-size: 19px; color: var(--bronze); }
.picker .search-box .input { min-height: 46px; }
.picker-body { flex: 1; min-height: 140px; overflow-y: auto; overscroll-behavior: contain; }
.picker-body ul { list-style: none; margin: 0; padding: 0; }
.picker-group { font-size: 13px; font-weight: 700; color: var(--bronze); margin: 12px 0 2px; }
.picker-item { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 6px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.picker-item:hover { background: var(--surface-2); }
.picker-item input { width: 20px; height: 20px; flex: none; accent-color: var(--bronze); }
.picker-name { flex: 1; min-width: 0; line-height: 1.5; }
.picker-meta { flex: none; max-width: 40%; text-align: end; color: var(--ink-3); font-size: 13px; }
.picker-body .btn { margin-top: 12px; }
.picker-foot { display: flex; flex-wrap: wrap; gap: 10px; }

/* ✕ clear button inside search boxes (the browser's own one is hidden so there is only one) */
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search-box, .rf-search-field { position: relative; }
.clear-btn {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  inset-inline-end: 54px; width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); cursor: pointer;
}
.clear-btn:hover { background: rgb(0 0 0 / .07); color: var(--ink); }
.clear-btn[hidden] { display: none; }
.search-box.has-clear .input { padding-inline-end: 92px; }
.rf-search-field .clear-btn { inset-inline-end: 6px; }
.reader-side .search-box .clear-btn { inset-inline-end: 46px; }
.reader-side .search-box.has-clear .input { padding-inline-end: 80px; }

/* Search results: the number is bold and clear */
.result-count { margin-bottom: 12px; font-size: 15px; color: var(--ink-2); }
.result-count strong { font-weight: 800; font-size: 17px; color: var(--ink); }

/* Pagination with 5-page jumps */
.pagination { flex-wrap: wrap; }
.pagination .page-jump { gap: 2px; padding-inline: 12px; }
.pagination .page-jump .icon { margin-inline: -3px; }
.rf-search .clear-btn { width: 32px; height: 32px; background: transparent; color: var(--ink-3); }
.rf-search .clear-btn:hover { background: rgb(0 0 0 / .07); color: var(--ink); }
.result-count strong { font-size: 16px; }

/* Search page: «بحث» and «مسح البحث» side by side */
.search-actions { display: flex; gap: 8px; }
.search-actions .btn-primary { flex: 1; }
.search-actions [hidden] { display: none; }
@media (max-width: 767px) { .search-head > .search-actions { order: 5; } }

/* Books page: «مسح البحث» beside the search pill */
.catalog-search-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.catalog-search-row .rf-search { flex: 1 1 280px; max-width: 720px; }
.catalog-search-row [hidden] { display: none; }

/* The ✕ inside the clear button: centred in its circle (the search-box icon rules placed it like the magnifier) */
.search-box .clear-btn .icon, .rf-search .clear-btn .icon, .reader-side .search-box .clear-btn .icon {
  position: static; inset: auto; transform: none; width: 18px; height: 18px; stroke-width: 2; color: inherit;
}

/* «بحث» and «مسح البحث» are as tall as the search bar beside them */
.search-actions .btn, .catalog-search-row > .btn { min-height: 58px; padding-inline: 26px; }

/* Search by meaning: a short note under the count, and the passage clamped to a few lines */
.meaning-note { margin: -4px 0 14px; font-size: 14px; color: var(--ink-3); }
.result p.result-passage { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; overflow: hidden; white-space: normal; }

/* ---------- account: sign in, devices ---------- */
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-account { min-height: 40px; padding: 0 16px; gap: 6px; font-size: 14px; border: 1.5px solid var(--bronze); color: #FFFFFF; background: var(--bronze); white-space: nowrap; opacity: .9; }
.header-account:hover, .header-account[aria-current] { background: var(--bronze); color: #FFFFFF; opacity: 1; text-decoration: none; }
.account-body { display: grid; gap: 18px; max-width: 640px; }
.account-card { display: grid; gap: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: clamp(18px, 3vw, 30px); box-shadow: var(--shadow-sm); }
.account-card .btn-primary { justify-self: start; min-width: 180px; }
.account-title { display: flex; align-items: center; gap: 8px; font-size: 19px; color: var(--bronze); }
.account-hint { font-size: 14px; }
.account-row { display: flex; flex-wrap: wrap; gap: 8px; }
.code-input { font-size: 26px; letter-spacing: .5em; text-align: center; max-width: 280px; font-variant-numeric: tabular-nums; }
.device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.device { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.device:last-child { border-bottom: 0; }
.device-name { display: grid; gap: 2px; }
.device-name small { font-size: 13px; }
.account-danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.account-danger .account-title { color: var(--danger); }
.account-danger form { display: grid; gap: 12px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #FFFFFF; justify-self: start; }
.btn-danger:hover { filter: brightness(.9); }
.form-error { color: var(--danger); font-weight: 600; }
.form-error:empty { display: none; }
/* Narrower screens: the account button is a round icon (its name shows on hover) so the menu keeps one line */
@media (max-width: 1359px) {
  .header-account { width: 40px; padding: 0; justify-content: center; border-radius: 50%; }
  .header-account span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* Fifth highlight colour (the iPhone app has five) */
.hl-purple { background: rgb(186 150 230 / .5); }
.hl-bar .hl-purple { background: #B48FE0; }
.saved-hl.c-purple { border-inline-start-color: #B48FE0; }
.account-choice { display: grid; gap: 12px; padding: 16px; border-radius: 18px; background: var(--surface-2); }
.account-choice[hidden] { display: none; }

/* ---------- study sessions ---------- */
.session-new { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.session-new .grow { flex: 1 1 240px; }
.session-list, .session-books, .session-found, .session-notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.session-item, .session-book { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; }
.session-book { background: var(--surface-2); }
.session-item .grow, .session-book .grow { display: grid; gap: 2px; min-width: 0; color: var(--ink); text-decoration: none; }
.session-item strong { font-size: 17px; }
.session-tools { display: flex; gap: 2px; }
.session-find { display: grid; gap: 10px; }
.session-found li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.session-found .grow { flex: 1 1 200px; }
.session-vol { display: flex; gap: 8px; flex: 1 0 100%; }
.session-vol select { max-width: 180px; }
.session-folder { display: flex; align-items: center; gap: 6px; font-size: 15px; color: var(--bronze); margin-top: 6px; }
.session-note { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); display: grid; gap: 4px; }
.session-note p { white-space: pre-line; color: var(--ink-2); font-size: 15px; line-height: 1.8; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; overflow: hidden; }
.session-hint { font-size: 13px; }
.saved-sessions { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; padding: 16px 18px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); color: var(--ink); text-decoration: none; }
.saved-sessions:hover { border-color: var(--bronze); text-decoration: none; }
.saved-sessions > span { flex: 1; display: grid; gap: 2px; }
.saved-sessions > .icon:first-child { color: var(--bronze); }
.reader-session { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px; background: var(--bronze); color: #FFFFFF; font-size: 13px; text-decoration: none; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.reader-session:hover { color: #FFFFFF; text-decoration: none; filter: brightness(1.08); }

/* ---------- the assistant (chat) ---------- */
.chat { display: grid; gap: 18px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) { .chat { grid-template-columns: 260px 1fr; } }
.chat-side { display: grid; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; }
@media (min-width: 900px) { .chat-side { position: sticky; top: calc(var(--header-h) + 16px); max-height: calc(100dvh - var(--header-h) - 32px); overflow-y: auto; } }
.chat-convs { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.chat-convs li { display: flex; align-items: center; gap: 2px; border-radius: 12px; }
.chat-convs li.is-active { background: var(--surface-2); }
.chat-convs a { flex: 1; min-width: 0; padding: 10px 10px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-convs .icon-btn { width: 32px; height: 32px; opacity: .55; }
.chat-convs li:hover .icon-btn, .chat-convs li.is-active .icon-btn { opacity: 1; }
.chat-main { display: grid; gap: 14px; min-width: 0; }
.chat-log { display: grid; gap: 14px; min-height: 280px; align-content: start; }
.chat-intro { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 40px 16px; color: var(--ink-2); }
.chat-intro .icon { color: var(--bronze); }
.chat-msg { padding: 14px 18px; border-radius: 20px; line-height: 1.9; max-width: 100%; overflow-wrap: anywhere; }
.chat-msg.is-user { justify-self: start; max-width: 85%; background: var(--bronze); color: #FFFFFF; border-end-start-radius: 6px; white-space: pre-line; }
.chat-msg.is-bot { background: var(--surface); border: 1px solid var(--border); border-end-end-radius: 6px; }
.chat-msg.is-error { background: #FBE9E9; color: var(--danger); display: grid; gap: 8px; justify-items: start; }
.chat-answer { font-family: var(--font-read); font-size: 17px; }
.chat-answer :is(h3, h4, h5, h6) { margin: .6em 0 .3em; color: var(--bronze); font-size: 1.05em; }
.chat-answer p { margin: 0 0 .6em; }
.chat-answer :is(ul, ol) { margin: 0 0 .6em; padding-inline-start: 1.4em; }
.chat-answer .cite { font-size: .8em; font-weight: 700; color: var(--bronze); text-decoration: none; vertical-align: super; padding: 0 1px; }
.chat-step { font-size: 14px; color: var(--ink-3); animation: chat-pulse 1.4s ease-in-out infinite; }
@keyframes chat-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .chat-step { animation: none; } }
.chat-sources { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.chat-sources summary { cursor: pointer; font-weight: 700; color: var(--bronze); font-size: 14px; }
.chat-sources ol { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.chat-sources li { padding: 10px 12px; border-radius: 14px; background: var(--surface-2); transition: box-shadow .3s; }
.chat-sources li.is-flash { box-shadow: 0 0 0 2px var(--bronze); }
.chat-sources a { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--ink); text-decoration: none; }
.chat-sources a:hover strong { color: var(--bronze); }
.chat-sources p { margin-top: 4px; font-family: var(--font-book); font-size: 15px; color: var(--ink-2); line-height: 1.8; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }
.chat-ask { position: sticky; bottom: 0; display: grid; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 22px; box-shadow: var(--shadow-sm); }
.chat-ask textarea { resize: vertical; min-height: 64px; line-height: 1.8; padding-block: 10px; font-size: 16px; }
.chat-ask-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.chat-ask-row .btn-primary, .chat-ask-row [data-action="stop"] { margin-inline-start: auto; min-width: 110px; }
.chat-count, .chat-quota { font-size: 13px; }
.chat-note { font-size: 12px; }
.chat-ask [hidden] { display: none; }

/* ---------- the iPhone app's highlight colours (brief 2, 3.2): washes over the page, same in every theme ---------- */
.hl-yellow { background: rgb(255 204 0 / .45); }
.hl-green { background: rgb(51 199 89 / .35); }
.hl-blue { background: rgb(10 133 255 / .35); }
.hl-pink { background: rgb(255 46 84 / .35); }
.hl-purple { background: rgb(176 82 222 / .35); }
.hl-bar .hl-yellow { background: #FFCC00; } .hl-bar .hl-green { background: #33C759; } .hl-bar .hl-blue { background: #0A85FF; }
.hl-bar .hl-pink { background: #FF2E54; } .hl-bar .hl-purple { background: #B052DE; }
.hl-swatch { flex: none; width: 14px; height: 14px; border-radius: 50%; }
.hl-sw-yellow { background: #FFCC00; } .hl-sw-green { background: #33C759; } .hl-sw-blue { background: #0A85FF; } .hl-sw-pink { background: #FF2E54; } .hl-sw-purple { background: #B052DE; }

/* ---------- numbered marks (4.2): a grey wash over the text, a number badge in a left gutter ---------- */
::highlight(nm-wash) { background-color: rgb(153 153 153 / .30); }
.sheet { position: relative; }
.sheet.has-marks .page-text { padding-left: 24px; }
.nm-layer { position: absolute; inset: 0; pointer-events: none; }
.nm-badge {
  position: absolute; height: 18px; padding: 0; border: 0; border-radius: 9px; pointer-events: auto; cursor: pointer;
  background: #A6450F; color: #FFFFFF; font: 700 11px/18px system-ui, -apple-system, sans-serif; text-align: center;
  font-variant-numeric: tabular-nums; direction: ltr;
}
.nm-badge.is-flash { animation: hl-flash 1.6s var(--ease) 2; }
.nm-capsule { flex: none; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; background: #A6450F; color: #FFFFFF; font: 700 12px/20px system-ui, sans-serif; text-align: center; direction: ltr; }
.picker-sheet { border: 0; border-radius: 22px; padding: 22px; width: min(440px, calc(100% - 32px)); box-shadow: var(--shadow-lg); background: var(--surface); color: var(--ink); }
.picker-sheet::backdrop { background: var(--scrim); }
.picker-sheet h2 { font-size: 19px; margin-bottom: 12px; color: var(--bronze); }
.mark-options { display: grid; gap: 6px; margin-bottom: 12px; max-height: 50vh; overflow-y: auto; }
.mark-option { display: grid; gap: 2px; text-align: start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--ink); cursor: pointer; font: inherit; }
.mark-option:hover { border-color: var(--bronze); background: var(--surface-2); }
.mark-option small { color: var(--ink-3); }
.mark-option.is-danger strong { color: var(--danger); }
.mark-group { font-size: 13px; font-weight: 700; color: var(--bronze); margin: 8px 4px 2px; }

/* ---------- notes ---------- */
.notes-body { max-width: 780px; }
.notes-folders { flex-wrap: wrap; }
.notes-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.notes-search .input { min-height: 50px; }
.notes-pickbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 16px; background: var(--surface-2); }
.notes-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.note-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.note-row .grow { display: grid; gap: 2px; min-width: 0; color: var(--ink); text-decoration: none; }
.note-row strong, .note-row small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--bronze); }
.note-read { padding: clamp(16px, 3vw, 28px); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; font-family: var(--font-read); font-size: 18px; line-height: 1.9; }
.note-line { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-line.is-empty { height: .9em; }
.note-line.is-flash { animation: hl-flash 1.6s var(--ease) 2; border-radius: 6px; }
.note-num { font-weight: 800; color: #A6440F; text-decoration: none; margin-inline-end: 4px; }
.note-num:hover { text-decoration: underline; }
.note-cite { font-size: .82em; color: var(--ink-3); }
.note-editor { min-height: 320px; padding: 16px; line-height: 1.9; font-family: var(--font-read); font-size: 18px; resize: vertical; }
.note-hint { font-size: 13px; }

/* ---------- lists: highlights, numbered marks, bookmarks ---------- */
.list-book { display: grid; gap: 8px; margin-bottom: 18px; }
.list-book-title { font-size: 16px; color: var(--bronze); }
.list-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.list-row .grow { display: grid; gap: 2px; min-width: 0; color: var(--ink); text-decoration: none; font-family: var(--font-read); }
.list-row .grow span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.list-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--bronze); }

/* ---------- tool tiles (a session; «المحفوظات») ---------- */
.session-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.session-tile { display: flex; align-items: center; gap: 10px; padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); color: var(--ink); text-decoration: none; font-weight: 700; }
.session-tile:hover { border-color: var(--bronze); text-decoration: none; }
.session-tile .icon { color: var(--bronze); }
.saved-tiles { margin-bottom: 26px; }

/* Top bar with 10 sections: icons only on wide screens; narrower laptops keep every name on one line */
@media (min-width: 1024px) and (max-width: 1599px) {
  .site-header .header-row { gap: 12px; }
  .main-nav { gap: 2px; margin-inline-start: 4px; }
  .main-nav a { padding-inline: 9px; font-size: 14px; gap: 6px; }
  .main-nav a .icon { display: none; }
}
@media (min-width: 1024px) and (max-width: 1365px) {
  .brand-logo { height: 40px; }
  .main-nav a { padding-inline: 7px; font-size: 13px; height: 36px; }
  .header-feedback { width: 40px; padding: 0; justify-content: center; border-radius: 50%; }
  .header-feedback > :not(.icon) { display: none; }
  .header-feedback { font-size: 0; }
  .header-feedback .icon { font-size: 14px; }
}

/* ---------- «جلسة علم»: a grid of sessions, each a small pile of its books ---------- */
.sessions-page .account-body, .notes-page .notes-body { max-width: none; }
.sess-grid { display: grid; gap: clamp(16px, 1.6vw, 26px); grid-template-columns: repeat(auto-fill, minmax(clamp(200px, 16vw, 250px), 1fr)); }
.sess-card { position: relative; display: grid; gap: 10px; align-content: start; padding: 16px; border-radius: 22px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.sess-card:hover { border-color: var(--bronze); box-shadow: 0 12px 28px rgb(92 70 42 / .14); }
.sess-open { display: grid; gap: 6px; color: var(--ink); text-decoration: none; }
.sess-open:hover { text-decoration: none; }
.sess-open h3 { font-size: 17px; line-height: 1.5; margin-top: 6px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.sess-open .meta { font-size: 13px; color: var(--ink-3); }
.sess-pile { position: relative; height: 170px; border-radius: 16px; background: linear-gradient(180deg, var(--surface-2), var(--surface-3)); overflow: hidden; }
.sess-pile-book { position: absolute; bottom: 14px; width: 92px; inset-inline-start: calc(50% - 46px + (var(--i) - (var(--n) - 1) / 2) * 42px); transform: rotate(calc((var(--i) - (var(--n) - 1) / 2) * 7deg)); transform-origin: bottom center; z-index: var(--i); }
.sess-pile-book .cover { border-radius: 8px; box-shadow: 0 8px 18px rgb(0 0 0 / .25); }
.sess-pile-book .cover-name { font-size: 11px; }
.sess-pile-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--border-strong); }
.sess-tools { display: flex; justify-content: center; gap: 2px; }
.sess-tools .icon-btn { width: 34px; height: 34px; }
.sess-new { border-style: dashed; border-width: 2px; background: transparent; box-shadow: none; justify-items: stretch; }
.sess-new-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; background: var(--bronze); color: #FFFFFF; justify-self: center; margin-top: 6px; }
.sess-new .btn { justify-self: stretch; }
.sess-empty { margin-top: 18px; }

/* one session */
.sess-head-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.sess-head-tools .muted { margin-inline-end: auto; font-weight: 600; }
.sess-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 30px; }
.sess-tile { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 16px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); color: var(--ink); text-decoration: none; box-shadow: var(--shadow-sm); }
.sess-tile:hover { border-color: var(--bronze); text-decoration: none; }
.sess-tile-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--surface-2); color: var(--bronze); }
.sess-tile-label { font-weight: 700; }
.sess-tile-count { min-width: 28px; height: 28px; padding: 0 8px; display: grid; place-items: center; border-radius: 999px; background: var(--bronze); color: #FFFFFF; font-size: 13px; font-weight: 700; }
.sess-books { align-items: start; }
.sess-book { gap: 8px; }
.sess-book-open { display: flex; flex-direction: column; gap: 8px; color: var(--ink); text-decoration: none; }
.sess-book-open:hover { text-decoration: none; }
.sess-book-open:hover .cover { transform: translateY(-3px); }
.sess-book .cover { transition: transform var(--dur) var(--ease); }
.sess-book .cover.skeleton { aspect-ratio: 3 / 4; border-radius: 13px; }
.sess-progress { justify-self: start; align-self: flex-start; padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--bronze) 14%, transparent); color: var(--bronze); font-size: 12px; font-weight: 700; }
.sess-progress.is-new { background: var(--surface-2); color: var(--ink-3); }
.sess-book .sess-tools { justify-content: flex-start; }
.sess-add { aspect-ratio: 3 / 4; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 14px; border: 2px dashed var(--border-strong); border-radius: 13px; background: transparent; color: var(--bronze); font: inherit; font-weight: 700; text-align: center; cursor: pointer; }
.sess-add:hover, .sess-add[aria-expanded="true"] { border-color: var(--bronze); background: var(--surface); }
.sess-add .icon { width: 32px; height: 32px; }
.sess-find { display: grid; gap: 12px; margin-top: 20px; padding: 18px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); }
.sess-find[hidden] { display: none; }
.sess-found { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.sess-found li { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 10px; border-radius: 16px; background: var(--surface-2); }
.sess-found .mini-cover { width: 44px; flex: none; }
.sess-found .grow { flex: 1 1 140px; display: grid; gap: 2px; min-width: 0; }
.sess-found strong { font-size: 15px; line-height: 1.5; }
.sess-vol { display: flex; gap: 8px; flex: 1 0 100%; }
.sess-vol select { max-width: 160px; }

/* ---------- «الملاحظات»: folders and notes as cards ---------- */
.folder-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.folder-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); color: var(--ink); text-decoration: none; font: inherit; text-align: start; cursor: pointer; }
.folder-card:hover { border-color: var(--bronze); text-decoration: none; }
.folder-card .icon { flex: none; color: var(--bronze); }
.folder-card span { display: grid; gap: 1px; min-width: 0; }
.folder-card strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-card small { color: var(--ink-3); font-size: 12px; }
.folder-card.is-active { background: var(--bronze); border-color: var(--bronze); color: #FFFFFF; }
.folder-card.is-active .icon, .folder-card.is-active small { color: #FFFFFF; }
.folder-new { border-style: dashed; border-width: 2px; background: transparent; color: var(--bronze); }
.notes-tools { align-items: center; margin-bottom: 14px; }
.notes-tools .notes-search { flex: 1 1 260px; }
.note-grid { display: grid; gap: clamp(14px, 1.4vw, 22px); grid-template-columns: repeat(auto-fill, minmax(clamp(220px, 18vw, 280px), 1fr)); }
.note-card { position: relative; display: grid; grid-template-rows: 1fr auto; min-height: 220px; padding: 18px 18px 12px; border-radius: 6px 18px 18px 6px; background: #FFFDF8; border: 1px solid var(--border); border-inline-end: 6px solid var(--bronze); box-shadow: 0 8px 20px rgb(92 70 42 / .10); transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.note-card:hover { transform: translateY(-3px); box-shadow: 0 14px 28px rgb(92 70 42 / .16); }
.note-card.is-picked { outline: 3px solid var(--bronze); }
.note-open { display: grid; gap: 8px; align-content: start; color: var(--ink); text-decoration: none; min-width: 0; }
.note-open:hover { text-decoration: none; }
.note-open strong { font-size: 17px; line-height: 1.5; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.note-open p { font-family: var(--font-read); font-size: 15px; line-height: 1.85; color: var(--ink-2); white-space: pre-line; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden; }
.note-card footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); }
.note-card footer small { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.note-order { display: flex; }
.note-order .icon-btn { width: 30px; height: 30px; }
.note-pick { position: absolute; top: 12px; inset-inline-start: 12px; width: 22px; height: 22px; accent-color: var(--bronze); z-index: 1; }
.note-card:has(.note-pick) .note-open { padding-inline-start: 30px; }
.note-new { grid-template-rows: auto auto; place-content: center; justify-items: center; gap: 10px; border: 2px dashed var(--border-strong); border-inline-end-width: 2px; background: transparent; box-shadow: none; color: var(--bronze); font: inherit; cursor: pointer; }
.note-new:hover { border-color: var(--bronze); background: var(--surface); }
.notes-empty { margin-top: 16px; }

/* «المحفوظات»: the same paper cards as «الملاحظات» */
.saved-page .saved-tiles { margin-bottom: 26px; }
.saved-page .section-head { margin-bottom: 14px; }
.saved-card { min-height: 170px; }
.saved-place { color: var(--bronze); font-size: 13px; font-weight: 700; }
.saved-card-note { font-family: var(--font-ui) !important; font-size: 14px !important; color: var(--ink) !important; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); -webkit-line-clamp: 3 !important; }
.saved-go { display: grid; place-items: center; width: 30px; height: 30px; color: var(--bronze); }
.saved-tiles .folder-card strong { white-space: normal; line-height: 1.4; }

/* «كل التظليلات» / «كل الإشارات المرقّمة»: the same paper cards, the stripe in the highlight's colour */
.list-back { margin-bottom: 8px; padding-inline: 12px; }
.lists-page .account-body { max-width: none; }
.lists-page .list-book { margin-bottom: 28px; }
.lists-page .list-book-title { font-size: 18px; margin-bottom: 4px; }
.list-card { min-height: 170px; }
.list-card .note-open p { font-family: var(--font-book); font-size: 16px; }
.list-card-head { display: flex; align-items: center; gap: 10px; }
.list-card-icon { color: var(--bronze); display: inline-flex; }
.list-card.c-yellow { border-inline-end-color: #FFCC00; } .list-card.c-green { border-inline-end-color: #33C759; }
.list-card.c-blue { border-inline-end-color: #0A85FF; } .list-card.c-pink { border-inline-end-color: #FF2E54; } .list-card.c-purple { border-inline-end-color: #B052DE; }
/* The way back to «المحفوظات» (or the session): a clear bronze pill */
.list-back {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin-bottom: 14px; padding: 0 18px 0 14px;
  border: 1.5px solid var(--bronze); border-radius: 999px; background: var(--surface); color: var(--bronze);
  font-weight: 700; font-size: 15px; box-shadow: var(--shadow-sm);
}
.list-back .icon { width: 20px; height: 20px; stroke-width: 2.4; }
.list-back:hover { background: var(--bronze); color: #FFFFFF; text-decoration: none; }
/* «النتائج» in the reader: the same clear bronze pill as the other ways back */
.back-results { min-height: 40px; border: 1.5px solid var(--bronze); border-radius: 999px; color: var(--bronze); font-weight: 700; font-size: 14px; padding: 0 14px 0 10px; }
.back-results .icon { width: 18px; height: 18px; stroke-width: 2.4; }
.back-results:hover { background: var(--bronze); color: #FFFFFF; text-decoration: none; }

/* «المؤلفون»: the same paper cards as «المحفوظات» */
.author-grid { grid-template-columns: repeat(auto-fill, minmax(clamp(190px, 15vw, 240px), 1fr)); }
.author-card { min-height: 150px; grid-template-rows: auto 1fr auto; gap: 10px; color: var(--ink); text-decoration: none; }
.author-card:hover { text-decoration: none; }
.author-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.author-initial { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--bronze); color: #FFFFFF; font-size: 19px; font-weight: 700; }
.author-card strong { font-size: 16px; line-height: 1.6; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.author-card footer { margin-top: 0; }

/* «إضافة كتب إلى الجلسة» as a window */
.add-books { width: min(620px, calc(100% - 24px)); max-height: min(86dvh, 760px); padding: 20px; display: none; }
.add-books[open] { display: grid; grid-template-rows: auto auto 1fr auto; gap: 14px; }
.add-books-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.add-books-head h2 { margin: 0; }
.add-books .search-box .input { min-height: 50px; }
.add-books-list { overflow-y: auto; min-height: 120px; overscroll-behavior: contain; }
.add-books-list .sess-found { grid-template-columns: 1fr; }
.add-books-done { justify-self: stretch; min-height: 48px; }
.sess-added { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; background: color-mix(in srgb, var(--bronze) 14%, transparent); color: var(--bronze); font-size: 13px; font-weight: 700; }

/* ---------- page transition: slide like an app (RTL: forward comes from the left) ---------- */
#main.is-sliding { overflow-x: clip; }
.slide-out-forward { animation: slide-out-forward 170ms cubic-bezier(.4, 0, 1, 1) forwards; pointer-events: none; }
.slide-out-back { animation: slide-out-back 170ms cubic-bezier(.4, 0, 1, 1) forwards; pointer-events: none; }
.slide-in-forward { animation: slide-in-forward 420ms cubic-bezier(.22, 1, .36, 1); }
.slide-in-back { animation: slide-in-back 420ms cubic-bezier(.22, 1, .36, 1); }
@keyframes slide-out-forward { to { opacity: 0; transform: translateX(60px); } }
@keyframes slide-out-back { to { opacity: 0; transform: translateX(-60px); } }
@keyframes slide-in-forward { from { opacity: 0; transform: translateX(-90px); } }
@keyframes slide-in-back { from { opacity: 0; transform: translateX(90px); } }

/* ---------- side menu (phones and tablets): solid, warm, sections as icon tiles ---------- */
.drawer-panel {
  background: #FBF6EE !important; -webkit-backdrop-filter: none; backdrop-filter: none;
  width: min(340px, 88vw); gap: 14px; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  border-start-end-radius: 28px; border-end-end-radius: 28px; box-shadow: -12px 0 40px rgb(60 40 20 / .22);
}
.drawer-scrim { background: rgb(40 28 16 / .45); }
.drawer-head { border-bottom: 0; padding-bottom: 4px; }
.drawer-account {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px;
  background: var(--bronze); color: #FFFFFF; text-decoration: none; box-shadow: 0 8px 18px rgb(92 70 42 / .22);
}
.drawer-account:hover { text-decoration: none; filter: brightness(1.05); }
.drawer-account-icon { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgb(255 255 255 / .2); }
.drawer-account-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.drawer-account-text strong { font-size: 16px; }
.drawer-account-text small { font-size: 12px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: start; }
.drawer-title { margin: 6px 4px 8px; padding: 0; font-size: 13px; font-weight: 700; color: var(--bronze); letter-spacing: 0; }
.drawer-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.drawer-tile {
  display: grid; justify-items: center; align-content: center; gap: 6px; min-height: 84px; padding: 10px 4px;
  border-radius: 16px; background: #FFFFFF; border: 1px solid var(--border); color: var(--ink);
  font-size: 13px; font-weight: 600; line-height: 1.35; text-align: center; text-decoration: none;
}
.drawer-tile:hover { border-color: var(--bronze); text-decoration: none; }
.drawer-tile-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); color: var(--bronze); }
.drawer-tile-icon .icon { width: 20px; height: 20px; }
.drawer-tile[aria-current="page"] { background: var(--bronze); border-color: var(--bronze); color: #FFFFFF; }
.drawer-tile[aria-current="page"] .drawer-tile-icon { background: rgb(255 255 255 / .2); color: #FFFFFF; }
.drawer-cats { display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; }
.drawer-cats a { min-height: 38px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 999px; background: #FFFFFF; color: var(--ink); font-size: 14px; }
.drawer-cats a:hover { border-color: var(--bronze); color: var(--bronze); text-decoration: none; }
.drawer-feedback {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; margin-top: 6px;
  border: 1.5px solid var(--bronze); border-radius: 999px; color: var(--bronze); font-weight: 700; text-decoration: none;
}
.drawer-feedback:hover, .drawer-feedback[aria-current] { background: var(--bronze); color: #FFFFFF; text-decoration: none; }
/* A tile left alone on the last row spans it, lying flat (icon beside the name) */
.drawer-tile:last-child:nth-child(3n + 1) { grid-column: 1 / -1; min-height: 60px; display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 14px; }
.drawer-cats { margin-top: -6px; }
.drawer-panel > .drawer-title { margin-bottom: 0; }

/* ---------- «المساعد الذكي»: a round button in the corner, the chat in a window over the page ---------- */
.ai-fab {
  position: fixed; z-index: calc(var(--z-drawer) - 2); inset-inline-end: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; display: grid; place-items: center; border: 0; border-radius: 50%; cursor: pointer;
  background: radial-gradient(circle at 30% 25%, #A88759, var(--bronze) 60%, #6E5434); color: #FFFFFF;
  box-shadow: 0 10px 26px rgb(92 70 42 / .35), inset 0 1px 0 rgb(255 255 255 / .25);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
}
.ai-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgb(92 70 42 / .42); }
.ai-fab .icon { width: 26px; height: 26px; }
.ai-fab[hidden] { display: none; }
.ai-fab.is-open .icon { transform: rotate(90deg); transition: transform 200ms var(--ease); }
.ai-pop {
  position: fixed; z-index: calc(var(--z-drawer) - 1); inset-inline-end: 20px; bottom: calc(92px + env(safe-area-inset-bottom));
  width: min(420px, calc(100vw - 40px)); height: min(640px, calc(100dvh - 130px));
  display: grid; grid-template-rows: auto 1fr; overflow: hidden;
  background: #FBF6EE; border: 1px solid var(--border-strong); border-radius: 24px; box-shadow: 0 24px 60px rgb(60 40 20 / .28);
  transform-origin: bottom left; animation: ai-pop-in 220ms cubic-bezier(.22, 1, .36, 1);
}
.ai-pop[hidden] { display: none; }
@keyframes ai-pop-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
.ai-pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 10px 8px; background: var(--bronze); color: #FFFFFF; }
.ai-pop-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding-inline-start: 6px; }
.ai-pop-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: rgb(255 255 255 / .2); }
.ai-pop-tools { display: flex; gap: 2px; }
.ai-pop-tools .icon-btn { width: 36px; height: 36px; color: #FFFFFF; }
.ai-pop-tools .icon-btn:hover { background: rgb(255 255 255 / .18); }
.ai-pop-body { overflow-y: auto; overscroll-behavior: contain; padding: 14px; }
/* the chat inside the window */
.chat.is-compact { display: grid; grid-template-columns: 1fr; gap: 0; height: 100%; }
.chat.is-compact .chat-main { gap: 12px; }
.chat.is-compact .chat-log { min-height: 0; }
.chat.is-compact .chat-intro { padding: 18px 6px; }
.chat.is-compact .chat-intro h2 { font-size: 17px; }
.chat.is-compact .chat-msg { padding: 12px 14px; }
.chat.is-compact .chat-answer { font-size: 16px; }
.chat.is-compact .chat-ask { bottom: -14px; margin-inline: -2px; border-radius: 18px; }
.ai-pop-body .state { padding: 24px 8px; }
/* phones: the window is the whole screen */
@media (max-width: 640px) {
  .ai-fab { width: 54px; height: 54px; inset-inline-end: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .ai-pop { inset: 0; width: auto; height: auto; border-radius: 0; border: 0; padding-bottom: env(safe-area-inset-bottom); }
  body.ai-open { overflow: hidden; }
  body.ai-open .ai-fab { display: none; }
}
@media (prefers-reduced-motion: reduce) { .ai-pop { animation: none; } }

/* ---------- top bar of the home page on tablets and laptops: readable over the photo ---------- */
body.is-home:not(.is-scrolled) .site-header {
  background: rgb(253 250 245 / .78);
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid rgb(255 255 255 / .6); box-shadow: 0 6px 24px rgb(60 40 20 / .08);
}
body.is-home .main-nav a:not([aria-current]) { color: var(--ink); }

/* ---------- «المساعد الذكي», new look ---------- */
/* the button: a dark-bronze pill with a gold ring and the name; a circle on phones */
.ai-fab {
  width: auto; height: 56px; padding: 0 8px 0 20px; gap: 10px; display: inline-flex; align-items: center; border-radius: 999px;
  background: linear-gradient(135deg, #3E2C1B, #6B4F31 55%, #8B6A42); color: #FBF3E4;
  box-shadow: 0 0 0 2px rgb(229 200 138 / .55), 0 12px 30px rgb(40 26 12 / .38);
  font-family: inherit; font-weight: 700; font-size: 15px;
}
.ai-fab:hover { transform: translateY(-2px); box-shadow: 0 0 0 2px rgb(229 200 138 / .9), 0 16px 34px rgb(40 26 12 / .45); }
.ai-fab-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(135deg, #E5C88A, #B08A55); color: #3E2C1B; }
.ai-fab-icon .icon { width: 22px; height: 22px; }
.ai-fab.is-open .ai-fab-icon .icon { transform: rotate(90deg); transition: transform 200ms var(--ease); }
.ai-fab.is-open .icon { transform: none; }
@media (max-width: 640px) {
  .ai-fab { width: 56px; padding: 0; justify-content: center; }
  .ai-fab-label { display: none; }
}
/* the window: cream paper, a quiet header with the mark */
.ai-pop { background: #FFFDF9; border: 1px solid rgb(176 138 85 / .35); border-radius: 26px; box-shadow: 0 30px 70px rgb(40 26 12 / .30); bottom: calc(90px + env(safe-area-inset-bottom)); }
.ai-pop-head { background: linear-gradient(180deg, #F7EEDF, #FFFDF9); color: var(--ink); padding: 14px 14px 12px; border-bottom: 1px solid rgb(176 138 85 / .2); }
.ai-pop-title { gap: 12px; padding: 0; }
.ai-pop-title > span:last-child { display: grid; gap: 1px; }
.ai-pop-title strong { font-size: 16px; }
.ai-pop-title small { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.ai-pop-mark { width: 40px; height: 40px; background: linear-gradient(135deg, #3E2C1B, #8B6A42); color: #E5C88A; box-shadow: 0 0 0 2px rgb(229 200 138 / .5); }
.ai-pop-tools .icon-btn { color: var(--ink-2); }
.ai-pop-tools .icon-btn:hover { background: rgb(176 138 85 / .14); color: var(--ink); }
.ai-pop-body { padding: 16px 14px 0; display: flex; flex-direction: column; }
.ai-pop-body > [data-slot="chat"] { flex: 1; display: flex; flex-direction: column; }
.chat.is-compact { flex: 1; display: flex; flex-direction: column; }
.chat.is-compact .chat-main { flex: 1; display: flex; flex-direction: column; }
.chat.is-compact .chat-log { flex: 1; }
.chat.is-compact .chat-ask { position: sticky; bottom: 0; margin: 0 -14px; border: 0; border-top: 1px solid rgb(176 138 85 / .2); border-radius: 0; padding: 12px 14px calc(10px + env(safe-area-inset-bottom)); background: #FFFDF9; box-shadow: none; }

/* the welcome: the mark, a question, ready-made questions to tap */
.chat-intro { gap: 10px; }
.chat-intro-mark { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(135deg, #3E2C1B, #8B6A42); color: #E5C88A; box-shadow: 0 0 0 3px rgb(229 200 138 / .45), 0 10px 24px rgb(40 26 12 / .2); }
.chat-intro-mark .icon { width: 30px; height: 30px; }
.chat-intro h2 { font-size: 20px; color: var(--ink); }
.chat-suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.chat-chip { padding: 9px 14px; border-radius: 999px; border: 1px solid rgb(176 138 85 / .45); background: #FFFFFF; color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; }
.chat-chip:hover { border-color: var(--bronze); background: #F7EEDF; }

/* the conversation */
.chat-msg.is-user { background: linear-gradient(135deg, #5A4129, #8B6A42); border-radius: 20px 20px 20px 6px; box-shadow: 0 6px 16px rgb(60 40 20 / .15); }
.chat-msg.is-bot { background: #FFFFFF; border: 1px solid rgb(176 138 85 / .25); border-radius: 20px 20px 6px 20px; box-shadow: 0 4px 14px rgb(60 40 20 / .06); }

/* the composer: a rounded field with a round send button */
.chat-ask { gap: 6px; }
.chat-compose { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 6px; border-radius: 26px; background: #FFFFFF; border: 1.5px solid rgb(176 138 85 / .45); box-shadow: 0 4px 14px rgb(60 40 20 / .06); }
.chat-compose:focus-within { border-color: var(--bronze); box-shadow: 0 0 0 3px rgb(176 138 85 / .18); }
.chat-input { flex: 1; min-width: 0; min-height: 44px; max-height: 140px; padding: 10px 12px; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); font: inherit; font-size: 16px; line-height: 1.6; }
.chat-send { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%; background: linear-gradient(135deg, #3E2C1B, #8B6A42); color: #F3E3C2; cursor: pointer; font: 700 13px/1 inherit; }
.chat-send:disabled { background: var(--surface-3); color: var(--ink-3); cursor: default; }
.chat-send[hidden] { display: none; }
.chat-ask-row { justify-content: space-between; padding-inline: 8px; }
.chat-note { text-align: center; }
.chat-ask .chat-input { resize: none; min-height: 44px; padding: 10px 12px; line-height: 1.6; font-size: 16px; }
/* Home top bar: frosted warm sand, the colour of the wall in the photo, with dark text */
body.is-home:not(.is-scrolled) .site-header { background: linear-gradient(180deg, rgb(226 208 182 / .72), rgb(236 222 200 / .55)); border-bottom-color: rgb(255 255 255 / .35); backdrop-filter: blur(18px) saturate(1.15); -webkit-backdrop-filter: blur(18px) saturate(1.15); }
body.is-home:not(.is-scrolled) .main-nav a:not([aria-current]) { color: #3A2A1A; }
/* Top bar: the names in the logo's dark bronze-brown (all pages) */
/* semi-bold in the site's own font (its bold is a different, heavier font): a hair of stroke */
.main-nav a:not([aria-current]), body.is-home:not(.is-scrolled) .main-nav a:not([aria-current]) { color: #5A3A1C; font-weight: 500; -webkit-text-stroke: .35px currentColor; }
/* «المساعد الذكي» button: the site's lighter bronze instead of the dark brown */
.ai-fab { background: linear-gradient(135deg, #B8925C, #8B6F4D); color: #FFFFFF; box-shadow: 0 0 0 2px rgb(229 200 138 / .6), 0 10px 26px rgb(92 70 42 / .32); }
.ai-fab:hover { box-shadow: 0 0 0 2px rgb(229 200 138 / .95), 0 14px 30px rgb(92 70 42 / .4); }
.ai-fab-icon { background: #FBF3E4; color: #8B6F4D; }

/* ---------- «المساعد الذكي» window: three rows — header, the conversation (scrolls), the question box ---------- */
.ai-pop { display: flex; flex-direction: column; }
.ai-pop-head { flex: none; }
.ai-pop-body { flex: 1; min-height: 0; overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.ai-pop-body > [data-slot="chat"] { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
.chat.is-compact, .chat.is-compact .chat-main { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0; }
.chat.is-compact .chat-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 18px; gap: 12px; align-content: start; }
.chat.is-compact .chat-ask { flex: none; position: static; margin: 0; padding: 10px 12px 10px; border-top: 1px solid rgb(176 138 85 / .22); border-radius: 0; background: #FFFDF9; box-shadow: 0 -6px 16px rgb(60 40 20 / .05); }
.chat.is-compact .chat-ask-row { padding-inline: 6px; font-size: 12px; }
.chat.is-compact .chat-note { font-size: 11px; margin: 0; }
.ai-pop-body .state { margin: auto; padding: 24px 16px; }
/* phones: the whole screen (its height follows the keyboard, see chat-widget.js) */
@media (max-width: 640px) {
  .ai-pop { inset: 0 0 auto 0; height: 100dvh; border-radius: 0; animation: none; }
  .ai-pop-head { padding: calc(10px + env(safe-area-inset-top)) 10px 10px; }
  .ai-pop-mark { width: 36px; height: 36px; }
  .chat.is-compact .chat-intro { padding: 10px 4px 4px; gap: 8px; }
  .chat.is-compact .chat-intro-mark { width: 52px; height: 52px; }
  .chat.is-compact .chat-intro h2 { font-size: 18px; }
  .chat.is-compact .chat-intro p { font-size: 14px; }
  .chat.is-compact .chat-chip { font-size: 13px; padding: 8px 12px; }
  .chat.is-compact .chat-msg { max-width: 100%; }
  .chat.is-compact .chat-msg.is-user { max-width: 88%; }
  .chat.is-compact .chat-ask { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  body.ai-open .ai-pop:focus-within .chat-note { display: none; } /* more room while typing */
}
/* The window's chat always spans its full width (an older rule shrank it to its content while an answer was empty) */
.chat.is-compact { align-items: stretch; }
.chat.is-compact .chat-main { align-items: stretch; width: 100%; }

/* Chat page: long chat titles stay inside their row (an unbreakable title widened the page on phones) */
.chat { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .chat { grid-template-columns: 260px minmax(0, 1fr); } }
.chat-side, .chat-main, .chat-convs, .chat-convs li { min-width: 0; }
.chat-convs a { min-width: 0; max-width: 100%; }
.chat-convs .icon-btn { flex: none; }


/* ---------- footer on phones: compact (links and sections as small chips, smaller logo, less space) ---------- */
@media (max-width: 640px) {
  .footer-grid { gap: 20px; padding-block: 26px 20px; }
  .footer-logo { height: 44px; margin-bottom: 8px; }
  .footer-about p { font-size: 14px; line-height: 1.8; }
  .footer-col h2 { font-size: 15px; margin-bottom: 8px; }
  .footer-col ul { display: flex; flex-wrap: wrap; gap: 6px; }
  .footer-col a { min-height: 32px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: rgb(255 255 255 / .55); font-size: 13px; color: var(--ink); }
  .footer-col a:hover { border-color: var(--bronze); text-decoration: none; }
  .footer-app p { font-size: 14px; margin-bottom: 8px; }
  .footer-app .store-badges { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .footer-bottom { font-size: 12px; }
  .footer-bottom-row { justify-content: center; text-align: center; padding-block: 12px calc(12px + env(safe-area-inset-bottom)); }
}
@media (max-width: 640px) {
  .footer-grid { grid-template-columns: minmax(0, 1fr); }
  .footer-app .store-badges { display: flex; flex-direction: row; }
  .footer-app .store-badges > * { flex: 1 1 140px; min-width: 0; }
}

/* ---------- footer on tablets and laptops: shorter (quick links in two columns, tighter spacing) ---------- */
@media (min-width: 641px) {
  .footer-grid { padding-block: 32px 24px; gap: 28px; }
  .footer-logo { height: 50px; margin-bottom: 10px; }
  .footer-about p { font-size: 14px; line-height: 1.8; }
  .footer-col h2 { font-size: 16px; margin-bottom: 8px; }
  .footer-col a { min-height: 30px; font-size: 14px; }
  [data-footer-links] { grid-template-columns: repeat(2, minmax(0, max-content)); column-gap: 28px; }
  .footer-app p { font-size: 14px; }
  .footer-bottom-row { padding-block: 12px; font-size: 13px; }
}
/* Tablets: links, sections and the app side by side in one row under the about text */
@media (min-width: 641px) and (max-width: 1023px) {
  .footer-grid { grid-template-columns: 1.3fr 1fr 1fr; gap: 20px 24px; }
  .footer-app { grid-column: auto; }
  .footer-app .store-badges .store-badge { padding-block: 6px; }
}

/* ---------- home: «الكتب الشيعية» / «الكتب الأخرى» as rounded chips, like the footer ---------- */
.toc-cats { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-start; }
.toc-cats li { display: contents; }
.toc-cat {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--border-strong);
  border-radius: 999px; background: rgb(255 255 255 / .55); color: var(--ink); font-size: 15px; line-height: 1.4;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.toc-cat:hover { border-color: var(--bronze); background: #FFFFFF; color: var(--bronze); text-decoration: none; }
.toc-cat .toc-n { display: none; }
.toc-cat .toc-t { flex: none; font-size: 15px; transform: none !important; }
.toc-cat .toc-c { font-size: 12px; color: var(--bronze); background: rgb(176 138 85 / .12); padding: 2px 8px; border-radius: 999px; }
.toc-cat .toc-c:empty { display: none; }
@media (max-width: 640px) {
  .toc-cats { gap: 8px; }
  .toc-cat { min-height: 40px; padding: 0 13px; font-size: 14px; }
  .toc-cat .toc-t { font-size: 14px; }
}
/* mini, like the footer: small chips, no counts, titles like the footer's */
.toc-cats { gap: 6px; }
.toc-cat { min-height: 32px; padding: 0 12px; font-size: 13px; background: rgb(255 255 255 / .55); color: var(--ink); }
.toc-cat .toc-t { font-size: 13px; }
.toc-cat .toc-c { display: none; }
.toc-section .rule-title { justify-content: flex-start; font-size: 17px; font-weight: 700; color: var(--bronze); margin-bottom: 10px; }
.toc-section .rule-title::before, .toc-section .rule-title::after { content: none; }
@media (max-width: 640px) {
  .toc-cat { min-height: 32px; padding: 0 12px; font-size: 13px; }
  .toc-cat .toc-t { font-size: 13px; }
  .toc-section .rule-title { font-size: 15px; margin-bottom: 8px; }
}

/* Section names always on one line; the small icons only where all ten fit with them */
.main-nav a { white-space: nowrap; }
@media (min-width: 1600px) and (max-width: 1879px) { .main-nav a .icon { display: none; } }
/* Home page after scrolling: keep the same logo colour (an older rule turned it black) */
body.is-home .main-nav a:not([aria-current]) { color: #5A3A1C; }

/* «حذف» in the notes: clearly a delete (red outline), and a whole card is the tap target while choosing */
.btn-delete { color: var(--danger); border: 1.5px solid currentColor; background: transparent; }
.btn-delete:hover { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.notes-pickbar [data-slot="picked"] { font-weight: 600; margin-inline-end: auto; }
.note-card:has(.note-pick) { cursor: pointer; }

/* The site's own confirm / rename window (ui.js confirmBox, promptBox) */
.ask-sheet { z-index: 2000; }
.ask-form { display: grid; gap: 14px; }
.ask-form h2 { margin: 0; font-size: 18px; line-height: 1.6; color: var(--ink); }
.ask-form p { margin: 0; line-height: 1.8; }
.ask-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.ask-actions .btn { flex: 1 1 120px; min-height: 46px; justify-content: center; }
.ask-actions .btn-danger { justify-self: auto; }
