/* Library: a dim reading room with a wooden bookcase. Every book is a CSS 3D
   box (.box3d) with real faces, so it can be turned, pulled out, carried to
   another shelf and opened. Each shelf row is its own small 3D scene: a camera
   slightly above it, a plank floor the books stand on and the plank's front
   edge, all depth-sorted together. */

:root {
  --text: #f1e7d6;
  --muted: #bca991;
  --dim: #86745d;
  --brass-hi: #f6dea0;
  --brass: #cfa553;
  --brass-lo: #7f6024;
  --paper: #f3e9d4;
  --ink: #2b2017;
  --danger: #e07a64;

  --serif: 'C059', 'Century Schoolbook', 'P052', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Noto Serif', 'DejaVu Serif', serif;
  --display: 'Noto Serif Display', 'C059', Georgia, 'Noto Serif', serif;
  --sans: 'Ubuntu', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Noto Sans', 'DejaVu Sans', sans-serif;
  --narrow: 'Ubuntu Condensed', 'Roboto Condensed', 'Arial Narrow', 'Noto Sans', sans-serif;
  --mono: 'Nimbus Mono PS', 'Courier Prime', 'Courier New', 'Liberation Mono', monospace;

  --row-h: 238px;
  --edge-h: 24px;
  --floor-d: 210px;
  --row-pad: 18px;
  --side-w: 26px;
  --board-h: 42px;
  --cam: 1500px;
  --cam-y: -110px;

  --ease-out: cubic-bezier(.2, .85, .25, 1);
  --spring: cubic-bezier(.3, 1.3, .5, 1);

  /* Wood grain: stretched fractal noise turned into translucent dark streaks,
     laid over a base colour. Tileable, rasterised once. */
  --grain-h: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='900' height='96'><filter id='f' x='0' y='0' width='100%' height='100%'><feTurbulence type='fractalNoise' baseFrequency='0.0032 0.21' numOctaves='3' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.11  0 0 0 0 0.05  0 0 0 0 0.02  0 0 0 -1.7 1.06'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
  --grain-v: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='96' height='900'><filter id='f' x='0' y='0' width='100%' height='100%'><feTurbulence type='fractalNoise' baseFrequency='0.21 0.0032' numOctaves='3' seed='11' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.11  0 0 0 0 0.05  0 0 0 0 0.02  0 0 0 -1.7 1.06'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
  --noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.5 -0.12'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  /* Marbled endpaper: wavy noise, swirled by a second noise field and banded
     into a cream, blue, oxblood and ochre palette. The filter area is larger
     than the tile so the swirls never pull in blank paper at the edges. */
  --marble: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='600'><filter id='m' filterUnits='userSpaceOnUse' x='-90' y='-90' width='600' height='780'><feTurbulence type='turbulence' baseFrequency='0.006 0.022' numOctaves='4' seed='9' result='n'/><feTurbulence type='fractalNoise' baseFrequency='0.02' numOctaves='2' seed='3' result='w'/><feDisplacementMap in='n' in2='w' scale='90' xChannelSelector='R' yChannelSelector='B'/><feColorMatrix values='2.4 0 0 0 -0.2  2.4 0 0 0 -0.2  2.4 0 0 0 -0.2  0 0 0 0 1'/><feComponentTransfer><feFuncR type='discrete' tableValues='0.11 0.17 0.50 0.72 0.90 0.92'/><feFuncG type='discrete' tableValues='0.15 0.26 0.17 0.56 0.83 0.88'/><feFuncB type='discrete' tableValues='0.30 0.44 0.18 0.29 0.66 0.78'/></feComponentTransfer></filter><rect x='-90' y='-90' width='600' height='780' filter='url(%23m)'/></svg>");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0e0a08;
  color: var(--text);
  font: 14px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
}

body { user-select: none; }
input { user-select: text; }
button { font-family: inherit; }
[hidden] { display: none !important; }

.ico { display: inline-grid; place-items: center; line-height: 0; }
.ico svg { width: 16px; height: 16px; }

/* ================================================================== room */

#app {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  isolation: isolate;
  background:
    radial-gradient(ellipse 70% 55% at 50% -8%, rgba(255, 196, 128, .16), transparent 70%),
    var(--noise),
    linear-gradient(180deg, #2a1f17 0%, #1b140f 45%, #0d0907 100%);
}

#glow {
  position: absolute;
  inset: 0;
  z-index: 19;
  pointer-events: none;
  background:
    radial-gradient(ellipse 42% 60% at 50% -6%, rgba(255, 206, 140, .09), transparent 72%),
    radial-gradient(ellipse 110% 85% at 50% 42%, transparent 56%, rgba(0, 0, 0, .5));
}

#dust {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  pointer-events: none;
}

/* ================================================================== top bar */

#topbar {
  position: relative;
  z-index: 30;
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 10px;
  padding: 13px 22px 12px;
  background:
    linear-gradient(180deg, rgba(52, 35, 23, .97), rgba(32, 22, 15, .97)),
    var(--grain-h);
  border-bottom: 1px solid rgba(214, 170, 92, .34);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .6), 0 10px 26px rgba(0, 0, 0, .45);
}

.brand { display: flex; align-items: center; gap: 11px; margin-right: 8px; }

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #3a270f;
  background: radial-gradient(circle at 30% 25%, var(--brass-hi), var(--brass) 55%, var(--brass-lo));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 2px 6px rgba(0, 0, 0, .5);
}
.brand-mark svg { width: 20px; height: 20px; }

.brand h1 {
  margin: 0;
  font: 600 20px/1.1 var(--serif);
  letter-spacing: .3px;
  color: #f7ebd7;
}

#stats { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; }

.search { position: relative; flex: 1 1 180px; max-width: 330px; min-width: 140px; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--dim); }

