/* Blog pages. Builds on /styles.css (colors, nav, article list, footer). */

.blog-page {
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --read-width: 720px;
}

.nav-link-active {
    color: var(--text-primary);
    position: relative;
}

.nav-link-active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -6px;
    height: 2px;
    border-radius: 1px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
}

/* ===== Index ===== */
.blog-index {
    padding-top: calc(var(--nav-height) + 2rem);
    padding-bottom: 5rem;
    position: relative;
}

.blog-index::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 520px;
    background:
        radial-gradient(600px 260px at 15% 0%, rgba(168, 85, 247, 0.16), transparent 70%),
        radial-gradient(500px 240px at 90% 10%, rgba(124, 58, 237, 0.10), transparent 70%);
    pointer-events: none;
}

.blog-hero {
    position: relative;
    margin-bottom: 3rem;
}

.blog-tools {
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.blog-search {
    flex: 1 1 280px;
    max-width: 440px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-muted);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.blog-search:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.18);
}

.blog-search input {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 0;
    background: transparent;
    border: 0;
    outline: none;
    color: var(--text-primary);
    font: inherit;
    font-size: 0.925rem;
}

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

.blog-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.blog-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.85rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.blog-chip b {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: var(--bg-surface);
    color: var(--text-muted);
}

.blog-chip:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.blog-chip.is-on {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.blog-chip.is-on b {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.blog-chip:focus-visible,
.blog-reset:focus-visible,
.post-nav-card:focus-visible,
.blog-item:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 3px;
    border-radius: 8px;
}

/* ===== Index: magazine grid ===== */
.blog-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.5rem;
}

.blog-card {
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.25s, transform 0.25s, box-shadow 0.25s;
}

.blog-card:hover {
    border-color: rgba(168, 85, 247, 0.55);
    transform: translateY(-4px);
    box-shadow: 0 18px 40px -20px rgba(168, 85, 247, 0.45);
}

.blog-card.is-featured {
    grid-column: 1 / -1;
    flex-direction: row;
    min-height: 320px;
}

