:root {
  --ink: #181411;
  --muted: #766a5f;
  --paper: #f6efe2;
  --paper-deep: #e8dcc8;
  --brass: #b18a4a;
  --teal: #2f6f6d;
  --wine: #763842;
  --forest: #2e5141;
  --navy: #293f54;
  --clay: #7c5746;
  --sidebar: #151311;
  --sidebar-2: #25201b;
  --wood-dark: #2a2019;
  --wood-mid: #6d523b;
  --wood-light: #a07752;
  --shadow: rgba(16, 12, 9, 0.28);
  --radius: 8px;
  --sidebar-width: 312px;
  font-family: "Iowan Old Style", "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 252, 245, 0.94), rgba(229, 219, 204, 0.88) 46%, rgba(35, 28, 23, 0.96)),
    linear-gradient(135deg, #f7f1e8 0%, #d9c9b5 46%, #24201c 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 10;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #f4e9d1;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.055), transparent 18%),
    linear-gradient(180deg, rgba(177, 138, 74, 0.13), transparent 22%),
    linear-gradient(180deg, var(--sidebar-2), var(--sidebar));
  border-right: 1px solid rgba(255, 221, 165, 0.18);
  box-shadow: 18px 0 56px rgba(0, 0, 0, 0.18);
  transition: width 260ms ease, transform 260ms ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 16px;
  border-bottom: 1px solid rgba(255, 221, 165, 0.14);
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  color: inherit;
  background: rgba(255, 244, 214, 0.08);
  border: 1px solid rgba(255, 231, 176, 0.22);
  border-radius: 8px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 244, 214, 0.15);
  border-color: rgba(255, 231, 176, 0.4);
}

.mobile-sidebar-toggle {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 42px;
  flex: 0 0 auto;
  display: block;
  border-radius: 3px 6px 6px 3px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.2), transparent 24%, rgba(255, 255, 255, 0.12) 78%),
    linear-gradient(180deg, #d7bd7c, #866540);
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, 0.16), inset -3px 0 0 rgba(255, 255, 255, 0.14), 0 10px 24px rgba(0, 0, 0, 0.26);
}

.brand-copy {
  min-width: 0;
  line-height: 1.1;
}

.brand-copy strong,
.brand-copy small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-copy strong {
  font-size: 17px;
  letter-spacing: 0;
}

.brand-copy small {
  margin-top: 4px;
  color: rgba(244, 233, 209, 0.66);
  font-size: 12px;
}

.search-box {
  padding: 14px 16px 8px;
}

.search-box input {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  color: #fff3dc;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 231, 176, 0.18);
  border-radius: 8px;
  outline: none;
}

.search-box input::placeholder {
  color: rgba(244, 233, 209, 0.5);
}

.search-box input:focus {
  border-color: rgba(213, 172, 88, 0.75);
  box-shadow: 0 0 0 3px rgba(180, 138, 59, 0.18);
}

.library-tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px 10px 18px;
}

.tree-book {
  margin: 4px 0;
}

.tree-book-button,
.tree-file-button,
.chapter-button {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.tree-book-button {
  min-height: 42px;
  padding: 9px 10px;
}

.tree-book-button:hover,
.tree-file-button:hover,
.chapter-button:hover {
  background: rgba(255, 244, 214, 0.08);
}

.tree-book-button.is-active {
  background: linear-gradient(90deg, rgba(180, 138, 59, 0.28), rgba(39, 95, 91, 0.12));
  box-shadow: inset 3px 0 0 var(--brass);
}

.tree-book-name,
.tree-file-name,
.chapter-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  margin-left: auto;
  color: rgba(244, 233, 209, 0.48);
  font-size: 12px;
  white-space: nowrap;
}

.tree-files {
  display: none;
  padding: 2px 0 8px 26px;
}

.tree-book.is-open .tree-files {
  display: block;
}

.tree-file-button {
  min-height: 32px;
  padding: 6px 8px;
  color: rgba(244, 233, 209, 0.78);
  font-size: 13px;
}