#search {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 34px;
  border-radius: 9px;
  border: 1px solid rgba(214, 170, 92, .22);
  background: rgba(10, 7, 5, .55);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .5);
  transition: border-color .15s, box-shadow .15s;
}
#search::placeholder { color: var(--dim); }
#search:focus { border-color: rgba(230, 182, 95, .7); box-shadow: inset 0 2px 5px rgba(0, 0, 0, .5), 0 0 0 3px rgba(230, 182, 95, .14); }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: rgba(10, 7, 5, .5);
  border: 1px solid rgba(214, 170, 92, .18);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5);
}
.seg button {
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); background: rgba(255, 230, 190, .07); }
.seg button.on {
  color: #33230f;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass));
  box-shadow: 0 1px 2px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.seg button:focus-visible, .btn:focus-visible, .plate-btn:focus-visible, .select select:focus-visible {
  outline: 2px solid rgba(246, 222, 160, .8);
  outline-offset: 2px;
}

.spacer { flex: 1 1 0; }

.select { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; }
.select select {
  height: 34px;
  padding: 0 28px 0 11px;
  border-radius: 9px;
  border: 1px solid rgba(214, 170, 92, .22);
  background: rgba(10, 7, 5, .55) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' fill='none' stroke='%23bca991' stroke-width='1.5'/></svg>") no-repeat right 10px center;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  appearance: none;
  outline: none;
  cursor: pointer;
}
.select option { background: #2a1d14; color: var(--text); }

.btn {
  height: 34px;
  padding: 0 13px;
  border-radius: 9px;
  border: 1px solid rgba(214, 170, 92, .28);
  background: linear-gradient(180deg, rgba(76, 52, 34, .92), rgba(52, 34, 22, .92));
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 225, 180, .12), 0 2px 5px rgba(0, 0, 0, .35);
  transition: border-color .15s, filter .15s, transform .1s;
}
.btn:hover { border-color: rgba(230, 182, 95, .6); filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  color: #2d1e0c;
  border-color: rgba(255, 222, 150, .65);
  background: linear-gradient(180deg, #f4d996, #d4a851 55%, #b78c3b);
  font-weight: 600;
  text-shadow: 0 1px 0 rgba(255, 240, 200, .5);
}

/* ================================================================== bookcase */

#scroller {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
}

#case {
  position: relative;
  width: min(1640px, calc(100% - 52px));
  margin: 30px auto 70px;
  padding: 0 var(--side-w);
}

/* The two side panels sit above the shelves and cast a shadow inwards. */
#case::before,
#case::after {
  content: '';
  position: absolute;
  top: 12px;
  bottom: 20px;
  width: var(--side-w);
  z-index: 6;
  pointer-events: none;
  background:
    var(--grain-v),
    linear-gradient(90deg, #352013, #6c4527 26%, #7e5231 54%, #5b381f 82%, #2a190d);
}
#case::before { left: 0; border-radius: 3px 0 0 3px; box-shadow: 12px 0 18px -8px rgba(0, 0, 0, .75); }
#case::after { right: 0; border-radius: 0 3px 3px 0; box-shadow: -12px 0 18px -8px rgba(0, 0, 0, .75); }

