/**
 * layout.css — Page Layout & Structural Styles
 * ═══════════════════════════════════════════════════════════════
 * Header, footer, sidebar, main container, responsive grid.
 * Minimal GitHub structure — no decorative backgrounds.
 * ═══════════════════════════════════════════════════════════════
 */

/* ── 1. Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--mb-bg);
  color: var(--mb-text);
}

/* ── 2. Header ───────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--mb-bg);
  border-bottom: 1px solid var(--mb-border);
}

.header-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: 44px;
  max-width: 1280px;
  margin: 0 auto;
}

.site-logo {
  font-family: "JetBrains Mono", monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--mb-text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.site-logo:hover { color: var(--mb-accent); text-decoration: none; }
.site-logo .logo-dot { color: var(--mb-accent); }
.site-logo-svg {
  color: var(--mb-accent);   /* currentColor in SVG picks this up */
  flex-shrink: 0;
  vertical-align: middle;
  margin-right: 0.45rem;
  transition: color 0.2s ease;
}

.header-spacer { flex: 1; }

/* Desktop nav */
.nav-desktop {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}
.nav-desktop a {
  display: block;
  padding: 0.3rem 0.65rem;
  font-size: 0.875rem;
  color: var(--mb-text-muted);
  text-decoration: none;
  border-radius: var(--pico-border-radius-sm);
}
.nav-desktop a:hover {
  color: var(--mb-text);
  background: var(--mb-surface-2);
}
.nav-desktop a.active {
  color: var(--mb-accent);
}

/* Header controls (search icon, etc.) */
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--mb-border);
  border-radius: var(--pico-border-radius-sm);
  background: transparent;
  color: var(--mb-text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}
.header-icon-btn:hover {
  color: var(--mb-text);
  background: var(--mb-surface-2);
  border-color: var(--mb-border-focus);
}

/* Hamburger (mobile) */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--mb-border);
  border-radius: var(--pico-border-radius-sm);
  cursor: pointer;
  padding: 0;
}
.hamburger span {
  display: block;
  width: 16px;
  height: 1px;
  background: var(--mb-text-muted);
  transition: background 0.1s;
}
.hamburger:hover span { background: var(--mb-text); }

/* "More ▾" overflow dropdown */
.nav-more {
  position: relative;
}
.nav-more-btn {
  font-size: 0.875rem;
  font-family: inherit;
  width: auto;
  padding: 0.3rem 0.65rem;
}
.nav-more-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--mb-surface-1);
  border: 1px solid var(--mb-border);
  min-width: 160px;
  z-index: 200;
  flex-direction: column;
}
.nav-more-dropdown.open { display: flex; }
.nav-more-dropdown a {
  display: block;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--mb-text-muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 1px solid var(--mb-border);
}
.nav-more-dropdown a:last-child { border-bottom: none; }
.nav-more-dropdown a:hover {
  background: var(--mb-surface-2);
  color: var(--mb-text);
}

/* Mobile nav */
.nav-mobile {
  display: none;
  flex-direction: column;
  border-top: 1px solid var(--mb-border);
  background: var(--mb-bg);
}
.nav-mobile.active { display: flex; }
.nav-mobile a {
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  color: var(--mb-text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--mb-border);
}
.nav-mobile a:hover {
  background: var(--mb-surface-2);
  color: var(--mb-text);
}
.nav-mobile a:last-child { border-bottom: none; }

/* ── 3. Main Content ─────────────────────────────────────────── */
.site-main {
  padding: 2rem 1rem;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  /* Contain any overflowing child elements */
  overflow-x: clip;
}

/* Content + sidebar layout */
.content-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  min-width: 0;
  overflow: clip;
}
.content-layout > * {
  min-width: 0;
  overflow: hidden;
}
.content-layout > aside {
  overflow: visible;
  min-width: 0;
}
@media (min-width: 1024px) {
  /* Closed: article + tab strip */
  .content-layout {
    grid-template-columns: 1fr 52px;
  }
  /* Open: article + full sidebar */
  .content-layout.toc-open {
    grid-template-columns: 1fr 260px;
  }
  .content-layout .post-content {
    max-width: none;
  }
  .content-layout.no-sidebar {
    grid-template-columns: 1fr;
  }
}

.site-main {
  flex: 1;
}

/* ── 4. Footer ───────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--mb-border);
  padding: 1.25rem 1rem;
  background: var(--mb-bg);
  margin-top: 0;
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--mb-text-faint);
  font-family: "JetBrains Mono", monospace;
}

.footer-inner a {
  color: var(--mb-text-faint);
  text-decoration: none;
}
.footer-inner a:hover { color: var(--mb-accent); }

.footer-links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer-legal {
  width: 100%;
  font-size: 0.7rem;
  color: var(--mb-text-faint);
  font-family: "JetBrains Mono", monospace;
  opacity: 0.5;
  margin-top: 0.25rem;
}

/* ── 5. Posts Grid ───────────────────────────────────────────── */

.posts-grid {
  display: grid;
  gap: 2rem;
  grid-template-columns: repeat(3, 1fr);
  border-radius: var(--pico-border-radius);
  overflow: hidden;
}

@media (max-width: 1100px) {
  .posts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 700px) {
  .posts-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.posts-grid.single-column {
  grid-template-columns: 1fr;
}

/* ── 6. Section header ───────────────────────────────────────── */
.section-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1.2rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  justify-content: space-between;
}
.section-header-title {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--mb-text-faint);
  text-transform: none;
  letter-spacing: 0.03em;
}
.section-header-slash {
  color: var(--mb-border-focus);
  font-size: 1.1em;
  font-family: "JetBrains Mono", monospace;
  margin-right: 0.5rem;
}
.section-header-meta {
  font-size: 0.92rem;
  color: var(--mb-text-faint);
  font-family: "JetBrains Mono", monospace;
  margin-bottom: 0.1rem;
}
@media (max-width: 600px) {
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  .section-header-title {
    font-size: 0.78rem;
  }
  .section-header-meta {
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
  }
}

/* Section description */
.section-description {
  font-size: 1.05rem;
  color: var(--mb-text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
  font-family: var(--pico-font-family-sans-serif);
  letter-spacing: 0.01em;
}

/* ── 7. Scroll to top ────────────────────────────────────────── */
.scroll-to-top {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 36px;
  height: 36px;
  border: 1px solid var(--mb-border);
  border-radius: var(--pico-border-radius-sm);
  background: var(--mb-surface-2);
  color: var(--mb-text-muted);
  cursor: pointer;
  font-size: 1rem;
  align-items: center;
  justify-content: center;
  z-index: 90;
  text-decoration: none;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.scroll-to-top.show { display: flex; }
.scroll-to-top:hover {
  background: var(--mb-surface-3);
  color: var(--mb-accent);
  border-color: var(--mb-border-focus);
}

/* ── 8. Responsive breakpoints ───────────────────────────────── */
@media (max-width: 768px) {
  .nav-desktop  { display: none; }
  .hamburger    { display: flex; }

  .posts-grid {
    grid-template-columns: 1fr;
  }

  .site-main { padding: 1rem 0.75rem; }
}

@media (max-width: 480px) {
  .header-container { height: 48px; }
  .site-logo { font-size: 0.9rem; }
}
