/* ultra_library — a sala de leitura ------------------------------------- */

:root {
  --room: #0e1411;
  --room-2: #172019;
  --wood: #3a2a1f;
  --wood-light: #6b4a33;
  --wood-dark: #24170f;
  --brass: #c19a5b;
  --brass-dim: #8b6d3f;
  --cream: #efe8d8;
  --cream-dim: #b8b09d;
  --ink: #16211c;
  --pages: #e9e2cf;
  --w: 270px;           /* largura da capa (profundidade do volume) */
  --slot: 440px;        /* altura de cada prateleira (livro mais alto: 428px) */
  --plank: 18px;        /* espessura da tábua */

  /* Tipografias por categoria */
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --body: "Literata", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --font-religiao: "Cormorant Garamond", "Cinzel", "Fraunces", Georgia, serif;
  --font-historia: "Cinzel", "Marcellus", "Fraunces", Georgia, serif;
  --font-estrategia: "Bodoni Moda", "Prata", "Cinzel", Georgia, serif;
  --font-literatura: "Playfair Display", "Fraunces", Georgia, serif;
  --font-filosofia: "Spectral", "Newsreader", Georgia, serif;
  --font-ciencia: "BioRhyme", "Space Grotesk", Georgia, serif;
  --font-economia: "Libre Baskerville", "Baskervville", Georgia, serif;
  --font-outros: "Fraunces", "Literata", Georgia, serif;

  /* Cores nobres e douramento */
  --gold: #d4af37;
  --gold-light: #fff2cc;
  --gold-dim: #997825;
  --bronze: #b38b4d;
  --silver: #e6e9ed;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body.library {
  margin: 0;
  background:
    radial-gradient(ellipse 70% 40% at 50% -5%, rgba(193,154,91,.18), transparent 70%),
    var(--room);
  color: var(--cream);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }

/* masthead ---------------------------------------------------------------- */
.masthead {
  text-align: center;
  padding: 4.5rem 1.5rem 2rem;
}
.masthead h1 {
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(2.6rem, 7vw, 5rem);
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 0;
  font-variation-settings: "opsz" 144;
}
.masthead h1 .ul {
  font-style: italic;
  color: var(--brass);
  font-weight: 400;
}
.tagline {
  margin: 1rem auto 0;
  max-width: 34rem;
  color: var(--cream-dim);
  font-style: italic;
  font-size: 1.05rem;
}
.stats {
  display: flex; gap: 1.6rem; justify-content: center; flex-wrap: wrap;
  margin: 1.4rem 0 0;
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brass-dim);
}

.shelf-nav {
  display: flex; gap: .25rem 1.4rem; justify-content: center; flex-wrap: wrap;
  padding: 0 1rem 2.5rem;
  font-family: var(--display);
  font-style: italic;
  font-size: 1rem;
}
.shelf-nav a { text-decoration: none; color: var(--cream-dim); border-bottom: 1px solid transparent; }
.shelf-nav a:hover { color: var(--brass); border-color: var(--brass-dim); }

/* estantes ---------------------------------------------------------------- */
.room {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1rem 4rem;
}
.bookcase {
  position: relative;
  margin: 0 auto 4rem;
  padding: 1.4rem 1.6rem 0;
  border-left: 14px solid var(--wood);
  border-right: 14px solid var(--wood);
  border-top: 10px solid var(--wood);
  background:
    linear-gradient(90deg, rgba(0,0,0,.35), transparent 6%, transparent 94%, rgba(0,0,0,.35)),
    linear-gradient(180deg, var(--room-2), #121a15);
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.8), inset 0 12px 30px rgba(0,0,0,.5);
  border-radius: 3px 3px 0 0;
}
.bookcase::before, .bookcase::after {
  content: ""; position: absolute; top: -10px; bottom: 0; width: 14px;
  background: linear-gradient(90deg, var(--wood-light), var(--wood) 40%, var(--wood-dark));
}
.bookcase::before { left: -14px; }
.bookcase::after { right: -14px; transform: scaleX(-1); }

.case-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  border-bottom: 1px solid rgba(193,154,91,.25);
  padding-bottom: .6rem;
  margin-bottom: .4rem;
}
.case-head h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.35rem;
  letter-spacing: .01em;
  color: var(--brass);
}
.case-count {
  font-family: var(--mono); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--brass-dim);
}

.legend {
  display: flex; flex-wrap: wrap; gap: .3rem 1.3rem;
  margin: .5rem 0 0;
  font-family: var(--mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--cream-dim);
}
.legend-item { display: inline-flex; align-items: center; gap: .5em; }
.legend-item i {
  width: 9px; height: 13px; border-radius: 1px;
  background: linear-gradient(90deg, rgba(0,0,0,.35), rgba(255,255,255,.1) 30%, rgba(0,0,0,.25)), hsl(var(--hue) 45% 38%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.3);
}
.legend-item em { font-style: normal; color: var(--brass-dim); }
/* espaço entre grupos de estantes diferentes na prateleira única */
.row-books .gap { flex: none; width: 26px; align-self: stretch; }

.row { position: relative; margin-top: 1.2rem; }
/* A fileira quebra em quantas prateleiras precisar; nada rola, nada é cortado.
   Cada linha tem altura fixa (--slot + --plank) e a tábua é desenhada no fundo,
   repetida a cada linha — assim todo livro sempre está apoiado numa tábua. */
.row-books {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: flex-end;
  margin: 0 -1.6rem;
  padding: 0 2.4rem;
  min-height: calc(var(--slot) + var(--plank));
  background:
    repeating-linear-gradient(180deg,
      rgba(0,0,0,.45) 0, transparent 22px,                          /* sombra da tábua de cima */
      transparent var(--slot),
      #7b5a40 var(--slot), var(--wood-light) calc(var(--slot) + 6px),
      var(--wood) calc(var(--slot) + 10px), var(--wood-dark) calc(var(--slot) + var(--plank)));
}
/* cada livro ocupa exatamente uma linha de --slot + --plank: apoiado na tábua */
.book { margin: calc(var(--slot) - var(--h)) 3px var(--plank) 0; }
.empty {
  align-self: center; margin: auto;
  font-family: var(--display); font-style: italic; color: rgba(184,176,157,.35);
}

.plank { position: relative; height: 0; }
.plank .label {
  position: absolute; right: 1.4rem; top: calc(var(--plank) / -2); transform: translateY(-50%);
  z-index: 2;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--brass); background: var(--wood-dark);
  padding: 2px 8px; border: 1px solid var(--brass-dim); border-radius: 2px;
}
.plank .label em { font-style: normal; margin-left: .7em; color: var(--brass-dim); }

/* o livro ----------------------------------------------------------------- */
.book {
  position: relative;
  flex: none;
  width: var(--t);
  height: var(--h);
  text-decoration: none;
  transform-style: preserve-3d;
  transform: perspective(1300px) translateZ(calc(var(--w) / -2)) rotateY(0deg);
  transition: transform .55s cubic-bezier(.2,.8,.2,1);
  transform-origin: 50% 100%;
  cursor: pointer;
  color: var(--cream);
}
@media (hover: hover) and (pointer: fine) {
  .book:hover, .book:focus-visible {
    transform: perspective(1300px) translateZ(calc(90px - var(--w) / 2)) rotateY(-34deg);
    z-index: 5;
  }
}
/* toque: sem giro nem tooltip — um leve afundamento confirma o tap; a ficha abre em seguida */
@media (hover: none) {
  .book { -webkit-tap-highlight-color: transparent; }
  .book:active { transform: perspective(1300px) translateZ(calc(var(--w) / -2)) scale(.97); transition-duration: .1s; }
}
.face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  display: block;
}

/* ========================================================================= */
/* TEXTURAS — grão gerado por SVG (feTurbulence), sem imagens externas        */
/* ========================================================================= */
/* Cada face tem `--sheen` (a luz: cilíndrica na lombada, plana na capa) e a
   textura empilha por baixo dela: mesclado grosso + grão fino, mesclados com
   soft-light/overlay sobre a cor do volume (--c). */
:root {
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='.33 .33 .33 0 -0.12 .33 .33 .33 0 -0.12 .33 .33 .33 0 -0.12 0 0 0 0 1'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
  --mottle: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='m'><feTurbulence type='fractalNoise' baseFrequency='.028' numOctaves='5' seed='7' stitchTiles='stitch'/><feColorMatrix values='.33 .33 .33 0 -0.15 .33 .33 .33 0 -0.15 .33 .33 .33 0 -0.15 0 0 0 0 1'/></filter><rect width='100%25' height='100%25' filter='url(%23m)' opacity='.6'/></svg>");
  --pebble: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='p'><feTurbulence type='turbulence' baseFrequency='.16' numOctaves='3' seed='3' stitchTiles='stitch'/><feColorMatrix values='.33 .33 .33 0 -0.14 .33 .33 .33 0 -0.14 .33 .33 .33 0 -0.14 0 0 0 0 1'/></filter><rect width='100%25' height='100%25' filter='url(%23p)' opacity='.6'/></svg>");
  --weave: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='h'><feTurbulence type='fractalNoise' baseFrequency='.02 .9' numOctaves='2' seed='2' stitchTiles='stitch'/><feColorMatrix values='.33 .33 .33 0 -0.12 .33 .33 .33 0 -0.12 .33 .33 .33 0 -0.12 0 0 0 0 1'/></filter><filter id='v'><feTurbulence type='fractalNoise' baseFrequency='.9 .02' numOctaves='2' seed='5' stitchTiles='stitch'/><feColorMatrix values='.33 .33 .33 0 -0.12 .33 .33 .33 0 -0.12 .33 .33 .33 0 -0.12 0 0 0 0 1'/></filter><rect width='100%25' height='100%25' filter='url(%23h)'/><rect width='100%25' height='100%25' filter='url(%23v)' opacity='.5'/></svg>");
  --paper: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='q'><feTurbulence type='fractalNoise' baseFrequency='.6' numOctaves='3' seed='11' stitchTiles='stitch'/><feColorMatrix values='.33 .33 .33 0 -0.04 .33 .33 .33 0 -0.04 .33 .33 .33 0 -0.04 0 0 0 0 1'/></filter><rect width='100%25' height='100%25' filter='url(%23q)' opacity='.55'/></svg>");
}

.spine, .cover, .card-cover, .back {
  background-color: var(--c);
  background-image: var(--sheen);
}