.crown {
  position: relative;
  z-index: 7;
  height: 46px;
  margin: 0 calc(-1 * var(--side-w) - 14px);
  border-radius: 5px 5px 2px 2px;
  background:
    linear-gradient(180deg,
      rgba(255, 222, 172, .32) 0 1px, transparent 1px 7px,
      rgba(0, 0, 0, .38) 7px 9px, rgba(255, 210, 160, .2) 9px 10px, transparent 10px 25px,
      rgba(0, 0, 0, .42) 25px 27px, rgba(255, 210, 160, .14) 27px 28px, transparent 28px 100%),
    var(--grain-h),
    linear-gradient(180deg, #8c5c35, #6c4427 40%, #4c2f1a);
  box-shadow: 0 14px 22px -8px rgba(0, 0, 0, .8), inset 0 -2px 0 rgba(0, 0, 0, .35);
}

.plinth {
  position: relative;
  z-index: 7;
  height: 52px;
  margin: 0 calc(-1 * var(--side-w) - 8px);
  border-radius: 2px 2px 4px 4px;
  background:
    linear-gradient(180deg,
      rgba(255, 220, 170, .26) 0 1px, transparent 1px 12px,
      rgba(0, 0, 0, .38) 12px 14px, rgba(255, 210, 160, .14) 14px 15px, transparent 15px 100%),
    var(--grain-h),
    linear-gradient(180deg, #6e4628, #4a2d18 70%, #36210f);
  box-shadow: 0 26px 40px rgba(0, 0, 0, .6), inset 0 -3px 0 rgba(0, 0, 0, .4);
}

#shelves { position: relative; }

.shelf { position: relative; }

/* The front edge of a thick shelf, carrying the brass label holder. */
.board {
  position: relative;
  z-index: 3;
  height: var(--board-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 22px;
  background:
    linear-gradient(180deg, rgba(255, 226, 182, .3) 0 1px, rgba(255, 215, 160, .07) 1px 3px,
      transparent 3px calc(100% - 4px), rgba(0, 0, 0, .45) calc(100% - 4px)),
    var(--grain-h),
    linear-gradient(180deg, #7e5231, #654025 50%, #50321c);
  box-shadow: 0 9px 14px -4px rgba(0, 0, 0, .72);
}

.plate {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 13px;
  border: 0;
  border-radius: 4px;
  background: linear-gradient(180deg, #f6dd9e, #cba04c 46%, #a77d34 54%, #dab366);
  box-shadow: inset 0 1px 0 rgba(255, 242, 205, .5), inset 0 -1px 0 rgba(0, 0, 0, .35), 0 2px 4px rgba(0, 0, 0, .6);
  transition: box-shadow .2s, transform .2s;
}
/* screw heads */
.plate::before,
.plate::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 5px;
  height: 5px;
  margin-top: -2.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff4cc, #8a6a2b 72%);
  box-shadow: 0 0 0 .5px rgba(0, 0, 0, .45);
}
.plate::before { left: 4px; }
.plate::after { right: 4px; }

.plate-card {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 10px;
  border-radius: 2px;
  background: linear-gradient(180deg, #f7eed8, #e7d9b9);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .35);
}

.plate-name {
  font: 700 11.5px/1 var(--serif);
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: #3b2a18;
  white-space: nowrap;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}

.plate-input {
  width: 15em;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: 700 11.5px/1 var(--serif);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #3b2a18;
}

.plate-count {
  min-width: 14px;
  font: 700 11px/1 var(--sans);
  color: #4c3612;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 240, 200, .6);
}

.plate-tools { display: flex; gap: 5px; opacity: 0; transition: opacity .18s; }
.board:hover .plate-tools,
.board:focus-within .plate-tools,
.shelf.menu-open .plate-tools { opacity: 1; }

.plate-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 7px;
  border: 1px solid rgba(255, 220, 160, .2);
  background: rgba(20, 12, 7, .45);
  color: #ead4ab;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.plate-btn:hover { background: rgba(20, 12, 7, .78); border-color: rgba(230, 182, 95, .6); color: #fff2d8; }
.plate-btn .ico svg { width: 15px; height: 15px; }

.shelf.drop-target .plate {
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255, 242, 205, .5), 0 0 0 2px rgba(255, 216, 140, .75), 0 0 24px rgba(255, 200, 110, .55);
}

/* ---- a row: back wall, then a 3D stage with floor, books and front edge */

.row {
  position: relative;
  height: var(--row-h);
  perspective: var(--cam);
  perspective-origin: 50% var(--cam-y);
  overflow-x: clip;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .64), rgba(0, 0, 0, .22) 40px, transparent 86px),
    linear-gradient(90deg, rgba(0, 0, 0, .5), transparent 76px, transparent calc(100% - 76px), rgba(0, 0, 0, .5)),
    radial-gradient(ellipse 70% 100% at 50% 0%, rgba(255, 190, 120, .07), transparent 76%),
    var(--grain-v),
    linear-gradient(180deg, #3b2517, #21140b);
}
.row.short { height: 132px; }
.row.lifted { z-index: 5; }

.shelf.drop-target .row::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 60% 80% at 50% 70%, rgba(255, 205, 130, .13), transparent 72%);
}

.stage {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

/* The plank the books stand on, hinged at the top of the front edge and
   lying flat, reaching back into the case. */
.floor {
  position: absolute;
  left: -90px;
  right: -90px;
  bottom: var(--edge-h);
  height: var(--floor-d);
  transform-origin: 50% 100%;
  transform: rotateX(90deg);
  background:
    linear-gradient(0deg, rgba(255, 222, 176, .14), transparent 22%, rgba(0, 0, 0, .62)),
    var(--grain-h),
    linear-gradient(0deg, #7b4e2d, #4a2d19);
}

.edge {
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: 0;
  height: var(--edge-h);
  background:
    linear-gradient(180deg, rgba(255, 230, 188, .46) 0 1px, rgba(255, 215, 160, .12) 1px 3px,
      transparent 3px calc(100% - 3px), rgba(0, 0, 0, .5) calc(100% - 3px)),
    var(--grain-h),
    linear-gradient(180deg, #86562f, #67401f 60%, #573619);
}

.books {
  position: absolute;
  top: 0;
  left: var(--row-pad);
  right: var(--row-pad);
  bottom: var(--edge-h);
  display: flex;
  align-items: flex-end;
  transform-style: preserve-3d;
}

/* ================================================================== books */

.slot {
  position: relative;
  flex: none;
  height: var(--h);
  transform-style: preserve-3d;
  transform-origin: 50% 100%;
  cursor: pointer;
  outline: none;
}

/* contact shadow on the plank */
.slot::before {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  bottom: 0;
  height: calc(var(--w) + 30px);
  transform-origin: 50% 100%;
  transform: translateY(-.6px) rotateX(90deg);
  background: linear-gradient(0deg, rgba(0, 0, 0, .18), rgba(0, 0, 0, .58) 10%, rgba(0, 0, 0, .45) 75%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 7px, #000 calc(100% - 7px), transparent);
  pointer-events: none;
  transition: opacity .3s;
}

.box3d {
  position: absolute;
  transform-style: preserve-3d;
}
.box3d > .face {
  position: absolute;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.box3d > .front,
.box3d > .back,
.box3d > .page { left: 0; top: 0; width: 100%; height: 100%; }
.box3d > .front { transform: translateZ(calc(var(--t) / 2)); }
.box3d > .back { transform: rotateY(180deg) translateZ(calc(var(--t) / 2)); }
.box3d > .page { transform: translateZ(calc(var(--t) / 2 - 1px)); }
.box3d > .spine,
.box3d > .fore { top: 0; height: 100%; width: var(--t); left: calc(50% - var(--t) / 2); }
.box3d > .spine { transform: rotateY(-90deg) translateZ(calc(var(--w) / 2)); }
.box3d > .fore { transform: rotateY(90deg) translateZ(calc(var(--w) / 2)); }
.box3d > .top,
.box3d > .bottom { left: 0; width: 100%; height: var(--t); top: calc(50% - var(--t) / 2); }
.box3d > .top { transform: rotateX(90deg) translateZ(calc(var(--h) / 2)); }
.box3d > .bottom { transform: rotateX(-90deg) translateZ(calc(var(--h) / 2)); }

.slot > .book {
  left: 50%;
  bottom: 0;
  width: var(--w);
  height: var(--h);
  margin-left: calc(var(--w) / -2);
  transform-origin: 50% 100%;
  pointer-events: none;
  transition: transform 560ms var(--spring);
}

/* Shelved poses. Spines: turned a quarter so the spine faces out, set back a
   little from the plank edge. Covers: face out, angled to show the spine. */
.shelf.v-spines .slot > .book { transform: translateZ(calc(var(--w) / -2 - 10px)) rotateY(90deg); }
.shelf.v-covers .slot > .book { transform: translateZ(calc(var(--t) * -.5 - var(--w) * .2 - 12px)) rotateY(24deg); }

/* Pulled out: tipped forward by a finger on the headcap and slid towards you. */
body:not(.is-dragging) .shelf.v-spines .slot:hover > .book,
.shelf.v-spines .slot.pulled > .book,
.shelf.v-spines .slot:focus-visible > .book {
  transform: translate3d(0, -12px, calc(var(--w) / -2 + 18px)) rotateX(-6deg) rotateY(90deg);
  transition-duration: 380ms;
}
body:not(.is-dragging) .shelf.v-covers .slot:hover > .book,
.shelf.v-covers .slot.pulled > .book,
.shelf.v-covers .slot:focus-visible > .book {
  transform: translate3d(0, -12px, calc(var(--t) * -.5 + 16px)) rotateX(-3deg) rotateY(7deg);
  transition-duration: 380ms;
}

/* ---- spine */

.book > .spine {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  background-color: var(--c);
  color: var(--ink);
}

/* rounded-spine light and shade, plus cloth tooth */
.book > .spine::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .5) 0%, rgba(0, 0, 0, .08) 14%, rgba(255, 255, 255, .17) 33%,
      rgba(255, 255, 255, .04) 52%, rgba(0, 0, 0, .1) 74%, rgba(0, 0, 0, .55) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, .1), transparent 5%, transparent 93%, rgba(0, 0, 0, .4)),
    var(--noise);
}

.sp-cap { position: relative; flex: none; width: 100%; height: calc(11px * var(--k)); }

.sp-mid {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(4px * var(--k)) 0;
}

.sp-title {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sp-text {
  writing-mode: vertical-rl;
  max-height: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs);
  line-height: 1.05;
  letter-spacing: .02em;
}
/* Long titles on thick spines set in two lines, side by side. */
.sp-title.two .sp-text {
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: anywhere;
  max-width: calc(var(--fs) * 2.3);
  line-height: 1.1;
  text-align: center;
}

.sp-author {
  position: relative;
  flex: none;
  max-height: 34%;
  margin-bottom: calc(7px * var(--k));
  writing-mode: vertical-rl;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font: 600 calc(var(--fs) * .62)/1 var(--narrow);
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .88;
}

/* Lettering: blocked foil on dark cloth, ink on light cloth. */
.is-dark .sp-text,
.is-dark .sp-author {
  color: var(--foil);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .55), 0 1px 0 rgba(255, 236, 190, .16);
}
.is-light .sp-text,
.is-light .sp-author { color: #2b2017; text-shadow: 0 1px 0 rgba(255, 255, 255, .22); }

.sf-serif .sp-text { font-family: var(--serif); font-weight: 700; }
.sf-display .sp-text { font-family: var(--display); font-weight: 700; letter-spacing: .04em; }
.sf-sans .sp-text {
  font-family: var(--narrow);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.is-upper .sp-text { text-transform: uppercase; letter-spacing: .06em; }

.sp-mark {
  position: relative;
  flex: none;
  width: min(calc(var(--t) * .4), calc(11px * var(--k)));
  height: min(calc(var(--t) * .4), calc(11px * var(--k)));
  margin-bottom: calc(7px * var(--k));
  border-radius: 50%;
  border: calc(1px * var(--k)) solid currentColor;
  color: var(--ink);
  opacity: .72;
}
.sp-mark.m1 { border-radius: 1px; transform: rotate(45deg) scale(.78); }
.sp-mark.m2 { border: 0; background: radial-gradient(circle, currentColor 32%, transparent 36%); }
.sp-mark.m3 { border-width: calc(2px * var(--k)); transform: scale(.85); }
.sp-mark.is-star {
  border: 0;
  opacity: 1;
  width: auto;
  height: auto;
  font-size: max(calc(var(--fs) * .95), calc(9px * var(--k)));
  line-height: 1;
}
.sp-mark.is-star::before {
  content: '\2605';
  color: #f7d97f;
  text-shadow: 0 0 calc(6px * var(--k)) rgba(255, 210, 110, .7), 0 1px 0 rgba(0, 0, 0, .5);
}

/* Variant: gilt bands at head and tail. */
.sv-bands .sp-cap::before,
.sv-bands .sp-cap::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: calc(1.5px * var(--k));
  background: linear-gradient(90deg, #7f6024, #f4da92 50%, #7f6024);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}
.sv-bands .sp-head::before { top: calc(4px * var(--k)); }
.sv-bands .sp-head::after { top: calc(7.5px * var(--k)); }
.sv-bands .sp-tail::before { bottom: calc(4px * var(--k)); }
.sv-bands .sp-tail::after { bottom: calc(7.5px * var(--k)); }
.is-light.sv-bands .sp-cap::before,
.is-light.sv-bands .sp-cap::after { background: rgba(43, 32, 23, .78); box-shadow: none; }

/* Variant: a leather title label with a gilt rule. */
.sv-label .sp-mid { padding-left: calc(3px * var(--k)); padding-right: calc(3px * var(--k)); }
.sv-label .sp-title {
  padding: calc(9px * var(--k)) 0;
  border-radius: calc(1.5px * var(--k));
  background: var(--lab);
  box-shadow: inset 0 0 0 calc(1px * var(--k)) rgba(235, 207, 136, .7), 0 1px 2px rgba(0, 0, 0, .45);
}
.sv-label .sp-text { color: var(--lab-ink); }

/* Variant: raised bands across an old leather spine. */
.sv-raised.book > .spine {
  background-image:
    linear-gradient(180deg,
      transparent 12%, rgba(0, 0, 0, .42) 12%, rgba(255, 255, 255, .22) 13.2%, rgba(0, 0, 0, .3) 14.6%, transparent 14.6%,
      transparent 19%, rgba(0, 0, 0, .42) 19%, rgba(255, 255, 255, .22) 20.2%, rgba(0, 0, 0, .3) 21.6%, transparent 21.6%,
      transparent 79%, rgba(0, 0, 0, .42) 79%, rgba(255, 255, 255, .22) 80.2%, rgba(0, 0, 0, .3) 81.6%, transparent 81.6%,
      transparent 86%, rgba(0, 0, 0, .42) 86%, rgba(255, 255, 255, .22) 87.2%, rgba(0, 0, 0, .3) 88.6%, transparent 88.6%);
}
.sv-raised .sp-mid { padding-top: calc(var(--h) * .1); padding-bottom: calc(var(--h) * .06); }

/* Variant: modern two-tone binding. */
.sv-block .sp-head { height: calc(var(--h) * .11); background: var(--c-deep); }
.sv-block .sp-tail { height: calc(var(--h) * .16); background: var(--c-lite); box-shadow: inset 0 1px 0 rgba(0, 0, 0, .3); }

/* Variant: book cloth with a visible weave. */
.sv-cloth.book > .spine {
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .06) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .09) 0 1px, transparent 1px 3px);
}

/* ---- page block and boards */

.book > .top,
.book > .bottom {
  background:
    linear-gradient(90deg, var(--c-dark) 0 calc(2.5px * var(--k)), transparent 0),
    linear-gradient(180deg, var(--c-dark) 0 calc(1.5px * var(--k)), transparent 0 calc(100% - 1.5px * var(--k)), var(--c-dark) 0),
    repeating-linear-gradient(180deg, #f0e6cf 0 1px, #d5c5a4 1px 2px);
}
.book > .fore {
  background:
    linear-gradient(90deg, var(--c-dark) 0 calc(1.5px * var(--k)), transparent 0 calc(100% - 1.5px * var(--k)), var(--c-dark) 0),
    linear-gradient(180deg, var(--c-dark) 0 calc(1px * var(--k)), transparent 0 calc(100% - 1px * var(--k)), var(--c-dark) 0),
    repeating-linear-gradient(90deg, #f0e6cf 0 1px, #d5c5a4 1px 2px);
}

/* Favourites get gilt edges, like a special edition. */
.is-fav > .top,
.is-fav > .bottom {
  background:
    linear-gradient(90deg, var(--c-dark) 0 calc(2.5px * var(--k)), transparent 0),
    linear-gradient(180deg, var(--c-dark) 0 calc(1.5px * var(--k)), transparent 0 calc(100% - 1.5px * var(--k)), var(--c-dark) 0),
    repeating-linear-gradient(180deg, #f7d985 0 1px, #c39338 1px 2px);
}
.is-fav > .fore {
  background:
    linear-gradient(90deg, var(--c-dark) 0 calc(1.5px * var(--k)), transparent 0 calc(100% - 1.5px * var(--k)), var(--c-dark) 0),
    repeating-linear-gradient(90deg, #f7d985 0 1px, #c39338 1px 2px);
}

/* Books nobody opened for months gather a little dust on top. */
.is-dusty > .top::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 40% 50%, rgba(205, 196, 178, .42), rgba(205, 196, 178, .2) 70%),
    var(--noise);
}

.book > .back { background: linear-gradient(90deg, rgba(0, 0, 0, .22), transparent 30%, rgba(0, 0, 0, .12)), var(--c); }

/* ---- front cover */

.cover {
  overflow: hidden;
  background-color: var(--c);
  border-radius: 0 calc(2px * var(--k)) calc(2px * var(--k)) 0;
}
.cover::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .38) 0, rgba(255, 255, 255, .2) calc(3px * var(--k)),
      rgba(0, 0, 0, .14) calc(7px * var(--k)), transparent calc(13px * var(--k))),
    linear-gradient(118deg, rgba(255, 255, 255, .16), transparent 42%, transparent 70%, rgba(0, 0, 0, .14));
}

