/* =============================================
   blog.css — Blog-specific styles
   Imports design tokens from ../css/main.css via <link>
   ============================================= */

/* ---- Reading Progress Bar ---- */
.read-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--grad);
  z-index: 9999;
  width: 0%;
  transition: none;
}

/* ---- Blog Top Bar ---- */
.blog-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--bdr);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  gap: 16px;
}

.blog-topbar .back-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--txt2);
  font-size: 14px;
  font-weight: 500;
  transition: color .3s;
}
.blog-topbar .back-link:hover { color: var(--accent); }
.blog-topbar .back-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Theme / Lang Toggles (same pattern as portfolio) ---- */
.t-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--bdr);
  border-radius: 10px;
  background: var(--card);
  color: var(--txt2);
  cursor: pointer;
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .3s;
}
.t-btn:hover { color: var(--accent); border-color: var(--accent); }
.t-btn svg { width: 18px; height: 18px; }

.lang-tog {
  display: flex;
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 10px;
  overflow: hidden;
  backdrop-filter: blur(20px);
}
.l-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-family: var(--fn);
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  color: var(--muted);
  transition: all .3s;
}
.l-btn.on {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-g);
}

.ic-light,
.ic-dark { display: none; }
html[data-theme="dark"] .ic-light { display: block; }
html[data-theme="light"] .ic-dark { display: block; }

/* ---- Blog Layout Wrapper ---- */
.blog-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 88px 24px 60px;
  position: relative;
  z-index: 1;
}

/* ---- Blog Listing Page ---- */
.blog-hero {
  text-align: center;
  margin-bottom: 48px;
}

.blog-hero h1 {
  font-family: var(--fn-d);
  font-size: clamp(2rem, 5vw, 3.5rem);
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.blog-hero p {
  color: var(--txt2);
  font-size: 16px;
  max-width: 540px;
  margin: 0 auto;
}

/* ---- Category Filter ---- */
.cat-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 40px;
}

.cat-btn {
  padding: 8px 20px;
  border-radius: 30px;
  border: 1px solid var(--bdr);
  background: transparent;
  color: var(--txt2);
  font-family: var(--fn);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .3s;
}
.cat-btn:hover,
.cat-btn.active {
  background: var(--grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 12px var(--accent-g);
}

/* ---- Post Cards Grid ---- */
.posts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

@media (max-width: 700px) {
  .posts-grid { grid-template-columns: 1fr; }
}

.post-card {
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all .3s;
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
}
.post-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--grad);
  opacity: 0;
  transition: opacity .3s;
}
.post-card:hover {
  transform: translateY(-4px);
  border-color: rgba(56,189,248,.25);
  box-shadow: 0 12px 40px var(--accent-g);
}
.post-card:hover::before { opacity: 1; }

.post-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.post-cat {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--accent-g);
  color: var(--accent);
  border: 1px solid rgba(56,189,248,.2);
  letter-spacing: .03em;
  text-transform: uppercase;
}

.post-readtime {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.post-readtime svg { width: 12px; height: 12px; }

.post-card h2 {
  font-family: var(--fn-d);
  font-size: 1.2rem;
  color: var(--txt);
  line-height: 1.4;
  margin: 0;
}

.post-excerpt {
  color: var(--txt2);
  font-size: 14px;
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.post-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

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

.read-more {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: gap .2s;
}
.read-more:hover { gap: 8px; }

/* ---- Single Post Layout ---- */
.post-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 40px;
  align-items: start;
  max-width: 1060px;
  margin: 0 auto;
  padding: 88px 24px 60px;
  position: relative;
  z-index: 1;
}

@media (max-width: 900px) {
  .post-layout {
    grid-template-columns: 1fr;
  }
  .toc-sidebar { display: none; }
}

/* ---- Article Content ---- */
.article-main { min-width: 0; }

.post-header {
  margin-bottom: 40px;
}

.post-header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.post-header h1 {
  font-family: var(--fn-d);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  color: var(--txt);
  line-height: 1.25;
  margin-bottom: 24px;
}

.author-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 12px;
}

