/* ============================================
   Bookshelf Reader - Zero Dependency Styles
   ============================================ */

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --sidebar-width: 280px;
  --content-max-width: 75ch;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #191919;
    --bg-secondary: #202020;
    --text-primary: #e8e8e7;
    --text-secondary: #b4b4b3;
    --text-muted: #7e7e7d;
    --border-color: #2f2f2f;
    --accent: #7b9ce1;
    --accent-hover: #99b3e8;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
  }
}

/* ============================================
   Base Styles
   ============================================ */

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

html {
  font-size: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  font-weight: 400;
  letter-spacing: -0.01em;
}

/* ============================================
   Library Page Styles (index.html)
   ============================================ */

.library-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

.library-header {
  margin-bottom: 3rem;
  text-align: center;
}

.library-header h1 {
  font-size: 2.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.library-header p {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* Reading Now Section */
.reading-now {
  max-width: 800px;
  margin: 0 auto 3rem;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.reading-now-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.reading-indicator {
  color: #10b981;
  font-size: 1.2rem;
  animation: pulse 2s ease-in-out infinite;
}

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

.reading-now-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.reading-now-card {
  display: flex;
  gap: 1.5rem;
  text-decoration: none;
  padding: 1.5rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.reading-now-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.book-cover {
  flex-shrink: 0;
}

.book-cover-placeholder {
  width: 120px;
  height: 160px;
  background: linear-gradient(135deg, var(--accent) 0%, #3b82f6 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  box-shadow: var(--shadow-md);
}

.book-cover-image {
  width: 120px;
  height: 160px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
}

.book-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.book-info h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
}

.book-info .book-author {
  font-size: 1rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 0 0 0.75rem 0;
}

.book-info .book-description {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

@media (max-width: 640px) {
  .reading-now-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .book-cover-placeholder {
    width: 100px;
    height: 140px;
  }
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.book-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.book-card-cover {
  width: 100px;
  height: 140px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.book-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.book-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.book-card .author {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.75rem;
}

.book-card .description {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.book-card .chapter-count {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
}

/* ============================================
   Reader Layout (Book Pages)
   ============================================ */

.reader-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
#sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 2rem 1.5rem;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

#sidebar.open {
  transform: translateX(0);
}

/* Sidebar Toggle Button */
.sidebar-toggle {
  position: fixed;
  left: 1.5rem;
  top: 1.5rem;
  z-index: 200;
  padding: 0.65rem 0.85rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
  line-height: 1;
}

.sidebar-toggle:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.05);
}

#sidebar.open ~ .sidebar-toggle {
  left: calc(var(--sidebar-width) + 1.5rem);
}

#sidebar .book-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

#sidebar .book-author {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 1.5rem;
}

#sidebar .back-to-library {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 1.5rem;
  margin-top: 2.5rem;
  padding: 0.5rem 0;
  transition: color 0.2s;
}

#sidebar .back-to-library:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

#sidebar nav ul {
  list-style: none;
}

#sidebar nav li {
  margin-bottom: 0.5rem;
}

#sidebar nav a {
  display: block;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.95rem;
  transition: background-color 0.2s, color 0.2s;
}

#sidebar nav a:hover {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

#sidebar nav a.active {
  background-color: var(--accent);
  color: white;
  font-weight: 500;
}

/* Main Content */
.reader-content {
  margin-left: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 2rem;
  transition: margin-left 0.3s ease;
}

article {
  max-width: var(--content-max-width);
  width: 100%;
}

/* Typography */
article h1 {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 1rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

article h2 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.4;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

article h3 {
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.5;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

article p {
  margin-bottom: 1.75rem;
  line-height: 1.8;
  letter-spacing: 0.01em;
}

article a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

article a:hover {
  border-bottom-color: var(--accent);
}

article img,
article svg {
  max-width: 100%;
  max-height: 70vh;
  height: auto;
  margin: 2rem auto;
  display: block;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.2s;
}

article img:hover,
article svg:hover {
  opacity: 0.85;
}

article svg image {
  max-width: 100%;
  height: auto;
}

article blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1.5rem;
  margin: 2rem 0;
  font-style: italic;
  color: var(--text-secondary);
}

article ul, article ol {
  margin-bottom: 1.5rem;
  padding-left: 2rem;
}

article li {
  margin-bottom: 0.5rem;
}

article code {
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
  background-color: var(--bg-secondary);
  padding: 0.2em 0.4em;
  border-radius: 3px;
}

article pre {
  background-color: var(--bg-secondary);
  padding: 1rem;
  border-radius: 5px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

article pre code {
  background-color: transparent;
  padding: 0;
}

article hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 3rem 0;
}

/* Chapter Navigation */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  max-width: var(--content-max-width);
  width: 100%;
}