/* Generated cover: a themed glow, a faint grid and the topic icon */
.blog-cover {
    --c1: #4c1d95;
    --c2: #c084fc;
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background:
        radial-gradient(120% 100% at 100% 0%, color-mix(in srgb, var(--c2) 55%, transparent) 0%, transparent 60%),
        linear-gradient(140deg, var(--c1) 0%, #0c0a14 80%);
}

.blog-cover::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
    background-size: 28px 28px;
    -webkit-mask-image: radial-gradient(circle at 75% 30%, #000 0%, transparent 70%);
    mask-image: radial-gradient(circle at 75% 30%, #000 0%, transparent 70%);
}

.cover-violet { --c1: #4c1d95; --c2: #c084fc; }
.cover-indigo { --c1: #312e81; --c2: #818cf8; }
.cover-rose { --c1: #881337; --c2: #fb7185; }
.cover-amber { --c1: #78350f; --c2: #fbbf24; }
.cover-cyan { --c1: #164e63; --c2: #22d3ee; }
.cover-fuchsia { --c1: #701a75; --c2: #f0abfc; }

.blog-cover-icon {
    position: absolute;
    right: 10%;
    bottom: 14%;
    font-size: 4rem;
    color: #fff;
    opacity: 0.92;
    filter: drop-shadow(0 8px 24px color-mix(in srgb, var(--c2) 70%, transparent));
    transition: transform 0.35s ease;
}

.blog-card:hover .blog-cover-icon {
    transform: scale(1.08) rotate(-4deg);
}

/* Real cover art: a photo fills the frame, a screenshot peeks out like a window */
.blog-cover-img {
    position: absolute;
    display: block;
}

.has-photo .blog-cover-img {
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.has-photo::before {
    /* a light scrim so the topic badges stay readable on bright photos */
    -webkit-mask-image: none;
    mask-image: none;
    background: linear-gradient(180deg, rgba(9, 9, 11, 0.55) 0%, transparent 38%);
    z-index: 1;
}

.has-shot .blog-cover-img {
    left: 12%;
    top: 22%;
    width: 80%;
    height: 92%;
    object-fit: cover;
    object-position: top left;
    border-radius: 10px;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 24px 50px -12px rgba(0, 0, 0, 0.75);
    transition: transform 0.4s ease;
}

.blog-card:hover .has-photo .blog-cover-img {
    transform: scale(1.04);
}

.blog-card:hover .has-shot .blog-cover-img {
    transform: translateY(-6px);
}

.is-featured .blog-cover {
    flex-basis: 56%;
}

/* Article covers are designed 16:9 with text on them, so the wide card shows them whole */
.is-featured .has-photo {
    background: #0b0b0f;
}

.is-featured .has-photo .blog-cover-img {
    object-fit: contain;
}

.is-featured .has-shot .blog-cover-img {
    left: 10%;
    top: 16%;
    width: 82%;
}

.blog-cover-topic,
.blog-cover-source {
    z-index: 2;
    position: absolute;
    top: 0.9rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    color: #fff;
    background: rgba(9, 9, 11, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.14);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.blog-cover-topic { left: 0.9rem; }
.blog-cover-source { right: 0.9rem; }

.blog-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1.25rem 1.35rem 1.4rem;
    flex: 1;
}

.blog-card-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.blog-card-meta i {
    font-size: 0.7em;
    margin-left: 0.15rem;
}

.blog-dot {
    margin: 0 0.45rem;
}

.blog-card-title {
    font-size: 1.1rem;
    font-weight: 650;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.blog-card-excerpt {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.blog-card-more {
    margin-top: auto;
    padding-top: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent-light);
}

.blog-card-more i {
    font-size: 0.75em;
    margin-left: 0.2rem;
    transition: transform 0.2s;
}

.blog-card:hover .blog-card-more i {
    transform: translateX(3px);
}

/* Featured: the newest post (or the newest match) across the full row */
.is-featured .blog-cover {
    flex: 0 0 52%;
    aspect-ratio: auto;
}

.is-featured .blog-cover-icon {
    font-size: 7rem;
}

.is-featured .blog-card-body {
    justify-content: center;
    padding: 2.25rem 2.5rem;
    gap: 0.9rem;
}

.is-featured .blog-card-meta::before {
    content: 'Latest';
    display: inline-block;
    margin-right: 0.7rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: var(--accent-dark);
}

.is-featured .blog-card-title {
    font-size: clamp(1.5rem, 2.6vw, 2rem);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.is-featured .blog-card-excerpt {
    font-size: 1rem;
    -webkit-line-clamp: 4;
}

.blog-item[hidden] {
    display: none;
}

.blog-empty {
    padding: 3rem 0;
    color: var(--text-muted);
    text-align: center;
}

.blog-reset {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent-light);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.blog-count {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Post ===== */
.read-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 1001;
    pointer-events: none;
}

.read-progress span {
    display: block;
    height: 100%;
    width: 100%;
    transform: scaleX(0);
    transform-origin: 0 50%;
    background: linear-gradient(90deg, var(--accent-dark), var(--accent-light));
}

.post {
    padding-top: calc(var(--nav-height) + 3rem);
    padding-bottom: 4rem;
}

.post-container,
.post-nav {
    max-width: calc(var(--read-width) + 48px);
    margin: 0 auto;
    padding: 0 24px;
}

.post-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 2rem;
    transition: color 0.2s, gap 0.2s;
}

.post-back:hover {
    color: var(--accent-light);
    gap: 0.7rem;
}

.post-header {
    padding-bottom: 2rem;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid var(--border-color);
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.post-tags .project-tag {
    text-decoration: none;
    color: var(--accent-light);
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.25);
    transition: background 0.2s;
}

.post-tags .project-tag:hover {
    background: rgba(168, 85, 247, 0.2);
}

.post-title {
    font-size: clamp(2rem, 5vw, 2.75rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-wrap: balance;
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.post-author {
    color: var(--text-secondary);
    font-weight: 500;
}

.post-body {
    font-size: 1.075rem;
    line-height: 1.8;
    color: var(--text-secondary);
    overflow-wrap: break-word;
}

.post-body > * + * {
    margin-top: 1.4em;
}

.post-body h2,
.post-body h3 {
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.3;
    margin-top: 2.2em;
}

.post-body h2 { font-size: 1.5rem; }
.post-body h3 { font-size: 1.2rem; }

.post-body a {
    color: var(--accent-light);
    text-decoration: underline;
    text-decoration-color: rgba(192, 132, 252, 0.4);
    text-underline-offset: 3px;
    transition: text-decoration-color 0.2s;
}

.post-body a:hover {
    text-decoration-color: var(--accent-light);
}

.post-body strong {
    color: var(--text-primary);
    font-weight: 600;
}

.post-body ol,
.post-body ul {
    padding-left: 1.4em;
}

.post-body li + li {
    margin-top: 0.6em;
}

.post-body li::marker {
    color: var(--accent-light);
}

.post-body code {
    font-family: var(--mono);
    font-size: 0.85em;
    padding: 0.15em 0.4em;
    border-radius: 5px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: #e9d5ff;
}

.post-body code strong,
.post-body code em {
    font-weight: inherit;
    font-style: normal;
    color: inherit;
}

.post-body pre {
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.65;
    padding: 1.1rem 1.25rem;
    border-radius: 12px;
    background: #0f0f12;
    border: 1px solid var(--border-color);
    color: #e4e4e7;
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
    position: relative;
}

.post-body pre code {
    font-size: inherit;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    color: inherit;
}

/* Tables scroll sideways on their own instead of widening the page */
.post-body table {
    display: block;
    max-width: 100%;
    width: max-content;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: 0.92rem;
    line-height: 1.5;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.post-body th,
.post-body td {
    padding: 0.6rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.post-body th {
    color: var(--text-primary);
    font-weight: 600;
    background: var(--bg-surface);
}

.post-body tbody tr:last-child td {
    border-bottom: 0;
}

.post-body .is-center { text-align: center; }
.post-body .is-right { text-align: right; }

.post-body pre:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 2px;
}

.post-body figure {
    margin-left: 0;
    margin-right: 0;
    text-align: center;
}

.post-body img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: #fff;
    cursor: zoom-in;
}

.post-body figcaption {
    margin-top: 0.6rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.post-gallery {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.25rem;
}

.post-gallery figure {
    margin: 0;
}

.post-origin {
    margin-top: 3rem;
    padding: 1rem 1.25rem;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.6rem;
    align-items: baseline;
}

.post-origin a {
    color: var(--accent-light);
}

.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 3.5rem;
}

.post-nav-card {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1.1rem 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    text-decoration: none;
    transition: border-color 0.2s, transform 0.2s;
}

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

.post-nav-card.is-newer {
    text-align: right;
    grid-column: 2;
}

.post-nav-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-light);
}

.post-nav-title {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.4;
}

/* Image zoom */
.img-zoom {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4vh 4vw;
    background: rgba(9, 9, 11, 0.92);
    backdrop-filter: blur(6px);
    cursor: zoom-out;
}

.img-zoom img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

@media (max-width: 640px) {
    .blog-index {
        padding-top: calc(var(--nav-height) + 2.5rem);
    }

    .blog-grid {
        grid-template-columns: 1fr;
    }

    .post-body {
        font-size: 1rem;
    }

    .post-nav {
        grid-template-columns: 1fr;
    }

    .post-nav-card.is-newer {
        grid-column: auto;
        text-align: left;
    }

    .post-nav-spacer {
        display: none;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .blog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 820px) {
    .blog-card.is-featured {
        flex-direction: column;
        min-height: 0;
    }

    .is-featured .blog-cover {
        flex: none;
        aspect-ratio: 16 / 9;
    }

    .is-featured .blog-cover-icon {
        font-size: 5rem;
    }

    .is-featured .blog-card-body {
        padding: 1.5rem 1.5rem 1.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .blog-card,
    .blog-cover-icon,
    .blog-cover-img,
    .blog-card-more i {
        transition: none;
    }

    .blog-card:hover,
    .blog-card:hover .blog-cover-icon,
    .blog-card:hover .blog-cover-img {
        transform: none;
    }
}

@media (max-width: 900px) {
    .nav-link-active::after {
        display: none;
    }
}

@media print {
    .read-progress,
    .post-nav,
    .navbar,
    .footer {
        display: none;
    }
}
