:root {
  --bg: #0c0a09;
  --text: #f5f0e8;
  --muted: #a89f91;
  --accent: #c0392b;
  --shelf-top: #6b2f1f;
  --shelf-face: #4a1f14;
  --shelf-edge: #2d120c;
  --shelf-shadow: rgba(0, 0, 0, 0.55);
  --panel-bg: rgba(18, 14, 12, 0.92);
  --glow: rgba(192, 57, 43, 0.25);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans KR", system-ui, sans-serif;
}
html {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(128, 76, 48, 0.28), transparent 68%),
    radial-gradient(circle at 15% 85%, rgba(173, 120, 66, 0.18), transparent 35%),
    linear-gradient(180deg, #17110f 0%, #090808 100%);
}

.ambient {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}
.ambient-a {
  width: 420px; height: 420px;
  top: -80px; left: 10%;
  background: var(--glow);
}
.ambient-b {
  width: 300px; height: 300px;
  bottom: 10%; right: 5%;
  background: rgba(255, 200, 100, 0.06);
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.6rem 1rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(18, 14, 12, 0.96), rgba(12, 10, 9, 0.88));
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  justify-content: center;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 150px;
  max-width: 220px;
  flex: 1 1 150px;
}
.search-wrap svg {
  width: 14px; height: 14px;
  fill: var(--muted);
  flex-shrink: 0;
}
.search-wrap input {
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  width: 100%;
  outline: none;
}
.search-wrap input::placeholder { color: var(--muted); }

.filter-select {
  padding: 0.4rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 0.7rem;
  max-width: 120px;
  outline: none;
  cursor: pointer;
}
.filter-select option {
  background: #1a1412;
  color: var(--text);
}

.skin-trigger {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
  transition: opacity 0.2s, transform 0.2s;
}
.skin-trigger:hover { transform: scale(1.04); }

.skin-picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.28rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  opacity: 0;
  width: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateX(8px);
  transition: width 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}
.skin-picker.open {
  opacity: 1;
  width: 192px;
  pointer-events: auto;
  transform: translateX(0);
}
.skin-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: var(--swatch);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}
.skin-btn:hover { transform: scale(1.1); }
.skin-btn.active {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);
}

.view-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 3px;
}
.view-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.view-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
.view-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s, transform 0.15s;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}
.icon-btn.small {
  width: 30px;
  height: 30px;
}
.icon-btn.small svg {
  width: 16px;
  height: 16px;
}
.icon-btn.active {
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 0 2px var(--accent);
}

.nav-arrow {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding-bottom: 2px;
  transition: background 0.2s, opacity 0.2s;
}
.nav-arrow:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}
.nav-arrow:disabled {
  opacity: 0.35;
  cursor: default;
}
.nav-arrow.light {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

.panel-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  padding-right: 1.5rem;
}
.panel-index {
  font-size: 0.82rem;
  color: var(--muted);
}

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4.5rem 0.5rem 2rem;
  min-height: calc(100vh - 74px);
}

.hint, .book-count {
  display: none;
}

.bookcase-viewport {
  width: min(100%, 100vw);
  height: auto;
  min-height: 520px;
  padding-top: 0.4rem;
  cursor: default;
  touch-action: pan-y;
  user-select: none;
  margin-top: 0.25rem;
}
.bookcase-viewport.dragging { cursor: grabbing; }
.bookcase-viewport.hidden { display: none; }

.bookcase-scene {
  width: 100%;
  height: 100%;
  perspective: none;
  perspective-origin: center;
}

.bookcase-frame {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: flat;
  transition: none;
  transform: none !important;
}

.bookcase-center {
  position: relative;
  z-index: 2;
}

