:root {
  --bg: #f7f3ec;
  --panel: #fffaf1;
  --ink: #24170f;
  --muted: #7d6c5d;
  --line: rgba(54, 34, 19, 0.14);
  --wood: #7b4a2d;
  --wood-dark: #4a2a18;
  --accent: #8d4b2f;
  --accent-2: #d7a86e;
  --shadow: 0 24px 70px rgba(65, 40, 21, 0.15);
  --radius: 24px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff7e8, var(--bg));
  color: var(--ink);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 320px 1fr; min-height: 100vh; }
.sidebar {
  padding: 28px;
  background: linear-gradient(180deg, #fffaf0, #efe1cf);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 28px; }
.logo {
  width: 54px; height: 54px; border-radius: 18px;
  display: grid; place-items: center;
  color: white; font-weight: 900; font-size: 28px;
  background: linear-gradient(135deg, #3b2214, #b97945);
  box-shadow: var(--shadow);
}
h1, h2, h3, p { margin: 0; }
.brand h1 { font-size: 24px; letter-spacing: -0.04em; }
.brand p, .topbar p, .muted { color: var(--muted); }
.primary-btn, .ghost-btn, .danger-btn {
  border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 700;
}
.primary-btn { background: var(--ink); color: white; width: 100%; box-shadow: var(--shadow); }
.ghost-btn { background: rgba(255,255,255,0.65); color: var(--ink); border: 1px solid var(--line); }
.danger-btn { background: #3a1712; color: white; }
.drop-zone {
  margin: 18px 0 24px; padding: 22px;
  border: 2px dashed rgba(74,42,24,0.25);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.45);
  display: grid; gap: 6px; color: var(--muted);
}
.drop-zone.dragover { background: white; border-color: var(--accent); }
.category-list { display: grid; gap: 8px; }
.category-btn {
  width: 100%; text-align: left; padding: 12px 14px; border-radius: 14px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
}
.category-btn.active, .category-btn:hover { background: rgba(255,255,255,0.75); border-color: var(--line); color: var(--ink); }
.storage-card {
  margin-top: 28px; padding: 16px; border: 1px solid var(--line); border-radius: 18px;
  display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,0.55);
}
.main { padding: 34px; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: center; margin-bottom: 24px; }
.topbar h2 { font-size: 40px; letter-spacing: -0.06em; }
.search-box { flex: 1; max-width: 520px; }
.search-box input, .modal input, .modal select {
  width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,0.8);
  outline: none;
}
.hero-card {
  display: flex; justify-content: space-between; align-items: center; gap: 30px;
  padding: 30px; border-radius: 30px;
  background: linear-gradient(135deg, #fffaf1, #ead4b8);
  box-shadow: var(--shadow); border: 1px solid rgba(255,255,255,0.7); margin-bottom: 30px;
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 12px; font-weight: 900; color: var(--accent); }
.hero-card h3 { max-width: 720px; font-size: 32px; line-height: 1.05; letter-spacing: -0.04em; margin: 8px 0 12px; }
.hero-card p { color: var(--muted); max-width: 700px; }
.hero-stack { display: flex; align-items: flex-end; gap: 8px; min-width: 130px; }
.hero-stack div { width: 34px; border-radius: 10px 10px 4px 4px; background: linear-gradient(180deg, #422414, #b47442); box-shadow: var(--shadow); }
.hero-stack div:nth-child(1) { height: 120px; transform: rotate(-4deg); }
.hero-stack div:nth-child(2) { height: 155px; background: linear-gradient(180deg, #1d2834, #6c91a9); }
.hero-stack div:nth-child(3) { height: 105px; background: linear-gradient(180deg, #4a1c1c, #c66a4d); transform: rotate(5deg); }
.empty-state { padding: 70px; text-align: center; border: 1px dashed var(--line); border-radius: 30px; color: var(--muted); }
.empty-state h3 { color: var(--ink); margin-bottom: 8px; }
.shelves { display: grid; gap: 36px; }
.shelf h3 { margin-bottom: 14px; }
.book-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px; align-items: end;
  padding: 26px 20px 36px; border-radius: 24px;
  background:
    linear-gradient(180deg, transparent 0 82%, rgba(80,43,22,0.22) 82% 100%),
    linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0.18));
  border: 1px solid var(--line);
}
.book-card { position: relative; display: grid; gap: 10px; justify-items: center; }
.book-cover {
  width: 128px; height: 178px; border: 0; padding: 0; border-radius: 8px 14px 14px 8px; overflow: hidden;
  background: #fff; box-shadow: 10px 16px 30px rgba(49,30,15,0.25), inset 8px 0 0 rgba(0,0,0,0.08);
  transform-origin: left; transition: transform 180ms ease, box-shadow 180ms ease;
}
.book-cover:hover { transform: translateY(-8px) rotate(-1deg); box-shadow: 14px 26px 42px rgba(49,30,15,0.32); }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-cover .fallback-cover { width: 100%; height: 100%; padding: 18px 10px; display: grid; place-items: center; background: linear-gradient(145deg, #3b2214, #c18a54); color: white; font-weight: 900; text-align: center; }
.book-title { font-weight: 800; text-align: center; font-size: 14px; max-width: 150px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-meta { font-size: 12px; color: var(--muted); text-align: center; }
.delete-book { position: absolute; top: -10px; right: 4px; width: 28px; height: 28px; border: 0; border-radius: 50%; background: #3b1712; color: white; opacity: 0; transition: opacity 150ms ease; }
.book-card:hover .delete-book { opacity: 1; }
.modal { border: 0; border-radius: 26px; box-shadow: var(--shadow); padding: 0; background: var(--panel); }
.modal::backdrop { background: rgba(28,18,12,0.5); backdrop-filter: blur(5px); }
.modal form { width: min(460px, 92vw); padding: 28px; display: grid; gap: 16px; }
.modal label { display: grid; gap: 8px; color: var(--muted); font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.reader-overlay { position: fixed; inset: 0; background: rgba(22,14,9,0.78); z-index: 20; padding: 24px; }
.reader-panel { height: 100%; display: grid; grid-template-rows: auto 1fr; gap: 16px; background: #eee0cf; border-radius: 28px; padding: 18px; box-shadow: var(--shadow); }
.reader-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; background: rgba(255,255,255,0.55); border-radius: 20px; padding: 14px 16px; }
.reader-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#pageIndicator { font-weight: 800; min-width: 110px; text-align: center; }
.book-reader { position: relative; display: grid; place-items: center; overflow: hidden; border-radius: 22px; background: radial-gradient(circle at center, #fff9ee, #b89670); }
.page-stage { display: flex; align-items: center; justify-content: center; gap: 6px; perspective: 1200px; max-width: 100%; max-height: 100%; }
.page-stage.flip { animation: flipPulse 260ms ease; }
@keyframes flipPulse { 0% { transform: rotateY(0deg) scale(1); } 50% { transform: rotateY(-4deg) scale(0.992); } 100% { transform: rotateY(0deg) scale(1); } }
.page-stage canvas { background: white; border-radius: 8px; box-shadow: 0 16px 45px rgba(34,21,12,0.32); max-width: 46vw; max-height: 72vh; }
.turn-hit { position: absolute; top: 0; bottom: 0; width: 22%; border: 0; background: transparent; }
.turn-hit.left { left: 0; }
.turn-hit.right { right: 0; }
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .topbar, .hero-card, .reader-header { flex-direction: column; align-items: stretch; }
  .page-stage { flex-direction: column; }
  .page-stage canvas { max-width: 88vw; max-height: 38vh; }
}
