:root {
    --card-min-width: 350px; 
}

body { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; width: 100%; }

.gallery-container { padding: 4rem 2rem; max-width: 1400px; margin: 0 auto; }
.gallery-controls-wrapper { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1.5rem; }

.gallery-filters { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.secondary-controls { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.filter-btn { height: 36px; background: var(--bg-sidebar); border: 1px solid var(--border-color); color: var(--text-muted); padding: 0 1.25rem; border-radius: 2rem; cursor: pointer; font-weight: 600; transition: all 0.2s; outline: none; font-size: 0.9rem; display: flex; align-items: center; justify-content: center; }
.filter-btn:hover, .filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.filter-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sort-btn { gap: 0.35rem; padding: 0 1rem; }

.view-controls { height: 36px; display: flex; background: var(--bg-sidebar); border: 1px solid var(--border-color); border-radius: 2rem; padding: 0.2rem; align-items: center; }
.view-controls .icon-btn { height: 100%; aspect-ratio: 1; background: transparent; border: none; color: var(--text-muted); padding: 0; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; outline: none; }
.view-controls .icon-btn:hover { color: var(--text-main); }
.view-controls .icon-btn.active { background: var(--border-color); color: var(--text-main); }
.view-controls .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.search-container { display: flex; align-items: center; gap: 0.5rem; width: 100%; margin-bottom: 1.5rem; position: relative; }
.search-icon { position: absolute; left: 1.25rem; color: var(--text-muted); pointer-events: none; }
.search-input { width: 100%; flex: 1; padding: 0.85rem 1rem 0.85rem 3.25rem; border-radius: 0.5rem; background: var(--bg-sidebar); border: 1px solid var(--border-color); color: var(--text-main); font-size: 0.95rem; outline: none; transition: border-color 0.2s; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
.search-input:focus { border-color: var(--accent); }

.tags-container { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 3rem; }
.tag-pill { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); padding: 0.35rem 0.85rem; border-radius: 2rem; font-size: 0.8rem; font-weight: 500; cursor: pointer; transition: all 0.2s; user-select: none; }
.tag-pill:hover, .tag-pill.active { background: rgba(59, 130, 246, 0.1); color: var(--accent); border-color: var(--accent); }
.tag-pill.more-btn { background: rgba(255,255,255,0.05); border-style: dashed; }
.tag-pill.more-btn:hover { background: rgba(255,255,255,0.1); color: white; border-color: var(--text-muted); }

.section-title { font-size: 1.25rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; display: flex; justify-content: space-between; align-items: center; }

/* Fixed Grid System */
.gallery-grid { display: grid; gap: 2rem; margin-bottom: 4rem; transition: all 0.3s; }
.gallery-grid.grid-3 { grid-template-columns: repeat(3, 1fr); }
.gallery-grid.grid-2 { grid-template-columns: repeat(2, 1fr); }
.gallery-grid.grid-1 { grid-template-columns: 1fr; }

.gallery-grid article { display: flex; height: 100%; }
.card { flex: 1; background: var(--bg-sidebar); border-radius: 0.75rem; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; display: flex; flex-direction: column; overflow: hidden; text-decoration: none; color: inherit; outline: none; position: relative; box-shadow: 0 0 0 1px var(--border-color); }
.card:hover, .card:focus-visible { transform: translateY(-4px); box-shadow: 0 0 0 1px var(--accent), 0 10px 25px -5px rgba(0,0,0,0.5); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card-preview { width: 100%; aspect-ratio: 16 / 9; position: relative; background-color: #0b0f19; overflow: hidden; border-bottom: 1px solid var(--border-color); border-radius: 0.75rem 0.75rem 0 0; z-index: 1; }
.iframe-scaler { pointer-events: none; border: none; background: transparent; position: absolute; top: 0; left: 0; width: 250%; height: 250%; transform: scale(0.4); transform-origin: 0 0; }
.iframe-scaler.scale-component { width: 150%; height: 150%; transform: scale(0.67); }

.card-body { padding: 1.5rem; display: flex; flex-direction: column; flex: 1; position: relative; }
.card-type { position: absolute; top: 1.5rem; right: 1.5rem; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; padding: 0.25rem 0.6rem; border-radius: 1rem; background: rgba(59, 130, 246, 0.1); color: var(--accent); }
.card h3 { font-size: 1.25rem; margin-bottom: 0.5rem; padding-right: 6.5rem; color: #fff; }
.card p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 1.5rem; flex: 1; }
.card-footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); padding-top: 1rem; }
.tech-stack { display: flex; gap: 0.5rem; color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }

.no-results { grid-column: 1 / -1; text-align: center; padding: 4rem 2rem; color: var(--text-muted); font-size: 1.1rem; }

/* Pagination Controls */
.pagination-controls { display: flex; justify-content: center; align-items: center; gap: 0.5rem; margin-top: 1rem; margin-bottom: 4rem; width: 100%; }
.page-btn { background: var(--bg-sidebar); border: 1px solid var(--border-color); color: var(--text-main); width: 36px; height: 36px; border-radius: 0.375rem; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; font-weight: 500; }
.page-btn:hover:not(:disabled) { background: var(--border-color); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: white; }
.page-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.page-dots { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; color: var(--text-muted); font-weight: 700; user-select: none; }

/* Combined responsive behaviors */
@media (max-width: 1024px) { 
    .gallery-grid.grid-3 { grid-template-columns: repeat(2, 1fr); } 
    #btn-grid-small { display: none; }
}

@media (max-width: 768px) {
    .gallery-container { padding: 4rem 1.5rem; }
    .gallery-container h1 { text-align: center; }
    
    .gallery-controls-wrapper { justify-content: center; gap: 0.5rem; }
    .search-container { justify-content: center; }
    .gallery-filters { justify-content: center; }
    .secondary-controls { justify-content: center; }
    .tags-container { justify-content: center; }
    
    .gallery-grid[class*="grid-"] { grid-template-columns: 1fr; }
    .view-controls { display: none; } 
}