:root {
  --paper: #fffdf8;
  --ink: #332d28;
  --warm: #f7ead8;
  --panel: #fff8ec;
  --line: rgba(92, 67, 39, 0.22);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background: radial-gradient(circle at 50% 12%, #fbf5eb 0%, #ecdfcf 42%, #cab7a2 100%);
  overflow: hidden;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(115deg, rgba(255,255,255,.2) 0 1px, transparent 1px);
  background-size: 5px 16px;
  opacity: .20;
  animation: rain 1.8s linear infinite;
}
@keyframes rain { from { background-position: 0 0; } to { background-position: -80px 220px; } }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 330px 1fr;
  transition: grid-template-columns .32s ease;
}
.app.sidebar-closed { grid-template-columns: 0 1fr; }

.sidebar {
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #fffaf1, #f2e2cc);
  border-right: 1px solid rgba(80,55,28,.18);
  box-shadow: 8px 0 24px rgba(56,38,20,.16);
  z-index: 80;
  transition: opacity .25s ease, transform .32s ease;
}
.app.sidebar-closed .sidebar { opacity: 0; pointer-events: none; }
.side-inner { width: 330px; height: 100%; padding: 22px 18px; overflow: auto; }
.brand { font-size: 30px; letter-spacing: .04em; margin: 0 0 3px; }
.subtitle { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: #806b54; margin: 0 0 18px; }
.side-actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.mini {
  border: 1px solid rgba(92,67,39,.25);
  background: #fff8ec;
  border-radius: 999px;
  padding: 8px 11px;
  font-size: 12px;
  cursor: pointer;
  color: #5b4939;
}
.mini:hover { background: #fff; }
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: #8a6d48;
  border-top: 1px solid rgba(106,80,48,.18);
  padding-top: 15px;
  margin: 18px 0 10px;
}
.toc-list, .bookmark-list { display: flex; flex-direction: column; gap: 6px; }
.toc-item, .bookmark-item {
  border: 0;
  background: rgba(255,255,255,.65);
  text-align: left;
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  font-family: inherit;
  color: #40372f;
  box-shadow: inset 0 0 0 1px rgba(120,88,52,.08);
}
.toc-item:hover, .bookmark-item:hover { background: #fff; }
.toc-item small, .bookmark-item small { display: block; font-size: 10px; color: #8a735b; margin-top: 2px; }
.empty { font-size: 13px; color: #8c7c6a; font-style: italic; line-height: 1.45; }

.stage {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 28px 26px;
  overflow: hidden;
}
.toolbar {
  position: absolute;
  top: 16px;
  left: 22px;
  right: 22px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 120;
  pointer-events: none;
}
.toolbar button, .toolbar .pill { pointer-events: auto; }
.tool-left, .tool-right { display: flex; align-items: center; gap: 10px; }
.btn {
  border: 1px solid rgba(83,60,36,.22);
  background: rgba(255,250,241,.9);
  backdrop-filter: blur(8px);
  color: #47392c;
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: 0 8px 20px rgba(65,42,22,.12);
  cursor: pointer;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 14px;
  white-space: nowrap;
}
.btn:hover { background: white; transform: translateY(-1px); }
.btn.bookmark-btn { padding: 10px 16px; background: linear-gradient(180deg, #fff4df, #f7dfb0); border-color: rgba(159,112,45,.35); }
.pill { font-size: 13px; background: rgba(255,250,242,.78); border-radius: 999px; padding: 9px 13px; color: #705b45; border: 1px solid rgba(100,72,44,.14); }

.book-wrap {
  position: relative;
  margin-top: 44px;
  filter: drop-shadow(0 22px 34px rgba(45,30,15,.28));
  transition: transform .25s ease;
}
.book-shadow { position: absolute; left: 4%; right: 4%; bottom: -22px; height: 32px; background: radial-gradient(ellipse at center, rgba(44,31,20,.38), transparent 70%); filter: blur(9px); z-index: 0; }
.flipbook { position: relative; z-index: 1; touch-action: pan-y; }
.flipbook .page {
  background: var(--paper);
  overflow: hidden;
  box-shadow: inset 0 0 18px rgba(70,48,26,.08);
  position: relative;
}
.flipbook .page::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgba(0,0,0,.13), transparent 10%, transparent 90%, rgba(0,0,0,.08)); opacity: .25; z-index: 2; }
.page img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; -webkit-user-drag: none; }

.live-bookmark {
  position: absolute;
  top: -3.5%;
  right: 4.5%;
  width: 25%;
  max-width: 150px;
  min-width: 70px;
  z-index: 18;
  filter: drop-shadow(0 12px 12px rgba(24,16,10,.36));
  transform-origin: top center;
  animation: bookmarkDrop .46s cubic-bezier(.2,.86,.2,1.05);
}
.page:nth-child(even) .live-bookmark { left: 4.5%; right: auto; }
@keyframes bookmarkDrop { from { transform: translateY(-28px) rotate(-2deg); opacity: 0; } to { transform: translateY(0) rotate(0); opacity: 1; } }

.controls { position: absolute; inset: 0; pointer-events: none; }
.nav-zone { position: absolute; top: 90px; bottom: 70px; width: 20%; pointer-events: auto; cursor: pointer; }
.nav-zone.left { left: 0; }
.nav-zone.right { right: 0; }
.edge-tab { position: absolute; top: 50%; transform: translateY(-50%); z-index: 55; border: 0; background: rgba(255,250,241,.78); box-shadow: 0 8px 22px rgba(64,42,24,.18); width: 42px; height: 86px; cursor: pointer; color: #6a553d; font-size: 22px; }
.edge-tab.prev { left: 14px; border-radius: 0 18px 18px 0; }
.edge-tab.next { right: 14px; border-radius: 18px 0 0 18px; }
.hint { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); font-size: 13px; color: rgba(69,50,32,.62); background: rgba(255,250,242,.6); border: 1px solid rgba(111,82,50,.12); padding: 8px 12px; border-radius: 999px; z-index: 40; }

/* Mobile and narrow screens: force real single-page Turn.js mode while keeping corner curl. */
@media (max-width: 980px), (max-height: 680px) {
  body { overflow: hidden; }
  .app { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 330px);
    opacity: 0;
    pointer-events: none;
    transform: translateX(-105%);
  }
  .app.sidebar-open-mobile .sidebar { opacity: 1; pointer-events: auto; transform: translateX(0); }
  .app.sidebar-open-mobile::after { content: ''; position: fixed; inset: 0; background: rgba(45,30,15,.28); z-index: 70; }
  .side-inner { width: min(86vw, 330px); }
  .stage { width: 100vw; height: 100dvh; padding: 58px 10px 16px; justify-content: center; }
  .toolbar { top: 8px; left: 8px; right: 8px; min-height: 42px; gap: 6px; }
  .tool-left, .tool-right { gap: 6px; }
  .btn { padding: 8px 9px; font-size: 12px; box-shadow: 0 5px 14px rgba(65,42,22,.10); }
  #prevBtn, #nextBtn { display: none; }
  .pill { display: none; }
  .book-wrap { margin-top: 0; transform: translateY(3px); }
  .edge-tab { width: 34px; height: 64px; font-size: 20px; background: rgba(255,250,241,.7); }
  .edge-tab.prev { left: 0; }
  .edge-tab.next { right: 0; }
  .nav-zone { top: 56px; bottom: 28px; width: 18%; }
  .hint { display: none; }
  .live-bookmark { width: 24%; min-width: 58px; max-width: 110px; }
  .flipbook .page::before { background: linear-gradient(90deg, rgba(0,0,0,.08), transparent 13%, transparent 88%, rgba(0,0,0,.11)); opacity: .22; }
}

@media (max-width: 420px) {
  .stage { padding-left: 6px; padding-right: 6px; }
  #bookmarkBtn { max-width: 126px; overflow: hidden; text-overflow: ellipsis; }
  .btn { font-size: 11px; padding: 8px 8px; }
  .edge-tab { width: 30px; height: 58px; }
}
