/* ============================================================
   The Living Bookshelf
   A warm study: wood shelves, cloth-bound spines, brass labels.
   ============================================================ */
:root{
  --ink:#2a2018;
  --wall-1:#241a13;
  --wall-2:#160f0a;
  --wood-1:#6b4526;
  --wood-2:#4a2d17;
  --wood-3:#3a2211;
  --wood-edge:#2a1809;
  --brass:#c8a765;
  --cream:#f3e9d6;
  --parchment:#efe4cf;
  --muted:#b8a488;
  --shadow:rgba(0,0,0,.45);
  --panel:#fbf5ea;
  --panel-ink:#332a20;
  --accent:#8a3b2e;
  --radius:14px;
  --topbar-h:120px;
}

*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0;
  font-family:"Inter",system-ui,-apple-system,sans-serif;
  color:var(--cream);
  background:
    radial-gradient(120% 90% at 50% -10%, #3a2a1d 0%, var(--wall-1) 42%, var(--wall-2) 100%) fixed;
  min-height:100vh;
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden; /* clip the off-screen (closed) drawer so it adds no h-scroll */
}

/* ---------------------------------------------------------- top bar */
.topbar{
  position:sticky; top:0; z-index:40;
  background:linear-gradient(180deg, rgba(20,13,8,.96), rgba(20,13,8,.86));
  backdrop-filter:blur(10px);
  border-bottom:1px solid rgba(200,167,101,.22);
  box-shadow:0 6px 24px rgba(0,0,0,.35);
}
.topbar-inner{
  max-width:1240px; margin:0 auto; padding:16px 22px 12px;
  display:flex; flex-wrap:wrap; gap:16px 28px; align-items:flex-end; justify-content:space-between;
}
.brand h1{
  font-family:"Fraunces",serif; font-weight:600; font-size:clamp(22px,3.4vw,34px);
  margin:0; letter-spacing:.3px; color:var(--parchment);
}
.tagline{margin:4px 0 0; font-size:14px; color:var(--muted); max-width:52ch}
.tagline strong{color:var(--brass); font-weight:600}
.count{color:var(--brass); font-weight:600; white-space:nowrap}

.controls{display:flex; flex-direction:column; gap:10px; align-items:flex-end; flex:1; min-width:280px}
.search-wrap{position:relative; width:100%; max-width:340px}
.search-ico{position:absolute; left:12px; top:50%; transform:translateY(-50%); width:18px; height:18px; color:var(--muted)}
#search{
  width:100%; padding:10px 14px 10px 38px; border-radius:999px;
  border:1px solid rgba(200,167,101,.35); background:rgba(255,255,255,.06);
  color:var(--cream); font-size:15px; outline:none; transition:border-color .2s, background .2s;
}
#search::placeholder{color:var(--muted)}
#search:focus{border-color:var(--brass); background:rgba(255,255,255,.1)}

