/* ==========================================================================
   Shared Post Stylesheet: Typography, Layout & Floating TOC
   Used across all essays on ncray.com
   ========================================================================== */

:root {
  --font-serif: "Newsreader", Georgia, serif;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", Menlo, Consolas, monospace;

  /* Light Theme */
  --bg: #faf9f6;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f1ea;
  --bg-elevated: #ffffff;
  --text-main: #1c1917;
  --text-muted: #66615c;
  --border: #e6e2db;
  --border-subtle: #eeece6;

  --accent: #b45309;
  --accent-soft: #fef3c7;
  --accent-hover: #92400e;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --bg-surface: #1c1b1a;
    --bg-subtle: #242220;
    --bg-elevated: #282624;
    --text-main: #f4f1ea;
    --text-muted: #a39e95;
    --border: #2e2b28;
    --border-subtle: #262422;

    --accent: #f59e0b;
    --accent-soft: #2e2413;
    --accent-hover: #fbbf24;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  }
}

html {
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  color: var(--text-main);
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  line-height: 1.78;
  padding: 2.5rem 1.25rem 6rem;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------------------
   Content Typography & Vertical Rhythm
   -------------------------------------------------------------------------- */
p {
  margin-bottom: 1.5rem;
}

h2 {
  font-family: var(--font-sans);
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 3.75rem 0 1.15rem;
  color: var(--text-main);
  border-bottom: 2px solid var(--border-subtle);
  padding-bottom: 0.4rem;
  scroll-margin-top: 3rem;
}

h3 {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 2.5rem 0 0.75rem;
  color: var(--text-main);
  scroll-margin-top: 3rem;
}

h4 {
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.75rem 0 0.5rem;
  color: var(--text-main);
}

ul, ol {
  margin: 1rem 0 1.5rem 1.5rem;
}

li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 0 0.75rem 1.25rem;
  margin: 1.75rem 0;
  font-style: italic;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-radius: 0 8px 8px 0;
}


/* --------------------------------------------------------------------------
   Layout Grid & Container
   -------------------------------------------------------------------------- */
.layout-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  position: relative;
}

@media (min-width: 1140px) {
  .layout-wrapper {
    grid-template-columns: 240px minmax(0, 780px);
    gap: 3.5rem;
    justify-content: center;
  }
}

.container {
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

@media (min-width: 1140px) {
  .container {
    margin: 0;
  }
}

.back-nav {
  margin-bottom: 2.5rem;
}

.back-nav a {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.15s ease;
}

.back-nav a:hover {
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   Post Header, Byline & Typography
   -------------------------------------------------------------------------- */
header {
  margin-bottom: 3.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.meta-tag {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  margin-bottom: 1.25rem;
  text-decoration: none;
}

header h1 {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-main);
  margin-bottom: 1rem;
}

@media (max-width: 640px) {
  header h1 {
    font-size: 2rem;
  }
}

.subtitle {
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-style: italic;
}

.byline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Desktop Sticky Floating Sidebar Table of Contents
   -------------------------------------------------------------------------- */
.toc-sidebar {
  display: none;
}

@media (min-width: 1140px) {
  .toc-sidebar {
    display: block;
    position: relative;
  }

  .toc-sticky-wrap {
    position: sticky;
    top: 2.5rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    padding-right: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }

  .toc-header {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
    padding-left: 0.75rem;
  }

  .toc-nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    border-left: 2px solid var(--border);
    padding-left: 0;
  }

  .toc-link {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.35rem 0.75rem;
    border-left: 2px solid transparent;
    margin-left: -2px;
    transition: all 0.15s ease;
    border-radius: 0 4px 4px 0;
  }

  .toc-link:hover {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--bg-subtle);
  }

  .toc-link.active {
    color: var(--accent);
    font-weight: 600;
    border-left-color: var(--accent);
    background: var(--bg-subtle);
  }
}

/* --------------------------------------------------------------------------
   Mobile Floating Action Pill Button & Slide-in Drawer TOC
   -------------------------------------------------------------------------- */
.mobile-toc-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 99;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.65rem 1.15rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.2s ease;
}

.mobile-toc-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

@media (min-width: 1140px) {
  .mobile-toc-toggle {
    display: none;
  }
}

.mobile-toc-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  display: flex;
  justify-content: flex-end;
}

.mobile-toc-drawer.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-toc-content {
  width: 85%;
  max-width: 340px;
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  box-sizing: border-box;
}

.mobile-toc-drawer.open .mobile-toc-content {
  transform: translateX(0);
}

.mobile-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.mobile-toc-title {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.mobile-toc-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem 0.5rem;
}

.mobile-toc-close:hover {
  color: var(--text-main);
}

.mobile-toc-links {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.mobile-toc-links a {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.mobile-toc-links a:hover,
.mobile-toc-links a.active {
  color: var(--accent);
  background: var(--bg-subtle);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Post Footer
   -------------------------------------------------------------------------- */
footer {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}
