/* Buch-Darstellung, Regal, Animationen */

.book {
  --w: 15px;
  --h: 140px;
  --c: var(--sub-graphit);
  --tint: transparent;
  --round: linear-gradient(90deg,
    rgb(0 0 0 / .30) 0%, rgb(0 0 0 / .06) 16%, rgb(255 255 255 / .11) 40%,
    rgb(255 255 255 / .05) 58%, rgb(0 0 0 / .08) 80%, rgb(0 0 0 / .32) 100%);
  --texture: none;
  position: relative;
  flex: none;
  display: block;
  width: var(--w);
  height: var(--h);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: var(--r-book) var(--r-book) 1px 1px;
  background-color: var(--c);
  background-image: linear-gradient(var(--tint), var(--tint)), var(--round), var(--texture);
  box-shadow: var(--shadow-book);
  color: inherit;
  transform-origin: bottom center;
  transition: transform var(--dur-fast) var(--ease-out), opacity var(--dur-med) ease;
  -webkit-tap-highlight-color: transparent;
}

/* Bünde oben und unten (ab Taschenbuch) */
.book::before, .book::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgb(0 0 0 / .22);
  box-shadow: 0 1px 0 rgb(255 255 255 / .12);
  pointer-events: none;
}
.book::before { top: 9%; }
.book::after { bottom: 9%; }
.book--notebook::before, .book--notebook::after { display: none; }
.book--tome::before { box-shadow: 0 1px 0 rgb(255 255 255 / .12), 0 4px 0 rgb(0 0 0 / .18); }
.book--tome::after { box-shadow: 0 1px 0 rgb(255 255 255 / .12), 0 -4px 0 rgb(0 0 0 / .18); }

