/* Local Poppins font faces */
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/Poppins-Regular.woff2") format("woff2");
}

@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("fonts/Poppins-Medium.woff2") format("woff2");
}

@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("fonts/Poppins-SemiBold.woff2") format("woff2");
}

@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("fonts/Poppins-Bold.woff2") format("woff2");
}

/* Reset and Base Styles */
:root {
    /* Light Mode Variables */
    --primary-color: #FA8B28;
    --background-color: #ffffff;
    --text-color: #202020;
    --text-muted: #555555;
    --nav-bg: #ffffff;
    --nav-text: #202020;
    --nav-height: 60px;
    --categories-height: 44px;
    --footer-bg: #1a1a1a;
    --footer-text: #cccccc;
    --section-bg-alt: #f9f9f9;
    
    /* Wallpaper Grid specific variables */
    --grid-gap: 32px;
    --columns: 2;
}

@media (max-width: 1023px) {
    :root {
        --grid-gap: 16px;
    }
}

[data-theme="dark"] {
    /* Dark Mode Variables */
    --background-color: #121212;
    --text-color: #ffffff;
    --text-muted: #a3a3a3;
    --nav-bg: #1a1a1a;
    --nav-text: #ffffff;
    --section-bg-alt: #1a1a1a;
    --footer-bg: #000000;
}

/* Wallpaper Detail Page Specific Overrides */
body.wallpaper-detail-page {
    overflow-y: auto; /* From detail.php */
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
    width: 100%;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* From detail.php */
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    font-family: 'Poppins', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    width: 100%;
}

img {
    max-width: 100%;
    height: auto;
}

/* Utilities */
.fade-in-up {
    animation: fadeInUp 0.8s ease-out forwards;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Navigation Bar */
nav {
    background-color: var(--nav-bg);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: background-color 0.3s;
}

body.fixed-bars nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
}

body.fixed-bars nav .nav-container {
    height: 100%;
}

nav .nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
}

nav .logo {
    font-size: 24px;
    font-weight: 700;
    color: #FA8B28;
    text-decoration: none;
    position: relative;
}

nav .nav-links {
    list-style: none;
    display: flex;
    align-items: center;
}

nav .nav-links li {
    margin: 0 15px;
}

nav .nav-links a {
    text-decoration: none;
    color: var(--nav-text);
    font-weight: 500;
    transition: color 0.3s;
}

nav .nav-links a:hover {
    color: #FA8B28;
}

.nav-cta-button {
    background-color: #FA8B28;
    color: #ffffff !important;
    padding: 10px 20px;
    border-radius: 5px;
}

.nav-cta-button:hover {
    background-color: #ff8f47;
}

.menu-icon {
    display: none;
    flex-direction: column;
    cursor: pointer;
}

.menu-icon span {
    height: 3px;
    width: 25px;
    background-color: var(--nav-text);
    margin: 4px 0;
    transition: all 0.3s;
}

/* Header Section */
header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    background-color: var(--section-bg-alt);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

.header-content {
    flex: 1 1 500px;
    max-width: 600px;
    text-align: center;
    animation: fadeInUp 1s ease-out;
}

.header-content h1 {
    font-size: 52px;
    margin-bottom: 20px;
    font-weight: 700;
}

.header-content p {
    font-size: 26px;
    margin-bottom: 40px;
    font-weight: 400;
}

