@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+KR:wght@400;700&family=Noto+Sans+KR:wght@300;400;500;700&display=swap');

:root {
  --primary: #5B4A3F;
  --primary-light: #8B7355;
  --accent: #C9A96E;
  --bg: #ffffff;
  --bg-dark: #f0f0f0;
  --text: #3A3A3A;
  --text-light: #888;
  --white: #fff;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ========== INDEX PAGE (Category List) ========== */
.ebook-index {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

.ebook-header {
  text-align: center;
  margin-bottom: 48px;
}

.ebook-header .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.ebook-header h1 {
  font-family: 'Noto Serif KR', serif;
  font-size: 2rem;
  color: var(--primary);
  letter-spacing: 2px;
}

.ebook-header p {
  color: var(--text-light);
  margin-top: 8px;
  font-size: 0.95rem;
}

/* Category Grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.category-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--white);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  border: 1px solid transparent;
  transition: all 0.25s ease;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.category-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.category-card--bible {
  border-color: var(--accent);
  background: linear-gradient(135deg, #fff 0%, #fdf8f2 100%);
}

.category-card--bible:hover {
  background: linear-gradient(135deg, #fdf8f2 0%, #f5edd8 100%);
}

.category-card__icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.category-card__name {
  font-family: 'Noto Serif KR', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}

.category-card__desc {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* ========== LIST PAGE ========== */
.ebook-list {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

.ebook-list__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.ebook-list__title {
  font-family: 'Noto Serif KR', serif;
  font-size: 1.6rem;
  color: var(--primary);
}

.ebook-list__back {
  color: var(--primary-light);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 6px 12px;
  border: 1px solid var(--bg-dark);
  border-radius: 6px;
  transition: background 0.2s;
}

.ebook-list__back:hover {
  background: var(--bg-dark);
}

/* Tabs */
.ebook-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--bg-dark);
  padding-bottom: 12px;
}

.ebook-tab {
  padding: 6px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 0.9rem;
  color: var(--text-light);
  background: var(--bg-dark);
  transition: all 0.2s;
}

.ebook-tab:hover,
.ebook-tab--active {
  background: var(--primary);
  color: var(--white);
}

/* Book Card Grid */
.book-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
}

.book-list-card {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  border: 1px solid transparent;
  transition: all 0.25s ease;
  box-shadow: var(--shadow);
}

.book-list-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.book-list-card__cover {
  width: 100%;
  aspect-ratio: 3/4;
  overflow: hidden;
  background: var(--bg-dark);
  position: relative;
}

.book-list-card__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-list-card__cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--primary-light);
  background: linear-gradient(135deg, var(--bg-dark), var(--bg));
}

.book-list-card__info {
  padding: 12px;
}

.book-list-card__title {
  font-family: 'Noto Serif KR', serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
  line-height: 1.4;
}

.book-list-card__meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.book-list-card__pages,
.book-list-card__views {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Pagination */
.ebook-pagination {
  margin-top: 40px;
  display: flex;
  justify-content: center;
}

/* Empty state */
.ebook-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

/* ========== BIBLE INDEX PAGE ========== */

/* Testament Section */
.testament-section {
  margin-bottom: 40px;
}

.testament-title {
  font-family: 'Noto Serif KR', serif;
  font-size: 1.2rem;
  color: var(--primary);
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.testament-title .badge {
  background: var(--accent);
  color: var(--white);
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 20px;
  font-family: 'Noto Sans KR', sans-serif;
  font-weight: 500;
}

/* Book Grid (Bible) */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.book-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
}

.book-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.book-card.disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.book-card .book-name {
  font-family: 'Noto Serif KR', serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.book-card .book-name-en {
  font-size: 0.7rem;
  color: var(--text-light);
  letter-spacing: 0.5px;
}

.book-card .book-chapters {
  font-size: 0.72rem;
  color: var(--primary-light);
  margin-top: 6px;
}

.book-card .ready-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4CAF50;
}

.book-card .progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 var(--radius) var(--radius);
  transition: width 0.3s;
}