.chapter-nav a {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background-color: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 5px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background-color 0.2s;
}

.chapter-nav a:hover {
  background-color: var(--accent-hover);
}

.chapter-nav .prev::before {
  content: "← ";
}

.chapter-nav .next::after {
  content: " →";
}

.chapter-nav .spacer {
  flex: 1;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Desktop: Show sidebar by default */
@media (min-width: 1025px) {
  #sidebar {
    transform: translateX(0);
  }

  .reader-content {
    margin-left: var(--sidebar-width);
  }

  .sidebar-toggle {
    display: none;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  .reader-content {
    margin-left: 0;
    padding: 2rem 1rem;
  }

  .library-container {
    padding: 2rem 1rem;
  }

  .books-grid {
    grid-template-columns: 1fr;
  }

  article h1 {
    font-size: 1.75rem;
  }

  article h2 {
    font-size: 1.4rem;
  }

  article h3 {
    font-size: 1.2rem;
  }

  .copy-content-btn {
    right: 1rem;
    bottom: 2.5rem;
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
    padding: 0.6rem;
  }

  .sidebar-toggle {
    left: 1rem;
    top: 1rem;
    font-size: 1.1rem;
    padding: 0.55rem 0.75rem;
  }

  .book-progress-container {
    padding: 0.3rem 1rem;
  }

  .book-progress-container:hover {
    padding: 0.5rem 1rem;
  }

  .book-progress-bar {
    height: 3px;
  }

  .book-progress-container:hover .book-progress-bar {
    height: 5px;
  }

  .book-progress-text {
    font-size: 0.7rem;
  }
}

/* Scrollbar Styling */
#sidebar::-webkit-scrollbar {
  width: 8px;
}

#sidebar::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

#sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Copy Content Button */
.copy-content-btn {
  position: fixed;
  right: 2rem;
  bottom: 6rem;
  z-index: 150;
  padding: 0.75rem 0.9rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.3rem;
  transition: all 0.2s;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
  line-height: 1;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.copy-content-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 8px 16px -2px rgba(0, 0, 0, 0.2);
}

.copy-content-btn:active {
  transform: scale(0.95);
}

/* Book Progress Bar (Bottom) */
.book-progress-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 0.4rem 2rem;
  z-index: 100;
  backdrop-filter: blur(10px);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  transition: padding 0.2s ease;
  cursor: pointer;
}

.book-progress-container:hover {
  padding: 0.75rem 2rem;
}

.book-progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  overflow: hidden;
  transition: height 0.2s ease;
}

.book-progress-container:hover .book-progress-bar {
  height: 6px;
  margin-bottom: 0.5rem;
}

.book-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
  transition: width 0.3s ease, box-shadow 0.2s ease;
}

.book-progress-container:hover .book-progress-fill {
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.3);
}

.book-progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.2s ease, opacity 0.2s ease, margin-top 0.2s ease;
}

.book-progress-container:hover .book-progress-text {
  max-height: 2rem;
  opacity: 1;
  margin-top: 0.25rem;
}

/* Image Modal (Lightbox) - Medium Style */
.image-modal {
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, background-color 0.3s ease;
}

.image-modal.show {
  opacity: 1;
  pointer-events: auto;
  background-color: rgba(0, 0, 0, 0.95);
}

.image-modal img {
  max-width: 90%;
  max-height: 90vh;
  object-fit: contain;
  cursor: zoom-out;
  border-radius: 4px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.2, 0, 0.2, 1), 
              opacity 0.35s ease;
}

.image-modal.show img {
  transform: scale(1);
  opacity: 1;
}

.image-modal-close {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 32px;
  font-weight: bold;
  color: #ffffff;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0;
  transform: scale(0.8);
  transition: background 0.2s, opacity 0.3s ease 0.1s, transform 0.3s ease 0.1s;
}

.image-modal.show .image-modal-close {
  opacity: 1;
  transform: scale(1);
}

.image-modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* Print Styles */
@media print {
  #sidebar,
  .book-progress-container,
  .chapter-nav,
  .copy-content-btn,
  .sidebar-toggle {
    display: none;
  }

  .reader-content {
    margin-left: 0;
  }
}