.gen-cover {
  position: absolute;
  inset: 0;
  display: flex;
  padding: calc(9px * var(--k)) calc(9px * var(--k)) calc(9px * var(--k)) calc(13px * var(--k));
  background: var(--noise), var(--c);
}
.gc-frame {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(6px * var(--k));
  padding: calc(8px * var(--k));
  text-align: center;
  border: calc(1.5px * var(--k)) solid color-mix(in srgb, var(--foil) 70%, transparent);
  box-shadow: inset 0 0 0 calc(3px * var(--k)) var(--c), inset 0 0 0 calc(4px * var(--k)) color-mix(in srgb, var(--foil) 40%, transparent);
  color: var(--ink);
}
.is-dark .gc-frame { color: var(--foil); }
.gc-orn { font-size: calc(13px * var(--k)); opacity: .75; }
.gc-title {
  max-width: 100%;
  font: 700 calc(12.5px * var(--k))/1.18 var(--serif);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.gc-author { max-width: 100%; font: italic calc(9px * var(--k))/1.2 var(--serif); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .45s ease;
}
.cover-img.ready { opacity: 1; }

/* ---- ribbon, tags, bookend */

/* A silk bookmark hanging over the plank edge: this one is being read. */
.ribbon {
  position: absolute;
  top: 100%;
  left: calc(50% - 3px);
  width: 6px;
  height: 21px;
  transform: translateZ(2px);
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .32), rgba(255, 255, 255, .26) 42%, rgba(0, 0, 0, .2)),
    var(--rc, #a3162b);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  transition: transform 560ms var(--spring);
}
body:not(.is-dragging) #case .slot:hover > .ribbon,
#case .slot.pulled > .ribbon,
#case .slot:focus-visible > .ribbon { transform: translate3d(0, -10px, 20px); transition-duration: 380ms; }