.tree-file-button.is-active {
  color: #fff7df;
  background: rgba(39, 95, 91, 0.24);
}

.sidebar-footer {
  padding: 12px 16px 16px;
  color: rgba(244, 233, 209, 0.58);
  border-top: 1px solid rgba(255, 221, 165, 0.12);
  font-size: 12px;
}

.main-stage {
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.shelf-view {
  position: relative;
  isolation: isolate;
  height: 100%;
  overflow: auto;
  padding: clamp(24px, 4vw, 56px);
  background:
    linear-gradient(180deg, rgba(250, 246, 237, 0.94) 0%, rgba(232, 223, 209, 0.9) 48%, rgba(49, 40, 34, 0.88) 100%),
    linear-gradient(135deg, #fbf6ed 0%, #d8c8b5 54%, #261f1a 100%);
}

.shelf-view::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.24), transparent 26%, rgba(30, 24, 20, 0.08) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), transparent 34%, rgba(18, 14, 11, 0.24) 100%);
  opacity: 0.68;
}

.room-light {
  position: fixed;
  inset: 0 0 auto var(--sidebar-width);
  height: 44vh;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 246, 224, 0.58), rgba(255, 246, 224, 0.18) 46%, transparent);
}

.shelf-header {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin-bottom: 30px;
  color: #211b16;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.36);
}

.eyebrow {
  margin: 0 0 8px;
  color: #8a6635;
  font-size: 12px;
  font-family: "Gill Sans", "Avenir Next", sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.shelf-header h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 86px);
  line-height: 0.95;
  letter-spacing: 0;
}

.shelf-meta {
  margin: 12px 0 0;
  color: rgba(33, 27, 22, 0.64);
  font-size: 15px;
}

.bookshelf {
  position: relative;
  z-index: 1;
  display: grid;
  gap: clamp(26px, 4vw, 42px);
  max-width: 1180px;
  padding-bottom: 40px;
}

.shelf-board {
  position: relative;
  min-height: 252px;
  display: flex;
  align-items: flex-end;
  gap: clamp(12px, 2vw, 22px);
  padding: 22px clamp(18px, 3vw, 34px) 34px;
  border-radius: 8px;
  perspective: 1050px;
  transform-style: preserve-3d;
  background:
    linear-gradient(90deg, rgba(36, 27, 21, 0.58) 0 18px, transparent 18px calc(100% - 18px), rgba(28, 22, 18, 0.46) calc(100% - 18px)),
    linear-gradient(180deg, rgba(255, 246, 222, 0.2), transparent 38%),
    linear-gradient(90deg, #362820, #806246 45%, #382a21);
  border: 1px solid rgba(255, 246, 224, 0.12);
  box-shadow:
    inset 0 18px 28px rgba(255, 255, 255, 0.08),
    inset 0 -20px 34px rgba(31, 22, 17, 0.52),
    0 26px 56px rgba(37, 28, 21, 0.24);
}

.shelf-board::before {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 30px;
  height: 52px;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(0, 0, 0, 0.34), transparent 66%),
    linear-gradient(180deg, transparent, rgba(31, 22, 17, 0.3));
}

.shelf-board::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30px;
  border-radius: 0 0 8px 8px;
  background:
    linear-gradient(180deg, rgba(255, 241, 211, 0.24), rgba(36, 27, 21, 0.76)),
    linear-gradient(90deg, var(--wood-dark), var(--wood-light), var(--wood-dark));
  box-shadow: 0 14px 22px rgba(25, 18, 14, 0.3);
}

