body {
    font-family: 'Inter', sans-serif;
    background-color: #0B1120; /* Darker Slate */
    background-image: radial-gradient(circle at top, hsl(222, 47%, 11%), #0B1120);
    color: #f8fafc; /* slate-50 */
}

/* Card styles with reveal animation */
.card {
    background-color: #161e31; /* Slightly lighter slate */
    border: 1px solid #334155; /* slate-700 */
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
    transform: translateY(20px);
    position: relative;
}

.card.is-visible {
    opacity: 1;
    transform: translateY(0px);
}

.card:hover {
    transform: translateY(-6px) scale(1.02);
    border-color: #8b5cf6; /* violet-500 */
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

.card-highlight {
    box-shadow: 0 0 30px 8px rgba(167, 139, 250, 0.8), 0 0 60px 15px rgba(139, 92, 246, 0.4) !important;
    border-color: #a78bfa !important;
    animation: pulse-highlight 1.5s ease-in-out infinite !important;
}

@keyframes pulse-highlight {
    0%, 100% { 
        box-shadow: 0 0 30px 8px rgba(167, 139, 250, 0.8), 0 0 60px 15px rgba(139, 92, 246, 0.4);
    }
    50% { 
        box-shadow: 0 0 40px 12px rgba(167, 139, 250, 1), 0 0 80px 20px rgba(139, 92, 246, 0.6);
    }
}


.tag-recommended {
    border-color: #f59e0b; /* amber-500 */
}

/* New GOAT animation styles for cards */
.card.tag-goat {
    position: relative;
    overflow: hidden; /* Hide the overflowing parts of the animation */
    border-color: transparent; /* Base border is transparent to let animation show */
    z-index: 1;
}

/* The animated gradient overlay */
.card.tag-goat::before {
    content: '';
    position: absolute;
    left: -50%;
    top: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(
        #06b6d4,       /* Aqua */
        #20dcc3,       /* Lighter Aqua-Green */
        #34f58b,       /* Peak Green */
        #20dcc3,       /* Lighter Aqua-Green */
        #06b6d4,       /* Aqua */
        #06b6d4        /* Aqua to ensure it's the dominant color */
    );
    animation: rotate 6s linear infinite;
}

.card.tag-goat:hover::before {
    animation-duration: 3s;
}

/* The inner mask to create the border effect */
.card.tag-goat::after {
    content: '';
    position: absolute;
    inset: 2px; /* Controls the border width */
    background: #161e31; /* Must match the card background */
    border-radius: inherit;
    z-index: 1; /* Sits above the ::before gradient */
}

/* Ensure card content is on top of everything */
.card.tag-goat > * {
    position: relative;
    z-index: 2;
}


/* Homepage Category Card Styles */
.category-card {
    background-color: #161e31;
    border-radius: 1rem;
    padding: 2rem;
    border: 1px solid #334155;
    transition: all 0.3s ease-in-out;
    display: block;
    height: 100%;
}

.category-card:hover {
    transform: translateY(-8px);
    border-color: #8b5cf6; /* violet-500 */
    box-shadow: 0 20px 30px -10px rgba(0, 0, 0, 0.4);
}

.category-card-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    height: 100%;
}


/* Tab styles */
.tabs-nav .tab-button {
    border-color: transparent;
    color: #94a3b8; /* slate-400 */
    transition: all 0.2s ease-in-out;
}
.tabs-nav .tab-button:hover {
    color: #ffffff;
    border-color: #475569; /* slate-600 */
}
.tabs-nav .tab-button.active {
    color: #a78bfa; /* violet-400 */
    border-color: #a78bfa; /* violet-400 */
}

/* Sub-tab active state */
.sub-tabs-nav .sub-tab-button {
    transition: all 0.2s ease-in-out;
}
.sub-tabs-nav .sub-tab-button:hover {
    background-color: #334155;
    color: #ffffff;
}
.sub-tabs-nav .sub-tab-button.active {
    background-color: #8b5cf6; /* violet-500 */
    color: #ffffff;
}
.sub-tabs-nav .sub-tab-button.tag-goat {
     border: 2px solid #06b6d4;
     color: #06b6d4;
     background-color: transparent;
}
.sub-tabs-nav .sub-tab-button.tag-goat.active,
.sub-tabs-nav .sub-tab-button.tag-goat:hover {
    background-color: #06b6d4;
    color: #0B1120;
    animation: pulse-glow-strong 2s infinite alternate;
}


.tab-content, .sub-tab-content {
    display: none;
}

.tab-content.active, .sub-tab-content.active {
    display: block;
    animation: fadeIn 0.5s ease-in-out;
}

/* Utility class provided by Tailwind, but good to have a fallback */
.hidden {
    display: none !important;
}

/* New styles for search dropdown */
#search-results-container .card {
    transform: scale(0.95);
    transform-origin: top left;
    margin-bottom: -1rem; /* Adjust for scale */
    transition: none;
    box-shadow: none;
    pointer-events: all; 
}

