@import url('https://cdnjs.cloudflare.com/ajax/libs/tippy.js/6.3.7/tippy.min.css');
@import url('https://cdnjs.cloudflare.com/ajax/libs/tippy.js/6.3.7/themes/translucent.min.css');

:root {
    --primary-color: #007bff; /* New blue color */
    --secondary-color: #f5f5f1; /* Off-white */
    --background-color: #141414; /* Dark background */
    --card-background: #222;
    --text-color: #fff;
    --text-muted: #aaa;
    --hover-color: #0056b3; /* Darker blue for hover */
    --loader-color: var(--primary-color);
}

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

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
header {
    background-color: rgba(20, 20, 20, 0.9);
    padding: 10px 0; /* Slightly reduced padding */
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid #333;
}

header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.logo {
    display: flex;
    align-items: center;
    margin-bottom: 10px; /* Add margin for spacing when wrapped */
    flex-shrink: 0; /* Prevent logo from shrinking too much */
}

.logo img {
    height: 35px; /* Adjusted size */
    margin-right: 8px;
}

.logo h1 {
    font-size: 1.6em; /* Adjusted size */
    color: var(--primary-color);
    font-weight: 700;
}

nav {
    order: 3; /* Push nav below search on wrap */
    width: 100%; /* Take full width when wrapped */
    margin-top: 10px;
}

nav ul {
    list-style: none;
    display: flex;
    justify-content: center; /* Center nav items */
    padding: 5px 0;
    background-color: rgba(34, 34, 34, 0.8); /* Add subtle background */
    border-radius: 4px;
}

nav ul li {
    margin: 0 15px; /* Adjust spacing */
}

nav ul li a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    transition: color 0.3s ease;
    padding: 5px 0; /* Add padding for easier clicking */
}

nav ul li a:hover,
nav ul li a.active {
    color: var(--text-color);
}

.search-bar {
    display: flex;
    order: 2; /* Keep search after logo before nav on larger screens */
    margin-left: auto; /* Push search to right on larger screens */
    margin-right: 15px; /* Space before profile */
    flex-grow: 1; /* Allow search bar to grow */
    max-width: 350px; /* Limit max width */
    margin-bottom: 10px; /* Add margin for spacing when wrapped */
}

.search-bar input {
    padding: 8px 12px;
    border: 1px solid #444;
    border-radius: 4px 0 0 4px;
    background-color: var(--card-background);
    color: var(--text-color);
    outline: none;
    width: 100%; /* Make input take available space */
    min-width: 150px; /* Ensure it doesn't get too small */
}

.search-bar button {
    padding: 8px 15px;
    border: none;
    background-color: var(--primary-color);
    color: var(--text-color);
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    transition: background-color 0.3s ease;
    flex-shrink: 0; /* Prevent button from shrinking */
}

.search-bar button:hover {
    background-color: var(--hover-color);
}

.profile {
    order: 2; /* Position profile icon next to search */
    margin-left: 0; /* Reset margin */
    margin-bottom: 10px; /* Match search/logo margin */
    flex-shrink: 0; /* Prevent shrinking */
}

.profile-icon {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid var(--text-muted);
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(20, 20, 20, 0.95); /* Slightly darker and more opaque */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000; /* Ensure it's on top of everything */
    transition: opacity 0.3s ease; /* Smooth fade out */
}

.loader {
    border: 6px solid var(--card-background); /* Light grey for the track */
    border-top: 6px solid var(--loader-color); /* Blue for the spinner */
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Main Content */
main {
    padding-top: 20px; /* Reduced padding */
}

.main-content {
    /* Styles specific to this main grid section, if any, can go here */
    /* Currently inherits styles from .anime-grid */
}

/* Featured Section */
.featured {
    margin-bottom: 30px; /* Reduced margin */
}

.featured h2 {
    font-size: 1.8em;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
}

.featured-content {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    min-height: 300px; /* Ensure minimum height */
    display: flex; /* Use flex for better control if needed */
    align-items: flex-end; /* Align info to bottom */
    background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.7) 30%, rgba(0,0,0,0) 60%); /* Adjusted gradient */
}