.book {
  --book-color: var(--forest);
  --book-height: 196px;
  --hover-x: 50%;
  --tilt-y: 0deg;
  position: relative;
  z-index: 1;
  width: clamp(64px, 8vw, 92px);
  height: var(--book-height);
  padding: 0;
  color: #fff6df;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.46) 0 10px, rgba(255, 255, 255, 0.1) 10px 12px, transparent 12px 78%, rgba(0, 0, 0, 0.22) 100%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 42%),
    linear-gradient(180deg, color-mix(in srgb, var(--book-color), #ffffff 12%), color-mix(in srgb, var(--book-color), #000000 10%));
  border: 1px solid rgba(255, 244, 214, 0.22);
  border-radius: 4px 7px 7px 4px;
  box-shadow:
    inset 7px 0 0 rgba(0, 0, 0, 0.2),
    inset -4px 0 0 rgba(255, 255, 255, 0.07),
    10px 0 18px rgba(0, 0, 0, 0.17),
    0 0 0 1px rgba(0, 0, 0, 0.08);
  transform-origin: left bottom;
  transform-style: preserve-3d;
  will-change: transform, filter;
  transition:
    transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 220ms ease,
    box-shadow 260ms ease;
}

.book::before,
.book::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.book::before {
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.14), transparent 24% 74%, rgba(0, 0, 0, 0.2)),
    linear-gradient(180deg, rgba(255, 249, 229, 0.14), transparent 28%);
  opacity: 0.2;
  transition: opacity 220ms ease;
}

.book::after {
  top: 12px;
  right: 8px;
  bottom: 12px;
  width: 1px;
  border-radius: 999px;
  background: linear-gradient(180deg, transparent, rgba(255, 238, 190, 0.48), transparent);
  opacity: 0.28;
  transform: none;
  transition: opacity 220ms ease;
}

.book:hover,
.book.is-active {
  filter: saturate(1.15) brightness(1.06);
  transform: translate3d(0, -18px, 30px) rotate(-1.6deg) rotateY(var(--tilt-y));
  box-shadow:
    inset 7px 0 0 rgba(0, 0, 0, 0.2),
    inset -4px 0 0 rgba(255, 255, 255, 0.08),
    16px 24px 34px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(255, 232, 170, 0.2);
}

.book:hover::before,
.book.is-active::before {
  opacity: 0.34;
}

.book:hover::after,
.book.is-active::after {
  opacity: 0.58;
}

.book:focus-visible {
  outline: 2px solid rgba(244, 214, 142, 0.9);
  outline-offset: 6px;
}

.book.is-opening {
  animation: pullBook 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.book.is-returning {
  animation: returnBook 780ms cubic-bezier(0.17, 0.78, 0.28, 1) both;
}

.book-spine {
  position: relative;
  z-index: 2;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 18px 10px 15px;
  gap: 10px;
}

.book-spine::before,
.book-spine::after {
  content: "";
  position: absolute;
  left: 13px;
  right: 11px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 231, 172, 0.42), transparent);
}

.book-spine::before {
  top: 18px;
}

.book-spine::after {
  bottom: 25px;
}

.book-title {
  max-height: calc(var(--book-height) - 66px);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  overflow: hidden;
  color: #fff7df;
  font-weight: 700;
  font-size: clamp(13px, 1.7vw, 16px);
  line-height: 1.12;
  letter-spacing: 0;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.22), 0 8px 18px rgba(0, 0, 0, 0.24);
}

.book-meta {
  max-width: 100%;
  padding: 2px 7px;
  color: rgba(255, 246, 223, 0.86);
  background: rgba(13, 10, 8, 0.18);
  border: 1px solid rgba(255, 238, 182, 0.22);
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.reader-view {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: clamp(12px, 2.8vw, 32px);
  pointer-events: none;
  opacity: 0;
  perspective: 1600px;
  transition: opacity 160ms ease;
}

.reader-view.is-active {
  pointer-events: auto;
  opacity: 1;
}

.reader-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 54% 0%, rgba(255, 229, 173, 0.32), transparent 36rem),
    rgba(19, 12, 8, 0.78);
  backdrop-filter: blur(4px);
  opacity: 0;
}

.reader-view.is-active .reader-backdrop {
  animation: readerFogIn 360ms ease both;
}

.reader-view.is-closing .reader-backdrop {
  animation: readerFogOut 740ms ease both;
}

