/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg:               #faf9f6;
  --text:             #1c1c1a;
  --text-muted:       #6f6a5c;
  --accent:           #b0362c;
  --accent-hover:     #8a2a22;
  --accent-soft:      rgba(176,54,44,0.04);
  --border:           #e5e0d5;
  --muted-label:      #8a8578;
  --quote-bg:         #f1ece0;
  --code-bg:          #f1ece0;
  --code-text:        #8a4a3a;
  --sidebar-bg:       #1c1c1a;
  --sidebar-border:   #2e2c27;
  --sidebar-text:     #9e977f;
  --sidebar-text-active: #faf9f6;
  --sidebar-hover-bg: #272521;
  --search-bg:        #272521;
  --search-border:    #3a372f;
  --sidebar-width:    280px;
  --content-max:      720px;
  --font-serif:       'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-sans:         'Public Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Reset / Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 17px; }

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
  transition: color 0.15s, text-decoration-color 0.15s;
}
a:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}

/* ── Layout ─────────────────────────────────────────────────── */
#layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-border) transparent;
}

#sidebar-header {
  padding: 1.75rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#site-title {
  display: block;
  text-decoration: none;
  color: var(--sidebar-text-active);
}
#site-title:hover { color: var(--accent); }

.title-main {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}

#nav-search {
  width: 100%;
  background: var(--search-bg);
  border: 1px solid var(--search-border);
  border-radius: 4px;
  color: var(--sidebar-text-active);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  padding: 0.5rem 0.7rem;
}
#nav-search::placeholder { color: var(--sidebar-text); }
#nav-search:focus {
  outline: none;
  border-color: var(--accent);
}

#sidebar-nav {
  padding: 0.75rem 0 2rem;
  flex: 1;
}

.nav-top {
  list-style: none;
  padding: 0 0 0.5rem;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 0.5rem;
}

.nav-top li a {
  display: block;
  padding: 0.35rem 1.25rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-top li a:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}
.nav-top li a.active {
  border-left-color: var(--accent);
  color: var(--sidebar-text-active);
  background: var(--sidebar-hover-bg);
  font-weight: 500;
}

.nav-category {
  margin-top: 0.25rem;
}
.nav-category.nav-category-hidden { display: none; }

.nav-category-title {
  display: block;
  padding: 0.75rem 1.25rem 0.2rem;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-label);
  text-decoration: none;
  cursor: default;
}

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

.nav-category ul li a {
  display: block;
  padding: 0.3rem 1.25rem 0.3rem 1.5rem;
  font-family: var(--font-sans);
  font-size: 0.825rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-left: 2px solid transparent;
  line-height: 1.4;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-category ul li a:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}
.nav-category ul li a.active {
  border-left-color: var(--accent);
  color: var(--sidebar-text-active);
  background: var(--sidebar-hover-bg);
  font-weight: 500;
}
.nav-category ul li.nav-link-hidden { display: none; }

/* ── Menu toggle (mobile) ───────────────────────────────────── */
#menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 300;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  font-size: 1.2rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}

/* ── Main content ───────────────────────────────────────────── */
#content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 4rem 2.5rem 6rem;
}

#page {
  width: 100%;
  max-width: var(--content-max);
}

/* ── Loading ────────────────────────────────────────────────── */
.loading {
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem 0;
}

/* ── Pattern header ─────────────────────────────────────────── */
.pattern-header {
  margin-bottom: 2.5rem;
  padding-bottom: 0.5rem;
}

.pattern-breadcrumb {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-label);
  margin-bottom: 0.6rem;
}

.pattern-header h1 {
  font-family: var(--font-serif);
  font-size: 2.15rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.pattern-aka {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-muted);
}
.pattern-aka strong {
  font-weight: 600;
  color: #3d3a33;
}

/* ── Page header (intro, about, contents) ───────────────────── */
.page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  font-family: var(--font-serif);
  font-size: 2.15rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}

/* ── Landing / Contents page ────────────────────────────────── */
.landing-header {
  margin-bottom: 0.5rem;
}

.landing-title {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

.landing-byline {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
}

.landing-description {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.75;
  margin: 1.5rem 0 2.5rem;
}

/* ── TOC blocks (Background, Featured Patterns, All Patterns) ── */
.toc-block {
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.toc-block:last-child { border-bottom: none; margin-bottom: 0; }

.toc-section-heading {
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.toc-category-group { margin-top: 1.5rem; }
.toc-category-group:first-of-type { margin-top: 0; }

.toc-category-subhead {
  font-family: var(--font-sans);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.65rem;
}

.toc-featured-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.toc-featured-pattern {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  text-decoration: none;
  transition: border-color 0.12s, background 0.12s;
}
.toc-featured-pattern:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.toc-featured-pattern.related-broken {
  cursor: default;
}
.toc-featured-pattern.related-broken:hover {
  border-color: var(--border);
  background: none;
}

.toc-featured-title {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent);
  line-height: 1.3;
}
.toc-featured-pattern.related-broken .toc-featured-title { color: var(--text); }

.toc-featured-summary {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ── Markdown body typography ───────────────────────────────── */
.prose h2 {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #3d3a33;
  margin: 2.75rem 0 0.85rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}
.prose h2:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: #2a2820;
  margin: 1.75rem 0 0.5rem;
}

.prose p, .prose li {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.75;
  color: #2a2820;
}

.prose p {
  margin-bottom: 1.1rem;
}

.prose ul, .prose ol {
  padding-left: 1.4rem;
  margin-bottom: 1.1rem;
}

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

.prose li::marker {
  color: var(--accent);
}

.prose strong {
  font-weight: 600;
  color: #2a2820;
}

.prose em {
  font-style: italic;
}

.prose blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  font-family: var(--font-serif);
  font-size: 1rem;
  font-style: italic;
  color: #5c574a;
}
.prose blockquote p { margin-bottom: 0; }

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

.prose code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  color: var(--code-text);
}

.broken-link {
  color: var(--text-muted);
  border-bottom: 1px dashed var(--text-muted);
}

/* Related patterns section */
.related-patterns {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.related-patterns h2 {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 0.85rem;
  padding-top: 0;
  border-top: none;
}

/* ── Prev / Next footer nav ─────────────────────────────────── */
.pattern-pagination {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.pattern-pagination .pagination-prev,
.pattern-pagination .pagination-next {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--accent);
  text-decoration: none;
}
.pattern-pagination .pagination-next { text-align: right; margin-left: auto; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  #menu-toggle {
    display: block;
  }

  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  #sidebar-backdrop.open {
    display: block;
  }

  #content {
    margin-left: 0;
    padding: 5rem 1.25rem 4rem;
  }

  .pattern-header h1,
  .page-header h1 {
    font-size: 1.7rem;
  }

  .toc-featured-grid { grid-template-columns: 1fr; }

}

@media (max-width: 480px) {
  html { font-size: 16px; }
  #content { padding: 4.5rem 1rem 3rem; }
}
