:root {
  --bg-color: #ffffff; /* Pure white background like WeRead web */
  --card-bg: #ffffff;
  --text-primary: #111111; /* Darker black */
  --text-secondary: #767676;
  --accent-color: #1B88EE; /* WeRead Blue */
  --accent-hover: #156dc2;
  --border-color: #e0e0e0;
  --font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  /* overflow: hidden;  <-- REMOVED: This was blocking scroll on index/detail pages */
}

body {
  font-family: var(--font-family);
  background-color: var(--WR_BC22, #f6f6f6);
}

/* Only lock scroll in reader mode */
body.reader-mode {
  overflow: hidden;
  background-color: #f6f6f6;
}


/* Desktop Only Menu Item */
.desktop-only-menu-item {
  display: flex;
}
@media (max-width: 768px) {
  .desktop-only-menu-item {
    display: none !important;
  }
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 56px;
  background: #fff;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #999;
  font-size: 10px;
  height: 100%;
  gap: 4px;
}

.nav-item.active {
  color: var(--accent-color);
}

.nav-item svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Adjust main padding for bottom nav */
main {
  padding-bottom: 80px !important; /* 56px nav + spacing */
}

/* Hide bottom nav on desktop if desired */
@media (min-width: 769px) {
  .bottom-nav {
    display: none;
  }
  main {
    padding-bottom: 40px !important;
  }
}

/* Header */
header {
  background: rgba(255, 255, 255, 0.98);
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
  border-bottom: 1px solid #f0f0f0;
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  color: var(--accent-color); /* Brand color for logo */
  letter-spacing: -0.5px;
}

/* Main Layout */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 104px 40px 40px 40px; /* Adjusted for fixed header (64+40) */
}

/* List View */
.list-view {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.list-item {
  display: flex;
  align-items: center;
  padding: 16px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: transform 0.2s;
}

.list-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.list-cover {
  width: 60px;
  height: 88px;
  object-fit: cover;
  border-radius: 4px;
  background: #f0f0f0;
  flex-shrink: 0;
}

.list-info {
  flex: 1;
  margin-left: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.list-title {
  font-size: 18px;
  font-weight: 600;
  color: #111;
  margin-bottom: 6px;
}

.list-author {
  font-size: 14px;
  color: #666;
}

.btn-read {
  padding: 8px 20px;
  background: var(--accent-color);
  color: #fff;
  border-radius: 20px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  margin-left: 20px;
}

.btn-read:hover {
  background: var(--accent-hover);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 40px 32px;
}

/* Book Card */
.card {
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  position: relative;
  transition: transform 0.2s;
}

.card:hover {
  transform: translateY(-2px);
}

.thumb {
  width: 100%;
  aspect-ratio: 3 / 4.4; /* Standard book ratio */
  background: #f8f8f8;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08); /* Subtle shadow */
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  transition: box-shadow 0.2s ease;
  border: 1px solid rgba(0,0,0,0.02);
}

.card:hover .thumb {
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ccc;
}

.meta {
  display: flex;
  flex-direction: column;
}

.filename {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 4px;
  color: #111;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.small {
  font-size: 13px;
  color: #999;
}

/* Detail Page Styles */
.detail-container {
  max-width: 900px;
  margin: 40px auto;
  display: flex;
  gap: 60px;
  align-items: flex-start;
}

.detail-cover {
  width: 260px;
  flex-shrink: 0;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
}

.detail-cover img {
  width: 100%;
  display: block;
}

.detail-info {
  flex: 1;
  padding-top: 10px;
}

.detail-title {
  font-size: 28px;
  font-weight: 600;
  color: #111;
  margin-bottom: 12px;
  line-height: 1.3;
}

.detail-author {
  font-size: 16px;
  color: var(--accent-color);
  margin-bottom: 30px;
  font-weight: 500;
}

.detail-desc {
  font-size: 15px;
  line-height: 1.8;
  color: #555;
  margin-bottom: 20px;
  text-align: justify;
  position: relative;
}

.detail-desc.collapsed {
  max-height: 160px; /* Approx 6 lines */
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}

.expand-btn {
  display: none;
  background: none;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  margin-bottom: 30px;
}

.recommend-section {
  margin-top: 60px;
  border-top: 1px solid #f0f0f0;
  padding-top: 40px;
}

.recommend-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-left: 10px;
  border-left: 4px solid var(--accent-color);
}

.detail-actions {
  display: flex;
  gap: 20px;
}

.btn-lg {
  padding: 12px 40px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 24px;
  background: var(--accent-color);
  color: #fff;
  text-decoration: none;
  transition: background 0.2s;
  border: none;
  cursor: pointer;
}

.btn-lg:hover {
  background: var(--accent-hover);
}

.btn-outline {
  background: #fff;
  border: 1px solid #ccc;
  color: #333;
}

.btn-outline:hover {
  border-color: #999;
  background: #f9f9f9;
}

/* Reader Styles */
/* body.reader-mode is already defined above for overflow:hidden */

.reader-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: #f6f6f6;
}

.reader-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.98);
  z-index: 100; /* Higher than nav zones */
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  transition: transform 0.3s ease;
}

/* Hide header when not hovering near top, or use JS to toggle. 
   For now, let's keep it simple: always visible or hover-based.
   User complained about nav buttons "running to top bar", so let's ensure separation.
*/

.reader-content {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  padding-top: 50px; /* Space for header */
}

#viewer {
  width: 100%;
  height: 100%;
  /* Ensure iframe fills this */
}