.reader-book {
  position: relative;
  width: min(1180px, 100%);
  height: min(880px, calc(100vh - 28px));
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(79, 43, 24, 0.7) 0 9px, transparent 9px 100%),
    var(--paper);
  border: 1px solid rgba(255, 241, 205, 0.5);
  border-radius: 8px;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.46),
    inset 12px 0 28px rgba(78, 44, 24, 0.18);
  transform-origin: left center;
  transform-style: preserve-3d;
  isolation: isolate;
}

.reader-view.is-active .reader-book {
  animation: openBook 720ms cubic-bezier(0.18, 0.86, 0.25, 1) both;
}

.reader-view.is-closing .reader-book {
  animation: closeBook 760ms cubic-bezier(0.62, 0, 0.38, 1) both;
}

.reader-book::before,
.reader-book::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.reader-book::before {
  inset: 0;
  z-index: 6;
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(17, 9, 4, 0.62) 0 12px, rgba(255, 235, 176, 0.18) 12px 16px, transparent 16px 100%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 34%),
    linear-gradient(135deg, #5c2f1a, #8b542e 42%, #2b160c);
  box-shadow:
    inset 0 0 0 1px rgba(255, 232, 174, 0.22),
    inset 22px 0 30px rgba(0, 0, 0, 0.26),
    28px 0 42px rgba(0, 0, 0, 0.34);
  transform-origin: left center;
  backface-visibility: hidden;
}

.reader-book::after {
  top: 82px;
  right: 16px;
  bottom: 18px;
  z-index: 3;
  width: 28px;
  border-radius: 0 7px 7px 0;
  background:
    linear-gradient(90deg, rgba(147, 108, 63, 0.18), rgba(255, 249, 230, 0.42), rgba(92, 56, 30, 0.15));
  opacity: 0.65;
}

.reader-view.is-active .reader-book::before {
  animation: coverOpen 720ms cubic-bezier(0.17, 0.84, 0.24, 1) both;
}

.reader-view.is-closing .reader-book::before {
  animation: coverClose 740ms cubic-bezier(0.64, 0, 0.3, 1) both;
}

.reader-view.is-closing .reader-toolbar {
  animation: toolbarClose 520ms ease both;
}

.reader-view.is-closing .paper-layout {
  animation: pagesClose 700ms cubic-bezier(0.62, 0, 0.38, 1) both;
}

.reader-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(160px, 300px);
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 14px 18px;
  color: #f7ead0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06), transparent 40%),
    linear-gradient(180deg, #4b2a18, #2e1a10);
  border-bottom: 1px solid rgba(81, 45, 24, 0.32);
}

.back-button {
  font-size: 21px;
}

.reader-title {
  min-width: 0;
}

.reader-title strong,
.reader-title small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-title strong {
  font-size: 18px;
}

.reader-title small {
  margin-top: 4px;
  color: rgba(247, 234, 208, 0.64);
  font-size: 12px;
}

#filePicker {
  width: 100%;
  min-height: 40px;
  color: #211a15;
  background: #f7ecd2;
  border: 1px solid rgba(100, 60, 34, 0.32);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}

.paper-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(190px, 260px) 1fr;
  background:
    radial-gradient(circle at 22% 14%, rgba(255, 255, 255, 0.44), transparent 22rem),
    var(--paper);
}

.chapter-rail {
  min-width: 0;
  overflow: auto;
  padding: 16px 12px;
  background:
    linear-gradient(90deg, rgba(107, 71, 39, 0.12), transparent),
    rgba(211, 190, 151, 0.26);
  border-right: 1px solid rgba(105, 72, 42, 0.18);
}

.chapter-button {
  min-height: 36px;
  padding: 7px 9px;
  color: #4f3a2b;
  font-size: 13px;
}

.chapter-button.is-active {
  color: #19110c;
  background: rgba(180, 138, 59, 0.24);
  box-shadow: inset 3px 0 0 var(--teal);
}