/* couro liso (bezerro): mesclado suave + grão finíssimo */
[data-texture="leather"] {
  background-image: var(--sheen), var(--mottle), var(--grain);
  background-size: auto, auto, 320px 320px, 90px 90px;
  background-blend-mode: normal, normal, soft-light, overlay;
}
/* marroquim: grão pipocado, mais vivo */
[data-texture="morocco"] {
  background-image: var(--sheen), var(--pebble), var(--grain);
  background-size: auto, auto, 110px 110px, 90px 90px;
  background-blend-mode: normal, normal, soft-light, overlay;
}
/* tecido: trama visível nos dois sentidos */
[data-texture="cloth"] {
  background-image: var(--sheen), var(--weave), var(--mottle);
  background-size: auto, auto, 160px 160px, 320px 320px;
  background-blend-mode: normal, normal, overlay, soft-light;
}
/* linho: trama mais aberta e clara */
[data-texture="linen"] {
  background-image: var(--sheen), var(--weave), var(--grain);
  background-size: auto, auto, 200px 200px, 120px 120px;
  background-blend-mode: normal, normal, overlay, soft-light;
}
/* buckram: tela engomada, granulada e fosca */
[data-texture="buckram"] {
  background-image: var(--sheen), var(--pebble), var(--weave);
  background-size: auto, auto, 130px 130px, 160px 160px;
  background-blend-mode: normal, normal, overlay, soft-light;
}

/* ========================================================================= */
/* TIPOGRAFIAS POR CATEGORIA                                                */
/* ========================================================================= */
[data-shelf="religiao"]   { --title-font: var(--font-religiao);   --title-track: .02em; }
[data-shelf="historia"]   { --title-font: var(--font-historia);   --title-track: .05em; --title-case: uppercase; }
[data-shelf="estrategia"] { --title-font: var(--font-estrategia); --title-track: .02em; }
[data-shelf="literatura"] { --title-font: var(--font-literatura); --title-track: .01em; }
[data-shelf="filosofia"]  { --title-font: var(--font-filosofia);  --title-track: .02em; }
[data-shelf="ciencia"]    { --title-font: var(--font-ciencia);    --title-track: .02em; }
[data-shelf="economia"]   { --title-font: var(--font-economia);   --title-track: .02em; }
[data-shelf="outros"]     { --title-font: var(--font-outros);     --title-track: .01em; }
.spine-title, .cover-title, .card h3 {
  font-family: var(--title-font, var(--display));
  letter-spacing: var(--title-track, .01em);
  text-transform: var(--title-case, none);
}

/* ========================================================================= */
/* A LOMBADA — anatomia comum a todos os templates                            */
/* ========================================================================= */
.spine {
  --pad: max(5px, calc(var(--t) * .09));       /* margem lateral proporcional à espessura */
  --gold-ink: #f1dc94;                          /* ouro estampado */
  --gold-line: rgba(222,186,90,.8);
  --sheen:
    linear-gradient(180deg, rgba(255,255,255,.07), transparent 22%, transparent 78%, rgba(0,0,0,.2)),
    linear-gradient(90deg, rgba(0,0,0,.6) 0, rgba(255,255,255,.1) 11%, rgba(255,255,255,.03) 40%, rgba(0,0,0,.14) 76%, rgba(0,0,0,.65) 100%);
  width: var(--t); height: var(--h);
  transform: translateZ(calc(var(--w) / 2));
  border-radius: 3px 3px 2px 2px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.4), inset 1px 0 0 rgba(255,255,255,.1);
  display: flex; flex-direction: column;
  padding: 0;
}
/* pequeno vinco de cabeça e pé (a virada do couro nas extremidades) */
.spine-crown, .spine-heel { flex: none; height: 6px; width: 100%; }
.spine-crown { background: linear-gradient(180deg, rgba(0,0,0,.5), rgba(255,255,255,.12) 45%, transparent); border-top: 1px solid rgba(255,255,255,.18); }
.spine-heel  { background: linear-gradient(0deg, rgba(0,0,0,.55), rgba(0,0,0,.15) 60%, transparent); }

.spine-comp {
  position: relative; min-height: 0; overflow: hidden;
  display: grid; grid-template-columns: 100%; place-items: center; align-content: center;
  padding: 4px var(--pad);
}
.spine-rib { flex: none; display: none; }
.spine-label-box, .spine-author-box {
  width: 100%; height: 100%; min-height: 0;
  display: grid; place-items: center; grid-template-columns: 100%;
  overflow: hidden;
}

