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

:root,
[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #1c2128;
  --border: #30363d;
  --border-light: #3d444d;
  --text-primary: #e6edf3;
  --text-secondary: #9198a1;
  --text-muted: #656d76;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-subtle: rgba(88, 166, 255, 0.1);
  --code-bg: #1c2128;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --header-bg: rgba(13, 17, 23, 0.85);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --radius: 8px;
  --header-height: 60px;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #e8ecf0;
  --bg-hover: #f0f3f6;
  --border: #d1d9e0;
  --border-light: #b8c0c8;
  --text-primary: #1f2328;
  --text-secondary: #59636e;
  --text-muted: #818b98;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-subtle: rgba(9, 105, 218, 0.08);
  --code-bg: #f0f3f6;
  --green: #1a7f37;
  --yellow: #9a6700;
  --red: #d1242f;
  --header-bg: rgba(255, 255, 255, 0.85);
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 1rem);
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

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

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-primary);
  text-decoration: none;
}

.site-logo:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.logo-icon {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 1.2rem;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
}

.site-nav a {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s;
}

.site-nav a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  transition: color 0.15s;
}

[data-theme="dark"] .theme-toggle:hover {
  color: #f0b429;
}

[data-theme="light"] .theme-toggle:hover {
  color: var(--accent);
}

[data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: inline; }
[data-theme="light"] .theme-icon-dark { display: inline; }
[data-theme="light"] .theme-icon-light { display: none; }

/* ===== Main Content ===== */
.site-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ===== Page Layout (cheatsheet pages) ===== */
.page-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 3rem;
  align-items: start;
}

.page-layout.no-toc {
  grid-template-columns: 1fr;
}

/* ===== TOC Sidebar ===== */
.toc-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 2rem);
  max-height: calc(100vh - var(--header-height) - 4rem);
  overflow-y: auto;
  font-size: 0.8rem;
}

.toc-header {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

#toc-nav ul {
  list-style: none;
}

#toc-nav li {
  margin-bottom: 2px;
}

#toc-nav a {
  display: block;
  padding: 3px 8px;
  color: var(--text-secondary);
  border-radius: 4px;
  font-size: 0.8rem;
  line-height: 1.4;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}

#toc-nav a:hover {
  color: var(--text-primary);
  text-decoration: none;
  background: var(--bg-hover);
}

#toc-nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-subtle);
}

#toc-nav .toc-h3 a {
  padding-left: 1.25rem;
  font-size: 0.75rem;
}

/* ===== Article Content ===== */
.page-content {
  min-width: 0;
}

.page-content h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.3;
}

.page-content h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.page-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 1.75rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.page-content h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.page-content p {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.page-content > p:first-child,
.page-content > h1 + p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.page-content ul, .page-content ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.page-content li {
  margin-bottom: 0.35rem;
}

.page-content li > ul, .page-content li > ol {
  margin-top: 0.35rem;
  margin-bottom: 0;
}

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

.page-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ===== Inline Code ===== */
.page-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--accent-hover);
}

/* ===== Code Blocks ===== */
.page-content pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

.page-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* ===== Tables ===== */
.page-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.page-content thead {
  position: sticky;
  top: 0;
}

.page-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
  text-align: left;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.page-content td {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  vertical-align: top;
}

.page-content tr:nth-child(even) {
  background: var(--bg-secondary);
}

.page-content tr:hover {
  background: var(--bg-hover);
}

.page-content td code {
  font-size: 0.82em;
  word-break: break-all;
  white-space: normal;
}

.page-content td:last-child {
  min-width: 200px;
}

/* ===== Mermaid Diagrams ===== */
.mermaid {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  text-align: center;
  overflow-x: auto;
}

/* ===== Blockquotes ===== */
.page-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  background: var(--accent-subtle);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

.page-content blockquote p:last-child {
  margin-bottom: 0;
}

/* ===== Home Page ===== */
.home {
  max-width: 820px;
  margin: 0 auto;
}

.home-hero {
  text-align: center;
  padding: 1.25rem 0 2.25rem;
}

.home-hero h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.home-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.search-box {
  max-width: 360px;
  margin: 0 auto;
  position: relative;
}

.search-box::before {
  content: "\f002";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.85rem 0.5rem 2.25rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

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

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ===== Card Groups ===== */
.card-group {
  margin-bottom: 1.5rem;
}

.group-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-left: 0.15rem;
}

/* ===== Cheatsheet Grid ===== */
.cheatsheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.cheatsheet-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  transition: all 0.15s;
  text-decoration: none;
}

.cheatsheet-card:hover {
  border-color: var(--border);
  background: var(--bg-secondary);
  text-decoration: none;
}

.card-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  width: 1.25rem;
  text-align: center;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-inner a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-inner a:hover {
  color: var(--text-secondary);
  text-decoration: none;
}