/* ========== VIEWER PAGE ========== */
.viewer-wrap {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #2C2C2C;
  overflow: hidden;
}

/* Top Bar */
.viewer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--primary);
  color: var(--white);
  flex-shrink: 0;
  z-index: 100;
}

.viewer-topbar .back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--white);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.2s;
}

.viewer-topbar .back-btn:hover {
  background: rgba(255,255,255,0.15);
}

.viewer-topbar .book-title {
  font-family: 'Noto Serif KR', serif;
  font-size: 1.1rem;
  font-weight: 700;
}

.viewer-topbar .tools {
  display: flex;
  gap: 4px;
}

.viewer-topbar .tool-btn {
  background: none;
  border: none;
  color: var(--white);
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s;
}
.viewer-topbar .tool-btn-label {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1;
}

.viewer-topbar .tool-btn:hover {
  background: rgba(255,255,255,0.15);
}

.viewer-topbar .tool-btn.bookmarked {
  color: var(--accent);
}

.viewer-topbar .tool-btn.slideshow-active {
  color: #4CAF50;
  animation: slideshow-pulse 1.5s ease-in-out infinite;
}

@keyframes slideshow-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Slideshow Speed Panel */
.slideshow-panel {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(0,0,0,0.5);
  z-index: 100;
}

.slideshow-panel.open {
  display: flex;
}

.slideshow-panel__label {
  color: var(--white);
  font-size: 0.8rem;
  white-space: nowrap;
}

.slideshow-panel__options {
  display: flex;
  gap: 6px;
}

.slideshow-speed-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--white);
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
}

.slideshow-speed-btn:hover {
  background: rgba(255,255,255,0.25);
}

.slideshow-speed-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--primary);
  font-weight: 600;
}

/* Viewer Body */
.viewer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 20px;
}

/* Flipbook */
.flipbook-container {
  position: relative;
  transform-origin: center center;
  transition: transform 0.3s ease;
}

.flipbook-container .page-wrapper {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.flipbook-container .page-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.flipbook-container .page-cover {
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--white);
  padding: 20px;
  text-align: center;
}

.flipbook-container .page-cover h2 {
  font-family: 'Noto Serif KR', serif;
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.flipbook-container .page-cover p {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* Scroll Viewer */
.scroll-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  scroll-behavior: smooth;
}

.scroll-page {
  width: 100%;
  max-width: 800px;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.scroll-page img {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Slide (Swiper) Viewer */
.slide-container {
  width: 100%;
  height: 100%;
}

.slide-container .swiper {
  width: 100%;
  height: 100%;
}

.slide-container .swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2C2C2C;
}

.slide-container .swiper-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Nav Arrows */
.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--primary);
  box-shadow: var(--shadow);
  z-index: 100;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.nav-arrow:hover {
  background: var(--white);
  box-shadow: var(--shadow-lg);
  transform: translateY(-50%) scale(1.1);
}

.nav-arrow.prev { left: 12px; }
.nav-arrow.next { right: 12px; }

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: default;
  transform: translateY(-50%);
}

/* Bottom Bar */
.viewer-bottombar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 16px;
  background: rgba(0,0,0,0.6);
  flex-shrink: 0;
  z-index: 100;
}

.viewer-bottombar .page-nav-btn {
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.viewer-bottombar .page-nav-btn:hover {
  background: rgba(255,255,255,0.15);
}

.viewer-bottombar .page-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.viewer-bottombar .page-info {
  color: var(--white);
  font-size: 0.85rem;
  min-width: 80px;
  text-align: center;
}

.viewer-bottombar .page-input {
  width: 48px;
  text-align: center;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--white);
  border-radius: 4px;
  padding: 4px;
  font-size: 0.85rem;
}

.viewer-bottombar .page-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Zoom Indicator */
.zoom-indicator {
  position: absolute;
  bottom: 70px;
  right: 20px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 50;
}

.zoom-indicator.show {
  opacity: 1;
}

/* TOC Panel */
.toc-panel {
  position: fixed;
  top: 0;
  left: -320px;
  width: 300px;
  height: 100vh;
  background: var(--white);
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  z-index: 200;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
}

