/* ============================================================
   Content details (article) page
   Linked per-page at the top of Pages/ContentDetails.
   Reusable bits live in public/components.css.
   ============================================================ */

/* Sit just under the sticky header (.tg-header__inner is 4rem tall)
   instead of at the very top of the viewport. */
.article-progress {
    top: 4rem;
}

.article-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.article-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--tg-text-muted);
}

.article-loading__inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ---------- Hero ----------
   The cover image can have any aspect ratio (the upload pipeline accepts both
   landscape and portrait). The hero is given a fixed cinematic aspect-ratio
   + max-height so a 9:16 phone shot doesn't blow the layout up vertically.
   `aspect-ratio` on .article-hero itself governs the slot; the img inside
   uses object-fit: cover to crop into that slot. */
.article-hero {
    position: relative;
    display: flex;
    align-items: flex-end;
    overflow: hidden;
    /* Stretch to the article-container's full width. Without this, the flex
       container would size to its (small, absolute-positioned) contents and
       the hero would shrink off the page width-wise. */
    width: 100%;
    aspect-ratio: 21 / 9;
    max-height: 70vh;
    min-height: 320px;
    margin-bottom: 3rem;
    border-radius: var(--tg-radius-2xl);
}

.article-hero__image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    /* Override the implicit aspect-ratio that browsers derive from the
       <img width/height> attributes (set for CLS). Without this, a portrait
       image's intrinsic ratio fights the absolute positioning on some browsers. */
    aspect-ratio: auto;
    object-fit: cover;
    object-position: center;
}

.article-hero__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, var(--tg-bg), rgba(16, 22, 34, 0.8) 50%, transparent);
}

.article-hero__body {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 64rem;
    padding: 1.5rem;
}

.article-hero__cats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.article-cat-chip {
    padding: 0.25rem 0.75rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #93c5fd;
    background: rgba(37, 106, 244, 0.2);
    border: 1px solid rgba(37, 106, 244, 0.3);
    border-radius: var(--tg-radius-full, 9999px);
}

.article-hero__title {
    margin: 0 0 1.5rem;
    max-width: 56rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.875rem;
    font-weight: 700;
    line-height: 1.1;
    color: #fff;
}

.article-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1.5rem;
    color: var(--tg-text-muted);
}

.article-author {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.article-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2.5rem;
    width: 2.5rem;
    font-weight: 700;
    color: var(--tg-primary);
    background: rgba(37, 106, 244, 0.2);
    border: 1px solid rgba(37, 106, 244, 0.3);
    border-radius: var(--tg-radius-full, 9999px);
}

.article-author__name {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 700;
    color: #fff;
}

.article-author__role {
    margin: 0;
    font-size: 0.75rem;
    color: var(--tg-text-muted);
}

.article-meta__divider {
    display: none;
    width: 1px;
    height: 2rem;
    background: rgba(255, 255, 255, 0.2);
}

.article-stats {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.article-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.article-stat .material-symbols-outlined {
    font-size: 18px;
}

/* ---------- Content grid ---------- */
.article-grid {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

.article-social {
    display: none;
}

.article-social__sticky {
    position: sticky;
    top: 6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.article-social__label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--tg-text-muted);
}

.article-social__divider {
    width: 1px;
    height: 2rem;
    background: var(--tg-bg-elev-2);
}

.share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2.5rem;
    width: 2.5rem;
    color: var(--tg-text-muted);
    background: var(--tg-bg-elev-2);
    border: 0;
    border-radius: var(--tg-radius-full, 9999px);
    cursor: pointer;
    transition: all 0.2s ease;
}

.share-btn:hover {
    color: #fff;
    background: var(--tg-primary);
}

.share-btn .material-symbols-outlined {
    font-size: 20px;
}

/* ---------- Article body ---------- */
.article-lead {
    margin: 0 0 2rem;
    font-size: 1.25rem;
    font-weight: 300;
    line-height: 1.625;
    color: #fff;
}

.article-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--tg-bg-elev-2);
}

.article-tags__label {
    margin-right: 0.5rem;
    padding: 0.25rem 0;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--tg-text-muted);
}

/* ---------- In-content images (EditorJS image blocks) ----------
   The renderer emits <figure class="ce-image"><img width=.. height=..>. The
   explicit width/height attributes are kept for CLS, but we still need to:
     - cap the rendered width to the article body width (the img itself can
       have any natural size)
     - cap the rendered height so a 9:16 phone shot doesn't dominate the
       entire viewport
     - reset the browser-imposed aspect-ratio so max-width/auto-height +
       max-height all play nicely together. */
