:root {
  --bg-color: #ffffff;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --border-color: #e5e7eb;
  --primary-color: #000000;
  --nav-bg: rgba(255, 255, 255, 0.8);
  --sidebar-bg: #f9fafb;
  --highlight-bg: #f3f4f6;
  --accent-color: #3291ff;
  --card-bg: #ffffff;
  --progress-bg: #000000;
}

[data-theme="dark"] {
  --bg-color: #0a0a0a;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --border-color: #27272a;
  --primary-color: #ffffff;
  --nav-bg: rgba(10, 10, 10, 0.8);
  --sidebar-bg: #171717;
  --highlight-bg: #262626;
  --accent-color: #3291ff;
  --card-bg: #171717;
  --progress-bg: #ffffff;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

/* Scroll Progress Indicator */
#scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background-color: var(--progress-bg);
  width: 0%;
  z-index: 9999;
  transition: width 0.1s ease;
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: var(--nav-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
  text-decoration: none;
  line-height: 1.05;
}

.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 4px;
  flex: 0 0 auto;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.brand__mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.brand__name {
  color: var(--primary-color);
  white-space: nowrap;
}

.brand__tagline {
  color: var(--text-secondary);
  font-size: 0.74rem;
  line-height: 1.1;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .brand {
    gap: 0.65rem;
  }

  .brand__mark {
    width: 34px;
    height: 34px;
    padding: 3px;
  }

  .brand__tagline {
    font-size: 0.68rem;
  }
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Main Layout */
.layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  gap: 3rem;
  min-height: calc(100vh - 160px);
}

/* Sidebar / Table of Contents */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  height: max-content;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-right: 1rem;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

.sidebar h3 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-link {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  display: block;
  transition: all 0.2s;
  border-left: 2px solid transparent;
}

.toc-link:hover {
  background-color: var(--highlight-bg);
  color: var(--text-primary);
}

.toc-link.active {
  color: var(--text-primary);
  font-weight: 500;
  border-left-color: var(--primary-color);
  background-color: var(--highlight-bg);
}

/* Content */
.content {
  flex-grow: 1;
  max-width: 800px;
}

.page-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

.page-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 1.125rem;
}

.legal-section {
  margin-bottom: 2.5rem;
  scroll-margin-top: 100px;
}

.legal-section h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--primary-color);
  letter-spacing: -0.01em;
}

.legal-section h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.legal-section p, 
.legal-section ul {
  margin-bottom: 1rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

.legal-section ul {
  padding-left: 1.5rem;
}

.legal-section li {
  margin-bottom: 0.5rem;
}

.highlight-box {
  background-color: var(--sidebar-bg);
  border-left: 4px solid var(--primary-color);
  padding: 1.25rem;
  border-radius: 0 8px 8px 0;
  margin: 1.5rem 0;
}

.highlight-box p:last-child {
  margin-bottom: 0;
}

/* Footer & NextFable Branding */
.footer {
  border-top: 1px solid var(--border-color);
  padding: clamp(2.25rem, 5vw, 3rem) 1.5rem 2.5rem;
  text-align: center;
  background:
    linear-gradient(180deg, transparent, rgba(148, 163, 184, 0.03)),
    var(--bg-color);
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 1120px;
  margin: 0 auto;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.4rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background-color: var(--card-bg);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.footer-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.6rem 0.95rem;
  border-radius: 999px;
  transition: all 0.2s ease;
}

.footer-link:hover {
  color: var(--text-primary);
  background-color: var(--highlight-bg);
}

.footer-note {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.35rem;
}

.nextfable-badge {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.48rem 0.7rem;
  border-radius: 999px;
  background-color: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.nextfable-badge:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
  background-color: var(--card-bg);
  color: var(--text-primary);
  border-color: var(--primary-color);
}

[data-theme="dark"] .nextfable-badge:hover {
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.nextfable-badge img {
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
  border-radius: 50%;
}

@media (max-width: 760px) {
  .nextfable-badge {
    left: 0.75rem;
    right: 0.75rem;
    justify-content: center;
  }

  .footer-links {
    width: 100%;
    border-radius: 20px;
    padding: 0.5rem;
  }

  .footer-link {
    width: calc(50% - 0.375rem);
    text-align: center;
  }

  .footer-note {
    margin-top: 0.5rem;
  }
}

/* Mobile Nav Toggle */
.mobile-nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
}

/* Responsive Design */
@media (max-width: 900px) {
  .layout {
    flex-direction: column;
    padding: 1rem;
  }
  
  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
    background-color: var(--sidebar-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    display: none; /* Hidden by default on mobile, toggled via JS */
  }

  .sidebar.active {
    display: block;
  }
  
  .mobile-toc-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 1rem;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-primary);
  }
  
  .mobile-toc-toggle svg {
    transition: transform 0.3s ease;
  }
  
  .mobile-toc-toggle.active svg {
    transform: rotate(180deg);
  }
  
  .content {
    max-width: 100%;
  }

  .page-header h1 {
    font-size: 2rem;
  }
}

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

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.legal-section {
  animation: fadeIn 0.5s ease-out forwards;
}

