:root {
  font-family: "Outfit", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color-scheme: light;
  --bg: #f7f8fb;
  --card: #ffffff;
  --border: rgba(31, 36, 48, 0.08);
  --text: #1f2430;
  --text-muted: #5b6378;
  --primary: #6a5acd;
  --primary-strong: #4b36b5;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11121b;
  --card: #151a28;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f7f8fb;
  --text-muted: #b6bbcc;
  --primary: #9b8bff;
  --primary-strong: #c0b4ff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Skip to content link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  z-index: 100;
  border-radius: 0 0 8px 0;
  font-weight: 600;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
}

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

a {
  color: inherit;
  text-decoration: none;
}

header {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-weight: 600;
}

.logo span {
  margin-right: 8px;
}

.library-nav {
  display: flex;
  gap: 12px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.library-nav a:hover,
.library-nav a:focus-visible {
  color: var(--primary);
}

.theme-toggle {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--card);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 81px);
  position: sticky;
  top: 81px;
}

.sidebar-header {
  padding: 20px;
}

.sidebar input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.article-list {
  list-style: none;
  margin: 0;
  padding: 0 0 40px;
  flex: 1;
  overflow-y: auto;
}

.article-list li {
  border-bottom: 1px solid var(--border);
}

.article-list button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 16px 20px;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.article-list button.active {
  background: rgba(106, 90, 205, 0.08);
  border-left: 4px solid var(--primary);
  padding-left: 16px;
}

.article-list button span {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.content {
  padding: 32px;
  overflow-y: auto;
  max-height: calc(100vh - 81px);
}

.content article {
  background: var(--card);
  border-radius: 24px;
  padding: 32px;
  border: 1px solid var(--border);
  box-shadow: 0 25px 35px rgba(31, 36, 48, 0.08);
}

.content h1 {
  margin-top: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.content .meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.content .article-body {
  line-height: 1.7;
}

.content .article-body h2,
.content .article-body h3,
.content .article-body h4 {
  margin-top: 1.6em;
}

.status {
  padding: 16px;
  border-radius: 16px;
  border: 1px dashed var(--border);
  background: rgba(106, 90, 205, 0.05);
  margin-bottom: 24px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Related Articles */
.related-articles {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.related-articles h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: var(--text);
}

.related-articles ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}

.related-articles li {
  padding: 12px 16px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: border-color 0.2s ease;
}

.related-articles li:hover {
  border-color: var(--primary);
}

.related-articles a {
  color: var(--text);
  font-weight: 500;
  display: block;
}

.related-articles a:hover {
  color: var(--primary);
}

/* Footer */
.library-footer {
  padding: 24px 32px;
  border-top: 1px solid var(--border);
  background: var(--card);
  text-align: center;
}

.library-footer .footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.library-footer .footer-links a {
  color: var(--text-muted);
}

.library-footer .footer-links a:hover {
  color: var(--primary);
}

.library-footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

/* Reading Time & Word Count */
.reading-time,
.word-count {
  display: inline;
}

.reading-time {
  font-weight: 500;
  color: var(--primary);
}

/* Table of Contents */
.article-toc {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 32px;
}

.article-toc summary {
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
}

.article-toc summary:hover {
  color: var(--primary);
}

.article-toc ul {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
}

.article-toc li {
  margin: 8px 0;
}

.article-toc .toc-h3 {
  padding-left: 16px;
  font-size: 0.9rem;
}

.article-toc a {
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.article-toc a:hover {
  color: var(--primary);
}

/* Loading Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg) 25%, var(--border) 50%, var(--bg) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 8px;
}

.skeleton-title {
  height: 40px;
  width: 70%;
  margin-bottom: 16px;
}

.skeleton-meta {
  height: 20px;
  width: 30%;
  margin-bottom: 24px;
}

.skeleton-line {
  height: 16px;
  margin-bottom: 12px;
}

.skeleton-line:nth-child(odd) {
  width: 100%;
}

.skeleton-line:nth-child(even) {
  width: 85%;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Responsive */
@media (max-width: 960px) {
  main {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .content {
    max-height: none;
  }

  .article-toc {
    margin-bottom: 24px;
  }
}

/* Print Stylesheet */
@media print {
  header,
  .sidebar,
  .theme-toggle,
  .article-toc details summary,
  .related-articles,
  .library-footer {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  main {
    display: block;
  }

  .content {
    padding: 0;
    max-height: none;
  }

  .content article {
    box-shadow: none;
    border: none;
    padding: 0;
  }

  .content h1 {
    font-size: 24pt;
    margin-bottom: 8pt;
  }

  .content .meta {
    font-size: 10pt;
    margin-bottom: 16pt;
  }

  .content .article-body {
    font-size: 11pt;
    line-height: 1.5;
  }

  .content .article-body h2 {
    font-size: 16pt;
    page-break-after: avoid;
  }

  .content .article-body h3 {
    font-size: 14pt;
    page-break-after: avoid;
  }

  .article-toc {
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .article-toc ul {
    columns: 2;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #666;
  }
}