/* Foliant: fünf erhabene Bünde und ein dunkles Rückenschild mit Messing-Rahmen */
.book--folio::before { box-shadow: 0 1px 0 rgb(255 255 255 / .12), 0 4px 0 rgb(0 0 0 / .18); }
.book--folio::after { box-shadow: 0 1px 0 rgb(255 255 255 / .12), 0 -4px 0 rgb(0 0 0 / .18); }
.book__bands {
  --band: linear-gradient(180deg, rgb(0 0 0 / .34) 0 1px, rgb(255 255 255 / .2) 1px 2px, rgb(255 255 255 / .07) 2px 3px, rgb(0 0 0 / .36) 3px 4px);
  position: absolute;
  left: 0;
  right: 0;
  top: 17%;
  bottom: 17%;
  background:
    var(--band) 0 0 / 100% 4px no-repeat,
    var(--band) 0 25% / 100% 4px no-repeat,
    var(--band) 0 50% / 100% 4px no-repeat,
    var(--band) 0 75% / 100% 4px no-repeat,
    var(--band) 0 100% / 100% 4px no-repeat;
  pointer-events: none;
}
.book__label {
  /* im Feld zwischen erstem und zweitem Bund */
  position: absolute;
  left: 3px;
  right: 3px;
  top: calc(17% + 8px);
  height: calc(16.5% - 13px);
  border-radius: 1px;
  background:
    linear-gradient(90deg, rgb(0 0 0 / .28), rgb(255 255 255 / .06) 45%, rgb(0 0 0 / .28)),
    color-mix(in srgb, var(--c) 32%, #120D09);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brass) 65%, transparent), 0 1px 0 rgb(255 255 255 / .08);
  pointer-events: none;
}
.book--folio .book__initial { top: calc(25.25% - 4px); z-index: 1; }

/* Einband: Leinen – sehr feines Streifenmuster */
.cover--linen {
  --texture:
    repeating-linear-gradient(0deg, rgb(255 255 255 / .035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgb(0 0 0 / .035) 0 1px, transparent 1px 2px);
}

/* Einband: Leder – weicher Glanz, etwas dunkler, runder */
.cover--leather {
  border-radius: var(--r-leather);
  --round: linear-gradient(90deg,
    rgb(0 0 0 / .42) 0%, rgb(0 0 0 / .14) 14%, rgb(255 255 255 / .20) 36%,
    rgb(255 255 255 / .06) 52%, rgb(0 0 0 / .16) 78%, rgb(0 0 0 / .44) 100%);
  --texture: linear-gradient(rgb(0 0 0 / .10), rgb(0 0 0 / .10));
}

/* Goldschnitt: 2 px Messing-Kante oben */
.has-gilt { box-shadow: inset 0 2px 0 var(--brass), var(--shadow-book); }

/* Prägung: Fach-Initiale vertikal in Messington */
.book__initial {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  writing-mode: vertical-rl;
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 600;
  color: var(--brass);
  text-shadow: 0 1px 0 rgb(0 0 0 / .35);
  pointer-events: none;
  line-height: 1;
}

/* Lesezeichen-Band: ragt unten 6 px heraus */
.book__ribbon {
  position: absolute;
  bottom: -6px;
  left: 30%;
  width: 3px;
  height: 14px;
  background: var(--ribbon, #C7A15A);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  pointer-events: none;
}

/* Eingerissen (aufgegeben) */
.is-torn {
  filter: saturate(.35);
  transform: rotate(-4deg);
  transform-origin: bottom left;
  margin-left: 9px;
  clip-path: polygon(0 7px, 12% 2px, 26% 9px, 40% 3px, 55% 10px, 68% 2px, 82% 8px, 100% 3px, 100% 100%, 0 100%);
}

/* Interaktion im Regal */
.shelf .book { cursor: pointer; }
.shelf .book:hover, .shelf .book:focus-visible { transform: translateY(-2px) rotate(-2.5deg); z-index: 2; }
.shelf .book.is-torn:hover, .shelf .book.is-torn:focus-visible { transform: translateY(-2px) rotate(-6deg); }
.shelf .book:focus-visible { outline-offset: 3px; }
.book.is-dimmed { opacity: .2; }
.book.is-hidden-for-fx { visibility: hidden; }

/* ---------- Regal ---------- */

.shelf {
  --board-h: 14px;
  --row-h: 200px; /* ROW_H in shelf.js */
  position: relative;
}
.shelf--walnutDark {
  --wood: #3A281D;
  --wood-edge: #4F382A;
  --wood-dark: #22160F;
}

.week { margin-bottom: var(--sp-6); }
.week__head {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-4);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  padding: 0 var(--sp-1) var(--sp-2);
  font-variant-numeric: tabular-nums;
}
.week__head strong { color: var(--ink); font-weight: 500; }
.week__head .sum { font-family: var(--font-serif); font-size: var(--fs-sm); color: var(--ink); }

.shelf-row { position: relative; }
.shelf-row + .shelf-row { margin-top: var(--sp-5); }

.shelf-books {
  position: relative;
  z-index: 2; /* Lesezeichen-Bänder hängen über die Brettkante */
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: var(--row-h);
  padding: 0 var(--sp-4);
}

.board {
  position: relative;
  height: var(--board-h);
  border-radius: 2px;
  background:
    linear-gradient(90deg, rgb(255 255 255 / .03), transparent 30%, rgb(0 0 0 / .05) 60%, transparent 85%, rgb(255 255 255 / .02)),
    linear-gradient(180deg, var(--wood-edge) 0 3px, var(--wood) 3px 70%, var(--wood-dark));
  box-shadow: var(--shadow-board);
  z-index: 1;
}
.board::after {
  /* Schattenkante unter den Büchern */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(rgb(0 0 0 / .18), transparent);
}

.shelf-empty {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--fs-lg);
  color: var(--ink-muted);
  align-self: center;
  padding-left: var(--sp-4);
  margin-bottom: 40px;
}

.week-placeholder { height: var(--ph, 240px); }

/* Deko-Objekte */
.decor { flex: none; pointer-events: none; color: var(--ink); }
.decor svg { display: block; }
.decor--bookend { margin-left: 1px; }
.decor--lamp, .decor--plant, .decor--ladder { margin-left: var(--sp-3); }
.decor--lamp { position: relative; }
.decor--ladder { margin-bottom: -2px; }
.lamp-glow {
  --glow: radial-gradient(closest-side, rgb(255 206 135 / .34), rgb(255 192 115 / .13) 55%, transparent);
  position: absolute;
  left: 50%;
  top: -80px;
  width: 400px;
  height: 300px;
  transform: translateX(-50%);
  background: var(--glow);
  pointer-events: none;
  mix-blend-mode: screen;
}
:root[data-theme="light"] .lamp-glow { mix-blend-mode: multiply; --glow: radial-gradient(closest-side, rgb(255 214 150 / .45), rgb(255 222 170 / .18) 55%, transparent); }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .lamp-glow { mix-blend-mode: multiply; --glow: radial-gradient(closest-side, rgb(255 214 150 / .45), rgb(255 222 170 / .18) 55%, transparent); }
}

