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

:root {
  --bg: #f4f0ea;
  --surface: #fcf9f5;
  --surface-hover: #f6f2ec;
  --border: #e5ddd2;
  --border-light: #efe8de;
  --text: #1d1b16;
  --text-secondary: #6b6256;
  --text-tertiary: #a09787;
  --primary: #c97a5a;
  --primary-hover: #b06444;
  --primary-light: #f0ddd0;
  --primary-glow: rgba(201, 122, 90, 0.12);
  --accent: #7d9e7a;
  --accent-hover: #658a69;
  --accent-light: #e8f0e8;
  --danger: #c94f4f;
  --danger-light: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', monospace;
}

html { -webkit-font-smoothing: antialiased; }

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

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

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

img { max-width: 100%; height: auto; display: block; }

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 1001;
  background: rgba(252, 249, 245, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-light);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 2px;
}

.navbar-links a {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.navbar-links a:hover { background: var(--surface-hover); color: var(--text); }

.user-menu-wrap { position: relative; display: flex; align-items: center; }

.user-menu-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--text-tertiary);
  padding: 0;
}

.user-menu-btn:hover { background: var(--surface-hover); color: var(--text-secondary); }

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #b58b72);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s;
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 1002;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: all 0.2s ease;
}

.user-menu-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0); }

.user-menu-dropdown .dropdown-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-light);
}

.user-menu-dropdown .dropdown-name { font-weight: 600; font-size: 0.85rem; color: var(--text); }
.user-menu-dropdown .dropdown-email { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 1px; }

.user-menu-dropdown .dropdown-link {
  display: block;
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.12s;
}

.user-menu-dropdown .dropdown-link:hover { background: var(--surface-hover); color: var(--text); }

.user-menu-dropdown .dropdown-btn {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 0.85rem;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: background 0.12s;
  color: var(--danger);
}

.user-menu-dropdown .dropdown-btn:hover { background: var(--danger-light); }

.user-menu-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: none;
  background: transparent;
}

.user-menu-overlay.open { display: block; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  line-height: 1.4;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b84343; }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* Hero */
.hero {
  text-align: center;
  padding: 52px 0 28px;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
  color: var(--text);
}

.hero p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 420px;
  margin: 0 auto 18px;
}

/* Post list */
.posts-list { padding-bottom: 52px; }

.post-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 10px;
  transition: all 0.2s ease;
  color: inherit;
}

.post-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  color: inherit;
}

.post-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
  line-height: 1.3;
}

.post-card-meta {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.post-card-excerpt {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

.post-card-footer {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

.post-card-footer span { display: inline-flex; align-items: center; gap: 4px; }

/* Post page */
.post-page { padding-top: 24px; }

.post-header {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 28px;
}

.post-header h1 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  line-height: 1.25;
}

.post-meta {
  display: flex;
  gap: 12px;
  color: var(--text-tertiary);
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.post-content { font-size: 1rem; line-height: 1.85; color: var(--text); overflow-wrap: break-word; }
.post-content p { margin-bottom: 1.2em; }
.post-content h2 { font-size: 1.3rem; font-weight: 700; margin: 1.5em 0 0.4em; }
.post-content h3 { font-size: 1.1rem; font-weight: 600; margin: 1.2em 0 0.3em; }
.post-content ul, .post-content ol { margin: 1em 0; padding-left: 1.5em; }
.post-content li { margin-bottom: 0.3em; }
.post-content blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 16px;
  color: var(--text-secondary);
  margin: 1.2em 0;
  font-style: italic;
}
.post-content code {
  background: var(--surface-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.post-content pre {
  background: #1a1a2e;
  color: #e4e4e7;
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 1.2em 0;
  line-height: 1.6;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.post-content img { border-radius: var(--radius-sm); margin: 1.2em 0; }

.post-actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border-light);
}

.like-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  transition: all 0.15s;
  color: var(--text-tertiary);
  font-weight: 500;
}

.like-btn:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }
.like-btn.liked { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }

.post-nav { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--border-light); }