.featured-banner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: -1; /* Behind the text */
    transition: opacity 0.7s ease-in-out; /* Add transition here */
}

.featured-info {
    padding: 30px;
    z-index: 1; /* Text needs to be above the gradient which is part of the parent */
    max-width: 60%; /* Limit width of text */
    transition: opacity 0.7s ease-in-out; /* Add transition here */
}

.featured-info h3 {
    font-size: 2.2em;
    margin-bottom: 10px;
    font-weight: 700;
}

.featured-info p {
    font-size: 1.1em;
    margin-bottom: 20px;
    color: var(--secondary-color);
}

.watch-now-btn {
    padding: 12px 25px;
    background-color: var(--primary-color);
    color: var(--text-color);
    border: none;
    border-radius: 5px;
    font-size: 1.1em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
    text-decoration: none; /* Ensure button styled links look like buttons */
    display: inline-block; /* For padding and centering */
}

.watch-now-btn:hover {
    background-color: var(--hover-color);
}

/* Filtered Content Section */
.filtered-content {
    margin-bottom: 30px; /* Reduced margin */
}

.filtered-content h2 {
    font-size: 1.6em;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
}

/* Anime Grid Sections */
.anime-grid {
    margin-bottom: 30px; /* Reduced margin */
}

.anime-grid h2 { /* Also applies to .anime-info-list-content h2 */
    font-size: 1.6em;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); /* Slightly smaller min */
    gap: 15px; /* Reduced gap */
}

.anime-card-link {
    text-decoration: none; /* Remove underline from link */
    color: inherit; /* Inherit text color */
    display: block; /* Make the link a block element */
    transition: transform 0.3s ease, box-shadow 0.3s ease; /* Move transition here */
}

.anime-card-link:hover {
    transform: translateY(-5px); /* Move hover effect here */
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3); /* Move hover effect here */
}

.anime-card {
    background-color: var(--card-background);
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer; /* Keep cursor pointer */
}

.anime-card-image-wrapper {
    position: relative; /* For positioning the play icon pseudo-element */
    height: 240px; /* Match image height */
    background-color: #000; /* Fallback background if image fails or for aspect ratio */
    display: flex; /* Center image if it's smaller than wrapper (though object-fit:cover handles it) */
    align-items: center;
    justify-content: center;
}

.anime-card-image-wrapper::after { /* Play icon */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/watermark.png');
    background-size: 60px 60px; /* Adjust size of play icon */
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1; /* Ensure it's above the image */
}

.anime-card-link.play-link:hover .anime-card-image-wrapper::after { /* Only show play icon for play links */
    opacity: 1;
}

.anime-card img {
    width: 100%;
    height: 100%; /* Make image fill the wrapper */
    object-fit: cover; /* Cover the area, might crop */
    display: block;
    transition: filter 0.3s ease; /* Transition for blur effect */
}

.anime-card-link.play-link:hover .anime-card-image-wrapper img { /* Only blur for play links */
    filter: blur(4px); 
}

