/* Fonts */
@font-face {
  font-family: 'Merriweather';
  src: url('fonts/merriweather-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Merriweather';
  src: url('fonts/merriweather-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('fonts/inter-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('fonts/inter-bold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: rgb(29, 45, 53);
  background: #FFFFFF;
  line-height: 1.6;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Merriweather', Georgia, serif;
  line-height: 1.3;
  margin-bottom: 1rem;
  font-weight: 700;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 2rem;
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  padding-top: 1rem;
}

h3 {
  font-size: 1.5rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
}

h4 {
  font-size: 1.25rem;
  margin-top: 1.5rem;
  margin-bottom: 0.875rem;
}

p {
  margin-bottom: 1.25rem;
  line-height: 1.8;
}

a {
  color: rgb(29, 45, 53);
  text-decoration: underline;
  transition: opacity 0.2s;
}

a:hover {
  opacity: 0.7;
}

strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

code.inline {
  background: #f4f4f4;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.9em;
}

/* Top Navigation */
.top-nav {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid #e5e5e5;
}

.top-nav a {
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
}

.top-nav-sep {
  margin: 0 0.5rem;
  color: #999;
  font-size: 0.95rem;
}

/* Hero Section */
.hero {
  max-width: 900px;
  margin: 0 auto;
  padding: 6rem 2rem 4rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(29, 45, 53, 0.02) 0%, rgba(29, 45, 53, 0) 100%);
  border-bottom: 1px solid rgba(29, 45, 53, 0.1);
}

.hero h1 {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.hero .subtitle {
  font-size: 1.5rem;
  color: rgba(29, 45, 53, 0.7);
  margin-bottom: 2.5rem;
  font-weight: 400;
  line-height: 1.4;
}

.cta-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  padding: 0.875rem 1.75rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.2s;
}

.btn.primary {
  background: rgb(29, 45, 53);
  color: white;
}

.btn.primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn.secondary {
  background: white;
  color: rgb(29, 45, 53);
  border: 2px solid rgb(29, 45, 53);
}

.btn.secondary:hover {
  background: rgb(29, 45, 53);
  color: white;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 4rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* Sidebar TOC */
.toc-sidebar {
  position: sticky;
  top: 1rem;
  align-self: start;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  /* Hide scrollbar but keep functionality */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.toc-sidebar::-webkit-scrollbar {
  display: none; /* Chrome/Safari/Opera */
}

.toc-sidebar nav {
  padding: 0;
}

.toc-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-sidebar li {
  margin: 0;
}

.toc-sidebar a {
  display: block;
  padding: 0.75rem 0;
  text-decoration: none;
  font-size: 1rem;
  line-height: 1.5;
  color: #666;
  transition: color 0.15s ease;
  border-bottom: 1px solid #f0f0f0;
}

.toc-sidebar a:hover {
  color: rgb(29, 45, 53);
}

.toc-sidebar a.active {
  color: rgb(29, 45, 53);
  font-weight: 600;
}

.toc-sidebar .toc-level-2 {
  margin-top: 0;
}

.toc-sidebar .toc-level-2 > a {
  font-weight: 500;
  padding: 1rem 0;
  font-size: 1.05rem;
  border-bottom: 1px solid #e5e5e5;
}

.toc-sidebar .toc-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
  background: #fafafa;
}

.toc-sidebar .toc-level-3 a {
  padding: 0.65rem 0 0.65rem 1.5rem;
  font-size: 0.95rem;
  border-bottom: 1px solid #f5f5f5;
  color: #777;
}

.toc-sidebar .toc-level-3 a:hover {
  color: rgb(29, 45, 53);
  background: #f5f5f5;
}

.toc-sidebar .toc-level-3:last-child a {
  border-bottom: 1px solid #e5e5e5;
}

/* Mobile TOC Toggle */
.toc-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 48px;
  height: 48px;
  background: white;
  border: 2px solid rgb(29, 45, 53);
  border-radius: 8px;
  cursor: pointer;
  z-index: 1000;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 0;
}

.toc-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: rgb(29, 45, 53);
  transition: all 0.3s;
}

/* Scroll to Top Button */
.scroll-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 48px;
  height: 48px;
  background: rgb(29, 45, 53);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s, transform 0.2s;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.scroll-to-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
}

/* Content */
.content {
  max-width: 740px;
  min-width: 0;
}

