:root[data-theme="light"] {
  --primary: #6366f1;
  --primary-light: #ede9fe;
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --text: #1a1a1a;
  --text-secondary: #6c757d;
  --border: #e9ecef;
}

:root[data-theme="dark"] {
  --primary: #818cf8;
  --primary-light: #312e81;
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #334155;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Navbar */
.navbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-weight: 700;
  font-size: 20px;
  color: var(--text);
  text-decoration: none;
}

.nav-links { display: flex; gap: 24px; }
.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}
.nav-links a:hover { color: var(--primary); }

.nav-actions { display: flex; gap: 12px; }
.nav-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
.nav-actions button:hover { background: var(--bg-secondary); }

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

/* Hero */
.hero {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 48px 0;
  text-align: center;
}

.hero-avatar {
  width: 80px;
  height: 80px;
  background: var(--primary-light);
  border-radius: 50%;
  margin: 0 auto 16px;
}

.hero h1 { font-size: 32px; margin-bottom: 8px; }
.hero-desc { color: var(--text-secondary); margin-bottom: 16px; }
.hero-tags { display: flex; gap: 8px; justify-content: center; }

/* Tags */
.tag {
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 14px;
  text-decoration: none;
  transition: opacity 0.2s;
}
.tag:hover { opacity: 0.8; }

/* Posts Grid */
.posts {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 48px 0;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.1);
}

.card-cover {
  height: 100%;
  min-height: 140px;
  background: var(--primary-light);
  background-size: cover;
  background-position: center;
}

.card-cover.placeholder {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
}

.card-link {
  display: grid;
  grid-template-columns: 200px 1fr;
  text-decoration: none;
  color: inherit;
}

.card-body { padding: 20px; }

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.date {
  color: var(--text-secondary);
  font-size: 14px;
}

.card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.card h2 a {
  color: var(--text);
  text-decoration: none;
}

.card h2 a:hover { color: var(--primary); }

.summary {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Single Post */
.single-layout {
  max-width: 1200px;
  margin: 48px auto;
  padding: 0 20px;
}

.single-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 48px;
}

.post-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.post-header h1 {
  font-size: 36px;
  margin-top: 12px;
}

.read-time {
  color: var(--text-secondary);
  font-size: 14px;
}

.post-content {
  font-size: 16px;
  line-height: 1.8;
}

.post-content h2 { margin-top: 32px; margin-bottom: 16px; }
.post-content p { margin-bottom: 16px; }
.post-content code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
}

.post-content pre {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
}

.post-content strong { font-weight: 700; }

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.post-content th,
.post-content td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}

.post-content th {
  background: var(--bg-secondary);
  font-weight: 700;
}

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

.post-content ul,
.post-content ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.post-content li { margin-bottom: 4px; }

.post-content blockquote {
  border-left: 4px solid var(--primary);
  padding: 8px 16px;
  margin: 0 0 16px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 0 8px 8px 0;
}

.post-content a { color: var(--primary); }

.post-content img {
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 16px;
}

.post-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* TOC */
.toc {
  position: sticky;
  top: 100px;
  height: fit-content;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.toc-title {
  font-weight: 700;
  margin-bottom: 12px;
}

.toc ul { list-style: none; }
.toc li { margin: 8px 0; }
.toc a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
}

.toc a:hover,
.toc a.active { color: var(--primary); }

/* Search Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

.modal.active { display: flex; align-items: flex-start; justify-content: center; padding-top: 100px; }

.modal-content {
  background: var(--bg);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 70vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.search-box {
  display: flex;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

#search-input {
  flex: 1;
  background: var(--bg-secondary);
  border: none;
  padding: 12px;
  border-radius: 6px;
  color: var(--text);
  font-size: 16px;
}

#search-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 0 12px;
}

#search-results {
  padding: 16px;
  max-height: calc(70vh - 60px);
  overflow-y: auto;
}

.search-item {
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.search-item:hover { background: var(--bg-secondary); }

.search-item h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.search-item p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 32px 0;
  margin-top: 64px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

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

/* Comments */
.comments { margin-top: 48px; }

/* Responsive */
@media (max-width: 768px) {
  .single-grid { grid-template-columns: 1fr; }
  .toc { display: none; }
  .card-link { grid-template-columns: 1fr; }
  .card { grid-template-columns: 1fr; }
  .card-cover { min-height: 160px; }
}