/* texto: o fitter (library.js) reduz a fonte até caber; se não couber, .v vira vertical */
.spine-title {
  display: block; width: 100%; max-height: 100%; overflow: hidden;
  text-align: center; line-height: 1.12; text-wrap: balance;
  overflow-wrap: normal; hyphens: manual;
  color: var(--gold-ink);
  text-shadow: 0 1px 0 rgba(0,0,0,.65), 0 0 2px rgba(0,0,0,.4);
  font-weight: 600; font-size: 14px;
}
.spine-author {
  display: block; max-width: 100%; max-height: 100%; overflow: hidden; text-align: center;
  font-family: var(--mono); font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; line-height: 1.3;
  color: var(--gold-ink); text-shadow: 0 1px 0 rgba(0,0,0,.6);
  overflow-wrap: normal;
}
.spine-author[data-layout="v"], .spine-author.v { writing-mode: vertical-rl; width: auto; letter-spacing: .14em; white-space: nowrap; }
.spine-title.v, .spine-title.vertical {
  writing-mode: vertical-rl; width: auto; max-width: 100%; height: auto; max-height: 100%;
  text-align: center; text-wrap: balance;
}
.spine-ornament { font-size: 9px; color: var(--gold); opacity: .8; text-shadow: 0 1px 1px rgba(0,0,0,.7); line-height: 1; }
.spine-year {
  font-family: var(--mono); font-size: 7.5px; letter-spacing: .1em; line-height: 1; white-space: nowrap;
  color: var(--gold-ink); text-shadow: 0 1px 0 rgba(0,0,0,.6);
}
.foot-comp { gap: 4px; align-content: end; padding-bottom: 6px; }
.spine-mark, .cover-mark {
  width: 15px; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--display); font-style: italic; font-weight: 600; font-size: 7.5px; line-height: 1;
  letter-spacing: -.04em; font-variation-settings: "opsz" 9;
  color: var(--gold-ink); text-shadow: 0 1px 0 rgba(0,0,0,.6);
  border: 1px solid var(--gold-line);
  box-shadow: 0 0 0 2px rgba(0,0,0,.15), 0 0 0 3px rgba(222,186,90,.4), inset 0 0 3px rgba(0,0,0,.5);
}

/* Tamanhos por espessura (ponto de partida; o fitter só reduz) */
.spine[data-tier="thin"]        { --fs-h: 12px; --fs-v: 15px; }
.spine[data-tier="regular"]     { --fs-h: 13px; --fs-v: 17px; }
.spine[data-tier="thick"]       { --fs-h: 15px; --fs-v: 20px; }
.spine[data-tier="monumental"]  { --fs-h: 17px; --fs-v: 23px; }
.spine .spine-title { font-size: var(--fs-h); }
.spine .spine-title.vertical, .spine .spine-title.v { font-size: var(--fs-v); }

/* ========================================================================= */
/* TEMPLATE 1: FÓLIO CLÁSSICO — nervuras em relevo, etiquetas de couro        */
/* ========================================================================= */
.spine[data-template="1"] .comp-1 { flex: 0 0 8%; }
.spine[data-template="1"] .comp-2 { flex: 0 0 30%; padding: 6px var(--pad); }
.spine[data-template="1"] .comp-3 { flex: 0 0 14%; padding: 5px var(--pad); }
.spine[data-template="1"] .comp-4 { flex: 1 1 auto; }
.spine[data-template="1"] .comp-5 { flex: 0 0 13%; }

.spine[data-template="1"] .spine-rib {
  display: block; height: 7px; width: 100%;
  background: linear-gradient(180deg, rgba(255,255,255,.32) 0%, rgba(255,255,255,.06) 40%, rgba(0,0,0,.55) 100%);
  box-shadow: 0 2px 4px rgba(0,0,0,.55), 0 -1px 1px rgba(0,0,0,.25);
  position: relative;
}
.spine[data-template="1"] .spine-rib::before, .spine[data-template="1"] .spine-rib::after {
  content: ""; position: absolute; left: 4px; right: 4px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-line) 18%, #fff3c8 50%, var(--gold-line) 82%, transparent);
  opacity: .85;
}
.spine[data-template="1"] .spine-rib::before { top: -3px; }
.spine[data-template="1"] .spine-rib::after  { bottom: -3px; }

