:root {
    --bg-color: #f5f5f7;
    /* Very light grey background */
    --card-bg: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #79716b;
    --text-body: #57534d;
    --text-date: #9a9a9a;
    --accent-blue: #0071e3;
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark Mode */
[data-theme="dark"] {
    --bg-color: #1d1d1f;
    --card-bg: #2c2c2e;
    --text-primary: #f5f5f7;
    --text-secondary: #a6a09b;
    --text-body: #d6d3d1;
    --text-date: #8e8e93;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    font-family: var(--font-family);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    padding-bottom: 40px;
    overflow-y: scroll; /* Prevent layout shift from scrollbar */
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    max-width: 1280px;
    margin: 0 auto;
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--bg-color);
}

@media (max-width: 768px) {
    header {
        padding: 20px 16px;
    }
}

.logo {
    display: flex;
    align-items: center;
}

.logo-img {
    height: 20px;
    width: auto;
}

[data-theme="dark"] .logo-img {
    filter: invert(1);
}

.header-icons {
    display: flex;
    gap: 20px;
    color: var(--text-secondary);
}

.icon {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* CSS Grid Layout (Replaces JS Masonry) */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 32px;
    position: relative; /* Required for absolute positioned cards in masonry layout */

    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 3 Columns by default */
    gap: 12px 24px;
    /* Row Gap 12px, Column Gap 24px */
}

@media (max-width: 1024px) {
    .container {
        grid-template-columns: repeat(2, 1fr);
        /* 2 Columns on Tablet */
    }
}

@media (max-width: 640px) {
    .container {
        grid-template-columns: 1fr;
        /* 1 Column on Mobile */
        padding: 0 16px;
    }
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .container {
        padding: 0 16px;
    }
}

/* Card Styles */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    break-inside: avoid;
    /* Prevent card from breaking across columns */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    /* JS will handle width and position on Desktop */
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
}

/* Loading state for dynamically loaded cards */
.card.card-loading {
    opacity: 0;
}

.card.card-loaded {
    opacity: 1;
    transition: opacity 0.3s ease;
}

.card-image {
    width: 100%;
    display: block;
    object-fit: cover;
    background-color: #f0f0f0;
    /* Placeholder color */
}

/* Specific aspect ratios for text-only cards or specific images */
.card-content {
    padding: 24px;
}

.card-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 500;
}

.card-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.6;
    text-align: justify;
}

.card-date {
    font-size: 12px;
    color: var(--text-date);
}

/* Specific Card Styling: Fiche */
.card.fiche-card .card-image-area {
    background-color: #0084a9;
    /* Teal blue color from screenshot */
    padding: 40px;
    color: white;
    height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.fiche-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
}

.fiche-desc {
    font-family: monospace;
    font-size: 14px;
    opacity: 0.9;
}

.fiche-link {
    font-family: monospace;
    font-size: 14px;
    opacity: 0.8;
}

/* SVG Icons */
svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Detail Page Styles */
.detail-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 32px;
}

@media (max-width: 768px) {
    .detail-container {
        padding: 0 16px;
    }
}

.detail-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 60px;
    align-items: stretch;
    /* Ensure Text expands to Image height */
}

.detail-image-wrapper {
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    background-color: #f0f0f0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    display: flex;
    justify-content: center;
    align-items: center;
    align-self: start;
    /* Prevent Grid stretching */
}

.detail-image {
    width: 100%;
    height: auto;
    /* Maintain aspect ratio */
    display: block;
}

.detail-text-area {
    padding: 40px;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.detail-title {
    font-size: 17px;
    font-weight: 600;
    /* font-semibold */
    margin-bottom: 4px;
    color: var(--text-primary);
    transition: color 0.2s;
}

@media (min-width: 640px) {

    /* min-width: 40rem */
    .detail-title {
        font-size: 24px;
        /* text-2xl */
        line-height: 32px;
    }
}

.detail-title a {
    text-decoration: underline;
    text-decoration-color: #d6d3d1;
    /* stone-300 */
    text-underline-offset: 4px;
    text-decoration-thickness: 1px;
    transition: text-decoration-color 0.2s;
    color: inherit;
}

.detail-title a:hover {
    text-decoration-color: #78716c;
    /* stone-500 */
}

/* Dark mode support if applicable, but using stone-500 as base hover */

.detail-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
    margin-bottom: 12px;
    font-weight: 500;
}

.detail-body {
    flex-grow: 1;
    font-size: 17px;
    line-height: 1.8;
    color: var(--text-body);
}

.detail-body p {
    margin-bottom: 1rem;
    /* mb-4 */
}

.detail-body p:last-child {
    margin-bottom: 0;
}

.detail-body a {
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-color: #d6d3d1;
    text-underline-offset: 4px;
    text-decoration-thickness: 1px;
    transition: text-decoration-color 0.2s;
}

.detail-body a:hover {
    text-decoration-color: #78716c;
}

[data-theme="dark"] .detail-body a {
    text-decoration-color: #57534e;
}

[data-theme="dark"] .detail-body a:hover {
    text-decoration-color: #a8a29e;
}

.detail-date {
    font-size: 12px;
    line-height: 1rem;
    color: var(--text-date);
    margin-top: auto;
}

@media (max-width: 768px) {
    .detail-content {
        grid-template-columns: 1fr;
        /* Stack vertically */
        height: auto;
    }

    .detail-image-wrapper {
        min-height: 300px;
        /* Use min-height instead of fixed height for mobile */
    }

    .detail-text-area {
        padding: 24px;
        /* Restore padding for readability on mobile */
    }
}

/* Pagination */
.pagination {
    margin: 40px 0;
    text-align: center;
}

.pagination .page-number,
.pagination .extend {
    display: inline-block;
    padding: 8px 16px;
    margin: 0 4px;
    background: var(--card-bg);
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.pagination .page-number:hover,
.pagination .extend:hover {
    background: var(--bg-color);
    transform: translateY(-1px);
}

.pagination .page-number.current {
    background: var(--text-primary);
    color: var(--bg-color);
    cursor: default;
}

/* Restored Navigation Styles */
.detail-navigation {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

.nav-link {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.nav-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
}

.nav-link.prev {
    grid-column: 1;
    align-items: flex-start;
}

.nav-link.next {
    grid-column: 2;
    align-items: flex-end;
    text-align: right;
}

.nav-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.nav-title {
    font-size: 14px;
    font-weight: 600;
}

@media (max-width: 768px) {
    .detail-navigation {
        grid-template-columns: 1fr;
    }

    .nav-link.prev,
    .nav-link.next {
        grid-column: auto;
        align-items: flex-start;
        text-align: left;
    }
}

/* Restored Site Footer */
.site-footer {
    max-width: 1280px;
    margin: 40px auto 0;
    padding: 0 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 13px;
}

@media (max-width: 768px) {
    .site-footer {
        padding: 0 16px;
        flex-direction: column;
        gap: 20px;
    }
}

.footer-icons {
    display: flex;
    gap: 16px;
}

.footer-icons a {
    color: var(--text-secondary);
    transition: opacity 0.2s;
}

.footer-icon {
    width: 16px;
    height: 16px;
    cursor: pointer;
    opacity: 0.6;
    fill: currentColor;
    stroke: none;
}

.footer-icons a:hover .footer-icon {
    opacity: 1;
}

/* About Page */
.about-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 32px;
}

.about-content {
    max-width: 640px;
}

.about-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.about-body {
    font-size: 17px;
    line-height: 1.8;
    color: var(--text-secondary);
}

.about-body p {
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .about-container {
        padding: 0 16px;
    }

    .about-title {
        font-size: 24px;
    }
}