/* ============================================================
   Crafting Platforms — Online Book
   reading.css
   Brand: Inter font, dark purple #2c2438, orange #ec7d31
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --color-purple:       #2c2438;
  --color-purple-mid:   #3d3550;
  --color-orange:       #ec7d31;
  --color-orange-hover: #d96e20;
  --color-text:         #1a1a1a;
  --color-muted:        #555;
  --color-bg:           #fff;
  --color-bg-subtle:    #f8f7f5;
  --color-border:       #e5e3df;
  --sidebar-width:      320px;
  --reading-width:      720px;
  --font:               'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:          'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --top-bar-height:     56px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--color-text); background: var(--color-bg); }
a { color: var(--color-orange); }
a:hover { color: var(--color-orange-hover); }
img { max-width: 100%; height: auto; }

/* ---------- Layout shell ---------- */
/* Top bar and sidebar are position:fixed.
   .book-layout pushes content below the top bar.
   .reading-area and footer are offset by sidebar width. */
.book-layout {
  padding-top: var(--top-bar-height);
}

.layout-body {
  min-height: calc(100vh - var(--top-bar-height));
}

/* ---------- Top bar ---------- */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-height);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  background: var(--color-purple);
  color: #e8e6e3;
  z-index: 200;
  border-bottom: 2px solid var(--color-orange);
}

.top-bar-title {
  font-weight: 800;
  font-size: 1.35rem;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.top-bar-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-left: auto;
}

.top-bar-links a {
  color: rgba(232, 230, 227, 0.8);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s;
}
.top-bar-links a:hover { color: #fff; }

.btn-buy {
  background: var(--color-orange);
  color: #fff !important;
  padding: 0.35rem 0.9rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: background 0.2s !important;
}
.btn-buy:hover { background: var(--color-orange-hover) !important; }

/* Hamburger — hidden on desktop */
.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: #e8e6e3;
  border-radius: 2px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: var(--top-bar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--top-bar-height));
  background: var(--color-purple);
  color: #e8e6e3;
  border-right: 3px solid var(--color-orange);
  overflow-y: auto;
  z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: rgba(236,125,49,0.4) transparent;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding-bottom: 2rem;
}

/* Language switcher */
.lang-switcher {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
}
.lang-current {
  color: var(--color-orange);
  font-weight: 600;
}
.lang-link {
  color: rgba(232,230,227,0.6);
  text-decoration: none;
  transition: color 0.2s;
}
.lang-link:hover { color: #fff; }
.lang-switcher .lang-current ~ .lang-link::before,
.lang-switcher .lang-link ~ .lang-current::before,
.lang-switcher .lang-link ~ .lang-link::before {
  content: '·';
  margin-right: 0.5rem;
  color: rgba(232,230,227,0.3);
}

/* Chapter nav */
.chapter-nav {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0;
  flex: 1;
}
.chapter-nav li a {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.55rem 1.25rem;
  color: rgba(232,230,227,0.75);
  text-decoration: none;
  font-size: 0.85rem;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  border-right: 3px solid transparent;
}
.chapter-nav li a:hover {
  background: rgba(236,125,49,0.12);
  color: #fff;
}
.chapter-nav li.active > a {
  background: rgba(236,125,49,0.18);
  color: #fff;
  border-right-color: var(--color-orange);
  font-weight: 500;
}

.nav-num {
  font-size: 0.7rem;
  color: var(--color-orange);
  font-weight: 700;
  min-width: 1.6rem;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.nav-title { flex: 1; }


/* ---------- Reading area ---------- */
.reading-area {
  margin-left: var(--sidebar-width);
}

/* ---------- Chapter ---------- */
.chapter {
  max-width: var(--reading-width);
  margin: 0 auto;
  padding: 3rem 2.5rem 5rem;
}

.chapter-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-border);
}

.chapter-number-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-orange);
  margin-bottom: 0.5rem;
}

.chapter-title {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--color-purple);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0;
}

/* ---------- Chapter body typography ---------- */
.chapter-body {
  font-size: 1.075rem;
  line-height: 1.8;
  color: var(--color-text);
}

.chapter-body p { margin: 0 0 1.4rem; }

.chapter-body h2 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--color-purple);
  margin: 3rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--color-orange);
  letter-spacing: -0.01em;
}

.chapter-body h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-purple-mid);
  margin: 2.25rem 0 0.75rem;
}

.chapter-body h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-muted);
  margin: 1.75rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chapter-body strong { color: var(--color-purple); }