.bookcase-crown,
.bookcase-base {
  width: 92%;
  margin: 0 auto;
  height: 18px;
  background: linear-gradient(180deg, var(--shelf-top), var(--shelf-face));
  border-radius: 4px 4px 0 0;
  box-shadow: 0 4px 12px var(--shelf-shadow);
}
.bookcase-base {
  border-radius: 0 0 6px 6px;
  height: 22px;
  margin-top: -2px;
}

.bookcase-body {
  position: relative;
  z-index: 2;
  width: 94%;
  margin: 0 auto;
  padding: 10px 18px 6px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.15) 0%, transparent 8%, transparent 92%, rgba(0,0,0,0.15) 100%),
    linear-gradient(180deg, var(--shelf-face), var(--shelf-edge));
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.35),
    0 20px 50px var(--shelf-shadow);
  border-left: 3px solid rgba(0, 0, 0, 0.3);
  border-right: 3px solid rgba(0, 0, 0, 0.3);
}

.shelf {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  justify-content: center;
  gap: 10px;
  min-height: 104px;
  padding: 12px 10px 16px;
  margin-bottom: 10px;
}
.shelf::after {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  bottom: 0;
  height: 14px;
  background: linear-gradient(180deg, var(--shelf-top), var(--shelf-face));
  border-radius: 3px;
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.45);
}
.shelf-bottom {
  min-height: 18px;
  padding-top: 8px;
  padding-bottom: 8px;
  margin-bottom: 0;
}
.shelf-bottom::after {
  height: 10px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.25);
}

.book {
  position: relative;
  flex-shrink: 0;
  transform-style: flat;
  cursor: pointer;
  transition: transform 0.25s ease, filter 0.25s, box-shadow 0.25s;
  transform: none;
  animation: bookIn 0.45s ease both;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.18));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.book.hidden-book { display: none; }

@keyframes bookIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.book:hover,
.book.focused {
  transform: translateY(-4px);
  filter: brightness(1.08) drop-shadow(0 16px 18px rgba(0, 0, 0, 0.22));
  z-index: 5;
}

.book-inner {
  position: relative;
  transform-style: flat;
}

.book-cover {
  display: block;
  object-fit: cover;
  border-radius: 2px 4px 4px 2px;
  box-shadow:
    2px 2px 6px rgba(0, 0, 0, 0.5),
    inset -2px 0 6px rgba(0, 0, 0, 0.15);
  backface-visibility: visible;
}

.book-spine,
.book-spine img,
.book-top,
.book-pages {
  display: none !important;
}

/* Grid view */
.grid-view {
  width: min(1100px, 96vw);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.25rem;
  padding: 0.5rem 0 1rem;
}
.grid-view.hidden { display: none; }