/* ===== Scrollbar ===== */
@media (pointer: fine) {
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-track {
    background: var(--bg-primary);
  }

  ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
  }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .page-layout {
    grid-template-columns: 1fr;
  }

  .toc-sidebar {
    display: none;
  }
}

@media (max-width: 768px) {
  .cheatsheet-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .home-hero h1 {
    font-size: 1.5rem;
  }

  .cheatsheet-grid {
    grid-template-columns: 1fr;
  }

  .page-content h1 {
    font-size: 1.5rem;
  }

  .page-content h2 {
    font-size: 1.2rem;
  }

  .site-main {
    padding: 1rem;
  }
}

/* ===== Syntax Highlighting (Rouge - GitHub Dark) ===== */
[data-theme="dark"] .highlight .c, [data-theme="dark"] .highlight .cm, [data-theme="dark"] .highlight .c1, [data-theme="dark"] .highlight .cs { color: #8b949e; }
[data-theme="dark"] .highlight .k, [data-theme="dark"] .highlight .kd, [data-theme="dark"] .highlight .kn, [data-theme="dark"] .highlight .kp, [data-theme="dark"] .highlight .kr { color: #ff7b72; }
[data-theme="dark"] .highlight .kt { color: #79c0ff; }
[data-theme="dark"] .highlight .s, [data-theme="dark"] .highlight .sb, [data-theme="dark"] .highlight .sc, [data-theme="dark"] .highlight .sd, [data-theme="dark"] .highlight .s2, [data-theme="dark"] .highlight .sh, [data-theme="dark"] .highlight .s1 { color: #a5d6ff; }
[data-theme="dark"] .highlight .si { color: #a5d6ff; }
[data-theme="dark"] .highlight .nb { color: #ffa657; }
[data-theme="dark"] .highlight .nf, [data-theme="dark"] .highlight .nx { color: #d2a8ff; }
[data-theme="dark"] .highlight .nc { color: #ffa657; }
[data-theme="dark"] .highlight .nn { color: #ffa657; }
[data-theme="dark"] .highlight .no { color: #79c0ff; }
[data-theme="dark"] .highlight .o, [data-theme="dark"] .highlight .ow { color: #ff7b72; }
[data-theme="dark"] .highlight .m, [data-theme="dark"] .highlight .mi, [data-theme="dark"] .highlight .mf, [data-theme="dark"] .highlight .mh, [data-theme="dark"] .highlight .mo { color: #79c0ff; }
[data-theme="dark"] .highlight .na { color: #79c0ff; }
[data-theme="dark"] .highlight .nt { color: #7ee787; }
[data-theme="dark"] .highlight .nv, [data-theme="dark"] .highlight .vi, [data-theme="dark"] .highlight .vg, [data-theme="dark"] .highlight .vs { color: #ffa657; }

/* ===== Syntax Highlighting (Rouge - GitHub Light) ===== */
[data-theme="light"] .highlight .c, [data-theme="light"] .highlight .cm, [data-theme="light"] .highlight .c1, [data-theme="light"] .highlight .cs { color: #6e7781; }
[data-theme="light"] .highlight .k, [data-theme="light"] .highlight .kd, [data-theme="light"] .highlight .kn, [data-theme="light"] .highlight .kp, [data-theme="light"] .highlight .kr { color: #cf222e; }
[data-theme="light"] .highlight .kt { color: #0550ae; }
[data-theme="light"] .highlight .s, [data-theme="light"] .highlight .sb, [data-theme="light"] .highlight .sc, [data-theme="light"] .highlight .sd, [data-theme="light"] .highlight .s2, [data-theme="light"] .highlight .sh, [data-theme="light"] .highlight .s1 { color: #0a3069; }
[data-theme="light"] .highlight .si { color: #0a3069; }
[data-theme="light"] .highlight .nb { color: #953800; }
[data-theme="light"] .highlight .nf, [data-theme="light"] .highlight .nx { color: #8250df; }
[data-theme="light"] .highlight .nc { color: #953800; }
[data-theme="light"] .highlight .nn { color: #953800; }
[data-theme="light"] .highlight .no { color: #0550ae; }
[data-theme="light"] .highlight .o, [data-theme="light"] .highlight .ow { color: #cf222e; }
[data-theme="light"] .highlight .m, [data-theme="light"] .highlight .mi, [data-theme="light"] .highlight .mf, [data-theme="light"] .highlight .mh, [data-theme="light"] .highlight .mo { color: #0550ae; }
[data-theme="light"] .highlight .na { color: #0550ae; }
[data-theme="light"] .highlight .nt { color: #116329; }
[data-theme="light"] .highlight .nv, [data-theme="light"] .highlight .vi, [data-theme="light"] .highlight .vg, [data-theme="light"] .highlight .vs { color: #953800; }

.highlight .p { color: var(--text-primary); }
.highlight .err { color: var(--red); }
