/* WaifuAI unified site theme
   Shared across docs/content pages (research-books, research-text, reasoning-pricer,
   ai-benchmarks, book-generator, blog-posts, and top-level hub pages).
   web-apps/ demo apps intentionally keep their own bespoke styling. */

:root {
  --bg: #0d1117;
  --card-bg: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #ff6b9d;
  --accent2: #c084fc;
  --accent3: #60a5fa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: 2rem;
}

/* Plain content/article pages (no .container wrapper) get their reading width here */
body.doc-page { max-width: 900px; margin: 0 auto; }

/* Hub/index pages wrap their content in .container */
.container { max-width: 1100px; margin: 0 auto; }

header { text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; border-bottom: 1px solid var(--border); }
header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2), var(--accent3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}
header p { color: var(--text-muted); font-size: 1.1rem; }
header .links, header .back { margin-top: 1rem; }
header .links a, header .back {
  color: var(--accent3);
  margin: 0 0.5rem;
  font-size: 0.9rem;
  text-decoration: none;
}
header .links a:hover, header .back:hover { text-decoration: underline; }

section { margin-bottom: 2.5rem; }

h1 { font-size: 2.25rem; font-weight: 700; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; margin-bottom: 0.5rem; color: var(--text); }
h2 { font-size: 1.4rem; margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); color: var(--text); display: flex; align-items: baseline; gap: 0.5rem; }
h3 { color: var(--accent3); margin-top: 1.5rem; }

.count { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }
.section-desc { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

.link-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.link-list a {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.link-list a:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(255, 107, 157, 0.15); }
.link-list a h3 { color: var(--text); font-size: 1.1rem; margin: 0 0 0.25rem; }
.link-list a p { color: var(--text-muted); font-size: 0.85rem; margin: 0; }

a { color: var(--accent3); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Keyboard focus: visible on every interactive element, on any background */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Skip link — first focusable element on a page, hidden until tabbed to */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 0 0 6px 0;
  padding: 0.6rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

article, .readme-content { font-size: 1.02rem; }
article h1, article h2, article h3, .readme-content h1, .readme-content h2, .readme-content h3 { color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 0.3em; margin: 1.8rem 0 0.8rem; }
article h1, .readme-content h1 { font-size: 1.7rem; }
article h2, .readme-content h2 { font-size: 1.4rem; }
article h3, .readme-content h3 { font-size: 1.15rem; }
article p, .readme-content p { margin: 0.9rem 0; }
article ul, article ol, .readme-content ul, .readme-content ol { margin: 0.9rem 0; padding-left: 1.6rem; }
article li, .readme-content li { margin: 0.35rem 0; }
article a, .readme-content a { color: var(--accent3); }
article strong, .readme-content strong { color: #fff; }
article em, .readme-content em { color: var(--text); }

pre { background: var(--card-bg); padding: 1rem; border-radius: 6px; overflow-x: auto; border: 1px solid var(--border); margin: 1rem 0; }
code { background: var(--card-bg); padding: 0.2em 0.4em; border-radius: 3px; font-size: 0.9em; }
pre code { background: none; padding: 0; }

table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.table-container { overflow-x: auto; margin: 1rem 0; }
.table-container table { margin: 0; }
th, td { border: 1px solid var(--border); padding: 8px; text-align: left; }
th { background: var(--card-bg); }

blockquote { border-left: 4px solid var(--accent); padding-left: 1rem; color: var(--text-muted); margin: 1rem 0; }

img { max-width: 100%; border-radius: 6px; }

/* Breadcrumb trail: hub > project > section */
.crumbs { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em; }
.crumbs a { color: var(--text-muted); }
.crumbs a:hover { color: var(--accent3); }
.crumbs .sep { opacity: 0.5; }
.crumbs [aria-current="page"] { color: var(--text); }

.back-link { display: inline-block; margin-bottom: 1rem; color: var(--text-muted); font-size: 0.9rem; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

.katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.5em 0; }

/* Chapter navigation / table-of-contents (research-books) */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6em; margin-bottom: 1rem; padding: 0.7em 1rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; font-size: 0.85em; }
.topbar a { color: var(--accent3); white-space: nowrap; }
.topbar .spacer { flex: 1 1 auto; }
.topbar .prevnext { padding: 0.3em 0.7em; background: var(--card-bg); border: 1px solid var(--border); border-radius: 4px; }
.topbar .prevnext.disabled { opacity: 0.35; pointer-events: none; }

details.toc { margin-bottom: 2rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; font-size: 0.85em; }
details.toc summary { cursor: pointer; padding: 0.7em 1rem; font-weight: 600; color: var(--accent3); list-style: none; }
details.toc summary::-webkit-details-marker { display: none; }
details.toc summary::before { content: "\25B8"; display: inline-block; margin-right: 0.5em; transition: transform 0.15s; }
details.toc[open] summary::before { transform: rotate(90deg); }
.toc-body { padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: 0.8em; }
.toc-chapter h4 { color: var(--accent3); font-size: 0.9em; margin: 0 0 0.3em; text-transform: uppercase; letter-spacing: 0.04em; }
.toc-chapter .toc-links { display: flex; flex-wrap: wrap; gap: 0.3em 1em; }
.toc-chapter .toc-links a.current { color: var(--accent); font-weight: 600; }

footer { text-align: center; color: var(--text-muted); font-size: 0.8rem; padding-top: 2rem; border-top: 1px solid var(--border); margin-top: 2rem; }
footer a { color: var(--accent3); }

/* Search box (hub + search page) */
.search-box { position: relative; margin: 0 0 2rem; }
.search-box input {
  width: 100%;
  padding: 0.8rem 1rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.15); }
.search-meta { color: var(--text-muted); font-size: 0.85rem; margin: -1.5rem 0 1.5rem; min-height: 1.2em; }
.search-results { display: flex; flex-direction: column; gap: 0.5rem; }
.search-results a {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  color: var(--text);
  text-decoration: none;
}
.search-results a:hover { border-color: var(--accent); }
.search-results .path { display: block; color: var(--text-muted); font-size: 0.78rem; margin-top: 0.15rem; word-break: break-all; }
.search-results mark { background: rgba(255, 107, 157, 0.25); color: inherit; border-radius: 2px; padding: 0 0.1em; }
[hidden] { display: none !important; }

/* ---- Small screens ---- */
@media (max-width: 720px) {
  body { padding: 1rem; }
  header { margin-bottom: 1.5rem; padding: 1rem 0; }
  header h1 { font-size: 1.9rem; }
  header p { font-size: 1rem; }
  header .links a, header .back { display: inline-block; margin: 0.2rem 0.4rem; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.25rem; }
  section { margin-bottom: 1.75rem; }
  .link-list { grid-template-columns: 1fr; gap: 0.75rem; }
  .link-list a { padding: 0.85rem 1rem; }
  article, .readme-content { font-size: 1rem; }
  pre { padding: 0.75rem; font-size: 0.85rem; }
  table { display: block; overflow-x: auto; }
  .topbar { font-size: 0.8em; padding: 0.6em 0.75rem; }
  .toc-chapter .toc-links { gap: 0.3em 0.7em; }
}

@media (max-width: 400px) {
  body { padding: 0.75rem; }
  header h1 { font-size: 1.6rem; }
}

/* ---- Respect reduced-motion preferences ---- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .link-list a:hover { transform: none; }
}
