/* ============ RESET ============ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
a { color: #3366cc; text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ============ THEME ============ */
:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --text: #202122;
  --text-secondary: #54595d;
  --text-muted: #72777d;
  --border: #e0e0e0;
  --border-light: #eaecf0;
  --link: #3366cc;
  --heading-font: 'Source Serif 4', 'Linux Libertine', Georgia, serif;
  --body-font: 'Inter', -apple-system, system-ui, sans-serif;
  --mono-font: 'JetBrains Mono', monospace;
  --infobox-bg: #f8f9fa;
  --shadow: rgba(0,0,0,0.06);
}
body.dark {
  --bg: #1a1a1a;
  --bg-secondary: #222222;
  --text: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #888;
  --border: #333;
  --border-light: #2a2a2a;
  --link: #6b9eff;
  --infobox-bg: #222;
  --shadow: rgba(0,0,0,0.3);
}
body { font-family: var(--body-font); background: var(--bg); color: var(--text); line-height: 1.6; transition: background 0.3s, color 0.3s; }

/* ============ HOME PAGE ============ */
#home-page {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; position: relative;
}
.home-top-nav {
  position: absolute; top: 16px; right: 24px; display: flex; align-items: center; gap: 12px;
}
.home-nav-btn {
  font-size: 14px; font-weight: 500; color: var(--text-muted); text-decoration: none;
  padding: 8px 20px; border: 1px solid var(--border); border-radius: 20px;
  transition: all 0.2s;
}
.home-nav-btn:hover { color: var(--text); border-color: var(--text); text-decoration: none; }
#home-theme-toggle {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 8px; border-radius: 8px; display: flex; align-items: center;
}
#home-theme-toggle:hover { color: var(--text); }
.home-center { text-align: center; width: 100%; max-width: 620px; padding: 0 24px; margin-top: -80px; min-height: 320px; }
.home-title {
  font-family: var(--heading-font); font-size: 52px; font-weight: 400;
  color: var(--text); letter-spacing: -1px; margin-bottom: 32px;
  min-height: 64px; line-height: 1.2;
}
.home-version { font-size: 18px; font-weight: 300; color: var(--text-muted); vertical-align: super; }
.home-search-wrap {
  display: flex; align-items: center; background: var(--bg);
  border: 1.5px solid var(--border); border-radius: 24px;
  padding: 4px 6px 4px 16px; transition: border-color 0.2s, box-shadow 0.2s;
}
.home-search-wrap:focus-within { border-color: var(--text-muted); box-shadow: 0 2px 12px var(--shadow); }
.home-search-icon { color: var(--text-muted); flex-shrink: 0; margin-right: 8px; }
#home-search {
  flex: 1; border: none; outline: none; font-size: 16px; padding: 12px 4px;
  background: transparent; color: var(--text); font-family: var(--body-font);
}
#home-search::placeholder { color: var(--text-muted); }
#home-search-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--text); color: var(--bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s; flex-shrink: 0;
}
#home-search-btn:hover { opacity: 0.8; }

/* Home Suggestions */
.home-suggestions {
  text-align: left; margin-top: 4px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; display: none; box-shadow: 0 4px 16px var(--shadow);
}
.home-suggestions.active { display: block; }
.sug-item {
  padding: 10px 16px; font-size: 14px; color: var(--text); cursor: pointer;
  border-bottom: 1px solid var(--border-light); transition: background 0.1s;
}
.sug-item:hover { background: var(--bg-secondary); }
.sug-item:last-child { border-bottom: none; }

/* Home Footer */
.home-footer {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 20px 32px; display: flex; justify-content: space-between; align-items: flex-end;
}
.home-footer-left { display: flex; gap: 24px; }
.article-count { font-size: 11px; color: var(--text-muted); line-height: 1.3; }
.article-count strong { font-size: 15px; color: var(--text-secondary); font-family: var(--mono-font); display: block; }
.home-footer-right { font-size: 12px; color: var(--text-muted); }
.home-footer-right a { color: var(--text-muted); }
.home-footer-right a:hover { color: var(--link); }
.sep { margin: 0 6px; }