.grid-card {
  cursor: pointer;
  border-radius: 12px;
  padding: 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
  animation: bookIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.grid-card.hidden-book { display: none; }
.grid-card:hover,
.grid-card.focused {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.grid-cover {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 3/4;
  margin-bottom: 0.65rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.grid-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.grid-pages {
  position: absolute;
  right: 6px;
  bottom: 6px;
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
}

.grid-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.grid-card p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Skin themes */
body[data-skin="red"] {
  --accent: #c0392b;
  --shelf-top: #6b2f1f;
  --shelf-face: #4a1f14;
  --shelf-edge: #2d120c;
  --glow: rgba(192, 57, 43, 0.25);
}
body[data-skin="gold"] {
  --accent: #d4a017;
  --shelf-top: #8b6914;
  --shelf-face: #6b4f0f;
  --shelf-edge: #3d2c08;
  --glow: rgba(212, 160, 23, 0.22);
}
body[data-skin="silver"] {
  --accent: #9aa5b1;
  --shelf-top: #5a6068;
  --shelf-face: #3d4248;
  --shelf-edge: #252830;
  --glow: rgba(154, 165, 177, 0.18);
}
body[data-skin="green"] {
  --accent: #2ecc71;
  --shelf-top: #1e4d2b;
  --shelf-face: #14361e;
  --shelf-edge: #0a1f12;
  --glow: rgba(46, 204, 113, 0.15);
}
body[data-skin="yellow"] {
  --accent: #f1c40f;
  --shelf-top: #8b6914;
  --shelf-face: #6b5210;
  --shelf-edge: #3d3008;
  --glow: rgba(241, 196, 15, 0.18);
}

/* Detail panel */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 90;
  backdrop-filter: blur(4px);
  transition: opacity 0.3s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.book-panel {
  position: fixed;
  top: 50%;
  right: 2rem;
  transform: translateY(-50%);
  z-index: 100;
  width: min(360px, calc(100vw - 2rem));
  background: var(--panel-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
}
.book-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(40px);
}

.panel-close {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.panel-close:hover { color: var(--text); }

.panel-cover-wrap {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  margin-bottom: 1rem;
}
.panel-cover-wrap img {
  display: block;
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
}

.panel-info h2 {
  margin: 0 0 0.5rem;
  font-family: Cinzel, serif;
  font-size: 1.05rem;
  line-height: 1.35;
}
.panel-info p {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.panel-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
  font-size: 0.82rem;
}
.panel-meta dt {
  color: var(--muted);
  margin-bottom: 0.15rem;
}
.panel-meta dd { margin: 0; font-weight: 500; }

.panel-actions {
  display: grid;
  gap: 0.55rem;
}

.read-btn {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.2s, transform 0.15s;
}
.read-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.read-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* Reader modal */
.reader-modal {
  position: fixed;
  inset: 4% 3%;
  z-index: 110;
  display: flex;
  flex-direction: column;
  background: #111;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.reader-modal.hidden {
  display: none;
}

.reader-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.reader-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-family: Cinzel, serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.reader-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.reader-index {
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 2.5rem;
  text-align: center;
}
.reader-link {
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
}
.reader-link:hover { color: var(--text); }

.reader-body {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #1a1a1a;
}
.reader-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}
.reader-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
  color: var(--muted);
  font-size: 0.9rem;
  z-index: 2;
}
.reader-loading.hidden { display: none; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: rgba(20, 16, 14, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast.hidden { display: none; }

.loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(10, 8, 7, 0.92);
  backdrop-filter: blur(8px);
}
.loader.hidden { display: none; }
.loader p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.loader-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 115;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.help-modal.hidden {
  display: none;
}
.help-card {
  position: relative;
  width: min(420px, 100%);
  background: rgba(16, 12, 10, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.help-card h2 {
  margin: 0 0 1rem;
  font-family: Cinzel, serif;
  font-size: 1.15rem;
}
.help-list {
  display: grid;
  gap: 0.55rem;
  margin: 0 0 1rem;
}
.help-list div {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 0.75rem;
  font-size: 0.88rem;
}
.help-list dt {
  color: var(--accent);
  font-weight: 600;
}
.help-list dd {
  margin: 0;
  color: var(--muted);
}
.help-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.85rem;
}

/* Book list drawer */
.book-list-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(360px, 92vw);
  height: 100%;
  z-index: 105;
  background: rgba(14, 11, 10, 0.97);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
  transform: translateX(0);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.book-list-drawer.hidden {
  transform: translateX(-105%);
  pointer-events: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.drawer-header h2 {
  margin: 0;
  font-family: Cinzel, serif;
  font-size: 1.05rem;
}

.drawer-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
}
.drawer-list li { margin-bottom: 0.35rem; }
.drawer-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: background 0.2s, border-color 0.2s;
}
.drawer-list button:hover,
.drawer-list button.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
}
.drawer-list img {
  width: 42px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}
.drawer-list strong {
  display: block;
  font-size: 0.82rem;
  line-height: 1.3;
  margin-bottom: 0.15rem;
}
.drawer-list small {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book.focused {
  animation: pulseBook 0.6s ease;
}

@media (hover: none), (pointer: coarse) {
  .book,
  .book:hover,
  .book.focused {
    transform: none !important;
    filter: brightness(1.02) drop-shadow(0 10px 10px rgba(0, 0, 0, 0.18)) !important;
    animation: none !important;
    z-index: 1 !important;
  }
}

body.touch-device .book,
body.touch-device .book:hover,
body.touch-device .book.focused {
  transform: none !important;
  filter: brightness(1.02) drop-shadow(0 10px 10px rgba(0, 0, 0, 0.18)) !important;
  animation: none !important;
  z-index: 1 !important;
}

body.touch-device .book.focused {
  animation: none !important;
}

@media (hover: hover) and (pointer: fine) {
  .book.focused {
    animation: pulseBook 0.6s ease;
  }
}

@keyframes pulseBook {
  0%, 100% { filter: brightness(1.08); }
  50% { filter: brightness(1.25); }
}

/* Empty shelf */
.empty-shelf {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-shelf.hidden { display: none; }
.empty-shelf p { margin: 0 0 1rem; font-size: 1rem; }
.empty-shelf .read-btn { display: inline-block; width: auto; padding: 0.75rem 1.5rem; }

/* Admin */
.admin-entry { opacity: 0.7; }
.admin-entry:hover { opacity: 1; }

.admin-login {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
}
.admin-login.hidden { display: none; }
.admin-login-card {
  width: min(360px, 92vw);
  background: rgba(16, 12, 10, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
}
.admin-login-card h2 {
  margin: 0 0 0.5rem;
  font-family: Cinzel, serif;
}
.admin-login-card p {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.admin-login-card input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
}

.admin-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100%;
  z-index: 140;
  background: linear-gradient(180deg, rgba(20, 16, 14, 0.98), rgba(12, 10, 9, 0.99));
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.52);
}
.admin-panel.hidden { display: none; }

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.admin-header h2 {
  margin: 0;
  font-family: Cinzel, serif;
  font-size: 1.1rem;
}
.text-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  margin-right: 0.5rem;
}
.text-btn:hover { color: var(--text); }

/* Tabs Bar */
.admin-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab {
  flex: 1 1 0px;
  min-width: 0;
  padding: 0.65rem 0.35rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  text-align: center;
}
.admin-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}
.admin-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
}
@media (max-width: 480px) {
  .admin-tab span {
    display: none;
  }
}

