:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #242424;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --accent: #c41e3a;
    --accent-hover: #e62950;
    --border: #333;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    --card-gradient: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0) 100%);
}

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

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

header {
    background: var(--bg-secondary);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--accent);
}

.search-box {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-right: 2.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.clear-search {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    display: none;
}

.search-box input:not(:placeholder-shown) + .clear-search {
    display: block;
}

.container {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    gap: 0;
    position: relative;
}

.filters {
    width: 260px;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 80px; /* Adjust based on header height */
    height: calc(100vh - 80px);
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 90;
}

.filters h3 {
    font-size: 1rem;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-filters {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
}

.filter-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    z-index: 99;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.filter-group {
    margin-bottom: 1.25rem;
}

.filter-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.filter-group select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-group input[type="date"] {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.filter-group input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

.btn-primary, .btn-secondary {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    margin-top: 1rem;
}

.toggle-group {
    display: flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.toggle-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn:first-child {
    border-right: 1px solid var(--border);
}

.toggle-btn.active {
    background: var(--accent);
    color: white;
}

.toggle-btn:hover:not(.active) {
    background: var(--bg-card);
}

.view-mode {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.stats {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.gallery {
    flex: 1;
    padding: 1.5rem;
    min-height: 100vh;
}

.card-grid {
    display: grid;
    gap: 1.25rem;
}

.card-grid.grid-small {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.card-grid.grid-medium {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.card-grid.grid-large {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid-size-control {
    display: flex;
    gap: 0.5rem;
}

.grid-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.grid-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.grid-btn:hover:not(.active) {
    border-color: var(--accent);
    color: var(--accent);
}

#scroll-sentinel {
    height: 1px;
}

/* Card Design Refinements */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease;
    cursor: pointer;
    position: relative;
    border: 1px solid transparent;
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    border-color: var(--border);
}

.card-image {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg-secondary);
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.card:hover .card-image img {
    transform: scale(1.08);
}

/* Gradient Overlay */
.card-image::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: var(--card-gradient);
    opacity: 0.6;
    transition: opacity 0.3s;
    pointer-events: none;
}

.card:hover .card-image::after {
    opacity: 0.8;
}

.image-count {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    z-index: 2;
    font-weight: 500;
}

.evo-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--accent);
    color: white;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    z-index: 2;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.card-info {
    padding: 1rem;
    position: relative;
}

.card-info h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text-primary);
}

.card-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.rarity, .piece {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    background: var(--bg-secondary);
    font-weight: 500;
    border: 1px solid rgba(255,255,255,0.1);
}

.rarity-x { background: #7c3aed; color: white; border-color: #7c3aed; }
.rarity-π { background: #f59e0b; color: black; border-color: #f59e0b; }
.rarity-BorN { background: #ef4444; color: white; border-color: #ef4444; }
.rarity-N { background: #6b7280; color: white; border-color: #6b7280; }
.rarity-R { background: #3b82f6; color: white; border-color: #3b82f6; }
.rarity-SR { background: #8b5cf6; color: white; border-color: #8b5cf6; }
.rarity-SSR { background: #f59e0b; color: black; border-color: #f59e0b; }

/* Skeleton Loading */
.skeleton {
    animation: skeleton-loading 1s linear infinite alternate;
}

@keyframes skeleton-loading {
    0% { background-color: var(--bg-secondary); }
    100% { background-color: var(--bg-card); }
}

.card.skeleton-card {
    pointer-events: none;
}

.skeleton-img {
    width: 100%;
    aspect-ratio: 1;
}

.skeleton-text {
    height: 0.9rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
}

.skeleton-meta {
    display: flex;
    gap: 0.5rem;
}

.skeleton-tag {
    height: 1.5rem;
    width: 40px;
    border-radius: 4px;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.load-more {
    text-align: center;
    padding: 2rem;
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 98;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Modal Enhancements */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.modal-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--accent);
}

.modal-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    color: white;
}

.modal-nav button {
    background: var(--bg-card);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.detail-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    overflow-y: auto;
    padding: 2rem;
}

.detail-modal.active {
    display: block;
}

.detail-modal-content {
    background: var(--bg-secondary);
    max-width: 1000px;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.detail-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 10;
    transition: color 0.2s;
    line-height: 1;
}

.detail-modal-close:hover {
    color: var(--accent);
}

.detail-layout {
    display: flex;
    gap: 2rem;
    padding: 2rem;
}

.detail-images {
    flex: 0 0 400px;
}

.detail-main-image {
    background: var(--bg-primary);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.detail-main-image img {
    width: 100%;
    height: auto;
    display: block;
}

.detail-thumbnails {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.download-btn {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.download-btn svg {
    flex-shrink: 0;
}

.detail-thumb {
    width: 70px;
    height: 70px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.detail-thumb.active {
    border-color: var(--accent);
}

.detail-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-info {
    flex: 1;
    min-width: 0;
}

.detail-info h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    padding-right: 2rem;
    line-height: 1.3;
}

.detail-section {
    margin-bottom: 2rem;
}

.detail-section h3 {
    font-size: 0.9rem;
    color: var(--accent);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-table th,
.detail-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.detail-table th {
    color: var(--text-secondary);
    font-weight: 500;
    width: 35%;
}

.detail-skill,
.detail-note {
    margin-bottom: 1.25rem;
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
}

.detail-skill:last-child,
.detail-note:last-child {
    margin-bottom: 0;
}

.detail-skill h4,
.detail-note h4 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-skill p,
.detail-note p {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 0.25rem;
}

.detail-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.detail-tag {
    background: var(--bg-card);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.highlight {
    color: var(--accent);
    background-color: rgba(196, 30, 58, 0.1);
    padding: 0 2px;
    border-radius: 2px;
}

@media (max-width: 800px) {
    .container {
        flex-direction: column;
    }
    
    .filters {
        position: fixed;
        left: -100%;
        top: 0;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        z-index: 1000;
        border-right: 1px solid var(--border);
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    }
    
    .filters.open {
        transform: translateX(0);
        left: 0;
    }
    
    .close-filters {
        display: block;
    }

    .filter-toggle {
        display: flex;
    }

    .detail-layout {
        flex-direction: column;
    }
    
    .detail-images {
        flex: none;
        max-width: 100%;
    }
    
    .detail-modal {
        padding: 0;
    }
    
    .detail-modal-content {
        border-radius: 0;
        min-height: 100vh;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    header {
        position: static;
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box {
        max-width: none;
    }
}

.modal-nav button:hover {
    background: var(--accent);
}

.card-detail-container {
    display: flex;
    gap: 2rem;
    padding: 2rem;
    flex-wrap: wrap;
}

.card-images-section {
    flex: 1;
    min-width: 300px;
    max-width: 600px;
}

.main-image {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.main-image img {
    width: 100%;
    height: auto;
    display: block;
}

.image-thumbnails {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.thumbnail {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.thumbnail.active {
    border-color: var(--accent);
}

.thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-info-section {
    flex: 1;
    min-width: 300px;
}

.info-block {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.info-block h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.info-table {
    width: 100%;
    border-collapse: collapse;
}

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

.info-table th {
    color: var(--text-secondary);
    font-weight: 500;
    width: 40%;
}

.skill-block, .note-block {
    margin-bottom: 1rem;
}

.skill-block h4, .note-block h4 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.skill-block p, .note-block p {
    line-height: 1.6;
    color: var(--text-primary);
}

.character-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    text-decoration: none;
    transition: background 0.2s;
}

.tag:hover {
    background: var(--accent);
}
