/* ─────────────────────────────────────────
   Design tokens
───────────────────────────────────────── */
:root {
  --bg:        #0f0f11;
  --surface:   #1a1a1f;
  --elevated:  #232329;
  --border:    rgba(255,255,255,.07);
  --accent:    #6c63ff;
  --accent-2:  #a78bfa;
  --glow:      rgba(108,99,255,.22);
  --text:      #e4e4f0;
  --muted:     #8080a0;
  --subtle:    #4a4a60;
  --danger:    #f87171;
  --success:   #34d399;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --nav-h:     64px;
  --font:      'Inter', system-ui, -apple-system, sans-serif;
  --mono:      'JetBrains Mono', 'Fira Code', monospace;

  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 48px rgba(0,0,0,.5);
}

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

html { scroll-behavior: smooth; }

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

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { cursor: pointer; font: inherit; border: none; background: none; }

/* ─────────────────────────────────────────
   Navbar
───────────────────────────────────────── */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem; height: var(--nav-h);
  background: rgba(15,15,17,.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-size: 1.125rem; font-weight: 800; letter-spacing: -0.5px;
  display: flex; align-items: center; gap: .35rem;
}
.nav-logo span { color: var(--accent); }

.nav-center {
  flex: 1; max-width: 380px; margin: 0 2rem;
}

.search-wrap {
  position: relative; display: flex; align-items: center;
}
.search-wrap svg {
  position: absolute; left: .75rem; color: var(--muted); pointer-events: none;
}
.search-input {
  width: 100%; padding: .5rem .75rem .5rem 2.25rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font: inherit; font-size: .875rem;
  transition: border-color .2s, box-shadow .2s;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }

.nav-actions { display: flex; align-items: center; gap: .5rem; }

/* ─────────────────────────────────────────
   Buttons
───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1.1rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 600;
  transition: transform .15s, opacity .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 12px var(--glow);
}
.btn-primary:hover { box-shadow: 0 4px 20px var(--glow); }

.btn-ghost {
  color: var(--muted); background: transparent;
  border: 1px solid transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--surface); border-color: var(--border); }

.btn-outline {
  color: var(--text); border: 1px solid var(--border); background: transparent;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--danger); color: #fff; }

.btn-sm { padding: .35rem .8rem; font-size: .8125rem; }
.btn-lg { padding: .75rem 1.75rem; font-size: 1rem; }

/* Avatar */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--border); background: var(--surface);
}
.avatar-lg { width: 56px; height: 56px; }
.avatar-xl { width: 80px; height: 80px; }

/* User menu */
.user-menu { position: relative; }
.user-trigger {
  display: flex; align-items: center; gap: .5rem;
  padding: .25rem .5rem; border-radius: var(--radius);
  cursor: pointer; transition: background .15s;
  border: 1px solid transparent;
}
.user-trigger:hover { background: var(--surface); border-color: var(--border); }
.user-trigger span { font-size: .875rem; font-weight: 500; }

.dropdown {
  position: absolute; top: calc(100% + .5rem); right: 0; min-width: 180px;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transform: translateY(-6px);
  transition: opacity .15s, transform .15s;
}
.dropdown.open { opacity: 1; pointer-events: all; transform: translateY(0); }
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: .5rem;
  width: 100%; padding: .65rem 1rem;
  font-size: .875rem; color: var(--text);
  transition: background .15s;
  text-align: left;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface); }
.dropdown hr { border: none; border-top: 1px solid var(--border); margin: .25rem 0; }
.dropdown .danger { color: var(--danger); }

/* ─────────────────────────────────────────
   Page layout
───────────────────────────────────────── */
.page { padding-top: var(--nav-h); min-height: 100vh; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 1.5rem; }
.container-sm { max-width: 780px; margin: 0 auto; padding: 0 1.5rem; }