/* ---------- Bücherregal: Regale mit je 7 Böden ---------- */

.bookcase {
  --side: 18px;
  --back: color-mix(in srgb, var(--wood-dark) 68%, #000);
  position: relative;
  min-height: var(--ph, 0);
  margin: 0 0 var(--sp-7);
}
.bookcase:not([data-rendered]) { height: var(--ph); }

.bookcase__crown {
  position: relative;
  z-index: 3;
  height: 30px;
  margin: 0 -8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(180deg, var(--wood-edge) 0 4px, var(--wood) 4px 21px, var(--wood-dark) 21px 24px, var(--wood) 24px);
  box-shadow: 0 5px 8px -4px rgb(0 0 0 / .45);
}
.bookcase__plate {
  padding: 2px 10px;
  border-radius: 2px;
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: .02em;
  color: #2B2016;
  background: linear-gradient(180deg, #D8BC86, var(--brass));
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .18), 0 1px 1px rgb(0 0 0 / .3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bookcase__body {
  position: relative;
  padding: 0 var(--side);
  background:
    linear-gradient(90deg, var(--wood-dark), var(--wood) 35%, var(--wood-edge) 70%, var(--wood)) left top / var(--side) 100% no-repeat,
    linear-gradient(90deg, var(--wood), var(--wood-edge) 30%, var(--wood) 65%, var(--wood-dark)) right top / var(--side) 100% no-repeat,
    var(--back);
}

.compartment {
  position: relative;
  padding-top: 10px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgb(0 0 0 / .45), transparent 34px),
    linear-gradient(90deg, rgb(0 0 0 / .35), transparent 16px, transparent calc(100% - 16px), rgb(0 0 0 / .35)),
    linear-gradient(90deg, rgb(255 255 255 / .02), rgb(255 255 255 / .05) 50%, rgb(255 255 255 / .02)),
    var(--back);
}
.bookcase .shelf-books { padding: 0 12px; }
.bookcase .board {
  height: 20px;
  border-radius: 0;
  box-shadow: 0 5px 7px -3px rgb(0 0 0 / .55);
}
.board-label {
  position: absolute;
  z-index: 3;
  top: 4px;
  left: 12px;
  height: 13px;
  padding: 0 6px;
  border-radius: 1px;
  font-size: 9.5px;
  line-height: 13px;
  color: #3B2E22;
  background: #ECE4D2;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .14), 0 1px 1px rgb(0 0 0 / .35);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.board-label--sum { left: auto; right: 12px; font-family: var(--font-serif); }
:root[data-theme="dark"] .board-label { background: #C9BFA9; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .board-label { background: #C9BFA9; }
}

.bookcase__plinth {
  height: 30px;
  margin: 0 -4px;
  border-radius: 0 0 2px 2px;
  background: linear-gradient(180deg, var(--wood-dark) 0 3px, var(--wood-edge) 3px 6px, var(--wood) 6px, var(--wood-dark));
  box-shadow: var(--shadow-board);
}

.bookcase .shelf-empty { color: rgb(255 240 220 / .6); margin-bottom: 70px; }

/* Stempel mit App- und Besitzername als Überschrift des Regals */
.owner-stamp {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-3) var(--sp-5) var(--sp-3);
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink);
  outline-offset: 3px;
  border-radius: 6px;
  font-family: var(--font-serif);
  line-height: 1.1;
  margin: 4px;
}
.owner-stamp__brand { font-style: italic; font-size: var(--fs-sm); color: var(--ink-muted); letter-spacing: .04em; }
.owner-stamp__name { font-size: var(--fs-xl); font-weight: 450; letter-spacing: -0.01em; }
.owner-stamp__orn { width: 46px; height: 8px; color: var(--brass); margin-top: 4px; }

/* ---------- Buch in Arbeit (Fokus) ---------- */

.wip-book {
  --scale-h: 2.15;
  --scale-w: 2.8;
  position: relative;
  width: max(34px, calc(var(--w) * var(--scale-w)));
  height: min(calc(var(--h) * var(--scale-h)), 31vh);
  border-radius: 4px 4px 2px 2px;
  background: color-mix(in srgb, var(--c) 26%, var(--paper));
  box-shadow: 1px 0 0 rgb(0 0 0 / .12), 0 2px 6px rgb(0 0 0 / .14);
  overflow: hidden;
  transform-origin: bottom left;
}
.wip-book__fill {
  position: absolute;
  inset: 0;
  background-color: var(--c);
  transform-origin: bottom center;
  transform: scaleY(var(--p, 0));
}
.wip-book__shade {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(90deg, rgb(0 0 0 / .26) 0%, rgb(0 0 0 / .05) 16%, rgb(255 255 255 / .12) 40%, rgb(255 255 255 / .05) 58%, rgb(0 0 0 / .08) 80%, rgb(0 0 0 / .28) 100%),
    repeating-linear-gradient(0deg, rgb(255 255 255 / .03) 0 1px, transparent 1px 3px);
  pointer-events: none;
}
.wip-book__band { position: absolute; left: 0; right: 0; height: 1px; background: rgb(0 0 0 / .2); box-shadow: 0 1px 0 rgb(255 255 255 / .1); }
.wip-book__band--top { top: 9%; }
.wip-book__band--bottom { bottom: 9%; }
.wip-book.is-notebook .wip-book__band { display: none; }
/* Im großen Buch in Arbeit: weiche Bünde statt harter Linien, höheres Rückenschild */
.wip-book .book__bands {
  --band: linear-gradient(180deg, rgb(0 0 0 / .2), rgb(255 255 255 / .2) 35%, rgb(255 255 255 / .07) 65%, rgb(0 0 0 / .24));
  background-size: 100% 8px;
}
.wip-book .book__label { left: 8px; right: 8px; top: calc(17% + 12px); height: calc(16.5% - 20px); border-radius: 2px; }
.wip-book.is-idle { opacity: .85; }
.wip-book.is-torn {
  filter: saturate(.35);
  clip-path: polygon(0 14px, 12% 4px, 26% 18px, 40% 6px, 55% 20px, 68% 4px, 82% 16px, 100% 6px, 100% 100%, 0 100%);
  transform: rotate(-12deg);
  transition: transform 400ms var(--ease-out), filter 400ms ease;
}

/* ---------- Tagesziel als Regalbrett ---------- */

.goal { display: flex; align-items: flex-end; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--ink-muted); }
.goal__shelf { width: 220px; display: flex; flex-direction: column; }
.goal__books { display: flex; align-items: flex-end; gap: 1px; height: 24px; padding: 0 3px; overflow: hidden; }
.goal__books i {
  display: block;
  flex: none;
  min-width: 3px;
  border-radius: 1px 1px 0 0;
  background-color: var(--c);
  background-image: linear-gradient(90deg, rgb(0 0 0 / .25), rgb(255 255 255 / .1) 45%, rgb(0 0 0 / .25));
}
.goal__board { height: 4px; border-radius: 1px; background: linear-gradient(180deg, var(--wood-edge) 0 1px, var(--wood) 1px); }
.goal__board.is-reached { box-shadow: 0 0 0 1px var(--brass); }
.goal__value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.goal__value strong { color: var(--ink); font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  .shelf .book:hover, .shelf .book:focus-visible { transform: none; }
  .shelf .book.is-torn:hover, .shelf .book.is-torn:focus-visible { transform: rotate(-4deg); }
}

/* Im Bücherregal liegt das Licht auf dunklem Holz: immer aufhellen */
.shelf .bookcase .lamp-glow {
  mix-blend-mode: screen;
  --glow: radial-gradient(closest-side, rgb(255 206 135 / .38), rgb(255 192 115 / .14) 55%, transparent);
}
