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

:root {
  /* Light theme */
  --bg: #fafafa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f3f3f5;
  --text: #1a1a2e;
  --text-secondary: #555568;
  --text-muted: #8888a0;
  --border: #e4e4ec;
  --accent: #7c6daa;
  --accent-light: #ede8f5;
  --accent-hover: #6a5a99;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
  --card-shadow-hover: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.06);
  --code-bg: #f0eef5;
  --code-text: #3d3456;
  --modal-bg: rgba(0,0,0,0.4);
  --badge-bg: #ede8f5;
  --badge-text: #6a5a99;
  --tag-bg: #f0eef5;
  --tag-text: #6a5a99;
  --tag-active-bg: #7c6daa;
  --tag-active-text: #ffffff;
  --scrollbar-thumb: #ccc;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #111118;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #22222e;
  --text: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a82;
  --border: #2a2a3a;
  --accent: #9d8ec7;
  --accent-light: #2a2540;
  --accent-hover: #b0a3d4;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.15);
  --card-shadow-hover: 0 2px 8px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.2);
  --code-bg: #1e1e2a;
  --code-text: #c8c0da;
  --modal-bg: rgba(0,0,0,0.65);
  --badge-bg: #2a2540;
  --badge-text: #b0a3d4;
  --tag-bg: #2a2540;
  --tag-text: #b0a3d4;
  --tag-active-bg: #9d8ec7;
  --tag-active-text: #111118;
  --scrollbar-thumb: #3a3a4a;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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

main {
  flex: 1;
}

.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

.hidden {
  display: none !important;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}

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

.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  transition: color var(--transition);
}

.logo-icon {
  font-size: 18px;
  color: var(--accent);
}

.theme-toggle {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
  overflow: hidden;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-icon {
  position: absolute;
  font-size: 16px;
  transition: opacity 0.2s, transform 0.3s;
}

.theme-icon--dark {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

[data-theme="dark"] .theme-icon--light {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

[data-theme="dark"] .theme-icon--dark {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* ===== Hero ===== */
.hero {
  padding: 48px 0 32px;
}

.hero-content {
  display: flex;
  align-items: center;
  gap: 28px;
}

.hero-avatar-wrap {
  flex-shrink: 0;
}

.hero-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  background-size: cover;
  background-position: center;
  border: 2px solid var(--border);
  transition: border-color var(--transition), background var(--transition), transform 0.3s ease;
  cursor: pointer;
}

.hero-avatar:hover {
  transform: scale(1.08);
  border-color: var(--accent);
}

.hero-name {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 4px;
}

.hero-bio {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
  max-width: 480px;
}

/* ===== Stats ===== */
.stats {
  padding: 0 0 40px;
}

.stats-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  min-width: 120px;
  flex: 1;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  box-shadow: var(--card-shadow);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Tags Cloud ===== */
.tags-cloud {
  padding: 0 0 40px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--tag-bg);
  color: var(--tag-text);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tag-btn:hover {
  border-color: var(--accent);
}

.tag-btn.active {
  background: var(--tag-active-bg);
  color: var(--tag-active-text);
  border-color: var(--tag-active-bg);
}

.tag-count {
  font-size: 11px;
  opacity: 0.7;
}

/* ===== Feed Toolbar ===== */
.feed {
  padding: 0 0 60px;
}

.feed-toolbar {
  margin-bottom: 24px;
}

.search-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 40px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.active-filters:empty {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  background: var(--accent-light);
  color: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.filter-chip:hover {
  opacity: 0.7;
}

.filter-chip-x {
  font-size: 14px;
  line-height: 1;
}

/* ===== Posts Grid ===== */
.posts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.posts-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ===== Post Card ===== */
.post-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  cursor: pointer;
  transition: box-shadow 0.25s, border-color 0.25s, transform 0.25s, background var(--transition);
  opacity: 0;
  transform: translateY(12px);
}

.post-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.post-card:hover {
  box-shadow: var(--card-shadow-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.post-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.post-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.post-lang {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--badge-bg);
  color: var(--badge-text);
  white-space: nowrap;
}

.post-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-code-preview {
  background: var(--code-bg);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  overflow: hidden;
  max-height: 96px;
  position: relative;
}

.post-code-preview::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(transparent, var(--code-bg));
  pointer-events: none;
}

.post-code-preview code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--code-text);
  white-space: pre;
  display: block;
}

.post-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.post-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.post-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--tag-bg);
  color: var(--tag-text);
}

