/* ============================================
   PIP:C Documentation — style.css
   Dark/Light theme, responsive docs layout
   ============================================ */

/* --- Theme Variables --- */
:root {
  --sidebar-width: 280px;
  --content-max: 860px;
  --radius: 6px;
  --transition: 0.2s ease;
  /* Dark theme (default) */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-dim: rgba(88,166,255,0.15);
  --code-bg: #0d1117;
  --code-text: #e6edf3;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --info-bg: rgba(88,166,255,0.1);
  --info-border: rgba(88,166,255,0.3);
  --warn-bg: rgba(210,153,34,0.1);
  --warn-border: rgba(210,153,34,0.3);
  --table-stripe: rgba(88,166,255,0.04);
  --scrollbar-track: #161b22;
  --scrollbar-thumb: #30363d;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #f0f2f5;
  --border: #d0d7de;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8c959f;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-dim: rgba(9,105,218,0.1);
  --code-bg: #f6f8fa;
  --code-text: #1f2328;
  --success: #1a7f37;
  --warning: #9a6700;
  --danger: #cf222e;
  --info-bg: rgba(9,105,218,0.08);
  --info-border: rgba(9,105,218,0.2);
  --warn-bg: rgba(154,103,0,0.08);
  --warn-border: rgba(154,103,0,0.2);
  --table-stripe: rgba(9,105,218,0.04);
  --scrollbar-track: #f6f8fa;
  --scrollbar-thumb: #d0d7de;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

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

img { max-width: 100%; display: block; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

/* --- Sidebar Navigation --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 24px 0;
  z-index: 100;
  transition: transform 0.3s ease, background var(--transition);
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-logo {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.sidebar-logo span {
  color: var(--accent);
}

.sidebar-version {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav-section {
  padding: 8px 20px 4px;
}

.nav-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.nav-link {
  display: block;
  padding: 6px 20px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--accent-dim);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
  font-weight: 500;
}

/* --- Mobile Menu Button --- */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 1.4rem;
}

.mobile-menu-btn:hover {
  background: var(--bg-tertiary);
}

/* --- Mobile Overlay --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

.sidebar-overlay.active {
  display: block;
}

/* --- Main Content Area --- */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-wrapper {
  flex: 1;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: 48px 40px 60px;
}

/* --- Top Bar (mobile-visible actions) --- */
.top-bar {
  display: none;
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: flex-end;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

/* --- Theme Toggle --- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.theme-toggle .icon {
  font-size: 1rem;
}

/* --- Typography --- */
.page-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.page-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.6;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 40px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 28px 0 10px;
}

h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 20px 0 8px;
}

p {
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.75;
}

strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* --- Lists --- */
ul, ol {
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-left: 24px;
}

li {
  margin-bottom: 6px;
  line-height: 1.7;
}

li::marker {
  color: var(--accent);
}

/* --- Inline Code --- */
code:not(pre code) {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Consolas, 'Liberation Mono', monospace;
}

/* --- Code Blocks --- */
.code-block {
  position: relative;
  margin: 16px 0 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--code-bg);
  overflow: hidden;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.copy-btn {
  padding: 3px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
}

.code-block pre {
  padding: 16px;
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--code-text);
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Consolas, 'Liberation Mono', monospace;
}

/* Inline pre without wrapper */
pre:not(.code-block pre) {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0 20px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--code-text);
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', Consolas, 'Liberation Mono', monospace;
}

/* --- Tables --- */
.table-wrapper {
  overflow-x: auto;
  margin: 16px 0 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead {
  background: var(--bg-secondary);
}

th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  color: var(--accent);
}

th .sort-icon {
  margin-left: 4px;
  font-size: 0.7rem;
  opacity: 0.5;
}

th.sorted .sort-icon {
  opacity: 1;
  color: var(--accent);
}

td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:nth-child(even) {
  background: var(--table-stripe);
}

tr:last-child td {
  border-bottom: none;
}

td strong, th strong {
  color: var(--text-primary);
}

/* --- Hint / Info Boxes --- */
.hint-box {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin: 16px 0 20px;
  border-left: 4px solid;
  font-size: 0.9rem;
}

.hint-box.info {
  background: var(--info-bg);
  border-color: var(--accent);
}

