/* ==========================================================================
   Accessibility
   ========================================================================== */

/* Keyboard-only escape hatch past the nav, revealed on focus */
.skip-link {
    position: absolute;
    left: 0.5rem;
    top: -3rem;
    z-index: 1080;
    padding: 0.5rem 1rem;
    border-radius: 0 0 0.375rem 0.375rem;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--bs-border-color);
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* Bootstrap hides the outline on some controls; keep it for keyboard users */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   Typography
   ========================================================================== */

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.75;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 1rem;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 0.75em;
}

h1 {
    font-size: 2.5rem;
    letter-spacing: -0.03em;
}

h2 {
    font-size: 1.875rem;
    letter-spacing: -0.02em;
}

h3 {
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

code, pre {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ==========================================================================
   Navigation
   ========================================================================== */

.navbar {
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.navbar-brand {
    font-size: 1.25rem;
    letter-spacing: -0.01em;
}

.nav-link {
    transition: color 0.2s ease;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* ==========================================================================
   Cards & Interactive Elements
   ========================================================================== */

.card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0.75rem;
    border: 1px solid var(--bs-border-color);
}

.card.homepage-featured-post,
.card.homepage-regular-post {
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

/* Gradient accent overlay on hover */
.card.homepage-featured-post::after,
.card.homepage-regular-post::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.card.homepage-featured-post:hover::after,
.card.homepage-regular-post:hover::after {
    transform: scaleX(1);
}

.card.homepage-featured-post:hover,
.card.homepage-regular-post:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    transform: translateY(-4px);
    border-color: transparent;
}

.card.homepage-featured-post:active,
.card.homepage-regular-post:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

[data-bs-theme="dark"] .card.homepage-featured-post:hover,
[data-bs-theme="dark"] .card.homepage-regular-post:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* Card image hover effect */
.card.homepage-featured-post .card-img-top {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.homepage-featured-post:hover .card-img-top {
    transform: scale(1.05);
}

.card.homepage-featured-post .card-img-top {
    overflow: hidden;
}

/* Ensure image container clips the scaled image */
.card.homepage-featured-post {
    overflow: hidden;
}

/* ==========================================================================
   Tags
   ========================================================================== */

.tag-badge {
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0.375rem;
    display: inline-block;
}

.tag-badge.bg-secondary:hover {
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

.tag-badge.bg-secondary:active {
    transform: translateY(0) scale(1);
}

/* ==========================================================================
   Post Content
   ========================================================================== */

#post-content {
    font-size: 1.0625rem;
}

#post-content p {
    text-align: left;
    margin-bottom: 1.25rem;
}

#post-content img {
    max-height: 25rem;
    border-radius: 0.5rem;
    transition: transform 0.2s ease;
}

#post-content img:hover {
    cursor: pointer;
    transform: scale(1.02);
}

#post-content figure {
    text-align: center;
    margin: 1.5rem 0;
}

figcaption {
    color: #6c757d;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

#banner-image {
    max-height: 25rem;
    text-align: center;
    margin: 1rem 0;
}

#banner-image img {
    max-height: 25rem;
    border-radius: 0.75rem;
    transition: transform 0.2s ease;
}

/* ==========================================================================
   Reading Time
   ========================================================================== */

.reading-time {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    color: #6c757d;
}

.reading-time i {
    font-size: 0.9rem;
}

/* ==========================================================================
   Tag Graph
   ========================================================================== */

#tag-graph {
    width: 100%;
    min-height: 500px;
    overflow: hidden;
    cursor: grab;
}

#tag-graph:active {
    cursor: grabbing;
}

#tag-graph svg {
    display: block;
}

.tag-tooltip {
    position: absolute;
    padding: 0.5rem 0.75rem;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 0.875rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 1000;
}