#search-results-container .card:hover {
    transform: scale(0.95);
    border-color: #334155; 
}

.search-result-item {
    transition: background-color 0.2s ease-in-out;
}

.search-result-item:hover {
    background-color: #1e293b; /* slate-800 */
}

#search-results-container .card.tag-goat,
#search-results-container .card.tag-goat:hover {
    animation: none !important;
    border-color: #06b6d4;
}

#search-results-container .card.tag-goat::before,
#search-results-container .card.tag-goat::after {
    display: none;
}


/* Tools Dropdown Full Card Overlay */
.card .tools-dropdown-content {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(22, 30, 49, 0.98) 0%, rgba(30, 41, 59, 0.98) 100%);
    backdrop-filter: blur(10px);
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8) translateY(20px);
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 0.75rem;
    box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.1), 0 20px 40px rgba(0, 0, 0, 0.3);
}

.card .card-main-content {
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* State when tools are active */
.card.tools-active .card-main-content {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
    pointer-events: none;
}

.card.tools-active .tools-dropdown-content {
    opacity: 1;
    transform: scale(1.02) translateY(0);
    pointer-events: auto;
}

.card.tools-active {
    transform: scale(1.02);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(139, 92, 246, 0.3);
    z-index: 20;
    border-color: #8b5cf6;
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(139, 92, 246, 0.3);
    }
    50% {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(139, 92, 246, 0.6);
    }
}