.admin-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 2rem;
}

.admin-tab-content {
  display: none;
}
.admin-tab-content.active {
  display: block;
}

/* Folder Upload & Firebase Dropzone */
.folder-dropzone {
  border-color: rgba(52, 152, 219, 0.4);
  background: rgba(52, 152, 219, 0.04);
}
.folder-dropzone:hover,
.folder-dropzone.dragover {
  border-color: #3498db;
  background: rgba(52, 152, 219, 0.12);
}
.primary-file-btn {
  background: rgba(52, 152, 219, 0.15);
  border-color: rgba(52, 152, 219, 0.3);
  color: #3498db;
  width: 100%;
  text-align: center;
}
.primary-file-btn:hover {
  background: rgba(52, 152, 219, 0.25);
}

.folder-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(46, 204, 113, 0.18);
  border: 1px solid rgba(46, 204, 113, 0.35);
  color: #2ecc71;
  font-size: 0.76rem;
  font-weight: 600;
}
.folder-badge.hidden { display: none; }

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem !important;
  color: var(--text) !important;
  margin-top: 0.5rem;
}
.checkbox-label input[type="checkbox"] {
  width: auto !important;
  margin: 0 !important;
  cursor: pointer;
}

/* Progress bar */
.upload-progress-wrap {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.85rem;
}
.upload-progress-wrap.hidden { display: none; }
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #3498db, #2ecc71);
  transition: width 0.2s ease;
}

/* Firebase Status & Guide */
.firebase-status-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}
.firebase-status-card.connected {
  border-color: rgba(46, 204, 113, 0.3);
  background: rgba(46, 204, 113, 0.06);
  color: var(--text);
}
.firebase-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e74c3c;
  flex-shrink: 0;
}

