/* Shared Design System matching index.html */

html {
  color-scheme: light dark;
  scroll-behavior: smooth;
}

body {
  font-family: ui-sans-serif, system-ui, sans-serif;
  line-height: 1.6;
  max-width: 680px;
  margin: 0; /* Keeps it strictly left-aligned */
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}

@media (min-width: 768px) {
  body {
    padding: 48px;
  }
}

/* Site Header Navigation */
.site-header {
  margin-bottom: 0.8em;
  font-size: 0.9rem;
}

.site-header a {
  color: rgba(128, 128, 128, 0.85);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

.site-header a:hover {
  color: #0066cc;
  text-decoration: underline;
}

@media (prefers-color-scheme: dark) {
  .site-header a {
    color: rgba(255, 255, 255, 0.65);
  }
  .site-header a:hover {
    color: #4d9fff;
  }
}

/* Byline Metadata */
.byline {
  font-size: 0.9rem;
  color: rgba(70, 70, 70, 0.9);
  margin-top: -0.5em;
  margin-bottom: 1em;
}

.byline a {
  color: var(--text, #171717);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.byline a:hover {
  color: #0066cc;
}

@media (prefers-color-scheme: dark) {
  .byline {
    color: rgba(255, 255, 255, 0.82);
  }
  .byline a {
    color: #f3f4f6;
  }
  .byline a:hover {
    color: #4d9fff;
  }
}

/* Headings */
h1 {
  margin-top: 0;
  margin-bottom: 0.4em;
  line-height: 1.25;
}

h2, h3, h4 {
  line-height: 1.3;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

h2 {
  font-size: 1.4rem;
  padding-bottom: 0.3em;
  border-bottom: 1.5px solid rgba(128, 128, 128, 0.35);
}

@media (prefers-color-scheme: dark) {
  h2 {
    border-bottom-color: rgba(255, 255, 255, 0.25);
  }
}

hr {
  border: 0;
  height: 1.5px;
  background-color: rgba(128, 128, 128, 0.35);
  margin: 2.2em 0;
}

@media (prefers-color-scheme: dark) {
  hr {
    background-color: rgba(255, 255, 255, 0.25);
  }
}

h3 {
  font-size: 1.15rem;
}

p, ul, ol {
  margin-bottom: 1em;
}

li {
  margin-bottom: 8px;
}

a {
  color: #0066cc;
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover {
  color: #004499;
}

@media (prefers-color-scheme: dark) {
  a {
    color: #4d9fff;
  }
  a:hover {
    color: #80bfff;
  }
}

/* Code & Media */
code {
  font-family: ui-monospace, monospace;
  font-size: 0.95em;
  background-color: rgba(128, 128, 128, 0.15);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

pre {
  background-color: rgba(128, 128, 128, 0.12);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.95em;
}

pre code {
  padding: 0;
  background: transparent;
}

blockquote, .callout {
  margin: 1.2em 0;
  padding: 12px 18px;
  border-left: 3.5px solid #0066cc;
  background-color: rgba(0, 102, 204, 0.05);
  border-radius: 0 6px 6px 0;
}

@media (prefers-color-scheme: dark) {
  blockquote, .callout {
    border-left-color: #4d9fff;
    background-color: rgba(77, 159, 255, 0.08);
  }
}

img, video {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 0.8em 0;
  border: 1px solid rgba(128, 128, 128, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  transition: opacity 0.15s ease;
}

a.img-link {
  text-decoration: none;
  display: block;
}

p:has(> a.img-link) {
  margin-bottom: 0;
}

a.img-link img {
  margin: 0.4em 0 0 0;
}

#introduction {
  margin-top: 0.8em !important;
}

a.img-link:hover img {
  opacity: 0.92;
}

@media (prefers-color-scheme: dark) {
  img, video {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

/* ----------------------------------------------------
   Table of Contents (#TOC) - Floating Button on Mobile / Fixed Sidebar on Desktop
---------------------------------------------------- */
#TOC ul {
  list-style-type: none;
  padding-left: 0;
  margin: 0;
}

#TOC ul ul {
  padding-left: 16px;
  margin-top: 4px;
}

#TOC li {
  margin-bottom: 6px;
}

#TOC a {
  text-decoration: none;
  opacity: 0.85;
  color: inherit;
  line-height: 1.35;
  display: inline-block;
  overflow-wrap: break-word;
  word-break: break-word;
  transition: opacity 0.15s ease;
}

#TOC a:hover {
  text-decoration: underline;
  opacity: 1;
}

/* Mobile (< 1050px): Out-of-flow zero-height container to eliminate layout shift */
@media (max-width: 1049px) {
  details#TOC {
    position: fixed !important;
    bottom: 0 !important;
    right: 0 !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    overflow: visible !important;
    pointer-events: none !important;
  }

  details#TOC summary {
    pointer-events: auto !important;
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 1000 !important;
    cursor: pointer;
    user-select: none;
    list-style: none;
    -webkit-appearance: none;
    appearance: none;
    width: 48px !important;
    height: 48px !important;
    flex-shrink: 0;
    box-sizing: border-box;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background-color: rgba(245, 245, 247, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(128, 128, 128, 0.22) !important;
    font-size: 1.1rem !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
    transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
    opacity: 0.85;
    -webkit-tap-highlight-color: transparent;
  }

  details#TOC summary::-webkit-details-marker,
  details#TOC summary::marker {
    display: none;
    content: "";
  }

  details#TOC summary:hover, details#TOC summary:active {
    opacity: 1;
    transform: scale(1.05);
  }

  details#TOC[open] summary {
    background-color: rgba(0, 102, 204, 0.9) !important;
    color: #ffffff !important;
    border-color: #0066cc !important;
    opacity: 1;
  }

  details#TOC[open] summary span {
    font-size: 0;
  }

  details#TOC[open] summary span::after {
    content: "✕";
    font-size: 1.1rem;
    font-weight: bold;
  }

  details#TOC > ul {
    pointer-events: auto !important;
    position: fixed;
    bottom: 76px;
    right: 16px;
    width: min(85vw, 280px);
    max-width: calc(100vw - 32px);
    box-sizing: border-box;
    max-height: 55vh;
    overflow-y: scroll;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    z-index: 999;
    background-color: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(128, 128, 128, 0.25);
    border-radius: 14px;
    padding: 16px 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    font-size: 0.875rem;
  }

  @media (prefers-color-scheme: dark) {
    details#TOC summary {
      background-color: rgba(26, 29, 38, 0.9) !important;
      color: #f3f4f6 !important;
      border-color: rgba(255, 255, 255, 0.2) !important;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
    }

    details#TOC[open] summary {
      background-color: rgba(77, 159, 255, 0.9) !important;
      color: #111827 !important;
      border-color: #4d9fff !important;
    }

    details#TOC > ul {
      background-color: rgba(22, 25, 34, 0.78);
      border-color: rgba(255, 255, 255, 0.2);
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }
  }
}

/* Desktop (>= 1050px): Classic Fixed Right Sidebar */
@media (min-width: 1050px) {
  details#TOC {
    position: fixed;
    top: 48px;
    left: min(760px, calc(100vw - 250px));
    width: 220px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    margin: 0;
    background-color: rgba(128, 128, 128, 0.08);
    border: 1px solid rgba(128, 128, 128, 0.18);
    border-radius: 8px;
    padding: 16px 20px;
    font-size: 0.9rem;
    backdrop-filter: blur(8px);
  }

  details#TOC summary {
    position: static;
    width: auto;
    height: auto;
    border-radius: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    pointer-events: none;
    list-style: none;
    font-weight: bold;
    margin-bottom: 10px;
    opacity: 0.9;
    padding: 0;
    display: block;
  }

  details#TOC summary::-webkit-details-marker {
    display: none;
  }

  details#TOC summary span::after {
    content: "Table of Contents";
  }

  details#TOC summary span {
    font-size: 0;
  }

  details#TOC summary span::after {
    font-size: 0.9rem;
  }

  details#TOC > ul {
    display: block !important;
  }
}