.anime-card .title {
    padding: 10px;
    font-size: 1em;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Anime Card Popup (New) */
.tippy-box[data-theme~='anime-popup'] {
    background-color: var(--card-background);
    color: var(--text-color);
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 0.9em;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.tippy-box[data-theme~='anime-popup'][data-placement^='top'] > .tippy-arrow::before {
    border-top-color: var(--card-background);
}
.tippy-box[data-theme~='anime-popup'][data-placement^='bottom'] > .tippy-arrow::before {
    border-bottom-color: var(--card-background);
}
.tippy-box[data-theme~='anime-popup'][data-placement^='left'] > .tippy-arrow::before {
    border-left-color: var(--card-background);
}
.tippy-box[data-theme~='anime-popup'][data-placement^='right'] > .tippy-arrow::before {
    border-right-color: var(--card-background);
}
.tippy-box[data-theme~='anime-popup'] .tippy-content {
    padding: 8px 12px;
    max-width: 250px; /* Limit popup width */
}

/* Search Results */
.search-results {
    margin-bottom: 40px;
}

.search-results h2 {
    font-size: 1.6em;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
}

/* Anime Detail Section */
.anime-detail-content {
    padding: 20px 0;
    margin-bottom: 30px;
}

.anime-detail-card {
    background-color: var(--card-background);
    border-radius: 8px;
    padding: 25px;
    display: flex;
    gap: 25px;
    align-items: flex-start; /* Align items to the start for varying text lengths */
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.anime-detail-image {
    width: 250px; /* Fixed width for the image */
    height: auto; /* Maintain aspect ratio */
    max-height: 375px; /* Max height for portrait images */
    object-fit: cover;
    border-radius: 5px;
    flex-shrink: 0; /* Prevent image from shrinking */
}

.anime-detail-info {
    flex-grow: 1; /* Allow text content to take remaining space */
}

.anime-detail-info h2 {
    font-size: 2em;
    color: var(--primary-color);
    margin-bottom: 15px;
    font-weight: 700;
}

.anime-detail-info p {
    font-size: 1.1em;
    line-height: 1.7;
    margin-bottom: 25px;
    color: var(--secondary-color);
}

/* Footer */
footer {
    background-color: #101010;
    color: var(--text-muted);
    text-align: center;
    padding: 15px 0;
    margin-top: 30px;
    font-size: 0.9em;
}

/* Responsive */
@media (max-width: 992px) {
    .container {
        padding: 0 15px;
    }
    .featured-info {
        max-width: 70%; /* Adjust width */
        padding: 25px;
    }
    .featured-info h3 {
        font-size: 2em;
    }
    .grid-container {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    .search-bar {
        max-width: 300px; /* Adjust search bar width */
    }
    .anime-detail-image {
        width: 200px;
        max-height: 300px;
    }
    .anime-detail-info h2 {
        font-size: 1.8em;
    }
    .anime-detail-info p {
        font-size: 1em;
    }
}

@media (max-width: 768px) {
    header .container {
        flex-direction: row; /* Keep row layout */
        align-items: center; /* Vertically center items */
    }

    .logo {
        margin-bottom: 0; /* Remove bottom margin */
        margin-right: auto; /* Push other items right */
    }

    .search-bar {
        order: 3; /* Search bar goes below logo/profile on new line */
        width: calc(100% - 50px); /* Take most width, leaving space for profile potentially */
        max-width: none; /* Remove max width */
        margin-left: 0;
        margin-right: 0; /* Remove side margins */
        margin-top: 10px; /* Add top margin */
        margin-bottom: 10px;
    }

    .profile {
        order: 2; /* Profile next to logo */
        margin-bottom: 0; /* Remove bottom margin */
        margin-left: 10px; /* Add space from logo */
    }

    nav {
        order: 4; /* Nav last */
        margin-top: 0; /* Remove top margin */
        margin-bottom: 5px; /* Add small bottom margin */
    }
    nav ul {
        justify-content: space-around; /* Keep space around */
        padding: 5px 0;
    }
    nav ul li {
        margin: 0 8px; /* Reduce nav spacing further for 4 items */
    }
    nav ul li a {
        font-size: 0.90em; /* Slightly smaller nav text */
    }

    .featured-info {
        padding: 20px;
        max-width: 90%; /* Allow more width */
    }
    .featured-info h3 {
        font-size: 1.7em; /* Adjust title size */
    }
    .featured-info p {
        font-size: 0.95em; /* Adjust text size */
        margin-bottom: 15px;
    }
    .watch-now-btn {
        padding: 10px 20px; /* Smaller button */
        font-size: 1em;
    }

    .grid-container {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); /* Further adjust grid */
        gap: 12px;
    }
    .anime-card-image-wrapper { /* Ensure wrapper height is responsive too */
        height: 190px;
    }
    .anime-card img {
        height: 100%; /* Image should fill wrapper */
    }
    .anime-card-link:hover {
        transform: translateY(-3px); /* Slightly smaller lift */
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
    }
    .anime-card .title {
        font-size: 0.9em;
        padding: 8px;
    }

    .anime-detail-card {
        flex-direction: column; /* Stack image and info vertically */
        align-items: center; /* Center items when stacked */
        padding: 15px;
    }
    .anime-detail-image {
        width: 80%; /* Image takes more width when stacked */
        max-width: 250px; /* But not too large */
        height: auto;
        margin-bottom: 15px; /* Space between image and text */
    }
    .anime-detail-info {
        text-align: center; /* Center text when stacked */
    }
    .anime-detail-info h2 {
        font-size: 1.6em;
    }
    .anime-detail-info p {
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 8px; /* Slightly tighter padding */
    }
    .logo h1 {
        font-size: 1.3em; /* Slightly smaller logo text */
    }
    .logo img {
        height: 28px; /* Slightly smaller logo image */
    }

    .search-bar {
        width: 100%; /* Full width search bar */
        margin-top: 8px; /* Adjust margin */
        margin-bottom: 8px;
    }
    .search-bar input {
        font-size: 0.85em; /* Slightly smaller font */
        padding: 6px 8px; /* Adjust padding */
    }
    .search-bar button {
        padding: 6px 10px; /* Adjust padding */
        font-size: 0.85em; /* Slightly smaller font */
    }

    .profile-icon {
        width: 30px; /* Slightly smaller icon */
        height: 30px;
    }

    nav ul li {
        margin: 0 4px; /* Even tighter nav spacing for 4 items */
    }
    nav ul li a {
        font-size: 0.8em; /* Smaller nav text */
        padding: 4px 0;
    }

    .featured {
        margin-bottom: 15px; /* Reduce margin */
    }
    .anime-grid h2, .filtered-content h2, .search-results h2, .anime-info-list-content h2 {
        font-size: 1.2em; /* Smaller section titles */
        padding-left: 6px;
        margin-bottom: 12px;
    }

    .featured-content {
        min-height: 200px; /* Adjust min-height for smaller banner area */
    }

    .featured-info {
        padding: 12px; /* Reduce padding */
        max-width: 100%; /* Full width text overlay */
    }
    .featured-info h3 {
        font-size: 1.25em; /* Smaller featured title */
        margin-bottom: 6px; /* Reduce margin */
    }
    .featured-info p {
        font-size: 0.8em; /* Smaller featured text */
        line-height: 1.4;
        margin-bottom: 10px;
    }
    .watch-now-btn {
        padding: 6px 12px; /* Smaller button */
        font-size: 0.85em;
    }

    .grid-container {
        grid-template-columns: repeat(3, 1fr); /* Adjust to 3 columns for smaller cards */
        gap: 6px; /* Reduce gap further */
    }
    .anime-card-image-wrapper { /* Ensure wrapper height is responsive too */
        height: 140px;
    }
    .anime-card img {
        height: 100%; /* Image should fill wrapper */
    }
    .anime-card .title {
        font-size: 0.75em;
        padding: 4px;
        white-space: normal; /* Allow title to wrap */
        text-align: left; /* Align wrapped text left */
        line-height: 1.2; /* Adjust line height for wrapped text */
        height: 2.5em; /* Limit height to roughly 2 lines */
        overflow: hidden; /* Hide overflow */
        display: -webkit-box; /* Enable multi-line ellipsis */
        -webkit-line-clamp: 2; /* Limit to 2 lines */
        -webkit-box-orient: vertical;
    }

    .anime-detail-image {
        width: 90%;
        max-width: 200px;
    }
    .anime-detail-info h2 {
        font-size: 1.4em;
    }
    .anime-detail-info p {
        font-size: 0.85em;
    }

    footer {
        font-size: 0.75em; /* Smaller footer text */
        padding: 8px 0;
        margin-top: 20px;
    }
}