/* ─────────────────────────────────────────
   Hero
───────────────────────────────────────── */
.hero {
  text-align: center; padding: 5rem 1.5rem 3.5rem;
  background: radial-gradient(ellipse 60% 40% at 50% 0%, rgba(108,99,255,.12) 0%, transparent 70%);
}
.hero-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .3rem 1rem; margin-bottom: 1.5rem;
  background: var(--glow); border: 1px solid rgba(108,99,255,.4);
  border-radius: 999px; font-size: .75rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2);
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 800;
  letter-spacing: -1.5px; line-height: 1.1; margin-bottom: 1rem;
}
.hero h1 em {
  font-style: normal;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.hero p { font-size: 1.0625rem; color: var(--muted); max-width: 480px; margin: 0 auto; }

/* ─────────────────────────────────────────
   Category filter
───────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: 1.5rem 0;
}
.filter-pill {
  padding: .4rem 1rem; border-radius: 999px; font-size: .8125rem; font-weight: 500;
  border: 1px solid var(--border); color: var(--muted); background: transparent;
  cursor: pointer; transition: all .15s;
}
.filter-pill:hover { border-color: var(--accent); color: var(--accent); }
.filter-pill.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* ─────────────────────────────────────────
   Post grid
───────────────────────────────────────── */
.posts-grid {
  display: grid; gap: 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.post-card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.post-card:hover {
  transform: translateY(-3px); box-shadow: var(--shadow);
  border-color: rgba(108,99,255,.3);
}

.card-image {
  width: 100%; height: 200px; object-fit: cover;
  background: var(--elevated);
}

.card-body { padding: 1.25rem; flex: 1; display: flex; flex-direction: column; gap: .75rem; }

.card-meta { display: flex; align-items: center; gap: .75rem; }
.category-tag {
  padding: .2rem .65rem; border-radius: 999px; font-size: .7rem; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase;
  background: var(--glow); color: var(--accent-2); border: 1px solid rgba(108,99,255,.25);
}

.card-date { font-size: .75rem; color: var(--muted); }

.card-title {
  font-size: 1.0625rem; font-weight: 700; line-height: 1.35;
  color: var(--text); transition: color .15s;
}
.post-card:hover .card-title { color: var(--accent-2); }

.card-excerpt { font-size: .875rem; color: var(--muted); line-height: 1.6; flex: 1; }

.card-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: .75rem; border-top: 1px solid var(--border);
  margin-top: auto;
}

.author-mini { display: flex; align-items: center; gap: .5rem; }
.author-mini img { width: 24px; height: 24px; border-radius: 50%; }
.author-mini span { font-size: .8rem; color: var(--muted); }

.card-stats { display: flex; align-items: center; gap: .75rem; }
.stat { display: flex; align-items: center; gap: .3rem; font-size: .78rem; color: var(--subtle); }
.stat svg { width: 14px; height: 14px; }

/* ─────────────────────────────────────────
   Pagination
───────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 2.5rem 0;
}
.page-btn {
  min-width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  color: var(--muted); font-size: .875rem; font-weight: 500;
  cursor: pointer; transition: all .15s; background: transparent;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ─────────────────────────────────────────
   Empty / Loading states
───────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 5rem 1rem;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.empty-state svg { color: var(--subtle); }
.empty-state h3 { font-size: 1.125rem; }
.empty-state p { color: var(--muted); font-size: .9rem; }

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--elevated) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─────────────────────────────────────────
   Single Post Page
───────────────────────────────────────── */
.post-hero {
  position: relative; height: 420px; overflow: hidden;
  margin-bottom: 2.5rem;
}
.post-hero-img {
  width: 100%; height: 100%; object-fit: cover; filter: brightness(.55);
}
.post-hero-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  justify-content: flex-end; padding: 2.5rem;
  background: linear-gradient(to top, rgba(15,15,17,.95) 0%, transparent 60%);
}
.post-hero-overlay .category-tag { align-self: flex-start; margin-bottom: .75rem; }
.post-title {
  font-size: clamp(1.5rem, 4vw, 2.5rem); font-weight: 800;
  line-height: 1.2; letter-spacing: -.5px; margin-bottom: 1rem;
}
.post-byline {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.post-byline img { width: 32px; height: 32px; border-radius: 50%; }
.post-byline-info { font-size: .875rem; color: rgba(255,255,255,.7); }
.post-byline-info strong { color: #fff; }
.post-stats-bar {
  display: flex; align-items: center; gap: 1.25rem;
  font-size: .8rem; color: rgba(255,255,255,.5);
}

.post-layout {
  display: grid; grid-template-columns: 1fr 280px; gap: 2.5rem;
  align-items: start;
}

/* Post content */
.post-content {
  font-size: 1.0625rem; line-height: 1.8; color: rgba(228,228,240,.9);
}
.post-content h2 {
  font-size: 1.5rem; font-weight: 700; margin: 2rem 0 .75rem;
  color: var(--text); letter-spacing: -.3px;
}
.post-content h3 {
  font-size: 1.2rem; font-weight: 600; margin: 1.5rem 0 .5rem; color: var(--text);
}
.post-content p { margin-bottom: 1.25rem; }
.post-content ul, .post-content ol {
  margin: 0 0 1.25rem 1.5rem;
}
.post-content li { margin-bottom: .4rem; }
.post-content strong { color: var(--text); font-weight: 600; }
.post-content a { color: var(--accent-2); border-bottom: 1px solid rgba(167,139,250,.3); }
.post-content a:hover { border-color: var(--accent-2); }
.post-content code {
  font-family: var(--mono); font-size: .875em;
  background: var(--elevated); border: 1px solid var(--border);
  padding: .15em .4em; border-radius: 4px; color: var(--accent-2);
}
.post-content pre {
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  overflow-x: auto; margin-bottom: 1.5rem;
}
.post-content pre code {
  background: none; border: none; padding: 0; color: #e2e8f0;
  font-size: .875rem; line-height: 1.7;
}
.post-content blockquote {
  border-left: 3px solid var(--accent); margin: 1.5rem 0;
  padding: .75rem 1.25rem; background: var(--glow); border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic; color: var(--muted);
}

/* Sidebar */
.post-sidebar { position: sticky; top: calc(var(--nav-h) + 1.5rem); }

.sidebar-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1rem;
}
.sidebar-card h4 { font-size: .8125rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 1rem; }

.like-btn {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  padding: .65rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); font-size: .875rem; font-weight: 500;
  cursor: pointer; transition: all .2s;
}
.like-btn:hover { border-color: #f87171; color: #f87171; }
.like-btn.liked { border-color: #f87171; color: #f87171; background: rgba(248,113,113,.1); }
.like-btn svg { transition: transform .2s; }
.like-btn.liked svg { transform: scale(1.2); }

.author-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .75rem; }
.author-card img { width: 60px; height: 60px; border-radius: 50%; border: 2px solid var(--border); }
.author-card h3 { font-size: 1rem; font-weight: 700; }
.author-card p { font-size: .825rem; color: var(--muted); line-height: 1.5; }

/* ─────────────────────────────────────────
   Comments
───────────────────────────────────────── */
.comments-section { margin-top: 3rem; }
.comments-section h2 {
  font-size: 1.25rem; font-weight: 700; margin-bottom: 1.5rem;
  padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}

.comment {
  display: grid; grid-template-columns: 36px 1fr; gap: .75rem;
  padding: 1rem 0; border-bottom: 1px solid var(--border);
}
.comment:last-child { border-bottom: none; }

.comment-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }

.comment-body {}
.comment-header { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .4rem; }
.comment-author { font-size: .875rem; font-weight: 600; }
.comment-date   { font-size: .75rem; color: var(--muted); }
.comment-text   { font-size: .9rem; color: rgba(228,228,240,.85); line-height: 1.65; }
.comment-delete {
  font-size: .75rem; color: var(--muted); background: none; border: none;
  cursor: pointer; margin-left: auto; padding: 0 .25rem;
  transition: color .15s;
}
.comment-delete:hover { color: var(--danger); }

/* Comment form */
.comment-form { margin-top: 1.5rem; }
.comment-form textarea {
  width: 100%; padding: .875rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font: inherit; font-size: .9375rem; resize: vertical;
  min-height: 110px; transition: border-color .2s, box-shadow .2s;
}
.comment-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.comment-form textarea::placeholder { color: var(--muted); }

.comment-form-footer {
  display: flex; align-items: center; justify-content: space-between; margin-top: .75rem;
}

.login-prompt {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .9rem; color: var(--muted);
}

/* ─────────────────────────────────────────
   Write Page
───────────────────────────────────────── */
.write-page { padding: calc(var(--nav-h) + 2rem) 0 4rem; }
.write-page h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 2rem; }

.write-form { display: flex; flex-direction: column; gap: 1.25rem; }