/* ============ TOP BAR ============ */
#topbar { background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.topbar-inner {
  max-width: 1400px; margin: 0 auto; padding: 0 24px; height: 50px;
  display: flex; align-items: center; gap: 16px;
}
.topbar-logo {
  font-family: var(--heading-font); font-size: 20px; font-weight: 400;
  color: var(--text); text-decoration: none; flex-shrink: 0;
}
.topbar-logo:hover { text-decoration: none; opacity: 0.7; }
.topbar-nav { display: flex; gap: 4px; margin-left: 16px; }
.topbar-nav .nav-link { font-size: 13px; color: var(--text-muted); padding: 6px 12px; border-radius: 6px; text-decoration: none; transition: all 0.2s; }
.topbar-nav .nav-link:hover { color: var(--text); background: var(--bg-secondary); text-decoration: none; }
.topbar-nav .nav-link.active { color: var(--text); background: var(--bg-secondary); font-weight: 600; }
.topbar-search-wrap {
  flex: 1; max-width: 400px; display: flex; align-items: center;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 20px; overflow: hidden; margin-left: auto;
}
#topbar-search {
  flex: 1; border: none; outline: none; padding: 7px 14px; font-size: 13px;
  background: transparent; color: var(--text); font-family: var(--body-font);
}
#topbar-search-btn {
  background: none; border: none; color: var(--text-muted); padding: 7px 12px;
  cursor: pointer; display: flex; align-items: center;
}
#topbar-search-btn:hover { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
#theme-toggle {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 6px; border-radius: 6px; display: flex; align-items: center;
}
#theme-toggle:hover { color: var(--text); background: var(--bg-secondary); }

/* ============ ARTICLE LAYOUT ============ */
.article-layout {
  max-width: 1100px; margin: 0 auto; padding: 24px 24px 80px;
  display: grid; grid-template-columns: 200px 1fr; gap: 32px;
}

/* TOC */
#toc-sidebar { align-self: start; position: sticky; top: 74px; }
#toc-nav { display: flex; flex-direction: column; }
#toc-nav a {
  font-size: 13px; color: var(--text-secondary); padding: 4px 0 4px 12px;
  text-decoration: none; border-left: 2px solid transparent; transition: all 0.15s;
  line-height: 1.4;
}
#toc-nav a:hover { color: var(--link); border-left-color: var(--link); text-decoration: none; }
#toc-nav a.active { color: var(--link); border-left-color: var(--link); font-weight: 600; }
#toc-nav a.sub { padding-left: 24px; font-size: 12px; color: var(--text-muted); }

/* Article */
#article { min-height: 60vh; }
.article-loading { display: flex; justify-content: center; padding: 80px 0; }
.spinner { width: 28px; height: 28px; border: 2.5px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Article Head */
#article-title {
  font-family: var(--heading-font); font-size: 32px; font-weight: 400;
  color: var(--text); border-bottom: 1px solid var(--border);
  padding-bottom: 6px; margin-bottom: 16px; line-height: 1.2;
}

/* Title Row */
.article-title-row { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 16px; }
.article-title-row #article-title { border: none; padding: 0; margin: 0; }
.listen-btn {
  display: flex; align-items: center; gap: 6px; padding: 8px 16px;
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 20px;
  color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.2s; flex-shrink: 0;
}
.listen-btn:hover { background: var(--link); color: #fff; border-color: var(--link); }
.listen-btn.loading { opacity: 0.6; cursor: wait; }
.audio-player { margin-bottom: 16px; display: flex; align-items: center; gap: 12px; }
.audio-player audio { flex: 1; height: 36px; }
#audio-status { font-size: 12px; color: var(--text-muted); }

/* Intro */
#article-intro { font-size: 15px; line-height: 1.75; color: var(--text); margin-bottom: 20px; }
#article-intro p { margin-bottom: 10px; }

/* Infobox */
.infobox {
  float: right; width: 280px; margin: 0 0 20px 28px;
  border: 1px solid var(--border); background: var(--infobox-bg);
  font-size: 13px; line-height: 1.5;
}
.infobox img {
  width: 100%; display: block; border-bottom: 1px solid var(--border);
}
#infobox-data { padding: 12px; }
#infobox-data .ib-title {
  font-family: var(--heading-font); font-size: 16px; font-weight: 600;
  text-align: center; padding-bottom: 8px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
#infobox-data .ib-row { display: flex; padding: 5px 0; border-bottom: 1px solid var(--border-light); gap: 8px; align-items: baseline; }
#infobox-data .ib-row:last-child { border-bottom: none; }
#infobox-data .ib-label { font-weight: 600; color: var(--text-secondary); width: 100px; flex-shrink: 0; font-size: 12px; line-height: 1.4; }
#infobox-data .ib-value { color: var(--text); font-size: 12px; line-height: 1.4; word-break: break-word; overflow-wrap: break-word; flex: 1; min-width: 0; }

/* Article Body */
#article-body { font-size: 15px; line-height: 1.78; color: var(--text); }
#article-body p { margin-bottom: 12px; }
#article-body h2 {
  font-family: var(--heading-font); font-size: 23px; font-weight: 400;
  color: var(--text); border-bottom: 1px solid var(--border);
  padding-bottom: 4px; margin: 28px 0 12px; clear: both;
}
#article-body h3 {
  font-family: var(--heading-font); font-size: 18px; font-weight: 600;
  color: var(--text); margin: 20px 0 8px;
}

