/* ==========================================================================================
   The Library — design tokens
   ========================================================================================== */
:root {
  --bg: #0b0d12;
  --bg-2: #12151d;
  --bg-3: #1a1e28;
  --ink: #ece6da;
  --ink-2: #b9b3a5;
  --ink-3: #8b867b;
  --gold: #e0b45c;
  --gold-2: #f3cc76;
  --gold-dim: rgba(224, 180, 92, .16);
  --paper: #e9e2d0;
  --teal: #6cc4b0;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .15);
  --glass: rgba(15, 17, 24, .72);
  --glass-2: rgba(20, 23, 32, .88);
  --shadow-1: 0 4px 14px rgba(0, 0, 0, .35);
  --shadow-2: 0 18px 48px rgba(0, 0, 0, .55);
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-pill: 999px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --dur-1: 150ms;
  --dur-2: 260ms;
  --dur-3: 460ms;
  --font-ui: "Manrope", "Noto Nastaliq Urdu", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Noto Nastaliq Urdu", Georgia, "Times New Roman", serif;
  --fs-xs: clamp(.72rem, .69rem + .15vw, .8rem);
  --fs-sm: clamp(.82rem, .79rem + .18vw, .9rem);
  --fs-md: clamp(.95rem, .9rem + .25vw, 1.05rem);
  --fs-lg: clamp(1.15rem, 1.05rem + .5vw, 1.45rem);
  --fs-xl: clamp(1.7rem, 1.3rem + 1.6vw, 2.5rem);
  --fs-2xl: clamp(2.2rem, 1.6rem + 3vw, 3.6rem);
  --topbar-h: 64px;
  --filters-w: 300px;
  --gutter: clamp(16px, 2.5vw, 32px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 800px at 70% -10%, #1a1f2e 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body.reading, body.modal-open { overflow: hidden; }
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-2); }
button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; letter-spacing: -.01em; margin: 0; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em; color: var(--gold-2); word-break: break-all; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); }
.small { font-size: var(--fs-sm); }
.ur, [dir="rtl"] { font-family: "Noto Nastaliq Urdu", var(--font-ui); line-height: 1.95; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
:focus:not(:focus-visible) { outline: none; }

.skip { position: fixed; top: -100px; left: 16px; z-index: 200; padding: 10px 16px; background: var(--gold); color: #1a1408; border-radius: var(--r-sm); font-weight: 700; }
.skip:focus { top: 12px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line-2); border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .04); color: var(--ink);
  font-weight: 600; font-size: var(--fs-sm); white-space: nowrap;
  transition: transform var(--dur-1) var(--ease), background var(--dur-1), border-color var(--dur-1), box-shadow var(--dur-2);
}
.btn:hover { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .22); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn.gold { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #1e1707; border-color: transparent; box-shadow: 0 6px 18px rgba(224, 180, 92, .25); }
.btn.gold:hover { box-shadow: 0 10px 26px rgba(224, 180, 92, .38); filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.lg { min-height: 48px; padding: 0 22px; font-size: var(--fs-md); }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: progress; transform: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid transparent; border-radius: 50%; background: transparent; color: var(--ink-2);
  font-size: 22px; line-height: 1;
  transition: background var(--dur-1), color var(--dur-1), transform var(--dur-1) var(--ease);
}
.icon-btn:hover { background: rgba(255, 255, 255, .08); color: var(--ink); }
.link { background: none; border: 0; padding: 0; color: var(--gold); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--gold-2); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--gold); color: #1e1707; font-size: 11px; font-weight: 800; }

