/* Projects Grid Layout */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 80px;
    padding: 0 10px;
}

/* Project Card */
.project-card {
    background-color: var(--clr-bg-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
    height: 100%;
    cursor: pointer;
    /* All cards are clickable */
}

.project-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: var(--clr-primary);
}

.project-card:active {
    transform: scale(0.98);
    border-color: var(--clr-primary);
}

/* Card Image Area */
.project-image-container {
    width: 100%;
    height: 180px;
    background-color: var(--clr-bg-body);
    border-bottom: 1px solid var(--clr-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.project-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.project-card:hover .project-img {
    transform: scale(1.05);
}

/* Card Content */
.project-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.project-title {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--clr-text-main);
    font-weight: 700;
}

.project-desc {
    font-size: 0.85rem;
    color: var(--clr-text-muted);
    margin-bottom: 1.5rem;
    flex-grow: 1;
    line-height: 1.4;
}

/* Tech Stack Tags */
.project-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 1.5rem;
}

.tech-tag {
    font-size: 0.8rem;
    padding: 4px 10px;
    background-color: var(--clr-bg-body);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-pill);
    color: var(--clr-text-muted);
    font-weight: 500;
}

/* Card Footer (Buttons) */
.project-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    /* Adjust spacing to your liking */
    margin-top: auto;
    /* Pushes footer to the bottom of the card */
}

.project-footer>*:only-child {
    grid-column: 1 / -1;
}

/* 3 Buttons Override (First button gets full row, next two split the bottom row) */
.project-footer>*:first-child:nth-last-child(3) {
    grid-column: 1 / -1;
    order: 2;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    flex: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-sm svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- MODAL SPECIFIC STYLES --- */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    flex-grow: 1;
    margin: 0;
}

/* Header Actions Container */
.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Round Header Buttons */
.modal-header-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--clr-border);
    background-color: var(--clr-bg-body);
    color: var(--clr-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.modal-header-btn:hover {
    background-color: var(--clr-bg-surface);
    color: var(--clr-primary);
    border-color: var(--clr-primary);
    transform: scale(1.05);
}

.modal-header-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.modal-body {
    padding: 1.85rem;
    overflow-y: auto;
    max-height: calc(85vh - 70px);
}

.modal-section {
    margin-bottom: 1.2rem;
}

.modal-section h4 {
    color: var(--clr-primary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--clr-border);
    padding-bottom: 4px;
    display: inline-block;
}

.modal-text {
    color: var(--clr-text-main);
    line-height: 1.7;
    font-size: 1rem;
}

/* --- MODAL BOTTOM SECTION (Instructions & Actions) --- */
.modal-bottom-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--clr-border);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-instructions {
    color: var(--clr-text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
    background-color: var(--clr-bg-body);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border-left: 3px solid var(--clr-primary);
}

html[dir="rtl"] .modal-instructions {
    border-left: none;
    border-right: 3px solid var(--clr-primary);
}

.modal-instructions a {
    color: var(--clr-primary);
    text-decoration: none;
    font-weight: 600;
    margin-inline-start: 6px;
    white-space: nowrap;
}

.modal-instructions a:hover {
    text-decoration: underline;
}

/* Modal Actions  */
.modal-actions {
    display: flex;
    gap: 15px;
}

/* --- COLLAPSIBLE SECTIONS (Details/Summary) --- */
details {
    background-color: var(--clr-bg-body);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all 0.2s ease;
    margin-bottom: 0;
}

summary {
    padding: 1rem;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none;
    /* Remove default triangle */
    color: var(--clr-text-main);
    background-color: var(--clr-bg-surface);
    user-select: none;
}

summary:hover {
    background-color: var(--clr-bg-body);
}

summary::-webkit-details-marker {
    display: none;
    /* Chrome/Safari */
}

/* Custom Arrow */
summary::after {
    content: '';
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--clr-primary);
    border-bottom: 2px solid var(--clr-primary);
    transform: rotate(45deg);
    /* Down Arrow */
    transition: transform 0.25s;
    margin-right: 10px;
    margin-left: 10px;
}

/* Rotate arrow when open */
details[open] summary::after {
    transform: rotate(-135deg);
    /* Up Arrow */
}

/* The Content Box */
.details-content {
    padding: 1rem;
    border-top: 1px solid var(--clr-border);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- FEATURES & ASPECTS GRID --- */
.features-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 2rem;
    align-items: start;
}

@media (max-width: 700px) {
    .features-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

/* Unified List Style (Used for both Features and Aspects) */
.features-list {
    list-style: none;
    padding: 0;
    margin-top: 0;
}

.features-list li {
    position: relative;
    padding-inline-start: 20px;
    margin-bottom: 8px;
    color: var(--clr-text-muted);
}

.features-list li::before {
    content: "•";
    color: var(--clr-primary);
    font-weight: bold;
    position: absolute;
    left: 0;
}

html[dir="rtl"] .features-list li::before {
    left: auto;
    right: 0;
}

/* --- GALLERY: MOSAIC / BENTO GRID --- */
.gallery-grid {
    display: grid;
    /* Creates flexible columns around 150px wide */
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    /* Sets a fixed row height to create "square-ish" base cells */
    grid-auto-rows: 185px;
    /* Magically packs smaller items into empty gaps */
    grid-auto-flow: dense;
    gap: 10px;
    margin-top: 10px;
}

.gallery-item {
    border-radius: var(--radius-md);
    border: 1px solid var(--clr-border);
    overflow: hidden;
    background-color: var(--clr-bg-body);
    cursor: zoom-in;
    transition: transform 0.2s ease;
    position: relative;

    /* Default: 1x1 Square */
    grid-column: span 1;
    grid-row: span 1;
}

/* Horizontal Images: 2 Columns x 1 Row */
.gallery-item.landscape {
    grid-column: span 2;
    grid-row: span 1;
}

/* Vertical Images: 1 Column x 2 Rows */
.gallery-item.portrait {
    grid-column: span 1;
    grid-row: span 2;
}

.gallery-item:hover {
    transform: scale(1.02);
    z-index: 2;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    /* 'cover' is crucial here! It forces the image to fill the 1x2 or 2x1 shape perfectly */
    object-fit: cover;
    display: block;
}

/* Mobile adjustments */
@media (max-width: 500px) {
    .gallery-grid {
        /* Force exactly 2 columns on small screens so span-2 still works */
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 140px;
    }
}

/* --- LIGHTBOX (Maximize Image) --- */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(5px);
}

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

.lightbox-img {
    max-width: 90%;
    max-height: 90%;
    border-radius: var(--radius-md);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.lightbox-overlay.open .lightbox-img {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 3rem;
    color: white;
    cursor: pointer;
    z-index: 3001;
    line-height: 1;
}

html[dir="rtl"] .lightbox-close {
    right: auto;
    left: 30px;
}