.paper {
  min-width: 0;
  overflow: auto;
  padding: clamp(28px, 5vw, 72px);
  color: #1d1712;
  background:
    linear-gradient(90deg, rgba(94, 58, 31, 0.06), transparent 24px),
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.38), transparent 24rem),
    var(--paper);
  font-size: 17px;
  line-height: 1.78;
}

.paper h1,
.paper h2,
.paper h3,
.paper h4,
.paper h5,
.paper h6 {
  margin: 1.45em 0 0.55em;
  line-height: 1.25;
  letter-spacing: 0;
}

.paper h1:first-child,
.paper h2:first-child,
.paper h3:first-child {
  margin-top: 0;
}

.paper h1 {
  font-size: clamp(30px, 5vw, 52px);
}

.paper h2 {
  font-size: clamp(24px, 3.2vw, 36px);
  border-bottom: 1px solid rgba(105, 72, 42, 0.18);
  padding-bottom: 0.28em;
}

.paper h3 {
  color: #4a2c1c;
  font-size: clamp(20px, 2.4vw, 28px);
}

.paper p,
.paper ul,
.paper ol,
.paper blockquote,
.paper pre,
.paper table {
  margin: 0 0 1.05em;
}

.paper a {
  color: #245a56;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.paper code {
  padding: 0.15em 0.35em;
  color: #412716;
  background: rgba(117, 88, 51, 0.13);
  border-radius: 4px;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.paper pre {
  overflow: auto;
  padding: 16px;
  color: #f5ead3;
  background: #231914;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 236, 190, 0.08);
}

.paper pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  border-radius: 0;
}

.paper blockquote {
  padding: 0.2em 0 0.2em 1em;
  color: #5d493a;
  border-left: 4px solid rgba(180, 138, 59, 0.55);
}

.paper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94em;
}

.paper th,
.paper td {
  padding: 8px 10px;
  border: 1px solid rgba(94, 58, 31, 0.2);
  vertical-align: top;
}

.paper th {
  background: rgba(180, 138, 59, 0.16);
}

.paper iframe {
  width: 100%;
  min-height: 68vh;
  border: 1px solid rgba(94, 58, 31, 0.24);
  border-radius: 8px;
  background: white;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: rgba(255, 246, 223, 0.72);
  border: 1px dashed rgba(255, 231, 176, 0.26);
  border-radius: 8px;
}

.sidebar-collapsed .app-shell {
  grid-template-columns: 66px 1fr;
}

.sidebar-collapsed .sidebar {
  width: 66px;
}

.sidebar-collapsed .brand-copy,
.sidebar-collapsed .search-box,
.sidebar-collapsed .tree-files,
.sidebar-collapsed .tree-count,
.sidebar-collapsed .sidebar-footer {
  display: none;
}

.sidebar-collapsed .sidebar-header {
  justify-content: center;
  padding: 14px 8px;
}

.sidebar-collapsed .brand {
  display: none;
}

.sidebar-collapsed .library-tree {
  padding: 8px;
}

.sidebar-collapsed .tree-book-button {
  justify-content: center;
  padding: 10px 6px;
}

.sidebar-collapsed .tree-book-name {
  width: 28px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: normal;
  font-size: 12px;
  line-height: 1.1;
}

.sidebar-collapsed .room-light {
  left: 66px;
}

@keyframes pullBook {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
  }
  38% {
    transform: translate3d(12px, -30px, 46px) rotate(-8deg) rotateY(-10deg) scale(1.04);
  }
  72% {
    transform: translate3d(28px, -18px, 68px) rotate(-4deg) rotateY(-18deg) scale(1.02);
  }
  100% {
    transform: translate3d(8px, -10px, 24px) rotate(-2deg) rotateY(-6deg) scale(1);
  }
}

@keyframes returnBook {
  0% {
    transform: translate3d(34px, -24px, 72px) rotate(-5deg) rotateY(-22deg) scale(1.03);
    filter: saturate(1.2) brightness(1.1);
  }
  55% {
    transform: translate3d(12px, -10px, 28px) rotate(-2deg) rotateY(-8deg) scale(1);
  }
  100% {
    transform: translate3d(0, 0, 0) rotate(0deg) rotateY(0deg) scale(1);
    filter: saturate(1) brightness(1);
  }
}

