*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --line: #c9c3b8;
  --paper: #f7f3ea;
  --paper-edge: #e8e0d2;
  --accent: #7a4b2a;
  --shadow: rgba(40, 30, 20, 0.12);
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Noto Sans", Tahoma, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, #fff9ef 0%, var(--paper) 45%, #efe7da 100%);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  width: min(760px, calc(100% - 2rem));
  margin: 2.5rem auto 3rem;
  padding: 3rem 3.25rem 2.5rem;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  box-shadow:
    0 18px 40px var(--shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.book-header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--ink);
}

.book-label {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent);
}

.book-title {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 700;
  line-height: 1.2;
}

.book-subtitle {
  margin: 0.75rem 0 0;
  font-size: 1.05rem;
  color: var(--muted);
}

.book-meta {
  margin: 1rem 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.toc {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc-chapter {
  margin-top: 1.25rem;
}

.toc-chapter:first-child {
  margin-top: 0;
}

.toc-chapter-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.toc-entry {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 0.65rem;
  padding: 0.45rem 0;
  border-bottom: 1px dotted var(--line);
}

.toc-entry.is-section {
  padding-left: 1.25rem;
}

.toc-number {
  min-width: 2rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

.toc-title {
  line-height: 1.5;
  word-break: break-word;
}

.toc-title span {
  display: inline;
}

.toc-page {
  min-width: 5.5rem;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: var(--muted);
}

.toc-entry a {
  display: contents;
  color: inherit;
  text-decoration: none;
}

.toc-entry a:hover .toc-title span {
  color: var(--accent);
  text-decoration: underline;
}

.toc-entry a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.loading,
.error {
  margin: 0;
  padding: 1rem 0;
  text-align: center;
  color: var(--muted);
}

.error {
  color: #8b2e2e;
}

.book-footer {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .page {
    width: calc(100% - 1rem);
    margin: 1rem auto 2rem;
    padding: 2rem 1.25rem 1.75rem;
  }

  .toc-entry {
    grid-template-columns: auto 1fr auto;
    gap: 0.45rem;
  }

  .toc-entry.is-section {
    padding-left: 0.75rem;
  }
}

@media print {
  body {
    background: #fff;
  }

  .page {
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
  }
}