.firebase-guide-box {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.78rem;
  color: var(--muted);
}
.firebase-guide-box h4 {
  margin: 0 0 0.5rem;
  color: var(--text);
  font-size: 0.85rem;
}
.firebase-guide-box p {
  margin: 0.35rem 0;
  line-height: 1.4;
}
.firebase-guide-box a {
  color: #3498db;
  text-decoration: none;
}
.firebase-guide-box a:hover {
  text-decoration: underline;
}

.admin-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.admin-section.highlight {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.admin-section h3 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
}
.admin-tip {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.admin-status {
  margin: 0.5rem 0;
  font-size: 0.78rem;
  color: var(--accent);
  min-height: 1.2em;
}
.admin-section label {
  display: block;
  margin-bottom: 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.admin-section input,
.admin-section textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}
.admin-section textarea { resize: vertical; min-height: 80px; }
.admin-section .read-btn { margin-top: 0.5rem; }

.admin-preview {
  display: flex;
  gap: 0.75rem;
  margin: 0.75rem 0;
}
.admin-preview img {
  width: 80px;
  height: 106px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}
.admin-preview .admin-fields {
  flex: 1;
  min-width: 0;
}
.admin-preview img.hidden { display: none; }

.admin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.file-btn {
  display: inline-block;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.file-btn:hover { filter: brightness(1.1); }
.danger-text { color: #e74c3c !important; }

.admin-book-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.admin-book-list li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.admin-book-list img {
  width: 40px;
  height: 52px;
  object-fit: cover;
  border-radius: 4px;
}
.admin-book-info strong {
  display: block;
  font-size: 0.82rem;
  line-height: 1.3;
}
.admin-book-info small {
  font-size: 0.68rem;
  color: var(--muted);
  word-break: break-all;
}
.admin-book-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.admin-book-actions button {
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.72rem;
  cursor: pointer;
}
.admin-book-actions button.danger {
  color: #e74c3c;
  border-color: rgba(231, 76, 60, 0.3);
}

.stage-shelf .bookcase-viewport {
  display: block;
}
.stage-shelf .grid-view {
  display: none;
}
.stage-shelf .grid-view:not(.hidden) {
  display: grid;
}
.stage-shelf .bookcase-viewport.hidden {
  display: none;
}

.cover-dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 0.75rem;
}
.cover-dropzone:hover,
.cover-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}
.dropzone-inner p {
  margin: 0.35rem 0 0.15rem;
  font-size: 0.88rem;
}
.dropzone-inner small {
  color: var(--muted);
  font-size: 0.72rem;
}
.dropzone-icon {
  font-size: 2rem;
}

.logo-upload-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.logo-upload-row input[type="text"] {
  flex: 1;
}
.file-btn.small-btn {
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  white-space: nowrap;
}
.logo-preview {
  display: block;
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 50%;
  margin-top: 0.5rem;
  border: 2px solid rgba(255, 255, 255, 0.15);
}
.logo-preview.hidden { display: none; }

.admin-section label small {
  color: var(--muted);
  font-weight: normal;
}

@media (max-width: 768px) {
  .top-bar {
    position: fixed;
    top: 0.4rem;
    left: 0.4rem;
    right: 0.4rem;
    width: calc(100% - 0.8rem);
    z-index: 100;
    padding: 0.35rem 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    background: rgba(15, 12, 11, 0.94);
    backdrop-filter: blur(12px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
    margin: 0;
  }

  .controls {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35rem;
    overflow: visible;
    padding: 0.04rem;
    position: relative;
    flex-wrap: wrap;
  }
  .controls::-webkit-scrollbar { display: none; }

  .library-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 1;
    visibility: visible;
    text-align: center;
    transition: opacity 0.2s ease, width 0.2s ease, visibility 0.2s ease;
  }

  .top-bar.expanded .library-name {
    opacity: 0;
    width: 0;
    visibility: hidden;
    overflow: hidden;
    pointer-events: none;
    margin: 0;
  }

  .mobile-tools-toggle {
    display: inline-flex;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-size: 1rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
  }

  .search-wrap,
  .filter-select,
  .view-toggle,
  .skin-picker,
  .icon-btn,
  .skin-trigger {
    background: rgba(10, 9, 11, 0.72);
    border-color: rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(10px);
  }

  .top-bar:not(.expanded) .search-wrap,
  .top-bar:not(.expanded) .filter-select,
  .top-bar:not(.expanded) .view-toggle,
  .top-bar:not(.expanded) .skin-picker,
  .top-bar:not(.expanded) .icon-btn,
  .top-bar:not(.expanded) .skin-trigger,
  .search-wrap,
  .filter-select,
  .view-toggle,
  .skin-picker,
  .icon-btn,
  .skin-trigger {
    opacity: 0;
    width: 0;
    min-width: 0;
    padding: 0;
    margin: 0;
    border: 0;
    pointer-events: none;
    overflow: hidden;
    visibility: hidden;
    transition: width 0.2s ease, opacity 0.2s ease, padding 0.2s ease, border 0.2s ease, visibility 0.2s ease;
  }

  .top-bar.expanded .search-wrap,
  .top-bar.expanded .filter-select,
  .top-bar.expanded .view-toggle,
  .top-bar.expanded .skin-picker,
  .top-bar.expanded .icon-btn,
  .top-bar.expanded .skin-trigger {
    opacity: 1;
    width: auto;
    min-width: 0;
    padding: 0.28rem 0.42rem;
    margin: 0;
    border-width: 1px;
    pointer-events: auto;
    overflow: visible;
    visibility: visible;
  }

  .top-bar.expanded .search-wrap {
    min-width: 120px;
    max-width: 180px;
    flex: 1 1 120px;
  }
  .top-bar.expanded .filter-select {
    max-width: 100px;
    min-width: 80px;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
  }
  .top-bar.expanded .view-toggle {
    padding: 2px;
    border-radius: 999px;
  }
  .top-bar.expanded .skin-picker {
    display: flex;
    width: auto;
    padding: 0.16rem 0.18rem;
    border-radius: 999px;
    background: rgba(14, 12, 11, 0.9);
  }
  .top-bar.expanded .icon-btn,
  .top-bar.expanded .skin-trigger {
    width: 26px;
    height: 26px;
    min-width: 26px;
    border-radius: 50%;
  }

  .search-wrap {
    flex: 1 1 100px;
    min-width: 0;
    padding: 0;
  }
  .search-wrap input {
    font-size: 0.68rem;
  }
  .filter-select {
    flex: 0 0 auto;
    max-width: 0;
    font-size: 0.62rem;
  }
  .view-toggle {
    padding: 0;
    border-radius: 999px;
    gap: 0;
    flex-shrink: 0;
  }
  .view-btn {
    padding: 0.12rem 0.18rem;
    font-size: 0.5rem;
    gap: 0.18rem;
  }
  .view-btn svg {
    width: 11px;
    height: 11px;
  }
  .skin-btn {
    width: 16px;
    height: 16px;
  }

  .bookcase-viewport {
    width: 100vw;
    height: auto;
    min-height: 0;
    margin-top: 0;
    padding-top: 0.2rem;
    overflow: visible;
    touch-action: pan-y;
  }
  .bookcase-scene {
    min-height: 100%;
    height: 100%;
    perspective: none;
  }
  .bookcase-frame {
    transform: none !important;
    transition: transform 0.2s ease;
    transform-origin: center top;
  }
  body.mobile-compact-view .bookcase-frame {
    transform: scale(0.82) !important;
  }
  body.mobile-full-view .bookcase-frame {
    transform: scale(0.58) !important;
  }
  .bookcase-body {
    width: calc(100% - 2px);
    max-width: 100%;
    padding: 6px 6px 2px;
  }
  .shelf {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: auto;
    padding: 10px 10px 14px;
    gap: 10px;
    margin-bottom: 8px;
    align-items: stretch;
  }
  .shelf::after {
    left: -4px;
    right: -4px;
    height: 10px;
  }
  .shelf-bottom {
    min-height: 12px;
    padding-top: 4px;
    padding-bottom: 4px;
  }
  .book {
    width: 100% !important;
    height: auto !important;
    min-width: 0;
    max-width: 100%;
    margin: 0 auto;
  }
  .book-inner {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 3 / 4;
  }
  .book-cover {
    width: 100% !important;
    height: 100% !important;
  }
  .book,
  .book:hover,
  .book.focused,
  .grid-card,
  .grid-card:hover {
    transform: none !important;
    animation: none !important;
    filter: none !important;
  }

  .reader-modal {
    inset: 0;
    border-radius: 0;
  }
  .admin-panel {
    width: 100vw;
  }
  .stage {
    min-height: 100vh;
    padding-top: 3.6rem;
    padding-bottom: 1rem;
    overflow: visible;
  }
}

/* ===== READER ERROR PANEL ===== */
.reader-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 7, 0.95);
  z-index: 3;
  padding: 1.5rem;
}
.reader-error.hidden { display: none; }
.reader-error-inner {
  text-align: center;
  max-width: 320px;
}
.reader-error-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.75rem;
}
.reader-error-inner p {
  margin: 0.25rem 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}