.cta-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.cta-button, .app-store-download-button {
    padding: 15px 25px;
    font-size: 1.1em;
    border: none;
    border-radius: 8px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.cta-button {
    background-color: #FA8B28;
    color: #ffffff;
}

.cta-button:hover {
    background-color: #ff8f47;
}

.app-store-download-button img {
    width: 150px;
}

.header-image {
    flex: 1 1 300px;
    max-width: 400px;
    text-align: center;
    margin-top: 40px;
}

.header-image img {
    border-radius: 20px;
}

/* Sections */
section {
    padding: 60px 20px;
    max-width: 1200px;
    margin: 0 auto;
}

section h2 {
    font-size: 36px;
    text-align: center;
    margin-bottom: 40px;
    color: #FA8B28;
    font-weight: 700;
}

section p {
    font-size: 18px;
    color: var(--text-muted);
    line-height: 1.6;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

/* Features Section */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    margin-top: 40px;
}

.feature {
    text-align: center;
}

.feature h3 {
    font-size: 22px;
    margin-top: 20px;
    color: #FA8B28;
    font-weight: 600;
}

.feature img {
    border-radius: 10px;
    transition: transform 0.3s;
}

.feature img:hover {
    transform: scale(1.05);
}

/* Features List */
.features-list {
    list-style: none;
    max-width: 800px;
    margin: 0 auto;
    padding: 0;
}

.features-list li {
    font-size: 18px;
    color: var(--text-muted);
    margin: 15px 0;
    position: relative;
    padding-left: 25px;
}

.features-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: #FA8B28;
    font-weight: 600;
}

/* FAQ Section */
.faq-item {
    max-width: 800px;
    margin: 20px auto;
}

.faq-item h3 {
    font-size: 22px;
    color: var(--text-color);
    font-weight: 600;
    margin-bottom: 10px;
}

.faq-item p {
    font-size: 18px;
    color: var(--text-muted);
    line-height: 1.6;
}

/* Wallpapers Grid Styles */
.wallpapers-main {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

body.fixed-bars main.wallpapers-main {
    padding-top: calc(var(--nav-height) + var(--categories-height) + 16px);
}

body.fixed-bars .detail-main {
    padding-top: calc(var(--nav-height) + var(--categories-height) + env(safe-area-inset-top));
}

.wallpapers-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--grid-gap);
    position: relative;
    width: 100%;
    margin: 0 auto;
    margin-bottom: 40px;
}

.wallpaper-item {
    width: calc((100% - (var(--columns) - 1) * var(--grid-gap)) / var(--columns));
    position: relative;
    display: block;
    break-inside: avoid;
    transition: transform 0.2s ease;
}

.wallpaper-item:hover {
    transform: translateY(-4px);
}

.wallpaper-link {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
}

.image-wrapper {
    width: 100%;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background-color: rgba(128, 128, 128, 0.1);
}

