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

:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface-2:    #21262d;
  --border:       #30363d;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --text-subtle:  #6e7681;
  --accent:       #58a6ff;
  --accent-hover: #79c0ff;
  --green:        #3fb950;
  --red:          #f85149;
  --tag-bg:       #1f3351;
  --tag-text:     #58a6ff;
  --code-bg:      #161b22;
  --radius:       6px;
  --radius-lg:    12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ── Layout ──────────────────────────────────────────────────────────────── */
.container { max-width: 900px; margin: 0 auto; padding: 0 24px; }
.container-wide { max-width: 1100px; margin: 0 auto; padding: 0 24px; }
main { flex: 1; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.site-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.site-title:hover { color: var(--accent); text-decoration: none; }

nav { display: flex; gap: 4px; align-items: center; }
nav a {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}
nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
  color: var(--text-subtle);
  font-size: 0.8rem;
  margin-top: auto;
}

/* ── Hero ────────────────────────────────────────────────────────────────── */
.hero {
  padding: 56px 0 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
.hero h1 { font-size: 2rem; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.03em; }
.hero p { color: var(--text-muted); font-size: 1.05rem; }

/* ── Category Filter ─────────────────────────────────────────────────────── */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 32px;
}
.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s;
}
.tag:hover { opacity: 0.8; text-decoration: none; color: var(--tag-text); }
.tag.active { background: var(--accent); color: #000; }
.tag-clear { background: var(--surface-2); color: var(--text-muted); }

/* ── Post Cards ──────────────────────────────────────────────────────────── */
.post-grid { display: flex; flex-direction: column; gap: 1px; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  transition: border-color 0.15s, background 0.15s;
}
.post-card:hover { border-color: var(--accent); background: var(--surface-2); }

.post-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.post-card-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.post-card-title:hover { color: var(--accent); text-decoration: none; }

.post-card-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 14px;
}

.post-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.read-more {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}
.read-more:hover { color: var(--accent-hover); text-decoration: none; }
.read-more::after { content: ' →'; }

/* ── Article ─────────────────────────────────────────────────────────────── */
.article-header {
  padding: 48px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
}
.back-link:hover { color: var(--text); text-decoration: none; }
.back-link::before { content: '←'; }

.article-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.2;
  margin-bottom: 16px;
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.875rem;
  flex-wrap: wrap;
}

.article-body {
  padding-bottom: 60px;
}

/* ── Markdown Content ────────────────────────────────────────────────────── */
.prose { max-width: 720px; }

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 2rem 0 0.75rem;
  line-height: 1.3;
}
.prose h1 { font-size: 1.8rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.prose h2 { font-size: 1.4rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.prose h3 { font-size: 1.15rem; }
.prose h4 { font-size: 1rem; color: var(--text-muted); }

.prose p { margin-bottom: 1rem; }
.prose ul, .prose ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.prose li { margin-bottom: 0.3rem; }
.prose strong { color: var(--text); font-weight: 600; }
.prose em { font-style: italic; }
.prose a { color: var(--accent); }

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

.prose blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  color: var(--text-muted);
  margin: 1.5rem 0;
  font-style: italic;
}

/* Inline code */
.prose code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: #e6b450;
}

/* Code blocks */
.prose pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  overflow-x: auto;
  margin: 1.25rem 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

.prose pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* highlight.js overrides */
.hljs { background: transparent; color: #adbac7; }
.hljs-keyword, .hljs-selector-tag { color: #f47067; }
.hljs-string, .hljs-attr { color: #96d0ff; }
.hljs-number, .hljs-literal { color: #6cb6ff; }
.hljs-comment { color: #768390; font-style: italic; }
.hljs-class .hljs-title, .hljs-type { color: #cae8ff; }
.hljs-function .hljs-title, .hljs-title.function_ { color: #dcbdfb; }
.hljs-built_in { color: #6cb6ff; }
.hljs-variable { color: #e6b450; }
.hljs-tag { color: #8ddb8c; }
.hljs-name { color: #8ddb8c; }
.hljs-attribute { color: #6cb6ff; }
.hljs-meta { color: #768390; }
.hljs-symbol { color: #e6b450; }

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 0;
  color: var(--text-muted);
}
.empty-state h2 { font-size: 1.5rem; margin-bottom: 8px; color: var(--text); }

/* ── Admin Styles ────────────────────────────────────────────────────────── */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.admin-header h1 { font-size: 1.5rem; font-weight: 700; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; opacity: 1; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.admin-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--surface-2); }
.admin-table .actions { display: flex; gap: 8px; justify-content: flex-end; }

.admin-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-input,
.form-textarea,
.form-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}
.form-input:focus,
.form-textarea:focus { border-color: var(--accent); }

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

.form-textarea.mono {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  min-height: 500px;
  tab-size: 2;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.error-msg {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

/* ── Login Page ──────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.login-card p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 28px;
}

/* ── Editor Layout ───────────────────────────────────────────────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.editor-pane { display: flex; flex-direction: column; }
.editor-pane-header {
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.editor-pane-header:not(:last-child) { border-right: 1px solid var(--border); }
.preview-pane {
  border-left: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
}
.preview-pane-inner { padding: 24px; }
.editor-textarea {
  flex: 1;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  padding: 20px;
}
.editor-textarea:focus { border-color: var(--border); }

/* ── 404 ─────────────────────────────────────────────────────────────────── */
.not-found {
  text-align: center;
  padding: 100px 24px;
}
.not-found h1 { font-size: 4rem; font-weight: 800; color: var(--border); margin-bottom: 16px; }
.not-found p { color: var(--text-muted); margin-bottom: 24px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .editor-layout { grid-template-columns: 1fr; }
  .preview-pane { display: none; }
  .article-title { font-size: 1.7rem; }
  .hero h1 { font-size: 1.5rem; }
}