.chapter-body a {
  color: var(--color-orange);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.chapter-body a:hover { color: var(--color-orange-hover); }

/* Inline code */
.chapter-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  padding: 0.1em 0.4em;
  border-radius: 3px;
}

/* Code blocks */
.chapter-body pre {
  background: #1e1a2e;
  color: #e8e6e3;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  line-height: 1.6;
  margin: 1.5rem 0;
  border-left: 3px solid var(--color-orange);
}
.chapter-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  color: inherit;
}

/* Tables */
.chapter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}
.chapter-body th {
  background: var(--color-purple);
  color: #e8e6e3;
  padding: 0.6rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chapter-body td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.chapter-body tr:nth-child(even) td { background: var(--color-bg-subtle); }

/* Blockquote (standard) */
.chapter-body blockquote {
  border-left: 4px solid var(--color-border);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  color: var(--color-muted);
  font-style: italic;
}

/* Lists */
.chapter-body ul, .chapter-body ol {
  padding-left: 1.75rem;
  margin: 0 0 1.4rem;
}
.chapter-body li { margin-bottom: 0.4rem; }
.chapter-body li p { margin-bottom: 0.5rem; }

/* ---------- Epigraph ---------- */
.epigraph {
  border-left: 4px solid var(--color-orange);
  background: rgba(236, 125, 49, 0.04);
  padding: 0.9rem 1.5rem;
  margin: 0 0 2.5rem;
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--color-muted);
}
.epigraph p { margin: 0; font-size: 1.05rem; }
.epigraph-author {
  display: block;
  font-style: normal;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-orange);
  margin-top: 0.6rem;
}

/* ---------- Admonitions ---------- */
.admonition {
  padding: 0 1.25rem 1rem;
  border-radius: 6px;
  border-left: 4px solid;
  margin: 1.75rem 0;
  background: var(--color-bg-subtle);
}
.admonition-label {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.6rem 0 0.4rem;
  display: block;
}
.admonition-body > :first-child { margin-top: 0; }
.admonition-body > :last-child  { margin-bottom: 0; }