.wallpaper-image {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.wallpaper-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    text-align: left;
    margin-top: 4px;
    padding: 0 8px;
    white-space: normal;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.short-description {
    font-size: 14px;
    color: var(--text-color);
    opacity: 0.8;
    margin-top: 4px;
    text-align: left;
    padding-left: 16px;
    padding-bottom: 16px;
}

.wallpaper-item:active .wallpaper-image {
    transform: scale(0.95);
}

/* Profile unlocked wallpapers grid overrides */
.profile-wallpapers-grid .wallpaper-item {
    width: 100%;
}

.profile-wallpapers-grid .image-wrapper {
    aspect-ratio: 2 / 3;
}

.profile-wallpapers-grid .wallpaper-image {
    height: 100%;
}

.profile-wallpapers-grid .wallpaper-title {
    font-size: 12px;
    text-align: center;
    padding: 6px 4px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(128, 128, 128, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Wallpaper Detail Page Styles */

/* Breadcrumbs */
.breadcrumbs {
    background: transparent;
    border: 0;
    box-shadow: none;
    justify-content: flex-start;
    text-align: left;
}

.detail-breadcrumbs {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    padding-left: 32px;
}

.breadcrumb-item {
    font-size: 14px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb-item:hover {
    color: var(--text-color);
}

.breadcrumb-separator {
    margin: 0 6px;
    color: var(--text-muted);
    opacity: 0.6;
}

.breadcrumb-item.active {
    color: var(--primary-color);
}

/* Detail Header */
.wallpaper-detail-header {
    background: transparent;
}

.wallpaper-detail-header h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.wallpaper-description {
    font-size: 16px;
    color: var(--text-color);
    opacity: 0.8;
    margin-top: 8px;
    line-height: 1.5;
}

/* Detail Main Container */
.detail-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
}

.image-container {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.3) 100%);
    padding: 20px;
}

/* Detail Image */
.detail-image {
    width: 100%;
    height: auto;
    max-height: 75vh;
    object-fit: contain;
}

.download-btn {
    flex: 1;
    padding: 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: env(safe-area-inset-bottom);
    text-decoration: none;
    text-align: center;
    box-shadow: 0 8px 20px rgba(250, 139, 40, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.download-btn:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.download-btn:active {
    transform: scale(0.98) translateY(2px);
    background: #e07a20;
    box-shadow: 0 4px 12px rgba(250, 139, 40, 0.2);
}

.download-btn:active:before {
    opacity: 1;
}

.unlock-btn {
    background-color: #2a2a2a;
    color: #ffffff;
    border: 1px solid #444;
}

.unlock-btn:hover {
    background-color: #333;
}

.download-btn-icon {
    width: 22px;
    height: 22px;
}

.wallpaper-tags {
    padding: 12px 16px;
    background: var(--section-bg-alt);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-top: 1px solid rgba(128, 128, 128, 0.1);
    display: flex;
    overflow-x: auto;
    gap: 8px;
    scrollbar-width: none;
    border-radius: 12px;
}

.wallpaper-tags::-webkit-scrollbar {
    display: none;
}

.tag {
    background: rgba(128, 128, 128, 0.1);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 12px;
    white-space: nowrap;
    color: var(--text-color);
    text-decoration: none;
}

.tag:active {
    background: rgba(128, 128, 128, 0.2);
}

/* Safe Area Insets (Common) */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 40px 0;
    flex-wrap: wrap;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border-radius: 20px;
    background: rgba(128, 128, 128, 0.1);
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 14px;
}

.pagination-btn:not(.disabled):hover {
    background: rgba(128, 128, 128, 0.2);
    transform: translateY(-2px);
}

.pagination-btn.active {
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    cursor: default;
}

.pagination-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-ellipsis {
    color: var(--text-color);
    opacity: 0.5;
    padding: 0 4px;
}

/* Categories Menu */
.categories-menu-container {
    transition: background-color 0.3s, border-color 0.3s;
}

body.fixed-bars .categories-menu-container {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    z-index: 900;
}

.categories-menu-frame {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

.categories-menu-frame::before,
.categories-menu-frame::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 34px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 2;
}

.categories-menu-frame::before {
    left: 0;
    background: linear-gradient(to right, var(--nav-bg) 0%, var(--nav-bg) 20%, rgba(255, 255, 255, 0) 100%);
}

.categories-menu-frame::after {
    right: 0;
    background: linear-gradient(to left, var(--nav-bg) 0%, var(--nav-bg) 20%, rgba(255, 255, 255, 0) 100%);
}

.categories-menu-frame.has-left::before {
    opacity: 1;
}

.categories-menu-frame.has-right::after {
    opacity: 1;
}

.categories-menu {
    -webkit-overflow-scrolling: touch;
    padding: 0 20px;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.category-link {
    display: inline-flex;
    align-items: center;
    height: 44px;
    color: #666;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

[data-theme="dark"] .category-link {
    color: #999;
}

.category-link:hover {
    color: var(--text-color);
}

.category-link.active {
    color: var(--text-color);
    border-bottom-color: var(--text-color);
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.page-title {
    color: var(--text-color);
    font-size: 20px;
    font-weight: 600;
    margin: 12px 16px;
}

/* App Promotion Banner */
.app-promotion {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px 16px;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    /* Fix for iOS scroll jitter/gap */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    width: 100%;
}

body.is-ios .app-promotion {
    display: flex !important;
}

.app-promotion-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.app-info {
    flex: 1;
}

.app-info h2 {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    margin: 0;
}

.app-info p {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    margin: 2px 0 0 0;
}

.download-app-btn {
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.download-app-btn:active {
    transform: scale(0.96);
    background: #ff8f47;
}

/* Footer */
footer {
    background-color: #1a1a1a;
    color: #cccccc;
    padding: 40px 20px;
    text-align: center;
}

footer a {
    color: #FA8B28;
    text-decoration: none;
    font-weight: 500;
}

.footer-content p {
    font-size: 14px;
    margin: 10px 0;
}

.social-media-icons {
    margin: 20px 0;
}

.social-media-icons a {
    margin: 0 10px;
    display: inline-block;
    transition: transform 0.3s;
}

.social-media-icons a:hover {
    transform: translateY(-5px);
}

.social-media-icons img {
    width: 30px;
    height: 30px;
}

/* Product Hunt Badge */
.product-hunt-badge {
    text-align: center;
    margin-top: 40px;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

/* Media Queries for Mobile Responsiveness */
@media (max-width: 1024px) {
    .header-content h1 {
        font-size: 42px;
    }

    .header-content p {
        font-size: 22px;
    }
}

    @media (max-width: 768px) {
    nav .nav-links {
        position: absolute;
        top: 60px;
        left: -100%;
        width: 100%;
        background-color: var(--nav-bg);
        flex-direction: column;
        align-items: center;
        transition: left 0.3s;
    }

    nav .nav-links.active {
        left: 0;
    }

    nav .nav-links li {
        margin: 15px 0;
    }

    .menu-icon {
        display: flex;
        width: 30px;
        height: 30px;
        align-items: center;
        justify-content: center;
        position: relative;
    }

    /* Position the active icon (X) absolutely within the nav container */
    .menu-icon.active {
        position: absolute; /* Position relative to nav .container */
        top: 15px;        /* Match container top padding */
        right: 20px;       /* Match container right padding */
        z-index: 1001;    /* Ensure it's above .nav-links.active */
    }

    .menu-icon.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
        background-color: var(--nav-text); /* Ensure visibility on white menu */
    }

    .menu-icon.active span:nth-child(2) {
        opacity: 0;
    }

    .menu-icon.active span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
        background-color: var(--nav-text); /* Ensure visibility on white menu */
    }

    .header-content h1 {
        font-size: 36px;
    }

    .header-content p {
        font-size: 20px;
    }

    .cta-buttons a {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 30px;
    }

    .header-content p {
        font-size: 18px;
    }

    .cta-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .cta-buttons a {
        width: 100%;
        padding: 12px 20px;
    }
}

/* Wallpapers Responsive */
@media (min-width: 640px) {
    :root {
        --columns: 3;
    }
}

@media (min-width: 1024px) {
    :root {
        --columns: 2;
    }
    .wallpaper-title {
        font-size: 18px;
    }
}

@media (min-width: 1280px) {
    :root {
        --columns: 3;
    }
    .app-promotion {
        display: none;
    }
    
    body.has-app-banner footer,
    body.has-app-banner.wallpaper-detail-page .detail-main {
        padding-bottom: 40px;
        margin-bottom: 0;
    }
}

@media (max-width: 1199px) {
    body.has-app-banner footer {
        padding-bottom: calc(120px + env(safe-area-inset-bottom));
    }
    
    body.has-app-banner.wallpaper-detail-page .detail-main {
        margin-bottom: calc(120px + env(safe-area-inset-bottom));
    }
}

/* Nav Icons */
.nav-icons {
    display: flex;
    align-items: center;
    gap: 20px;
}

.icon-link {
    color: var(--nav-text);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: color 0.3s;
    text-decoration: none;
}

.icon-link:hover {
    color: #FA8B28;
}

.nav-icon {
    width: 24px;
    height: 24px;
}

.cart-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: #FA8B28;
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
}

@media (max-width: 768px) {
    .nav-icons {
        gap: 15px;
    }
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}
