/* ==========================================================================
   AiReadCode Open Source Bookshelf & Interactive Web Reader Stylesheet
   Theme: Obsidian Cyber / Adaptive Clean Light
   ========================================================================== */

/* Bookshelf Gallery Styles */
.books-hero {
  padding: 80px 0 40px;
  text-align: center;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
  margin-top: 40px;
  margin-bottom: 80px;
}

.book-card-item {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  color: inherit;
}

.book-card-item:hover {
  transform: translateY(-6px);
  border-color: rgba(99, 102, 241, 0.45);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.65), 0 0 35px rgba(99, 102, 241, 0.18);
}

.book-card-cover {
  padding: 36px 28px;
  position: relative;
  border-bottom: 1px solid var(--border-subtle);
}

.book-card-badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
}

.book-card-title {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.3;
  margin-bottom: 8px;
}

.book-card-meta {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
}

.book-card-content {
  padding: 26px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.book-card-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 20px;
}

.book-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 24px;
}

.book-card-tags span {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 4px 9px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.book-card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.book-read-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Sticky solid header on reader pages to prevent scroll bleed */
.site-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(16px);
}
html[data-theme="light"] .site-header {
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid #e2e8f0;
}

/* ==========================================================================
   Interactive Web Reader Layout (Split Panes: Left TOC | Center Book | Right Code)
   ========================================================================== */
.reader-container {
  display: grid;
  grid-template-columns: 280px 1fr 480px;
  min-height: calc(100vh - var(--nav-height));
  background: var(--bg-primary);
  border-top: 1px solid var(--border-subtle);
}

/* Left TOC Sidebar */
.reader-sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  padding: 24px 18px;
  height: calc(100vh - var(--nav-height));
  position: sticky;
  top: var(--nav-height);
  overflow-y: auto;
}

.reader-book-header {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.reader-book-badge {
  font-size: 11px;
  color: var(--accent-cyan);
  font-weight: 700;
  margin-bottom: 4px;
  display: block;
}

.reader-book-title {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
}

.reader-toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.toc-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
  line-height: 1.4;
}

.toc-link:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.toc-link.active {
  background: rgba(6, 182, 212, 0.12);
  color: #38bdf8;
  font-weight: 600;
  border-left: 3px solid var(--accent-cyan);
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.toc-link.active .toc-num {
  color: #38bdf8;
}

/* Center Article Content */
.reader-main {
  padding: 48px 56px 96px;
  max-width: 860px;
  margin-inline: auto;
  overflow-y: visible;
}

.book-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.book-breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}
.book-breadcrumb a:hover {
  color: var(--accent-cyan);
}

.reader-chapter-title {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1.25;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.reader-chapter-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 32px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Reader Typography & Blocks */
.reader-body p {
  font-size: 16px;
  line-height: 1.85;
  color: var(--text-highlight);
  margin-bottom: 24px;
}

.reader-body h2 {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  margin: 48px 0 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.reader-body h3 {
  font-family: var(--font-heading);
  font-size: 19px;
  font-weight: 600;
  margin: 32px 0 16px;
  color: var(--text-primary);
}

/* Intuition Card */
.intuition-card {
  padding: 20px 24px;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.25);
  margin: 32px 0;
}

.intuition-title {
  font-size: 14px;
  font-weight: 700;
  color: #a5b4fc;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.intuition-desc {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin: 0;
}

/* FACT Tag Interactive Anchor */
.fact-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: #38bdf8;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
  vertical-align: middle;
  text-decoration: none;
}

.fact-pill:hover,
.fact-pill.active {
  background: rgba(6, 182, 212, 0.25);
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.35);
  transform: translateY(-1px);
}

/* Inference Box */
.inference-box {
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  background: rgba(245, 158, 11, 0.08);
  border-left: 4px solid var(--accent-amber);
  margin: 24px 0;
  font-size: 14px;
  line-height: 1.7;
  color: #fde68a;
}
.inference-tag {
  font-weight: 700;
  margin-right: 6px;
}

/* Reader CTA Banner */
.reader-cta-card {
  margin-top: 64px;
  padding: 36px 32px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.95) 100%);
  border: 1px solid rgba(99, 102, 241, 0.35);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 40px rgba(99, 102, 241, 0.15);
  text-align: center;
}

.reader-cta-card h3 {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  color: #ffffff;
}

