:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --bg-hover: #1c2128;
  --border: #30363d;
  --border-muted: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-subtle: #656d76;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-bg: rgba(88,166,255,0.1);
  --green: #3fb950;
  --green-bg: rgba(63,185,80,0.1);
  --orange: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --sidebar-w: 260px;
  --navbar-h: 56px;
  --content-max: 860px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 6px;
  --radius-lg: 12px;
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

[data-theme='light'] {
  --bg: #ffffff;
  --bg-2: #f6f8fa;
  --bg-3: #eaeef2;
  --bg-hover: #f3f4f6;
  --border: #d0d7de;
  --border-muted: #e1e4e8;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-subtle: #8c959f;
  --accent: #0969da;
  --accent-hover: #0349b4;
  --accent-bg: rgba(9,105,218,0.1);
  --green: #1a7f37;
  --green-bg: rgba(26,127,55,0.1);
  --orange: #9a6700;
  --red: #d1242f;
  --purple: #8250df;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font);
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-2);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: var(--radius);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

::selection {
  background-color: var(--accent-bg);
  color: var(--accent);
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(to right, var(--accent), var(--purple));
  z-index: 10000;
  transition: width 0.1s;
}

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-h);
  background: rgba(13, 17, 23, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  align-items: center;
}

[data-theme='light'] .navbar {
  background: rgba(255, 255, 255, 0.8);
}

.navbar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 1.5rem;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.5px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  width: 32px;
  height: 32px;
  position: relative;
  z-index: 100;
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background-color: var(--text);
  margin-bottom: 4px;
  transition: var(--transition);
  transform-origin: center;
}
.hamburger span:last-child { margin-bottom: 0; }

.hamburger.open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.hamburger.open span:nth-child(2) {
  opacity: 0;
}
.hamburger.open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.icon-button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: var(--radius);
  transition: var(--transition);
}

.icon-button:hover {
  color: var(--text);
  background-color: var(--bg-hover);
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: 99px;
  font-size: 0.875rem;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
}

.search-trigger:hover {
  border-color: var(--border-muted);
  background-color: var(--bg-hover);
  color: var(--text);
}

.search-shortcut {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: var(--bg-3);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme='light'] .theme-toggle .sun-icon { display: block; }
[data-theme='light'] .theme-toggle .moon-icon { display: none; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  padding-top: var(--navbar-h);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: var(--navbar-h);
  bottom: 0;
  width: var(--sidebar-w);
  background-color: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1.5rem 1rem;
  z-index: 900;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-group {
  margin-bottom: 1.5rem;
}

.nav-group-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-subtle);
  margin-bottom: 0.5rem;
  padding: 0 0.5rem;
}

.sidebar ul {
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-radius: var(--radius);
  transition: var(--transition);
  margin-bottom: 0.1rem;
}

.nav-item:hover {
  background-color: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background-color: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
  border-left: 3px solid var(--accent);
}

.badge-new {
  font-size: 0.65rem;
  background-color: var(--green-bg);
  color: var(--green);
  padding: 0.1rem 0.3rem;
  border-radius: 99px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.content {
  grid-column: 2;
  overflow-y: auto;
  height: calc(100vh - var(--navbar-h));
  position: relative;
}

article {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 3rem 2rem 5rem;
  animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Typography & Content Formatting */
article h1 { font-size: 2rem; font-weight: 700; margin-bottom: 1.5rem; color: var(--text); }
article h2 { font-size: 1.5rem; font-weight: 600; margin-top: 2.5rem; margin-bottom: 1rem; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
article h3 { font-size: 1.25rem; font-weight: 600; margin-top: 2rem; margin-bottom: 0.75rem; color: var(--text); }
article h4 { font-size: 1rem; font-weight: 600; margin-top: 1.5rem; margin-bottom: 0.5rem; color: var(--text); }

article h1, article h2, article h3, article h4 {
  position: relative;
}

.anchor {
  position: absolute;
  left: -1.25rem;
  color: transparent;
  text-decoration: none;
  transition: var(--transition);
}

article h1:hover .anchor,
article h2:hover .anchor,
article h3:hover .anchor,
article h4:hover .anchor {
  color: var(--text-subtle);
}

article p { margin-bottom: 1rem; color: var(--text-muted); line-height: 1.7; }
article ul, article ol { margin-bottom: 1rem; padding-left: 1.5rem; color: var(--text-muted); line-height: 1.7; }
article li { margin-bottom: 0.25rem; }
article li > p { margin-bottom: 0.5rem; }

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

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

article hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

article blockquote {
  border-left: 3px solid var(--border-muted);
  background-color: var(--bg-2);
  padding: 1rem;
  margin: 1.5rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
}
article blockquote p:last-child { margin-bottom: 0; }

article code {
  font-family: var(--mono);
  background-color: var(--bg-3);
  color: var(--accent);
  padding: 0.15em 0.3em;
  border-radius: var(--radius);
  font-size: 0.85em;
}

article pre {
  background-color: var(--bg-2) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
  overflow-x: auto;
}
article pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.875rem;
}
article th, article td {
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  text-align: left;
}
article th {
  background-color: var(--bg-3);
  font-weight: 600;
  color: var(--text);
}
article tr:hover td {
  background-color: var(--bg-hover);
}

/* Loading */
.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.loading-spinner.hidden { display: none; }
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

/* Search Modal */
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
}
.search-modal.open {
  display: flex;
}
.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.search-box {
  position: relative;
  width: 100%;
  max-width: 560px;
  background-color: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.search-input-wrapper {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.search-input-wrapper input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 1.1rem;
  padding: 0 0.75rem;
  outline: none;
}
.search-results {
  max-height: 60vh;
  overflow-y: auto;
}
.search-result-item {
  display: block;
  padding: 1rem 1.25rem;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.selected {
  background-color: var(--bg-hover);
}
.search-result-title {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.search-result-excerpt {
  color: var(--text-muted);
  font-size: 0.875rem;
}
.search-result-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

/* Mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--navbar-h);
  background: rgba(0,0,0,0.5);
  z-index: 800;
  opacity: 0;
  transition: opacity 0.3s;
}

@media (max-width: 768px) {
  .hamburger { display: block; }
  .layout { grid-template-columns: 1fr; }
  .content { grid-column: 1; }
  
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar.open ~ .sidebar-overlay {
    display: block;
    opacity: 1;
  }
  
  .search-box {
    margin: 0 1rem;
  }
  
  article {
    padding: 2rem 1.5rem 4rem;
  }
}
