/* books.css — apasbooks.com design system
   Reading-first design. Typography, comfort, focus.
*/
@import url('https://fonts.googleapis.com/css2?family=Literata:ital,opsz,wght@0,7..72,300;0,7..72,400;0,7..72,500;1,7..72,300;1,7..72,400&family=Inter:wght@300;400;500&display=swap');

:root {
  --font-reading: 'Literata', Georgia, serif;
  --font-ui:      'Inter', system-ui, sans-serif;

  /* Reading themes */
  --bg:          #0f0f0f;
  --surface:     #161616;
  --surface2:    #1e1e1e;
  --border:      #2a2a2a;
  --border2:     #333333;

  /* Text — warm for reading */
  --t1: #f0ece4;   /* primary reading text — warm white */
  --t2: #c8c0b0;   /* secondary */
  --t3: #a09080;   /* tertiary */
  --t4: #706050;   /* muted */
  --t5: #4a4035;   /* very muted */
  --t6: #2a2520;   /* disabled */

  /* Accent */
  --accent:        #c8a96e;  /* warm gold — book feel */
  --accent-dim:    #1e1800;
  --accent-border: #3a2e00;

  /* Highlight colors */
  --hl-yellow: rgba(255, 220, 100, 0.25);
  --hl-blue:   rgba(100, 180, 255, 0.2);
  --hl-green:  rgba(100, 220, 150, 0.2);
  --hl-pink:   rgba(255, 150, 180, 0.2);

  /* Layout */
  --topbar-h:      52px;
  --progress-h:    3px;
  --sidebar-w:     260px;
  --reading-max:   680px;   /* optimal line length for reading */
  --ease:          0.16s ease;
  --radius-sm:     5px;
  --radius-md:     9px;
  --radius-lg:     13px;
}

/* Sepia theme */
[data-theme="sepia"] {
  --bg:      #f4ede0;
  --surface: #ede4d3;
  --surface2:#e6dbc8;
  --border:  #d4c8b0;
  --border2: #c4b89a;
  --t1: #2c2218;
  --t2: #4a3828;
  --t3: #6a5840;
  --t4: #8a7860;
  --t5: #aa9880;
  --t6: #c4b8a0;
  --accent: #7a4820;
  --hl-yellow: rgba(180, 140, 40, 0.2);
}

/* Light theme */
[data-theme="light"] {
  --bg:      #ffffff;
  --surface: #f8f8f8;
  --surface2:#f0f0f0;
  --border:  #e0e0e0;
  --border2: #d0d0d0;
  --t1: #1a1a1a;
  --t2: #2a2a2a;
  --t3: #4a4a4a;
  --t4: #6a6a6a;
  --t5: #8a8a8a;
  --t6: #b0b0b0;
  --accent: #8b5e3c;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--t2);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; }

/* ── Reading progress bar ── */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--progress-h);
  background: var(--border);
  z-index: 200;
}
.reading-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s ease;
}

/* ── Topbar ── */
.books-topbar {
  position: fixed; top: var(--progress-h); left: 0; right: 0;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  transition: opacity var(--ease);
}
.books-topbar.hidden { opacity: 0; pointer-events: none; }

.topbar-brand {
  font-family: var(--font-reading);
  font-size: 1.05rem;
  color: var(--accent);
  font-style: italic;
}
.topbar-title {
  font-family: var(--font-reading);
  font-size: 0.88rem;
  color: var(--t3);
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

.icon-btn {
  background: none; border: none; color: var(--t4);
  cursor: pointer; padding: 0.3rem; border-radius: var(--radius-sm);
  font-size: 17px; display: flex; align-items: center;
  transition: color var(--ease);
}
.icon-btn:hover { color: var(--t1); }

/* ── Reader layout ── */
.reader-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  padding-top: calc(var(--topbar-h) + var(--progress-h));
}
.reader-layout.no-sidebar {
  grid-template-columns: 1fr;
}