/* Animate dropdown items */
.card.tools-active .tools-dropdown-content > * {
    animation: slideInUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.card.tools-active .tools-dropdown-content > *:nth-child(1) {
    animation-delay: 0.08s;
}

.card.tools-active .tools-dropdown-content > *:nth-child(2) {
    animation-delay: 0.12s;
}

.card.tools-active .tools-dropdown-content > *:nth-child(3) {
    animation-delay: 0.16s;
}

.card.tools-active .tools-dropdown-content > *:nth-child(4) {
    animation-delay: 0.2s;
}

.card.tools-active .tools-dropdown-content > *:nth-child(5) {
    animation-delay: 0.24s;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Close button hover effect */
.close-tools-button {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.close-tools-button:hover {
    transform: rotate(90deg) scale(1.1);
}

/* Tools button ripple effect */
.tools-dropdown-button {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.tools-dropdown-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tools-dropdown-button:active {
    transform: translateY(0);
}

/* Position the dropdown arrow icon on the right */
.tools-dropdown-button svg {
    position: absolute;
    right: 1rem;
    pointer-events: none;
}

/* Custom Tooltip for Tools button - appears faster */
.tools-dropdown-button::before {
    content: "Click to Expand";
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: rgba(15, 23, 42, 0.95);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
    transition-delay: 0.1s;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tools-dropdown-button::after {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    border: 6px solid transparent;
    border-top-color: rgba(15, 23, 42, 0.95);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
    transition-delay: 0.1s;
    z-index: 100;
}

.tools-dropdown-button:hover::before,
.tools-dropdown-button:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: ripple-animation 0.6s ease-out;
    pointer-events: none;
}

@keyframes ripple-animation {
    to {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* Dropdown content buttons */
.tools-dropdown-content a,
.tools-dropdown-content button {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tools-dropdown-content a:hover,
.tools-dropdown-content button:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tools-dropdown-content h4 {
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}



@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow-weak {
    from { box-shadow: 0 0 8px rgba(6, 182, 212, 0.2); }
    to { box-shadow: 0 0 16px rgba(6, 182, 212, 0.5); }
}

@keyframes pulse-glow-strong {
    from { box-shadow: 0 0 12px rgba(6, 182, 212, 0.5); }
    to { box-shadow: 0 0 24px rgba(6, 182, 212, 0.8); }
}

@keyframes rotate {
    100% {
        transform: rotate(1turn);
    }
}


/* Modal animation */
.modal-overlay {
    background-color: rgba(11, 17, 32, 0.8);
    backdrop-filter: blur(8px);
    transition: opacity 0.3s ease-in-out;
}
.modal-content, #image-guide-content {
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    opacity: 0;
    transform: scale(0.95) translateY(10px);
}
.modal-overlay:not(.hidden) .modal-content,
.modal-overlay:not(.hidden) #image-guide-content {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* For Tailwind Prose styles */
.prose {
    --tw-prose-body: #d1d5db;
    --tw-prose-headings: #ffffff;
    --tw-prose-bold: #ffffff;
}

.stremio-button {
    border-color: #06b6d4; /* cyan-500 */
    color: #06b6d4;
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
    animation: pulse-glow-weak 4s infinite alternate;
}

.stremio-button:hover {
    background-color: #06b6d4;
    color: #0B1120;
    animation: pulse-glow-strong 2s infinite alternate;
}

/* ===== LIGHT MODE STYLES ===== */
[data-theme="light"] body {
    background-color: #f1f5f9; /* slate-100 */
    background-image: radial-gradient(circle at top, #e2e8f0, #f1f5f9);
    color: #0f172a; /* slate-900 */
}

[data-theme="light"] header {
    background-color: rgba(255, 255, 255, 0.9) !important;
    border-bottom-color: #e2e8f0 !important;
}

[data-theme="light"] .card {
    background-color: #ffffff;
    border-color: #cbd5e1; /* slate-300 */
    color: #0f172a;
}

[data-theme="light"] .card:hover {
    border-color: #8b5cf6;
    box-shadow: 0 10px 25px -5px rgba(139, 92, 246, 0.2), 0 8px 10px -6px rgba(139, 92, 246, 0.1);
}

[data-theme="light"] .card.tag-goat::after {
    background: #ffffff;
}

[data-theme="light"] .category-card {
    background-color: #ffffff;
    border-color: #cbd5e1;
}

[data-theme="light"] .tabs-nav {
    background-color: rgba(255, 255, 255, 0.9) !important;
    border-top-color: #e2e8f0 !important;
}

[data-theme="light"] .tabs-nav .tab-button {
    color: #64748b; /* slate-500 */
}

[data-theme="light"] .tabs-nav .tab-button:hover {
    color: #0f172a;
    border-color: #94a3b8;
}

[data-theme="light"] .tabs-nav .tab-button.active {
    color: #8b5cf6;
    border-color: #8b5cf6;
}

[data-theme="light"] .sub-tabs-nav {
    background-color: #f8fafc !important;
}

[data-theme="light"] .sub-tabs-nav .sub-tab-button {
    color: #64748b;
}

[data-theme="light"] .sub-tabs-nav .sub-tab-button:hover {
    background-color: #e2e8f0;
    color: #0f172a;
}

[data-theme="light"] .sub-tabs-nav .sub-tab-button.active {
    background-color: #8b5cf6;
    color: #ffffff;
}

[data-theme="light"] h1, 
[data-theme="light"] h2, 
[data-theme="light"] h3, 
[data-theme="light"] h4 {
    color: #0f172a !important;
}

[data-theme="light"] p {
    color: #475569 !important;
}

[data-theme="light"] .text-slate-400 {
    color: #64748b !important;
}

[data-theme="light"] .text-slate-300 {
    color: #475569 !important;
}

[data-theme="light"] .text-white {
    color: #0f172a !important;
}

[data-theme="light"] .bg-slate-800 {
    background-color: #f8fafc !important;
    border-color: #e2e8f0 !important;
}

[data-theme="light"] .bg-slate-900 {
    background-color: #ffffff !important;
}

[data-theme="light"] .border-slate-700 {
    border-color: #cbd5e1 !important;
}

[data-theme="light"] .border-slate-800 {
    border-color: #e2e8f0 !important;
}

[data-theme="light"] input {
    background-color: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

[data-theme="light"] input::placeholder {
    color: #94a3b8 !important;
}

[data-theme="light"] input:focus {
    background-color: #ffffff !important;
    color: #0f172a !important;
}

[data-theme="light"] #search-results-container {
    background-color: #ffffff !important;
    border-color: #cbd5e1 !important;
}

[data-theme="light"] .search-result-item:hover {
    background-color: #f8fafc !important;
}

[data-theme="light"] footer {
    border-top-color: #e2e8f0 !important;
}

[data-theme="light"] .text-slate-500 {
    color: #64748b !important;
}

[data-theme="light"] .modal-overlay {
    background-color: rgba(241, 245, 249, 0.9);
}

[data-theme="light"] .modal-content {
    background-color: #ffffff !important;
    border-color: #cbd5e1 !important;
}

[data-theme="light"] #theme-toggle {
    background-color: #f8fafc !important;
}

[data-theme="light"] #theme-toggle:hover {
    background-color: #e2e8f0 !important;
}

[data-theme="light"] .card .tools-dropdown-content {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.98) 100%);
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.1);
}

/* ===== NEW FEATURE STYLES ===== */

/* Copy Link Button */
.copy-link-btn {
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    z-index: 10;
}

/* Bios Download Button - Center text properly */
.bios-download-btn {
    position: relative;
}

.bios-download-btn .bios-text {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.bios-download-btn svg {
    margin-left: auto;
}

/* Center all button text when copy link button is present */
a[href] span:first-child {
    flex: 1;
    text-align: center;
}

/* Ensure Visit Site and other main buttons have centered text */
.card a[target="_blank"]:not(.bios-download-btn) {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.card a[target="_blank"]:not(.bios-download-btn) span:first-child {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.copy-link-btn:hover {
    transform: scale(1.1);
    background-color: rgba(71, 85, 105, 0.8) !important;
}

/* Recently Added Badge */
.recently-added-badge {
    animation: pulse-badge 2s infinite;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
    flex-shrink: 0;
}

/* RetroAchievements Badge */
.retroachievements-badge {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 0.5rem;
    vertical-align: middle;
    cursor: help;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.retroachievements-badge img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.retroachievements-badge:hover {
    transform: scale(1.2);
}

/* RetroAchievements Tooltip - Using native HTML title attribute instead of CSS */

@keyframes pulse-badge {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

/* Favorite Button */
.favorite-btn {
    flex-shrink: 0;
    cursor: pointer;
}

.favorite-btn:hover {
    transform: scale(1.15);
}

/* Card Favicon */
.card-favicon {
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px;
}

[data-theme="light"] .card-favicon {
    background: rgba(0, 0, 0, 0.05);
}

/* Favorited Card Styling */
.favorited-card {
    border-color: rgba(239, 68, 68, 0.3) !important;
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.1);
}

.favorited-card:hover {
    border-color: rgba(239, 68, 68, 0.5) !important;
}

[data-theme="light"] .favorited-card {
    border-color: rgba(239, 68, 68, 0.2) !important;
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.15);
}

/* Resource Counter */
.resource-counter {
    animation: slideInRight 0.5s ease-out;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Search Filters */
#search-filters select {
    cursor: pointer;
}

#search-filters select:hover {
    border-color: #8b5cf6;
}

[data-theme="light"] #search-filters select {
    background-color: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

[data-theme="light"] .copy-link-btn,
[data-theme="light"] .favorite-btn {
    background-color: rgba(248, 250, 252, 0.9);
}

[data-theme="light"] .copy-link-btn:hover,
[data-theme="light"] .favorite-btn:hover {
    background-color: rgba(226, 232, 240, 1);
}

/* Hidden Systems Toggle */
.hidden-system {
    display: none;
}

.systems-list.expanded .hidden-system {
    display: inline-block;
}

/* Animated Card Transitions */
.card {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.card[style*="display: none"] {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

.card:not([style*="display: none"]) {
    opacity: 1;
    transform: scale(1);
}

/* Smooth Grid Transitions */
#emulators-grid {
    transition: all 0.3s ease;
}

/* Stats Dashboard Styles */
.stats-card {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(99, 102, 241, 0.1) 100%);
    border: 1px solid rgba(139, 92, 246, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stats-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(139, 92, 246, 0.15);
}

.stats-number {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #a78bfa 0%, #818cf8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Accessibility Improvements */
.focus-visible:focus {
    outline: 2px solid #a78bfa;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #a78bfa;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Lazy Loading Images */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Image placeholder while loading */
img[loading="lazy"]:not(.loaded) {
    background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ===== MOBILE OPTIMIZATIONS ===== */

/* Improve touch targets on mobile */
@media (max-width: 768px) {
    /* Larger touch targets for buttons */
    .tab-button {
        min-height: 44px;
        padding: 0.75rem 0.75rem !important;
        flex-direction: row;
        gap: 0.5rem !important;
        font-size: 0.8rem;
        white-space: nowrap;
    }
    
    .tab-button svg {
        width: 1.125rem;
        height: 1.125rem;
        flex-shrink: 0;
    }
    
    .sub-tab-button {
        min-height: 44px;
        padding: 0.75rem 1rem !important;
    }
    
    /* Better mobile header */
    header .flex.items-center.gap-4 {
        gap: 0.5rem;
    }
    
    header {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    /* Keep logo and TMTY visible on mobile */
    header .flex.items-center.gap-4 > a {
        flex-shrink: 0;
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
    }
    
    header .flex.items-center.gap-4 > a svg {
        width: 2rem !important;
        height: 2rem !important;
    }
    
    header .flex.items-center.gap-4 > a .text-2xl {
        font-size: 1.125rem !important;
        display: inline-block !important;
    }
    
    /* Show TMTY text on mobile */
    header .flex.items-center.gap-4 > a > span {
        display: inline-block !important;
    }
    
    /* Adjust search bar for mobile */
    #search-bar-container {
        padding: 0.5rem 0.25rem;
        flex: 1;
        min-width: 0;
    }
    
    #search-bar-container .relative.max-w-lg {
        max-width: 100%;
    }
    
    /* Make search input more compact */
    #global-filter {
        font-size: 0.875rem;
        padding: 0.5rem 0.5rem 0.5rem 2.5rem;
    }
    
    #global-filter::placeholder {
        font-size: 0.875rem;
    }
    
    /* Ensure navigation doesn't overflow */
    nav {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    .tabs-nav > div {
        max-width: 100vw;
    }
    
    /* Make settings button more compact */
    #settings-dropdown-btn {
        padding: 0.5rem !important;
    }
    
    /* Improve card spacing on mobile */
    .card {
        padding: 1rem !important;
    }
    
    /* Better modal on mobile */
    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
        overflow-y: auto;
    }
    
    /* Optimize settings dropdown position */
    #settings-dropdown {
        right: 0;
        left: auto;
        min-width: 200px;
    }
    
    /* Better category cards on mobile */
    .category-card {
        padding: 1.5rem;
    }
    
    /* Improve stats grid on mobile */
    .stats-card {
        padding: 1rem !important;
    }
    
    .stats-number {
        font-size: 2rem !important;
    }
    
    /* Better tools dropdown on mobile */
    .card .tools-dropdown-content {
        padding: 1rem;
        gap: 0.5rem;
    }
    
    /* Improve sub-tabs wrapping */
    .sub-tabs-nav {
        padding: 0.5rem !important;
        gap: 0.25rem !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
    }
    
    .sub-tabs-nav::-webkit-scrollbar {
        display: none;
    }
    
    .sub-tabs-nav .sub-tab-button {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem !important;
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    /* Even smaller padding for tiny screens */
    body {
        font-size: 14px;
    }
    
    .card {
        padding: 0.75rem !important;
    }
    
    .category-card {
        padding: 1rem;
    }
    
    /* Compact header */
    header .h-16 {
        height: auto;
        min-height: 3.5rem;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    /* Smaller logo and title */
    header svg {
        height: 1.75rem;
        width: 1.75rem;
    }
    
    header .text-2xl {
        font-size: 1.125rem;
    }
    
    /* Ensure header content wraps if needed */
    header .flex.items-center.justify-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* Keep subtitle visible but smaller */
    header .text-xs {
        font-size: 0.65rem;
    }
    
    /* Hide full title on very small screens but keep TMTY */
    header .hidden.md\:block {
        display: none !important;
    }
    
    /* Compact search */
    #global-filter {
        font-size: 0.875rem;
        padding: 0.5rem 0.5rem 0.5rem 2rem;
    }
    
    /* Hide search placeholder text on tiny screens */
    #global-filter::placeholder {
        content: "Search";
    }
    
    /* Smaller stats */
    .stats-number {
        font-size: 1.5rem !important;
    }
    
    .stats-card .text-sm {
        font-size: 0.75rem;
    }
    
    /* Keep tab buttons readable on very small screens */
    .tab-button {
        font-size: 0.7rem !important;
        padding: 0.625rem 0.5rem !important;
    }
    
    .tab-button svg {
        width: 1rem;
        height: 1rem;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    /* Make header more compact in landscape */
    header .h-16 {
        height: 3rem;
    }
    
    .tab-button {
        padding: 0.5rem !important;
    }
}

/* Smooth scrolling for mobile tabs */
.tabs-nav > div {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.tabs-nav > div::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Better tap highlight colors */
@media (hover: none) and (pointer: coarse) {
    /* This targets touch devices */
    * {
        -webkit-tap-highlight-color: rgba(167, 139, 250, 0.3);
    }
    
    button, a, .card {
        -webkit-tap-highlight-color: rgba(167, 139, 250, 0.2);
    }
    
    /* Prevent text selection on buttons */
    button, .tab-button, .sub-tab-button {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Better active states for touch */
    .card:active {
        transform: scale(0.98);
    }
    
    button:active, .tab-button:active, .sub-tab-button:active {
        opacity: 0.7;
    }
}

/* Prevent horizontal scroll on body */
body {
    overflow-x: hidden;
    max-width: 100vw;
}

html {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Prevent any element from causing horizontal scroll */
@media (max-width: 768px) {
    * {
        box-sizing: border-box;
    }
    
    /* Constrain all containers */
    div, section, article, aside, nav, header, footer, main {
        max-width: 100vw;
    }
    
    /* Allow specific elements to use full viewport */
    .max-w-screen-2xl {
        max-width: 100vw !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .w-full {
        max-width: 100% !important;
    }
    
    /* Fix flex containers that might overflow */
    .flex {
        flex-wrap: wrap;
        max-width: 100%;
    }
    
    /* Specific fix for sub-tabs that were causing overflow */
    .sub-tabs-nav.flex {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
    }
}

/* Ensure images don't overflow on mobile */
img {
    max-width: 100%;
    height: auto;
}

/* Better spacing for mobile grids */
@media (max-width: 640px) {
    .grid {
        gap: 1rem !important;
    }
    
    /* Single column on mobile for better readability */
    .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3.xl\:grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
    
    .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
    
    .grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    
    /* Ensure main content doesn't overflow */
    main {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    /* Fix any wide containers */
    .max-w-screen-2xl {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Improve focus visibility for keyboard navigation on mobile */
@media (max-width: 768px) {
    *:focus-visible {
        outline: 3px solid #a78bfa;
        outline-offset: 2px;
    }
    
    /* Better button sizing for touch */
    .favorite-btn, .copy-link-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.75rem;
    }
    
    /* Improve tools button on mobile */
    .tools-dropdown-button {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
    
    /* Better spacing for card buttons */
    .card a, .card button {
        min-height: 44px;
    }
    
    /* Improve heading sizes on mobile */
    h1 {
        font-size: 1.875rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    /* Better text readability */
    p {
        line-height: 1.6;
    }
}

/* Tablet optimization (between mobile and desktop) */
@media (min-width: 641px) and (max-width: 1024px) {
    /* Optimize card grid for tablets */
    .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3.xl\:grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    
    /* Better category card layout on tablets */
    .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* Mobile-specific search results */
@media (max-width: 768px) {
    #search-results-container {
        position: fixed;
        left: 0.5rem;
        right: 0.5rem;
        top: auto;
        margin-top: 0.5rem;
        max-height: 60vh;
        width: auto;
    }
    
    /* Better scrolling for search results on mobile */
    #search-results-container {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent zoom on input focus for iOS */
@media (max-width: 768px) {
    input[type="text"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Light mode mobile optimizations */
@media (max-width: 768px) {
    [data-theme="light"] .card {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    [data-theme="light"] .card:hover {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    
    [data-theme="light"] .category-card {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    [data-theme="light"] .category-card:hover {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
}

/* Mobile header layout improvements */
@media (max-width: 640px) {
    /* Stack header elements vertically if needed */
    header > div > div.flex.items-center.justify-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
    }
    
    /* Logo row */
    header .flex.items-center.gap-4 {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Search row */
    #search-bar-container {
        width: 100%;
        max-width: 100% !important;
        order: 2;
    }
    
    /* Settings button stays with logo */
    #search-bar-container > div:last-child {
        position: absolute;
        right: 1rem;
        top: 1rem;
    }
}