@keyframes openBook {
  0% {
    opacity: 0;
    transform: rotateY(-68deg) translateX(-78px) translateY(10px) scale(0.86);
  }
  58% {
    opacity: 1;
    transform: rotateY(-12deg) translateX(-10px) translateY(0) scale(1.015);
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg) translateX(0) translateY(0) scale(1);
  }
}

@keyframes closeBook {
  0% {
    opacity: 1;
    transform: rotateY(0deg) translateX(0) translateY(0) scale(1);
  }
  46% {
    opacity: 1;
    transform: rotateY(-18deg) translateX(-12px) translateY(2px) scale(0.985);
  }
  78% {
    opacity: 0.82;
    transform: rotateY(-58deg) translateX(-62px) translateY(8px) scale(0.88);
  }
  100% {
    opacity: 0;
    transform: rotateY(-82deg) translateX(-112px) translateY(14px) scale(0.72);
  }
}

@keyframes coverOpen {
  0% {
    opacity: 1;
    transform: rotateY(0deg) translateX(0);
  }
  70% {
    opacity: 0.92;
    transform: rotateY(-112deg) translateX(-8px);
  }
  100% {
    opacity: 0;
    transform: rotateY(-118deg) translateX(-12px);
  }
}

@keyframes coverClose {
  0% {
    opacity: 0;
    transform: rotateY(-118deg) translateX(-12px);
  }
  42% {
    opacity: 0.96;
    transform: rotateY(-56deg) translateX(-4px);
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg) translateX(0);
  }
}

@keyframes pagesClose {
  0% {
    transform: translateX(0) scaleX(1);
    filter: brightness(1);
  }
  100% {
    transform: translateX(-10px) scaleX(0.94);
    filter: brightness(0.86);
  }
}

@keyframes toolbarClose {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0.45;
    transform: translateY(-8px);
  }
}

@keyframes readerFogIn {
  0% {
    opacity: 0;
    backdrop-filter: blur(0);
  }
  100% {
    opacity: 1;
    backdrop-filter: blur(4px);
  }
}

@keyframes readerFogOut {
  0% {
    opacity: 1;
    backdrop-filter: blur(4px);
  }
  100% {
    opacity: 0;
    backdrop-filter: blur(0);
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 260px 1fr;
  }

  .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  #filePicker {
    grid-column: 1 / -1;
  }

  .paper-layout {
    grid-template-columns: 1fr;
  }

  .chapter-rail {
    display: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(0);
  }

  .sidebar-collapsed .sidebar {
    width: min(88vw, 340px);
    left: -110vw;
    transform: none;
    box-shadow: none;
  }

  .mobile-sidebar-toggle {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 18;
    display: inline-grid;
    color: #f4e9d1;
    background: rgba(35, 22, 15, 0.86);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(8px);
  }

  body:not(.sidebar-collapsed) .mobile-sidebar-toggle {
    display: none;
  }

  .sidebar-collapsed .brand-copy,
  .sidebar-collapsed .search-box,
  .sidebar-collapsed .tree-count,
  .sidebar-collapsed .sidebar-footer {
    display: block;
  }

  .sidebar-collapsed .brand,
  .sidebar-collapsed .tree-files {
    display: flex;
  }

  .sidebar-collapsed .tree-book.is-open .tree-files {
    display: block;
  }

  .sidebar-collapsed .sidebar-header {
    justify-content: flex-start;
    padding: 16px;
  }

  .sidebar-collapsed .tree-book-name {
    width: auto;
    writing-mode: initial;
    white-space: nowrap;
    font-size: 14px;
  }

  .shelf-view {
    padding: 72px 16px 36px;
  }

  .reader-view {
    padding: 8px;
  }

  .reader-book {
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
  }

  .reader-book::after {
    display: none;
  }

  .paper {
    padding: 26px 20px;
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