/* ── Sidebar — chapter/section nav ── */
.reader-sidebar {
  position: fixed;
  top: calc(var(--topbar-h) + var(--progress-h));
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h) - var(--progress-h));
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: thin;
  transition: transform var(--ease);
  z-index: 50;
}
.reader-sidebar.collapsed {
  transform: translateX(-100%);
}
.reader-sidebar::-webkit-scrollbar { width: 4px; }
.reader-sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.sidebar-book-title {
  padding: 1rem;
  font-family: var(--font-reading);
  font-size: 0.88rem;
  color: var(--t2);
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}
.sidebar-chapter-label {
  padding: 0.65rem 1rem 0.2rem;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--t5);
}
.sidebar-section {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 1rem 0.35rem 1.25rem;
  font-size: 0.8rem;
  color: var(--t4);
  cursor: pointer;
  transition: all var(--ease);
  border-left: 2px solid transparent;
  line-height: 1.4;
}
.sidebar-section:hover { color: var(--t2); background: var(--surface2); }
.sidebar-section.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}
.sidebar-section.free-tag::after {
  content: "free";
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0 4px;
  border-radius: 3px;
  margin-left: auto;
}

/* ── Reading area ── */
.reading-area {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 2rem 6rem;
  transition: margin-left var(--ease);
}
.reading-area.full-width {
  margin-left: 0;
}

/* Reading content — constrained for comfort */
.reading-content {
  width: 100%;
  max-width: var(--reading-max);
}

/* Section meta */
.section-meta {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.section-chapter {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--t5);
  margin-bottom: 0.5rem;
}
.section-title {
  font-family: var(--font-reading);
  font-size: 1.8rem;
  font-weight: 400;
  color: var(--t1);
  line-height: 1.25;
  margin-bottom: 0.5rem;
}
.section-code {
  font-family: monospace;
  font-size: 0.68rem;
  color: var(--t6);
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 3px;
}

/* Reading typography — the most important part */
.reading-content p,
.reading-content .prose {
  font-family: var(--font-reading);
  font-size: var(--reading-size, 1rem);
  line-height: var(--reading-leading, 1.85);
  color: var(--t1);
  margin-bottom: 1.25rem;
  letter-spacing: 0.01em;
}

.reading-content h2, .reading-content h3 {
  font-family: var(--font-reading);
  color: var(--t1);
  margin: 2rem 0 0.75rem;
  font-weight: 400;
}