.reader-error-hint {
  color: var(--muted) !important;
  font-size: 0.82rem !important;
  font-weight: 400 !important;
  margin-top: 0.5rem !important;
  line-height: 1.55;
}
.reader-error-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}
.read-btn.secondary {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.read-btn.secondary:hover {
  background: rgba(255,255,255,0.13);
}

/* ===== MOBILE EXTRA OPTIMIZATIONS ===== */
@media (max-width: 768px) {
  /* 3-column grid on mobile — better browsing density */
  .grid-view {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.55rem !important;
    padding: 0.5rem !important;
  }
  .grid-card {
    border-radius: 8px;
    padding: 0.4rem;
  }
  .grid-card h3 {
    font-size: 0.68rem;
    margin-bottom: 0.2rem;
  }
  .grid-card p {
    font-size: 0.6rem;
  }

  /* Reader header touch-friendly on mobile */
  .reader-header {
    padding: 0.5rem 0.6rem;
    min-height: 48px;
  }
  .reader-header h3 {
    font-size: 0.75rem;
  }
  .reader-link {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
  }
  .panel-close {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }

  /* Larger touch target for nav arrows on mobile */
  .nav-arrow {
    width: 36px;
    height: 36px;
    font-size: 1.4rem;
    flex-shrink: 0;
  }

  /* Reader fullscreen hides on mobile (pinch-zoom is native) */
  #reader-fullscreen {
    display: none;
  }

  /* Grid cards — tappable cover images */
  .grid-card img {
    aspect-ratio: 3 / 4;
    width: 100%;
    object-fit: cover;
  }

  /* Shelf: 2 books per shelf already set, keep consistent */
  .shelf {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Toast bottom offset */
  .toast {
    bottom: 1rem;
    font-size: 0.8rem;
    padding: 0.5rem 0.9rem;
    max-width: calc(100vw - 2rem);
    text-align: center;
  }

  /* Error panel inside reader */
  .reader-error-inner {
    max-width: 90vw;
  }
  .reader-error-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .reader-error-actions .read-btn,
  .reader-error-actions a.read-btn {
    width: 100%;
    text-align: center;
  }
}

/* Very small phones: 2-column grid */
@media (max-width: 400px) {
  .grid-view {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
