/* Bookshelf — books.mamdouh.de */

:root {
  --paper: #f7f2e9;
  --paper-2: #efe7d8;
  --card: #fffdf8;
  --ink: #2a2420;
  --ink-2: #5c5249;
  --muted: #877b6e;
  --line: #e2d7c5;
  --accent: #9a3d2a;
  --accent-ink: #fffaf3;
  --shadow: 0 1px 2px rgb(60 40 20 / .10), 0 10px 24px -14px rgb(60 40 20 / .45);
  --shadow-lift: 0 2px 4px rgb(60 40 20 / .10), 0 18px 32px -14px rgb(60 40 20 / .55);
  --serif: 'Newsreader Variable', 'Noto Naskh Arabic Variable', Georgia, 'Times New Roman', serif;
  --arabic: 'Noto Naskh Arabic Variable', 'Newsreader Variable', 'Geeza Pro', 'Arial', serif;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1b1815;
    --paper-2: #24201b;
    --card: #2a2520;
    --ink: #efe6d8;
    --ink-2: #cbbfae;
    --muted: #9d9182;
    --line: #3b342d;
    --accent: #e4a27f;
    --accent-ink: #23170f;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 24px -14px rgb(0 0 0 / .8);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / .4), 0 18px 32px -14px rgb(0 0 0 / .9);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.55;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; }

:lang(ar), [lang="ar"], [lang="fa"], [lang="ur"] { font-family: var(--arabic); line-height: 1.7; }

a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: .18em; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

h1, h2, h3 { font-weight: 500; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
svg { width: 1.1em; height: 1.1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.wrap { max-width: 1140px; margin-inline: auto; padding-inline: 16px; }
@media (min-width: 720px) { .wrap { padding-inline: 32px; } }

.visually-hidden, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 10; background: var(--card); padding: .5rem 1rem; }

/* ── Masthead ─────────────────────────────────────────────────────────── */

.masthead { border-bottom: 1px solid var(--line); }
.masthead-inner {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: .5rem 2rem; padding-block: 1.25rem;
}
.brand { display: flex; align-items: baseline; gap: .75rem; text-decoration: none; }
.brand:hover { color: inherit; }
.brand-name { font-size: 1.45rem; font-weight: 600; letter-spacing: -.02em; }
.brand-ar { font-size: 1.15rem; color: var(--muted); line-height: 1; }
.nav { display: flex; gap: 1.5rem; font-size: 1rem; }
.nav a { text-decoration: none; color: var(--ink-2); padding-block: .25rem; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ── Intro & controls ─────────────────────────────────────────────────── */

.intro { padding-block: clamp(2rem, 6vw, 3.75rem) 1.75rem; max-width: 46rem; }
.intro h1 { font-size: clamp(1.9rem, 4.6vw, 2.9rem); }
.intro p { color: var(--ink-2); font-size: 1.15rem; margin: .9rem 0 0; }
.intro .intro-ar { text-align: left; }
.hash { color: var(--muted); margin-inline-end: .1em; }
.intro .title-ar { color: var(--muted); font-size: .7em; margin-inline-start: .35em; }

.crumbs { margin: 1.5rem 0 0; font-size: .95rem; }
.crumbs a { display: inline-flex; align-items: center; gap: .3rem; color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.controls { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.search { flex: 1 1 280px; max-width: 30rem; }
.search input {
  width: 100%; font: inherit; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .65rem 1rem;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button {
  font: inherit; font-size: .95rem; color: var(--ink-2); background: none; border: 0;
  padding: .55rem .95rem; cursor: pointer; line-height: 1.4;
}
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: .45rem; margin-block: .25rem 1.25rem; }
.chip {
  display: inline-flex; align-items: baseline; gap: .4rem;
  font-size: .9rem; line-height: 1.3; text-decoration: none; color: var(--ink-2);
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: .32rem .8rem;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-current="page"], .chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip-count { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .chip-count, .chip[aria-current="page"] .chip-count { color: inherit; opacity: .7; }

.result-count { color: var(--muted); font-size: .92rem; margin: 0 0 1.25rem; }
.empty { color: var(--ink-2); padding-block: 2rem; }
button.link { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }

/* ── Book grid & cards ────────────────────────────────────────────────── */

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 2.25rem 1.75rem;
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.75rem 1.1rem; }
}

.card-link { display: block; text-decoration: none; }
.card-link:hover { color: inherit; }
.card-cover { position: relative; aspect-ratio: 2 / 3; container-type: inline-size; transition: transform .25s ease; }
.card-cover > .cover { box-shadow: var(--shadow); transition: box-shadow .25s ease; }
.card-cover::after { /* spine shading */
  content: ""; position: absolute; inset: 0; border-radius: 3px 6px 6px 3px; pointer-events: none;
  background: linear-gradient(90deg, rgb(0 0 0 / .22) 0, rgb(255 255 255 / .16) 2.5%, rgb(0 0 0 / .05) 5%, transparent 9%);
}
.card-link:hover .card-cover { transform: translateY(-4px); }
.card-cover.is-wide::after { display: none; }
.card-cover.is-wide > img.cover { position: absolute; inset: auto 0 0 0; height: auto; border-radius: 4px; }
.card-link:hover .card-cover > .cover { box-shadow: var(--shadow-lift); }
@media (prefers-reduced-motion: reduce) { .card-cover, .card-cover > .cover { transition: none; } }

.cover {
  display: block; width: 100%; height: 100%; object-fit: cover;
  border-radius: 3px 6px 6px 3px; background: var(--paper-2);
}
.card-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  margin-top: .85rem; font-weight: 600; font-size: 1.02rem; line-height: 1.3;
}
.card-title:lang(ar) { line-height: 1.55; }
.card-author { display: block; color: var(--muted); font-size: .92rem; margin-top: .15rem; }
.card-note { color: var(--ink-2); font-size: .9rem; margin: .5rem 0 0; line-height: 1.45; }

.ribbon, .pdf-badge {
  position: absolute; z-index: 1; font-family: system-ui, sans-serif; font-weight: 600;
  font-size: .66rem; letter-spacing: .08em; text-transform: uppercase; line-height: 1;
  padding: .38rem .55rem; border-radius: 4px;
}
.ribbons { position: absolute; z-index: 1; top: .55rem; inset-inline-end: -.35rem; display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; }
.ribbon { position: static; background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 6px rgb(0 0 0 / .25); }
.ribbon-banned { background: var(--ink); color: var(--paper); }
.pdf-badge { bottom: .55rem; inset-inline-end: .55rem; background: rgb(20 15 10 / .72); color: #fff; backdrop-filter: blur(4px); }

/* Generated typographic cover (when no image exists) */
.cover-gen {
  --h: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7cqi;
  padding: 12cqi 10cqi; text-align: center; overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% 0%, hsl(var(--h) 30% 40% / .55), transparent 60%),
    hsl(var(--h) 34% 26%);
  color: hsl(var(--h) 45% 90%);
  box-shadow: inset 0 0 0 5cqi hsl(var(--h) 34% 26%), inset 0 0 0 calc(5cqi + 1px) hsl(var(--h) 55% 72% / .55);
}
.card-cover > .cover-gen { box-shadow: inset 0 0 0 5cqi hsl(var(--h) 34% 26%), inset 0 0 0 calc(5cqi + 1px) hsl(var(--h) 55% 72% / .55), var(--shadow); }
.cg-title { font-size: 11cqi; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.cg-title:lang(ar) { line-height: 1.5; font-size: 12cqi; }
.cg-rule { width: 22cqi; height: 1px; background: currentColor; opacity: .55; flex: none; }
.cg-author { font-size: 7.5cqi; opacity: .85; font-style: italic; }
.cg-author:lang(ar) { font-style: normal; }
.hue-0 { --h: 8; } .hue-1 { --h: 28; } .hue-2 { --h: 45; } .hue-3 { --h: 90; }
.hue-4 { --h: 150; } .hue-5 { --h: 175; } .hue-6 { --h: 200; } .hue-7 { --h: 220; }
.hue-8 { --h: 250; } .hue-9 { --h: 285; } .hue-10 { --h: 320; } .hue-11 { --h: 345; }

/* ── Book page ────────────────────────────────────────────────────────── */

.book {
  display: grid; grid-template-columns: minmax(180px, 300px) minmax(0, 1fr);
  gap: clamp(1.75rem, 5vw, 4rem); align-items: start; padding-top: 1.75rem;
}
@media (max-width: 680px) {
  .book { grid-template-columns: 1fr; }
  .book-cover { max-width: 210px; }
}
.book-cover { position: sticky; top: 1.5rem; aspect-ratio: 2 / 3; container-type: inline-size; }
@media (max-width: 680px) { .book-cover { position: static; } }
.book-cover > .cover { box-shadow: var(--shadow-lift); }
.book-cover > img.cover { height: auto; aspect-ratio: auto; }

.badges { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 .9rem; }
.badge-coll {
  display: inline-block; font-family: system-ui, sans-serif; font-size: .72rem; font-weight: 600; text-decoration: none;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
  border: 1px solid currentColor; border-radius: 4px; padding: .3rem .55rem;
}
.badge-coll:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge-banned { color: var(--ink); }
.badge-banned:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
/* Arabic titles keep RTL shaping but align with the rest of the (LTR) column. */
.book-title[dir="rtl"], .book-subtitle[dir="rtl"], .byline [dir="rtl"] { text-align: left; }
.book-title { font-size: clamp(2rem, 5vw, 3.1rem); }
.book-title:lang(ar) { line-height: 1.45; }
.book-subtitle { font-size: 1.25rem; color: var(--ink-2); margin: .6rem 0 0; line-height: 1.5; }
.book-alt { font-size: 1.3rem; font-style: italic; color: var(--ink-2); margin: .5rem 0 0; }
.byline { font-size: 1.2rem; margin: 1rem 0 0; }
.muted { color: var(--muted); }

.facts { display: flex; flex-wrap: wrap; gap: .75rem 2.25rem; margin: 1.75rem 0; padding-block: 1rem; border-block: 1px solid var(--line); }
.facts dt { font-family: system-ui, sans-serif; font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: .15rem 0 0; font-weight: 500; font-variant-numeric: tabular-nums; }

.coll-note { margin: 1.5rem 0; padding: 1rem 1.25rem; background: var(--paper-2); border-inline-start: 3px solid var(--accent); border-radius: 0 8px 8px 0; }
.coll-note h2 { font-family: system-ui, sans-serif; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.coll-note p { margin: .4rem 0 0; }
.coll-note-banned { border-inline-start-color: var(--ink); }
.coll-note-banned h2 { color: var(--ink); }

.prose { font-size: 1.15rem; line-height: 1.7; max-width: 38em; }
.prose:lang(ar), .prose[dir="rtl"] { line-height: 1.9; }
.prose p { margin: 0 0 1em; }
.prose a { color: var(--accent); }

.quote { margin: 1.75rem 0; padding-inline-start: 1.5rem; border-inline-start: 2px solid var(--line); font-size: 1.25rem; font-style: italic; color: var(--ink-2); max-width: 36em; }
.quote p { margin: 0; }

.actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 2rem; }
.btn {
  display: inline-flex; align-items: center; gap: .55rem;
  font-family: system-ui, sans-serif; font-size: .95rem; font-weight: 500; text-decoration: none;
  padding: .75rem 1.15rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { color: var(--accent-ink); filter: brightness(1.08); }
.btn-meta { opacity: .65; font-weight: 400; font-variant-numeric: tabular-nums; }

.reader { margin-top: 3.5rem; scroll-margin-top: 1rem; }
.reader-bar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: space-between; align-items: baseline; margin-bottom: .9rem; }
.reader-bar h2 { font-size: 1.5rem; }
.reader-bar a { display: inline-flex; align-items: center; gap: .4rem; font-size: .95rem; color: var(--ink-2); }
.reader iframe {
  display: block; width: 100%; height: min(88vh, 1150px); min-height: 420px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2);
}
.reader-source { color: var(--muted); font-size: .9rem; margin: .6rem 0 0; }

.similar { margin-top: 4.5rem; padding-top: 2rem; border-top: 1px solid var(--line); }
.similar h2, .related-tags h2 { font-size: 1.5rem; margin-bottom: 1.5rem; }
.related-tags { margin-top: 3.5rem; }

/* ── Tags index ───────────────────────────────────────────────────────── */

.tag-groups { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.tag-group {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 1.1rem; align-items: center;
  padding: 1.1rem 1.25rem; background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-decoration: none;
}
.tag-group:hover { border-color: var(--accent); color: inherit; }
.tag-group:hover .tag-group-name { color: var(--accent); }
.tag-stack { grid-row: span 2; display: flex; padding-inline-start: 22px; }
.tag-stack > .cover {
  width: 44px; height: 66px; flex: none; margin-inline-start: -22px; padding: 0; gap: 0;
  border: 2px solid var(--card); box-sizing: content-box; box-shadow: var(--shadow);
}
.tag-stack > .cover:nth-child(2) { transform: rotate(4deg) translateY(2px); }
.tag-stack > .cover:nth-child(3) { transform: rotate(8deg) translateY(5px); }
.tag-stack > .cover-gen > * { display: none; }
.tag-group-name { font-size: 1.2rem; font-weight: 600; align-self: end; }
.tag-group-count { color: var(--muted); font-size: .9rem; align-self: start; }

/* ── Footer ───────────────────────────────────────────────────────────── */

.footer { margin-top: 5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1.5rem; padding-block: 1.75rem; }
.footer a { color: inherit; }