/* Highlights */
.highlight {
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.highlight.yellow { background: var(--hl-yellow); }
.highlight.blue   { background: var(--hl-blue);   }
.highlight.green  { background: var(--hl-green);   }
.highlight.pink   { background: var(--hl-pink);    }

/* Selection toolbar — appears on text select */
.selection-toolbar {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.5rem;
  display: none;
  align-items: center;
  gap: 0.25rem;
  z-index: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.selection-toolbar.visible { display: flex; }
.sel-btn {
  background: none; border: none; cursor: pointer;
  padding: 0.25rem 0.4rem; border-radius: var(--radius-sm);
  font-size: 12px; transition: background var(--ease);
  color: var(--t2); font-family: var(--font-ui);
  display: flex; align-items: center; gap: 0.25rem;
}
.sel-btn:hover { background: var(--surface2); }
.sel-color {
  width: 14px; height: 14px; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.1);
}
.sel-divider { width: 1px; height: 16px; background: var(--border2); margin: 0 0.15rem; }

/* Notes panel */
.notes-panel {
  position: fixed;
  top: calc(var(--topbar-h) + var(--progress-h));
  right: 0;
  width: 280px;
  height: calc(100vh - var(--topbar-h) - var(--progress-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--ease);
  z-index: 50;
}
.notes-panel.open { transform: translateX(0); }
.notes-panel-header {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.notes-panel-title { font-size: 0.82rem; color: var(--t2); font-weight: 500; }
.notes-list { flex: 1; overflow-y: auto; padding: 0.75rem; }
.note-item {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--accent);
  font-size: 0.78rem; color: var(--t2); line-height: 1.5;
  cursor: pointer; transition: background var(--ease);
}
.note-item:hover { background: var(--border); }
.note-item .note-quote {
  font-family: var(--font-reading);
  font-style: italic;
  color: var(--t3);
  font-size: 0.72rem;
  margin-bottom: 0.3rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-item .note-text { color: var(--t2); }
.note-item .note-time { font-size: 0.62rem; color: var(--t5); margin-top: 0.25rem; }
.note-input-area {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.note-textarea {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem; color: var(--t2);
  font-size: 0.8rem; font-family: var(--font-ui);
  resize: none; outline: none; height: 72px;
  transition: border-color var(--ease);
}
.note-textarea:focus { border-color: var(--accent); }
.note-textarea::placeholder { color: var(--t5); }

/* Reading settings panel */
.settings-panel {
  position: absolute;
  top: calc(var(--topbar-h) + var(--progress-h) + 8px);
  right: 1rem;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 1rem;
  width: 240px;
  display: none;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.settings-panel.open { display: block; }
.settings-label {
  font-size: 0.62rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--t5); margin-bottom: 0.5rem;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.85rem;
}
.settings-row label { font-size: 0.8rem; color: var(--t3); }
.theme-btns { display: flex; gap: 0.35rem; }
.theme-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border2); cursor: pointer;
  transition: border-color var(--ease);
}
.theme-btn.active { border-color: var(--accent); }
.theme-btn.dark  { background: #0f0f0f; }
.theme-btn.sepia { background: #f4ede0; }
.theme-btn.light { background: #ffffff; }
.size-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--t3); border-radius: var(--radius-sm);
  padding: 0.2rem 0.6rem; cursor: pointer;
  font-family: var(--font-ui); font-size: 0.78rem;
  transition: all var(--ease);
}
.size-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Section nav footer */
.section-nav-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 3rem; padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  max-width: var(--reading-max); width: 100%;
}
.nav-prev, .nav-next {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.82rem; color: var(--t4);
  text-decoration: none; transition: color var(--ease);
  max-width: 200px;
}
.nav-prev:hover, .nav-next:hover { color: var(--accent); }
.nav-label { font-size: 0.68rem; color: var(--t5); display: block; margin-bottom: 0.15rem; }
.nav-title { line-height: 1.3; }

/* Catalog page */
.book-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  transition: all var(--ease); text-decoration: none; display: block;
}
.book-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.book-cover {
  height: 180px; display: flex; align-items: center; justify-content: center;
  font-size: 3rem; border-bottom: 1px solid var(--border);
}
.book-info { padding: 1rem; }
.book-title { font-family: var(--font-reading); font-size: 0.95rem; color: var(--t1); margin-bottom: 0.2rem; line-height: 1.35; }
.book-author { font-size: 0.72rem; color: var(--t4); margin-bottom: 0.5rem; }
.book-tags { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.book-tag {
  font-size: 0.6rem; padding: 2px 6px; border-radius: 3px;
  background: var(--surface2); color: var(--t5); border: 1px solid var(--border2);
}
.book-price {
  font-size: 0.82rem; font-weight: 500; color: var(--accent);
  margin-top: 0.5rem;
}

/* Locked overlay */
.locked-overlay {
  position: relative; overflow: hidden;
  border-radius: var(--radius-md);
}
.locked-overlay::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 30%, var(--bg) 100%);
  pointer-events: none;
}
.locked-cta {
  text-align: center; padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

/* Button */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.48rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 500;
  font-family: var(--font-ui); cursor: pointer;
  transition: opacity var(--ease); border: none;
}
.btn-primary { background: var(--accent); color: #0f0900; }
.btn-primary:hover { opacity: 0.88; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border2); color: var(--t3);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* Mobile */
@media (max-width: 768px) {
  .reader-sidebar { transform: translateX(-100%); }
  .reader-sidebar.mobile-open { transform: translateX(0); }
  .reading-area { margin-left: 0; padding: 1.5rem 1rem 5rem; }
  .books-topbar { padding: 0 1rem; }
  .topbar-title { display: none; }
  .notes-panel { width: 100%; }
}