/* ==========================================================================
   Our Digital Library — design system
   ========================================================================== */

:root {
    --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

    --bg: #f6f1e9;
    --bg-elev: #fffdf9;
    --bg-sunk: #ede5d8;
    --ink: #221c17;
    --ink-soft: #5d5148;
    --ink-faint: #93877c;
    --line: #e3d8c8;
    --line-strong: #d2c3ad;
    --accent: #b4532a;
    --accent-ink: #fff8f0;
    --ibrahim: #2f6f8f;
    --esra: #c0577a;
    --both: #6b8f4e;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 2px rgba(60, 40, 20, .06), 0 1px 1px rgba(60, 40, 20, .04);
    --shadow: 0 10px 30px -12px rgba(60, 40, 20, .25), 0 2px 6px rgba(60, 40, 20, .05);
    --shadow-lg: 0 30px 60px -20px rgba(40, 25, 10, .35), 0 8px 20px -8px rgba(40, 25, 10, .15);
    --ease: cubic-bezier(.2, .8, .2, 1);
    --topbar-h: 64px;

    color-scheme: light;
}

[data-theme='dark'] {
    --bg: #14110f;
    --bg-elev: #1d1916;
    --bg-sunk: #0f0d0b;
    --ink: #f2ebe1;
    --ink-soft: #bfb3a5;
    --ink-faint: #85796d;
    --line: #2c2621;
    --line-strong: #3b332c;
    --accent: #e07a4a;
    --accent-ink: #1a0f08;
    --ibrahim: #6bb3d6;
    --esra: #ea8fae;
    --both: #9cc47a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 12px 30px -12px rgba(0, 0, 0, .7);
    --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .8);

    color-scheme: dark;
}

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

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

body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
    transition: background-color .4s var(--ease), color .4s var(--ease);
}

body.no-scroll { overflow: hidden; }

/* subtle paper grain */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    opacity: .5;
    background:
        radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
        radial-gradient(900px 500px at -10% 10%, color-mix(in srgb, var(--ibrahim) 10%, transparent), transparent 60%);
}

img, svg { display: block; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.icon-fill { fill: currentColor; stroke: none; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
}

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

.hidden { display: none !important; }
.muted { color: var(--ink-faint); }

.skip-link {
    position: absolute;
    left: 1rem; top: -100px;
    z-index: 100;
    background: var(--ink);
    color: var(--bg);
    padding: .6rem 1rem;
    border-radius: var(--radius-sm);
}
.skip-link:focus { top: 1rem; }

.container {
    width: min(1240px, 100% - 2.5rem);
    margin-inline: auto;
}

/* ---------- Buttons ---------- */
.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px; height: 40px;
    border-radius: 999px;
    color: var(--ink-soft);
    transition: background-color .2s, color .2s, transform .2s var(--ease);
}
.icon-btn:hover { background: var(--bg-sunk); color: var(--ink); }
.icon-btn:active { transform: scale(.94); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    height: 42px;
    padding: 0 1.1rem;
    border-radius: 999px;
    font-weight: 500;
    font-size: .92rem;
    background: var(--bg-elev);
    border: 1px solid var(--line-strong);
    transition: transform .2s var(--ease), background-color .2s, box-shadow .2s;
    white-space: nowrap;
}
.btn:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn svg { width: 17px; height: 17px; }

.btn-accent {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: transparent;
}
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.topbar-inner {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: -.01em;
}
.brand-mark { width: 30px; height: 30px; stroke: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: var(--accent-ink); }

.topbar-actions { display: flex; align-items: center; gap: .25rem; }
.nav-link {
    padding: .45rem .8rem;
    border-radius: 999px;
    font-size: .92rem;
    color: var(--ink-soft);
    transition: color .2s, background-color .2s;
}
.nav-link:hover { color: var(--ink); background: var(--bg-sunk); }

