/* ==========================================================================
   ZWPlayer Documentation — Modernized Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Variables & Theming
   -------------------------------------------------------------------------- */
:root {
  /* Colors - Light Theme */
  --bg-body: #ffffff;
  --bg-sidebar: #f8fafc;
  --bg-nav: rgba(255, 255, 255, 0.85);
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  
  --text-main: #334155;
  --text-heading: #0f172a;
  --text-muted: #64748b;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-bg: #eff6ff;
  
  --border-color: #e2e8f0;
  
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;
  
  /* Layout Metrics */
  --nav-height: 64px;
  --sidebar-width: 280px;
  --toc-width: 240px;
  --layout-max-width: 1440px;
}

/* Future-proofing for Dark Mode (Phase 3 can add JS toggle) */
[data-theme='dark'] {
  --bg-body: #0f172a;
  --bg-sidebar: #0f172a;
  --bg-nav: rgba(15, 23, 42, 0.85);
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  
  --text-main: #cbd5e1;
  --text-heading: #f8fafc;
  --text-muted: #94a3b8;
  
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-bg: rgba(59, 130, 246, 0.15);
  
  --border-color: #334155;
}

/* --------------------------------------------------------------------------
   2. Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body, h1, h2, h3, h4, p, blockquote, pre, dl, dd, ol, ul, figure, hr { margin: 0; padding: 0; }
ul, ol { list-style: none; }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-main);
  background-color: var(--bg-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.35s ease, color 0.35s ease;
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }

/* --------------------------------------------------------------------------
   3. Header overrides (docs-specific: search bar positioning)
   -------------------------------------------------------------------------- */
.navbar-search {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  padding: 0 16px;
}

/* --------------------------------------------------------------------------
   4. CSS Grid Layout (The Core Upgrade)
   -------------------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
  max-width: 100%;
  margin: 0 auto;
  min-height: calc(100vh - var(--nav-height));
}

/* --------------------------------------------------------------------------
   5. Sidebar
   -------------------------------------------------------------------------- */
.sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  padding: 32px 24px;
  /* Custom scrollbar for sidebar */
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }

.sidebar-section { margin-bottom: 32px; }
.sidebar-section-title {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-left: 12px;
}
.sidebar-link {
  display: block;
  padding: 8px 12px;
  color: var(--text-main);
  font-size: 14px;
  border-radius: 6px;
  transition: all 0.2s;
  margin-bottom: 4px;
  border-left: 3px solid transparent;
}
.sidebar-link:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-heading);
  text-decoration: none;
  border-left-color: var(--primary);
}
.sidebar-link.active {
  color: var(--primary);
  background-color: var(--primary-bg);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   6. Content Area
   -------------------------------------------------------------------------- */
.content {
  padding: 48px 64px;
  max-width: 1040px; /* Optimal reading width constraint within the fraction */
  margin: 0 auto; /* Center within the grid cell if cell is wider */
  width: 100%;
}

.breadcrumb {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); text-decoration: none; }
.breadcrumb .sep { margin: 0 8px; color: var(--border-color); }

/* Markdown Body - Typography */
.markdown-body h1 {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-heading);
  letter-spacing: -0.02em;
  margin-bottom: 24px;
  line-height: 1.2;
}
.markdown-body h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-heading);
  margin: 48px 0 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}
.markdown-body h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-heading);
  margin: 32px 0 16px;
}
.markdown-body p { margin-bottom: 1.25rem; }
.markdown-body ul, .markdown-body ol { margin-bottom: 1.25rem; padding-left: 1.5rem; }
.markdown-body ul { list-style: disc; }
.markdown-body ol { list-style: decimal; }
.markdown-body li { margin-bottom: 0.5rem; }

.markdown-body blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 4px solid var(--primary);
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
  border-radius: 0 8px 8px 0;
}

.markdown-body hr {
  margin: 40px 0;
  border: none;
  border-top: 1px solid var(--border-color);
}

.markdown-body img {
  margin: 32px 0;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 32px 0;
  font-size: 0.95rem;
}
.markdown-body th, .markdown-body td {
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  text-align: left;
}
.markdown-body th {
  background-color: var(--bg-surface-hover);
  font-weight: 600;
  color: var(--text-heading);
}

/* Page Navigation */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}
.page-prev, .page-next {
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 48%;
}
.page-prev:hover, .page-next:hover {
  border-color: var(--primary);
  text-decoration: none;
}
.page-next { align-items: flex-end; text-align: right; margin-left: auto; }
.page-prev .label, .page-next .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.page-prev .title, .page-next .title {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-prev:hover, .page-next:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
  text-decoration: none;
}
.page-prev:hover .title, .page-next:hover .title {
  color: var(--primary-hover);
}

/* --------------------------------------------------------------------------
   7. Table of Contents (TOC)
   -------------------------------------------------------------------------- */
.toc {
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  padding: 48px 24px 48px 0;
  overflow-y: auto;
  font-size: 13px;
  scrollbar-width: none; /* Hide scrollbar for a cleaner look */
}
.toc-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-heading);
  margin-bottom: 16px;
  letter-spacing: 0.05em;
}
.toc-nav { display: flex; flex-direction: column; border-left: 1px solid var(--border-color); }
.toc a {
  display: block;
  padding: 6px 0 6px 16px;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 2px solid transparent;
  margin-left: -1px;
}
.toc a:hover { color: var(--text-main); }
.toc a.active {
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}
.toc .toc-h2 { padding-left: 16px; }
.toc .toc-h3 { padding-left: 32px; font-size: 12.5px; }