/* etiquetas de couro de outra cor (o "título" e o "autor" em peças coladas) */
.spine[data-template="1"] .spine-label-box,
.spine[data-template="1"] .spine-author-box {
  --label: hsl(calc(var(--hue) + 24) 34% 13%);
  background-color: var(--label);
  background-image:
    linear-gradient(180deg, rgba(255,255,255,.14), transparent 35%, rgba(0,0,0,.25)),
    linear-gradient(90deg, rgba(0,0,0,.3), transparent 15%, transparent 85%, rgba(0,0,0,.35)),
    var(--pebble);
  background-size: auto, auto, 110px 110px;
  background-blend-mode: normal, normal, soft-light;
  border: 1px solid var(--gold-line);
  outline: 1px solid rgba(222,186,90,.4); outline-offset: 2px;
  border-radius: 2px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), inset 0 -1px 0 rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.6);
  padding: 5px 5px;
  margin: 3px;
  width: calc(100% - 6px); height: calc(100% - 6px);
}
.spine[data-template="1"] .spine-title { font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.spine[data-template="1"] .spine-author-box { display: grid; place-items: center; overflow: hidden; }
.spine[data-template="1"] .spine-ornament { font-size: 11px; }

/* ========================================================================= */
/* TEMPLATE 2: ESTAMPAGEM A OURO DE BIBLIOTECA — filetes duplos, tudo em ouro */
/* ========================================================================= */
.spine[data-template="2"] .spine-rib.rib-1, .spine[data-template="2"] .spine-rib.rib-4 {
  display: block; height: 4px; width: calc(100% - 2 * var(--pad)); margin: 3px auto;
  border-top: 1px solid var(--gold-line); border-bottom: 1px solid var(--gold-line);
  box-shadow: 0 1px 1px rgba(0,0,0,.5);
}
.spine[data-template="2"] .comp-1 { flex: 0 0 5%; }
.spine[data-template="2"] .comp-2 { flex: 0 0 42%; }
.spine[data-template="2"] .comp-3 { flex: 0 0 16%; }
.spine[data-template="2"] .comp-4 { flex: 1 1 auto; }
.spine[data-template="2"] .comp-5 { flex: 0 0 14%; }
.spine[data-template="2"] .spine-title { text-transform: uppercase; letter-spacing: .08em; line-height: 1.22; }
.spine[data-template="2"] .spine-author { letter-spacing: .14em; }
.spine[data-template="2"] .spine-ornament { font-size: 0; }
.spine[data-template="2"] .spine-ornament::before {
  content: ""; display: block; width: 22px; height: 1px; background: var(--gold-line);
  box-shadow: 0 3px 0 var(--gold-line);
}

/* ========================================================================= */
/* TEMPLATE 3: TECIDO COM FILETES — título vertical, autor no pé              */
/* ========================================================================= */
.spine[data-template="3"] .spine-rib.rib-1, .spine[data-template="3"] .spine-rib.rib-4 {
  display: block; height: 3px; width: calc(100% - 2 * var(--pad)); margin: 4px auto;
  border-top: 1px solid rgba(0,0,0,.5); border-bottom: 1px solid rgba(255,255,255,.18);
}
.spine[data-template="3"] .comp-1, .spine[data-template="3"] .comp-4 { display: none; }
.spine[data-template="3"] .comp-2 { flex: 1 1 auto; padding: 8px var(--pad); }
.spine[data-template="3"] .comp-3 { flex: 0 0 auto; max-height: 26%; padding: 4px var(--pad); }
.spine[data-template="3"] .comp-5 { flex: 0 0 12%; }
.spine[data-template="3"] .spine-title { color: var(--cream); font-weight: 500; letter-spacing: .03em; text-shadow: 0 1px 2px rgba(0,0,0,.7); }
.spine[data-template="3"] .spine-author { color: var(--cream); font-size: 9px; }
.spine[data-template="3"] .spine-year { color: var(--cream-dim); }
.spine[data-template="3"] .spine-mark { color: var(--cream); border-color: rgba(239,232,216,.55); box-shadow: 0 0 0 2px rgba(0,0,0,.15), 0 0 0 3px rgba(239,232,216,.25); }

/* ========================================================================= */
/* TEMPLATE 4: CARTELA DE PAPEL — etiqueta colada, tipografia preta           */
/* ========================================================================= */
.spine[data-template="4"] .comp-1 { flex: 0 0 5%; }
.spine[data-template="4"] .comp-2 { flex: 0 0 38%; padding: 4px calc(var(--pad) - 1px); }
.spine[data-template="4"] .comp-3 { flex: 0 0 auto; max-height: 24%; }
.spine[data-template="4"] .comp-4 { flex: 1 1 auto; }
.spine[data-template="4"] .comp-5 { flex: 0 0 13%; }
.spine[data-template="4"] .spine-label-box {
  background-color: #ece4d1;
  background-image: linear-gradient(180deg, rgba(255,255,255,.5), transparent 40%, rgba(0,0,0,.06)), var(--paper);
  background-size: auto, 240px 240px;
  background-blend-mode: normal, multiply;
  border: 1px solid #5a4d3b; outline: 1px solid rgba(90,77,59,.35); outline-offset: -3px;
  box-shadow: 0 1px 3px rgba(0,0,0,.55), 0 0 0 1px rgba(0,0,0,.25);
  border-radius: 1px;
  padding: 8px 6px;
}
.spine[data-template="4"] .spine-title { color: #1a1612; text-shadow: none; font-weight: 700; letter-spacing: 0; }
.spine[data-template="4"] .spine-author { color: var(--cream); }
.spine[data-template="4"] .spine-ornament { color: var(--cream-dim); opacity: .55; }
.spine[data-template="4"] .spine-year { color: var(--cream-dim); }
.spine[data-template="4"] .spine-mark { color: var(--cream); border-color: rgba(239,232,216,.5); box-shadow: 0 0 0 2px rgba(0,0,0,.15), 0 0 0 3px rgba(239,232,216,.22); }

/* ========================================================================= */
/* TEMPLATE 5: CAPA DURA MODERNA — réguas duplas em ouro, título vertical     */
/* ========================================================================= */
.spine[data-template="5"] .spine-rib.rib-1, .spine[data-template="5"] .spine-rib.rib-4 {
  display: block; height: 5px; width: calc(100% - 2 * var(--pad)); margin: 4px auto;
}
.spine[data-template="5"] .spine-rib.rib-1 { border-top: 2px solid var(--gold-line); border-bottom: 1px solid rgba(222,186,90,.5); }
.spine[data-template="5"] .spine-rib.rib-4 { border-top: 1px solid rgba(222,186,90,.5); border-bottom: 2px solid var(--gold-line); }
.spine[data-template="5"] .comp-1, .spine[data-template="5"] .comp-4 { display: none; }
.spine[data-template="5"] .comp-2 { flex: 1 1 auto; padding: 8px var(--pad); }
.spine[data-template="5"] .comp-3 { flex: 0 0 auto; max-height: 26%; padding: 4px var(--pad); }
.spine[data-template="5"] .comp-5 { flex: 0 0 12%; }
.spine[data-template="5"] .spine-title { color: var(--cream); font-weight: 600; letter-spacing: .04em; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.spine[data-template="5"] .spine-author { color: var(--gold-ink); font-size: 9px; }

/* ========================================================================= */
/* TEMPLATE 6: ANTIQUÁRIO — filetes triplos e florão                          */
/* ========================================================================= */
.spine[data-template="6"] .spine-rib {
  display: block; height: 5px; width: calc(100% - 2 * var(--pad) + 4px); margin: 2px auto;
  border-top: 1px solid var(--gold-line); border-bottom: 1px solid var(--gold-line);
  background: linear-gradient(180deg, transparent 40%, rgba(222,186,90,.7) 40%, rgba(222,186,90,.7) 60%, transparent 60%);
}
.spine[data-template="6"] .comp-1 { flex: 0 0 7%; }
.spine[data-template="6"] .comp-2 { flex: 0 0 36%; }
.spine[data-template="6"] .comp-3 { flex: 0 0 15%; }
.spine[data-template="6"] .comp-4 { flex: 1 1 auto; }
.spine[data-template="6"] .comp-5 { flex: 0 0 13%; }
.spine[data-template="6"] .spine-title { text-transform: uppercase; letter-spacing: .06em; line-height: 1.2; }
.spine[data-template="6"] .spine-ornament { font-size: 14px; opacity: .9; }
.spine[data-template="6"] .spine-ornament::before { content: "❦"; }
.spine[data-template="6"] .spine-ornament { font-size: 0; }
.spine[data-template="6"] .spine-ornament::before { font-size: 15px; color: var(--gold); text-shadow: 0 1px 1px rgba(0,0,0,.7); }

/* Templates de título vertical (3 e 5): o título nasce vertical */
.spine[data-template="3"] .spine-title, .spine[data-template="5"] .spine-title {
  writing-mode: vertical-rl; width: auto; max-width: 100%; height: auto; max-height: 100%;
  font-size: var(--fs-v);
}

/* Faces 3D do livro ------------------------------------------------------- */
.cover, .back {
  width: var(--w); height: var(--h);
  left: 50%; margin-left: calc(var(--w) / -2);
}
.cover { transform: rotateY(90deg) translateZ(calc(var(--t) / 2)); }
.back  { transform: rotateY(-90deg) translateZ(calc(var(--t) / 2)); --sheen: linear-gradient(90deg, rgba(0,0,0,.3), transparent 20%), linear-gradient(transparent, transparent); }
.edge {
  width: var(--t); height: var(--h);
  transform: rotateY(180deg) translateZ(calc(var(--w) / 2));
  background: repeating-linear-gradient(90deg, var(--pages) 0 1px, #cfc6ae 1px 2px);
}
.top, .bottom {
  width: var(--t); height: var(--w);
  top: 50%; margin-top: calc(var(--w) / -2);
  background:
    linear-gradient(90deg, rgba(0,0,0,.25), transparent 12%, transparent 88%, rgba(0,0,0,.25)),
    repeating-linear-gradient(0deg, var(--pages) 0 1px, #cfc6ae 1px 2px);
}
.top    { transform: rotateX(90deg) translateZ(calc(var(--h) / 2)); }
.bottom { transform: rotateX(-90deg) translateZ(calc(var(--h) / 2)); background: var(--c); }

/* sombra de contato do volume na tábua */
.book::before {
  content: ""; position: absolute; left: -10px; right: -10px; bottom: -3px; height: 14px;
  background: radial-gradient(ellipse 60% 100% at 50% 0, rgba(0,0,0,.6), transparent 70%);
  transform: translateZ(calc(var(--w) / 2 + 1px));
  pointer-events: none;
}

/* ========================================================================= */
/* CAPA DO LIVRO (COVER) E FICHA (CARD-COVER)                                */
/* ========================================================================= */
.cover, .card-cover {
  --sheen:
    radial-gradient(ellipse 80% 60% at 30% 20%, rgba(255,255,255,.14), transparent 60%),
    linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,.1) 6%, transparent 14%, transparent 70%, rgba(0,0,0,.12));
  --gold-ink: #f1dc94;
  --gold-line: rgba(222,186,90,.8);
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.4), inset 5px 0 12px -4px rgba(0,0,0,.75);
  border-radius: 1px 4px 4px 1px;
  overflow: hidden;
  padding: 11px 11px 11px 15px;
  display: flex;
}

/* Moldura dourada em baixo-relevo */
.cover-frame {
  position: relative; flex: 1;
  display: flex; flex-direction: column; justify-content: space-between;
  border: 1px solid var(--gold-line);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.3), 0 0 0 1px rgba(0,0,0,.25);
  border-radius: 2px;
  padding: 12px 10px;
  min-height: 0;
}
.cover-inner-border {
  position: absolute; inset: 3px;
  border: 1px solid rgba(222,186,90,.3);
  pointer-events: none; border-radius: 1px;
}
.corner {
  position: absolute; width: 9px; height: 9px;
  border-color: var(--gold-line); pointer-events: none;
}
.corner-tl { top: -1px; left: -1px; border-top: 2px solid; border-left: 2px solid; }
.corner-tr { top: -1px; right: -1px; border-top: 2px solid; border-right: 2px solid; }
.corner-bl { bottom: -1px; left: -1px; border-bottom: 2px solid; border-left: 2px solid; }
.corner-br { bottom: -1px; right: -1px; border-bottom: 2px solid; border-right: 2px solid; }

.cover-header { text-align: center; margin-bottom: 4px; }
.cover-badge {
  font-family: var(--mono); font-size: 7px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--gold-ink); padding: 2px 8px; display: inline-block;
  border-top: 1px solid rgba(222,186,90,.45); border-bottom: 1px solid rgba(222,186,90,.45);
}

