/* Long-form article reading experience. Loaded only where article prose is used. */

.article-progress {
    position: fixed;
    inset-block-start: 0;
    inset-inline-start: 0;
    z-index: 60;
    width: 100%;
    height: 3px;
    background: transparent;
    pointer-events: none;
}

.article-progress span {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-strong), var(--accent));
    box-shadow: var(--glow);
    transform: scaleX(0);
    transform-origin: left center;
}

[dir="rtl"] .article-progress span {
    transform-origin: right center;
}

.article-page {
    padding-block: var(--section-pad-article-page);
}

.article-header {
    grid-area: header;
    width: 100%;
    max-width: 760px;
    margin-inline: auto;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-block-end: 1.75rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.breadcrumbs a {
    color: var(--accent);
    text-decoration: none;
}

.breadcrumbs a:hover {
    text-decoration: underline;
}

.article-eyebrow {
    margin: 0 0 0.6rem;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

[dir="rtl"] .article-eyebrow {
    letter-spacing: 0;
    text-transform: none;
}

.article-title {
    margin: 0;
    font-family: var(--font-en-display);
    font-size: clamp(2.3rem, 6vw, 4.4rem);
    font-weight: 500;
    line-height: 1.05;
    letter-spacing: 0.01em;
    color: var(--text);
    text-wrap: balance;
}

[lang="fa"] .article-title,
[dir="rtl"] .article-title {
    font-family: var(--font-fa-display);
    font-size: clamp(2rem, 5.5vw, 3.7rem);
    font-weight: 400;
    letter-spacing: 0;
}

.article-summary {
    margin-block-start: 1.6rem;
    padding: 1.15rem 1.35rem;
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--accent);
    border-radius: 0 16px 16px 0;
    background: var(--surface);
    box-shadow: 0 12px 36px rgba(var(--brand-rgb), 0.08);
}

[dir="rtl"] .article-summary {
    border-radius: 16px 0 0 16px;
}

.article-summary p {
    margin: 0;
    color: var(--text);
    font-size: clamp(1rem, 2vw, 1.18rem);
    line-height: 1.85;
}

.article-byline {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-block: 1.6rem;
    color: var(--text);
    font-size: 0.88rem;
}

.article-avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-block-start: 0.15rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.article-cover {
    margin: 1.5rem 0 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.article-cover img {
    display: block;
    width: 100%;
    max-height: 360px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: inherit;
}

.article-layout {
    display: grid;
    grid-template-areas: "header" "toc" "body" "widgets";
    grid-template-columns: minmax(0, 1fr);
    gap: 1.75rem;
    margin-block-start: 0;
    align-items: start;
}

.article-body-column {
    grid-area: body;
    min-width: 0;
    width: 100%;
    max-width: 760px;
    margin-inline: auto;
}

.article-prose {
    color: var(--text);
    font-size: clamp(1rem, 1.6vw, 1.08rem);
    line-height: 1.9;
    overflow-wrap: break-word;
}

[dir="rtl"] .article-prose {
    font-family: var(--font-fa-body);
    line-height: 2.1;
}

.article-prose > *:first-child {
    margin-block-start: 0;
}

.article-prose h2,
.article-prose h3,
.article-prose h4 {
    margin-block: var(--content-gap) 0.9rem;
    color: var(--text);
    line-height: 1.25;
    scroll-margin-block-start: 6rem;
    text-wrap: balance;
}

.article-prose h2 {
    font-family: var(--font-en-display);
    font-size: clamp(1.65rem, 3.4vw, 2.25rem);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.article-prose h3 {
    font-size: clamp(1.25rem, 2.4vw, 1.6rem);
    font-weight: 700;
}

.article-prose h4 {
    font-size: 1.1rem;
    font-weight: 700;
}

[dir="rtl"] .article-prose h2,
[dir="rtl"] .article-prose h3,
[dir="rtl"] .article-prose h4 {
    font-family: var(--font-fa-display);
    font-weight: 400;
    letter-spacing: 0;
}

.article-prose h2::before {
    content: "";
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    margin-inline-end: 0.6rem;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: var(--glow);
    vertical-align: middle;
}

.article-prose p {
    margin-block: 1.1rem;
}

.article-prose strong {
    color: var(--text);
    font-weight: 700;
}

.article-prose a {
    color: var(--accent);
    text-decoration-color: var(--accent-soft);
    text-underline-offset: 3px;
}

.article-prose a:hover {
    text-decoration-color: var(--accent);
}

.article-prose ul,
.article-prose ol {
    margin-block: 1.1rem;
    padding-inline-start: 1.4rem;
}

.article-prose li {
    margin-block: 0.45rem;
}

.article-prose li::marker {
    color: var(--accent);
}

.article-prose blockquote {
    margin-block: 1.6rem;
    padding: 0.9rem 1.25rem;
    border-inline-start: 3px solid var(--accent);
    border-radius: 0 12px 12px 0;
    background: var(--accent-soft);
    color: var(--text);
}

[dir="rtl"] .article-prose blockquote {
    border-radius: 12px 0 0 12px;
}

.article-prose blockquote p {
    margin: 0;
}

.article-prose code {
    direction: ltr;
    unicode-bidi: isolate;
}

.article-prose :not(pre) > code {
    padding: 0.12rem 0.38rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--code-color);
    font-family: var(--font-mono);
    font-size: 0.88em;
}

.code-card {
    margin-block: 1.7rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(8, 12, 20, 0.86);
    box-shadow: var(--shadow);
}

:root[data-theme="light"] .code-card {
    background: var(--text);
}

.code-card__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0.9rem;
    border-block-end: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(148, 163, 184, 0.08);
}

.code-card__language {
    color: var(--brand-300);
    font-family: var(--font-mono);
    font-size: 0.74rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.code-card__copy {
    padding: 0.28rem 0.7rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 7px;
    background: transparent;
    color: var(--accent-silver);
    font-size: 0.75rem;
    cursor: pointer;
}

.code-card__copy:hover,
.code-card__copy:focus-visible,
.code-card__copy.is-copied {
    border-color: var(--brand-400);
    color: var(--brand-400);
}

.code-card pre {
    direction: ltr;
    text-align: left;
    margin: 0;
    padding: 1.1rem 1.2rem;
    overflow-x: auto;
    color: var(--accent-silver);
    font-family: var(--font-mono);
    font-size: 0.86rem;
    line-height: 1.75;
    tab-size: 2;
}

.code-card code {
    font-family: inherit;
}

.tok-keyword { color: var(--accent-silver); }
.tok-string { color: var(--brand-300); }
.tok-comment { color: var(--text-muted); font-style: italic; }
.tok-number { color: #fbbf24; }

.article-sources {
    margin-block-start: var(--content-gap-lg);
    padding-block-start: var(--content-pad);
    border-block-start: 1px solid var(--border);
}

.article-sources h2 {
    margin: 0 0 0.5rem;
    font-family: var(--font-en-display);
    font-size: 1.8rem;
    font-weight: 500;
}

[dir="rtl"] .article-sources h2 {
    font-family: var(--font-fa-display);
    font-weight: 400;
}

.article-sources__intro {
    margin-block: 0 1.2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.article-sources ol {
    margin: 0;
    padding-inline-start: 1.3rem;
}

.article-sources li {
    margin-block: 0.6rem;
    font-size: 0.92rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.article-sources a {
    color: var(--accent);
}

.article-source__context {
    color: var(--text-muted);
}

.article-tags {
    margin-block: var(--content-gap-sm);
}

/* ---------- Sidebar stack ---------- */

.article-sidebar {
    display: contents;
}

.article-sidebar__toc {
    grid-area: toc;
}

.article-toc-card--mobile {
    display: none;
}

.article-sidebar__scroll {
    grid-area: widgets;
    display: grid;
    gap: 1rem;
    min-width: 0;
    width: 100%;
    min-width: 0;
    max-width: 760px;
    margin-inline: auto;
}

.article-sidebar__card {
    min-width: 0;
    padding: 1.15rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition:
        transform var(--transition),
        border-color var(--transition),
        box-shadow var(--transition),
        background-color var(--transition);
}

:root[data-theme="light"] .article-sidebar__card {
    box-shadow: 0 12px 32px rgba(var(--ink-rgb), 0.08);
}

.article-sidebar__card:hover,
.article-sidebar__card:focus-within {
    transform: translateY(-4px);
    border-color: rgba(var(--brand-rgb), 0.5);
}

:root[data-theme="light"] .article-sidebar__card:hover,
:root[data-theme="light"] .article-sidebar__card:focus-within {
    border-color: rgba(var(--brand-rgb), 0.36);
    box-shadow: 0 18px 44px rgba(var(--ink-rgb), 0.12);
}

html.motion-enabled .article-sidebar__card[data-reveal].is-revealed:hover,
html.motion-enabled .article-sidebar__card[data-reveal].is-revealed:focus-within {
    transform: translateY(-4px);
}

.article-sidebar__heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-block-end: 0.95rem;
}

.article-sidebar__heading h2 {
    margin: 0;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.35;
}

[dir="rtl"] .article-sidebar__heading h2 {
    font-family: var(--font-fa-body);
    font-weight: 600;
}

.article-sidebar__badge {
    flex: none;
    padding: 0.18rem 0.5rem;
    border: 1px solid rgba(var(--brand-rgb), 0.34);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

[dir="rtl"] .article-sidebar__badge {
    letter-spacing: 0;
    text-transform: none;
}

.article-sidebar__more {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-block-start: 0.95rem;
    padding-block-start: 0.8rem;
    border-block-start: 1px solid var(--border);
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
}

.article-sidebar__more:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

[dir="rtl"] .article-sidebar__more span {
    transform: scaleX(-1);
}

/* ---------- On this page ---------- */

.article-toc-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: start;
    cursor: pointer;
}

[dir="rtl"] .article-toc-toggle {
    font-family: var(--font-fa-body);
    font-weight: 600;
}

.article-toc-toggle__icon {
    flex: none;
    width: 0.55rem;
    height: 0.55rem;
    border-inline-end: 2px solid currentColor;
    border-block-end: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform var(--transition);
}

.article-toc-toggle[aria-expanded="false"] .article-toc-toggle__icon {
    transform: rotate(-135deg);
}

.article-toc {
    margin-block-start: 1rem;
}

.article-toc-card.is-collapsed .article-toc {
    display: none;
}

.article-toc__title {
    display: none;
    margin: 0 0 0.9rem;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

[dir="rtl"] .article-toc__title {
    font-family: var(--font-fa-body);
    letter-spacing: 0;
    text-transform: none;
}

.article-toc ul {
    display: grid;
    gap: 0.35rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.article-toc a {
    display: block;
    padding: 0.35rem 0;
    color: var(--text-muted);
    font-size: 0.86rem;
    line-height: 1.5;
    text-decoration: none;
    transition: color var(--transition);
}

.article-toc a:hover,
.article-toc a.is-active {
    color: var(--accent);
}

.article-toc a.is-active {
    font-weight: 600;
}

.article-toc__item--3 a {
    padding-inline-start: 1rem;
    font-size: 0.8rem;
}

.article-toc__item--4 a {
    padding-inline-start: 1.6rem;
    font-size: 0.78rem;
}

/* ---------- Latest tech news ---------- */

.article-news-list {
    display: grid;
    gap: 0.85rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.article-news-item {
    min-width: 0;
    padding-block-start: 0.85rem;
    border-block-start: 1px solid var(--border);
}

.article-news-item:first-child {
    padding-block-start: 0;
    border-block-start: 0;
}

.article-news-item__link {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: start;
    gap: 0.75rem;
    color: inherit;
    text-decoration: none;
}

.article-news-item__link:hover .article-news-item__title,
.article-news-item__link:focus-visible .article-news-item__title {
    color: var(--accent);
}

.article-news-item__media {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
}

.article-news-item__media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.article-news-item__icon {
    opacity: 0.85;
}

.article-news-item__body {
    min-width: 0;
}

.article-news-item__title {
    display: -webkit-box;
    overflow: hidden;
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    transition: color var(--transition);
}

.article-news-item__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    margin-block-start: 0.35rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.4;
}

/* ---------- Related insights ---------- */

.article-related-list ul {
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.article-related-list li {
    min-width: 0;
    padding-block-start: 0.75rem;
    border-block-start: 1px solid var(--border);
    font-size: 0.86rem;
    line-height: 1.5;
}

.article-related-list li:first-child {
    padding-block-start: 0;
    border-block-start: 0;
}

.article-related-list a {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.article-related-list a:hover {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.article-related-list__meta {
    display: block;
    margin-block-start: 0.25rem;
    color: var(--text-muted);
    font-size: 0.72rem;
}

/* ---------- Contact card ---------- */

.article-cta-card {
    border-color: rgba(var(--brand-rgb), 0.28);
    background: linear-gradient(145deg, var(--accent-soft), var(--surface) 58%);
}

.article-cta-card .article-eyebrow {
    margin-block-end: 0.4rem;
    font-size: 0.68rem;
}

.article-cta-card h2 {
    margin: 0 0 0.55rem;
    font-family: var(--font-en-display);
    font-size: 1.4rem;
    font-weight: 500;
    line-height: 1.2;
}

[dir="rtl"] .article-cta-card h2 {
    font-family: var(--font-fa-display);
    font-size: 1.25rem;
    font-weight: 400;
}

.article-cta-card > p:not(.article-eyebrow) {
    margin: 0 0 0.95rem;
    color: var(--text-muted);
    font-size: 0.84rem;
    line-height: 1.6;
}

.article-cta-card .btn {
    justify-content: center;
    width: 100%;
}

/* ---------- Layout modes ---------- */

@media (min-width: 1024px) {
    /* `overflow-x: hidden` turns body into a scroll container, which breaks
       position: sticky. Clipping prevents overflow without that side effect. */
    html:has(.article-layout),
    body:has(.article-layout) {
        overflow-x: clip;
    }

    body:has(.article-layout) {
        overflow-y: visible;
    }

    .article-layout {
        grid-template-columns: minmax(0, 1.8fr) minmax(300px, 1fr);
        grid-template-areas: "header sidebar" "body sidebar";
        column-gap: clamp(1.5rem, 3vw, 2.75rem);
        row-gap: var(--content-gap);
        justify-content: center;
    }

    .article-header,
    .article-body-column {
        margin-inline: 0;
    }

    .article-sidebar {
        display: grid;
        grid-area: sidebar;
        grid-row: 1 / span 2;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        gap: 0.8rem;
        position: sticky;
        inset-block-start: 5.5rem;
        align-self: start;
        width: 100%;
        max-width: 360px;
        height: calc(100vh - 6.5rem);
        height: calc(100svh - 6.5rem);
        margin-inline: auto;
        overflow: hidden;
    }

    .article-sidebar__toc {
        max-height: min(36vh, 19rem);
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }

    .article-sidebar__scroll {
        max-width: none;
        min-height: 0;
        margin: 0;
        padding: 0.1rem 0.35rem 0.6rem 0.1rem;
        overflow-y: auto;
        overscroll-behavior-y: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
        scroll-behavior: auto;
    }

    .article-sidebar__scroll::-webkit-scrollbar,
    .article-sidebar__toc::-webkit-scrollbar {
        width: 6px;
    }

    .article-sidebar__scroll::-webkit-scrollbar-thumb,
    .article-sidebar__toc::-webkit-scrollbar-thumb {
        border-radius: 999px;
        background: var(--border);
    }

    .article-toc-toggle {
        display: flex;
    }

    .article-toc {
        margin-block-start: 0;
    }

    .article-toc-card.is-collapsed .article-toc {
        display: block;
    }

    .article-toc-card.is-collapsed .article-toc ul li:not(.is-current) {
        display: none;
    }

    .article-toc-card:not(.is-collapsed) .article-toc {
        max-height: 28vh;
        overflow-y: auto;
    }

    .article-toc-card .article-toc__title {
        display: none;
    }

    .article-news-list {
        overflow: visible;
    }
}

@media (max-width: 1023px) {
    .article-sidebar__toc {
        display: none;
    }

    .article-toc-card--mobile {
        display: block;
        margin-block: 1.25rem;
    }

    .article-sidebar__scroll {
        grid-template-columns: minmax(0, 1fr);
    }

    .article-news-list {
        display: grid;
        grid-auto-columns: calc((100% - 0.75rem) / 2);
        grid-auto-flow: column;
        grid-template-columns: none;
        gap: 0.75rem;
        overflow-x: auto;
        padding: 0.1rem 0.1rem 0.65rem;
        scroll-snap-type: x mandatory;
        overscroll-behavior-inline: contain;
        scrollbar-width: thin;
    }

    .article-news-item {
        min-width: 0;
        padding: 0.55rem;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: var(--surface);
        scroll-snap-align: start;
    }

    .article-news-item:first-child {
        padding-block-start: 0.55rem;
        border-block-start: 1px solid var(--border);
    }

    .article-news-item__link {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.55rem;
    }

    .article-news-item__media {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
        border-radius: 9px;
    }

    .article-news-item__title {
        font-size: 0.8rem;
    }

    .article-news-item__meta {
        font-size: 0.67rem;
    }
}

@media (max-width: 699px) {
    .article-sidebar__card {
        padding: 1rem;
        border-radius: 14px;
    }

    .article-summary {
        border-inline-start-width: 2px;
    }

    .article-cover img {
        max-height: 220px;
        aspect-ratio: 4 / 3;
    }
}

@media (prefers-reduced-motion: reduce) {
    .article-progress span,
    .article-sidebar__card,
    .article-sidebar__more,
    .article-toc a,
    .article-toc-toggle__icon,
    .article-news-item__title {
        transition: none;
    }

    .article-sidebar__card,
    .article-sidebar__card:hover,
    .article-sidebar__card:focus-within,
    html.motion-enabled .article-sidebar__card[data-reveal].is-revealed:hover,
    html.motion-enabled .article-sidebar__card[data-reveal].is-revealed:focus-within {
        transform: none;
    }
}