/* Internal links */
.wiki-link { color: var(--link); cursor: pointer; }
.wiki-link:hover { text-decoration: underline; }

/* Inline Article Images — float beside text like Grokipedia */
.inline-img {
  float: right; width: 220px; margin: 0 0 16px 20px; clear: right;
  border: 1px solid var(--border); background: var(--bg-secondary);
  font-size: 12px; color: var(--text-muted);
}
.inline-img img { width: 100%; display: block; }
.inline-img .img-caption { padding: 6px 8px; line-height: 1.4; font-style: italic; }

/* Gallery at bottom */
.article-images-section { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); }
.article-images-section h2 { font-family: var(--heading-font); font-size: 20px; font-weight: 400; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.img-card { background: var(--bg-secondary); border: 1px solid var(--border-light); border-radius: 4px; overflow: hidden; }
.img-card img { width: 100%; display: block; cursor: pointer; transition: opacity 0.2s; }
.img-card img:hover { opacity: 0.85; }
.img-caption { padding: 6px 8px; font-size: 11px; color: var(--text-muted); line-height: 1.4; }

@media (max-width: 800px) {
  .inline-img { float: none; width: 100%; margin: 0 0 16px 0; }
}

/* See Also */
.see-also { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.see-also h2 { font-family: var(--heading-font); font-size: 20px; font-weight: 400; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
#see-also-links { display: flex; flex-wrap: wrap; gap: 6px; }
#see-also-links a {
  display: inline-block; padding: 5px 12px; font-size: 13px;
  background: var(--bg-secondary); border: 1px solid var(--border-light);
  border-radius: 4px; color: var(--link); transition: background 0.15s;
}
#see-also-links a:hover { background: var(--border-light); text-decoration: none; }

/* Sources */
.sources { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.sources h2 { font-family: var(--heading-font); font-size: 20px; font-weight: 400; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
#source-list { padding-left: 20px; font-size: 13px; color: var(--text-secondary); }
#source-list li { margin-bottom: 4px; }
#source-list a { color: var(--link); word-break: break-all; }

/* ============ RESPONSIVE ============ */

/* Tablet */
@media (max-width: 800px) {
  .article-layout { grid-template-columns: 1fr; gap: 0; padding: 16px 16px 60px; }
  #toc-sidebar { display: none; }
  .infobox { float: none; width: 100%; max-width: 100%; margin: 0 0 20px 0; border-radius: 12px; overflow: hidden; }
  .infobox img { max-height: 300px; object-fit: cover; }
  #infobox-data .ib-row { flex-direction: row; gap: 8px; }
  #infobox-data .ib-label { width: 110px; }
  #article-title { font-size: 26px; }
  .home-title { font-size: 38px; }
  .home-footer { flex-direction: column; align-items: center; gap: 8px; text-align: center; }
  .home-top-nav { position: static; justify-content: center; flex-wrap: wrap; padding: 12px 16px; gap: 8px; }
  .topbar-nav { display: none; }
  .topbar-inner { padding: 0 12px; gap: 8px; }
  .topbar-search-wrap { max-width: none; }
  #article-body { font-size: 15px; }
  #article-body h2 { font-size: 20px; }
  #article-body h3 { font-size: 17px; }
  .inline-img { float: none; width: 100%; margin: 0 0 16px 0; border-radius: 8px; }
  #article-images-section { padding: 0; }
  .images-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .see-also h2, .sources h2 { font-size: 18px; }
  #see-also-links { gap: 6px; }
  #see-also-links a { font-size: 12px; padding: 4px 10px; }
}

/* Mobile */
@media (max-width: 480px) {
  body { font-size: 15px; }
  .home-title { font-size: 28px; letter-spacing: -0.5px; }
  .home-version { font-size: 13px; }
  .home-center { margin-top: -20px; padding: 0 16px; }
  .home-search { padding: 12px 16px; font-size: 16px; border-radius: 24px; }
  .home-top-nav { gap: 6px; padding: 10px 12px; }
  .home-nav-btn { font-size: 12px; padding: 6px 12px; }
  .home-footer-left { flex-direction: column; gap: 8px; }
  .article-count { font-size: 10px; }
  .article-count strong { font-size: 13px; }
  .topbar-inner { height: 44px; }
  .topbar-logo { font-size: 17px; }
  #topbar-search { font-size: 14px; padding: 6px 12px; }
  .topbar-right { gap: 4px; }
  .article-layout { padding: 12px 12px 40px; }
  #article-title { font-size: 22px; line-height: 1.3; }
  #article-intro { font-size: 14px; line-height: 1.6; }
  .infobox { border-radius: 10px; }
  .infobox img { max-height: 250px; }
  #infobox-data { padding: 10px; }
  #infobox-data .ib-title { font-size: 15px; padding: 8px 0; }
  #infobox-data .ib-row { padding: 4px 0; }
  #infobox-data .ib-label { width: 90px; font-size: 11px; }
  #infobox-data .ib-value { font-size: 11px; }
  #article-body { font-size: 14px; line-height: 1.7; }
  #article-body h2 { font-size: 18px; margin-top: 24px; }
  #article-body h3 { font-size: 15px; }
  #article-body p { margin-bottom: 12px; }
  .images-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .listen-btn { font-size: 13px; padding: 6px 14px; }
  #see-also-links a { font-size: 11px; padding: 3px 8px; }
  #source-list { font-size: 12px; }
}

/* Tiny screens */
@media (max-width: 360px) {
  .home-title { font-size: 24px; }
  #article-title { font-size: 20px; }
  .topbar-logo { font-size: 15px; }
  .article-layout { padding: 10px 8px 40px; }
  #infobox-data .ib-label { width: 75px; font-size: 10px; }
  #infobox-data .ib-value { font-size: 10px; }
}

/* ============ AI COMMENTARY (Vyb — Grokipedia-style) ============ */
.ai-commentary {
  display: none;
  margin: 18px 0 20px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(124,108,255,0.07), rgba(0,230,184,0.04));
  border: 1px solid rgba(124,108,255,0.25);
  border-radius: 12px;
  position: relative;
}
.ai-commentary.visible { display: block; animation: aiSlide .35s ease; }
@keyframes aiSlide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.ai-commentary-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px;
  color: #7c6cff; margin-bottom: 8px;
}
.ai-commentary-head .ai-avatar {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, #7c6cff, #00e6b8);
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
}
.ai-commentary-head .ai-name { color: #7c6cff; font-size: 12px; font-weight: 700; text-transform: none; letter-spacing: 0; }
.ai-commentary-head .ai-label { color: var(--text-muted); font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.8px; }
.ai-commentary .ai-body { font-size: 14px; line-height: 1.65; color: var(--text); min-height: 22px; }
.ai-commentary .ai-text { white-space: pre-wrap; }
.ai-commentary .ai-thinking { display: flex; gap: 4px; padding: 4px 0; }
.ai-commentary .ai-thinking.hidden { display: none; }
.ai-commentary .ai-thinking .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(124,108,255,0.55);
  animation: aiDot 1.3s infinite ease-in-out;
}
.ai-commentary .ai-thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.ai-commentary .ai-thinking .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiDot { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

body.dark .ai-commentary {
  background: linear-gradient(135deg, rgba(124,108,255,0.14), rgba(0,230,184,0.06));
  border-color: rgba(124,108,255,0.35);
}

/* ============================================================
   NEW-feature badges (added 2026-04-16 for Vybtrail launch)
   ============================================================ */
.nav-link-new {
  position: relative;
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(139,92,246,0.10));
}
.nav-link-new:hover {
  background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(139,92,246,0.18));
}
.nav-new-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  border-radius: 100px;
  vertical-align: middle;
}
.home-nav-btn-featured {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%) !important;
  color: #fff !important;
  border-color: transparent !important;
  box-shadow: 0 6px 20px -8px rgba(99,102,241,0.6);
  position: relative;
}
.home-nav-btn-featured:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px -8px rgba(99,102,241,0.75);
}
.home-nav-new {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  background: rgba(255,255,255,0.25);
  border-radius: 100px;
  vertical-align: middle;
}