.author-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.author-info .author-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--txt);
}

.author-info .post-publish-date {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---- Post Body Typography ---- */
.post-body {
  font-size: 16px;
  line-height: 1.8;
  color: var(--txt);
  max-width: 720px;
}

.post-body h2 {
  font-family: var(--fn-d);
  font-size: 1.7rem;
  color: var(--txt);
  margin: 2.2em 0 .8em;
  padding-bottom: .4em;
  border-bottom: 1px solid var(--bdr);
}

.post-body h3 {
  font-family: var(--fn);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--txt);
  margin: 1.8em 0 .6em;
}

.post-body p { margin-bottom: 1.2em; color: var(--txt2); }

.post-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.post-body ul,
.post-body ol {
  margin: 1em 0 1.4em 1.6em;
  color: var(--txt2);
}

.post-body li { margin-bottom: .5em; }

/* Code blocks */
.post-body pre {
  background: #1e293b;
  border: 1px solid rgba(148,163,184,.12);
  border-radius: 10px;
  padding: 20px 24px;
  overflow-x: auto;
  margin: 1.6em 0;
  position: relative;
}

.post-body pre code {
  font-family: var(--mono), 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.7;
  color: #e2e8f0;
  background: transparent;
  padding: 0;
  border: none;
  border-radius: 0;
}

.post-body code {
  font-family: var(--mono), 'Courier New', monospace;
  font-size: 13px;
  background: rgba(56,189,248,.08);
  color: var(--accent);
  border: 1px solid rgba(56,189,248,.12);
  padding: 2px 7px;
  border-radius: 5px;
}

/* Blockquotes */
.post-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.8em 0;
  padding: 16px 20px;
  background: var(--accent-g);
  border-radius: 0 10px 10px 0;
  font-style: italic;
  color: var(--txt2);
}

.post-body blockquote p { margin: 0; color: var(--txt2); }

/* ---- Table of Contents Sidebar ---- */
.toc-sidebar {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.toc-box {
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 14px;
  padding: 20px;
}

.toc-box h4 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list li { margin-bottom: 4px; }

.toc-list a {
  display: block;
  font-size: 13px;
  color: var(--txt2);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 7px;
  border-left: 2px solid transparent;
  transition: all .2s;
  line-height: 1.5;
}

.toc-list a:hover,
.toc-list a.active {
  color: var(--accent);
  background: var(--accent-g);
  border-left-color: var(--accent);
}

.toc-list .toc-h3 a {
  padding-left: 20px;
  font-size: 12px;
}

/* ---- Share Buttons ---- */
.share-section {
  margin: 48px 0;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.share-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--txt2);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.share-btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--bdr);
  background: transparent;
  color: var(--txt2);
  font-family: var(--fn);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all .3s;
}
.share-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.share-btn:hover {
  background: var(--card-h);
  border-color: var(--accent);
  color: var(--accent);
}
.share-btn.copy-btn.copied {
  background: rgba(52,211,153,.1);
  border-color: rgba(52,211,153,.3);
  color: #34d399;
}

/* ---- Related Posts ---- */
.related-section { margin: 48px 0; }

.related-section h3 {
  font-family: var(--fn-d);
  font-size: 1.4rem;
  margin-bottom: 20px;
  color: var(--txt);
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-width: 560px) {
  .related-grid { grid-template-columns: 1fr; }
}

.related-card {
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: all .3s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.related-card:hover {
  border-color: rgba(56,189,248,.25);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-g);
}

.related-card .post-cat { display: inline-flex; width: fit-content; }
.related-card h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--txt);
  line-height: 1.4;
}
.related-card span {
  font-size: 12px;
  color: var(--muted);
}

/* ---- Post Navigation ---- */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 40px 0;
}

