/* ===================================================================
   Orange Book Reader — extends Natural Island theme
=================================================================== */

.book-reader-page {
  --book-content-max: 44rem;
  --book-sidebar-width: 20rem;
}

.book-main {
  padding-bottom: 4rem;
}

.book-reader-page .book-main {
  padding-top: calc(var(--header-height) + 1.25rem);
}

.book-breadcrumb {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.book-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.book-breadcrumb a:hover {
  text-decoration: underline;
}

.book-breadcrumb [aria-current="page"] {
  color: var(--ink);
}

.book-hero {
  padding-top: 1rem;
  padding-bottom: 1rem;
}

/* 覆盖全站 page-hero 的 58vh 最小高度，避免标题区与正文之间留白过大 */
.book-reader-page .book-hero.page-hero {
  min-height: 0;
  display: block;
  padding-top: 1.25rem;
  padding-bottom: 0.75rem;
}

.book-hero .hero-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
}

.book-reader-page .book-hero .hero-tag {
  margin-bottom: 0.65rem;
}

.book-hero-title {
  font-family: var(--font-serif);
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  line-height: 1.3;
  color: var(--ink);
  margin-bottom: 1rem;
}

.book-hero-title span {
  display: block;
  font-size: 0.72em;
  font-weight: 600;
  color: var(--accent-light);
  margin-top: 0.35rem;
}

.book-lead {
  margin: 0 0 1.25rem;
  padding: 1rem 1.15rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-panel) var(--radius-panel) 0;
  background: var(--accent-bg);
  color: var(--ink-soft);
  font-size: 0.98rem;
  line-height: 1.7;
}

.book-lead p {
  margin: 0;
}

.book-start-actions {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.book-layout {
  display: grid;
  grid-template-columns: minmax(var(--book-sidebar-width), 22rem) minmax(0, 1fr);
  gap: 2.25rem;
  align-items: start;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px 2rem;
}

.book-reader-page .book-layout.section-inner {
  padding-top: 0;
}

.book-layout-index {
  padding-top: 0;
}

.book-toc {
  position: sticky;
  top: calc(var(--header-height) + 1rem);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--header-height) - 2rem);
  overflow: hidden;
  padding: 1rem 0.85rem 1rem 1rem;
  border: 1px solid var(--border-light);
  border-radius: var(--card-radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
}

.book-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.book-toc-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}

.book-toc-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--accent);
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-panel);
  cursor: pointer;
}

.book-toc-list {
  list-style: none;
  margin: 0;
  padding: 0 0.15rem 0 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.book-toc-list li {
  margin: 0;
}

.book-toc-list a {
  display: -webkit-box;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.38;
  color: var(--ink-soft);
  text-decoration: none;
  overflow-wrap: anywhere;
  word-break: normal;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.book-toc-list a:hover {
  background: var(--accent-bg);
  color: var(--accent);
}

.book-toc-list .is-active a {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.book-toc-home {
  display: block;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.82rem;
  color: var(--accent);
  text-decoration: none;
  flex-shrink: 0;
}

.book-toc::-webkit-scrollbar,
.book-toc-list::-webkit-scrollbar {
  width: 6px;
}

.book-toc::-webkit-scrollbar-thumb,
.book-toc-list::-webkit-scrollbar-thumb {
  background: rgba(45, 90, 61, 0.22);
  border-radius: 999px;
}

.book-toc::-webkit-scrollbar-thumb:hover,
.book-toc-list::-webkit-scrollbar-thumb:hover {
  background: rgba(45, 90, 61, 0.38);
}

.book-toc-home:hover {
  text-decoration: underline;
}

.book-content {
  min-width: 0;
  max-width: var(--book-content-max);
}

.book-prose {
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.78;
}

.book-prose > *:first-child {
  margin-top: 0;
}

.book-prose h2,
.book-prose h2.prose-h1 {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  color: var(--ink);
  margin: 2.25rem 0 0.85rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-light);
}

.book-prose h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--ink-soft);
  margin: 1.75rem 0 0.65rem;
}

.book-prose h4 {
  font-size: 1rem;
  color: var(--ink-soft);
  margin: 1.25rem 0 0.5rem;
}

.book-prose p,
.book-prose ul,
.book-prose ol {
  margin: 0 0 1rem;
}

.book-prose ul,
.book-prose ol {
  padding-left: 1.35rem;
}

.book-prose li {
  margin-bottom: 0.35rem;
}

.book-prose blockquote {
  margin: 1.25rem 0;
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--accent-border);
  background: rgba(255, 255, 255, 0.55);
  color: var(--text-secondary);
}

.book-prose blockquote p {
  margin: 0;
}