[data-bs-theme="dark"] .tag-tooltip {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.graph-controls {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    display: flex;
    gap: 0.25rem;
    z-index: 10;
}

.graph-controls .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.graph-hint {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bs-body-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    opacity: 0.8;
}

/* ==========================================================================
   Tag Columns
   ========================================================================== */

.ul-columns {
    column-count: 3;
    -webkit-column-count: 3;
    -moz-column-count: 3;
}

@media (max-width: 768px) {
    .ul-columns {
        column-count: 2;
    }
}

@media (max-width: 480px) {
    .ul-columns {
        column-count: 1;
    }
}

/* ==========================================================================
   Post Header
   ========================================================================== */

.post-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ==========================================================================
   Smooth Scrolling & Animations
   ========================================================================== */

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Fade-in animation for page content */
.container > .justify-content-center {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered fade-in for cards */
@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card.homepage-featured-post,
.card.homepage-regular-post {
    animation: cardFadeIn 0.5s ease-out backwards;
}

/* Stagger featured post cards */
.homepage-featured-post:nth-child(1) { animation-delay: 0.1s; }
.homepage-featured-post:nth-child(2) { animation-delay: 0.2s; }
.homepage-featured-post:nth-child(3) { animation-delay: 0.3s; }
.homepage-featured-post:nth-child(4) { animation-delay: 0.4s; }

/* Stagger regular post cards */
#posts-container .row:nth-child(1) .homepage-regular-post { animation-delay: 0.1s; }
#posts-container .row:nth-child(2) .homepage-regular-post { animation-delay: 0.15s; }
#posts-container .row:nth-child(3) .homepage-regular-post { animation-delay: 0.2s; }
#posts-container .row:nth-child(4) .homepage-regular-post { animation-delay: 0.25s; }
#posts-container .row:nth-child(5) .homepage-regular-post { animation-delay: 0.3s; }
#posts-container .row:nth-child(6) .homepage-regular-post { animation-delay: 0.35s; }
#posts-container .row:nth-child(7) .homepage-regular-post { animation-delay: 0.4s; }
#posts-container .row:nth-child(8) .homepage-regular-post { animation-delay: 0.45s; }
#posts-container .row:nth-child(9) .homepage-regular-post { animation-delay: 0.5s; }
#posts-container .row:nth-child(10) .homepage-regular-post { animation-delay: 0.55s; }

/* ==========================================================================
   Dark Mode Adjustments
   ========================================================================== */

[data-bs-theme="dark"] figcaption {
    color: #adb5bd;
}

[data-bs-theme="dark"] .reading-time {
    color: #adb5bd;
}

/* ==========================================================================
   Share Buttons
   ========================================================================== */

.share-buttons .btn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.share-buttons .btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 0;
}

.share-buttons .btn:hover {
    transform: translateY(-3px) scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.35);
    border-color: transparent;
    color: white;
}

.share-buttons .btn:hover::before {
    opacity: 1;
}

.share-buttons .btn:active {
    transform: translateY(-1px) scale(1.05);
}

.share-buttons .btn i {
    font-size: 1rem;
    position: relative;
    z-index: 1;
}

/* ==========================================================================
   Related Posts
   ========================================================================== */

.related-post-card {
    transition: all 0.2s ease;
    border-radius: 0.5rem;
}

.related-post-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

[data-bs-theme="dark"] .related-post-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.related-post-card .card-title {
    font-size: 0.95rem;
    line-height: 1.4;
}

.related-post-card .card-title a {
    color: inherit;
}

.related-post-card .card-title a:hover {
    color: var(--bs-primary);
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
    font-size: 0.875rem;
}

/* ==========================================================================
   Links
   ========================================================================== */

a {
    transition: color 0.2s ease;
}

#post-content a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

#post-content a:hover {
    text-decoration-thickness: 2px;
}

/* ==========================================================================
   Load More Button
   ========================================================================== */

#load-more-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 2rem;
    position: relative;
    overflow: hidden;
}

#load-more-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

#load-more-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.35);
    border-color: #667eea;
    color: #667eea;
}

#load-more-btn:hover:not(:disabled)::before {
    opacity: 0.1;
}

#load-more-btn:active:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.25);
}

#load-more-container p {
    font-size: 0.875rem;
}

/* ==========================================================================
   General Button Enhancements
   ========================================================================== */

.btn {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.45);
    transform: translateY(-2px);
}

.btn-outline-primary:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
}

/* ==========================================================================
   Sticky Sidebar
   ========================================================================== */

.sticky-sidebar {
    position: sticky;
    top: 1rem;
}

@media (max-width: 991.98px) {
    .sticky-sidebar {
        position: static;
        margin-top: 1.5rem;
        padding-top: 1rem;
        border-top: 1px solid var(--bs-border-color);
    }
}

/* ==========================================================================
   Image Sizing
   ========================================================================== */

.card.homepage-featured-post .card-img-top {
    aspect-ratio: 16 / 9;
    object-fit: cover;
    width: 100%;
}

/* Banner images vary in shape, so let the intrinsic size win over the width/height hints */
#banner-image img {
    width: auto;
    height: auto;
    max-width: 100%;
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .card.homepage-featured-post:hover,
    .card.homepage-regular-post:hover,
    .card.homepage-featured-post:hover .card-img-top,
    .share-buttons .btn:hover,
    .tag-badge.bg-secondary:hover {
        transform: none;
    }
}