.reader-cta-card p {
  color: var(--text-secondary);
  font-size: 15px;
  max-width: 600px;
  margin: 0 auto 24px;
  line-height: 1.65;
}

/* Right Split Pane: Real Code Inspector */
.reader-code-pane {
  background: #090d16;
  border-left: 1px solid var(--border-subtle);
  height: calc(100vh - var(--nav-height));
  position: sticky;
  top: var(--nav-height);
  display: flex;
  flex-direction: column;
}

.code-pane-header {
  padding: 10px 14px;
  background: #0d121f;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.code-pane-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.code-pane-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-code-action {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94a3b8;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-sans);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-code-action:hover {
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.4);
  color: #38bdf8;
}

.btn-code-action.copied {
  background: rgba(16, 185, 129, 0.2);
  border-color: #10b981;
  color: #34d399;
}

.code-pane-status {
  font-size: 11px;
  color: #34d399;
  display: flex;
  align-items: center;
  gap: 5px;
}

.code-pane-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  background: #070a12;
  scroll-behavior: smooth;
}

.code-line {
  display: flex;
  gap: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  min-width: max-content;
}

.code-line.highlight {
  background: rgba(6, 182, 212, 0.18);
  border-left: 3px solid var(--accent-cyan);
  box-shadow: inset 1px 0 0 rgba(6, 182, 212, 0.3);
}

.code-line.highlight .code-text {
  color: #f0fdfa;
  font-weight: 500;
}

.line-no {
  color: #475569;
  user-select: none;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
  font-size: 11px;
}

.code-text {
  white-space: pre;
  tab-size: 2;
  word-break: normal;
  overflow-wrap: normal;
  color: #94a3b8;
}

.code-pane-footer {
  padding: 10px 14px;
  background: #0c101a;
  border-top: 1px solid var(--border-subtle);
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.code-pane-filepath {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Multi-chapter Chapter-by-Chapter View & Transitions */
.reader-chapter-section {
  display: none;
  padding-top: 16px;
  margin-bottom: 48px;
  animation: chapterFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.reader-chapter-section.active-chapter {
  display: block;
}

@keyframes chapterFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chapter-header {
  margin-bottom: 28px;
}

.chapter-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.25);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: 12px;
}

.chapter-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px dashed var(--border-subtle);
}

.code-block-wrapper {
  position: relative;
  margin: 24px 0;
  border-radius: var(--radius-md);
  background: #090d16;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: #0e1424;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.code-copy-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.table-container {
  overflow-x: auto;
  margin: 24px 0;
}

.reader-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.reader-table th, .reader-table td {
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.reader-table th {
  background: rgba(255, 255, 255, 0.04);
  font-weight: 700;
  color: var(--text-primary);
}

.reader-list {
  margin: 16px 0 24px 20px;
  color: var(--text-highlight);
  line-height: 1.8;
}

.reader-list li {
  margin-bottom: 6px;
}

.reader-quote {
  border-left: 3px solid var(--accent-cyan);
  padding: 8px 18px;
  margin: 20px 0;
  background: rgba(6, 182, 212, 0.05);
  color: var(--text-secondary);
  font-style: italic;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.reader-details {
  margin: 18px 0;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.reader-details[open] {
  background: rgba(14, 20, 36, 0.6);
  border-color: rgba(6, 182, 212, 0.3);
}

.reader-summary {
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
  outline: none;
  transition: color 0.15s ease;
}

.reader-summary:hover {
  color: var(--accent-cyan);
}

.reader-details p {
  margin-top: 10px;
}

/* FACT Verification Pill & GitHub Jump Action */
.fact-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.28);
  padding: 1px 7px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #38bdf8;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  vertical-align: middle;
  margin: 0 3px;
  text-decoration: none;
}

.fact-pill:hover {
  background: rgba(6, 182, 212, 0.18);
  border-color: rgba(6, 182, 212, 0.55);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.25);
  transform: translateY(-1px);
}

.fact-pill code {
  color: inherit;
  background: transparent;
  padding: 0;
  font-size: inherit;
}