#themeToggle .icon-moon { display: none; }
[data-theme='dark'] #themeToggle .icon-sun { display: none; }
[data-theme='dark'] #themeToggle .icon-moon { display: block; }

/* ---------- Hero ---------- */
.hero { padding: clamp(3.5rem, 9vw, 7rem) 0 clamp(2.5rem, 6vw, 4rem); }

.eyebrow {
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1rem;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.6rem, 7.2vw, 5.6rem);
    line-height: 1.02;
    letter-spacing: -.035em;
    font-variation-settings: 'opsz' 144;
    max-width: 14ch;
}
.hero-title em {
    font-style: italic;
    font-weight: 400;
    color: var(--accent);
}
#heroCount { font-variant-numeric: tabular-nums; }

.hero-lead {
    margin-top: 1.5rem;
    max-width: 52ch;
    font-size: clamp(1.02rem, 1.6vw, 1.18rem);
    color: var(--ink-soft);
}

.stats {
    margin-top: clamp(2.5rem, 5vw, 3.5rem);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}
.stat {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding: 1.35rem 1.4rem;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .85rem; color: var(--ink-soft); font-weight: 500; }
.stat-value {
    font-family: var(--font-display);
    font-size: 2.6rem;
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}
.stat-sub { font-size: .8rem; color: var(--ink-faint); }

.meter {
    height: 6px;
    margin-top: .4rem;
    border-radius: 99px;
    background: var(--bg-sunk);
    overflow: hidden;
}
.meter span {
    display: block;
    height: 100%;
    width: var(--w);
    border-radius: inherit;
    background: var(--tone, var(--accent));
    transform-origin: left;
    animation: grow 1.2s var(--ease) both .2s;
}
.meter-ibrahim { --tone: var(--ibrahim); }
.meter-esra { --tone: var(--esra); }
.meter-both { --tone: var(--both); }

@keyframes grow { from { transform: scaleX(0); } }

/* ---------- Sections ---------- */
.section { padding: clamp(2.5rem, 6vw, 4.5rem) 0; }
.section-head { margin-bottom: 1.75rem; }
.section-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.8rem, 3.5vw, 2.6rem);
    letter-spacing: -.025em;
    line-height: 1.1;
}
.section-sub { margin-top: .4rem; color: var(--ink-soft); }

/* ---------- Insights ---------- */
.insights-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1rem;
}
.panel {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}
.panel-wide { grid-column: 1 / -1; }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.panel-head h3 { font-size: 1rem; font-weight: 600; }
.panel-meta { font-size: .82rem; color: var(--ink-faint); }

.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--ink-soft); }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot-ibrahim { background: var(--ibrahim); }
.dot-esra { background: var(--esra); }

/* bar chart */
.chart { height: 240px; }
.bars {
    height: 100%;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: clamp(4px, 1vw, 12px);
    align-items: end;
    border-bottom: 1px solid var(--line);
    background-image: linear-gradient(to top, var(--line) 1px, transparent 1px);
    background-size: 100% 25%;
}
.bar-group {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    outline: none;
}
.bar-pair {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
}
.bar {
    flex: 1;
    max-width: 18px;
    height: var(--h);
    min-height: 2px;
    border-radius: 5px 5px 2px 2px;
    transform-origin: bottom;
    transition: filter .2s, transform .2s var(--ease);
}
.is-visible .bar { animation: rise .9s var(--ease) both; }
.bar-ibrahim { background: var(--ibrahim); }
.bar-esra { background: var(--esra); animation-delay: .08s !important; }
.bar-label {
    position: absolute;
    bottom: -1.6rem;
    left: 0; right: 0;
    text-align: center;
    font-size: .72rem;
    color: var(--ink-faint);
    font-variant-numeric: tabular-nums;
}
.bar-tip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translate(-50%, 4px);
    padding: .45rem .65rem;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--bg);
    font-size: .75rem;
    line-height: 1.35;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s, transform .15s var(--ease);
    z-index: 2;
}
.bar-group:hover .bar-tip,
.bar-group:focus-visible .bar-tip { opacity: 1; transform: translate(-50%, 0); }
.bar-group:hover .bar,
.bar-group:focus-visible .bar { filter: brightness(1.12); }
.panel-chart .chart { height: 270px; margin-bottom: 1.6rem; padding-top: 3.2rem; }

