html, body { height: 100%; margin: 0; padding: 0; }
body.reader-page { overflow: hidden; background: #1a1a2e; }

#app {
  display: flex;
  height: 100vh;
  box-sizing: border-box;
}

/* --- Left Sidebar (TOC) --- */
#sidebar {
  width: 240px; min-width: 240px;
  background: #1a1a2e;
  color: #ccc;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #2a2a4e;
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
}

#sidebar.collapsed { width: 48px; min-width: 48px; }
#sidebar.collapsed #sidebar-header h1,
#sidebar.collapsed #sidebar-header .meta,
#sidebar.collapsed #sidebar-header .close-btn span,
#sidebar.collapsed #toc,
#sidebar.collapsed #sidebar-footer { display: none; }
#sidebar.collapsed #sidebar-header { padding: 12px 0; text-align: center; }
#sidebar.collapsed #sidebar-header .close-btn { margin: 0; }

#sidebar-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid #2a2a4e;
  display: flex; align-items: center;
}

#sidebar-header .close-btn {
  color: #888; text-decoration: none; font-size: 16px; line-height: 1;
  margin-right: 10px;
}
#sidebar-header .close-btn:hover { color: #fff; }
#sidebar-header .close-btn span { display: inline; }

#sidebar-toggle {
  background: none; border: none; color: #666; font-size: 16px;
  cursor: pointer; padding: 2px 4px; line-height: 1;
  margin-left: auto; transition: color 0.15s;
}
#sidebar-toggle:hover { color: #ddd; }
#sidebar.collapsed #sidebar-toggle { margin: 0; color: #888; }

#sidebar-header h1 {
  font-size: 14px; font-weight: 600; color: #ddd; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}

#sidebar-header .meta {
  font-size: 11px; color: #666; margin-top: 4px;
  flex-basis: 100%;
}

#toc {
  flex: 1; overflow-y: auto; padding: 6px 0;
}

#toc a {
  display: block; padding: 9px 18px;
  color: #999; text-decoration: none;
  font-size: 13px; line-height: 1.4;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
}

#toc a:hover { color: #ddd; background: rgba(255,255,255,0.03); }

#toc a.active {
  color: #fff; background: rgba(74,144,217,0.15);
  border-left-color: #4a90d9; font-weight: 600;
}

#sidebar-footer {
  padding: 10px 18px;
  border-top: 1px solid #2a2a4e;
}

#sidebar-footer .preview-label {
  font-size: 11px; color: #666; display: block; margin-bottom: 6px;
}

#sidebar-footer .buy-link {
  display: block; text-align: center; background: #4a90d9; color: #fff;
  padding: 9px; border-radius: 6px; text-decoration: none;
  font-size: 13px; font-weight: 600; transition: background 0.2s;
}
#sidebar-footer .buy-link:hover { background: #357abd; }

/* --- Top Bar --- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: 44px;
  background: linear-gradient(to bottom, rgba(26,26,46,0.92) 60%, rgba(26,26,46,0.7) 85%, transparent);
  color: #ccc;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
#topbar.visible { opacity: 1; pointer-events: auto; }

#topbar .tb-back {
  color: #888; text-decoration: none; font-size: 18px; line-height: 1;
  padding: 4px 6px 4px 0;
}
#topbar .tb-back:hover { color: #fff; }

#topbar .tb-title {
  font-size: 13px; font-weight: 600; color: #ddd;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}

#topbar .tb-btn {
  background: none; border: 1px solid rgba(255,255,255,0.15);
  color: #aaa; font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 3px;
  cursor: pointer; line-height: 1.4;
  transition: all 0.15s;
}
#topbar .tb-btn:hover { color: #fff; border-color: rgba(255,255,255,0.3); }
#topbar .tb-btn.active { color: #4a90d9; border-color: #4a90d9; }

#topbar .tb-divider {
  width: 1px; height: 18px; background: rgba(255,255,255,0.12);
}

/* Font sizes */
.chapter-content p  { transition: font-size 0.15s; }
.chapter-content h2 { transition: font-size 0.15s; }
.content-font-sm .chapter-content p  { font-size: 16px; }
.content-font-sm .chapter-content h2 { font-size: 20px; }
.content-font-md .chapter-content p  { font-size: 18px; }
.content-font-md .chapter-content h2 { font-size: 22px; }
.content-font-lg .chapter-content p  { font-size: 20px; }
.content-font-lg .chapter-content h2 { font-size: 24px; }

/* --- Content Area --- */
#content {
  flex: 1; overflow-y: auto; background: #fff;
  padding: 36px 44px;
}

.chapter-content {
  display: none;
  max-width: 700px;
  animation: fadeIn 0.3s ease;
}

.chapter-content.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chapter-content h2 {
  font-family: Georgia, "Literata", "Times New Roman", serif;
  font-size: 22px; font-weight: 700;
  color: #1a1a2e; margin: 0 0 6px;
}