#viewer iframe {
  width: 100% !important;
  height: 100% !important;
  border: none;
  display: block;
}

/* PDF Canvas specific */
#pdf-canvas {
  box-shadow: 0 0 20px rgba(0,0,0,0.05);
  max-height: 98vh;
  width: auto;
  max-width: 100%;
  display: block;
  margin: 0 auto;
}

/* Navigation Zones */
.nav-zone {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  color: #ccc;
  transition: color 0.2s, background 0.2s;
  border-radius: 4px;
}

.nav-zone:hover {
  color: #333;
  background: rgba(0,0,0,0.05);
}

.nav-prev { left: 10px; }
.nav-next { right: 10px; }

.nav-icon svg { width: 32px; height: 32px; }

/* Mobile Nav */
@media (max-width: 600px) {
  .nav-zone {
    display: none !important;
  }
}

/* Page Number Indicator */
.page-indicator {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
}

/* Back Button */
.back-btn {
  text-decoration: none;
  color: #666;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.back-btn:hover { color: var(--accent-color); }

#title {
  color: #333;
  font-weight: 500;
}

/* Search Input */
#search {
  background: #f5f5f5;
  border: none !important;
  color: #333;
  font-size: 14px;
  transition: background 0.2s;
}
#search:focus {
  background: #fff;
  box-shadow: 0 0 0 1px var(--accent-color);
}

/* --- Responsive Design --- */

/* Tablet & Mobile Common Adjustments */
@media (max-width: 1024px) {
  main {
    padding: 20px;
  }
  
  .grid {
    gap: 20px 16px;
  }
  
  .detail-container {
    gap: 40px;
    margin: 20px auto;
  }
}

/* Mobile Specific */
@media (max-width: 768px) {
  /* Hide 5th recommendation on mobile to keep 2x2 grid */
  .recommend-section .grid .card:nth-child(5) {
    display: none;
  }
  
  /* Header */
  header {
    padding: 0 16px;
    height: 56px;
  }
  
  header h1 {
    font-size: 18px;
  }
  
  /* Search bar on mobile */
  header > div {
    margin-left: 16px !important;
    max-width: none !important;
  }

  /* Grid: 2 columns on mobile */
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 12px;
  }
  
  /* Detail Page */
  .detail-container {
    flex-direction: column;
    align-items: center;
    gap: 24px;
  }

  main {
    padding: 76px 20px 20px 20px; /* Adjusted for fixed header (56+20) */
  }
  
  .detail-cover {
    width: 160px; /* Smaller cover */
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  }
  
  .detail-info {
    text-align: center;
    padding-top: 0;
    width: 100%;
  }
  
  .detail-title {
    font-size: 22px;
    margin-bottom: 8px;
  }
  
  .detail-author {
    margin-bottom: 20px;
    font-size: 14px;
  }
  
  .detail-desc {
    font-size: 14px;
    text-align: left;
    margin-bottom: 30px;
    color: #666;
  }
  
  .detail-actions {
    justify-content: center;
    flex-direction: column;
    gap: 12px;
  }
  
  .btn-lg {
    width: 100%;
    text-align: center;
    padding: 12px 0;
  }

  /* Reader Mode Mobile */
  .reader-header {
    padding: 0 12px;
  }
  
  #title {
    max-width: 50%; /* More space for title on small screens */
  }
  
  .nav-zone {
    width: 20%; /* Larger touch targets */
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(2, 1fr); /* Keep 2 columns but tighter */
    gap: 12px 8px;
  }
  
  .filename {
    font-size: 14px;
  }
}

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  color: #999;
  font-size: 12px;
  margin-top: 40px;
  border-top: 1px solid #f0f0f0;
}

/* Custom Modal */
.custom-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.custom-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.custom-modal {
  background: #fff;
  width: 90%;
  max-width: 320px;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  transform: scale(0.95);
  transition: transform 0.2s;
  text-align: center;
}

.custom-modal-overlay.active .custom-modal {
  transform: scale(1);
}

.custom-modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #111;
}

.custom-modal-message {
  font-size: 15px;
  color: #666;
  margin-bottom: 24px;
  line-height: 1.5;
}

.custom-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-btn {
  flex: 1;
  padding: 10px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.2s;
}

.modal-btn-cancel {
  background: #f5f5f5;
  color: #666;
}

.modal-btn-confirm {
  background: var(--accent-color);
  color: #fff;
}

.modal-btn-danger {
  background: #ff4d4f;
  color: #fff;
}

/* Modern Login Styles */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f7fa;
  padding: 20px;
}

.login-card {
  background: transparent;
  width: 100%;
  max-width: 400px;
  border-radius: 0;
  box-shadow: none;
  padding: 20px;
  transition: transform 0.3s;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 48px;
  height: 48px;
  background: var(--accent-color);
  color: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 16px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: #111;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 14px;
  color: #999;
}

.input-group {
  margin-bottom: 20px;
}

.input-field {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #f9f9f9;
}

.input-field:focus {
  background: #fff;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(27, 136, 238, 0.1);
  outline: none;
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 10px;
}

.login-btn:active {
  transform: scale(0.98);
}

.login-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 14px;
  color: #666;
}

.login-link {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 500;
}

@media (max-width: 480px) {
  .login-page {
    background: #fff;
    align-items: flex-start;
    padding: 0;
  }
  .login-card {
    box-shadow: none;
    padding: 40px 24px;
    border-radius: 0;
    height: 100vh;
  }
}