/* placa de papel (a "cartela" colada na capa) */
.plate {
  flex: 1; min-height: 0;
  background-color: #ede5d2;
  background-image: linear-gradient(180deg, rgba(255,255,255,.55), transparent 35%, rgba(0,0,0,.05)), var(--paper);
  background-size: auto, 240px 240px;
  background-blend-mode: normal, multiply;
  color: var(--ink);
  margin: 6px 2px;
  padding: 12px 8px;
  border-radius: 1px;
  box-shadow: inset 0 0 0 1px rgba(90,77,59,.35), inset 0 0 0 3px #ede5d2, inset 0 0 0 4px rgba(90,77,59,.25), 0 2px 5px rgba(0,0,0,.4);
  display: grid; place-items: center; text-align: center;
  overflow: hidden;
}
.plate-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; max-height: 100%; }
.cover-title {
  display: block; width: 100%; max-height: 100%; overflow: hidden;
  font-weight: 600; font-size: 14px; line-height: 1.15;
  color: #1a1612; text-wrap: balance; overflow-wrap: normal;
}
.cover-divider { font-size: 8px; color: var(--brass); line-height: 1; opacity: .85; }
.cover-author {
  font-family: var(--mono); font-size: 7.5px; letter-spacing: .12em; text-transform: uppercase;
  color: #5a5043;
}
.cover-footer { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 4px; }
.cover-year { font-family: var(--mono); font-size: 8px; letter-spacing: .1em; color: var(--gold-ink); }
.cover-mark { width: 13px; font-size: 6.5px; }