.chapter-content .subheading-anchor { display: none; }

.chapter-content p {
  font-family: Georgia, "Literata", "Times New Roman", serif;
  font-size: 18px; line-height: 1.8;
  color: #333; margin: 0 0 18px;
}

.chapter-content img {
  max-width: 100%; height: auto; border-radius: 4px;
  margin: 16px 0;
}

.chapter-content blockquote {
  margin: 20px 0; padding: 12px 24px;
  background: #f5f5f5; border-left: 3px solid #4a90d9;
  font-style: italic; color: #555;
}
.chapter-content blockquote p { margin: 0; }

.chapter-content table {
  width: 100%; border-collapse: collapse; margin: 20px 0;
  font-size: 15px;
}

.chapter-content th, .chapter-content td {
  border: 1px solid #ddd; padding: 8px 12px; text-align: left;
}

.chapter-content th {
  background: #1a1a2e; color: #fff; font-weight: 600;
}

.chapter-content hr {
  border: none; border-top: 1px solid #eee; margin: 24px 0;
}

.chapter-content a { color: #4a90d9; }

/* --- Chapter Navigation --- */
.chapter-nav {
  display: flex;
  margin-top: 36px; padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.nav-link {
  padding: 8px 18px; border-radius: 5px;
  text-decoration: none; font-size: 13px; font-weight: 600;
  background: #f0f0f5; color: #1a1a2e;
  transition: background 0.2s;
  cursor: pointer;
}
.nav-link:hover { background: #e0e0ea; }
.nav-link.next { margin-left: auto; }

/* --- Edition Cards Below Content --- */
.editions-below {
  max-width: 700px;
  margin-top: 40px;
  padding-top: 32px;
  border-top: 2px solid #e0e0e0;
}

.editions-below h3 {
  font-size: 15px; font-weight: 600; color: #1a1a2e;
  margin: 0 0 16px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.edition-card-row {
  display: flex; gap: 16px; flex-wrap: wrap;
}

.edition-card-row .edition-card {
  flex: 1; min-width: 180px;
  background: #f8f8fb; border: 1px solid #e0e0e8;
  border-radius: 8px; padding: 20px;
  transition: box-shadow 0.2s;
}
.edition-card-row .edition-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }

.edition-card .edition-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 3px; margin-bottom: 10px;
}
.edition-badge.annotated { background: #4a90d9; color: #fff; }
.edition-badge.simple    { background: #27ae60; color: #fff; }
.edition-badge.fifteen   { background: #e67e22; color: #fff; }

.edition-card h4 {
  font-size: 15px; font-weight: 600; color: #1a1a2e; margin: 0 0 6px;
}

.edition-card p {
  font-size: 13px; color: #666; line-height: 1.5; margin: 0 0 14px;
}

.edition-card .buy-btn {
  display: inline-block; background: #4a90d9; color: #fff;
  padding: 7px 18px; border-radius: 5px; text-decoration: none;
  font-size: 13px; font-weight: 600; transition: background 0.2s;
}
.edition-card .buy-btn:hover { background: #357abd; }

/* --- Right Sidebar (Editions) --- */
#editions-sidebar {
  width: 110px; min-width: 110px;
  background: #f4f4f8;
  border-left: 1px solid #ddd;
  padding: 12px 10px;
  overflow-y: auto;
  display: flex; flex-direction: column;
  justify-content: center;
}

#editions-sidebar h3 {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: #888; margin: 0 0 10px;
  text-align: center;
}

#editions-sidebar .edition-card {
  background: #fff; border: 1px solid #e0e0e8;
  border-radius: 5px; padding: 10px 8px; margin-bottom: 8px;
  text-align: center;
  transition: box-shadow 0.2s;
}
#editions-sidebar .edition-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

#editions-sidebar .edition-badge {
  display: inline-block; font-size: 8px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 2px; margin-bottom: 6px;
}

#editions-sidebar .edition-card h4 {
  font-size: 11px; font-weight: 600; color: #1a1a2e; margin: 0 0 2px;
  line-height: 1.3;
}

#editions-sidebar .edition-card p {
  display: none;
}

#editions-sidebar .buy-btn {
  display: block; text-align: center;
  background: #4a90d9; color: #fff;
  padding: 5px 6px; border-radius: 3px; text-decoration: none;
  font-size: 10px; font-weight: 600; transition: background 0.2s;
}
#editions-sidebar .buy-btn:hover { background: #357abd; }

/* --- Responsive --- */
@media screen and (max-width: 1024px) {
  #editions-sidebar { display: none; }
}

@media screen and (max-width: 768px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; min-width: unset; max-height: 40vh; border-right: none; border-bottom: 1px solid #2a2a4e; }
  #content { padding: 20px 16px; }
  .chapter-content h2 { font-size: 20px; }
  .chapter-content p { font-size: 15px; }
  .edition-card-row { flex-direction: column; }
  .edition-card-row .edition-card { min-width: unset; }
}