.hint-box.warning {
  background: var(--warn-bg);
  border-color: var(--warning);
}

.hint-box.success {
  background: rgba(63,185,80,0.08);
  border-color: var(--success);
}

.hint-box p {
  margin-bottom: 0;
}

.hint-box .hint-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

/* --- NSFW Gate --- */
.nsfw-gate {
  border: 2px solid var(--danger);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  margin: 24px 0;
  background: rgba(248,81,73,0.05);
}

.nsfw-gate p {
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.nsfw-gate .gate-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--danger);
  margin-bottom: 8px;
}

.nsfw-unlock-btn {
  padding: 8px 20px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity var(--transition);
}

.nsfw-unlock-btn:hover {
  opacity: 0.85;
}

.nsfw-content {
  display: none;
}

.nsfw-content.visible {
  display: block;
}

/* --- Footer --- */
.page-footer {
  margin-top: 60px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-brand {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-brand a {
  color: var(--text-secondary);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

.footer-links a {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

/* --- Search Box --- */
.search-box {
  padding: 0 16px 8px;
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.84rem;
  outline: none;
  transition: border-color var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
}

/* --- Reading Order List --- */
.reading-order {
  counter-reset: reading;
  list-style: none;
  padding-left: 0;
}

.reading-order li {
  counter-increment: reading;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.reading-order li::before {
  content: counter(reading) ".";
  color: var(--accent);
  font-weight: 600;
  min-width: 20px;
}

/* --- Tier Badges --- */
.tier-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 6px;
}

.tier-badge.tier1 { background: rgba(63,185,80,0.15); color: var(--success); }
.tier-badge.tier2 { background: rgba(88,166,255,0.15); color: var(--accent); }
.tier-badge.tier3 { background: rgba(210,153,34,0.15); color: var(--warning); }

/* --- Step list (Build order) --- */
.step-list {
  list-style: none;
  padding-left: 0;
  counter-reset: steps;
}

.step-list li {
  counter-increment: steps;
  padding: 12px 16px 12px 48px;
  position: relative;
  margin-bottom: 4px;
  border-left: 3px solid var(--border);
  color: var(--text-secondary);
}

.step-list li::before {
  content: counter(steps);
  position: absolute;
  left: -16px;
  top: 10px;
  width: 30px;
  height: 30px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 600;
}

.step-list li strong {
  display: block;
  color: var(--text-primary);
  font-size: 1rem;
  margin-bottom: 2px;
}

/* --- Checklist --- */
.checklist {
  list-style: none;
  padding-left: 0;
}

.checklist li {
  padding: 4px 0;
  padding-left: 24px;
  position: relative;
}

.checklist li::before {
  content: "\2610";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 1.1rem;
}

/* --- Horizontal Rule --- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* --- Blockquote --- */
blockquote {
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  margin: 16px 0;
  background: var(--accent-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
}

blockquote p {
  color: var(--text-primary);
  margin-bottom: 0;
}

/* --- Responsive: Tablet --- */
@media (max-width: 900px) {
  .content-wrapper {
    padding: 40px 28px 50px;
  }
}

/* --- Responsive: Mobile --- */
@media (max-width: 700px) {
  :root {
    --sidebar-width: 280px;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .top-bar {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding-top: 56px;
  }

  .content-wrapper {
    padding: 24px 16px 40px;
  }

  .page-title {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  .page-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: 8px 10px;
  }

  .code-block pre,
  pre:not(.code-block pre) {
    font-size: 0.78rem;
    padding: 12px;
  }
}

/* --- Noscript Fallback (for model/bot scraping) --- */
/* When JS is disabled, NSFW gates are removed and content is shown.
   This ensures LLMs and other non-JS agents can read gated documentation. */
noscript .nsfw-gate {
  display: none !important;
}
noscript .nsfw-content {
  display: block !important;
}

/* --- Print --- */
@media print {
  .sidebar, .mobile-menu-btn, .top-bar, .theme-toggle, .copy-btn, .search-box {
    display: none !important;
  }
  .main-content {
    margin-left: 0;
  }
  .content-wrapper {
    max-width: 100%;
    padding: 20px;
  }
  body {
    background: #fff;
    color: #000;
  }
}
