/* ==========================================================================
   Kasuti — The Complete Encyclopedia
   Design system: black ground + warm Kasuti palette (red/orange/yellow/purple),
   echoing the traditional Chandrakali colour scheme (Ch.5, Ch.8).
   ========================================================================== */

:root {
  --ink: #1c1410;
  --paper: #faf6ef;
  --paper-soft: #f2ead9;
  --black: #171210;
  --red: #a6321f;
  --orange: #c2661a;
  --yellow: #d1a017;
  --purple: #5b3159;
  --line: #e2d5bd;
  --muted: #6b5f4f;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --max: 1180px;
  --radius: 6px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.65;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--yellow); color: var(--black); padding: 10px 16px; z-index: 200;
}
.skip-link:focus { left: 10px; top: 10px; }

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; color: var(--black); line-height: 1.2; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.site-header {
  background: var(--black);
  color: var(--paper);
  position: sticky; top: 0; z-index: 100;
  border-bottom: 3px solid var(--red);
}
.header-inner {
  max-width: var(--max); margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--paper); }
.brand:hover { text-decoration: none; opacity: .9; }
.brand-mark { color: var(--yellow); display: inline-flex; }
.brand-text { font-family: var(--serif); font-size: 1.3rem; letter-spacing: .04em; }
.brand-text em { font-style: italic; color: var(--orange); font-weight: 500; }

.nav-toggle {
  display: none;
  background: none; border: 1px solid #444; border-radius: 4px;
  width: 38px; height: 34px; cursor: pointer; padding: 0;
  flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.nav-toggle span { width: 20px; height: 2px; background: var(--paper); display: block; }

.header-search { flex: 1; position: relative; max-width: 520px; }
.header-search input {
  width: 100%; padding: 9px 14px; border-radius: 20px; border: 1px solid #3a332c;
  background: #241d18; color: var(--paper); font-family: var(--sans); font-size: .92rem;
}
.header-search input::placeholder { color: #a89d8d; }
.header-search input:focus { outline: 2px solid var(--yellow); }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--paper); color: var(--ink); border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0,0,0,.35); max-height: 420px; overflow-y: auto; z-index: 150;
}
.search-results a {
  display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink);
}
.search-results a:hover { background: var(--paper-soft); text-decoration: none; }
.search-results .sr-title { font-weight: 700; color: var(--red); display: block; }
.search-results .sr-part { font-size: .78rem; color: var(--muted); }
.search-results .sr-excerpt { font-size: .85rem; color: var(--ink); display: block; margin-top: 2px; }
.search-results .sr-empty { padding: 14px; color: var(--muted); font-size: .9rem; }
mark { background: var(--yellow); color: var(--black); padding: 0 2px; }

.top-links { display: flex; gap: 16px; white-space: nowrap; }
.top-links a { color: var(--paper); font-size: .92rem; }
.top-links a:hover { color: var(--yellow); }