.form-group { display: flex; flex-direction: column; gap: .5rem; }
.form-group label { font-size: .8125rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.form-input, .form-select, .form-textarea {
  padding: .75rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font: inherit; font-size: .9375rem;
  transition: border-color .2s, box-shadow .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--muted); }
.form-select option { background: var(--elevated); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* Editor */
.editor-toolbar {
  display: flex; align-items: center; gap: .25rem; flex-wrap: wrap;
  padding: .5rem .75rem; background: var(--elevated);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.toolbar-btn {
  padding: .3rem .55rem; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .875rem; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  transition: all .15s;
}
.toolbar-btn:hover { color: var(--text); background: var(--surface); border-color: var(--border); }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 .25rem; }

.editor-content {
  min-height: 380px; padding: 1.25rem; font-size: .9375rem; line-height: 1.8;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  color: var(--text); outline: none; overflow-y: auto;
}
.editor-content:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.editor-content:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.editor-content h2 { font-size: 1.35rem; font-weight: 700; margin: 1rem 0 .5rem; }
.editor-content h3 { font-size: 1.1rem; font-weight: 600; margin: .75rem 0 .4rem; }
.editor-content pre { background: var(--elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem 1rem; font-family: var(--mono); font-size: .875rem; margin: .5rem 0; white-space: pre-wrap; }
.editor-content blockquote { border-left: 3px solid var(--accent); padding: .5rem 1rem; color: var(--muted); font-style: italic; background: var(--glow); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.editor-content ul, .editor-content ol { margin-left: 1.5rem; }

.cover-preview {
  display: none; margin-top: .5rem;
  width: 100%; height: 180px; object-fit: cover;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.cover-preview.show { display: block; }

.write-actions {
  display: flex; align-items: center; gap: .75rem;
  padding-top: .5rem; border-top: 1px solid var(--border);
}

/* ─────────────────────────────────────────
   Toast
───────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: .6rem;
  padding: .75rem 1.1rem; border-radius: var(--radius);
  background: var(--elevated); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: .875rem;
  animation: slide-in .25s ease; pointer-events: all;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger);  }
.toast-icon { font-size: 1rem; }
@keyframes slide-in { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slide-out { to { transform: translateX(120%); opacity: 0; } }

/* ─────────────────────────────────────────
   Footer
───────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border); padding: 2rem 1.5rem;
  text-align: center; font-size: .8125rem; color: var(--subtle);
  margin-top: 4rem;
}
.footer a { color: var(--muted); transition: color .15s; }
.footer a:hover { color: var(--accent); }

/* ─────────────────────────────────────────
   Responsive
───────────────────────────────────────── */
@media (max-width: 900px) {
  .post-layout { grid-template-columns: 1fr; }
  .post-sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
}

@media (max-width: 700px) {
  .navbar { padding: 0 1rem; }
  .nav-center { display: none; }
  .posts-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .post-hero { height: 300px; }
  .post-hero-overlay { padding: 1.5rem; }
  .post-sidebar { grid-template-columns: 1fr; }
}