.article-body figure.ce-image {
    margin: 1.5rem auto;
    text-align: center;
}

.article-body figure.ce-image img {
    display: block;
    max-width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain;
    margin: 0 auto;
    border-radius: var(--tg-radius, 0.5rem);
}

.article-body figure.ce-image figcaption {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--tg-text-muted);
    font-style: italic;
}

.article-body .article-tag {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    color: #fff;
    background: var(--tg-bg-elev-2);
    border-radius: var(--tg-radius, 0.25rem);
    transition: all 0.2s ease;
}

.article-body .article-tag:hover {
    color: var(--tg-primary);
    background: rgba(37, 106, 244, 0.2);
}

/* ---------- Author bio ---------- */
.author-bio {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-top: 3rem;
    padding: 1.5rem;
    text-align: center;
    background: var(--tg-bg-elev);
    border: 1px solid var(--tg-bg-elev-2);
    border-radius: var(--tg-radius-xl);
}

.author-bio__avatar {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    height: 5rem;
    width: 5rem;
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--tg-primary);
    background: rgba(37, 106, 244, 0.2);
    border: 1px solid rgba(37, 106, 244, 0.3);
    border-radius: var(--tg-radius-full, 9999px);
}

.author-bio__name {
    margin: 0 0 0.5rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
}

.author-bio__text {
    margin: 0 0 1rem;
    color: var(--tg-text-muted);
}

.author-bio .author-bio__link {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--tg-primary);
    background: transparent;
    border: 0;
    cursor: pointer;
}

.author-bio .author-bio__link:hover {
    color: var(--tg-primary-dark);
}

/* ---------- Right sidebar ---------- */
.article-sidebar__sticky {
    position: sticky;
    top: 6rem;
}

.article-sidebar__sticky > * + * {
    margin-top: 2rem;
}

.article-related__title {
    margin: 0 0 1.5rem;
    padding-left: 0.75rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fff;
    border-left: 4px solid var(--tg-primary);
}

.article-related__text {
    font-size: 0.875rem;
    color: var(--tg-text-muted);
}

.related-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.related-item {
    display: flex;
    gap: 0.875rem;
    align-items: center;
    text-decoration: none;
    border-radius: 0.75rem;
    padding: 0.5rem;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.related-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(2px);
}

.related-item__thumb {
    flex: 0 0 64px;
    width: 64px;
    height: 64px;
    border-radius: 0.625rem;
    object-fit: cover;
    object-position: center;
    background-color: rgba(255, 255, 255, 0.06);
}

.related-item__body {
    min-width: 0;
}

.related-item__title {
    margin: 0 0 0.35rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
    color: #fff;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.2s ease;
}

.related-item:hover .related-item__title {
    color: var(--tg-primary);
}

.related-item__meta {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--tg-text-muted);
}

.related-item__meta .material-symbols-outlined {
    font-size: 0.95rem;
}

.related-skeleton {
    height: 64px;
    border-radius: 0.625rem;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0.04) 25%,
        rgba(255, 255, 255, 0.08) 37%,
        rgba(255, 255, 255, 0.04) 63%);
    background-size: 400% 100%;
    animation: related-shimmer 1.4s ease infinite;
}

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

@media (min-width: 768px) {
    .article-hero {
        /* keep the 21:9 ratio; just raise the floor for desktop */
        min-height: 420px;
    }

    .article-hero__body {
        padding: 3rem;
    }

    .article-hero__title {
        font-size: 3rem;
    }

    .article-lead {
        font-size: 1.5rem;
    }

    .article-meta {
        flex-direction: row;
        align-items: center;
    }

    .article-meta__divider {
        display: block;
    }

    .author-bio {
        flex-direction: row;
        align-items: flex-start;
        padding: 2rem;
        text-align: left;
    }
}

@media (min-width: 1024px) {
    .article-container {
        padding: 2rem 2.5rem;
    }

    .article-hero__title {
        font-size: 3.75rem;
    }

    .article-grid {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        gap: 3rem;
    }

    .article-social {
        display: block;
        grid-column: span 1 / span 1;
    }

    .article-body {
        grid-column: span 8 / span 8;
    }

    .article-sidebar {
        grid-column: span 3 / span 3;
    }
}

@media (min-width: 640px) {
    .article-container {
        padding: 2rem 1.5rem;
    }
}