@keyframes rise { from { transform: scaleY(0); } }

/* top authors */
.rank-list { list-style: none; padding: 0; display: grid; gap: .25rem; }
.rank {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .35rem .75rem;
    align-items: center;
    padding: .55rem .6rem;
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background-color .2s;
}
.rank:hover { background: var(--bg-sunk); }
.rank-name { font-size: .92rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-count { font-size: .82rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.rank-bar {
    grid-column: 1 / -1;
    position: relative;
    height: 4px;
    border-radius: 99px;
    background: var(--bg-sunk);
    overflow: hidden;
}
.rank-bar span {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--w);
    border-radius: inherit;
    background: color-mix(in srgb, var(--accent) 35%, transparent);
}
.rank-bar .rank-read { background: var(--accent); }

/* recent strip */
.recent-strip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 128px;
    gap: 1.1rem;
    overflow-x: auto;
    padding: .25rem .25rem 1rem;
    margin: -.25rem;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
}
.recent {
    display: flex;
    flex-direction: column;
    gap: .45rem;
    text-align: left;
    scroll-snap-align: start;
}
.recent .cover { transition: transform .35s var(--ease), box-shadow .35s var(--ease); }
.recent:hover .cover { transform: translateY(-4px) rotate(-1deg); box-shadow: var(--shadow-lg); }
.recent-title {
    font-size: .84rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.recent-meta { display: inline-flex; align-items: center; gap: .4rem; font-size: .75rem; color: var(--ink-faint); }

/* ---------- Toolbar ---------- */
.toolbar {
    position: sticky;
    top: var(--topbar-h);
    z-index: 30;
    padding: .85rem 0;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: saturate(1.5) blur(12px);
    -webkit-backdrop-filter: saturate(1.5) blur(12px);
    border-bottom: 1px solid transparent;
    transition: border-color .25s, box-shadow .25s;
}
.toolbar.is-stuck {
    border-bottom-color: var(--line);
    box-shadow: 0 10px 20px -18px rgba(0, 0, 0, .4);
}
.toolbar-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
}

.search {
    flex: 1 1 200px;
    position: relative;
    display: flex;
    align-items: center;
    height: 44px;
    padding: 0 .6rem 0 .9rem;
    gap: .55rem;
    background: var(--bg-elev);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    transition: border-color .2s, box-shadow .2s;
    cursor: text;
}
.search:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.search svg { width: 18px; height: 18px; color: var(--ink-faint); flex: none; }
.search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    background: transparent;
    outline: none;
    font-size: .95rem;
}
.search input::placeholder { color: var(--ink-faint); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-kbd {
    font-family: var(--font-body);
    font-size: .75rem;
    color: var(--ink-faint);
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    padding: 0 .45rem;
    line-height: 1.5;
}
.search:focus-within .search-kbd { opacity: 0; }

.chips {
    display: flex;
    gap: .35rem;
    padding: 4px;
    background: var(--bg-sunk);
    border-radius: 999px;
    overflow-x: auto;
    scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    height: 36px;
    padding: 0 .85rem;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 500;
    color: var(--ink-soft);
    white-space: nowrap;
    transition: background-color .2s, color .2s, box-shadow .2s;
}
.chip:hover { color: var(--ink); }
.chip.is-active {
    background: var(--bg-elev);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}
.chip-count {
    font-size: .72rem;
    font-variant-numeric: tabular-nums;
    padding: 1px 7px;
    border-radius: 99px;
    background: color-mix(in srgb, var(--ink) 8%, transparent);
    color: var(--ink-soft);
}
.chip.is-active .chip-count { background: var(--accent); color: var(--accent-ink); }

.toolbar-end { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

.select { position: relative; }
.select::after {
    content: '';
    position: absolute;
    right: 14px; top: 50%;
    width: 7px; height: 7px;
    border-right: 1.8px solid var(--ink-soft);
    border-bottom: 1.8px solid var(--ink-soft);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}
.select select {
    appearance: none;
    height: 42px;
    padding: 0 2.3rem 0 1rem;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--bg-elev);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
}

.view-toggle {
    display: flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--bg-sunk);
}
.view-toggle .icon-btn { width: 36px; height: 36px; }
.view-toggle svg { width: 17px; height: 17px; }
.view-toggle [aria-pressed='true'] { background: var(--bg-elev); color: var(--ink); box-shadow: var(--shadow-sm); }

