/* ============================================
   Directional Textual Inversion - Project Page
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --text-color: #1e293b;
    --text-light: #64748b;
    --bg-color: #ffffff;
    --bg-secondary: #f8fafc;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --max-width: 1000px;
    --transition: all 0.2s ease;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-color);
    background-color: var(--bg-color);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* ---------- Container ---------- */
.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ---------- Header ---------- */
.header {
    padding: 4rem 0 3rem;
    text-align: center;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-color) 100%);
}

.title {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 2.75rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text-light);
    margin-bottom: 1.5rem;
}

.authors {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem 1.5rem;
    margin-bottom: 0.75rem;
}

.author a {
    font-size: 1.125rem;
    font-weight: 500;
}

.author sup {
    font-size: 0.75rem;
    color: var(--text-light);
}

.affiliations {
    color: var(--text-light);
    margin-bottom: 1rem;
}

.affiliation {
    font-size: 1rem;
}

.venue {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-color);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn i {
    font-size: 1.125rem;
}

/* ---------- Sections ---------- */
.section {
    padding: 3rem 0;
    background-color: var(--bg-color);
}

.section-title {
    font-family: 'Noto Serif', Georgia, serif;
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    position: relative;
}

.section-title::after {
    content: '';
    display: block;
    width: 60px;
    height: 3px;
    background: var(--primary-color);
    margin: 0.75rem auto 0;
    border-radius: 2px;
}

/* ---------- Teaser ---------- */
.teaser {
    padding: 2rem 0 3rem;
}

.teaser-figure {
    text-align: center;
}

.teaser-figure img {
    max-width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin: 0 auto 1.5rem;
}

.teaser-figure figcaption {
    max-width: 800px;
    margin: 0 auto;
    color: var(--text-light);
    font-size: 0.9375rem;
    line-height: 1.6;
}

/* ---------- Abstract ---------- */
.abstract {
    background-color: var(--bg-secondary);
}

.abstract-text {
    max-width: 800px;
    margin: 0 auto;
    font-size: 1.0625rem;
    text-align: justify;
}

/* ---------- Method ---------- */
.method-figure {
    text-align: center;
    margin-bottom: 2rem;
}

.method-figure img {
    max-width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin: 0 auto 1rem;
}

.method-figure figcaption {
    max-width: 750px;
    margin: 0 auto;
    color: var(--text-light);
    font-size: 0.9375rem;
}

.method-description {
    max-width: 800px;
    margin: 0 auto;
}

.method-description h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem;
    color: var(--text-color);
}

.method-description p {
    margin-bottom: 1rem;
}

.equation {
    background: var(--bg-secondary);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 1.125rem;
    font-family: 'Times New Roman', Times, serif;
    font-style: italic;
    margin: 1rem 0;
    border-left: 4px solid var(--primary-color);
}

/* ---------- Results ---------- */
.results h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 2rem 0 1rem;
    color: var(--text-color);
}

.results h3:first-of-type {
    margin-top: 0;
}

.results-gallery {
    margin-bottom: 2rem;
}

.result-item {
    text-align: center;
}

.result-item img {
    max-width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin: 0 auto 1rem;
}

.result-item figcaption {
    color: var(--text-light);
    font-size: 0.9375rem;
    max-width: 700px;
    margin: 0 auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.gallery-item {
    text-align: center;
}

.gallery-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 0.5rem;
    transition: var(--transition);
}

.gallery-item img:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

.gallery-item p {
    font-size: 0.875rem;
    color: var(--text-light);
    font-style: italic;
}

/* ---------- Table ---------- */
.table-container {
    overflow-x: auto;
    margin: 1rem 0;
}

.results-table {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.results-table th,
.results-table td {
    padding: 0.75rem 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.results-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-color);
}

.results-table th:first-child,
.results-table td:first-child {
    text-align: left;
}

.results-table tr.highlight {
    background: rgba(37, 99, 235, 0.05);
}

.results-table tr.highlight td {
    color: var(--primary-color);
}

.table-caption {
    text-align: center;
    font-size: 0.9375rem;
    color: var(--text-light);
    max-width: 700px;
    margin: 1rem auto 0;
}

/* ---------- Ablation ---------- */
.ablation-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.ablation-item {
    text-align: center;
}

