/* ============================================================
   Book layout — sidebar + chapter content
   ============================================================ */

/* ---- Skip link (keyboard / screen-reader users) ---- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 9999;
  padding: 0.5rem 1rem;
  background: var(--accent-color);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0 0 4px 4px;
  text-decoration: none;
  transition: top 0.1s;
}

.skip-link:focus {
  top: 0;
}

.book-body {
  background: var(--bg-color);
}

/* Shell: sidebar + main side by side */
.book-shell {
  display: flex;
  min-height: calc(100vh - 58px);
}

/* ---- Sidebar ---- */
.book-nav {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-color);
  background: var(--bg-secondary);
  padding: 2rem 0 4rem;
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
}

.book-nav-header {
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.book-nav-title {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-color);
  text-decoration: none;
  display: block;
  line-height: 1.4;
}

.book-nav-title:hover {
  color: var(--accent-color);
  text-decoration: none;
}

.book-nav-description {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-secondary);
  font-family: var(--sans);
}

.book-nav-section {
  padding: 0.5rem 0 0.75rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.25rem;
}

.book-nav-part {
  display: block;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  padding: 0 1.25rem 0.4rem;
}

.book-nav ul {
  list-style: none;
}

.book-nav li a {
  display: block;
  padding: 0.28rem 1.25rem;
  font-size: 0.83rem;
  color: var(--text-secondary);
  text-decoration: none;
  line-height: 1.45;
  border-left: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.book-nav li a:hover {
  color: var(--accent-color);
  text-decoration: none;
  background: rgba(9, 105, 218, 0.06);
}

.book-nav li a:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: -2px;
  border-radius: 2px;
  color: var(--accent-color);
  background: rgba(9, 105, 218, 0.06);
}

.book-nav li a.active {
  color: var(--accent-color);
  font-weight: 600;
  border-left-color: var(--accent-color);
  background: rgba(9, 105, 218, 0.08);
}

/* ---- Chapter main ---- */
.book-main {
  flex: 1;
  min-width: 0;
  padding: 3rem 2.5rem 4rem;
  max-width: 780px;
}

/* ---- Headings inside book chapters ---- */
.book-main h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
  line-height: 1.2;
  color: var(--text-color);
}

.book-main h2 {
  font-family: var(--sans);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-color);
}

.book-main h2::before { content: ""; }

.book-main h3 {
  font-family: var(--sans);
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
  color: var(--text-color);
}

.book-main h3::before { content: ""; }

.book-main h4 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
  color: var(--text-color);
}

.book-main h4::before { content: ""; }

.book-main h5 {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
}

/* ---- Prose ---- */
.book-main p {
  margin-bottom: 1.2rem;
  line-height: 1.8;
  font-size: 1rem;
  color: var(--text-color);
  max-width: 68ch;
}

.book-main ul, .book-main ol {
  margin: 0.75rem 0 1.25rem 1.5rem;
  max-width: 68ch;
}

.book-main li {
  margin-bottom: 0.4rem;
  line-height: 1.7;
}

/* ---- Tables ---- */
.book-main table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin: 1.5rem 0;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.book-main th {
  background: var(--bg-secondary);
  text-align: left;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 2px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  white-space: nowrap;
  color: var(--text-secondary);
  font-family: var(--mono);
}

.book-main td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  vertical-align: top;
  line-height: 1.5;
}

.book-main tr:nth-child(even) td {
  background: var(--bg-secondary);
}

/* ---- Code blocks ---- */
.book-main pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.6;
  margin: 1.25rem 0;
}

.book-main pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* ---- Blockquote / callout ---- */
.book-main blockquote {
  border-left: 3px solid var(--accent-color);
  background: rgba(9, 105, 218, 0.04);
  padding: 0.9rem 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 6px 6px 0;
}

.book-main blockquote p {
  margin-bottom: 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* ---- Book cover hero (landing page) ---- */
.book-cover-hero {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
  margin-bottom: 2.5rem;
}

.book-cover-img {
  width: 200px;
  flex-shrink: 0;
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(31, 35, 40, 0.18);
  display: block;
}

.book-cover-meta {
  flex: 1;
  min-width: 0;
}

.book-cover-meta h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
  line-height: 1.15;
}

.book-subtitle {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem !important;
}

.book-author {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent-color);
  margin-bottom: 1rem !important;
}

.book-description {
  font-size: 0.97rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

@media (max-width: 600px) {
  .book-cover-hero {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .book-cover-img { width: 160px; }
}

/* ---- Inline figures inside chapters ---- */
.book-main figure {
  margin: 2rem 0;
  max-width: 100%;
}

.book-main figure img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.book-main figcaption {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  line-height: 1.5;
  font-style: italic;
}

/* ---- Chapter footer ---- */
.book-chapter-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-family: var(--mono);
  line-height: 1.6;
  max-width: 68ch;
}

.book-chapter-footer p { margin: 0; max-width: none; }

/* ---- Mobile nav toggle ---- */
.book-nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .book-shell {
    flex-direction: column;
  }

  .book-nav {
    position: fixed;
    top: 0;
    left: -280px;
    height: 100vh;
    width: 260px;
    z-index: 200;
    transition: left 0.2s ease;
    box-shadow: none;
  }

  .book-nav.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }

  .book-nav-toggle {
    display: inline-block;
  }

  .book-main {
    padding: 1.75rem 1.25rem 3rem;
  }
}