.results-info {
    margin: 1.5rem 0 1.25rem;
    font-size: .9rem;
    color: var(--ink-soft);
}
.results-info strong { color: var(--ink); font-weight: 600; }

/* ---------- Generated book covers ---------- */
.cover {
    --bg: #333; --fg: #eee; --accent: #c90;
    position: relative;
    aspect-ratio: 2 / 3;
    width: 100%;
    border-radius: 3px 8px 8px 3px;
    overflow: hidden;
    background: var(--bg);
    color: var(--fg);
    box-shadow: var(--shadow);
    isolation: isolate;
    container-type: inline-size;
}
/* spine + sheen */
.cover::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, .28) 0, rgba(255, 255, 255, .14) 3%, rgba(0, 0, 0, .12) 6%, transparent 9%),
        linear-gradient(115deg, rgba(255, 255, 255, .14), transparent 40%);
}
.cover-art { position: absolute; inset: 0; z-index: 1; }
.cover-text {
    position: absolute;
    inset: 12% 10% 9% 14%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: .5rem;
}
.cover-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(.7rem, 11.5cqi, 1.6rem);
    line-height: 1.08;
    letter-spacing: -.01em;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    hyphens: auto;
}
.cover-author {
    font-size: clamp(.5rem, 6.5cqi, .8rem);
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    opacity: .85;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* pattern variants */
.cover--band .cover-art {
    background: linear-gradient(var(--accent), var(--accent)) 0 62% / 100% 7% no-repeat;
}
.cover--circle .cover-art {
    background: radial-gradient(circle at 78% 72%, var(--accent) 0 22%, transparent 22.5%),
                radial-gradient(circle at 78% 72%, transparent 0 28%, color-mix(in srgb, var(--accent) 45%, transparent) 28.5% 29.5%, transparent 30%);
}
.cover--frame .cover-art {
    inset: 6% 6% 6% 9%;
    border: 1.5px solid color-mix(in srgb, var(--fg) 55%, transparent);
    outline: 1px solid color-mix(in srgb, var(--fg) 25%, transparent);
    outline-offset: 4px;
}
.cover--diagonal .cover-art {
    background: linear-gradient(155deg, transparent 58%, var(--accent) 58.2% 66%, transparent 66.2% 70%, color-mix(in srgb, var(--accent) 50%, transparent) 70.2% 73%, transparent 73.2%);
}
.cover--dots .cover-art {
    background-image: radial-gradient(color-mix(in srgb, var(--accent) 70%, transparent) 1.4px, transparent 1.6px);
    background-size: 11px 11px;
    background-position: 0 0;
    mask-image: linear-gradient(to top, #000 0 38%, transparent 55%);
    -webkit-mask-image: linear-gradient(to top, #000 0 38%, transparent 55%);
}
.cover--split .cover-art {
    background: linear-gradient(to top, var(--accent) 0 34%, transparent 34%);
}
.cover--split .cover-author { color: var(--bg); opacity: 1; }

.cover--sm .cover-text { inset: 10% 9% 8% 13%; }
.cover--lg { border-radius: 4px 12px 12px 4px; box-shadow: var(--shadow-lg); }

/* ---------- Books grid ---------- */
.books {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 2.25rem 1.5rem;
}
.book {
    animation: fadeUp .6s var(--ease) both;
    animation-delay: calc(min(var(--i), 16) * 25ms);
}
.book-hit {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: .9rem;
    text-align: left;
    border-radius: var(--radius-sm);
    perspective: 900px;
}
.book-hit .cover {
    transform-origin: left center;
    transition: transform .45s var(--ease), box-shadow .45s var(--ease);
}
.book-hit:hover .cover,
.book-hit:focus-visible .cover {
    transform: rotateY(-14deg) translateY(-6px);
    box-shadow: 18px 22px 40px -18px rgba(30, 15, 5, .55), var(--shadow);
}
.book-info { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.book-title {
    font-size: .95rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.book-author {
    font-size: .84rem;
    color: var(--ink-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: .45rem;
}
.book-pages { font-size: .75rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.badges { display: inline-flex; gap: 4px; }
.badge {
    display: inline-grid;
    place-items: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    font-size: .68rem;
    font-weight: 700;
    color: var(--ink-faint);
    border: 1.5px dashed var(--line-strong);
    transition: transform .2s var(--ease);
}
.badge.is-read { border: 0; color: #fff; }
.badge-ibrahim.is-read { background: var(--ibrahim); }
.badge-esra.is-read { background: var(--esra); }
[data-theme='dark'] .badge.is-read { color: #111; }
.recent-meta .badge { width: 18px; height: 18px; font-size: .6rem; }

/* list layout */
.books[data-view='list'] {
    grid-template-columns: 1fr;
    gap: 0;
    border-top: 1px solid var(--line);
}
.books[data-view='list'] .book-hit {
    flex-direction: row;
    align-items: center;
    gap: 1.1rem;
    padding: .8rem .5rem;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    transition: background-color .2s;
}
.books[data-view='list'] .book-hit:hover { background: var(--bg-elev); }
.books[data-view='list'] .cover { width: 46px; flex: none; box-shadow: var(--shadow-sm); }
.books[data-view='list'] .cover-text { display: none; }
.books[data-view='list'] .book-hit:hover .cover { transform: none; box-shadow: var(--shadow-sm); }
.books[data-view='list'] .book-info {
    flex: 1;
    display: grid;
    grid-template-columns: 2fr 1.4fr auto;
    align-items: center;
    gap: 1rem;
}
.books[data-view='list'] .book-title { -webkit-line-clamp: 1; }
.books[data-view='list'] .book-foot { margin: 0; gap: 1.25rem; }
.books[data-view='list'] .book-pages { min-width: 52px; text-align: right; }

.sentinel { height: 1px; }

/* empty state */
.empty {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--ink-soft);
}
.empty svg { width: 44px; height: 44px; margin: 0 auto 1rem; color: var(--ink-faint); stroke-width: 1.4; }
.empty h3 { font-family: var(--font-display); font-size: 1.4rem; color: var(--ink); margin-bottom: .3rem; }
.empty .btn { margin-top: 1.25rem; }

/* ---------- Modal ---------- */
.modal {
    width: min(860px, calc(100% - 2rem));
    max-height: min(88vh, 760px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--bg-elev);
    color: var(--ink);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    margin: auto;
}
.modal[open] { animation: modalIn .35s var(--ease); }
.modal::backdrop {
    background: rgba(20, 14, 8, .55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn .3s ease;
}
.modal-body {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 2.25rem;
    padding: 2.25rem;
    max-height: inherit;
    overflow-y: auto;
}
.modal-cover {
    padding: 1.5rem;
    border-radius: var(--radius);
    background:
        radial-gradient(circle at 50% 110%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 70%),
        var(--bg-sunk);
    align-self: start;
}
.modal-cover .cover { animation: coverIn .6s var(--ease) both .05s; }
.modal-content { min-width: 0; padding-top: .25rem; }
.modal-content .eyebrow { margin-bottom: .6rem; padding-right: 2.5rem; }
.modal-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.6rem, 3.5vw, 2.3rem);
    line-height: 1.1;
    letter-spacing: -.02em;
}
.modal-author {
    margin-top: .5rem;
    font-size: 1.02rem;
    color: var(--ink-soft);
    text-decoration: underline;
    text-decoration-color: var(--line-strong);
    text-underline-offset: 4px;
    transition: color .2s, text-decoration-color .2s;
}
.modal-author:hover { color: var(--accent); text-decoration-color: currentColor; }
.modal-close { position: absolute; top: 1rem; right: 1rem; background: var(--bg-elev); }

.read-rows { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1.75rem; }
.read-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .9rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}
.read-row .badge { width: 34px; height: 34px; font-size: .85rem; flex: none; }
.read-row strong { display: block; font-size: .92rem; }
.read-row span:not(.badge) { font-size: .82rem; color: var(--ink-faint); }
.read-row.is-read span:not(.badge) { color: var(--ink-soft); }

.note {
    margin-top: 1.25rem;
    padding: .9rem 1.1rem;
    border-left: 3px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 7%, transparent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--ink-soft);
}

.more { margin-top: 1.75rem; }
.more h3 {
    font-size: .78rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: .6rem;
}
.more ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.more button {
    padding: .4rem .8rem;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    font-size: .84rem;
    transition: border-color .2s, color .2s;
}
.more button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Footer ---------- */
.footer {
    margin-top: 3rem;
    padding: 2.5rem 0;
    border-top: 1px solid var(--line);
    color: var(--ink-faint);
    font-size: .88rem;
}
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.heart { color: var(--esra); display: inline-block; animation: beat 1.8s ease-in-out infinite; }

/* ---------- Motion ---------- */
.is-ready .reveal:not(.is-visible) { opacity: 0; transform: translateY(14px); }
.reveal {
    transition: opacity .8s var(--ease), transform .8s var(--ease);
    transition-delay: var(--d, 0ms);
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.98); } }
@keyframes coverIn { from { opacity: 0; transform: rotateY(-25deg) translateX(-10px); } }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.2); } 30% { transform: scale(1); } }