/* --------------------------------------------------------------------------
   8. Search overrides
   -------------------------------------------------------------------------- */
#search { width: 100%; max-width: 320px; position: relative; }
.search-input {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
  outline: none;
  transition: all 0.2s;
}
.search-input:focus {
  background-color: var(--bg-surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 500px;
  max-width: 90vw;
  max-height: 400px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  z-index: 1001;
  display: none;
}
.search-result {
  display: block;
  padding: 16px;
  text-decoration: none !important;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background-color: var(--bg-surface-hover); }

.search-result-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 4px;
}
.search-result-excerpt {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result-excerpt mark {
  background-color: rgba(59, 130, 246, 0.2);
  color: var(--primary);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}
.search-no-result {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   9. Code Display (Pre-Shiki setup)
   -------------------------------------------------------------------------- */
:not(pre) > code {
  background-color: var(--bg-surface-hover);
  color: var(--primary);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  border: 1px solid var(--border-color);
}
.code-block-wrapper {
  margin: 24px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-hover);
}
pre.shiki {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
  border: none;
  background-color: transparent !important;
}
pre.shiki code {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
}
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0; transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  z-index: 10;
}
.code-block-wrapper:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--bg-surface-hover); color: var(--text-main); border-color: var(--primary); }

/* --------------------------------------------------------------------------
   10. Footer
   -------------------------------------------------------------------------- */
.footer {
  border-top: 1px solid var(--border-color);
  text-align: center;
  padding: 32px 24px;
  color: var(--text-muted);
  font-size: 14px;
  background-color: var(--bg-body);
}

/* --------------------------------------------------------------------------
   11. Responsive Design
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 240px 1fr 200px; }
  .content { padding: 40px; }
}

@media (max-width: 1024px) {
  /* Hide right TOC on medium screens */
  .layout { grid-template-columns: 260px 1fr; }
  .toc { display: none; }
}

@media (max-width: 768px) {
  /* Mobile drawer */
  .layout {
    display: block; /* Remove grid on mobile */
  }
  .content { padding: 24px 20px; }
  
  .hamburger { display: flex; }
  .navbar-search { display: none; /* Hide search in top bar for mobile, can add to sidebar later */ }
  
  .sidebar {
    position: fixed;
    top: var(--nav-height);
    left: -100%;
    width: 280px;
    z-index: 900;
    transition: left 0.3s ease;
    border-right: none;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.1);
    background-color: var(--bg-body);
  }
  .sidebar.open { left: 0; }
  
  /* Backdrop will be injected by JS */
  .sidebar-backdrop {
    position: fixed;
    inset: 0; top: var(--nav-height);
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 899;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.sidebar-open { overflow: hidden; }
  
  .page-nav { flex-direction: column; gap: 16px; }
  .page-prev, .page-next { width: 100%; align-items: flex-start; text-align: left; }
}

/* --------------------------------------------------------------------------
   12. Admonitions (Tip, Warning, Danger) & Mobile TOC
   -------------------------------------------------------------------------- */
.markdown-body .tip,
.markdown-body .warning,
.markdown-body .danger {
  padding: 16px 20px;
  margin: 24px 0;
  border-left: 4px solid;
  border-radius: 4px;
}
.markdown-body .tip {
  background-color: rgba(16, 185, 129, 0.1);
  border-color: #10b981;
  color: var(--text-main);
}
.markdown-body .warning {
  background-color: rgba(245, 158, 11, 0.1);
  border-color: #f59e0b;
  color: var(--text-main);
}
.markdown-body .danger {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
  color: var(--text-main);
}

.mobile-toc {
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
}
.mobile-toc-header {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text-heading);
}
.mobile-toc .toc-title { display: none; }
.mobile-toc .toc-nav { display: flex; flex-direction: column; border-left: none; }
.mobile-toc a { display: block; padding: 4px 0; border-left: none; color: var(--text-muted); }
.mobile-toc a:hover { color: var(--text-main); text-decoration: none; }
.mobile-toc a.active { color: var(--primary); font-weight: 600; }
.mobile-toc .toc-h2 { padding-left: 0; }
.mobile-toc .toc-h3 { padding-left: 16px; font-size: 13px; }

/* --------------------------------------------------------------------------
   13. Back to Top Button
   -------------------------------------------------------------------------- */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 44px;
  height: 44px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 1000;
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.back-to-top:hover {
  background-color: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(59, 130, 246, 0.2);
}

/* Custom Scrollbar for Pre */
pre::-webkit-scrollbar { height: 6px; }
pre::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }
pre::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------------------
   14. Dark Mode Code Overrides (Shiki dual theme)
   -------------------------------------------------------------------------- */
[data-theme='dark'] .shiki,
[data-theme='dark'] .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}
[data-theme='dark'] .code-block-wrapper {
  background-color: #161b22;
  border-color: #30363d;
}
[data-theme='dark'] :not(pre) > code {
  background-color: rgba(110, 118, 129, 0.2);
  color: #79c0ff;
  border-color: #30363d;
}

/* Scroll entrance animation */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1), transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Reading progress bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  width: 0%;
  z-index: 9999;
  transition: width 0.1s linear;
}