.post-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 32px;
}

.pagination:empty {
  display: none;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  padding: 0 4px;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--modal-bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.25s;
}

.modal-overlay.open {
  opacity: 1;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  padding: 32px;
  position: relative;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background var(--transition), border-color var(--transition);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  line-height: 1;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 6px;
  padding-right: 40px;
}

.modal-lang {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--badge-bg);
  color: var(--badge-text);
  margin-bottom: 16px;
}

.modal-desc {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.modal-code-block {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.modal-code-block code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  color: var(--code-text);
  white-space: pre;
  display: block;
}

/* Syntax highlighting — CSS-only classes applied by JS */
.syn-kw { color: #7c6daa; font-weight: 600; }
.syn-str { color: #6a9955; }
.syn-num { color: #b5834a; }
.syn-cm { color: #808090; font-style: italic; }
.syn-fn { color: #4a8fbf; }
.syn-op { color: #999; }

[data-theme="dark"] .syn-kw { color: #b0a3d4; }
[data-theme="dark"] .syn-str { color: #8abf70; }
[data-theme="dark"] .syn-num { color: #d4a55a; }
[data-theme="dark"] .syn-cm { color: #6a6a82; }
[data-theme="dark"] .syn-fn { color: #6ab8e0; }

.modal-attachments {
  margin-bottom: 20px;
}

.attachment-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.2s;
}

.attachment-link:hover {
  background: var(--accent-light);
}

.attachment-icon {
  font-size: 15px;
}

.modal-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.modal-date {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Lightbox ===== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 20px;
}

.lightbox-overlay.open {
  opacity: 1;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 12px;
  object-fit: contain;
  transform: scale(0.8);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.lightbox-overlay.open .lightbox-img {
  transform: scale(1);
}

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  transition: border-color var(--transition);
}

.footer-inner {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.footer-views {
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.footer-credit {
  font-size: 13px;
  color: var(--text-muted);
}

.footer-credit a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-credit a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.footer-heart {
  display: inline-block;
  position: relative;
  width: 12px;
  height: 11px;
  margin: 0 3px;
  vertical-align: middle;
}

.footer-heart::before,
.footer-heart::after {
  content: "";
  position: absolute;
  top: 0;
  width: 7px;
  height: 11px;
  border-radius: 7px 7px 0 0;
  background: var(--accent);
}

.footer-heart::before {
  left: 0;
  transform: rotate(-45deg);
  transform-origin: bottom right;
}

.footer-heart::after {
  left: 5px;
  transform: rotate(45deg);
  transform-origin: bottom left;
}

/* ===== Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeInUp 0.4s ease forwards;
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-line {
  height: 14px;
  margin-bottom: 8px;
}

.skeleton-line:last-child {
  width: 60%;
}

/* ===== Responsive ===== */
@media (min-width: 600px) {
  .posts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 800px) {
  .hero {
    padding: 60px 0 36px;
  }

  .hero-avatar {
    width: 96px;
    height: 96px;
  }

  .hero-name {
    font-size: 28px;
  }

  .modal {
    padding: 40px;
  }
}

@media (max-width: 480px) {
  .hero-content {
    flex-direction: column;
    text-align: center;
  }

  .hero-bio {
    max-width: 100%;
  }

  .stat-card {
    min-width: calc(50% - 8px);
  }

  .modal {
    padding: 20px;
    border-radius: 12px;
  }

  .modal-overlay {
    padding: 20px 10px;
  }
}