.filters{display:flex; flex-wrap:wrap; gap:7px; justify-content:flex-end}
.chip{
  font:inherit; font-size:12.5px; font-weight:500; cursor:pointer;
  padding:5px 12px; border-radius:999px; color:var(--muted);
  border:1px solid rgba(200,167,101,.28); background:transparent; transition:all .16s;
}
.chip:hover{color:var(--cream); border-color:var(--brass)}
.chip[aria-pressed="true"]{background:var(--brass); color:#241a10; border-color:var(--brass); font-weight:600}
.chip.sort{margin-left:6px}

.roomnav{
  max-width:1240px; margin:0 auto; padding:0 22px 10px;
  display:flex; gap:8px; overflow-x:auto; scrollbar-width:thin;
}
.roomnav a{
  flex:0 0 auto; font-size:12.5px; color:var(--muted); text-decoration:none;
  padding:4px 11px; border-radius:999px; border:1px solid transparent; white-space:nowrap;
}
.roomnav a:hover{color:var(--cream); border-color:rgba(200,167,101,.3)}

/* ---------------------------------------------------------- library */
.library{max-width:1240px; margin:0 auto; padding:26px 22px 90px}
.loading{padding:80px 0; text-align:center; color:var(--muted); font-size:16px}

.room{margin:0 0 46px; scroll-margin-top:150px}
.room-head{display:flex; align-items:baseline; gap:14px; margin:0 4px 14px}
.room-head h2{
  font-family:"Fraunces",serif; font-weight:600; font-size:22px; margin:0;
  color:var(--parchment); letter-spacing:.4px;
}
.room-head .zone-sub{font-size:13px; color:var(--muted)}
.room-rule{flex:1; height:1px; background:linear-gradient(90deg, rgba(200,167,101,.4), transparent)}

/* ---------------------------------------------------------- a shelf */
.shelf{margin:0 0 30px}
.shelf-label{
  display:inline-flex; align-items:center; gap:8px; margin:0 0 8px 6px;
  font-size:12.5px; font-weight:600; letter-spacing:.6px; text-transform:uppercase;
  color:#2a1c0d; background:linear-gradient(180deg,#d8b877,#b98f4c);
  padding:3px 12px; border-radius:4px;
  box-shadow:0 1px 0 rgba(255,255,255,.35) inset, 0 2px 4px rgba(0,0,0,.35);
}
.shelf-label .n{opacity:.65}

/* one physical shelf-row; books that spill over wrap onto the next plank below */
.shelf-row{
  display:flex; align-items:flex-end; gap:3px; flex-wrap:nowrap;
  padding:22px 13px 0; overflow:visible; min-height:250px;
  position:relative; z-index:2;
}

/* one-book-wide space that separates two categories on the shelf */
.shelf-gap{ flex:0 0 auto; width:42px; align-self:flex-end; }

/* the category nameplate: zero-width so the category's books sit directly above
   it; its brass plate overflows to the right, embossed into the shelf edge */
.shelf-tag{
  flex:0 0 0; width:0; align-self:flex-end; overflow:visible;
  position:relative; z-index:3; transform:translateY(19px);
}
.shelf-tag span{
  display:inline-block;
  font-family:"Inter",system-ui,sans-serif;
  font-size:10.5px; font-weight:700; letter-spacing:1px; text-transform:uppercase;
  white-space:nowrap; padding:3px 12px 4px; border-radius:2px;
  /* recessed brass plate set into the wood */
  background:linear-gradient(180deg, #a9853f 0%, #c2a05a 45%, #9c7a37 100%);
  color:#4a3616;
  box-shadow:
    inset 0 2px 3px rgba(0,0,0,.55),          /* pressed-in shadow (top) */
    inset 0 -1px 1px rgba(255,244,210,.4),     /* catch-light (bottom) */
    0 1px 0 rgba(255,235,190,.18),             /* routed groove edge in wood */
    0 -1px 1px rgba(0,0,0,.35);
  /* engraved lettering */
  text-shadow:0 1px 0 rgba(255,246,214,.5), 0 -1px 1px rgba(0,0,0,.4);
}

/* the wooden ledge */
.shelf-plank{
  height:20px; border-radius:2px; margin-bottom:22px; z-index:1;
  background:
    linear-gradient(180deg, var(--wood-1) 0%, var(--wood-2) 55%, var(--wood-3) 100%);
  box-shadow:
    0 2px 0 var(--wood-edge),
    0 10px 18px -6px var(--shadow),
    inset 0 1px 0 rgba(255,220,170,.25);
  position:relative;
}
.shelf-plank::after{
  content:""; position:absolute; left:0; right:0; top:0; height:6px;
  background:linear-gradient(180deg, rgba(0,0,0,.28), transparent);
}

/* ---------------------------------------------------------- a spine */
.spine{
  --w:34px; --h:190px; --c:#4a5a6b;
  position:relative; flex:0 0 auto;
  width:var(--w); height:var(--h);
  border:0; padding:0; cursor:pointer; color:var(--cream);
  border-radius:3px 3px 1px 1px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.16) 0%, rgba(255,255,255,0) 14%,
      rgba(0,0,0,.12) 86%, rgba(0,0,0,.32) 100%),
    var(--c);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,.22),
    2px 3px 8px -3px rgba(0,0,0,.55);
  transform-origin:bottom center;
  transition:transform .22s cubic-bezier(.2,.8,.3,1), box-shadow .22s, filter .22s;
  overflow:hidden;
  display:flex; align-items:center; justify-content:center;
}
/* the book's own cover, shown at reduced opacity over its dominant colour so it
   is identifiable while the spine keeps a cohesive cloth tone */
.spine-art{
  position:absolute; inset:0; z-index:0;
  background-size:cover; background-position:center;
  opacity:.25; filter:saturate(1.05);
}
/* darken the centre band (behind the vertical title) so the cover's own text
   stops competing with the spine title, plus soft edge-shading */
.spine.has-art::after{
  content:""; position:absolute; inset:0; z-index:1; pointer-events:none;
  background:
    radial-gradient(58% 130% at 50% 50%, rgba(0,0,0,.5) 0%, rgba(0,0,0,.12) 62%, rgba(0,0,0,0) 100%),
    linear-gradient(90deg, rgba(255,255,255,.1) 0%, rgba(255,255,255,0) 16%,
      rgba(0,0,0,.12) 84%, rgba(0,0,0,.34) 100%);
}
.spine.has-art{color:#fbf5ea}
.spine.has-art .spine-title{text-shadow:0 1px 2px rgba(0,0,0,.95), 0 0 5px rgba(0,0,0,.9), 0 0 1px rgba(0,0,0,.95)}
.spine.has-art .spine-foot{text-shadow:0 1px 3px rgba(0,0,0,.9)}

/* head & tail bands */
.spine::before{
  content:""; position:absolute; left:0; right:0; top:10px; height:2px; z-index:2;
  background:rgba(0,0,0,.28); box-shadow:0 168px 0 rgba(0,0,0,.28), 0 1px 0 rgba(255,255,255,.14);
}
.spine-title{ position:relative; z-index:3;
  writing-mode:vertical-rl; text-orientation:mixed;
  font-family:"Fraunces",serif; font-weight:600; font-size:var(--fs,13px); line-height:1.16;
  max-height:calc(var(--h) - 18px); max-width:calc(var(--w) - 3px); overflow:hidden;
  padding:10px 0; letter-spacing:.15px; text-align:center;
  text-shadow:0 1px 1px rgba(0,0,0,.35);
  white-space:normal;   /* full title wraps to a 2nd column instead of an ellipsis */
}
.spine-foot{
  position:absolute; bottom:7px; left:0; right:0; text-align:center; z-index:3;
  font-size:7.5px; letter-spacing:.3px; opacity:.78; text-transform:uppercase;
  writing-mode:horizontal-tb;
}
.spine:hover, .spine:focus-visible{
  transform:translateY(-14px);
  box-shadow:inset 0 0 0 1px rgba(0,0,0,.22), 4px 12px 22px -6px rgba(0,0,0,.6);
  filter:brightness(1.08); outline:none;
}
.spine:focus-visible{outline:2px solid var(--brass); outline-offset:2px}
.spine.dim{opacity:.14; filter:grayscale(.6) brightness(.7); pointer-events:none}
.spine.hit{transform:translateY(-14px)}

/* light-coloured covers get dark ink + a pale highlight so titles stay legible */
.spine.light-spine{color:#2a2018}
.spine.light-spine .spine-title{text-shadow:0 1px 0 rgba(255,255,255,.35)}
.spine.light-spine .spine-foot{opacity:.6}
.spine.light-spine::before{background:rgba(0,0,0,.18); box-shadow:0 168px 0 rgba(0,0,0,.18), 0 1px 0 rgba(255,255,255,.3)}


/* ---------------------------------------------------------- detail drawer */
.scrim{
  position:fixed; inset:0; background:rgba(10,6,3,.55); z-index:50;
  opacity:0; transition:opacity .25s;
}
.scrim.show{opacity:1}
.drawer{
  position:fixed; top:0; right:0; height:100dvh; width:min(440px,92vw);
  background:var(--panel); color:var(--panel-ink); z-index:60;
  transform:translateX(100%); transition:transform .32s cubic-bezier(.2,.8,.25,1);
  box-shadow:-20px 0 50px -12px rgba(0,0,0,.5);
  overflow-y:auto; padding:0;
}
.drawer.open{transform:translateX(0)}
.drawer-close{
  position:absolute; top:14px; right:16px; z-index:2;
  width:34px; height:34px; border-radius:50%; border:0; cursor:pointer;
  font-size:24px; line-height:1; color:var(--panel-ink);
  background:rgba(0,0,0,.06); transition:background .15s;
}
.drawer-close:hover{background:rgba(0,0,0,.13)}
.drawer-body{padding:30px 30px 44px}

.d-hero{display:flex; gap:18px; align-items:flex-start; margin-bottom:20px}
.d-cover{
  flex:0 0 128px; width:128px; aspect-ratio:2/3; border-radius:5px; object-fit:cover;
  background:linear-gradient(135deg,#e7dcc6,#cdbfa2);
  box-shadow:0 10px 26px -8px rgba(0,0,0,.4), 0 0 0 1px rgba(0,0,0,.06);
}
.d-cover.placeholder{
  display:flex; align-items:center; justify-content:center; padding:14px; text-align:center;
  font-family:"Fraunces",serif; font-size:14px; color:#6a5c46;
}
.d-meta{flex:1; min-width:0}
.d-title{font-family:"Fraunces",serif; font-weight:600; font-size:22px; line-height:1.15; margin:2px 0 6px}
.d-author{font-size:15px; color:#6a5b45; margin:0 0 12px}
.d-tags{display:flex; flex-wrap:wrap; gap:6px}
.d-tag{
  font-size:11.5px; font-weight:600; letter-spacing:.3px; padding:3px 9px; border-radius:999px;
  background:rgba(0,0,0,.06); color:#4a3f2e;
}
.d-tag.genre{background:var(--panel-ink); color:var(--panel)}
.d-tag.rating{background:#8a5a1e; color:#fff}
.d-summary{
  margin-top:20px; font-size:15.5px; line-height:1.62; color:#403626;
  font-family:"Fraunces",serif; font-weight:400;
}
.d-summary.empty{color:#9a8b72; font-style:italic}
.d-foot{margin-top:22px; padding-top:14px; border-top:1px solid rgba(0,0,0,.1); font-size:12.5px; color:#8a7c64}

/* ---------------------------------------------------------- misc */
.empty{
  display:none; text-align:center; color:var(--muted); padding:40px; font-size:16px;
}
.empty[hidden]{display:none}
.empty.show{display:block}
.foot{
  text-align:center; color:var(--muted); font-size:12.5px; padding:0 20px 40px;
}
.foot strong{color:var(--brass)}

@media (max-width:640px){
  .topbar-inner{flex-direction:column; align-items:stretch}
  .controls{align-items:stretch}
  .search-wrap{max-width:none}
  .filters{justify-content:flex-start}
  .drawer{width:100vw; height:auto; top:auto; bottom:0; max-height:88dvh;
    transform:translateY(100%); border-radius:18px 18px 0 0}
  .drawer.open{transform:translateY(0)}
}

@media (prefers-reduced-motion:reduce){
  html{scroll-behavior:auto}
  *{transition:none !important; animation:none !important}
  .spine:hover,.spine:focus-visible{transform:none}
}