.ablation-item img {
    width: 100%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.ablation-item figcaption {
    font-size: 0.9375rem;
    color: var(--text-light);
    text-align: left;
}

.ablation-item figcaption strong {
    color: var(--text-color);
}

/* ---------- Gallery with Tabs ---------- */
.tabs {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 0.5rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-light);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.tab-btn.active {
    color: var(--bg-color);
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.gallery-grid-large {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.gallery-grid-large img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.gallery-grid-large img:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}

/* ---------- Subject Tabs ---------- */
.subject-tabs {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.subject-btn {
    padding: 0.625rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-light);
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 2rem;
    cursor: pointer;
    transition: var(--transition);
}

.subject-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.subject-btn.active {
    color: var(--bg-color);
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.subject-panel {
    display: none;
}

.subject-panel.active {
    display: block;
}

/* ---------- Results Grid (Reference + Generated) ---------- */
.results-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.result-row {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.reference-images {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.reference-images img {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 3px solid var(--primary-color);
    box-shadow: var(--shadow-md);
}

.reference-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.generated-images {
    flex: 1;
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    padding-bottom: 0.5rem;
}

.generated-images::-webkit-scrollbar {
    height: 6px;
}

.generated-images::-webkit-scrollbar-track {
    background: transparent;
}

.generated-images::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.generated-images .gallery-item {
    flex: 0 0 auto;
    width: 140px;
    cursor: pointer;
    transition: var(--transition);
}

.generated-images .gallery-item:hover {
    transform: translateY(-4px);
}

.generated-images .gallery-item img {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.generated-images .gallery-item:hover img {
    box-shadow: var(--shadow-lg);
}

.generated-images .gallery-item figcaption {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-light);
    text-align: center;
    line-height: 1.3;
    font-style: italic;
}

@media (max-width: 768px) {
    .result-row {
        flex-direction: column;
        align-items: stretch;
    }

    .reference-images {
        flex-direction: row;
        justify-content: flex-start;
        gap: 1rem;
    }

    .reference-images img {
        width: 100px;
        height: 100px;
    }

    .generated-images .gallery-item {
        width: 120px;
    }

    .generated-images .gallery-item img {
        width: 120px;
        height: 120px;
    }
}

/* ---------- Horizontal Scrollable Gallery ---------- */
.horizontal-gallery {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1rem 0.5rem;
    margin: 0 -0.5rem;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.horizontal-gallery::-webkit-scrollbar {
    height: 8px;
}

.horizontal-gallery::-webkit-scrollbar-track {
    background: transparent;
}

.horizontal-gallery::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.horizontal-gallery::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

.horizontal-gallery .gallery-item {
    flex: 0 0 auto;
    width: 180px;
    scroll-snap-align: start;
    cursor: pointer;
    transition: var(--transition);
}

.horizontal-gallery .gallery-item:hover {
    transform: translateY(-4px);
}

.horizontal-gallery .gallery-item img {
    width: 180px;
    height: 180px;
    object-fit: cover;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.horizontal-gallery .gallery-item:hover img {
    box-shadow: var(--shadow-lg);
}

.horizontal-gallery .gallery-item figcaption {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Lightbox ---------- */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 2rem;
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-content {
    max-width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-caption {
    margin-top: 1rem;
    color: #ffffff;
    font-size: 1rem;
    text-align: center;
    max-width: 600px;
}

.lightbox-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #ffffff;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #ffffff;
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--transition);
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-nav.prev {
    left: 1.5rem;
}

.lightbox-nav.next {
    right: 1.5rem;
}

@media (max-width: 768px) {
    .horizontal-gallery .gallery-item {
        width: 140px;
    }

    .horizontal-gallery .gallery-item img {
        width: 140px;
        height: 140px;
    }

    .lightbox-nav {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .lightbox-nav.prev {
        left: 0.5rem;
    }

    .lightbox-nav.next {
        right: 0.5rem;
    }
}

/* ---------- Citation ---------- */
.citation p {
    text-align: center;
    margin-bottom: 1rem;
}

.bibtex-container {
    position: relative;
    max-width: 700px;
    margin: 0 auto;
}

.copy-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-light);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.copy-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.bibtex {
    background: var(--bg-secondary);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    border: 1px solid var(--border-color);
}

.bibtex code {
    display: block;
    white-space: pre;
}

/* ---------- Acknowledgements ---------- */
.acknowledgements p {
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
    color: var(--text-light);
}

/* ---------- Footer ---------- */
.footer {
    padding: 2rem 0;
    text-align: center;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.footer p {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.template-credit {
    font-size: 0.8125rem !important;
}

.template-credit a {
    color: var(--text-light);
    text-decoration: underline;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .title {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1.25rem;
    }

    .section {
        padding: 2rem 0;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .author a {
        font-size: 1rem;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .abstract-text {
        font-size: 1rem;
        text-align: left;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

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

@media (max-width: 480px) {
    .title {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 1.125rem;
    }

    .links {
        flex-direction: column;
        align-items: center;
    }

    .btn {
        width: 100%;
        max-width: 200px;
        justify-content: center;
    }

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

/* ---------- Utilities ---------- */
.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mt-4 {
    margin-top: 2rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.mb-4 {
    margin-bottom: 2rem;
}