/* Encadernações de tecido/modernas (T3, T5): título estampado direto no pano, sem cartela */
[data-template="3"] .plate, [data-template="5"] .plate {
  background: none; box-shadow: none; color: var(--cream); padding: 10px 4px;
}
[data-template="3"] .cover-title, [data-template="5"] .cover-title {
  color: var(--cream); text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
[data-template="5"] .cover-title { color: var(--gold-ink); }
[data-template="3"] .cover-author, [data-template="5"] .cover-author { color: var(--cream-dim); }
[data-template="3"] .cover-divider, [data-template="5"] .cover-divider { color: var(--gold); }

/* Escala na capa do livro 3D */
.book .cover .cover-frame { padding: 16px 14px; }
.book .cover .cover-title { font-size: 24px; }
.book .cover .plate { padding: 18px 12px; margin: 8px 4px; }
.book .cover .cover-author { font-size: 11px; }
.book .cover .cover-badge { font-size: 8.5px; padding: 3px 10px; }
.book .cover .cover-year { font-size: 10.5px; }
.book .cover .cover-mark { width: 17px; font-size: 8.5px; }
.book .cover .cover-divider { font-size: 11px; }

/* apoio de estante ao fim da fileira única */
.bookend {
  flex: none; align-self: flex-end; position: relative;
  width: 14px; height: 120px; margin: 0 0 var(--plank) 4px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.22), transparent 35%, rgba(0,0,0,.4)),
    linear-gradient(180deg, #8f6c3e, #5e4529 60%, #3e2c19);
  border-radius: 2px 2px 0 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), 4px 6px 12px -4px rgba(0,0,0,.7);
}
.bookend::after {
  content: ""; position: absolute; left: -40px; bottom: 0; width: 42px; height: 5px;
  background: linear-gradient(180deg, #8c6a3c, #4a361f);
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 -6px 12px -4px rgba(0,0,0,.5);
  border-radius: 1px;
}

/* tooltip (o L4 ao tocar) ------------------------------------------------- */
.book .tip { display: none; }
.tooltip {
  position: fixed; z-index: 50;
  width: min(360px, calc(100vw - 2rem));
  background: #f4efe3; color: var(--ink);
  border-radius: 4px;
  padding: .9rem 1rem;
  box-shadow: 0 20px 40px -12px rgba(0,0,0,.8), 0 0 0 1px rgba(0,0,0,.4);
  pointer-events: none;
  opacity: 0; transform: translateY(6px);
  transition: opacity .18s, transform .18s;
  font-size: .86rem; line-height: 1.5;
}
.tooltip.on { opacity: 1; transform: none; }
.tooltip b { display: block; font-family: var(--display); font-weight: 500; font-size: 1.05rem; line-height: 1.2; }
.tooltip i { display: block; font-style: italic; color: #6b6355; margin-bottom: .5rem; font-size: .8rem; }
.tooltip .tip-l4 { display: block; text-wrap: pretty; }
.tooltip .tip-hint { display: block; margin-top: .6rem; font-family: var(--mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: #8b6d3f; }

/* estantes vazias e rodapé ------------------------------------------------ */
.empties { margin-top: 3rem; }
.empties summary {
  cursor: pointer; list-style: none;
  font-family: var(--display); font-style: italic; color: var(--cream-dim);
  text-align: center; padding: .6rem;
}
.empties summary::before { content: "▸ "; color: var(--brass-dim); }
.empties[open] summary { margin-bottom: 2rem; }
.empties[open] summary::before { content: "▾ "; }
.empties .bookcase { opacity: .6; }

.colophon {
  text-align: center; padding: 1rem 1.5rem 4rem;
  color: var(--cream-dim); font-style: italic; font-size: .92rem;
}

/* ficha do livro ---------------------------------------------------------- */
.card-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6,9,8,.6); backdrop-filter: blur(3px);
}
.card {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: min(560px, 100vw);
  background: #141b17;
  border-left: 1px solid rgba(193,154,91,.25);
  box-shadow: -30px 0 60px -20px rgba(0,0,0,.9);
  overflow-y: auto;
  padding: 1.6rem 1.6rem 3rem;
  animation: slide-in .35s cubic-bezier(.2,.8,.2,1);
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.card[hidden], .card-backdrop[hidden] { display: none; }
.card-close {
  position: absolute; top: .8rem; right: .9rem;
  background: none; border: 1px solid rgba(193,154,91,.35); color: var(--brass);
  width: 34px; height: 34px; border-radius: 50%; font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.card-close:hover { background: rgba(193,154,91,.12); }
.card-inner { display: grid; grid-template-columns: 150px 1fr; gap: 1.5rem; align-items: start; }
.card-ladder { grid-column: 1 / -1; }
.card-cover { width: 150px; height: 220px; position: sticky; top: 0; }
.card-body { min-width: 0; }
.card .eyebrow { padding-right: 2.6rem; }
.card .eyebrow {
  margin: .2rem 0 .5rem; font-family: var(--mono); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--brass);
}
.card h3 {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: 1.7rem; line-height: 1.1;
  letter-spacing: -.01em; text-wrap: balance;
}
.card .orig-title { margin: .3rem 0 0; font-style: italic; color: var(--cream-dim); font-size: .95rem; }
.card .l4 {
  margin: 1.2rem 0 0; font-size: .98rem; line-height: 1.6; text-wrap: pretty;
  border-left: 2px solid hsl(var(--hue) 45% 55% / .6); padding-left: .9rem;
}
.card .l4[hidden] { display: none; }
.spoiler-toggle {
  margin: .7rem 0 0; background: none; border: 1px solid hsl(var(--hue) 45% 55% / .5); border-radius: 999px;
  padding: .3rem .8rem; cursor: pointer; color: inherit;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase;
}
.spoiler-toggle:hover, .spoiler-toggle[aria-pressed="true"] { border-color: hsl(var(--hue) 45% 55%); background: hsl(var(--hue) 45% 55% / .15); }
.ladder-title {
  margin: 1.8rem 0 .6rem; font-family: var(--mono); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--brass-dim);
}
.ladder { display: grid; gap: 2px; }
.l1-cuts {
  margin: .9rem 0 0; font-size: .82rem; line-height: 1.5; color: var(--brass-dim); text-wrap: pretty;
}
.l1-cuts b { font-weight: 500; color: inherit; }
.rung {
  display: grid; grid-template-columns: 9.5rem 1fr; gap: 1rem; align-items: center;
  padding: .6rem .6rem; border-radius: 3px; text-decoration: none;
  transition: background .15s;
}
.rung:hover { background: rgba(193,154,91,.1); }
.rung-name b { display: block; font-family: var(--display); font-weight: 500; font-size: 1rem; }
.rung-name span { display: block; font-size: .72rem; color: var(--cream-dim); line-height: 1.3; }
/* barra + porcentagem na primeira linha; palavras · páginas · tempo na segunda, tudo em linha */
.rung-data {
  display: grid; grid-template-columns: 1fr auto; column-gap: .7rem; row-gap: .35rem; align-items: center;
  min-width: 0;
}
.rung-bar { height: 8px; background: rgba(255,255,255,.06); border-radius: 2px; overflow: hidden; }
.rung-bar i { display: block; height: 100%; background: hsl(var(--hue) 50% 58%); border-radius: 2px; }
.rung-pct {
  font-family: var(--mono); font-size: .8rem; font-weight: 500; text-align: right;
  min-width: 3.6em; color: hsl(var(--hue) 55% 72%); font-variant-numeric: tabular-nums;
}
.rung-num {
  grid-column: 1 / -1;
  font-family: var(--mono); font-size: .68rem; letter-spacing: .03em; color: var(--cream-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.rung-num b { font-weight: 500; color: var(--cream); }
.rung-num .sep { margin: 0 .55em; color: var(--brass-dim); }

@media (max-width: 640px) {
  .card-inner { grid-template-columns: 1fr; }
  .card-ladder { grid-column: auto; }
  .card-cover { position: static; }
  .rung { grid-template-columns: 1fr; gap: .4rem; }
  .rung-num { font-size: .64rem; }
  .rung-num .sep { margin: 0 .4em; }
  .bookcase { border-left-width: 8px; border-right-width: 8px; padding: 1rem .8rem 0; }
  .bookcase::before, .bookcase::after { width: 8px; }
  .bookcase::before { left: -8px; } .bookcase::after { right: -8px; }
  .row-books { margin: 0 -.8rem; padding: 0 1.4rem; }
  .plank .label { right: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .book, .tooltip, .card { transition: none; animation: none; }
}