.admonition-note    { border-color: #4a90d9; }
.admonition-note    .admonition-label { color: #2563eb; }

.admonition-tip     { border-color: #34a853; }
.admonition-tip     .admonition-label { color: #16a34a; }

.admonition-warning { border-color: #e8a000; }
.admonition-warning .admonition-label { color: #d97706; }

.admonition-story   { border-color: var(--color-purple-mid); background: rgba(44, 36, 56, 0.04); }
.admonition-story   .admonition-label { color: var(--color-purple-mid); }

.admonition-skill   { border-color: var(--color-orange); background: rgba(236, 125, 49, 0.05); }
.admonition-skill   .admonition-label { color: var(--color-orange); }

.admonition-reading { border-color: #7c3aed; background: rgba(124, 58, 237, 0.04); }
.admonition-reading .admonition-label { color: #7c3aed; }

.admonition-placeholder { border-color: #9ca3af; background: #f3f4f6; }
.admonition-placeholder .admonition-label { color: #6b7280; }

.admonition-authornote { border-color: #9ca3af; background: #f9f9f7; }
.admonition-authornote .admonition-label { color: #6b7280; font-style: italic; }

/* ---------- Citations ---------- */
.citation { font-size: 0.875em; color: var(--color-muted); }
.citation a { color: inherit; }
.citation.missing { color: #dc2626; }

/* ---------- Mermaid ---------- */
code.language-mermaid {
  display: block;
  background: none;
  border: none;
  padding: 0;
}
.chapter-body pre:has(code.language-mermaid) {
  background: none;
  border: none;
  padding: 0;
}

/* ---------- Pagination (prev/next) ---------- */
.chapter-pagination {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 3rem 0 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}
.pagination-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--color-text);
  transition: border-color 0.2s, background 0.2s;
}
.pagination-item:hover {
  border-color: var(--color-orange);
  background: rgba(236,125,49,0.03);
  color: var(--color-text);
}
.pagination-next { text-align: right; }
.pagination-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-orange);
}
.pagination-title { font-weight: 500; font-size: 0.95rem; }

/* ---------- TOC CTA ---------- */
.toc-cta {
  margin-top: 2rem;
  max-width: 480px;
}

/* ---------- CTA box ---------- */
.cta-box {
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
}
.cta-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-orange);
  margin: 0 0 0.4rem;
}
.cta-body {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin: 0 0 0.9rem;
  line-height: 1.5;
}
.btn {
  display: block;
  text-align: center;
  padding: 0.55rem 1rem;
  border-radius: 5px;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  margin-bottom: 0.5rem;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.btn-primary {
  background: var(--color-orange);
  color: #fff;
}
.btn-primary:hover { background: var(--color-orange-hover); color: #fff; }
.btn-secondary {
  border: 1.5px solid var(--color-orange);
  color: var(--color-orange);
  background: transparent;
}
.btn-secondary:hover { background: var(--color-orange); color: #fff; }
.btn-tertiary {
  color: var(--color-muted);
  font-weight: 400;
  font-size: 0.8rem;
  text-align: center;
  padding: 0.3rem;
}
.btn-tertiary:hover { color: var(--color-orange); }
/* ---------- TOC page ---------- */
.toc-page { max-width: var(--reading-width); margin: 0 auto; padding: 3rem 2.5rem 5rem; }
.toc-intro { margin-bottom: 3rem; }
.toc-intro h1 { font-size: 5rem; font-weight: 800; color: var(--color-purple); letter-spacing: -0.04em; margin-bottom: 0.75rem; line-height: 1.05; }
.toc-intro p { font-size: 1.1rem; line-height: 1.75; color: var(--color-muted); }

.toc-chapter-list h2 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.toc-chapter-entry {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--color-text);
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.toc-chapter-entry:hover {
  border-color: var(--color-orange);
  background: rgba(236,125,49,0.03);
  transform: translateX(3px);
}
.toc-chapter-number {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-orange);
  min-width: 2rem;
  flex-shrink: 0;
}
.toc-chapter-meta { flex: 1; }
.toc-chapter-title { display: block; font-weight: 600; font-size: 1rem; }
.toc-chapter-desc { display: block; font-size: 0.875rem; color: var(--color-muted); margin-top: 0.2rem; }
.toc-chapter-arrow { color: var(--color-orange); font-size: 1.1rem; flex-shrink: 0; }

/* TOC — second-level sections */
.toc-chapter-block { margin-bottom: 0.5rem; }
.toc-section-list {
  list-style: none;
  margin: 0;
  padding: 0.15rem 0 0.4rem 3.5rem;
}
.toc-section-item a {
  display: block;
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
  color: var(--color-muted);
  text-decoration: none;
  border-left: 2px solid var(--color-border);
  margin-bottom: 0.1rem;
  transition: color 0.15s, border-color 0.15s;
}
.toc-section-item a:hover {
  color: var(--color-orange);
  border-color: var(--color-orange);
}

/* Sidebar — second-level sections */
.nav-section-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0.4rem 2.85rem;
}
.nav-section-item a {
  display: block;
  padding: 0.25rem 0.75rem 0.25rem 0.5rem;
  font-size: 0.78rem;
  color: rgba(232,230,227,0.5);
  text-decoration: none;
  border-left: 2px solid rgba(236,125,49,0.2);
  margin-bottom: 0.1rem;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.35;
}
.nav-section-item a:hover {
  color: rgba(232,230,227,0.9);
  border-color: var(--color-orange);
}

/* ---------- Footer ---------- */
.site-footer {
  margin-left: var(--sidebar-width);
  padding: 2rem 2.5rem;
  border-top: 1px solid var(--color-border);
}
.footer-inner { font-size: 0.85rem; color: var(--color-muted); }
.footer-inner p { margin: 0 0 0.4rem; }
.footer-links { display: flex; gap: 1.25rem; }
.footer-links a { color: var(--color-muted); text-decoration: none; }
.footer-links a:hover { color: var(--color-orange); }

/* ---------- Mobile (≤ 900px) ---------- */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* Overlay behind open sidebar */
  .sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }

  .reading-area, .site-footer {
    margin-left: 0;
  }

  .sidebar-toggle { display: flex; }

  .chapter, .toc-page { padding: 2rem 1.25rem 4rem; }

  .chapter-title { font-size: 1.75rem; }

  .chapter-pagination { grid-template-columns: 1fr; }

  .site-footer { padding: 1.5rem 1.25rem; }
}

@media (max-width: 480px) {
  .chapter-title { font-size: 1.5rem; }
  .chapter-body { font-size: 1rem; }
  .chapter-body h2 { font-size: 1.4rem; }
  .chapter-body pre { padding: 1rem; font-size: 0.8rem; }
}