.book-prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(45, 90, 61, 0.08);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.book-prose pre {
  margin: 1rem 0 1.25rem;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border-radius: var(--radius-panel);
  background: #1e2a24;
  color: #e8efe9;
  font-size: 0.86rem;
  line-height: 1.55;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

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

.book-prose .table-wrap {
  overflow-x: auto;
  margin: 1rem 0 1.25rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-panel);
  background: rgba(255, 255, 255, 0.65);
}

.book-prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.5;
}

.book-prose th,
.book-prose td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  vertical-align: top;
}

.book-prose th {
  background: var(--accent-bg);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}

/* 书目首页「完整目录」等双列表格：首列给足宽度，减少标题折行 */
.book-prose .table-wrap td:first-child {
  min-width: 13.5rem;
  width: 44%;
  vertical-align: top;
}

.book-prose .table-wrap td:first-child a {
  line-height: 1.45;
}

.book-prose tr:last-child td {
  border-bottom: 0;
}

.book-prose hr {
  border: 0;
  border-top: 1px solid var(--border-light);
  margin: 2rem 0;
}

.book-prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.book-prose a:hover {
  color: var(--accent-hover);
}

.book-link-soon {
  cursor: not-allowed;
  opacity: 0.65;
  text-decoration: none !important;
}

.book-link-unresolved {
  text-decoration-style: dashed;
  opacity: 0.85;
}

.book-prose a[href^="http"]:not([href*="daoark.com"])::after {
  content: "";
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  margin-left: 0.15em;
  vertical-align: -0.05em;
  background: currentColor;
  opacity: 0.45;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3'/%3E%3C/svg%3E") center / contain no-repeat;
}

.book-prose pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.book-prose img {
  max-width: 100%;
  height: auto;
  border-radius: calc(var(--card-radius) * 0.5);
}

.book-prose .task-item {
  list-style: none;
  margin-left: -0.35rem;
  padding-left: 0.15rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.book-prose .task-box {
  flex-shrink: 0;
  width: 1.05rem;
  height: 1.05rem;
  margin-top: 0.35rem;
  border: 2px solid var(--accent-border);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.8);
}

.book-prose .task-box.is-checked {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px #fff;
}

.book-prose li.task-item.is-done {
  color: var(--text-secondary);
}

.book-prose kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
  padding: 0.15em 0.45em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-card);
}

.book-prose :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media print {
  .book-toc,
  .chapter-nav,
  .book-breadcrumb,
  header,
  footer,
  .book-start-actions {
    display: none !important;
  }

  .book-layout {
    display: block;
  }

  .book-content {
    max-width: none;
  }
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: stretch;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-light);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-light);
  border-radius: var(--card-radius);
  background: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  transition: border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}

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

.chapter-nav-prev {
  text-align: left;
}

.chapter-nav-next {
  text-align: right;
}

.chapter-nav-index {
  align-self: center;
  justify-self: center;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  background: var(--bg-card);
}

.chapter-nav-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.chapter-nav-title {
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.4;
}

.chapter-nav-prev.is-empty,
.chapter-nav-next.is-empty {
  visibility: hidden;
}

@media (min-width: 1100px) {
  .book-reader-page {
    --book-sidebar-width: 22rem;
  }
}

@media (min-width: 769px) {
  .book-reader-page .book-main {
    padding-top: calc(var(--header-height) + 1.75rem);
  }

  .book-reader-page .book-hero.page-hero {
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
  }

  .book-reader-page .book-hero-title {
    margin-bottom: 0.6rem;
  }

  .book-reader-page .book-lead {
    margin-bottom: 0;
    padding: 0.75rem 1rem;
  }

  .book-reader-page .book-layout {
    gap: 1.75rem;
    padding-top: 0;
    margin-top: 0;
  }

  .book-reader-page .book-start-actions {
    margin-top: 1rem;
  }
}

@media (max-width: 768px) {
  .book-reader-page .book-main {
    padding-top: calc(var(--header-height) + 1rem);
  }

  /* 避免与全站 .page-hero 的 padding-top 叠加 */
  .book-reader-page .book-hero.page-hero {
    padding-top: 0.85rem;
  }
}

@media (max-width: 1024px) {
  .book-layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .book-toc {
    position: static;
    max-height: none;
    display: block;
    overflow: visible;
    padding: 1rem;
  }

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

  .book-toc-list {
    display: none;
    flex: none;
    max-height: none;
    overflow: visible;
  }

  .book-toc-list.is-open {
    display: block;
    max-height: min(60vh, 28rem);
    overflow-y: auto;
  }
}

@media (max-width: 768px) {
  .chapter-nav {
    grid-template-columns: 1fr;
  }

  .chapter-nav-next {
    text-align: left;
  }

  .chapter-nav-index {
    order: -1;
    width: 100%;
    text-align: center;
  }

  .book-start-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .book-start-actions .cta-btn,
  .book-start-actions .btn-secondary {
    text-align: center;
  }
}