/* ------------------------------------------------------------------ loading */
.loading {
  position: fixed; inset: 0; z-index: 400;
  display: grid; place-content: center; justify-items: center; gap: 18px;
  background: var(--bg);
  transition: opacity var(--dur-3) var(--ease), visibility var(--dur-3);
}
.loading.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-mark { display: flex; gap: 6px; align-items: flex-end; height: 44px; }
.loading-mark span { width: 12px; border-radius: 3px 3px 2px 2px; background: var(--gold); opacity: .85; animation: bookrise 1.2s var(--ease) infinite; }
.loading-mark span:nth-child(1) { height: 30px; }
.loading-mark span:nth-child(2) { height: 42px; background: var(--paper); animation-delay: .15s; }
.loading-mark span:nth-child(3) { height: 36px; animation-delay: .3s; }
@keyframes bookrise { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.loading-text { margin: 0; color: var(--ink-2); font-family: var(--font-display); font-size: var(--fs-lg); font-style: italic; }
.loading-bar { width: 220px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.loading-bar span { display: block; height: 100%; width: 5%; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transition: width var(--dur-2) var(--ease); }

/* ------------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
  height: var(--topbar-h); padding: 0 var(--gutter);
  background: var(--glass); backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); min-width: 0; }
.brand-mark svg { display: block; border-radius: 9px; box-shadow: var(--shadow-1); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-family: var(--font-display); font-size: 1.25rem; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; }
.brand-stats { font-size: var(--fs-xs); color: var(--ink-3); white-space: nowrap; letter-spacing: .02em; }

.search { position: relative; display: flex; align-items: center; max-width: 560px; justify-self: center; width: 100%; }
.search-icon { position: absolute; left: 14px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; height: 42px; padding: 0 44px 0 42px;
  border: 1px solid var(--line-2); border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .05); color: var(--ink); font: inherit; font-size: var(--fs-sm);
  transition: border-color var(--dur-1), background var(--dur-1), box-shadow var(--dur-2);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: none; border-color: rgba(224, 180, 92, .6); background: rgba(255, 255, 255, .07); box-shadow: 0 0 0 4px var(--gold-dim); }
.search input::-webkit-search-cancel-button { display: none; }
.search-kbd { position: absolute; right: 14px; padding: 2px 7px; border: 1px solid var(--line-2); border-radius: 6px; color: var(--ink-3); font-family: var(--font-ui); font-size: 11px; pointer-events: none; }
.search input:focus ~ .search-kbd, .search.has-value .search-kbd { display: none; }
.search-clear { position: absolute; right: 4px; width: 34px; height: 34px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line-2); border-radius: var(--r-pill); background: rgba(255, 255, 255, .04); }
.seg button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 14px; border: 0; border-radius: var(--r-pill); background: transparent; color: var(--ink-2);
  font-size: var(--fs-sm); font-weight: 600; transition: background var(--dur-2) var(--ease), color var(--dur-1);
}
.seg button svg { flex: none; opacity: .8; }
.seg button[aria-selected="true"] { background: var(--ink); color: #14121a; box-shadow: var(--shadow-1); }
.sort select {
  height: 40px; padding: 0 34px 0 14px; border: 1px solid var(--line-2); border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .04) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23b9b3a5' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center / 14px;
  color: var(--ink); font: inherit; font-size: var(--fs-sm); font-weight: 600; appearance: none; -webkit-appearance: none; cursor: pointer;
}
.sort select:hover { background-color: rgba(255, 255, 255, .08); }
.sort select option { background: var(--bg-3); color: var(--ink); }

/* ------------------------------------------------------------------ filters panel */
.filters {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 90;
  width: var(--filters-w); display: flex; flex-direction: column;
  background: var(--glass); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-right: 1px solid var(--line);
  transform: translateX(-100%); visibility: hidden;
  transition: transform var(--dur-3) var(--ease), visibility var(--dur-3);
}
.filters.open { transform: none; visibility: visible; }
.filters-head { display: flex; align-items: center; gap: 12px; padding: 18px 16px 12px 22px; }
.filters-head h2 { font-size: var(--fs-lg); flex: 1; }
.filters-body { flex: 1; overflow-y: auto; padding: 0 12px 40px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.facet-group { margin: 6px 0; border-top: 1px solid var(--line); }
.facet-group summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 10px; cursor: pointer; list-style: none;
  font-weight: 700; font-size: var(--fs-sm); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2);
}
.facet-group summary::-webkit-details-marker { display: none; }
.facet-group summary::after { content: ""; width: 8px; height: 8px; margin-left: auto; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(-45deg); transition: transform var(--dur-2) var(--ease); }
.facet-group[open] summary::after { transform: rotate(45deg); }
.facet-group summary .n { color: var(--ink-3); font-weight: 500; letter-spacing: 0; text-transform: none; }
.facet-search { width: calc(100% - 20px); margin: 0 10px 8px; height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: rgba(255,255,255,.04); color: var(--ink); font: inherit; font-size: var(--fs-sm); }
.facet-search:focus { outline: none; border-color: rgba(224,180,92,.5); }
.facet-list { display: flex; flex-direction: column; gap: 2px; padding: 0 4px 8px; }
.facet {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); text-align: left;
  font-size: var(--fs-sm); transition: background var(--dur-1), color var(--dur-1);
}
.facet:hover { background: rgba(255, 255, 255, .06); color: var(--ink); }
.facet[aria-pressed="true"] { background: var(--gold-dim); color: var(--gold-2); }
.facet[aria-pressed="true"]::before { content: "✓"; font-size: 11px; font-weight: 800; }
.facet-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet.ur .facet-name { white-space: normal; line-height: 1.8; }
.facet-count { color: var(--ink-3); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.facet.zero { opacity: .38; }
.facet-more { margin: 2px 10px 10px; }

/* ------------------------------------------------------------------ active chips */
.chips {
  position: fixed; left: var(--gutter); right: var(--gutter); top: calc(var(--topbar-h) + 12px); z-index: 60;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; pointer-events: none;
}
.chips:empty { display: none; }
.chips > * { pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 6px 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-pill);
  background: var(--glass-2); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: var(--ink); font-size: var(--fs-xs); font-weight: 600; box-shadow: var(--shadow-1);
  animation: chipin var(--dur-2) var(--ease-spring);
}
.chip b { color: var(--ink-3); font-weight: 600; }
.chip button { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 50%; background: rgba(255,255,255,.08); color: var(--ink-2); font-size: 15px; line-height: 1; }
.chip button:hover { background: var(--gold); color: #1e1707; }
.chip.count { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); padding-left: 4px; backdrop-filter: none; text-shadow: 0 1px 6px rgba(0,0,0,.8); }
@keyframes chipin { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
body.shelf-view .chips { position: static; padding: 18px var(--gutter) 0; }

/* ------------------------------------------------------------------ 3D gallery */
.gallery { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 1; overflow: hidden; background: var(--bg); }
#gl { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#gl.dragging { cursor: grabbing; }
#gl.hit { cursor: pointer; }
.gl-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(5, 6, 9, .75) 100%); }
.gl-label {
  position: absolute; left: 50%; bottom: 68px; transform: translateX(-50%); z-index: 5;
  max-width: min(640px, 92%); padding: 12px 22px; pointer-events: none; text-align: center;
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  background: var(--glass-2); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-2);
  animation: chipin var(--dur-1) var(--ease);
}
.gl-label .t { display: block; font-family: var(--font-display); font-size: var(--fs-lg); line-height: 1.25; text-wrap: balance; }
.gl-label .t.ur { line-height: 1.9; }
.gl-label .a { display: block; margin-top: 4px; color: var(--ink-2); font-size: var(--fs-sm); }
.gl-label .a em { color: var(--gold); font-style: normal; }
.gl-sections { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.gl-genre {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  padding: 7px 14px; border: 1px solid rgba(224, 180, 92, .35); border-radius: var(--r-pill);
  background: var(--glass-2); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: var(--gold-2); font-family: var(--font-display); font-size: var(--fs-md); white-space: nowrap;
  box-shadow: var(--shadow-1); cursor: pointer; opacity: 0; transition: opacity var(--dur-2);
  will-change: transform, opacity;
}
.gl-genre:hover { background: var(--gold-dim); border-color: var(--gold); }
.gl-genre span { margin-left: 9px; color: var(--ink-3); font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 600; }
.gl-hint {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 4;
  display: flex; gap: 10px; align-items: center; padding: 8px 16px; border-radius: var(--r-pill);
  background: rgba(10, 12, 18, .55); color: var(--ink-2); font-size: var(--fs-xs); letter-spacing: .02em; white-space: nowrap;
  transition: opacity var(--dur-3);
}
.gl-hint i { color: var(--ink-3); font-style: normal; }
.gl-hint.fade { opacity: 0; pointer-events: none; }
.gl-empty { position: absolute; inset: 0; display: grid; place-content: center; z-index: 4; font-family: var(--font-display); font-size: var(--fs-lg); color: var(--ink-2); text-align: center; }
.gl-nav { position: absolute; right: 14px; top: 20%; bottom: 20%; width: 3px; border-radius: 3px; background: rgba(255, 255, 255, .08); z-index: 4; }
.gl-nav span { position: absolute; left: 0; right: 0; height: 12%; border-radius: 3px; background: var(--gold); opacity: .8; }

/* ------------------------------------------------------------------ shelf grid */
.shelf { position: relative; z-index: 2; padding: 12px var(--gutter) 40px; min-height: calc(100vh - var(--topbar-h)); }
.grid {
  display: grid; gap: clamp(14px, 2vw, 26px);
  grid-template-columns: repeat(auto-fill, minmax(clamp(120px, 11vw, 162px), 1fr));
  padding-top: 12px;
}
.grid-section {
  grid-column: 1 / -1; position: sticky; top: calc(var(--topbar-h) + 6px); z-index: 4;
  display: flex; align-items: baseline; gap: 14px; margin: 22px 0 0; padding: 9px 14px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--glass-2); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: var(--fs-lg); font-weight: 500; color: var(--gold-2);
}
.grid-section:first-child { margin-top: 4px; }
.grid-section .gs-count { color: var(--ink-3); font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.card {
  display: flex; flex-direction: column; gap: 8px; padding: 0; border: 0; background: transparent; text-align: left;
  color: var(--ink); perspective: 900px; content-visibility: auto; contain-intrinsic-size: 180px 330px;
  animation: cardin var(--dur-3) var(--ease) both;
}
@keyframes cardin { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.cover {
  position: relative; display: block; aspect-ratio: 2 / 3; border-radius: 6px 10px 10px 6px; overflow: hidden;
  background: var(--c, var(--bg-3));
  box-shadow: inset 3px 0 6px -3px rgba(255,255,255,.35), var(--shadow-1);
  transform-style: preserve-3d; transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2);
}
.cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(105deg, rgba(255,255,255,.14) 0%, transparent 28%, transparent 70%, rgba(0,0,0,.18) 100%); pointer-events: none; }
.cover img { width: 100%; height: 100%; object-fit: cover; background: var(--c, var(--bg-3)); }
.cover img.contain { object-fit: contain; }
.card:hover .cover, .card:focus-visible .cover { box-shadow: inset 3px 0 6px -3px rgba(255,255,255,.4), var(--shadow-2), 0 0 0 1px rgba(224,180,92,.35); }
.card-title { font-family: var(--font-display); font-size: var(--fs-md); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-title.ur { line-height: 1.85; -webkit-line-clamp: 2; }
.card-author { color: var(--ink-2); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-fmts { display: flex; gap: 6px; }
.card-fmts i { font-style: normal; font-size: 10px; font-weight: 800; letter-spacing: .06em; padding: 2px 6px; border-radius: 4px; background: rgba(255,255,255,.08); color: var(--ink-2); }
.card-fmts i.off { text-decoration: line-through; opacity: .5; }
.empty { padding: 80px 0; text-align: center; font-family: var(--font-display); font-size: var(--fs-lg); color: var(--ink-2); }
.sentinel { height: 1px; }
.foot { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; margin-top: 48px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: var(--fs-xs); }

/* ------------------------------------------------------------------ detail panel */
.backdrop { position: fixed; inset: 0; z-index: 110; background: rgba(4, 5, 8, .55); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: fadein var(--dur-2) both; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.detail {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 120; width: min(560px, 100vw);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--glass-2); backdrop-filter: blur(24px) saturate(160%); -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-left: 1px solid var(--line); box-shadow: -20px 0 60px rgba(0,0,0,.5);
  animation: slidein var(--dur-3) var(--ease) both;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent;
}
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.detail-close { position: sticky; top: 12px; margin-left: auto; margin-right: 12px; z-index: 2; background: rgba(0,0,0,.35); float: right; }
.detail-body { padding: 8px 28px 48px; clear: both; }
.detail-hero { display: grid; grid-template-columns: 150px 1fr; gap: 22px; align-items: start; margin-top: -32px; }
.detail-cover { aspect-ratio: 2 / 3; border-radius: 6px 12px 12px 6px; overflow: hidden; background: var(--c, var(--bg-3)); box-shadow: inset 3px 0 6px -3px rgba(255,255,255,.35), var(--shadow-2); transform: rotateY(8deg) rotateX(2deg); transform-style: preserve-3d; transition: transform var(--dur-3) var(--ease); }
.detail-cover:hover { transform: rotateY(0) rotateX(0) scale(1.02); }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover img.contain { object-fit: contain; }
.detail-kicker { color: var(--gold); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
#detail-title { font-size: var(--fs-xl); line-height: 1.15; margin: 4px 0 8px; text-wrap: balance; }
#detail-title.ur { line-height: 1.8; }
.detail-authors { color: var(--ink-2); font-size: var(--fs-md); }
.detail-authors button { background: none; border: 0; padding: 0; color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: rgba(255,255,255,.25); text-underline-offset: 3px; }
.detail-authors button:hover { color: var(--gold-2); }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 14px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 8px; }
.detail-actions .btn { flex: 1 1 auto; justify-content: center; }
.detail-formats { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 20px; }
.fmt-btn { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--r-pill); background: rgba(255,255,255,.04); color: var(--ink-2); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em; }
.fmt-btn:hover { color: var(--ink); background: rgba(255,255,255,.08); }
.fmt-btn small { color: var(--ink-3); font-weight: 500; letter-spacing: 0; }
.fmt-btn.off { opacity: .45; cursor: not-allowed; text-decoration: line-through; }
.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-meta div { min-width: 0; }
.detail-meta dt { color: var(--ink-3); font-size: var(--fs-xs); letter-spacing: .06em; text-transform: uppercase; }
.detail-meta dd { margin: 2px 0 0; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.detail-meta dd button, .detail-tags button { border: 0; padding: 0; background: none; color: var(--ink); text-decoration: underline; text-decoration-color: rgba(255,255,255,.25); text-underline-offset: 3px; text-align: left; }
.detail-meta dd button:hover, .detail-tags button:hover { color: var(--gold-2); }
.detail-section { margin-top: 22px; }
.detail-section h3 { font-size: var(--fs-xs); font-family: var(--font-ui); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-tags button { padding: 5px 11px !important; border-radius: var(--r-pill); background: rgba(255,255,255,.06) !important; font-size: var(--fs-xs); text-decoration: none !important; }
.detail-tags button:hover { background: var(--gold-dim) !important; }
.detail-desc { color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.65; }
.detail-desc p { margin: 0 0 .8em; }
.detail-desc h1, .detail-desc h2, .detail-desc h3, .detail-desc h4 { font-family: var(--font-ui); font-size: 1em; font-weight: 700; color: var(--ink); margin: 1em 0 .4em; }
.detail-desc ul, .detail-desc ol { padding-left: 1.2em; }
.detail-links { display: flex; flex-wrap: wrap; gap: 14px; font-size: var(--fs-sm); }

/* ------------------------------------------------------------------ reader */
.reader { position: fixed; inset: 0; z-index: 300; display: flex; flex-direction: column; background: #0f1117; }
.reader-bar {
  display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 12px; flex: none;
  background: var(--glass-2); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.reader-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-display); font-size: var(--fs-md); }
.reader-title.ur { line-height: 1.6; }
.reader-title small { color: var(--ink-3); font-family: var(--font-ui); font-size: var(--fs-xs); margin-left: 8px; }
.reader-tools { display: flex; align-items: center; gap: 4px; }
.reader-tools .btn { min-height: 34px; padding: 0 12px; }
.reader-body { position: relative; flex: 1; min-height: 0; }
.reader-frame { width: 100%; height: 100%; border: 0; background: #2a2a2e; }
.reader-epub { position: absolute; inset: 0 0 46px 0; }
.reader-epub.light { background: #f7f3ea; }
.reader-epub.sepia { background: #f1e7d0; }
.reader-epub.dark { background: #0f1117; }
.reader-turn { position: absolute; top: 0; bottom: 46px; width: 14%; max-width: 160px; border: 0; background: transparent; color: transparent; cursor: pointer; z-index: 3; }
.reader-turn:hover { background: linear-gradient(90deg, rgba(0,0,0,.12), transparent); }
.reader-turn.next { right: 0; }
.reader-turn.next:hover { background: linear-gradient(270deg, rgba(0,0,0,.12), transparent); }
.reader-turn.prev { left: 0; }
.reader-foot { position: absolute; left: 0; right: 0; bottom: 0; height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--glass-2); border-top: 1px solid var(--line); color: var(--ink-3); font-size: var(--fs-xs); }
.reader-foot input[type="range"] { flex: 1; accent-color: var(--gold); }
.reader-toc { position: absolute; top: 0; left: 0; bottom: 46px; z-index: 5; width: min(360px, 90vw); overflow-y: auto; padding: 14px 8px 30px; background: var(--glass-2); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-right: 1px solid var(--line); box-shadow: var(--shadow-2); animation: slidein var(--dur-2) var(--ease) both; }
.reader-toc h3 { padding: 4px 12px 10px; font-family: var(--font-ui); font-size: var(--fs-xs); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.reader-toc button { display: block; width: 100%; padding: 8px 12px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); text-align: left; font-size: var(--fs-sm); }
.reader-toc button:hover { background: rgba(255,255,255,.06); color: var(--ink); }
.reader-toc button.l2 { padding-left: 28px; font-size: var(--fs-xs); }
.reader-status { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; justify-items: center; z-index: 4; background: #0f1117; color: var(--ink-2); font-family: var(--font-display); font-size: var(--fs-lg); font-style: italic; text-align: center; padding: 20px; }
.reader-status .spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.12); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ modal */
.modal { position: fixed; inset: 0; z-index: 250; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4,5,8,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fadein var(--dur-2) both; }
.modal-card { position: relative; width: min(460px, 100%); padding: 28px; border: 1px solid var(--line-2); border-radius: var(--r-lg); background: var(--glass-2); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); box-shadow: var(--shadow-2); animation: chipin var(--dur-3) var(--ease-spring) both; }
.modal-card h2 { font-size: var(--fs-xl); margin-bottom: 6px; }
.modal-close { position: absolute; top: 10px; right: 10px; }
.share-qr { display: grid; place-items: center; margin: 18px auto; padding: 12px; width: fit-content; border-radius: var(--r-md); background: #fff; }
.share-qr svg { display: block; width: 180px; height: 180px; }
.share-row { display: flex; gap: 8px; }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.share-actions .btn { flex: 1 1 auto; justify-content: center; }
.share-row input { flex: 1; min-width: 0; height: 42px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: var(--r-pill); background: rgba(255,255,255,.05); color: var(--ink); font: inherit; font-size: var(--fs-sm); }

/* ------------------------------------------------------------------ visitors + reading */
.me { gap: 10px; padding-left: 6px; max-width: 200px; }
.me #me-name { overflow: hidden; text-overflow: ellipsis; }
.me-avatar { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #1e1707; font-weight: 800; font-size: 13px; }
.welcome-card { text-align: center; }
.welcome-mark { display: flex; justify-content: center; margin-bottom: 10px; }
.welcome-mark svg { border-radius: 14px; box-shadow: var(--shadow-2); }
.welcome-card .share-row { margin: 20px 0 14px; }
.welcome-card input { text-align: center; font-size: var(--fs-md); }
.continue { margin: 14px 0 4px; }
.continue-title { margin: 0 0 10px 4px; font-size: var(--fs-lg); color: var(--gold-2); }
.continue-row { display: flex; gap: 14px; overflow-x: auto; padding: 4px 4px 12px; scroll-snap-type: x proximity; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.continue-row .card { flex: 0 0 clamp(118px, 12vw, 150px); scroll-snap-align: start; }
.progress { position: relative; display: block; height: 4px; border-radius: 2px; background: rgba(255,255,255,.1); overflow: hidden; }
.progress span { position: absolute; inset: 0; width: var(--p, 0%); border-radius: 2px; background: linear-gradient(90deg, var(--gold), var(--gold-2)); }
.card > .progress { margin-top: -2px; }
.card-meta { color: var(--ink-3); font-size: var(--fs-xs); }
.detail-reading { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; padding: 10px 14px; border-radius: var(--r-md); background: var(--gold-dim); color: var(--gold-2); font-size: var(--fs-sm); }
.detail-reading .progress { flex: 1; min-width: 60px; }
.me-card { width: min(560px, 100%); }
.me-list { display: flex; flex-direction: column; gap: 6px; max-height: 44vh; overflow-y: auto; margin: 14px 0 16px; padding-right: 4px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.me-item { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 8px; border-radius: var(--r-md); background: rgba(255,255,255,.04); }
.me-item img { width: 44px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; background: var(--bg-3); }
.me-item .t { font-family: var(--font-display); font-size: var(--fs-sm); line-height: 1.25; }
.me-item .t.ur { line-height: 1.8; }
.me-item .s { margin-top: 3px; color: var(--ink-3); font-size: var(--fs-xs); }
.me-item .progress { margin-top: 6px; }
.me-item .btn { min-height: 34px; padding: 0 12px; }
.me-empty { padding: 18px 0; color: var(--ink-3); text-align: center; }
.board-card { width: min(540px, 100%); }
.board-periods { margin: 10px 0 14px; }
.board-list { list-style: none; margin: 0; padding: 0 4px 0 0; max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.board-item { display: grid; grid-template-columns: 36px 32px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: var(--r-md); background: rgba(255,255,255,.04); }
.board-item.you { background: var(--gold-dim); box-shadow: inset 0 0 0 1px rgba(224,180,92,.45); }
.board-rank { font-family: var(--font-display); font-size: var(--fs-md); color: var(--ink-2); text-align: center; font-variant-numeric: tabular-nums; }
.board-rank.top { font-size: 20px; }
.board-name { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-name small { display: block; color: var(--ink-3); font-weight: 500; font-size: var(--fs-xs); }
.board-time { color: var(--gold-2); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.board-empty { padding: 22px; color: var(--ink-3); text-align: center; }

/* ------------------------------------------------------------------ toast */
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 500; transform: translate(-50%, 20px); opacity: 0; max-width: min(520px, 90vw); padding: 12px 18px; border: 1px solid var(--line-2); border-radius: var(--r-md); background: var(--glass-2); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: var(--shadow-2); font-size: var(--fs-sm); text-align: center; pointer-events: none; transition: transform var(--dur-3) var(--ease), opacity var(--dur-3); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.busy::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px; vertical-align: -1px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--gold); animation: spin 1s linear infinite; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1360px) and (min-width: 901px) {
  /* medium widths: icon-only buttons so the search keeps room */
  .topbar-actions .btn span:not(.badge) { display: none; }
  .topbar-actions .btn { padding: 0 12px; }
  #me #me-name { display: none; }
  #me { padding: 0 6px; }
  .search { min-width: 170px; }
}
@media (min-width: 1100px) {
  body.shelf-view.filters-open .shelf { padding-left: calc(var(--filters-w) + var(--gutter)); }
  body.shelf-view.filters-open .chips { padding-left: calc(var(--filters-w) + var(--gutter)); }
  body.filters-open .gl-hint { left: calc(50% + var(--filters-w) / 2); }
  #filters-backdrop { display: none !important; }
}
@media (max-width: 1099px) {
  .filters { width: min(360px, 88vw); box-shadow: var(--shadow-2); }
}
@media (max-width: 900px) {
  :root { --topbar-h: 112px; }
  .topbar { grid-template-columns: 1fr auto auto auto auto; grid-template-rows: auto auto; row-gap: 10px; column-gap: 6px; height: auto; padding-top: 10px; padding-bottom: 10px; }
  .topbar-actions { display: contents; }
  .brand { grid-column: 1; grid-row: 1; }
  #board-btn { grid-column: 2; grid-row: 1; padding: 0 10px; }
  #me { grid-column: 3; grid-row: 1; padding: 0 6px; }
  #me #me-name { display: none; }
  #filters-btn { grid-column: 4; grid-row: 1; }
  #share-btn { grid-column: 5; grid-row: 1; justify-self: end; }
  .search { grid-column: 1 / 5; grid-row: 2; max-width: none; }
  .seg { grid-column: 5; grid-row: 2; justify-self: end; }
  .seg button span { display: none; }
  .seg button { padding: 8px 12px; }
  .brand-stats { display: none; }
  .brand-name { overflow: hidden; text-overflow: ellipsis; }
  .sort { display: none; }
  .btn span:not(.badge) { display: none; }
  .btn { padding: 0 12px; }
  .detail-hero { grid-template-columns: 120px 1fr; gap: 16px; margin-top: 0; }
  .detail-body { padding: 8px 18px 40px; }
  .detail-meta { grid-template-columns: 1fr 1fr; }
  .gl-hint { display: none; }
  .reader-title small { display: none; }
  .reader-turn { width: 22%; }
}
@media (max-width: 560px) {
  .brand-name { font-size: 1.05rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
  .card-title { font-size: var(--fs-sm); }
  .detail-hero { grid-template-columns: 1fr; }
  .detail-cover { width: 150px; }
  .modal-card { padding: 22px 18px; }
  .reader-tools .btn { padding: 0 9px; }
}
@media (hover: none) {
  .card:hover .cover { transform: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
