/* ==========================================================================
   Public articles: cards, listing page, article reader, comments, lightbox
   Uses design tokens from style.css
   ========================================================================== */

/* ---------- Card ---------- */
.articles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.25rem; }
.article-card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column; transition: var(--transition); box-shadow: var(--shadow-xs); }
.article-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--border-hover); }
.ac-cover { position: relative; display: block; aspect-ratio: 16 / 9; overflow: hidden; background: linear-gradient(135deg, #ecfdf5, #f0f9ff); }
.ac-cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s cubic-bezier(.16, 1, .3, 1); }
.article-card:hover .ac-cover img { transform: scale(1.06); }
.ac-ph { width: 100%; height: 100%; display: grid; place-items: center; font-size: 2.4rem; color: var(--primary); opacity: .5; }
.ac-cat { position: absolute; top: .7rem; inset-inline-start: .7rem; background: rgba(255, 255, 255, .94); backdrop-filter: blur(6px); color: var(--primary); font-size: .72rem; font-weight: 700; padding: .2rem .65rem; border-radius: var(--radius-full); box-shadow: var(--shadow-sm); }
.ac-body { padding: 1.1rem 1.15rem 1rem; display: flex; flex-direction: column; gap: .55rem; flex: 1; }
.ac-meta { display: flex; gap: .9rem; font-size: .76rem; color: var(--text-sub); }
.ac-meta i, .ac-stats i { margin-inline-end: .3rem; font-size: .72rem; }
.ac-title { font-size: 1.08rem; line-height: 1.45; font-weight: 800; }
.ac-title a { color: var(--text-main); text-decoration: none; transition: var(--transition); }
.ac-title a:hover { color: var(--primary); }
.ac-excerpt { font-size: .87rem; color: var(--text-sub); line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ac-tags { display: flex; gap: .4rem; flex-wrap: wrap; }
.ac-tags span { font-size: .72rem; color: var(--accent-blue); background: var(--accent-soft-blue); padding: .1rem .5rem; border-radius: var(--radius-xs); font-family: var(--font-latin); }
.ac-foot { margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.ac-stats { display: flex; gap: .8rem; font-size: .76rem; color: var(--text-sub); }
.ac-read { font-size: .82rem; font-weight: 700; color: var(--primary); text-decoration: none; display: inline-flex; gap: .35rem; align-items: center; }
.ac-read i { transition: transform .2s; font-size: .72rem; }
.ac-read:hover i { transform: translateX(-3px); }
html[dir="ltr"] .ac-read:hover i { transform: translateX(3px); }

/* Featured: wide layout */
.article-card.is-featured { grid-column: 1 / -1; flex-direction: row; }
.article-card.is-featured .ac-cover { flex: 1.15; aspect-ratio: auto; min-height: 280px; }
.article-card.is-featured .ac-body { flex: 1; padding: 1.8rem; justify-content: center; gap: .8rem; }
.article-card.is-featured .ac-title { font-size: 1.55rem; }
.article-card.is-featured .ac-excerpt { -webkit-line-clamp: 4; font-size: .95rem; }

/* ---------- Listing page ---------- */
.page-hero { padding: 3rem 0 1.5rem; text-align: center; }
.page-hero h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; margin: .4rem 0; }
.page-hero p { color: var(--text-sub); max-width: 560px; margin: 0 auto; }
.list-toolbar { display: flex; gap: .8rem; flex-wrap: wrap; align-items: center; justify-content: space-between; margin: 1.5rem 0 1.5rem; }
.list-search { position: relative; flex: 1; min-width: 220px; max-width: 360px; }
.list-search i { position: absolute; inset-inline-start: .85rem; top: 50%; transform: translateY(-50%); color: var(--text-sub); }
.list-search input { width: 100%; padding: .6rem .9rem; padding-inline-start: 2.4rem; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: #fff; font-family: inherit; font-size: .9rem; transition: var(--transition); }
.list-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.chip-row { display: flex; gap: .45rem; flex-wrap: wrap; }
.chip { padding: .38rem .9rem; border-radius: var(--radius-full); border: 1px solid var(--border-subtle); background: #fff; font-size: .82rem; font-weight: 600; color: var(--text-muted); cursor: pointer; font-family: inherit; transition: var(--transition); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.sort-select { padding: .5rem .8rem; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: #fff; font-family: inherit; font-size: .85rem; }
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--text-sub); grid-column: 1 / -1; }
.empty-state i { font-size: 2.4rem; display: block; margin-bottom: .6rem; opacity: .5; }
.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 37%, #eef2f7 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: var(--radius-lg); height: 340px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.section-footer { text-align: center; margin-top: 1.75rem; }

/* ---------- Article page ---------- */
.read-progress { position: fixed; top: 0; inset-inline: 0; height: 3px; z-index: 200; background: transparent; }
.read-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #10b981, #0284c7); transition: width .1s; }
html[dir="rtl"] .read-progress span { margin-inline-start: auto; }
.article-wrap { max-width: 1120px; margin: 0 auto; padding: 2rem 1.25rem 3rem; position: relative; z-index: 1; }
.crumbs { display: flex; gap: .5rem; align-items: center; font-size: .82rem; color: var(--text-sub); margin-bottom: 1.2rem; }
.crumbs a { color: var(--primary); text-decoration: none; font-weight: 600; }
.article-head { max-width: 780px; margin: 0 auto 1.6rem; text-align: center; }
.article-head .cat-pill { display: inline-block; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .78rem; padding: .25rem .8rem; border-radius: var(--radius-full); margin-bottom: .9rem; }
.article-head h1 { font-size: 2.2rem; line-height: 1.35; font-weight: 800; letter-spacing: -.02em; margin-bottom: .9rem; }
.article-head .lead { font-size: 1.05rem; color: var(--text-sub); line-height: 1.8; margin-bottom: 1.1rem; }
.article-meta { display: flex; gap: 1.1rem; justify-content: center; flex-wrap: wrap; font-size: .84rem; color: var(--text-sub); }
.article-meta i { margin-inline-end: .3rem; color: var(--primary); }
.article-cover { max-width: 980px; margin: 0 auto 2.2rem; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-md); border: 1px solid var(--border-subtle); aspect-ratio: 16 / 8; background: #eef2f7; }
.article-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.article-layout { display: grid; grid-template-columns: 56px minmax(0, 1fr) 240px; gap: 2rem; align-items: start; max-width: 1060px; margin: 0 auto; }
.react-rail { position: sticky; top: 90px; display: flex; flex-direction: column; gap: .7rem; align-items: center; }
.react-btn { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border-subtle); background: #fff; display: grid; place-items: center; font-size: 1.05rem; color: var(--text-muted); cursor: pointer; transition: var(--transition); position: relative; box-shadow: var(--shadow-xs); }
.react-btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }
.react-btn.liked { background: #fff1f2; border-color: #fda4af; color: #e11d48; }
.react-btn.liked i { animation: pop .4s; }
@keyframes pop { 50% { transform: scale(1.5); } }
.react-count { font-size: .74rem; font-weight: 700; color: var(--text-sub); margin-top: -.35rem; }
.share-pop { position: relative; }
.share-menu { position: absolute; inset-inline-start: 56px; top: 0; background: #fff; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: .4rem; box-shadow: var(--shadow-md); display: none; flex-direction: column; min-width: 160px; z-index: 5; }
.share-menu.open { display: flex; }
.share-menu a, .share-menu button { display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem; border-radius: var(--radius-sm); font-size: .84rem; color: var(--text-muted); text-decoration: none; background: none; border: none; cursor: pointer; font-family: inherit; text-align: start; }
.share-menu a:hover, .share-menu button:hover { background: var(--primary-soft); color: var(--primary); }

.prose { font-size: 1.05rem; line-height: 2; color: #1e293b; min-width: 0; }
.prose h2 { font-size: 1.5rem; font-weight: 800; margin: 2.2rem 0 .8rem; scroll-margin-top: 90px; padding-inline-start: .8rem; border-inline-start: 4px solid var(--primary); line-height: 1.4; }
.prose h3, .prose h4 { font-size: 1.2rem; font-weight: 700; margin: 1.8rem 0 .6rem; scroll-margin-top: 90px; }
.prose p { margin: 1rem 0; }
.prose a { color: var(--accent-blue); text-decoration: underline; text-underline-offset: 3px; }
.prose ul, .prose ol { margin: 1rem 0; padding-inline-start: 1.6rem; }
.prose li { margin: .35rem 0; }
.prose li::marker { color: var(--primary); font-weight: 700; }
.prose blockquote { margin: 1.5rem 0; padding: 1rem 1.3rem; background: var(--primary-soft); border-inline-start: 4px solid var(--primary); border-radius: var(--radius-md); color: #064e3b; font-weight: 500; }
.prose figure { margin: 1.8rem 0; }
.prose img.md-img { max-width: 100%; border-radius: var(--radius-lg); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-sm); cursor: zoom-in; display: block; margin: 0 auto; transition: var(--transition); }
.prose img.md-img:hover { box-shadow: var(--shadow-md); }
.prose figcaption { text-align: center; font-size: .82rem; color: var(--text-sub); margin-top: .6rem; }
.prose code { font-family: var(--font-mono); background: #f1f5f9; padding: .1rem .4rem; border-radius: var(--radius-xs); font-size: .88em; direction: ltr; unicode-bidi: embed; }
.prose pre.md-code { background: #0f172a; color: #e2e8f0; border-radius: var(--radius-md); padding: 1rem 1.2rem; overflow-x: auto; direction: ltr; text-align: left; margin: 1.5rem 0; position: relative; line-height: 1.7; font-size: .88rem; }
.prose pre.md-code[data-lang]:not([data-lang=""])::before { content: attr(data-lang); position: absolute; top: .4rem; inset-inline-end: .8rem; font-size: .68rem; text-transform: uppercase; color: #64748b; font-family: var(--font-latin); }
.prose pre.md-code code { background: none; padding: 0; color: inherit; }
.prose hr { border: none; border-top: 1px dashed var(--border-hover); margin: 2rem 0; }

.toc-rail { position: sticky; top: 90px; background: #fff; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 1rem; font-size: .84rem; max-height: calc(100vh - 120px); overflow-y: auto; }
.toc-rail h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-sub); margin-bottom: .6rem; }
.toc-rail a { display: block; padding: .3rem .6rem; color: var(--text-muted); text-decoration: none; border-inline-start: 2px solid var(--border-subtle); transition: var(--transition); line-height: 1.5; }
.toc-rail a.lvl3, .toc-rail a.lvl4 { padding-inline-start: 1.2rem; font-size: .8rem; }
.toc-rail a:hover { color: var(--primary); }
.toc-rail a.active { color: var(--primary); border-color: var(--primary); font-weight: 700; background: var(--primary-soft); }

.article-tags { display: flex; flex-wrap: wrap; gap: .5rem; margin: 2.2rem 0 0; padding-top: 1.2rem; border-top: 1px solid var(--border-subtle); }
.article-tags span { background: var(--accent-soft-blue); color: var(--accent-blue); padding: .25rem .75rem; border-radius: var(--radius-full); font-size: .8rem; font-weight: 600; font-family: var(--font-latin); }

/* Comments */
.comments-box { max-width: 780px; margin: 2.5rem auto 0; background: #fff; border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-xs); }
.comments-box h3 { font-size: 1.2rem; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.comments-box h3 em { font-style: normal; background: var(--primary-soft); color: var(--primary); font-size: .8rem; padding: .1rem .6rem; border-radius: var(--radius-full); }
.comment-form { display: grid; gap: .7rem; margin-bottom: 1.4rem; }
.comment-form input, .comment-form textarea { width: 100%; padding: .65rem .9rem; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); font-family: inherit; font-size: .92rem; background: var(--bg-main); transition: var(--transition); }
.comment-form input:focus, .comment-form textarea:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-glow); }
.comment-form textarea { min-height: 96px; resize: vertical; }
.comment-form button { justify-self: start; }
.comment { display: flex; gap: .85rem; padding: 1rem 0; border-top: 1px solid var(--border-subtle); animation: cin .4s; }
@keyframes cin { from { opacity: 0; transform: translateY(8px); } }
.c-avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex-shrink: 0; background: linear-gradient(135deg, #10b981, #0284c7); }
.c-body { min-width: 0; flex: 1; }
.c-head { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.c-head strong { font-size: .92rem; }
.c-head small { color: var(--text-sub); font-size: .76rem; }
.c-text { margin-top: .25rem; font-size: .93rem; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.no-comments { text-align: center; color: var(--text-sub); padding: 1.2rem 0 .4rem; }

.related { max-width: 1060px; margin: 3rem auto 0; }
.related h3 { font-size: 1.3rem; margin-bottom: 1rem; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(15, 23, 42, .88); z-index: 300; display: none; align-items: center; justify-content: center; padding: 1.5rem; cursor: zoom-out; backdrop-filter: blur(4px); }
.lightbox.open { display: flex; animation: lb .2s; }
.lightbox img { max-width: 95vw; max-height: 90vh; border-radius: var(--radius-md); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.lightbox button { position: absolute; top: 1rem; inset-inline-end: 1rem; width: 42px; height: 42px; border-radius: 50%; background: rgba(255, 255, 255, .15); color: #fff; font-size: 1.1rem; border: none; cursor: pointer; }
@keyframes lb { from { opacity: 0; } }

@media (max-width: 980px) {
  .article-layout { grid-template-columns: 56px minmax(0, 1fr); }
  .toc-rail { display: none; }
}
@media (max-width: 720px) {
  .article-layout { grid-template-columns: 1fr; }
  .react-rail { position: fixed; bottom: 14px; top: auto; inset-inline: 50% auto; transform: translateX(-50%); flex-direction: row; background: rgba(255, 255, 255, .95); backdrop-filter: blur(10px); padding: .45rem .8rem; border-radius: var(--radius-full); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-md); z-index: 80; }
  .react-count { margin: 0; }
  .share-menu { inset-inline-start: auto; bottom: 56px; top: auto; }
  .article-head h1 { font-size: 1.6rem; }
  .article-card.is-featured { flex-direction: column; }
  .article-card.is-featured .ac-cover { min-height: 200px; aspect-ratio: 16/9; }
  .article-card.is-featured .ac-title { font-size: 1.25rem; }
  .article-wrap { padding-bottom: 5.5rem; }
}
