:root {
    --bg-primary: #05050C;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --accent: #6668ff;
    /* Brighter green */
    --accent-hover: #575aff;
    --border: #30363d;
    --heart: #f76e8c;
    /* Softer pink heart */
    --shadow: rgba(0, 0, 0, 0.4);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html,
body {
    overflow-x: hidden;
    max-width: 100vw;
    box-sizing: border-box;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}


body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Add this to your CSS */
body.modal-open {
    overflow: hidden;
    position: fixed;
}

body.compact-view .character-card {
    flex-direction: row;
    /* Make children fill height */
    padding: 0;
    /* Remove padding from card */
    cursor: pointer;
    gap: 0;
    /* Remove gap */
}

body.compact-view .character-image {
    width: 30%;
    aspect-ratio: 1/1;
    font-size: 2.2rem;
    border-bottom: none;
    border-right: 1px solid var(--border);
    border-radius: 0;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 8px;
    margin: 12px;

}

body.compact-view .character-info {
    padding: 12px 12px 12px 4px;
    /* Add padding here instead */
    display: flex;
    flex-direction: column;
    flex: 1;
    /* Allow this section to grow and shrink */
    min-width: 0;
}

body.compact-view .character-title {
    font-size: 0.75rem;
    /* Smaller font size */
    font-weight: 400;
}

body.compact-view .character-details {
    font-size: 0.7rem;
    margin: 6px 0px 2px 0px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.compact-view .character-short-bio {
    font-size: 0.75rem;
    margin: 2px 0px 6px 0px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* No truncation in compact view either */
}

body.compact-view .character-actions {
    margin-top: auto;
    /* Pushes to the bottom */
    flex-shrink: 0;
    /* Prevent actions from shrinking */
}

body.compact-view .select-btn,
body.compact-view .like-btn {
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 6px;
}

body.compact-view .like-btn .heart-icon svg {
    width: 16px;
    height: 16px;
}


.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    /* ADD THESE LINES */
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

/* Search & Filter Section */
.controls-section {
    padding: 16px 0 8px;
    /* Adjusted padding */
    position: sticky;
    top: 0;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    z-index: 100;
}

.search-wrapper {
    /* NEW */
    position: relative;
    margin-bottom: 16px;
}

.search-input {
    width: 100%;
    padding: 12px 60px 12px 18px;
    /* Added right-padding for the icon */
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    font-weight: 700;
    transition: var(--transition);
    margin-bottom: 0;
    /* Removed margin */
}


.view-switcher {
    /* NEW */
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    z-index: 5;
}

.view-switcher:hover {
    background: var(--bg-tertiary);
}

.view-switcher svg {
    width: 24px;
    height: 24px;
    fill: var(--text-secondary);
}

#compactViewIcon {
    display: block;
}

#regularViewIcon {
    display: none;
}

body.compact-view #compactViewIcon {
    display: none;
}

body.compact-view #regularViewIcon {
    display: block;
}



.search-input::placeholder {
    color: var(--text-secondary);
    font-weight: 600;
    /* Bold placeholder */
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(46, 160, 67, 0.3);
}

/* New Filter Row */
.filter-row {
    display: flex;
    gap: 10px;
    position: relative;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
}

.filter-select {
    position: relative;
}

.filter-button {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.filter-button:hover {
    border-color: var(--text-primary);
}

.filter-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 25px var(--shadow);
    z-index: 110;
    min-width: 180px;
    padding: 6px;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: var(--transition);
}

.filter-dropdown.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.filter-option,
.multi-select-option {
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    transition: background-color 0.2s ease;
}

.filter-option:hover,
.multi-select-option:hover {
    background-color: var(--bg-tertiary);
}

.filter-option.selected {
    color: var(--accent);
    font-weight: 600;
}

.multi-select-option {
    display: flex;
    align-items: center;
    gap: 10px;
}

.multi-select-option input[type="checkbox"] {
    display: none;
    /* Hide default checkbox */
}

.custom-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 6px;
    background-color: var(--bg-primary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.multi-select-option input:checked+.custom-checkbox {
    background-color: var(--accent);
    border-color: var(--accent);
}

.custom-checkbox::after {
    content: '✔';
    color: white;
    font-size: 12px;
    opacity: 0;
    transform: scale(0.5);
    transition: var(--transition);
}

.multi-select-option input:checked+.custom-checkbox::after {
    opacity: 1;
    transform: scale(1);
}


/* Character Grid */
.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    padding: 12px 0;
}