.content figure {
  margin: 2rem 0;
  text-align: center;
}

.content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 6px;
}

.content figure + p {
  text-align: center;
  font-size: 0.9rem;
  color: #666;
  font-style: italic;
  margin-top: 0.5rem;
}

.content ul, .content ol {
  margin-bottom: 1.25rem;
  padding-left: 2rem;
}

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

.content blockquote {
  border-left: 4px solid #e5e5e5;
  padding-left: 1.5rem;
  margin: 1.5rem 0;
  font-style: italic;
  color: #666;
}

.content hr {
  border: none;
  border-top: 1px solid #e5e5e5;
  margin: 3rem 0;
}

/* Footer */
footer {
  text-align: center;
  padding: 3rem 2rem;
  border-top: 1px solid #e5e5e5;
  margin-top: 4rem;
}

footer a {
  margin: 0 1rem;
  text-decoration: none;
  font-size: 0.9rem;
  color: #666;
}

footer a:hover {
  color: rgb(29, 45, 53);
}

/* Glossary Terms */
.glossary-term {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: #999;
  text-underline-offset: 2px;
  cursor: help;
  color: inherit;
  transition: text-decoration-color 0.2s;
}

.glossary-term:hover {
  text-decoration-color: rgb(29, 45, 53);
}

/* Glossary Modal */
.glossary-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.glossary-modal.visible {
  display: flex;
}

.glossary-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
}

.glossary-modal-content {
  position: relative;
  background: white;
  max-width: 600px;
  max-height: 80vh;
  width: 90%;
  margin: 2rem;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow-y: auto;
  animation: slideUp 0.3s ease;
  z-index: 1;
}

.glossary-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  color: #999;
  padding: 0.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.glossary-modal-close:hover {
  background: #f0f0f0;
  color: rgb(29, 45, 53);
}

.glossary-modal-term {
  margin: 0 0 1rem 0;
  padding-right: 3rem;
  font-size: 1.75rem;
  color: rgb(29, 45, 53);
}

.glossary-modal-definition {
  color: #333;
  line-height: 1.7;
}

.glossary-modal-definition p {
  margin-bottom: 1rem;
}

.glossary-modal-definition p:last-child {
  margin-bottom: 0;
}

.glossary-modal-definition code.inline {
  background: #f4f4f4;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.9em;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

body.modal-open {
  overflow: hidden;
}

/* Responsive */
@media (max-width: 768px) {
  .hero {
    padding: 4rem 1.5rem 3rem;
  }

  .hero h1 {
    font-size: 2.25rem;
  }

  .hero .subtitle {
    font-size: 1.125rem;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 2rem 1rem;
  }

  .toc-sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    width: 80%;
    max-width: 320px;
    height: 100vh;
    background: white;
    padding: 5rem 2rem 2rem;
    transition: right 0.3s;
    z-index: 999;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  }

  .toc-sidebar.open {
    right: 0;
  }

  .toc-toggle {
    display: flex;
  }

  body.toc-open::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 998;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.25rem;
  }

  .glossary-modal-content {
    max-width: 100%;
    margin: 1rem;
    padding: 1.5rem;
    max-height: 85vh;
  }

  .glossary-modal-term {
    font-size: 1.5rem;
  }
}

/* Reading Progress Bar */
.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(29, 45, 53, 0.1);
  z-index: 9999;
}

.reading-progress-fill {
  height: 100%;
  background: rgb(29, 45, 53);
  width: 0%;
  transition: width 0.1s ease-out;
}

/* Heading Anchor Links */
.heading-anchor {
  margin-left: 0.5rem;
  opacity: 0;
  color: rgba(29, 45, 53, 0.4);
  text-decoration: none;
  transition: opacity 0.2s, color 0.2s;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.heading-anchor:hover {
  opacity: 1 !important;
  color: rgb(29, 45, 53);
}

.heading-anchor.copied {
  color: #059669;
  opacity: 1 !important;
}

.content h2:hover .heading-anchor,
.content h3:hover .heading-anchor {
  opacity: 0.6;
}

.heading-anchor svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 768px) {
  .heading-anchor {
    opacity: 0.4;
  }

  .heading-anchor svg {
    width: 16px;
    height: 16px;
  }
}

/* Copy Toast Notification */
.copy-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgb(29, 45, 53);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 10000;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.copy-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