/* Comments */
.comments-section { margin-top: 36px; padding-top: 24px; border-top: 1px solid var(--border-light); }

.comments-section h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.comment-form { margin-bottom: 20px; }

.comment-form textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: vertical;
  min-height: 72px;
  transition: border-color 0.15s;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
}

.comment-form textarea:focus { outline: none; border-color: var(--primary); }
.comment-form .btn { margin-top: 8px; }

.comment { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border-light); }
.comment:last-child { border-bottom: none; }

.comment-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.comment-body { flex: 1; min-width: 0; }
.comment-author { font-weight: 600; font-size: 0.85rem; margin-bottom: 1px; }
.comment-time { font-size: 0.72rem; color: var(--text-tertiary); margin-bottom: 4px; }
.comment-text { font-size: 0.88rem; line-height: 1.55; color: var(--text); }

.comment-as { font-size: 0.75rem; color: var(--text-tertiary); margin: 6px 0 8px; }
.comment-as strong { color: var(--text); font-weight: 600; }

/* Auth */
.auth-page {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.85rem;
  margin-bottom: 22px;
}

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: all 0.15s;
  background: var(--surface);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.form-actions { margin-top: 18px; }
.form-actions .btn { width: 100%; justify-content: center; }

.auth-footer { text-align: center; margin-top: 14px; font-size: 0.85rem; color: var(--text-tertiary); }
.auth-footer a { font-weight: 600; }

.forgot-link {
  display: block;
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-top: -8px;
  margin-bottom: 14px;
}

.forgot-link:hover { color: var(--primary); }

/* Admin */
.admin-page { padding: 28px 0 52px; }

.admin-page h1 { font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; }

.admin-subtitle { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 22px; }

.admin-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border-light);
}

.admin-tabs button {
  padding: 9px 20px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}

.admin-tabs button:hover { color: var(--text); }
.admin-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.admin-form { max-width: 620px; }
.admin-form textarea { min-height: 280px; font-family: var(--font-mono); font-size: 0.85rem; }

.admin-post-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  gap: 10px;
  transition: border-color 0.15s;
}

.admin-post-item:hover { border-color: var(--border); }

.admin-post-info { flex: 1; min-width: 0; }
.admin-post-info h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-post-info .meta { font-size: 0.78rem; color: var(--text-tertiary); }

.admin-post-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 99999;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  line-height: 1.4;
}

.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-info { background: #2c281f; color: #fff; }
.toast-success { background: var(--accent); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* Loading */
.loading {
  text-align: center;
  padding: 48px;
  color: var(--text-tertiary);
}

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 52px 20px; color: var(--text-tertiary); }
.empty-state h3 { font-size: 1.05rem; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.9rem; margin-bottom: 16px; }

/* Footer */
.footer {
  text-align: center;
  padding: 28px 0;
  color: var(--text-tertiary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-light);
  margin-top: 36px;
}

/* Verify notice */
.verify-notice {
  background: var(--primary-light);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.85rem;
  border: 1px solid #e8cdc0;
}

/* Responsive */
@media (max-width: 640px) {
  .container { padding: 0 18px; }
  .hero h1 { font-size: 1.55rem; }
  .hero { padding: 36px 0 20px; }
  .post-card { padding: 18px 20px; }
  .post-header h1 { font-size: 1.3rem; }
  .auth-card { padding: 28px 22px; }
  .navbar-links a { padding: 6px 10px; font-size: 0.8rem; }
  .admin-post-item { flex-direction: column; align-items: stretch; }
  .admin-post-actions { justify-content: flex-end; }
  .admin-form textarea { min-height: 200px; }
  .post-content pre { font-size: 0.8rem; padding: 12px 14px; }
  .comment-form textarea { min-height: 60px; }
}

@media (max-width: 480px) {
  .container { padding: 0 14px; }
  .navbar .container { height: 52px; }
  .hero h1 { font-size: 1.3rem; }
  .hero p { font-size: 0.85rem; }
  .post-card-title { font-size: 1rem; }
  .post-header h1 { font-size: 1.15rem; }
  .user-menu-dropdown { right: -6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