.toc-panel.open {
  left: 0;
}

.toc-panel .toc-header {
  padding: 16px 20px;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-panel .toc-header h3 {
  font-family: 'Noto Serif KR', serif;
  font-size: 1rem;
}

.toc-panel .toc-close {
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.3rem;
  cursor: pointer;
}

.toc-panel .toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.toc-panel .toc-item {
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-panel .toc-item:hover {
  background: var(--bg);
}

.toc-panel .toc-item.active {
  background: var(--bg-dark);
  font-weight: 700;
  color: var(--primary);
}

.toc-panel .toc-item.bookmarked {
  color: var(--accent);
}

.toc-panel .toc-item .page-num {
  font-size: 0.75rem;
  color: var(--text-light);
}

.toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 199;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.toc-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Book List Panel */
.booklist-panel {
  position: fixed;
  top: 0;
  left: -340px;
  width: 320px;
  height: 100vh;
  background: #1e1e1e;
  border-right: 1px solid rgba(255,255,255,0.08);
  box-shadow: 8px 0 40px rgba(0,0,0,0.5);
  z-index: 200;
  transition: left 0.35s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.booklist-panel.open {
  left: 0;
}

.booklist-panel .booklist-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.booklist-panel .booklist-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

.booklist-panel .booklist-close {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.booklist-panel .booklist-close:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.booklist-panel .booklist-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.booklist-panel .booklist-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  border-left: 2px solid transparent;
  transition: background 0.2s, border-color 0.2s;
  text-decoration: none;
  color: inherit;
}

.booklist-panel .booklist-item:hover {
  background: rgba(255,255,255,0.04);
  border-left-color: rgba(255,255,255,0.2);
}

.booklist-panel .booklist-item.active {
  background: rgba(255,255,255,0.06);
  border-left-color: var(--accent);
}

.booklist-panel .booklist-item-cover {
  width: 40px;
  height: 54px;
  border-radius: 4px;
  overflow: hidden;
  background: #333;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.booklist-panel .booklist-item-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.booklist-panel .booklist-item-cover svg {
  color: #666;
}

.booklist-panel .booklist-item-info {
  flex: 1;
  min-width: 0;
}

.booklist-panel .booklist-item-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.booklist-panel .booklist-item.active .booklist-item-title {
  color: var(--accent);
}

.booklist-panel .booklist-item-pages {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 2px;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44,44,44,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 999;
  color: var(--white);
}

.loading-overlay .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Fullscreen mode */
body.fullscreen .viewer-topbar,
body.fullscreen .viewer-bottombar {
  opacity: 0;
  transition: opacity 0.3s;
}

body.fullscreen:hover .viewer-topbar,
body.fullscreen:hover .viewer-bottombar {
  opacity: 1;
}

/* Download protection */
.viewer-body img,
.scroll-page img,
.swiper-slide img {
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  pointer-events: none;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .ebook-header h1 { font-size: 1.5rem; }

  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .book-card-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
  }

  .book-card { padding: 12px 8px; }
  .book-card .book-name { font-size: 0.88rem; }
  .book-card .book-name-en { font-size: 0.65rem; }

  .nav-arrow { width: 36px; height: 36px; font-size: 1rem; }
  .nav-arrow.prev { left: 4px; }
  .nav-arrow.next { right: 4px; }

  .viewer-body { padding: 10px 4px; }
  .viewer-topbar { padding: 6px 10px; }
  .viewer-topbar .book-title { font-size: 0.95rem; }
  .viewer-topbar .tool-btn { min-width: 32px; width: 32px; padding: 0; }
  .viewer-topbar .tool-btn-label { display: none; }
}

@media (max-width: 480px) {
  .ebook-index { padding: 20px 12px 40px; }
  .ebook-list { padding: 20px 12px 40px; }

  .book-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .book-card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .book-card .book-name-en { display: none; }

  .ebook-list__header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .viewer-topbar .tools .tool-btn:nth-child(n+5) {
    display: none;
  }
}