/* ---------- Layout ---------- */
.layout { display: flex; max-width: var(--max); margin: 0 auto; align-items: flex-start; }
.sidebar {
  width: 300px; flex-shrink: 0; padding: 24px 18px; border-right: 1px solid var(--line);
  position: sticky; top: 58px; max-height: calc(100vh - 58px); overflow-y: auto;
}
.sidebar-title { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; margin-bottom: 10px; color: var(--purple); }
.toc-part { margin-bottom: 16px; }
.toc-part-title { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 4px; }
.toc-chapters { list-style: none; margin: 0; padding: 0; }
.toc-chapters li a {
  display: flex; gap: 8px; padding: 5px 6px; border-radius: 4px; color: var(--ink); font-size: .88rem;
}
.toc-chapters li a:hover { background: var(--paper-soft); text-decoration: none; }
.toc-chapters li a.active { background: var(--red); color: #fff; }
.chnum { color: var(--orange); font-weight: 700; width: 1.4em; flex-shrink: 0; }
.toc-chapters li a.active .chnum { color: var(--yellow); }

.content { flex: 1; min-width: 0; padding: 0 0 60px; }

/* ---------- Hero ---------- */
.hero { background: var(--black); color: var(--paper); padding: 50px 20px; }
.hero-inner { max-width: var(--max); margin: 0 auto; display: flex; gap: 40px; align-items: center; }
.hero-cover { width: 260px; flex-shrink: 0; border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.eyebrow { color: var(--yellow); text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; margin: 0 0 10px; }
.hero h1 { font-size: 2.6rem; margin: 0 0 14px; color: #fff; }
.hero h1 span { color: var(--orange); font-style: italic; font-weight: 500; }
.lede { font-size: 1.08rem; color: #d8cfc0; max-width: 60ch; }
.hero-ctas { display: flex; gap: 14px; margin-top: 20px; flex-wrap: wrap; }
.btn { padding: 11px 20px; border-radius: 30px; font-size: .92rem; font-weight: 600; display: inline-block; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: #8a2a1a; text-decoration: none; }
.btn-ghost { border: 1px solid #55483a; color: var(--paper); }
.btn-ghost:hover { background: #241d18; text-decoration: none; }

/* ---------- Sections ---------- */
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 20px; }
.how-to-use, .stitch-preview, .toc-section { padding: 48px 20px; }
.how-to-use { background: var(--paper-soft); }
.how-to-use h2, .stitch-preview h2, .toc-section h2 { text-align: center; font-size: 1.9rem; margin-bottom: 28px; }
.use-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.use-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; border-top: 4px solid var(--orange); }
.use-card h3 { margin-top: 0; color: var(--red); }
.use-card a { font-size: .88rem; font-weight: 600; }

.stitch-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.stitch-card { text-align: center; background: var(--paper-soft); border-radius: var(--radius); padding: 16px; }
.stitch-card img { width: 100%; height: 110px; object-fit: contain; background: #fff; border-radius: 4px; }
.stitch-card h4 { margin: 12px 0 4px; color: var(--purple); }
.stitch-card p { font-size: .84rem; color: var(--muted); margin: 0; }

.toc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 30px 44px; }
.toc-part-card h3 { color: var(--purple); border-bottom: 2px solid var(--yellow); padding-bottom: 6px; font-size: 1.15rem; }
.toc-part-card ol { padding-left: 20px; margin: 10px 0; }
.toc-part-card li { margin-bottom: 4px; font-size: .95rem; }

/* ---------- Chapter page ---------- */
.chapter-wrap { max-width: 840px; margin: 0 auto; padding: 40px 24px 20px; }
.chapter-eyebrow { text-transform: uppercase; letter-spacing: .07em; font-size: .78rem; color: var(--orange); font-weight: 700; margin: 0 0 6px; }
.chapter-title { font-size: 2.1rem; margin: 0 0 28px; border-bottom: 3px solid var(--yellow); padding-bottom: 16px; }

.chapter-body h2 { font-size: 1.5rem; color: var(--red); margin-top: 2.2em; }
.chapter-body h3 { font-size: 1.2rem; color: var(--purple); margin-top: 1.8em; }
.chapter-body p { margin: 1em 0; }
.chapter-body ul, .chapter-body ol { padding-left: 1.4em; }
.chapter-body li { margin-bottom: .5em; }
.chapter-body table {
  width: 100%; border-collapse: collapse; margin: 1.6em 0; font-size: .92rem;
}
.chapter-body th, .chapter-body td {
  border: 1px solid var(--line); padding: 9px 12px; text-align: left; vertical-align: top;
}
.chapter-body th { background: var(--paper-soft); font-family: var(--serif); font-weight: 700; color: var(--purple); }
.chapter-body tr:nth-child(even) td { background: #fdfaf3; }
.chapter-body em { color: var(--muted); }
.chapter-body code { background: var(--paper-soft); padding: 1px 5px; border-radius: 3px; }

blockquote.img-placeholder {
  border: 2px dashed var(--orange);
  background: #fff8ec;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 1.6em 0;
  font-size: .88rem;
  color: var(--muted);
}
blockquote.img-placeholder p { margin: 4px 0; }
blockquote.img-placeholder strong { color: var(--red); }

.chapter-pager {
  max-width: 840px; margin: 40px auto 0; padding: 24px; display: flex; justify-content: space-between;
  gap: 18px; border-top: 1px solid var(--line);
}
.pager-link { max-width: 45%; }
.pager-label { display: block; font-size: .75rem; text-transform: uppercase; color: var(--orange); font-weight: 700; }
.pager-title { display: block; font-family: var(--serif); font-size: 1.05rem; color: var(--ink); }
.pager-next { text-align: right; margin-left: auto; }

/* ---------- Footer ---------- */
.site-footer { background: var(--black); color: #cfc4b3; padding: 34px 20px; }
.footer-inner { max-width: var(--max); margin: 0 auto; font-size: .88rem; }
.footer-links a { color: var(--yellow); }
.footer-note { color: #8f8474; font-size: .8rem; margin-top: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .use-grid { grid-template-columns: 1fr; }
  .stitch-grid { grid-template-columns: repeat(2, 1fr); }
  .toc-grid { grid-template-columns: 1fr; }
  .hero-inner { flex-direction: column; text-align: center; }
  .hero-cover { width: 200px; }
}
@media (max-width: 760px) {
  .nav-toggle { display: flex; }
  .top-links { display: none; }
  .sidebar {
    position: fixed; left: -320px; top: 0; height: 100vh; background: var(--paper);
    width: 300px; z-index: 300; transition: left .25s ease; box-shadow: 6px 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { left: 0; }
  .header-search { order: 3; width: 100%; max-width: none; margin-top: 8px; }
  .header-inner { flex-wrap: wrap; }
}