@media (max-width: 560px) {
  .post-nav { grid-template-columns: 1fr; }
}

.post-nav-btn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: all .3s;
}
.post-nav-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px var(--accent-g);
}
.post-nav-btn.next { text-align: right; }
.post-nav-btn span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}
.post-nav-btn strong {
  font-size: 14px;
  color: var(--txt);
  font-weight: 600;
  line-height: 1.4;
}

/* ---- Blog Footer ---- */
.blog-footer {
  text-align: center;
  padding: 40px 24px;
  border-top: 1px solid var(--bdr);
  color: var(--muted);
  font-size: 13px;
  position: relative;
  z-index: 1;
}
.blog-footer a {
  color: var(--accent);
  text-decoration: none;
}
.blog-footer a:hover { text-decoration: underline; }

/* ---- Arabic RTL support ---- */
html[lang="ar"] body,
.ar-content {
  font-family: var(--fn-ar-b), var(--fn-ar), sans-serif;
  direction: rtl;
}

html[lang="ar"] .post-body h2,
html[lang="ar"] .post-body h3 {
  font-family: var(--fn-ar-b), sans-serif;
}

html[lang="ar"] .post-body blockquote {
  border-left: none;
  border-right: 3px solid var(--accent);
  border-radius: 10px 0 0 10px;
}

html[lang="ar"] .toc-list a {
  border-left: none;
  border-right: 2px solid transparent;
  padding-left: 10px;
  padding-right: 10px;
}
html[lang="ar"] .toc-list a:hover,
html[lang="ar"] .toc-list a.active {
  border-right-color: var(--accent);
  border-left: none;
}

html[lang="ar"] .toc-list .toc-h3 a {
  padding-right: 20px;
  padding-left: 10px;
}

html[lang="ar"] .post-nav-btn.next { text-align: left; }

html[lang="ar"] .blog-topbar .back-link svg {
  transform: scaleX(-1);
}

/* ---- Light theme tweaks ---- */
html[data-theme="light"] .post-body pre {
  background: #1e293b;
}

html[data-theme="light"] .post-card,
html[data-theme="light"] .author-card,
html[data-theme="light"] .toc-box,
html[data-theme="light"] .share-section,
html[data-theme="light"] .related-card,
html[data-theme="light"] .post-nav-btn {
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* ---- Animations ---- */
@keyframes fadeUp {
  from { opacity:0; transform:translateY(20px); }
  to   { opacity:1; transform:translateY(0); }
}
.post-card {
  animation: fadeUp .5s ease both;
}
.post-card:nth-child(2) { animation-delay: .08s; }
.post-card:nth-child(3) { animation-delay: .16s; }
.post-card:nth-child(4) { animation-delay: .24s; }
.post-card:nth-child(5) { animation-delay: .32s; }

.post-card[style*="display: none"] { animation: none; }

/* ---- Toast notification ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--txt);
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- RSS Subscribe Button ---- */
.rss-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 7px 16px;
  border: 1px solid var(--bdr);
  border-radius: 8px;
  background: transparent;
  color: var(--txt2);
  font-family: var(--fn);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: all .3s;
  letter-spacing: .03em;
}
.rss-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-g);
}

/* ---- Copy Code Button ---- */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  border: 1px solid rgba(148,163,184,.2);
  border-radius: 6px;
  background: rgba(30,41,59,.8);
  color: #94a3b8;
  font-family: var(--fn);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  z-index: 2;
}
.code-copy-btn:hover { color: #e2e8f0; border-color: rgba(148,163,184,.4); }
.code-copy-btn.copied { color: #34d399; border-color: rgba(52,211,153,.3); }

/* ---- Reading Progress Percentage ---- */
.read-pct {
  position: fixed;
  top: 5px;
  right: 16px;
  z-index: 10000;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  font-family: var(--mono);
  opacity: 0;
  transition: opacity .3s;
}
.read-pct.vis { opacity: 1; }
