:root {
  --bg: #09090b;
  --surface: #18181b;
  --surface-hover: #27272a;
  --border: #27272a;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --accent: #8b5cf6;
  --radius: 10px;
}

.light {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f4f4f5;
  --border: #e4e4e7;
  --text: #09090b;
  --text-muted: #71717a;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent);
  flex-shrink: 0;
}

.nav {
  flex: 1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav-btn {
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, background .15s;
}
.nav-btn:hover { color: var(--text); background: var(--surface-hover); }
.nav-btn.active { background: var(--accent); color: #fff; }

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

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, border-color .15s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--text); }
.btn-icon.spinning svg { animation: spin .6s ease; }

/* Sort */
.sort-bar { display: flex; gap: 6px; margin-bottom: 16px; }

.sort-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.sort-btn:hover { color: var(--text); background: var(--surface-hover); }
.sort-btn.active { background: var(--accent); color: #fff; }

/* Main */
.main { padding: 16px 0; }
.container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* Grid */
.grid { columns: 3; column-gap: 12px; }
@media (max-width: 1024px) { .grid { columns: 2; } }
@media (max-width: 600px) { .grid { columns: 1; } }

/* Card */
.card {
  break-inside: avoid;
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .15s, border-color .15s;
  animation: fadeUp .3s ease both;
  contain: layout style paint;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }

.card-img-wrap { position: relative; overflow: hidden; }
.card-img { width: 100%; display: block; background: var(--bg); min-height: 80px; }

.card-body { padding: 10px 12px; }

.card-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.card-sub { color: var(--accent); font-weight: 500; }
.card-stats { display: flex; gap: 8px; }

.card-tag {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
}

.nsfw-blur { filter: blur(20px); }
.card:hover .nsfw-blur { filter: blur(8px); }

/* Loader */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 0;
  color: var(--text-muted);
  gap: 10px;
  font-size: 0.85rem;
}
.loader[hidden] { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* Error */
.error { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 0.9rem; }
.error[hidden] { display: none; }

.btn {
  display: inline-block;
  margin-top: 10px;
  padding: 7px 16px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: rgba(255,255,255,.1); }

.modal-img { width: 100%; display: block; border-radius: var(--radius) var(--radius) 0 0; }

.modal-info { padding: 16px; }
.modal-info h2 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }

.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* Scroll top */
.scroll-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  z-index: 50;
}
.scroll-top[hidden] { display: none; }
.scroll-top:hover { border-color: var(--accent); }

/* New posts banner */
.new-posts {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 150;
  cursor: pointer;
  animation: fadeIn .2s;
}
.new-posts[hidden] { display: none; }

/* Animations */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } }
