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

:root {
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --transition: 0.25s ease;
  --max-width: 900px;
  --header-h: 60px;
}

[data-theme="dark"] {
  --bg: #0a0e0a;
  --bg-alt: #0d120d;
  --surface: #111811;
  --surface-alt: #161e16;
  --text: #d4e0d4;
  --text-secondary: #9aaa9a;
  --text-muted: #7a8a7a;
  --border: #2d4a2d;
  --border-bright: #3d6b3d;
  --primary: #4caf50;
  --primary-hover: #66bb6a;
  --primary-dim: #2e7d32;
  --danger: #e57373;
  --danger-hover: #ef9a9a;
  --input-bg: #1a241a;
  --input-border: #2d4a2d;
  --card-bg: #111811;
  --card-border: #2d4a2d;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.5);
  --code-bg: #0d120d;
  --toast-bg: #1a241a;
  --toast-border: #3d6b3d;
  --scrollbar-track: #0d120d;
  --scrollbar-thumb: #2d4a2d;
}

[data-theme="light"] {
  --bg: #f5f0eb;
  --bg-alt: #f2ece6;
  --surface: #faf7f4;
  --surface-alt: #fdfbfa;
  --text: #3d2c2c;
  --text-secondary: #7a6060;
  --text-muted: #a08080;
  --border: #e8d5d0;
  --border-bright: #dbb8b8;
  --primary: #c97a7a;
  --primary-hover: #d48f8f;
  --primary-dim: #b06060;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --input-bg: #fdfbfa;
  --input-border: #e8d5d0;
  --card-bg: #faf7f4;
  --card-border: #e8d5d0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.1);
  --code-bg: #f2ece6;
  --toast-bg: #faf7f4;
  --toast-border: #dbb8b8;
  --scrollbar-track: #f2ece6;
  --scrollbar-thumb: #e8d5d0;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

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

::selection { background: var(--primary); color: #fff; }

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

img { max-width: 100%; height: auto; border-radius: var(--radius); }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  height: var(--header-h);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary) !important;
  text-decoration: none !important;
  letter-spacing: -0.5px;
}

#nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

#nav a {
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: all var(--transition);
  text-decoration: none;
}
#nav a:hover,
#nav a.active {
  color: var(--text);
  background: var(--surface-alt);
  text-decoration: none;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.0rem;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: all var(--transition);
  line-height: 1;
}
.icon-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border-bright);
}

#mobile-menu-btn { display: none; }

/* Main */
#main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 30px 20px;
  width: 100%;
}

.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-muted);
  font-style: italic;
}

/* Footer */
#footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  transition: background var(--transition), border-color var(--transition);
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
}
.card:hover { border-color: var(--border-bright); }

.card-grid {
  display: grid;
  gap: 16px;
}

/* Blog cards */
.blog-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
  cursor: pointer;
}
.blog-card:hover {
  border-color: var(--border-bright);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.blog-card a {
  color: inherit;
  text-decoration: none;
}
.blog-card a:hover {
  text-decoration: none;
}
.card-img {
  width: 100%;
  height: 200px;
  overflow: hidden;
}
.card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-img--default {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface-alt), var(--border));
  font-size: 3rem;
}
.card-body {
  padding: 20px 24px 24px;
}
.card-body h2 {
  font-size: 1.3rem;
  margin-bottom: 6px;
  color: var(--text);
}
.card-body .meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.card-body .subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.cat-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--primary-dim);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-img { position: relative; }
.card-cat {
  position: absolute;
  top: 10px;
  left: 10px;
}
.blog-header-cat { margin-bottom: 12px; }

/* Blog detail */
.blog-detail .blog-header {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.blog-detail h1 {
  font-size: 2rem;
  line-height: 1.3;
  margin-bottom: 4px;
}
.blog-detail .subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.blog-detail .meta {
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.blog-detail .blog-body {
  font-size: 1.05rem;
  line-height: 1.8;
}
.blog-detail .blog-body p { margin-bottom: 1em; }
.blog-detail .blog-body img {
  display: block;
  max-width: 100%;
  height: auto;
  min-height: 160px;
  margin: 20px auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  background: var(--surface-alt);
}
.blog-detail .blog-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 12px 20px;
  margin: 16px 0;
  background: var(--surface-alt);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}
.blog-detail .blog-body pre {
  background: var(--code-bg);
  padding: 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin: 16px 0;
}
.blog-detail .blog-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.blog-detail .blog-footer {
  margin-top: 30px;
  padding: 20px;
  background: var(--surface-alt);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.blog-detail .sources {
  margin-top: 20px;
  font-size: 0.9rem;
}
.blog-detail .sources h3 {
  margin-bottom: 8px;
  color: var(--text-secondary);
}
.blog-detail .sources a {
  display: inline-block;
  margin-right: 12px;
  margin-bottom: 4px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="file"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: all var(--transition);
  outline: none;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(76,175,80,0.15);
}
[data-theme="light"] input:focus,
[data-theme="light"] textarea:focus,
[data-theme="light"] select:focus {
  box-shadow: 0 0 0 3px rgba(201,122,122,0.15);
}

textarea {
  min-height: 120px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.btn:hover {
  background: var(--surface-alt);
  border-color: var(--border-bright);
  text-decoration: none;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}
.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

/* Forms layout */
.form-card {
  max-width: 480px;
  margin: 0 auto;
}
.form-card h1 {
  margin-bottom: 24px;
  font-size: 1.5rem;
  text-align: center;
}

/* Comments */
.comments-section {
  margin-top: 40px;
}
.comments-section h2 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.comment {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--surface);
  transition: background var(--transition), border-color var(--transition);
}
.comment .comment-author {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary);
  margin-bottom: 4px;
}
.comment .comment-text {
  color: var(--text);
  line-height: 1.6;
}
.comment .comment-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}
.comment-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 0;
  font-style: italic;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--toast-bg);
  border: 1px solid var(--toast-border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition: all 0.4s ease;
  pointer-events: none;
  font-size: 0.95rem;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

/* Back btn */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 0.9rem;
}
.back-btn:hover { color: var(--text); }

/* User badge */
.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.user-badge .logout-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.user-badge .logout-btn:hover {
  background: rgba(229,115,115,0.15);
}

/* Section titles */
.section-title {
  font-size: 1.6rem;
  margin-bottom: 24px;
}
.section-subtitle {
  color: var(--text-secondary);
  margin-bottom: 30px;
  font-size: 1rem;
}

/* Auth page specific */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-h) - 100px);
}
.auth-page .form-card {
  width: 100%;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

/* Responsive */
@media (max-width: 600px) {
  #nav a, #nav button { display: none; padding: 6px 10px; font-size: 0.82rem; }
  #mobile-menu-btn { display: inline-flex; }
  #nav.expanded { position: absolute; top: var(--header-h); left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--border); flex-direction: column; padding: 12px 20px; gap: 4px; }
  #nav.expanded a, #nav.expanded button { display: inline-flex; width: 100%; }
  .blog-detail h1 { font-size: 1.5rem; }
  .card { padding: 16px; }
  .blog-card { padding: 16px; }
}

/* Helper */
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