.badge-lines {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #38bdf8;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  padding: 2px 7px;
  border-radius: 4px;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.code-loading-msg {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ==========================================================================
   Light Mode Optimizations for Books & Code Inspector
   ========================================================================== */
html[data-theme="light"] .reader-container {
  background: #ffffff;
}

html[data-theme="light"] .reader-sidebar {
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
}

html[data-theme="light"] .toc-link {
  color: #475569;
}

html[data-theme="light"] .toc-link:hover {
  background: rgba(15, 23, 42, 0.05);
  color: #0f172a;
}

html[data-theme="light"] .toc-link.active {
  background: rgba(2, 132, 199, 0.1);
  color: #0284c7;
  border-left-color: #0284c7;
}

html[data-theme="light"] .toc-link.active .toc-num {
  color: #0284c7;
}

html[data-theme="light"] .reader-code-pane {
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  box-shadow: -3px 0 16px rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] .code-pane-header {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

html[data-theme="light"] .code-pane-title {
  color: #0f172a;
}

html[data-theme="light"] .code-pane-title svg {
  stroke: #0284c7;
}

html[data-theme="light"] .badge-lines {
  color: #0284c7;
  background: rgba(2, 132, 199, 0.08);
  border: 1px solid rgba(2, 132, 199, 0.25);
}

html[data-theme="light"] .btn-code-action {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
}

html[data-theme="light"] .btn-code-action:hover {
  background: #f1f5f9;
  border-color: #0284c7;
  color: #0284c7;
}

html[data-theme="light"] .btn-code-action.copied {
  background: #ecfdf5;
  border-color: #10b981;
  color: #059669;
}

html[data-theme="light"] .code-pane-body {
  background: #ffffff;
}

html[data-theme="light"] .code-pane-body.flash-highlight {
  background: rgba(2, 132, 199, 0.12) !important;
}

html[data-theme="light"] .code-line {
  color: #1e293b;
}

html[data-theme="light"] .line-no {
  color: #94a3b8;
}

html[data-theme="light"] .code-text {
  color: #1e293b; /* Deep slate, high legibility */
}

html[data-theme="light"] .code-line.highlight {
  background: #e0f2fe; /* Light cyan-sky background */
  border-left: 3px solid #0284c7;
  box-shadow: inset 1px 0 0 rgba(2, 132, 199, 0.3);
}

html[data-theme="light"] .code-line.highlight .line-no {
  color: #0284c7;
  font-weight: 700;
}

html[data-theme="light"] .code-line.highlight .code-text {
  color: #0369a1; /* Deep vivid cyan-blue, extremely readable */
  font-weight: 600;
}

html[data-theme="light"] .code-pane-footer {
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  color: #64748b;
}

html[data-theme="light"] .code-pane-filepath {
  color: #475569;
}

html[data-theme="light"] .fact-pill {
  background: rgba(2, 132, 199, 0.08);
  border-color: rgba(2, 132, 199, 0.28);
  color: #0284c7;
}

html[data-theme="light"] .fact-pill:hover,
html[data-theme="light"] .fact-pill.active {
  background: rgba(2, 132, 199, 0.16);
  border-color: #0284c7;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.25);
  color: #0369a1;
}

html[data-theme="light"] .code-block-wrapper {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

html[data-theme="light"] .code-block-header {
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  color: #64748b;
}

html[data-theme="light"] .source-code-block {
  background: #ffffff;
  color: #1e293b;
}

html[data-theme="light"] .source-code-block code {
  color: #1e293b;
}

html[data-theme="light"] .code-copy-btn {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #475569;
}

html[data-theme="light"] .code-copy-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

html[data-theme="light"] .inference-box {
  background: rgba(245, 158, 11, 0.08);
  border-left-color: #d97706;
  color: #92400e;
}

html[data-theme="light"] .reader-quote {
  background: rgba(2, 132, 199, 0.05);
  border-left-color: #0284c7;
  color: #334155;
}

html[data-theme="light"] .reader-details {
  background: #f8fafc;
  border-color: #e2e8f0;
}

html[data-theme="light"] .reader-details[open] {
  background: #ffffff;
  border-color: rgba(2, 132, 199, 0.4);
}

html[data-theme="light"] .reader-table th {
  background: #f1f5f9;
  color: #0f172a;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .reader-container {
    grid-template-columns: 240px 1fr;
  }
  .reader-code-pane {
    display: none; /* Collapsed on tablet/mobile unless toggled */
  }
  .books-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .reader-container {
    grid-template-columns: 1fr;
  }
  .reader-sidebar {
    display: none;
  }
  .reader-main {
    padding: 24px 20px 64px;
  }
  .books-grid {
    grid-template-columns: 1fr;
  }
}