.character-card {
    background: linear-gradient(180deg, rgba(45, 45, 45, 1) 0%, rgba(22, 27, 33, 1) 100%);
    border-radius: 12px;
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.character-image {
    aspect-ratio: 1 / 1;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    margin: 12px 12px 2px 12px;
    border-radius: 8px;
}

.character-image .character-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-info {
    padding: 12px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.character-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Add this new class for character details */
.character-details {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: capitalize;
    margin: 8px 0px;
}

/* Modify the character-short-bio to remove truncation */
.character-short-bio {
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-grow: 1;
    margin-top: 4px;
    color: #d2d2d2;
    /* REMOVE these lines that cause truncation:
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    */
}

.character-actions {
    display: flex;
    gap: 8px;
    align-items: stretch;
    /* Make buttons same height */
}

.select-btn {
    flex-grow: 1;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: 1px solid var(--accent);
    /* Added for state change */
    border-radius: 8px;
    font-family: "Inter", sans-serif;
    font-weight: 700;
    /* Bolder Font */
    cursor: pointer;
    transition: all 0.4s ease;
    font-size: 14px;
}

.select-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    /* Added for hover */
}

.select-btn.selected {
    background: var(--bg-tertiary);
    color: var(--accent);
    border-color: var(--accent);
    padding: 10px 10px;
}

.select-btn:active {
    transform: scale(0.9);
}





.like-btn {
    padding: 0 12px;
    font-family: "Inter", sans-serif;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    /* Bolder Font */
}

.like-btn:hover {
    border-color: var(--heart);
    color: var(--heart);
}

.like-btn.liked {
    color: var(--heart);
    border-color: var(--heart);
}

.like-btn .heart-icon {
    display: flex;
    /* Use flexbox to center the icon */
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Pop animation */
}

.like-btn:active .heart-icon {
    transform: scale(1.2);
}

.like-btn .heart-icon-filled {
    display: none;
}

.like-btn.liked .heart-icon-filled {
    display: block;
    /* Use block/none to swap */
}

.like-btn.liked .heart-icon-outline {
    display: none;
}

.character-detail-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    /* Darker, more focused backdrop */
    z-index: 1500;
    display: none;
    /* Hidden by default */
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    padding: 20px;
    display: none;
    align-items: center;
    justify-content: center;
}

.character-detail-content {
    background: #050505;
    /* New background from design */
    border: 1px solid var(--border);
    max-width: 480px;
    width: 100%;
    max-height: calc(100vh - 40px);
    /* Safe area */
    border-radius: 16px;
    /* New border-radius */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: fadeInScale 0.3s ease forwards;
}

/* Refined pop animation */
@keyframes fadeInScale {
    0% {
        transform: scale(0.9);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}





.modal-copy-btn {
    position: absolute;
    top: 4%;
    right: 5%;
    background: rgba(78, 78, 78, 0.7);
    border: none;
    border-radius: 20px;
    padding: 8px;
    color: white;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 20;
    transition: background-color 0.2s ease;
}

.modal-copy-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.modal-copy-btn svg {
    width: 1rem;
    height: 1rem;
}


.success-popup {
    font-size: 0.75rem;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    justify-content: center;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.success-popup.show {
    opacity: 1;
}

.modal-back-btn {
    position: absolute;
    top: 4%;
    left: 5%;
    background: rgba(78, 78, 78, 0.7);
    border: none;
    border-radius: 20px;
    padding: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 20;
    transition: background-color 0.2s ease;
}

.modal-back-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}


.modal-back-btn svg {
    width: 1rem;
    height: 1rem;
}

.modal-header-image {
    width: 300px;
    height: 300px;
    margin: 36px auto 12px auto;
    border-radius: 24px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    overflow: hidden;
}

.modal-header-image .character-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* This new container will hold all the scrollable text and details */
.modal-scroll-container {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-main-info .char-name {
    color: #ffffff;
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.2;
}

.modal-main-info .char-subtext {
    color: rgba(255, 255, 255, 0.76);
    font-size: 0.9rem;
    font-weight: 400;
    text-transform: capitalize;
    margin-top: 4px;
}

/* Override grid action buttons for the modal context */
.modal-scroll-container .character-actions {
    margin-top: 10px;
    align-items: stretch;
    /* Keep buttons same height */
}

.modal-scroll-container .select-btn {
    flex-grow: 1;
    /* Allow select button to be larger */
}

.modal-scroll-container .like-btn {
    background: rgba(255, 255, 255, 0.13);
    border-color: transparent;
}

.modal-scroll-container .like-btn:hover {
    border-color: var(--heart);
}

.modal-scroll-container .like-btn.liked {
    background: var(--heart);
    color: white;
}


.modal-scroll-container::-webkit-scrollbar {
    width: 8px;
}

.modal-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}

.modal-scroll-container::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
    border: 1px solid var(--bg-secondary);
}