.tag {
  position: absolute;
  left: 50%;
  bottom: calc(var(--h) - 8px);
  width: 40px;
  height: 15px;
  margin-left: -20px;
  transform: translateZ(6px) rotate(-9deg);
  pointer-events: none;
  border-radius: 2px;
  background: #efe3c6;
  color: #8f2c1e;
  font: 700 8px/15px var(--sans);
  letter-spacing: .08em;
  text-align: center;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .55);
}
.slot.is-missing > .book > .face { filter: grayscale(.85) brightness(.55); }

.bookend {
  position: relative;
  flex: none;
  width: 30px;
  height: 104px;
  margin-left: 6px;
  transform-style: preserve-3d;
  pointer-events: none;
}
.be-box {
  --w: 78px;
  --h: 104px;
  --t: 30px;
  --k: 1;
  left: 50%;
  bottom: 0;
  width: var(--w);
  height: var(--h);
  margin-left: calc(var(--w) / -2);
  transform: translateZ(calc(var(--w) / -2 - 6px)) rotateY(90deg);
}
.be-box > .spine {
  border-radius: 15px 15px 2px 2px;
  background:
    radial-gradient(ellipse 80% 50% at 40% 22%, rgba(255, 246, 214, .75), transparent 60%),
    linear-gradient(90deg, #6d5120, #d8b464 40%, #f1d88f 55%, #a67f31 80%, #5c4318);
  box-shadow: inset 0 0 0 1px rgba(255, 240, 200, .25), inset 0 -12px 16px rgba(0, 0, 0, .35);
}
.be-box > .front,
.be-box > .back { background: linear-gradient(180deg, #b38b3d, #6f5221); }
.be-box > .top { background: linear-gradient(90deg, #f6dd9a, #9c7630); }

/* ---- empty shelves and the "new shelf" compartment */

.shelf-hint {
  position: absolute;
  z-index: 2;
  left: 70px;
  right: 70px;
  top: calc(var(--board-h) + 76px);
  display: none;
  text-align: center;
  pointer-events: none;
}
.shelf.is-empty .shelf-hint { display: block; }
.shelf-hint .hint-text { color: rgba(255, 226, 186, .34); font: italic 15px/1.5 var(--serif); }
.shelf-hint.welcome { top: calc(var(--board-h) + 30px); pointer-events: auto; }
.shelf-hint.welcome .hint-title { color: #f2e4cb; font: 600 22px/1.3 var(--serif); margin-bottom: 6px; }
.shelf-hint.welcome .hint-text { color: rgba(255, 230, 196, .6); font-size: 14px; font-style: normal; max-width: 470px; margin: 0 auto 16px; }

.add-shelf .plate { cursor: pointer; background: transparent; box-shadow: none; padding: 0; }
.add-shelf .plate::before,
.add-shelf .plate::after { display: none; }
.add-shelf .plate-card {
  background: rgba(20, 12, 7, .35);
  box-shadow: none;
  border: 1px dashed rgba(246, 222, 160, .45);
  height: 26px;
  padding: 0 14px;
  transition: background .15s, border-color .15s;
}
.add-shelf .plate-name { color: rgba(246, 222, 160, .85); cursor: pointer; letter-spacing: 1.4px; }
.add-shelf .plate:hover .plate-card { background: rgba(20, 12, 7, .6); border-color: rgba(246, 222, 160, .85); }
.add-shelf.drop-target .plate-card { border-style: solid; border-color: #f6de9f; background: rgba(246, 222, 160, .16); }
.add-hint {
  position: absolute;
  inset: 0 0 var(--edge-h);
  display: grid;
  place-items: center;
  color: rgba(255, 226, 186, .26);
  font: italic 14px var(--serif);
  pointer-events: none;
  transition: color .2s;
}
body.is-dragging .add-shelf .add-hint { color: rgba(255, 226, 186, .6); }

.no-matches { position: relative; }
.nm-card {
  position: absolute;
  inset: 0 0 var(--edge-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: rgba(255, 230, 196, .7);
  font: italic 16px var(--serif);
}

/* ================================================================== drag & drop */

body.is-dragging,
body.is-dragging * { cursor: grabbing !important; }
body.is-dragging .slot { transition: width 240ms var(--ease-out), margin 240ms var(--ease-out); }

.slot.drag-origin { width: 0 !important; margin-right: 0 !important; }
.slot.drag-origin > *,
.slot.drag-origin::before { visibility: hidden; }

.slot.ph {
  width: 0;
  margin: 0;
  cursor: default;
  transition: width 240ms var(--ease-out);
}
.slot.ph.open { width: var(--sw); }
.slot.ph::before { display: none; }
.slot.ph::after {
  content: '';
  position: absolute;
  left: 3px;
  right: 5px;
  bottom: 0;
  height: 100%;
  border: 1.5px dashed rgba(255, 214, 150, .42);
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  background: rgba(255, 214, 150, .05);
  opacity: 0;
  transition: opacity .18s;
}
.slot.ph.open::after { opacity: 1; }

#dragLayer {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
  perspective: 1400px;
}
.ghost { position: absolute; left: 0; top: 0; transform-style: preserve-3d; }
.ghost > .book {
  left: calc(var(--w) / -2);
  bottom: 0;
  width: var(--w);
  height: var(--h);
  transform-origin: 50% 100%;
}
.ghost-shadow {
  position: absolute;
  left: -60px;
  top: -14px;
  width: 120px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .55), transparent);
  filter: blur(4px);
}

/* ================================================================== theater */

#theater {
  position: fixed;
  inset: 0;
  z-index: 80;
  visibility: hidden;
  pointer-events: none;
  perspective: 1700px;
  perspective-origin: 50% 45%;
}
#theater.active { visibility: visible; pointer-events: auto; cursor: pointer; }
#theater.passive { pointer-events: none; }
html.returning #theater { visibility: visible; }

#theater .veil {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(10, 6, 3, .5), rgba(5, 3, 2, .9));
}
#theater .fade {
  position: absolute;
  inset: 0;
  z-index: 2;
  opacity: 0;
  background: var(--reader-desk, #2e2924);
}
html.returning #theater .veil,
html.returning #theater .fade { opacity: 1; }

.flyer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}
.flyer > .book {
  left: calc(var(--w) / -2);
  top: calc(var(--h) / -2);
  width: var(--w);
  height: var(--h);
}

.hinge {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  transform: translateZ(calc(var(--t) / 2));
}
.hinge > .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.hinge > .cover-in {
  transform: rotateY(180deg);
  border-radius: calc(2px * var(--k)) 0 0 calc(2px * var(--k));
  background: var(--marble);
  background-size: cover;
  box-shadow: inset 0 0 0 calc(7px * var(--k)) var(--c), inset calc(-14px * var(--k)) 0 calc(18px * var(--k)) rgba(0, 0, 0, .35);
}

.book > .page {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .18), transparent calc(16px * var(--k))),
    var(--noise),
    #f4ecda;
}
.half-title { padding: 0 12%; text-align: center; color: #3b2d1f; }
.ht-title { font: 600 var(--ht, calc(15px * var(--k)))/1.25 var(--serif); overflow-wrap: break-word; text-wrap: balance; }
.is-theater .cover-img { transition: none; }
.ht-author { margin-top: calc(10px * var(--k)); font: italic calc(11px * var(--k))/1.3 var(--serif); color: #6b5640; }
.ht-orn { margin-top: calc(16px * var(--k)); font-size: calc(15px * var(--k)); color: #8c6f45; }

.slot.away > .book,
.slot.away > .ribbon,
.slot.away > .tag { visibility: hidden; }
.slot.away::before { opacity: .3; }

/* A quick gilt shimmer when a book becomes a favourite. */
.slot.gild > .book > .spine::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  background: linear-gradient(180deg, transparent 35%, rgba(255, 238, 176, .8) 50%, transparent 65%);
  background-size: 100% 300%;
  animation: gild 1s ease-out both;
}
@keyframes gild { from { background-position: 0 100%; } to { background-position: 0 0; } }

/* ================================================================== popovers */

#card {
  position: fixed;
  z-index: 45;
  left: 0;
  top: 0;
  width: 336px;
  display: flex;
  gap: 14px;
  padding: 18px 16px 24px;
  border-radius: 3px;
  color: #2c2117;
  background:
    linear-gradient(180deg, transparent 0 46px, rgba(160, 30, 40, .55) 46px 47px, transparent 47px),
    repeating-linear-gradient(180deg, transparent 0 20px, rgba(70, 110, 160, .13) 20px 21px),
    var(--noise),
    #f5ecd6;
  background-position: 0 0, 0 47px, 0 0, 0 0;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) rotate(-.5deg);
  transition: opacity .16s ease, transform .22s var(--ease-out);
}
#card.show { opacity: 1; transform: rotate(-.5deg); }
#card.measuring { transition: none; }
/* the rod hole every catalogue card has */
#card::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 12px;
  height: 7px;
  margin-left: -6px;
  border-radius: 50%;
  background: #1b130d;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .8);
  opacity: .8;
}
#card.fav::before {
  content: '\2605';
  position: absolute;
  right: 12px;
  top: 10px;
  color: #c99a33;
  font-size: 15px;
}
.cc-cover {
  position: relative;
  flex: none;
  width: 76px;
  height: 108px;
  overflow: hidden;
  border-radius: 1px 3px 3px 1px;
  background: var(--c);
  box-shadow: 0 3px 8px rgba(0, 0, 0, .35), inset 3px 0 4px rgba(0, 0, 0, .3);
}
.cc-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cc-initial {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 240, 210, .85);
  font: 700 34px var(--serif);
}
.cc-body { flex: 1; min-width: 0; }
.cc-title {
  font: 700 15px/1.25 var(--serif);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.cc-author { margin-top: 2px; font: italic 12.5px var(--serif); color: #6d5843; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  margin: 10px 0 0;
  font: 12px/1.45 var(--mono);
}
.cc-fields dt { color: #8a7358; font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; line-height: 1.9; }
.cc-fields dd { margin: 0; min-width: 0; color: #2c2117; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-fields dd.warn { color: #a3312a; font-weight: 700; }
.cc-bar { height: 4px; margin-top: 8px; border-radius: 2px; background: rgba(60, 40, 20, .15); overflow: hidden; }
.cc-bar i { display: block; height: 100%; background: linear-gradient(90deg, #8f1426, #cf4a3a); }
.cc-hint { margin-top: 9px; font: 10.5px/1.3 var(--sans); color: #8a7358; }

.menu {
  position: fixed;
  z-index: 90;
  min-width: 214px;
  max-width: 320px;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid rgba(214, 170, 92, .34);
  background: linear-gradient(180deg, #30231a, #241a12);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .62), inset 0 1px 0 rgba(255, 225, 180, .08);
  color: var(--text);
  font-size: 13px;
  animation: menu-in .14s var(--ease-out);
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover,
.menu-item:focus,
.menu-item.open { background: rgba(230, 182, 95, .17); outline: none; }
.menu-item:disabled { opacity: .42; cursor: default; background: transparent; }
.menu-item.danger { color: #f3a593; }
.menu-item.danger:hover:not(:disabled),
.menu-item.danger:focus:not(:disabled) { background: rgba(224, 122, 100, .2); }
.mi-icon { width: 16px; color: var(--brass); flex: none; }
.menu-item.danger .mi-icon { color: inherit; }
.mi-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mi-hint { color: var(--dim); font-size: 11.5px; }
.mi-arrow { color: var(--muted); font-size: 16px; line-height: 1; }
.menu-sep { height: 1px; margin: 5px 6px; background: rgba(214, 170, 92, .18); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 5, 3, .56);
  animation: fade-in .15s ease;
}
.modal.closing { animation: fade-out .14s ease forwards; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
.dialog {
  width: min(420px, 100%);
  padding: 22px 22px 18px;
  border-radius: 8px;
  color: #2c2117;
  background: var(--noise), #f5ecd6;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6), inset 0 0 0 1px rgba(255, 255, 255, .5);
  animation: dialog-in .22s var(--ease-out);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.dialog h2 { margin: 0 0 6px; font: 700 18px/1.3 var(--serif); }
.dialog p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.5; color: #5a4633; }
.dialog input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 7px;
  border: 1px solid #c9b38c;
  background: #fffaf0;
  color: #2c2117;
  font: 15px var(--serif);
  outline: none;
}
.dialog input:focus { border-color: #b0802f; box-shadow: 0 0 0 3px rgba(176, 128, 47, .2); }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog .btn {
  color: #3b2a18;
  border-color: #cdb78f;
  background: linear-gradient(180deg, #fbf4e3, #eadcbc);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.dialog .btn.primary { color: #2d1e0c; border-color: #b8893a; background: linear-gradient(180deg, #f4d996, #d4a851); }
.dialog .btn.danger { color: #fff; border-color: #8f2c1e; background: linear-gradient(180deg, #c75441, #9c3322); text-shadow: 0 1px 0 rgba(0, 0, 0, .3); }

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 92;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 10px 10px 18px;
  border-radius: 10px;
  border: 1px solid rgba(214, 170, 92, .36);
  background: rgba(38, 27, 18, .97);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity .2s ease, transform .26s var(--ease-out);
}
#toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast-msg { padding: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-btn {
  flex: none;
  height: 28px;
  padding: 0 12px;
  border-radius: 7px;
  border: 1px solid rgba(246, 222, 160, .45);
  background: transparent;
  color: var(--brass-hi);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.toast-btn:hover { background: rgba(246, 222, 160, .12); }

#fileHint {
  position: fixed;
  left: 50%;
  top: 84px;
  z-index: 50;
  padding: 9px 18px;
  border-radius: 999px;
  color: #2d1e0c;
  background: linear-gradient(180deg, #f4d996, #d4a851);
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .18s, transform .22s var(--ease-out);
  pointer-events: none;
}
body.file-over #fileHint { opacity: 1; transform: translate(-50%, 0); }

/* ================================================================== misc */

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 7px;
  background-clip: padding-box;
  background-color: rgba(230, 190, 130, .22);
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(230, 190, 130, .38); }

/* The top bar sheds words before it ever wraps: labels go first, icons stay
   (each button keeps its tooltip). */
@media (max-width: 1680px) {
  .select > span { display: none; }
  #nav .label { display: none; }
  #nav button { padding: 0 9px; }
}
/* Home has no bookcase to filter or arrange. */
html.route-home :is(#filters, #views, .select:has(#sort)) { display: none; }
@media (max-width: 1520px) {
  #newShelfBtn .label, #addBtn .label { display: none; }
  #newShelfBtn, #addBtn { padding: 0 10px; }
}
@media (max-width: 1200px) {
  #views .label, #nav .label { display: none; }
}

@media (max-width: 760px) {
  :root { --side-w: 16px; --row-pad: 10px; }
  #topbar { padding: 10px 12px; }
  #case { width: calc(100% - 44px); margin-top: 18px; }
  .btn .label, .seg .label { display: none; }
  .select > span { display: none; }
  .shelf-hint { left: 24px; right: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .slot > .book,
  .ribbon,
  .cover-img { transition: none !important; }
  #dust { display: none; }
}

.btn.icon-btn { padding: 0 9px; }
.btn.icon-btn .ico svg { width: 17px; height: 17px; }

/* ================================================================== continue reading */

#hero {
  --hero-bg:
    radial-gradient(ellipse 45% 90% at 16% 0%, rgba(255, 200, 130, .2), transparent 70%),
    linear-gradient(180deg, rgba(58, 38, 25, .92), rgba(30, 20, 13, .92));
  --hero-line: rgba(214, 170, 92, .26);
  --hero-desk: linear-gradient(180deg, #8a5a34, #5c3a21 45%, #3f2715);
  --hero-accent: var(--brass-hi);
  position: relative;
  width: min(1640px, calc(100% - 52px));
  margin: 26px auto 0;
}
#hero[hidden] { display: none; }

.hero-inner {
  position: relative;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) minmax(0, 330px);
  align-items: center;
  gap: 34px;
  min-height: 300px;
  padding: 0 40px 0 24px;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--hero-line);
  background: var(--hero-bg);
  perspective: 1300px;
  perspective-origin: 174px 10%;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 230, 190, .08);
}

/* the desk, the lamp and the book standing on it */
.hero-stage { position: static; align-self: stretch; min-height: 300px; }
.hero-lamp {
  position: absolute;
  left: 0;
  top: -40px;
  width: 360px;
  bottom: 0;
  background: radial-gradient(ellipse 55% 60% at 50% 30%, rgba(255, 214, 150, .28), transparent 70%);
  pointer-events: none;
}
/* The desk runs the width of the nook; everything rests on it. */
.hero-desk {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40px;
  background:
    linear-gradient(180deg, rgba(255, 228, 185, .35) 0 1px, transparent 1px 12px, rgba(0, 0, 0, .3) 12px 13px, transparent 13px),
    var(--grain-h),
    var(--hero-desk);
  box-shadow: 0 -8px 20px rgba(0, 0, 0, .25);
}
.hero-book {
  position: absolute;
  left: 174px;
  bottom: 30px;
  padding: 0;
  border: 0;
  background: none;
  transform: translateX(-50%);
  transform-style: preserve-3d;
  cursor: pointer;
  outline: none;
}
.hero-book::before {
  content: '';
  position: absolute;
  left: -14%;
  right: -22%;
  bottom: -14px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .55), transparent);
  filter: blur(3px);
}
.hero-book > .book {
  left: 50%;
  bottom: 0;
  width: var(--w);
  height: var(--h);
  margin-left: calc(var(--w) / -2);
  transform-origin: 50% 100%;
  transform: translateZ(calc(var(--t) * -.5)) rotateY(24deg);
  transition: transform .5s var(--spring);
}
.hero-book:hover > .book,
.hero-book:focus-visible > .book { transform: translate3d(0, -10px, 20px) rotateY(10deg) rotateX(-2deg); }
.hero-book.away > .book,
.hero-book.away::before { visibility: hidden; }

.hero-text { position: relative; min-width: 0; padding: 26px 0 58px; }
.hero-greet { color: var(--muted); font: italic 15px/1.4 var(--serif); }
.hero-eyebrow {
  margin-top: 14px;
  color: var(--hero-accent);
  font: 700 11px/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
}
.hero-title {
  margin: 8px 0 0;
  color: var(--text);
  font: 700 clamp(24px, 2.6vw, 34px)/1.15 var(--serif);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.hero-author { margin-top: 6px; color: var(--muted); font: italic 16px/1.3 var(--serif); }
.hero-progress {
  position: relative;
  max-width: 460px;
  height: 6px;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 3px;
  background: rgba(255, 255, 255, .1);
}
.hero-progress i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #8f1426, #d4473a);
  box-shadow: 0 0 10px rgba(212, 71, 58, .45);
}
.hero-meta { margin-top: 9px; color: var(--muted); font: 13px/1.4 var(--sans); }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 22px; }
.hero-actions .btn { height: 40px; padding: 0 18px; font-size: 14px; }
.hero-hint { color: var(--dim); font-size: 12px; }

.hero-more { position: relative; align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 22px 0 54px; }
.hero-more .hero-eyebrow { margin: 0 0 2px; }
.hero-other {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(0, 0, 0, .14);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.hero-other:hover,
.hero-other:focus-visible { border-color: var(--hero-line); background: rgba(255, 255, 255, .06); outline: none; }
.hero-other-cover {
  position: relative;
  flex: none;
  width: 34px;
  height: 48px;
  overflow: hidden;
  border-radius: 1px 3px 3px 1px;
  background: var(--c);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.hero-other-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-other.away .hero-other-cover { visibility: hidden; }
.hero-other-text { min-width: 0; flex: 1; }
.hero-other-text b { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 600 13.5px/1.3 var(--serif); }
.hero-other-bar { display: block; height: 3px; margin-top: 7px; border-radius: 2px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.hero-other-bar i { display: block; height: 100%; background: #c0392f; }

.hero-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--dim);
  font-size: 20px;
  cursor: pointer;
}
.hero-close:hover { background: rgba(255, 255, 255, .08); color: var(--text); }

/* arriving: the nook fades up, then the book is set down on the desk */
#hero.entering .hero-inner { animation: hero-in .6s var(--ease-out) both; }
#hero.entering .hero-book > .book { animation: hero-book-in .9s .25s var(--ease-out) both; }
#hero.entering .hero-text > * { animation: hero-in .55s var(--ease-out) both; }
#hero.entering .hero-text > :nth-child(2) { animation-delay: .1s; }
#hero.entering .hero-text > :nth-child(3) { animation-delay: .16s; }
#hero.entering .hero-text > :nth-child(n+4) { animation-delay: .22s; }
@keyframes hero-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes hero-book-in {
  from { transform: translate3d(0, -60px, 60px) rotateY(60deg); }
  to { transform: translateZ(calc(var(--t) * -.5)) rotateY(24deg); }
}

@media (max-width: 1100px) {
  .hero-inner { grid-template-columns: 240px minmax(0, 1fr); }
  .hero-more { display: none; }
}
@media (max-width: 760px) {
  #hero { width: calc(100% - 44px); margin-top: 18px; }
  .hero-inner { grid-template-columns: minmax(0, 1fr); padding: 0 22px; }
  .hero-stage { display: none; }
}

/* ================================================================== pages inside the opening book */

/* Loose leaves, hinged at the spine like the cover. */
.leaf {
  position: absolute;
  top: 1.2%;
  bottom: 1.2%;
  left: 0;
  right: 1.2%;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
}
.leaf > .lf {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .14), transparent 9%),
    var(--noise),
    #f6efdf;
}
.leaf > .lf-back {
  transform: rotateY(180deg);
  background:
    linear-gradient(270deg, rgba(0, 0, 0, .14), transparent 9%),
    var(--noise),
    #f3ebd9;
}

/* running head, lines of type and the page number */
.pg-head {
  position: absolute;
  top: 6%;
  left: 0;
  right: 0;
  overflow: hidden;
  color: #8c7456;
  font: italic calc(7.5px * var(--k)) / 1 var(--serif);
  letter-spacing: .08em;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 14%;
}
.pg-text {
  position: absolute;
  top: 12%;
  bottom: 12%;
  left: 13%;
  right: 12%;
  background: repeating-linear-gradient(180deg,
    transparent 0 calc(5px * var(--k)),
    rgba(70, 52, 34, .2) calc(5px * var(--k)) calc(6.4px * var(--k)),
    transparent calc(6.4px * var(--k)) calc(9.5px * var(--k)));
  -webkit-mask-image: linear-gradient(90deg, #000 0 72%, rgba(0, 0, 0, .55) 86%, #000);
}
.pg-no {
  position: absolute;
  bottom: 5%;
  left: 0;
  right: 0;
  color: #7d6648;
  font: calc(8px * var(--k)) / 1 var(--serif);
  text-align: center;
}
/* darkens as a leaf stands up mid-turn */
.pg-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, .28), rgba(0, 0, 0, .08));
  opacity: 0;
  pointer-events: none;
}
.book > .page .pg-shade { display: none; }

/* the ribbon lying across the page you stopped at */
.page-ribbon {
  position: absolute;
  top: -1%;
  right: 22%;
  width: 3.4%;
  height: 74%;
  background: linear-gradient(90deg, #7e0f1d, #d43b47 45%, #8a1222);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 95%, 0 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
}

/* ---- each shelf's own Spines / Covers switch, at the right of its board */
.shelf-view {
  display: inline-flex;
  gap: 2px;
  margin-left: auto;
  padding: 2px;
  border-radius: 8px;
  background: rgba(20, 12, 7, .4);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .45);
  opacity: .55;
  transition: opacity .18s;
}
.board:hover .shelf-view,
.shelf-view:focus-within { opacity: 1; }
.shelf-view-btn {
  width: 26px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #d8c09a;
  cursor: pointer;
}
.shelf-view-btn .ico svg { width: 14px; height: 14px; }
.shelf-view-btn:hover { color: #fff2d8; }
.shelf-view-btn.on {
  color: #33230f;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass));
}
.shelf-view-btn:focus-visible { outline: 2px solid rgba(246, 222, 160, .8); outline-offset: 1px; }

/* ================================================================== home: every shelf at a glance */

#dash, #crumbs {
  --hero-bg:
    radial-gradient(ellipse 45% 90% at 16% 0%, rgba(255, 200, 130, .2), transparent 70%),
    linear-gradient(180deg, rgba(58, 38, 25, .92), rgba(30, 20, 13, .92));
  --hero-line: rgba(214, 170, 92, .26);
  --hero-desk: linear-gradient(180deg, #8a5a34, #5c3a21 45%, #3f2715);
  --hero-accent: var(--brass-hi);
  --dash-card: linear-gradient(180deg, rgba(52, 35, 23, .86), rgba(30, 20, 13, .86));
  --dash-plank: linear-gradient(180deg, #8d5d36, #5f3c22 60%, #462b17);
  --dash-back: linear-gradient(180deg, rgba(10, 6, 4, .55), rgba(30, 18, 10, .35));
}
/* What is inside home and the crumbs is styled in their Svelte components
   (ui/src/home); here only where they sit on the page. */
#dash {
  position: relative;
  width: min(1640px, calc(100% - 52px));
  margin: 26px auto 0;
}
#dash[hidden], #case[hidden] { display: none; }
#crumbs:has(.crumbs) + #case { margin-top: 14px; }

@media (max-width: 760px) {
  #dash { width: calc(100% - 44px); margin-top: 18px; }
}