::view-transition-old(root),
::view-transition-new(root) { animation-duration: .45s; }

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

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .insights-grid { grid-template-columns: 1fr; }
    .toolbar-end { margin-left: 0; width: 100%; }
    .toolbar-end .btn { margin-left: auto; }
}

@media (max-width: 680px) {
    .container { width: min(100% - 1.5rem, 1240px); }
    .nav-link { display: none; }
    .stat { padding: 1.1rem; }
    .stat-value { font-size: 2.1rem; }
    .panel { padding: 1.15rem; border-radius: var(--radius); }
    .chips { width: 100%; }
    .chip { flex: 1 0 auto; justify-content: center; }
    .toolbar-end .btn span { display: none; }
    .toolbar-end .btn { width: 42px; padding: 0; justify-content: center; }
    .books { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 1.75rem 1rem; }
    .books[data-view='list'] .book-info { grid-template-columns: 1fr auto; }
    .books[data-view='list'] .book-author { grid-row: 2; }
    .books[data-view='list'] .book-foot { grid-row: 1 / 3; grid-column: 2; flex-direction: column; align-items: flex-end; gap: .3rem; }
    .modal-body { grid-template-columns: 1fr; padding: 1.5rem; gap: 1.5rem; }
    .modal-cover { width: 200px; margin-inline: auto; padding: 1rem; }
    .read-rows { grid-template-columns: 1fr; }
    .modal { max-height: 92vh; }
}

@media (max-width: 420px) {
    .stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
    .stat-label { font-size: .78rem; }
}