.modal-scroll-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-secondary);
}

.modal-bio {
    color: #ffffff;
    font-size: 0.9rem;
    line-height: 1.6;
    font-weight: 400;
}

.modal-optional-details {
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 20px 0;
}

.optional-detail-item .detail-title {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.optional-detail-item .detail-text {
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 400;
}

.modal-tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.modal-tags-container .tag {
    background: rgba(255, 255, 255, 0.2);
    border-color: transparent;
    border-radius: 25px;
    font-size: 0.7rem;
    padding: 4px 12px;
    font-weight: 600;
    color: white;
}

.modal-tags-container .tag:hover {
    transform: none;
    /* Disable hover effect in modal */
}



/* Loading/Empty States */
.loading,
.empty-state {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 60px 20px;
    text-align: center;
}

.loading {
    display: none;
    /* Keep it hidden by default */
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

/* 2. Define the shine animation */
@keyframes shine {
    to {
        background-position-x: -200%;
    }
}

/* 3. Style the skeleton card structure */
.skeleton-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.skeleton-shine {
    background: var(--bg-tertiary);
    background: linear-gradient(110deg, #21262d 8%, #2a3038 18%, #21262d 33%);
    background-size: 200% 100%;
    animation: 1.5s shine linear infinite;
}

.skeleton-filter {
    height: 36px;
    width: 90px;
    border-radius: 18px;
}


.skeleton-image {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
}

.skeleton-text {
    border-radius: 5px;
    height: 1rem;
    margin-bottom: 8px;
}

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

.skeleton-info {
    padding: 14px;
}

.skeleton-text {
    border-radius: 5px;
    height: 1rem;
    margin-bottom: 8px;
}

.skeleton-title {
    width: 60%;
    height: 1.2rem;
    margin-bottom: 12px;
}

.skeleton-line-1 {
    width: 90%;
}

.skeleton-line-2 {
    width: 75%;
    margin-bottom: 0;
}










.pagination-container {
    display: none;
    /* Hidden by default, shown by JS */
    justify-content: center;
    align-items: center;
    padding: 24px 0 40px 0;
    gap: 8px;
    flex-wrap: wrap;
    -webkit-user-select: none;
    /* Prevents text selection on rapid clicking */
    user-select: none;
}

.pagination-btn {
    font-family: inherit;
    font-weight: 600;
    font-size: 14px;
    padding: 8px 14px;
    min-width: 40px;
    text-align: center;
    border: 1px solid var(--border);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--accent);
    border-color: var(--accent);
    color: white;
}

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

.pagination-btn:disabled {
    color: var(--text-secondary);
    cursor: not-allowed;
    display: none;
    opacity: 0.6;
}




/* 4. Ensure it's responsive on mobile, just like the real grid */
@media (max-width: 520px) {
    body:not(.compact-view) .loading {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}



/* Responsive */

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


    .modal-header-image {
        width: 200px;
        height: 200px;
        margin-top: 20px;
    }

    .modal-scroll-container {
        padding: 16px;
    }

    .modal-main-info .char-name {
        font-size: 1.5rem;
    }

    /* Make select button text smaller on mobile */
    .select-btn {
        font-size: 13px;
        padding: 9px 12px;
    }

    /* Even smaller when selected to accommodate longer text */
    .select-btn.selected {
        font-size: 12px;
        padding: 9px 10px;
    }

    /* Adjust like button to be more compact */
    .like-btn {
        padding: 0 10px;
        min-width: 40px;
    }

    .like-btn .like-count {
        font-size: 10px;
    }
}

@media (max-width: 520px) {

    /* This rule now ONLY applies when NOT in compact view */
    body:not(.compact-view) .characters-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    /* This rule ensures compact view is a single column list on small screens */
    body.compact-view .characters-grid {
        grid-template-columns: 1fr;
    }
}


@media (max-width: 380px) {
    .modal-header-image {
        width: 140px;
        height: 140px;
        margin-top: 20px;
    }

    .character-info {
        padding: 10px;
    }

    .character-title {
        font-size: 0.8rem;
    }

    .like-btn .like-count {
        display: none;
    }

    .like-btn {
        padding: 8px;
        /* Adjust padding for icon-only button */
    }

}